/* Radio Intelligence - base styles
   Branding-thema's leveren --brand-* en --surface-* variabelen.
   Analytics-kleuren zijn bewust ONGEKOOPPELD van branding (sectie 55).
   Geen Node-buildstap: volledig offline en licht (sectie 49). */

:root {
    /* Default = Ludo, overschreven door :root[data-theme=...] in branding/theme.css */
    --brand-primary: #E85A0C;
    --brand-primary-hover: #C94B08;
    --brand-dark: #3B2418;
    --brand-cream: #F1E4C4;
    --brand-cream-light: #FAF6EB;
    --background: #141210;
    --surface: #1D1A17;
    --surface-raised: #27221D;
    --text-primary: #F8F3E8;
    --text-secondary: #BEB3A3;
    --border: #3A332C;

    /* Semantische analytics-kleuren - NIET afleiden van branding */
    --positive: #22C55E;
    --negative: #EF4444;
    --warning: #F59E0B;
    --neutral: #94A3B8;
    --info: #38BDF8;

    --radius: 10px;
    --radius-sm: 6px;
    --sidebar-w: 232px;
    --header-h: 60px;
    --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
    font-family: var(--font);
    background: var(--background);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
}

a { color: var(--brand-primary); text-decoration: none; }
a:hover { color: var(--brand-primary-hover); }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 40;
}

.sidebar .brand {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    min-height: var(--header-h);
}

.sidebar .brand img.logo {
    height: 40px; width: auto; max-width: 150px;
    object-fit: contain;
}

.sidebar .brand .logo-fallback {
    font-weight: 700; font-size: 15px; color: var(--brand-cream);
    background: var(--brand-dark); padding: 6px 10px; border-radius: var(--radius-sm);
    letter-spacing: 0.5px;
}

.sidebar .brand .sub { font-size: 10px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 1px; }

.nav { flex: 1; overflow-y: auto; padding: 10px 8px; }

.nav-group { margin-bottom: 14px; }

.nav-group .g-label {
    font-size: 10px; text-transform: uppercase; letter-spacing: 1.2px;
    color: var(--text-secondary); padding: 6px 10px 4px;
}

.nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; border-radius: var(--radius-sm);
    color: var(--text-secondary); font-size: 13px;
    border-left: 2px solid transparent;
    transition: background 0.15s;
}

.nav a:hover { background: var(--surface-raised); color: var(--text-primary); }

.nav a.active {
    background: var(--surface-raised);
    color: var(--text-primary);
    border-left-color: var(--brand-primary);
    font-weight: 600;
}

.nav a .ico { width: 18px; text-align: center; opacity: 0.85; }

.sidebar .foot { padding: 10px 14px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-secondary); }

/* ---------- Main / header ---------- */
.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }

.header {
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 16px;
    padding: 0 20px;
    position: sticky; top: 0; z-index: 30;
}

.header .title { font-weight: 700; font-size: 16px; }
.header .title .h-sub { color: var(--text-secondary); font-weight: 400; font-size: 12px; margin-left: 8px; }

.header .spacer { flex: 1; }

.header .date { color: var(--text-secondary); font-size: 13px; }

.station-switch select {
    background: var(--surface-raised);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    padding: 5px 8px;
    font-size: 13px;
    cursor: pointer;
}
.station-switch select:hover { border-color: var(--brand-primary); }

.status-pill {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 12px; font-weight: 600;
    padding: 4px 10px; border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-raised);
}

.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--neutral); }
.status-pill.ok .dot { background: var(--positive); }
.status-pill.busy .dot { background: var(--warning); animation: pulse 1.2s infinite; }
.status-pill.down .dot { background: var(--negative); }

@keyframes pulse { 50% { opacity: 0.35; } }

.header .user-menu { position: relative; }
.header .user-btn {
    background: var(--surface-raised); border: 1px solid var(--border);
    color: var(--text-primary); padding: 6px 12px; border-radius: var(--radius-sm);
    cursor: pointer; font-size: 13px; display: flex; align-items: center; gap: 8px;
}
.header .user-btn:hover { border-color: var(--brand-primary); }

/* ---------- Content ---------- */
.content { padding: 22px; flex: 1; }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.page-head h1 { font-size: 20px; font-weight: 700; }
.page-head .crumbs { color: var(--text-secondary); font-size: 12px; margin-bottom: 2px; }

/* ---------- KPI cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }

.kpi {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 14px 16px;
}

.kpi .k-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-secondary); }
.kpi .k-value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .k-delta { font-size: 12px; margin-top: 3px; font-weight: 600; }
.kpi .k-delta.up { color: var(--positive); }
.kpi .k-delta.down { color: var(--negative); }
.kpi .k-delta.flat { color: var(--neutral); }

/* ---------- Cards & panels ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px; margin-bottom: 18px;
}

.card h3 { font-size: 14px; font-weight: 700; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card h3 .hint { font-size: 11px; color: var(--text-secondary); font-weight: 400; }

.chart-box { width: 100%; height: 320px; }
.chart-box.tall { height: 420px; }
.chart-box.small { height: 240px; }

.channel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.channel-card { background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.channel-card .ch-label { font-size: 13px; font-weight: 700; color: var(--text-primary); margin-bottom: 8px; }
.channel-card .ch-total { margin-top: 8px; font-size: 12px; color: var(--text-secondary); }
.channel-card .ch-empty { height: 200px; display: flex; align-items: center; justify-content: center; color: var(--text-secondary); font-size: 12px; }

/* ---------- Delta / analysis ---------- */
.delta { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.delta.pos { color: var(--positive); }
.delta.neg { color: var(--negative); }
.delta.flat { color: var(--text-secondary); }

.bar { height: 12px; background: var(--surface-raised); border-radius: 6px; overflow: hidden; min-width: 120px; }
.bar > div { height: 100%; background: var(--brand-primary); border-radius: 6px; }

.card-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 12px;
}
.card-head h3 { margin-bottom: 0; }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions .btn { white-space: nowrap; }

.mapping-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 8px 16px; margin-bottom: 14px;
}
.mapping-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.mapping-row select { padding: 5px 8px; font-size: 12px; }

p.ok { color: var(--positive); }
p.err { color: var(--negative); }
.text-right { text-align: right; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
    text-align: left; padding: 10px 12px; font-size: 11px; text-transform: uppercase;
    letter-spacing: 0.7px; color: var(--text-secondary); border-bottom: 1px solid var(--border);
    background: var(--surface-raised); position: sticky; top: 0; white-space: nowrap;
}
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--border); }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: var(--surface-raised); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .pos { color: var(--positive); }
table.data .neg { color: var(--negative); }

/* ---------- Badges ---------- */
.badge {
    display: inline-block; font-size: 11px; font-weight: 600;
    padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border);
}
.badge.pos { color: var(--positive); border-color: var(--positive); background: rgba(34,197,94,0.08); }
.badge.neg { color: var(--negative); border-color: var(--negative); background: rgba(239,68,68,0.08); }
.badge.neutral { color: var(--neutral); }
.badge.info { color: var(--info); border-color: var(--info); background: rgba(56,189,248,0.08); }
.badge.brand { color: var(--brand-primary); border-color: var(--brand-primary); background: rgba(232,90,12,0.08); }

/* ---------- Forms ---------- */
label.field { display: block; margin-bottom: 4px; font-size: 12px; color: var(--text-secondary); }
input, select, textarea {
    width: 100%; padding: 9px 12px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--surface-raised);
    color: var(--text-primary); font-size: 14px; font-family: var(--font);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-primary); outline-offset: 0; border-color: transparent; }
input.search { width: 240px; max-width: 100%; }
.form-row { margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }

.btn {
    display: inline-flex; align-items: center; gap: 8px; justify-content: center;
    background: var(--brand-primary); color: #fff; border: none;
    padding: 9px 16px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600;
    cursor: pointer; transition: background 0.15s;
}
.btn:hover { background: var(--brand-primary-hover); color: #fff; }
.btn.secondary { background: var(--surface-raised); color: var(--text-primary); border: 1px solid var(--border); }
.btn.secondary:hover { border-color: var(--brand-primary); }
.btn.danger { background: var(--negative); }
.btn.danger:hover { background: #DC2626; }
.btn.sm { padding: 5px 10px; font-size: 12px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; }
.login-brand {
    flex: 0 0 45%; background: var(--brand-dark);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 18px; padding: 40px; position: relative; overflow: hidden;
}
.login-brand::after {
    content: ""; position: absolute; inset: 0;
    background-image: repeating-linear-gradient(180deg, transparent 0 12px, rgba(241,228,196,0.05) 12px 13px);
    pointer-events: none;
}
.login-brand .logo { max-height: 130px; max-width: 80%; object-fit: contain; }
.login-brand h1 { color: var(--brand-cream); font-size: 22px; letter-spacing: 1px; text-transform: uppercase; }
.login-brand p { color: var(--brand-cream); opacity: 0.75; font-size: 13px; max-width: 320px; text-align: center; }
.login-form { flex: 1; display: flex; align-items: center; justify-content: center; padding: 40px; }
.login-box { width: 100%; max-width: 380px; }
.login-box h2 { font-size: 20px; margin-bottom: 4px; }
.login-box .sub { color: var(--text-secondary); margin-bottom: 22px; }
.login-box .error { background: rgba(239,68,68,0.12); color: var(--negative); border: 1px solid var(--negative); padding: 9px 12px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 13px; }

@media (max-width: 820px) {
    .login-wrap { flex-direction: column; }
    .login-brand { flex: none; padding: 30px 20px; }
    .login-brand .logo { max-height: 90px; }
}

/* ---------- Responsive sidebar ---------- */
.menu-toggle { display: none; align-items: center; justify-content: center; background: none; border: none; color: var(--text-primary); font-size: 20px; cursor: pointer; padding: 4px 8px; border-radius: var(--radius-sm); }
.menu-toggle:hover { background: var(--surface-raised); }
.nav-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 35; display: none; }

@media (max-width: 900px) {
    :root { --sidebar-w: 64px; }
    .sidebar .brand .sub, .nav a span, .sidebar .foot, .nav-group .g-label { display: none; }
    .sidebar .brand img.logo { max-height: 34px; }
    .header .date { display: none; }
    .content { padding: 14px; }
}

/* ---------- Mobiel (<= 768px): off-canvas sidebar, volle breedte + labels ---------- */
@media (max-width: 768px) {
    :root { --sidebar-w: 232px; }
    .menu-toggle { display: inline-flex; }
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 8px 0 30px rgba(0, 0, 0, 0.5);
    }
    .main { margin-left: 0; }
    body.nav-open .sidebar { transform: translateX(0); }
    body.nav-open .nav-backdrop { display: block; }

    /* tenzij op desktop <=900px: op mobiel de labels WEL tonen */
    .sidebar .brand .sub { display: block; }
    .sidebar .foot { display: block; }
    .nav-group .g-label { display: block; }
    .nav a span { display: inline; }
    .sidebar .brand img.logo { max-height: 40px; }

    .header { padding: 0 12px; gap: 10px; }
    .header .title { font-size: 14px; }
    .header .title .h-sub { display: none; }

    .content { padding: 12px; }
    .page-head { flex-direction: column; align-items: stretch; }
    .page-head h1 { font-size: 17px; }
    .page-head .flex { width: 100%; }
    .page-head form.flex { flex-wrap: wrap; }
    .page-head form.flex input, .page-head form.flex select {
        flex: 1 1 auto; min-width: 0; width: auto;
    }
    .page-head form.flex input[type="search"] { width: 100% !important; flex-basis: 100%; }

    .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
    .chart-box { height: 260px; }
    .chart-box.tall { height: 300px; }
    .channel-grid { grid-template-columns: 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
}

/* ---------- AI insight ---------- */
.ai-insight {
    background: linear-gradient(180deg, var(--surface-raised), var(--surface));
    border: 1px solid var(--border); border-left: 3px solid var(--brand-primary);
    border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px;
}
.ai-insight .ai-label { font-size: 10px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--brand-primary); font-weight: 700; margin-bottom: 6px; }
.ai-insight .ai-text { font-size: 14px; }
.ai-insight .ai-meta { margin-top: 8px; font-size: 12px; color: var(--text-secondary); display: flex; gap: 12px; flex-wrap: wrap; }

/* ---------- Misc ---------- */
.flex { display: flex; align-items: center; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; }
.muted { color: var(--text-secondary); font-size: 12px; }
.mt { margin-top: 14px; }
.alert {
    padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 14px;
    border: 1px solid var(--border); background: var(--surface-raised);
}
.alert.warn { border-color: var(--warning); color: var(--warning); background: rgba(245,158,11,0.08); }
.alert.error { border-color: var(--negative); color: var(--negative); background: rgba(239,68,68,0.08); }
.alert.ok { border-color: var(--positive); color: var(--positive); background: rgba(34,197,94,0.08); }

.drop-zone {
    border: 2px dashed var(--border); border-radius: var(--radius);
    padding: 40px; text-align: center; color: var(--text-secondary);
    transition: border-color 0.15s; cursor: pointer; margin-bottom: 16px;
}
.drop-zone.hover { border-color: var(--brand-primary); color: var(--brand-primary); }

.dropdown-menu {
    position: absolute; right: 0; top: 42px; min-width: 180px;
    background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius-sm);
    box-shadow: 0 10px 30px rgba(0,0,0,0.4); padding: 6px; z-index: 50; display: none;
}
.dropdown-menu.open { display: block; }
.dropdown-menu a, .dropdown-menu button {
    display: block; width: 100%; text-align: left; background: none; border: none; color: var(--text-primary);
    padding: 8px 12px; border-radius: var(--radius-sm); font-size: 13px; cursor: pointer;
}
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--surface); }

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--brand-primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-block; }

.hidden { display: none !important; }
