/* Colors follow the dataviz reference palette (light + selected dark steps). */
.viz-root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.04);
  --good-text: #006300;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --mark: #fde7a8;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.05);
    --good-text: #0ca30c;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --mark: #5a4a12;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 600; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
.sub { margin: 2px 0 0; color: var(--text-secondary); font-size: 13px; }
.muted { color: var(--text-muted); font-size: 13px; }
main { max-width: 1280px; margin: 0 auto; padding: 16px 20px 60px; }

.topbar {
  display: flex; align-items: baseline; gap: 16px; padding: 12px 20px;
  border-bottom: 1px solid var(--border); background: var(--surface-1);
}
.brand { font-weight: 600; color: var(--text-primary); font-size: 15px; }

.filters { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; margin-bottom: 14px; }
.filters.inline { margin: 0; }
.filters label { display: flex; gap: 6px; align-items: center; color: var(--text-secondary); font-size: 13px; }
select, input[type="search"] {
  font: inherit; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--axis); border-radius: 6px; padding: 5px 8px;
}
input[type="search"] { width: 220px; }

.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px; margin-bottom: 16px;
}
.card-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 8px; }
.chart { width: 100%; }

button.ghost {
  font: inherit; font-size: 13px; color: var(--text-secondary); background: transparent;
  border: 1px solid var(--axis); border-radius: 6px; padding: 4px 10px; cursor: pointer; white-space: nowrap;
}
button.ghost:hover { background: var(--wash); }
button.ghost[aria-pressed="true"] { color: var(--text-primary); border-color: var(--text-secondary); font-weight: 600; }
.seg { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.sep { width: 8px; }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.tile .label { color: var(--text-secondary); font-size: 13px; }
.tile .value { font-size: 24px; font-weight: 600; margin-top: 2px; }
.tile .delta { color: var(--text-muted); font-size: 12px; }

.table-wrap { overflow: auto; max-height: 640px; }
.table-wrap.tall { max-height: 520px; }
table.grid { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.grid th, table.grid td { padding: 6px 8px; border-bottom: 1px solid var(--grid); text-align: left; white-space: nowrap; }
table.grid th {
  position: sticky; top: 0; background: var(--surface-1); color: var(--text-secondary);
  font-weight: 600; font-size: 12px; cursor: pointer; user-select: none;
}
table.grid th.sorted::after { content: " ↓"; }
table.grid th.sorted.asc::after { content: " ↑"; }
table.grid td.c, table.grid th.c { text-align: center; }
table.grid td.name { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:hover { background: var(--wash); }
table.grid tbody tr.nolink { cursor: default; }

.st { font-size: 15px; display: inline-block; width: 1.2em; text-align: center; }
.st2 { color: var(--good-text); font-weight: 700; }
.st1 { color: var(--text-secondary); }
.st0 { color: var(--text-muted); }
.legend-line .st { margin-left: 10px; }
.legend-line .st:first-child { margin-left: 0; }

.pager { display: flex; justify-content: center; gap: 16px; align-items: center; margin-top: 10px; }
.back { display: inline-block; margin-bottom: 10px; font-size: 13px; }
.company-head { margin-bottom: 14px; }

.multiples { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 16px; }
.multiples .m { border-top: 1px solid var(--grid); padding-top: 6px; }
.multiples .m h3 { font-size: 13px; font-weight: 600; margin: 0; }
.multiples .m .unit { color: var(--text-muted); font-size: 12px; font-weight: 400; }
.multiples .empty { color: var(--text-muted); font-size: 13px; padding: 30px 0; }

#drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 92vw); z-index: 10;
  background: var(--surface-1); border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12); display: flex; flex-direction: column;
}
.drawer-head { display: flex; justify-content: space-between; gap: 12px; padding: 14px 16px 8px; }
.drawer-tools { display: flex; gap: 10px; align-items: center; padding: 0 16px 10px; border-bottom: 1px solid var(--grid); }
#d-body { overflow: auto; flex: 1; padding: 12px 16px; }
#d-text { white-space: pre-wrap; word-wrap: break-word; font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; margin: 0; }
mark { background: var(--mark); color: inherit; }
mark.current { outline: 2px solid var(--series-2); }

@media (max-width: 900px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .multiples { grid-template-columns: 1fr; }
}

.tabs { display: flex; gap: 4px; margin-left: 12px; }
.tabs a { color: var(--text-secondary); padding: 3px 10px; border-radius: 6px; font-size: 13px; }
.tabs a:hover { background: var(--wash); text-decoration: none; }
.tabs a.active { color: var(--text-primary); font-weight: 600; background: var(--wash); }
.table-wrap.wide { max-height: none; }
table.counts td, table.counts th { text-align: right; padding: 5px 8px; }
table.counts th:first-child, table.counts td:first-child {
  position: sticky; left: 0; z-index: 1; background: var(--surface-1); text-align: left;
  white-space: normal; min-width: 300px; max-width: 360px;
}
table.counts thead th:first-child { z-index: 2; }
table.counts tbody tr { cursor: default; }
table.counts tr.group td { color: var(--text-secondary); font-weight: 600; font-size: 12px; padding-top: 14px; border-bottom: 1px solid var(--axis); }
table.counts tr.total td { font-weight: 600; }
table.counts td.zero { color: var(--text-muted); }
.notes { margin-top: 12px; max-width: 980px; }

.multiples .tags { margin: 1px 0 2px; font-size: 11.5px; line-height: 1.5; color: var(--text-muted); }
.multiples .tags code { font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text-muted); }
.multiples .tags code.used { color: var(--text-primary); font-weight: 600; }

table.grid td.r, table.grid th.r { text-align: right; }

.chart-title { font-size: 13px; font-weight: 600; margin: 10px 0 0; color: var(--text-primary); }
.chart-title .muted { font-weight: 400; }
.tiles .tile.text { border-top: 3px solid var(--grid); }

.filters.primary { margin-bottom: 8px; }
.filters.primary label { font-size: 14px; color: var(--text-primary); }
.filters.secondary { margin-bottom: 14px; padding-top: 8px; border-top: 1px solid var(--grid); }
.inline-label { display: flex; gap: 6px; align-items: center; color: var(--text-secondary); font-size: 13px; }
