:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-1-soft: #86b6ef;
  --compare: #898781;
  --good: #006300;
  --bad: #d03b3b;
  --hover: rgba(11, 11, 11, 0.04);
  --tooltip-bg: #0b0b0b;
  --tooltip-text: #f0efec;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-1-soft: #1c5cab;
    --compare: #898781;
    --good: #0ca30c;
    --bad: #e66767;
    --hover: rgba(255, 255, 255, 0.05);
    --tooltip-bg: #f0efec;
    --tooltip-text: #0b0b0b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-1-soft: #1c5cab;
  --compare: #898781;
  --good: #0ca30c;
  --bad: #e66767;
  --hover: rgba(255, 255, 255, 0.05);
  --tooltip-bg: #f0efec;
  --tooltip-text: #0b0b0b;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  padding: 24px clamp(16px, 3vw, 40px) 48px;
  max-width: 1440px;
  margin-inline: auto;
}
h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 14px; margin: 0; font-weight: 600; }
.sub { margin: 2px 0 0; color: var(--text-2); font-size: 13px; }

.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }

button, select, input { font: inherit; color: inherit; }
.ghost {
  background: transparent; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; color: var(--text-2);
}
.ghost:hover { background: var(--hover); color: var(--text); }

.filters {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  position: sticky; top: 0; z-index: 10; background: var(--page);
  padding: 8px 0 12px; border-bottom: 1px solid var(--border);
}
.field { display: flex; flex-direction: column; gap: 4px; min-width: 130px; }
.field.wide { flex: 1 1 240px; max-width: 360px; }
.flabel { font-size: 12px; color: var(--text-2); }
.filters select {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; min-height: 36px; color: var(--text);
}
.filters select:disabled { opacity: 0.5; }

/* Multi-select picker */
.ms { position: relative; }
.ms-btn {
  width: 100%; min-height: 36px; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px;
  cursor: pointer; text-align: left;
}
.ms-btn:hover { border-color: var(--axis); }
.ms-btn.active { border-color: var(--series-1); box-shadow: inset 0 0 0 1px var(--series-1); }
.ms-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-caret { color: var(--muted); font-size: 11px; }
.ms-panel {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; width: max(100%, 280px); max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.16); padding: 8px; display: flex; flex-direction: column; gap: 6px;
}
.ms-panel[hidden] { display: none; }
.ms-search { width: 100%; background: var(--page); border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; }
.ms-presets, .ms-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.ms-presets button, .ms-actions button {
  border: 1px solid var(--border); background: transparent; border-radius: 999px; padding: 3px 10px;
  font-size: 12px; cursor: pointer; color: var(--text-2);
}
.ms-presets button:hover, .ms-actions button:hover { background: var(--hover); color: var(--text); }
.ms-actions button { border: 0; padding: 3px 6px; color: var(--series-1); }
.ms-list { max-height: 300px; overflow-y: auto; margin: 0 -4px; }
.ms-opt { display: flex; align-items: flex-start; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.ms-opt:hover { background: var(--hover); }
.ms-opt input { margin: 2px 0 0; accent-color: var(--series-1); width: 16px; height: 16px; flex: none; }
.ms-label { display: flex; flex-direction: column; min-width: 0; }
.ms-label small { color: var(--muted); font-size: 11px; }
.ms-empty { color: var(--muted); font-size: 12px; margin: 6px 8px; }
.ms-foot { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--grid); padding-top: 6px; font-size: 12px; color: var(--text-2); }
.ms-done { background: var(--series-1); color: #fff; border: 0; border-radius: 6px; padding: 5px 14px; cursor: pointer; }

/* Active-filter chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin: 12px 0 16px; font-size: 13px; min-height: 28px; }
.chip-group { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.chip-dim { color: var(--text-2); margin-right: 2px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 3px 8px 3px 10px; cursor: pointer; color: var(--text); max-width: 280px;
}
.chip span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .x { color: var(--muted); font-size: 10px; }
.chip:hover { background: var(--hover); }
.chip:hover .x { color: var(--text); }
.chip-clear { border: 0; background: none; color: var(--series-1); cursor: pointer; padding: 3px 4px; }
.chip-none { color: var(--muted); }

main.loading { opacity: 0.5; }
main { transition: opacity 120ms; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.kpi .label { color: var(--text-2); font-size: 12px; }
.kpi .value { font-size: 26px; font-weight: 650; margin-top: 2px; letter-spacing: -0.01em; }
.kpi .delta { font-size: 12px; margin-top: 4px; color: var(--text-2); }
.kpi .delta .up { color: var(--good); font-weight: 600; }
.kpi .delta .down { color: var(--bad); font-weight: 600; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.span2 { grid-column: span 2; }
@media (max-width: 860px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .span2 { grid-column: auto; }
}
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; min-width: 0; }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }

.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 12px; height: 10px; border-radius: 2px; background: var(--series-1); }
.legend i.line { height: 2px; border-radius: 1px; background: var(--compare); }

.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .cat { fill: var(--text-2); font-size: 12px; }
.chart .val { fill: var(--text-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--series-1); }
.chart .bar.dim { fill: var(--series-1-soft); }
.chart .bar.partial { fill: url(#hatch); }
.chart .cmp { stroke: var(--compare); stroke-width: 2; fill: none; }
.chart .cmp-dot { fill: var(--compare); stroke: var(--surface); stroke-width: 2; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover, .chart .hit:focus { fill: var(--hover); outline: none; }
.chart .empty { fill: var(--muted); font-size: 13px; }

.tooltip {
  position: fixed; z-index: 20; pointer-events: none; max-width: 280px;
  background: var(--tooltip-bg); color: var(--tooltip-text); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}
.tooltip .t-title { opacity: 0.75; margin-bottom: 4px; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 16px; }
.tooltip .t-row b { font-variant-numeric: tabular-nums; }
.tooltip .t-key { display: inline-block; width: 10px; height: 2px; margin-right: 6px; vertical-align: middle; }

.table-tools { display: flex; gap: 8px; }
.table-tools input { background: var(--page); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; min-width: 180px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--text-2); font-weight: 600; font-size: 12px; cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--surface); }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
th::after { content: " ↕"; color: var(--muted); opacity: 0.6; }
th.pick::after { content: ""; }
th:hover { color: var(--text); }
th[aria-sort]::after { opacity: 1; color: var(--series-1); }
th[aria-sort="descending"]::after { content: " ↓"; }
th[aria-sort="ascending"]::after { content: " ↑"; }
th[aria-sort] { color: var(--text); }
.table-tools { flex-wrap: wrap; align-items: center; }
.sort-by { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.sort-by select { background: var(--page); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; color: var(--text); }
#sortDir { min-width: 104px; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--hover); }
td.site { max-width: 320px; overflow: hidden; text-overflow: ellipsis; color: var(--text); font-weight: 500; }
td .up { color: var(--good); }
td .down { color: var(--bad); }
td.muted { color: var(--muted); }
.more { margin-top: 10px; }

.defs { color: var(--muted); font-size: 12px; margin-top: 16px; line-height: 1.6; }
.defs b { color: var(--text-2); font-weight: 600; }

@media (max-width: 700px) {
  .filters { position: static; }
  .field, .field.wide { flex: 1 1 140px; min-width: 0; max-width: none; }
  .kpi .value { font-size: 22px; }
}

th.pick, td.pick { width: 32px; text-align: center; }
td.pick input { accent-color: var(--series-1); width: 16px; height: 16px; cursor: pointer; }
tbody tr.picked { background: var(--hover); }
tbody tr.picked td.site { color: var(--series-1); }

.kpi .label {
  display: inline-flex; align-items: center; gap: 6px; background: none; border: 0; padding: 0;
  color: var(--text-2); font-size: 12px; cursor: help; text-align: left;
}
.kpi .label .info {
  display: inline-grid; place-items: center; width: 14px; height: 14px; border-radius: 50%;
  border: 1px solid var(--muted); color: var(--muted); font-size: 9px; font-weight: 700; font-style: italic;
}
.kpi .label:hover, .kpi .label:focus-visible { color: var(--text); }
.kpi .label:hover .info, .kpi .label:focus-visible .info { border-color: var(--text); color: var(--text); }
.tooltip .t-text { margin: 0; line-height: 1.45; }
.tooltip { max-width: 300px; }
.kpi .value small { font-size: 13px; font-weight: 600; color: var(--text-2); margin-left: 6px; letter-spacing: 0; white-space: nowrap; }

.summary { font-size: 15px; line-height: 1.6; color: var(--text-2); max-width: 980px; margin: 0 0 6px; }
.basis { font-size: 12px; color: var(--muted); margin: 0 0 16px; }
.summary strong { color: var(--text); font-weight: 600; }

.link { background: none; border: 0; padding: 0; color: var(--series-1); cursor: pointer; font-size: 12px; text-decoration: underline; text-underline-offset: 2px; }
.tax-note { margin: -6px 0 16px; font-size: 13px; color: var(--text-2); }
.tax-note p { margin: 0 0 10px; max-width: 980px; line-height: 1.55; }
.tax-note p:last-child { margin: 10px 0 0; }
.tax-note th { cursor: default; position: static; }
.tax-note th::after { content: none; }
.tax-note tbody tr { cursor: default; }

/* Forecast */
.chart .bar.fc { fill: var(--series-1-soft); fill-opacity: 0.45; stroke: var(--series-1); stroke-width: 1; stroke-dasharray: 3 2; }
.chart .bar.fc.dim { fill-opacity: 0.2; stroke-opacity: 0.5; }
.chart .rng { stroke: var(--text-2); stroke-width: 1.5; }
.legend i.fc { background: transparent; border: 1px dashed var(--series-1); box-shadow: inset 0 0 0 10px color-mix(in srgb, var(--series-1-soft) 45%, transparent); }
.legend i.rng { width: 2px; height: 12px; border-radius: 0; background: var(--text-2); }
.kpis.outlook .kpi { border-style: dashed; }
.kpi .foot { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stretch { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-2); margin-top: 4px; }
.stretch input { width: 52px; background: var(--page); border: 1px solid var(--border); border-radius: 6px; padding: 3px 6px; color: var(--text); }
th.fccol, td.fccol { background: color-mix(in srgb, var(--series-1-soft) 12%, transparent); }
