:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.05);
  --accent: #2a78d6;
  --up: #006300;
  --down: #d03b3b;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --other: #b5b3ab;
  --c-blue: #2a78d6; --c-orange: #eb6834; --c-aqua: #1baf7a; --c-yellow: #eda100;
  --c-magenta: #e87ba4; --c-green: #008300; --c-violet: #4a3aa7; --c-red: #e34948;
  --c-lightblue: #6da7ec;
  --forecast: #4a3aa7;
  --forecast-wash: rgba(74, 58, 167, 0.09);
  --critical: #d03b3b;
  --warning: #fab219;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.06);
    --accent: #3987e5;
    --up: #0ca30c;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --other: #5f5e59;
    --c-blue: #3987e5; --c-orange: #d95926; --c-aqua: #199e70; --c-yellow: #c98500;
    --c-magenta: #d55181; --c-green: #008300; --c-violet: #9085e9; --c-red: #e66767;
    --c-lightblue: #86b6ef;
    --forecast: #9085e9;
    --forecast-wash: rgba(144, 133, 233, 0.14);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --wash: rgba(255, 255, 255, 0.06);
  --accent: #3987e5;
  --up: #0ca30c;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --other: #5f5e59;
  --c-blue: #3987e5; --c-orange: #d95926; --c-aqua: #199e70; --c-yellow: #c98500;
  --c-magenta: #d55181; --c-green: #008300; --c-violet: #9085e9; --c-red: #e66767;
  --c-lightblue: #86b6ef;
  --forecast: #9085e9;
  --forecast-wash: rgba(144, 133, 233, 0.14);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, select, input { font: inherit; color: inherit; }

.wrap { max-width: 1440px; margin: 0 auto; padding: 20px 24px 48px; }

header.top {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  margin-bottom: 16px;
}
header.top h1 { font-size: 20px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
header.top h1 span { color: var(--muted); font-weight: 400; }
.status { color: var(--ink-2); font-size: 13px; margin-left: auto; text-align: right; }
.status .err { color: var(--critical); }
.status .file { color: var(--muted); }
.actions { display: flex; gap: 8px; align-items: center; }

.btn {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
.btn:hover { background: var(--wash); }
.btn:disabled { opacity: .5; cursor: progress; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--wash); }

.filters {
  display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center;
  padding: 12px 0 16px; position: sticky; top: 0; z-index: 5; background: var(--page);
}
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--wash); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.filters label { color: var(--ink-2); font-size: 13px; display: inline-flex; gap: 8px; align-items: center; }
.filters select {
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; background: var(--surface);
  max-width: 260px;
}

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px;
}
.tile .label { color: var(--ink-2); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .value { font-size: 26px; font-weight: 600; margin-top: 4px; letter-spacing: -0.01em; white-space: nowrap; }
.tile .sub { color: var(--muted); font-size: 12px; margin-top: 2px; min-height: 17px; }
.tile .delta.up { color: var(--up); }
.tile .delta.down { color: var(--down); }
.tile.hero .value { font-size: 34px; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px 10px; min-width: 0;
}
.card.wide { grid-column: 1 / -1; }
.card-head { display: flex; align-items: baseline; gap: 12px; }
.card-head h2 { font-size: 15px; font-weight: 600; margin: 0; }
.card-head .hint { color: var(--muted); font-size: 12px; }
.card-head .card-actions { margin-left: auto; display: flex; gap: 6px; }
.card-head .btn { padding: 2px 8px; font-size: 12px; }
.card-head .btn[aria-pressed="true"] { background: var(--wash); border-color: var(--axis); }
.card-head .btn:disabled { opacity: .45; cursor: default; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 8px 0 0; color: var(--ink-2); font-size: 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.legend i.line { height: 2px; width: 14px; border-radius: 1px; vertical-align: 3px; }
.chart { height: 300px; width: 100%; }
.chart.tall { height: 380px; }
.loading .chart, .loading .tiles { opacity: .45; transition: opacity .2s; }

.table-wrap { max-height: 320px; overflow: auto; margin-top: 8px; border-top: 1px solid var(--grid); }
table { border-collapse: collapse; width: 100%; font-size: 12px; }
th, td { padding: 4px 8px; border-bottom: 1px solid var(--grid); text-align: left; white-space: nowrap; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
th { position: sticky; top: 0; background: var(--surface); color: var(--ink-2); font-weight: 500; }

.note { color: var(--muted); font-size: 12px; margin-top: 16px; }
.banner { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--critical); border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; }
.empty { padding: 48px; text-align: center; color: var(--ink-2); }

@media (max-width: 900px) {
  .wrap { padding: 12px 16px 32px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .status { margin-left: 0; text-align: left; width: 100%; order: 3; }
  .tile .value { font-size: 22px; }
  .tile.hero .value { font-size: 28px; }
  .chart { height: 260px; }
  .chart.tall { height: 320px; }
  .filters { position: static; }
}
@media (max-width: 520px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile { padding: 10px; }
  .tile .label { font-size: 11px; }
  .tile .value, .tile.hero .value { font-size: 20px; }
  .seg button { padding: 6px 10px; }
}
.tile .fc { color: var(--ink-2); font-size: 12px; margin-top: 4px; }
.tile .fc span { color: var(--muted); }
.tile .fc-val { color: var(--forecast); background: var(--forecast-wash); font-weight: 600; border-radius: 4px; padding: 1px 5px; margin-left: -5px; white-space: nowrap; }
.legend i.dash { width: 14px; height: 0; border-radius: 0; vertical-align: 3px; }
.tile .yoy { color: var(--ink-2); font-size: 12px; margin-top: 2px; }
.tile .yoy span { color: var(--muted); }
.seg[hidden] { display: none; }
.filters label[hidden] { display: none; }
.legend i.dot { width: 14px; height: 0; border-radius: 0; vertical-align: 3px; }
.legend.below { margin: 4px 0 2px; }
.views { margin-left: 8px; }
.table-wrap.rating { max-height: 560px; border-top: 0; margin-top: 4px; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
th.sorted { color: var(--ink); }
.card-note { color: var(--muted); font-size: 12px; margin: 8px 0 2px; line-height: 1.4; }
.card-note.warn { color: var(--c-red); }
