* { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #f1f4f8;
    color: #1e293b;
    line-height: 1.5;
}

/* Base containers */
.container {
    width: 100%;
    max-width: 960px;
    margin: 30px auto;
    padding: 0 16px;
    box-sizing: border-box;
}
.container.narrow { max-width: 420px; margin-top: 60px; }
.container.wide {
    width: 100%;
    max-width: 1140px;
    margin: 20px auto;
    padding: 0 16px;
    box-sizing: border-box;
}

/* Global Topbar */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}
.topbar a { color: #1877f2; text-decoration: none; font-weight: 500; }
.topbar a:hover { text-decoration: underline; }
h1 { color: #1877f2; margin: 0; font-size: 24px; }

/* Base Card */
.card {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    border: 1px solid #e2e8f0;
    box-sizing: border-box;
}

/* Form Controls */
input[type=text], input[type=password], input[type=datetime-local], input[type=url], textarea, select {
    width: 100%;
    max-width: 100%;
    padding: 9px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
    box-sizing: border-box;
    font-family: inherit;
}
input:focus, textarea:focus, select:focus {
    border-color: #1877f2;
    outline: none;
    box-shadow: 0 0 0 3px rgba(24, 119, 242, 0.15);
}

/* Buttons */
button, .button {
    background: #1877f2;
    color: #fff;
    border: none;
    padding: 9px 18px;
    border-radius: 6px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.15s ease;
    box-sizing: border-box;
}
button:hover, .button:hover { background: #145dbf; }
.btn-light {
    background: #fff;
    color: #1877f2;
    font-weight: 600;
    border: 1px solid #cbd5e1;
}
.btn-light:hover { background: #f8fafc; border-color: #94a3b8; }
.btn-outline-light {
    background: rgba(255,255,255,0.15);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.4);
}
.btn-outline-light:hover { background: rgba(255,255,255,0.25); }
.btn-sm-action {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #cbd5e1;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.btn-sm-action:hover { background: #e2e8f0; color: #0f172a; }

/* Alerts */
.error { color: #dc2626; background: #fef2f2; border: 1px solid #fecaca; padding: 10px 14px; border-radius: 6px; font-size: 13.5px; margin-bottom: 14px; }
.success { color: #16a34a; background: #f0fdf4; border: 1px solid #bbf7d0; padding: 10px 14px; border-radius: 6px; font-size: 13.5px; margin-bottom: 14px; }

/* Base tables */
table { width: 100%; border-collapse: collapse; }
table th, table td { text-align: left; padding: 10px; border-bottom: 1px solid #e2e8f0; font-size: 13.5px; }

.status-published { color: #16a34a; font-weight: bold; }
.status-scheduled { color: #d97706; font-weight: bold; }
.status-failed { color: #dc2626; font-weight: bold; }

/* Compose grid for dashboard */
.compose-grid { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-start; }
.compose-form { flex: 1 1 360px; min-width: 280px; }
.compose-preview-wrap { flex: 1 1 300px; min-width: 260px; }
.fb-preview { border: 1px solid #dcdfe4; border-radius: 10px; overflow: hidden; background: #fff; }
.fb-preview-header { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.fb-avatar { width: 38px; height: 38px; border-radius: 50%; background: #1877f2; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 16px; flex-shrink: 0; }
.fb-preview-name { font-weight: 600; font-size: 13.5px; }
.fb-preview-meta { font-size: 11.5px; color: #64748b; }
.fb-preview-caption { padding: 4px 12px 10px; white-space: pre-wrap; font-size: 13.5px; line-height: 1.4; word-break: break-word; color: #0f172a; }
.fb-preview-media { width: 100%; background: #f1f5f9; }
.fb-preview-media img, .fb-preview-media video { width: 100%; display: block; max-height: 320px; object-fit: cover; }
.fb-preview-footer { display: flex; justify-content: space-around; padding: 8px 0; border-top: 1px solid #eee; color: #64748b; font-size: 12px; }

/* ==========================================================================
   TECH NEWS HUB — ZERO OVERFLOW LAYOUT
   ========================================================================== */

/* Topbar tech */
.tech-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
}
.tech-page-title {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.timezone-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #e2e8f0;
    color: #334155;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11.5px;
    font-weight: 600;
}

/* Hero Header */
.tech-hero {
    background: linear-gradient(135deg, #1877f2 0%, #0c4a9e 100%);
    border-radius: 10px;
    padding: 16px 20px;
    color: #fff;
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
}
.tech-hero h2 { margin: 0 0 4px 0; font-size: 18px; color: #fff; }
.tech-hero p { margin: 0; font-size: 13px; color: rgba(255,255,255,0.9); }
.tech-hero-stats { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.hero-stat-pill {
    background: rgba(255,255,255,0.2);
    padding: 3px 10px;
    border-radius: 14px;
    font-size: 11.5px;
    font-weight: 500;
}

/* Toolbar & Filtri */
.table-toolbar {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 12px 16px;
    margin-bottom: 16px;
    width: 100%;
    box-sizing: border-box;
}
.toolbar-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    width: 100%;
}
.search-input-wrap {
    position: relative;
    flex: 1 1 260px;
    max-width: 440px;
}
.search-input-wrap input {
    width: 100%;
    padding: 8px 10px 8px 32px;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    font-size: 13.5px;
    box-sizing: border-box;
}
.search-input-wrap .search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: 13px;
}
.source-filter-chips {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #f1f5f9;
    width: 100%;
}
.filter-chip {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid transparent;
    padding: 4px 10px;
    border-radius: 16px;
    font-size: 11.5px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}
.filter-chip:hover { background: #e2e8f0; color: #0f172a; }
.filter-chip.active {
    background: #1877f2;
    color: #fff;
    font-weight: 600;
}
.chip-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }

/* ==========================================================================
   TABELLA ORDINATA: ZERO OVERFLOW
   ========================================================================== */
.news-table-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.03);
    margin-bottom: 24px;
    width: 100%;
    box-sizing: border-box;
}
.clean-news-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    box-sizing: border-box;
}
.clean-news-table th {
    background: #f8fafc;
    color: #475569;
    font-size: 11.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 10px 12px;
    border-bottom: 1px solid #e2e8f0;
    text-align: left;
    box-sizing: border-box;
}
.clean-news-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
    font-size: 13.5px;
    box-sizing: border-box;
    word-break: break-word;
    overflow-wrap: break-word;
}
.clean-news-table tbody tr:last-child td { border-bottom: none; }
.clean-news-table tbody tr:hover td { background: #f8fafc; }

/* Colonna 1: Testata */
.source-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}
.source-tag .tag-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.source-time { font-size: 11px; color: #64748b; margin-top: 3px; display: block; white-space: nowrap; }

/* Colonna 2: Thumbnail */
.table-thumb-box {
    width: 58px;
    height: 42px;
    border-radius: 6px;
    overflow: hidden;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin: 0 auto;
}
.table-thumb-box img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.thumb-empty-icon { font-size: 18px; color: #94a3b8; }

/* Colonna 3: Titolo Modificabile */
.title-edit-wrap {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
    box-sizing: border-box;
}
.editable-title-input {
    width: 100%;
    max-width: 100%;
    font-size: 13.5px;
    font-weight: 600;
    color: #1e293b;
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 6px 9px;
    line-height: 1.35;
    resize: vertical;
    min-height: 40px;
    box-sizing: border-box;
    display: block;
    font-family: inherit;
}
.editable-title-input:focus {
    background: #fff;
    border-color: #1877f2;
    box-shadow: 0 0 0 2px rgba(24, 119, 242, 0.15);
    outline: none;
}
.title-sublinks {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11.5px;
    color: #64748b;
    flex-wrap: wrap;
}
.title-sublinks a { color: #1877f2; text-decoration: none; }
.title-sublinks a:hover { text-decoration: underline; }

/* Colonna 4: Pulsante Scegli per Banner */
.btn-choose-banner {
    background: linear-gradient(135deg, #1877f2 0%, #0d6efd 100%);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 7px 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    max-width: 140px;
    white-space: nowrap;
    box-sizing: border-box;
    box-shadow: 0 1px 3px rgba(24, 119, 242, 0.2);
}
.btn-choose-banner:hover {
    background: #1464cc;
    transform: translateY(-1px);
}

/* ==========================================================================
   STUDIO MODAL: RESPONSIVE & NO OVERFLOW
   ========================================================================== */
.studio-modal-overlay {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(6px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    overflow-y: auto;
}
.studio-modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}
.studio-card {
    background: #fff;
    border-radius: 12px;
    width: 100%;
    max-width: 860px;
    max-height: 90vh;
    display: grid;
    grid-template-columns: 320px 1fr;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
}
.studio-preview-pane {
    background: #0f172a;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-right: 1px solid #1e293b;
    box-sizing: border-box;
}
.studio-banner-frame {
    width: 100%;
    max-width: 250px;
    aspect-ratio: 4 / 5;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    background: #1e293b;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}
.studio-banner-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.studio-controls-pane {
    padding: 20px 24px;
    overflow-y: auto;
    max-height: 90vh;
    box-sizing: border-box;
}
.studio-close-btn {
    position: absolute;
    top: 10px;
    right: 12px;
    background: #f1f5f9;
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    z-index: 10;
}
.studio-close-btn:hover { background: #e2e8f0; color: #0f172a; }

.fb-publish-box {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px;
    margin-top: 14px;
    box-sizing: border-box;
}
.fb-publish-box h4 {
    margin: 0 0 8px 0;
    color: #1877f2;
    font-size: 13.5px;
}

/* Toast */
.sp-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #0f172a;
    color: #fff;
    padding: 10px 16px;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    font-size: 13px;
    z-index: 10000;
    transform: translateY(80px);
    opacity: 0;
    transition: all 0.25s ease;
}
.sp-toast.show { transform: translateY(0); opacity: 1; }
.sp-toast.success { border-left: 4px solid #10b981; }
.sp-toast.error { border-left: 4px solid #ef4444; }

/* Responsive Media Queries: strictly prevent overflow */
@media (max-width: 768px) {
    .container.wide { padding: 0 10px; margin: 12px auto; }
    .studio-card { grid-template-columns: 1fr; max-height: 94vh; overflow-y: auto; }
    .studio-preview-pane { padding: 14px; }
    .studio-banner-frame { max-width: 200px; }
    
    /* Responsive table on mobile */
    .clean-news-table th:nth-child(2), .clean-news-table td:nth-child(2) {
        display: none; /* Hide thumbnail on very small screens to give title full width */
    }
    .clean-news-table col:nth-child(2) { width: 0 !important; }
}

/* Language Switcher */
.lang-switcher a {
    color: #1877f2;
    text-decoration: none;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.15s ease;
}
.lang-switcher a:hover {
    background: #e2e8f0;
}
