/* Jivuu Analytics — dashboard styles (no build step required). */

:root {
    color-scheme: light;
    --page: #f9f9f7;
    --surface: #fcfcfb;
    --surface-2: #f3f2ee;
    --surface-hover: #efeee9;
    --border: rgba(11, 11, 11, 0.10);
    --border-strong: rgba(11, 11, 11, 0.18);
    --text: #0b0b0b;
    --text-2: #52514e;
    --muted: #898781;
    --grid: #e1e0d9;
    --axis: #c3c2b7;
    --accent: #2a78d6;
    --accent-soft: rgba(42, 120, 214, 0.10);
    --good: #006300;
    --bad: #b42323;
    --warn-bg: #fff6e0;
    --warn-text: #7a4d00;
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --series-3: #1baf7a;
    --series-4: #eda100;
    --series-5: #e87ba4;
    --series-6: #008300;
    --series-7: #6250d6;
    --series-8: #e34948;
    --seq-0: #f0efec;
    --seq-1: #cde2fb;
    --seq-2: #9ec5f4;
    --seq-3: #6da7ec;
    --seq-4: #3987e5;
    --seq-5: #256abf;
    --seq-6: #184f95;
    --shadow: 0 1px 2px rgba(11, 11, 11, 0.04);
    --radius: 10px;
    --sidebar: 232px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme="light"])) {
        color-scheme: dark;
        --page: #0d0d0d;
        --surface: #1a1a19;
        --surface-2: #222220;
        --surface-hover: #2a2a28;
        --border: rgba(255, 255, 255, 0.10);
        --border-strong: rgba(255, 255, 255, 0.18);
        --text: #f0efec;
        --text-2: #c3c2b7;
        --muted: #898781;
        --grid: #2c2c2a;
        --axis: #383835;
        --accent: #3987e5;
        --accent-soft: rgba(57, 135, 229, 0.16);
        --good: #0ca30c;
        --bad: #e66767;
        --warn-bg: #2e2412;
        --warn-text: #f3c56b;
        --series-1: #3987e5;
        --series-2: #d95926;
        --series-3: #199e70;
        --series-4: #c98500;
        --series-5: #d55181;
        --series-6: #008300;
        --series-7: #9085e9;
        --series-8: #e66767;
        --seq-0: #222220;
        --seq-1: #104281;
        --seq-2: #184f95;
        --seq-3: #1c5cab;
        --seq-4: #2a78d6;
        --seq-5: #5598e7;
        --seq-6: #86b6ef;
        --shadow: none;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #222220;
    --surface-hover: #2a2a28;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --accent: #3987e5;
    --accent-soft: rgba(57, 135, 229, 0.16);
    --good: #0ca30c;
    --bad: #e66767;
    --warn-bg: #2e2412;
    --warn-text: #f3c56b;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --seq-0: #222220;
    --seq-1: #104281;
    --seq-2: #184f95;
    --seq-3: #1c5cab;
    --seq-4: #2a78d6;
    --seq-5: #5598e7;
    --seq-6: #86b6ef;
    --shadow: none;
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; }

body {
    background: var(--page);
    color: var(--text);
    font: 14px/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select { font: inherit; color: inherit; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---------- Shell ---------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar);
    flex: 0 0 var(--sidebar);
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 24px;
    z-index: 30;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; font-weight: 650; font-size: 15px; }
.brand-mark {
    width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #fff;
    display: grid; place-items: center; font-size: 14px; font-weight: 700;
}
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 10px 6px; }
.nav a {
    display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
    color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-hover); text-decoration: none; color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }

.sidebar-foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 0 8px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex; align-items: center; gap: 12px; padding: 14px 28px;
    border-bottom: 1px solid var(--border); background: var(--surface);
    position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 650; }
.topbar .range-label { color: var(--muted); font-size: 13px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.menu-toggle { display: none; }

.content { padding: 20px 28px 48px; display: flex; flex-direction: column; gap: 20px; max-width: 1600px; width: 100%; }

/* ---------- Buttons & inputs ---------- */

.btn {
    display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px;
    border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface);
    color: var(--text); cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-hover); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-icon { width: 34px; padding: 0; justify-content: center; }
.btn svg { width: 16px; height: 16px; }
.btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 12px; color: var(--text-2); font-weight: 500; }
.input, .select {
    height: 34px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface);
    padding: 0 10px; min-width: 0; width: 100%;
}
.select { padding-right: 28px; }
.input:focus, .select:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Filter bar ---------- */

.filters {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow);
}
.filters-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filters-row .field { width: 170px; }
.filters-row .field.wide { width: 220px; }
.filters-row .field.narrow { width: 140px; }
.filters-more { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.filters-more[hidden] { display: none; }
.filters-actions { margin-left: auto; display: flex; gap: 8px; }
.filter-count {
    display: inline-grid; place-items: center; min-width: 18px; height: 18px; border-radius: 9px;
    background: var(--accent); color: #fff; font-size: 11px; padding: 0 5px;
}
.filter-count:empty { display: none; }

/* ---------- Notices ---------- */

.notice {
    display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: 8px;
    background: var(--warn-bg); color: var(--warn-text); font-size: 13px;
}
.notice svg { width: 16px; height: 16px; flex: none; margin-top: 2px; }
.notice-error { background: rgba(208, 59, 59, 0.10); color: var(--bad); }

/* ---------- Grid & cards ---------- */

.grid { display: grid; gap: 16px; }
.grid-kpi { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }

.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); min-width: 0;
}
.card-head {
    display: flex; align-items: flex-start; gap: 8px; padding: 14px 16px 0;
}
.card-head h2 { font-size: 14px; font-weight: 600; margin: 0; }
.card-head p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.card-head .btn { margin-left: auto; height: 28px; font-size: 12px; padding: 0 8px; }
.card-body { padding: 12px 16px 16px; position: relative; }

.section-title { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 8px 0 -4px; text-transform: uppercase; letter-spacing: .05em; }

/* ---------- KPI tiles ---------- */

.kpi { padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; position: relative; }
.kpi-label { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.kpi-info {
    width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--border-strong);
    font-size: 10px; display: inline-grid; place-items: center; color: var(--muted); cursor: help;
    background: none; padding: 0;
}
.kpi-value { font-size: 26px; font-weight: 650; letter-spacing: -0.01em; line-height: 1.2; }
.kpi-meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.delta { font-weight: 600; display: inline-flex; align-items: center; gap: 2px; }
.delta.good { color: var(--good); }
.delta.bad { color: var(--bad); }
.delta.flat { color: var(--muted); }
.kpi-definition {
    display: none; position: absolute; left: 12px; right: 12px; top: 100%; margin-top: 4px; z-index: 10;
    background: var(--text); color: var(--page); border-radius: 8px; padding: 8px 10px; font-size: 12px; line-height: 1.4;
}
.kpi:hover .kpi-definition, .kpi:focus-within .kpi-definition { display: block; }

/* ---------- Charts ---------- */

.chart-box { position: relative; height: var(--chart-h, 280px); }
.chart-box canvas { display: block; cursor: default; }
.chart-box.clickable canvas { cursor: pointer; }
.chart-note { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.chart-table { max-height: var(--chart-h, 280px); overflow: auto; }
.chart-table[hidden], .chart-box[hidden] { display: none; }

.state {
    position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
    color: var(--muted); font-size: 13px; padding: 16px; background: var(--surface);
}
.state[hidden] { display: none; }
.state strong { display: block; color: var(--text-2); font-weight: 600; margin-bottom: 2px; }

.skeleton {
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-hover) 50%, var(--surface-2) 75%);
    background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 6px;
}
.skeleton-line { height: 12px; margin: 6px 0; }
.skeleton-value { height: 30px; width: 60%; margin: 4px 0; }
.is-loading .chart-box canvas { opacity: .35; transition: opacity .2s; }

@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th { font-weight: 600; color: var(--text-2); font-size: 12px; background: var(--surface-2); position: sticky; top: 0; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: var(--surface-hover); }
table.data th button { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
table.data th button:focus-visible { outline: 2px solid var(--accent); }
table.data th[aria-sort="ascending"] button::after { content: "▲"; font-size: 9px; }
table.data th[aria-sort="descending"] button::after { content: "▼"; font-size: 9px; }
table.data .truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--text-2); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.badge.s-2 { color: var(--good); }
.badge.s-1 { color: var(--warn-text); }
.badge.s-3 { color: var(--accent); }
.badge.s-0 { color: var(--muted); }

/* ---------- Heatmap ---------- */

.heatmap { display: grid; grid-template-columns: 36px repeat(24, minmax(10px, 1fr)); gap: 2px; font-size: 11px; color: var(--muted); }
.heatmap .cell { aspect-ratio: 1.4; border-radius: 3px; background: var(--seq-0); position: relative; }
.heatmap .cell:hover { outline: 2px solid var(--text); outline-offset: 0; z-index: 1; }
.heatmap .row-label { align-self: center; }
.heatmap .col-label { text-align: center; }
.heat-legend { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 10px; }
.heat-legend span { width: 18px; height: 10px; border-radius: 2px; display: inline-block; }

/* ---------- Anomalies ---------- */

.anomaly-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.anomaly-list li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.anomaly-list li:last-child { border-bottom: 0; }
.anomaly-list .tag { font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 4px; }
.anomaly-list .spike { background: rgba(236, 131, 90, .16); color: var(--text); }
.anomaly-list .drop { background: var(--accent-soft); color: var(--text); }
.anomaly-list .num { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--text-2); }

/* ---------- Pagination ---------- */

.pager { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 13px; color: var(--text-2); flex-wrap: wrap; }
.pager .spacer { margin-left: auto; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.toolbar .search { flex: 1 1 220px; max-width: 360px; }

/* ---------- Report cards ---------- */

.report-card { padding: 18px; display: flex; flex-direction: column; gap: 6px; }
.report-card h2 { margin: 0; font-size: 16px; }
.report-card p { margin: 0; color: var(--text-2); font-size: 13px; flex: 1; }
.report-card .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

/* ---------- Detail header ---------- */

.detail-head { padding: 16px; display: flex; flex-wrap: wrap; gap: 16px 32px; align-items: center; }
.detail-head h2 { margin: 0; font-size: 20px; }
.detail-head dl { display: flex; flex-wrap: wrap; gap: 6px 24px; margin: 0; }
.detail-head dt { font-size: 12px; color: var(--muted); }
.detail-head dd { margin: 0; font-weight: 500; }

/* ---------- Login ---------- */

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.login h1 { margin: 0; font-size: 20px; }
.login p { margin: 0; color: var(--text-2); }
.error { color: var(--bad); font-size: 13px; }

/* ---------- Responsive ---------- */

@media (max-width: 1200px) {
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 960px) {
    .sidebar { position: fixed; left: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.2); }
    .shell.nav-open .sidebar { transform: none; }
    .menu-toggle { display: inline-flex; }
    .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
    .span-2 { grid-column: auto; }
    .topbar, .content { padding-left: 16px; padding-right: 16px; }
}

@media (max-width: 600px) {
    .filters-row .field, .filters-row .field.wide, .filters-row .field.narrow { width: calc(50% - 6px); }
    .filters-actions { margin-left: 0; width: 100%; }
    .filters-actions .btn { flex: 1; justify-content: center; }
    .grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .kpi-value { font-size: 21px; }
    .topbar .range-label { display: none; }
    .heatmap { grid-template-columns: 30px repeat(24, minmax(6px, 1fr)); font-size: 9px; }
}

/* ---------- Print ---------- */

@media print {
    .sidebar, .topbar-actions, .filters, .menu-toggle, .card-head .btn { display: none !important; }
    body { background: #fff; }
    .card { box-shadow: none; break-inside: avoid; }
}
