/* ============================================================
   SYNCHROTRON DASHBOARD — CSS v3
   Mobile-first, polished dark UI
   ============================================================ */

:root {
    --bg: #0b0d11;
    --bg-card: #14161c;
    --bg-hover: #1a1d25;
    --bg-input: #111318;
    --border: #23262f;
    --border-light: #2e323d;
    --text: #e8e9ed;
    --text-sec: #a1a3ab;
    --text-muted: #6b6e78;
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-glow: rgba(99,102,241,.12);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-w: 240px;
    --topbar-h: 56px;
    --shadow: 0 2px 12px rgba(0,0,0,.3);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
::selection { background: var(--primary); color: #fff; }

/* ============================================================
   LOGIN
   ============================================================ */
.screen { min-height: 100vh; min-height: 100dvh; }

#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse at 30% 20%, rgba(99,102,241,.08) 0%, transparent 50%),
        radial-gradient(ellipse at 70% 80%, rgba(139,92,246,.06) 0%, transparent 50%),
        var(--bg);
    padding: 16px;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px 32px;
    width: 100%;
    max-width: 380px;
    text-align: center;
    box-shadow: var(--shadow);
}

.login-logo svg { margin-bottom: 14px; filter: drop-shadow(0 0 20px rgba(99,102,241,.3)); }
.login-logo h1 { font-size: 1.4rem; font-weight: 700; letter-spacing: -.02em; }
.login-logo p { color: var(--text-muted); font-size: 0.8rem; margin: 4px 0 24px; }

#login-form input {
    width: 100%;
    padding: 11px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.88rem;
    margin-bottom: 10px;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}
#login-form input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.86rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all .15s;
    width: 100%;
    -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); }
.btn-primary:active { transform: scale(.98); }

.btn-google { background: #fff; color: #333; border: 1px solid #e0e0e0; }
.btn-google:hover { background: #f5f5f5; }

.btn-small { padding: 7px 14px; font-size: 0.78rem; width: auto; border-radius: 6px; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }

.divider { display: flex; align-items: center; margin: 16px 0; color: var(--text-muted); font-size: 0.76rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.divider span { padding: 0 12px; }

.error-msg { color: var(--danger); font-size: 0.76rem; margin-top: 10px; min-height: 18px; }

/* ============================================================
   DASHBOARD LAYOUT
   ============================================================ */
#dashboard-screen { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* ---- SIDEBAR ---- */
#sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 18px 16px;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: -.02em;
}
.sidebar-header svg { flex-shrink: 0; }

nav { flex: 1; padding: 4px 0; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 500;
    transition: all .12s;
    border-left: 3px solid transparent;
}
.nav-item:hover { color: var(--text-sec); background: var(--bg-hover); }
.nav-item.active { color: var(--primary-light); background: var(--primary-glow); border-left-color: var(--primary); }

.nav-icon { font-size: 0.85rem; width: 20px; text-align: center; opacity: .75; }

.sidebar-footer {
    padding: 12px 18px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
#user-info { display: flex; align-items: center; gap: 8px; overflow: hidden; }
#user-avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--border); object-fit: cover; }
#user-name { font-size: 0.74rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100px; }

/* ---- Menu toggle (hidden on desktop) ---- */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 6px;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
}

.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40; }

/* ---- MAIN ---- */
#main-content { flex: 1; overflow-y: auto; position: relative; min-width: 0; }

#topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: var(--topbar-h);
    background: rgba(11,13,17,.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
#topbar h2 { font-size: 1.05rem; font-weight: 600; letter-spacing: -.02em; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

#date-picker {
    padding: 5px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.78rem;
    outline: none;
}

.page { padding: 20px; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 14px;
}

.card h3 {
    font-size: 0.84rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-sec);
    letter-spacing: -.01em;
}

.card h4 {
    font-size: 0.8rem;
    color: var(--primary-light);
    margin: 14px 0 8px;
    font-weight: 600;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.card-header h3 { margin-bottom: 0; }

/* ============================================================
   STAT CARDS
   ============================================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 14px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 14px;
    position: relative;
    overflow: hidden;
}
.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    opacity: .5;
}

.stat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .6px;
    margin-bottom: 6px;
    font-weight: 600;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -.03em;
    line-height: 1.2;
}

/* ============================================================
   GRIDS
   ============================================================ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ============================================================
   BAR CHARTS
   ============================================================ */
.chart-area { min-height: 100px; }

.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; font-size: 0.76rem; }
.bar-label { min-width: 90px; text-align: right; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.74rem; }
.bar-track { flex: 1; height: 20px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width .5s cubic-bezier(.22,1,.36,1);
    display: flex;
    align-items: center;
    padding-left: 6px;
    font-size: 0.65rem;
    font-weight: 600;
    color: rgba(255,255,255,.85);
    white-space: nowrap;
}
.bar-value { min-width: 50px; text-align: right; font-weight: 600; font-size: 0.76rem; font-variant-numeric: tabular-nums; }

.bar-fill.c0 { background: linear-gradient(90deg, #6366f1, #818cf8); }
.bar-fill.c1 { background: linear-gradient(90deg, #8b5cf6, #a78bfa); }
.bar-fill.c2 { background: linear-gradient(90deg, #a855f7, #c084fc); }
.bar-fill.c3 { background: linear-gradient(90deg, #ec4899, #f472b6); }
.bar-fill.c4 { background: linear-gradient(90deg, #f43f5e, #fb7185); }
.bar-fill.c5 { background: linear-gradient(90deg, #f97316, #fb923c); }
.bar-fill.c6 { background: linear-gradient(90deg, #eab308, #facc15); }
.bar-fill.c7 { background: linear-gradient(90deg, #10b981, #34d399); }
.bar-fill.c8 { background: linear-gradient(90deg, #14b8a6, #2dd4bf); }
.bar-fill.c9 { background: linear-gradient(90deg, #3b82f6, #60a5fa); }

/* ============================================================
   TABLES
   ============================================================ */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
th { text-align: left; padding: 8px 8px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; font-size: 0.65rem; letter-spacing: .5px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--border); color: var(--text-sec); }
tr:hover td { background: var(--bg-hover); }

/* ============================================================
   TIMELINE
   ============================================================ */
.timeline-container { max-height: 600px; overflow-y: auto; }
.tl-event { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 0.8rem; align-items: center; }
.tl-time { min-width: 80px; font-family: 'SF Mono', monospace; color: var(--text-muted); font-size: 0.72rem; }
.tl-badge { padding: 2px 7px; border-radius: 4px; font-size: 0.65rem; font-weight: 600; text-transform: uppercase; min-width: 52px; text-align: center; }
.tl-badge.program { background: rgba(99,102,241,.12); color: #818cf8; }
.tl-badge.tg { background: rgba(59,130,246,.12); color: #60a5fa; }
.tl-badge.spot { background: rgba(239,68,68,.12); color: #f87171; }
.tl-badge.promo { background: rgba(245,158,11,.12); color: #fbbf24; }
.tl-badge.bumper { background: rgba(168,85,247,.12); color: #c084fc; }
.tl-badge.sigla { background: rgba(16,185,129,.12); color: #34d399; }
.tl-badge.other { background: rgba(107,110,120,.12); color: #6b6e78; }
.tl-info { flex: 1; min-width: 0; }
.tl-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-meta { color: var(--text-muted); font-size: 0.7rem; margin-top: 1px; }
.tl-duration { min-width: 55px; text-align: right; color: var(--text-muted); font-family: monospace; font-size: 0.72rem; }

/* ============================================================
   FORMS
   ============================================================ */
.input-inline, select {
    padding: 7px 11px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.8rem;
    outline: none;
    transition: border-color .2s;
}
.input-inline:focus, select:focus { border-color: var(--primary); }
select { cursor: pointer; }
optgroup { color: var(--primary-light); font-weight: 600; font-style: normal; }
option { color: var(--text); background: var(--bg-card); }

textarea {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 10px;
    font-family: 'SF Mono', monospace;
    font-size: 0.72rem;
    resize: vertical;
    outline: none;
}
textarea:focus { border-color: var(--primary); }

/* ============================================================
   CHANNEL LOGOS (inline emoji placeholders)
   ============================================================ */
.ch-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    letter-spacing: -.02em;
}
.ch-logo.mediaset { background: linear-gradient(135deg, #0066cc, #0099ff); }
.ch-logo.rai { background: linear-gradient(135deg, #003399, #0055cc); }
.ch-logo.sky { background: linear-gradient(135deg, #1a1a2e, #333366); }

/* ============================================================
   LOADING + EMPTY
   ============================================================ */
.loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(11,13,17,.6); z-index: 100; backdrop-filter: blur(4px); }
.spinner { width: 30px; height: 30px; border: 2.5px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 36px 16px; color: var(--text-muted); font-size: 0.84rem; }

/* ============================================================
   SETTINGS
   ============================================================ */
.settings-status .bar-row { padding: 4px 0; }
.settings-status .bar-label { min-width: 120px; font-size: 0.76rem; }
.settings-status .bar-value { text-align: left; font-size: 0.76rem; }

/* ============================================================
   CAPTURE CONTROLS
   ============================================================ */
.capture-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ============================================================
   RESPONSIVE — TABLET (<=1024)
   ============================================================ */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
}

/* ============================================================
   RESPONSIVE — MOBILE (<=768)
   ============================================================ */
@media (max-width: 768px) {
    .menu-toggle { display: block; }

    /* Sidebar: off-screen by default, slides in */
    #sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: var(--sidebar-w);
        z-index: 50;
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: none;
    }
    #sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,.5);
    }

    .sidebar-overlay.open { display: block; }

    /* Main takes full width */
    #main-content { width: 100%; }

    #topbar { padding: 0 14px; }
    #topbar h2 { font-size: 0.95rem; }

    .page { padding: 14px; }

    .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card { padding: 12px 10px; }
    .stat-value { font-size: 1.2rem; }

    .card { padding: 14px; border-radius: var(--radius-sm); }

    .capture-controls {
        flex-direction: column;
        align-items: stretch;
    }
    .capture-controls select,
    .capture-controls input,
    .capture-controls .btn { width: 100%; }

    .card-header { flex-direction: column; align-items: stretch; gap: 8px; }

    .tl-event { flex-wrap: wrap; gap: 6px; padding: 8px 0; }
    .tl-time { min-width: auto; font-size: 0.68rem; order: 1; }
    .tl-badge { order: 2; }
    .tl-info { order: 4; flex-basis: 100%; }
    .tl-duration { order: 3; min-width: auto; }

    .bar-label { min-width: 65px; font-size: 0.68rem; }
    .bar-value { min-width: 40px; font-size: 0.7rem; }
    .bar-track { height: 18px; }

    table { font-size: 0.7rem; }
    th, td { padding: 6px 5px; }

    .login-card { padding: 28px 20px; }
}

@media (max-width: 400px) {
    .stats-grid { grid-template-columns: 1fr; gap: 6px; }
    .stat-card {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px 12px;
    }
    .stat-label { margin-bottom: 0; }
    .stat-value { font-size: 1rem; }

    .topbar-right { gap: 4px; }
    #date-picker { font-size: 0.72rem; padding: 4px 6px; }
    .btn-small { font-size: 0.72rem; padding: 5px 10px; }
}
