/* Design tokens. Dark values are selected steps for the dark surface, not an
   automatic flip: the media query covers the OS setting, the [data-theme] scope
   covers the in-page toggle and must win in both directions. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --series: #2a78d6;
  --series-soft: #cde2fb;
  --good: #006300;
  --critical: #d03b3b;
  --warning: #fab219;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 12px rgba(11, 11, 11, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series: #3987e5;
    --series-soft: #184f95;
    --good: #0ca30c;
    --critical: #d03b3b;
    --warning: #fab219;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --series: #3987e5;
  --series-soft: #184f95;
  --good: #0ca30c;
  --critical: #d03b3b;
  --warning: #fab219;
  --shadow: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- sign-in gate ---------- */

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 40px;
  max-width: 380px;
  width: 100%;
  text-align: center;
}

.gate-card h1 { font-size: 22px; margin: 0 0 6px; letter-spacing: -0.01em; }
.gate-card p { color: var(--text-secondary); margin: 0 0 28px; font-size: 13px; }

.btn {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  padding: 9px 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 120ms ease;
}
.btn:hover { background: color-mix(in srgb, var(--text-primary) 5%, var(--surface)); }
.btn-primary {
  background: var(--series);
  border-color: transparent;
  color: #fff;
  font-weight: 500;
  width: 100%;
  justify-content: center;
  padding: 11px 14px;
}
.btn-primary:hover { background: color-mix(in srgb, #000 12%, var(--series)); }

.error {
  color: var(--critical);
  font-size: 13px;
  margin-top: 18px;
  min-height: 20px;
}

/* ---------- header ---------- */

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

.brand h1 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
.brand .sub { color: var(--text-secondary); font-size: 13px; margin-top: 3px; }

.top-actions { display: flex; align-items: center; gap: 10px; }
.who { color: var(--text-secondary); font-size: 13px; }

/* ---------- stat tiles ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.tile .label {
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}
.tile .value { font-size: 27px; letter-spacing: -0.02em; line-height: 1.15; }
.tile .value .unit { font-size: 15px; color: var(--text-secondary); margin-left: 2px; }
.tile .note { color: var(--muted); font-size: 12px; margin-top: 6px; }
.delta { font-size: 12px; margin-top: 6px; display: inline-flex; align-items: center; gap: 5px; }
.delta.up { color: var(--critical); }
.delta.down { color: var(--good); }
.delta.flat { color: var(--muted); }

/* ---------- cards & charts ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px 12px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.card h2 { font-size: 15px; margin: 0; font-weight: 600; }
.card .hint { color: var(--muted); font-size: 12px; }

.legend { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin: 8px 0 4px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.swatch.line { height: 2px; border-radius: 1px; width: 16px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; }
.grid-2 .card { margin-bottom: 0; }

.chart { width: 100%; overflow-x: auto; }
svg { display: block; max-width: 100%; }

text { font-family: inherit; }
.tick { fill: var(--muted); font-size: 11px; }
.tick-num { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.bar-label { fill: var(--text-secondary); font-size: 11px; font-variant-numeric: tabular-nums; }
.cat-label { fill: var(--text-primary); font-size: 12px; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--axis); stroke-width: 1; }

/* ---------- tooltip ---------- */

.tip {
  position: fixed;
  pointer-events: none;
  z-index: 40;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14);
  opacity: 0;
  transition: opacity 90ms ease;
  max-width: 260px;
}
.tip.on { opacity: 1; }
.tip .t-title { font-weight: 600; margin-bottom: 3px; }
.tip .t-row { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.tip .t-flag { color: var(--warning); margin-top: 4px; }

/* ---------- table ---------- */

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 12px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }
.table-scroll.tall { max-height: 520px; overflow-y: auto; }
.table-scroll.tall thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.coverage {
  color: var(--muted);
  font-size: 12px;
  padding: 10px 2px 4px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}

.filter {
  font: inherit;
  font-size: 13px;
  width: 100%;
  max-width: 320px;
  padding: 7px 10px;
  margin: 4px 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
}
.filter::placeholder { color: var(--muted); }
.empty-row td { color: var(--muted); text-align: center; padding: 20px; }
td.rank, th.rank { color: var(--muted); width: 42px; padding-right: 14px; }

details.data-view { margin: 6px 0 4px; }
details.data-view summary {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 4px 0;
}
details.data-view[open] summary { margin-bottom: 6px; }
.data-view .table-scroll { max-height: 260px; overflow-y: auto; }

/* ---------- misc ---------- */

.notice {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--warning);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 18px;
}

.skeleton { color: var(--muted); padding: 40px 0; text-align: center; }
[hidden] { display: none !important; }
