/* Tokens: reference data-viz palette (light + dark selected separately). */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f3f2ee;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6d68;
  --axis: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-1-wash: rgba(42, 120, 214, 0.10);
  --band-run: rgba(42, 120, 214, 0.07);
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --info: #898781;
  --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5;
  --seq-5: #256abf; --seq-6: #184f95; --seq-7: #0d366b;
  --seq-0: #f0efec;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06), 0 4px 16px rgba(11, 11, 11, 0.06);
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface-1: #1a1a19; --surface-2: #232321;
    --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #a3a29b;
    --axis: #898781; --grid: #2c2c2a; --baseline: #383835; --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-1-wash: rgba(57, 135, 229, 0.14);
    --band-run: rgba(57, 135, 229, 0.10); --good-text: #0ca30c;
    --seq-1: #104281; --seq-2: #184f95; --seq-3: #1c5cab; --seq-4: #256abf;
    --seq-5: #3987e5; --seq-6: #6da7ec; --seq-7: #b7d3f6; --seq-0: #2c2c2a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface-1: #1a1a19; --surface-2: #232321;
  --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #a3a29b;
  --axis: #898781; --grid: #2c2c2a; --baseline: #383835; --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-1-wash: rgba(57, 135, 229, 0.14);
  --band-run: rgba(57, 135, 229, 0.10); --good-text: #0ca30c;
  --seq-1: #104281; --seq-2: #184f95; --seq-3: #1c5cab; --seq-4: #256abf;
  --seq-5: #3987e5; --seq-6: #6da7ec; --seq-7: #b7d3f6; --seq-0: #2c2c2a;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--text-primary); font-size: 15px; line-height: 1.5; }
a { color: var(--series-1); }
button { font: inherit; color: inherit; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px 64px; }

/* header */
header.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 0 8px; flex-wrap: wrap; }
.brand h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.brand p { margin: 2px 0 0; color: var(--text-secondary); font-size: 13px; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.btn { border: 1px solid var(--border); background: var(--surface-1); border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 13px; }
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .chip:focus-visible, .seg button:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

/* filter row */
.filters { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; padding: 12px 0 20px; position: sticky; top: 0; z-index: 5; background: var(--page); }
.filter { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); flex-wrap: wrap; min-width: 0; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-1); }
.seg button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; font-size: 13px; color: var(--text-secondary); }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--text-primary); font-weight: 600; }
.replay output { font-variant-numeric: tabular-nums; color: var(--text-primary); font-weight: 600; min-width: 132px; }
/* two-handle date slider: two stacked range inputs, only the thumbs take pointer events */
.dual { position: relative; width: 240px; height: 24px; }
.dual-track { position: absolute; left: 8px; right: 8px; top: 10px; height: 4px; border-radius: 2px; background: var(--border); }
.dual-fill { position: absolute; top: 0; bottom: 0; border-radius: 2px; background: var(--series-1); }
.dual input[type="range"] { position: absolute; inset: 0; width: 100%; height: 24px; margin: 0; background: none; pointer-events: none;
  -webkit-appearance: none; appearance: none; }
.dual input[type="range"]::-webkit-slider-runnable-track { background: transparent; height: 24px; }
.dual input[type="range"]::-moz-range-track { background: transparent; }
.dual input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; pointer-events: auto; width: 16px; height: 16px; margin-top: 4px;
  border-radius: 50%; background: var(--series-1); border: 2px solid var(--surface-1); box-shadow: 0 0 0 1px var(--series-1); cursor: pointer; }
.dual input[type="range"]::-moz-range-thumb { pointer-events: auto; width: 14px; height: 14px; border-radius: 50%; background: var(--series-1);
  border: 2px solid var(--surface-1); box-shadow: 0 0 0 1px var(--series-1); cursor: pointer; }
.dual input[type="range"]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--series-1); outline-offset: 2px; }
.dual input[type="range"]:disabled::-webkit-slider-thumb { cursor: default; opacity: 0.5; }

/* cards & grid */
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: 1.4fr 1fr; }
.g-2e { grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .g-2, .g-2e { grid-template-columns: 1fr; } }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { font-size: 16px; margin: 0 0 2px; font-weight: 650; }
.card .sub { font-size: 13px; color: var(--text-secondary); margin: 0 0 12px; }
section { margin-top: 28px; }
section > h2.section { font-size: 18px; margin: 0 0 12px; font-weight: 650; }

/* KPIs */
.kpis { display: grid; grid-template-columns: minmax(0, 1.7fr) repeat(5, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 600px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .kpis .hero { grid-column: 1 / -1; } }
@media (max-width: 1100px) and (min-width: 601px) { .kpis .hero { grid-column: span 1; } }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { font-size: 12.5px; color: var(--text-secondary); }
.tile .value { font-size: 26px; font-weight: 650; margin-top: 2px; letter-spacing: -0.01em; }
.tile .note { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.hero .value { font-size: 48px; line-height: 1.05; white-space: nowrap; }
.hero .value small { font-size: 18px; font-weight: 600; margin-left: 4px; color: var(--text-secondary); }
.tile .value { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hero { display: flex; flex-direction: column; justify-content: center; }

/* digest */
.digest .headline { font-size: 18px; font-weight: 650; margin: 6px 0 8px; }
.digest p { margin: 0 0 10px; color: var(--text-primary); }
.digest ul { margin: 0 0 10px 18px; padding: 0; }
.digest li { margin: 2px 0; }
.digest .tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.prov { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.prov .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--series-1); }
.actions-list { margin: 6px 0 0; padding: 0; list-style: none; }
.actions-list li { padding: 6px 0 6px 22px; position: relative; border-top: 1px solid var(--grid); }
.actions-list li::before { content: "→"; position: absolute; left: 2px; color: var(--text-muted); }

/* chips */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { border: 1px solid var(--border); background: var(--surface-1); border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 13px; color: var(--text-secondary); }
.chip[aria-pressed="true"] { background: var(--text-primary); color: var(--surface-1); border-color: var(--text-primary); }
.chip .n { font-variant-numeric: tabular-nums; opacity: 0.75; margin-left: 4px; }

/* insight cards */
.feed { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; }
@media (max-width: 420px) { .feed { grid-template-columns: 1fr; } }
.icard { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; box-shadow: var(--shadow); border-left-width: 4px; }
.icard h3 { font-size: 15.5px; margin: 0; font-weight: 650; }
.icard p { margin: 0; font-size: 14px; }
.icard .muted { color: var(--text-secondary); }
.icard .rec { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; font-size: 13.5px; }
.icard .rec b { font-weight: 600; }
.icard .save { font-size: 13.5px; }
.icard footer { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 4px; font-size: 12px; color: var(--text-muted); flex-wrap: wrap; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; }
.status svg { flex: none; }
.badge { font-size: 11px; border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; color: var(--text-muted); }
.empty { color: var(--text-muted); padding: 24px; text-align: center; }

/* charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--axis); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .axis line, .chart .baseline { stroke: var(--baseline); stroke-width: 1; }
.chart .ref { stroke: var(--text-muted); stroke-width: 1; }
.chart .ref-label { fill: var(--text-secondary); font-size: 11px; }
.chart .crosshair { stroke: var(--text-muted); stroke-width: 1; pointer-events: none; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .mark-hover:hover, .chart .mark-hover:focus { opacity: 0.8; outline: none; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-secondary); margin: 0 0 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; }
.legend i.line { width: 16px; height: 2px; border-radius: 2px; }
.legend i.rect { width: 10px; height: 10px; border-radius: 2px; }
.legend i.dot { width: 9px; height: 9px; border-radius: 50%; }
.scale { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); margin-top: 6px; }
.scale .steps { display: flex; }
.scale .steps i { width: 22px; height: 10px; display: block; }

#tooltip { position: fixed; pointer-events: none; z-index: 50; background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.16); max-width: 280px; display: none; }
#tooltip .t { color: var(--text-secondary); font-size: 12px; margin-bottom: 4px; }
#tooltip .row { display: flex; align-items: center; gap: 8px; }
#tooltip .row b { font-variant-numeric: tabular-nums; }
#tooltip .key { width: 12px; height: 2px; border-radius: 2px; display: inline-block; }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-weight: 600; color: var(--text-secondary); font-size: 12.5px; padding: 8px 10px; border-bottom: 1px solid var(--baseline); }
td { padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
details.tableview { margin-top: 8px; font-size: 13px; }
details.tableview summary { cursor: pointer; color: var(--text-secondary); }
details.tableview .scroll { max-height: 260px; overflow: auto; margin-top: 6px; }

/* drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.32); z-index: 40; display: none; }
.drawer { position: fixed; top: 0; right: 0; height: 100%; width: min(620px, 100%); background: var(--surface-1); z-index: 41; transform: translateX(100%); transition: transform 0.18s ease; overflow-y: auto; border-left: 1px solid var(--border); }
.drawer.open { transform: none; }
.drawer-backdrop.open { display: block; }
.drawer .inner { padding: 20px 22px 40px; }
.drawer h2 { margin: 6px 0 4px; font-size: 19px; }
.drawer h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-secondary); margin: 22px 0 8px; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 4px 12px; font-size: 13.5px; }
.kv dt { color: var(--text-secondary); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; word-break: break-word; }
.note-box { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.trust-list { margin: 0; padding-left: 18px; font-size: 13.5px; }
.trust-list li { margin: 3px 0; }
.footer-note { color: var(--text-muted); font-size: 12px; margin-top: 32px; }
@media (max-width: 600px) { .kv { grid-template-columns: 1fr; } .dual { width: 170px; } .hero .value { font-size: 36px; } }

#savings { overflow-x: auto; }
#savings table { min-width: 640px; }
