:root {
    color-scheme: light;
    --surface-0: #f4f4f2;
    --surface-1: #fcfcfb;
    --border: #e1e0dc;
    --text-primary: #0b0b0b;
    --text-secondary: #52514e;
    --text-muted: #7a7974;
    --grid: #ebeae6;
    --accent: #2a78d6;
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --series-3: #1baf7a;
    --reference: #8a8984;
    --band: rgba(138, 137, 132, 0.18);
    --error: #c62828;
    --radius: 8px;
}
@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme="light"])) {
        color-scheme: dark;
        --surface-0: #121211;
        --surface-1: #1a1a19;
        --border: #34332f;
        --text-primary: #f0efec;
        --text-secondary: #c3c2b7;
        --text-muted: #8f8e86;
        --grid: #2a2a27;
        --accent: #3987e5;
        --series-1: #3987e5;
        --series-2: #d95926;
        --series-3: #199e70;
        --reference: #a3a29a;
        --band: rgba(163, 162, 154, 0.18);
        --error: #ef6b6b;
    }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --surface-0: #121211; --surface-1: #1a1a19; --border: #34332f;
    --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8f8e86; --grid: #2a2a27;
    --accent: #3987e5; --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --reference: #a3a29a; --band: rgba(163, 162, 154, 0.18); --error: #ef6b6b;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--surface-0);
    color: var(--text-primary);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-size: 0.9em; background: var(--surface-1); padding: 1px 4px; border-radius: 4px; border: 1px solid var(--border); }
h1 { font-size: 1.4rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 0.5rem; }
.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }
.error { color: var(--error); }

.topbar {
    display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
    padding: 0.6rem 16px; background: var(--surface-1); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; color: var(--text-primary); letter-spacing: 0.02em; }
.topbar nav { display: flex; gap: 0.25rem; flex-wrap: wrap; flex: 1; }
.topbar nav a { padding: 0.3rem 0.7rem; border-radius: 6px; color: var(--text-secondary); }
.topbar nav a.active, .topbar nav a:hover { background: var(--surface-0); color: var(--text-primary); text-decoration: none; }
.logout { margin: 0; }
@media (max-width: 560px) {
    .topbar nav { order: 3; flex-basis: 100%; }
    .topbar .logout { margin-left: auto; }
}
main { max-width: 1280px; margin: 0 auto; padding: 1rem 16px 2rem; }
footer { text-align: center; color: var(--text-muted); font-size: 0.8rem; padding: 1rem 16px 2rem; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.controls { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin: 0.5rem 0; }
.controls label { display: flex; align-items: center; gap: 0.35rem; color: var(--text-secondary); font-size: 0.9rem; }
input, select, button {
    font: inherit; color: var(--text-primary); background: var(--surface-1);
    border: 1px solid var(--border); border-radius: 6px; padding: 0.3rem 0.5rem;
}
input[type="number"] { width: 6rem; }
input[type="checkbox"] { padding: 0; }
button { cursor: pointer; background: var(--accent); color: #fff; border-color: var(--accent); }
button.secondary { background: var(--surface-1); color: var(--text-primary); border-color: var(--border); }
button.link { background: none; border: none; color: var(--text-secondary); padding: 0.3rem; }
button:disabled { opacity: 0.6; cursor: wait; }

.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.tabs { display: flex; gap: 0.25rem; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin: 0.5rem 0 0.75rem; }
.tabs button { background: none; color: var(--text-secondary); border: none; border-bottom: 2px solid transparent; border-radius: 0; padding: 0.5rem 0.75rem; }
.tabs button.active { color: var(--text-primary); border-bottom-color: var(--accent); }

.chart { width: 100%; height: 320px; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 0.75rem; }
.chart.tall { height: 460px; }
.chart.small { height: 230px; }
.chart .empty { display: flex; height: 100%; align-items: center; justify-content: center; color: var(--text-muted); padding: 1rem; text-align: center; }

.panel { margin-bottom: 1.25rem; }
.panel h2 { display: flex; align-items: baseline; gap: 0.5rem; }
.panel h2 .muted { font-weight: normal; font-size: 0.85rem; }
.panel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 560px), 1fr)); gap: 0.75rem; }
.panel-grid .chart { margin: 0; }

.table-wrap { overflow-x: auto; margin-bottom: 0.75rem; }
table.data { border-collapse: collapse; width: 100%; background: var(--surface-1); font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 0.35rem 0.6rem; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.data th { color: var(--text-secondary); font-weight: 600; font-size: 0.85rem; position: sticky; top: 0; background: var(--surface-1); }
table.data.compact th, table.data.compact td { padding: 0.25rem 0.45rem; font-size: 0.85rem; }
table.data .num { text-align: right; }
table.data td.partial { font-style: italic; color: var(--text-muted); }
table.data tr.selected td { background: var(--band); font-weight: 600; }
details summary { cursor: pointer; color: var(--text-secondary); margin: 0.5rem 0; }

.stats { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.stat { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 0.9rem; min-width: 8rem; }
.stat .label { color: var(--text-muted); font-size: 0.8rem; }
.stat .value { font-size: 1.3rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.link-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 0.75rem; }
.link-grid ul { margin: 0; padding-left: 1.1rem; }
.link-grid li { margin: 0.2rem 0; }
.link-grid figure { margin: 0 0 0.75rem; }
.link-grid img { max-width: 100%; height: auto; border-radius: 4px; }

.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 0.75rem; }
.login h1 { font-size: 1.6rem; }
.login p { margin: 0; }
.login label { display: flex; flex-direction: column; gap: 0.3rem; color: var(--text-secondary); }
.toast { position: fixed; bottom: 1rem; right: 1rem; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 1rem; box-shadow: 0 4px 16px rgba(0,0,0,.15); max-width: calc(100% - 2rem); }
.toast.error { border-color: var(--error); }
