:root {
  color-scheme: light;
  --page:           #f9f9f7;
  --surface:         #fcfcfb;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --gridline:        #e1e0d9;
  --baseline:        #c3c2b7;
  --border:          rgba(11,11,11,0.10);
  --accent-strong:   #184f95;
  --success-text:    #006300;

  --series-1: #2a78d6; /* blue    */
  --series-2: #eb6834; /* orange  */
  --series-3: #1baf7a; /* aqua    */
  --series-4: #eda100; /* yellow  */
  --series-5: #e87ba4; /* magenta */
  --series-6: #008300; /* green   */
  --series-7: #4a3aa7; /* violet  */
  --series-8: #e34948; /* red     */

  --warn-bg: #fdf1de;
  --warn-text: #8a5a06;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page:           #0d0d0d;
    --surface:        #1a1a19;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.10);
    --accent-strong:  #3987e5;
    --success-text:   #0ca30c;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;

    --warn-bg: #3a2f1a;
    --warn-text: #e0b364;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:           #0d0d0d;
  --surface:        #1a1a19;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255,255,255,0.10);
  --accent-strong:  #3987e5;
  --success-text:   #0ca30c;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  --warn-bg: #3a2f1a; --warn-text: #e0b364;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  padding-inline: 20px;
}
.muted { color: var(--text-muted); font-size: 12.5px; }

.topbar {
  display: flex; justify-content: space-between; align-items: flex-end;
  flex-wrap: wrap; gap: 12px;
  padding-block: 18px 10px;
}
.topbar-left { display: flex; flex-direction: column; gap: 2px; }
.topbar h1 { font-size: 19px; margin: 0; letter-spacing: -0.01em; }

.tabbar { display: flex; gap: 4px; }
.tabbtn {
  appearance: none; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-secondary); font: inherit; font-weight: 700; font-size: 13px;
  padding: 8px 16px; border-radius: 8px; cursor: pointer;
}
.tabbtn[aria-selected="true"] { color: var(--text-primary); border-color: var(--accent-strong); }
.tabbtn:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }

.filterbar {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 16px;
}
.filter-group { display: flex; flex-direction: column; gap: 4px; min-width: 140px; flex: 1 1 160px; }
.filter-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
select {
  background: var(--page); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; font: inherit; font-size: 13px;
}
select[multiple] { min-height: 34px; }
.filter-group-checkbox { flex: 0 0 auto; justify-content: flex-end; padding-bottom: 7px; }
.filter-checkbox { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-secondary); cursor: pointer; white-space: nowrap; }
.filter-checkbox input { accent-color: var(--accent-strong); width: 14px; height: 14px; }
.btn-ghost {
  appearance: none; background: transparent; border: 1px solid var(--border);
  color: var(--text-secondary); border-radius: 6px; padding: 7px 12px; font: inherit;
  font-size: 12.5px; cursor: pointer; align-self: flex-end;
}
.btn-ghost:hover { background: var(--gridline); }

.kpirow {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px; margin-bottom: 18px;
}
.kpi-tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 4px;
}
.kpi-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.kpi-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 11.5px; color: var(--text-secondary); }

.panel[hidden] { display: none; }

.chart-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px; margin-bottom: 16px;
}
/* All 3 Overall charts on one row on wide screens; wraps to fewer columns as it narrows. */
.chart-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 900px) { .chart-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 620px) { .chart-grid-3 { grid-template-columns: 1fr; } }
.chart-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; min-width: 0;
}
.chart-card-wide { grid-column: 1 / -1; }
.chart-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.chart-card-head h2 { font-size: 14px; margin: 0; }
/* Fixed-height wrapper + maintainAspectRatio:false (set in app.js) keeps every chart
   a sane, consistent height regardless of how wide its card is -- Chart.js otherwise
   scales height off its own aspect ratio, which blows up on a full-width card. */
.chart-canvas-wrap { position: relative; height: 240px; width: 100%; }
.chart-canvas-wrap-tall { height: 360px; }
.chart-canvas-wrap canvas { max-width: 100%; }

.table-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; margin-bottom: 24px;
}
.table-card-head { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: 8px; }
.table-card-head h2 { font-size: 14px; margin: 0; }
.table-wrap { overflow-x: auto; max-height: 480px; overflow-y: auto; }

table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 12.5px; }
thead th {
  position: sticky; top: 0; background: var(--surface); text-align: right;
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
  font-weight: 700; color: var(--text-secondary); cursor: pointer; user-select: none;
}
thead th.col-dim { text-align: left; }
thead th .sort-arrow { color: var(--text-muted); margin-left: 3px; }
tbody td { padding: 6px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--gridline); }
tbody td.col-dim { text-align: left; font-weight: 600; }
tbody tr:hover { background: var(--gridline); }
tbody tr.low-signal { background: var(--warn-bg); }
tbody tr.low-signal:hover { filter: brightness(0.97); }
.signal-badge { font-size: 10px; font-weight: 700; color: var(--warn-text); }

.footnote { color: var(--text-muted); font-size: 12px; padding-block: 18px 28px; }

@media (max-width: 480px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .filterbar { flex-direction: column; align-items: stretch; }
  .filter-group { min-width: 0; }
}
