/* Palette roles from the design system. Light/dark swap in one place; everything
   below is written against roles, never raw hex. */
:root {
  color-scheme: light;
  --surface-1:      #fcfcfb;
  --page:           #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --grid:           #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);
  --series-1:       #2a78d6;
  --series-1-wash:  rgba(42, 120, 214, 0.10);
  --delta-up:       #006300;
  --delta-down:     #d03b3b;
  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;
  --status-info:     #52514e;
  --ghost:          rgba(11, 11, 11, 0.04);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --page:           #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --series-1:       #3987e5;
    --series-1-wash:  rgba(57, 135, 229, 0.10);
    --delta-up:       #0ca30c;
    --status-info:     #c3c2b7;
    --ghost:          rgba(255, 255, 255, 0.05);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --page:           #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:           #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --series-1:       #3987e5;
  --series-1-wash:  rgba(57, 135, 229, 0.10);
  --delta-up:       #0ca30c;
  --status-info:     #c3c2b7;
  --ghost:          rgba(255, 255, 255, 0.05);
}

* { 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;
}

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

/* ---------- header ---------- */
header {
  display: flex; align-items: center; gap: 12px;
  flex-wrap: wrap; margin-bottom: 22px;
}
header h1 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
header .spacer { flex: 1; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  font-size: 12px; color: var(--text-secondary); white-space: nowrap;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); }
.pill.live .dot { background: var(--status-good); }
.pill.warn .dot { background: var(--status-critical); }

button {
  font: inherit; font-size: 13px;
  padding: 5px 11px; border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-primary);
  cursor: pointer;
}
button:hover { background: var(--ghost); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--series-1); border-color: transparent; color: #fff; }
button.primary:hover { filter: brightness(1.07); }
button.link {
  border: none; background: none; color: var(--text-secondary);
  text-decoration: underline; padding: 2px 4px;
}

/* ---------- cards ---------- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
}
.card + .card { margin-top: 16px; }
.card h2 { font-size: 13px; font-weight: 600; margin: 0 0 2px; letter-spacing: -0.005em; }
.card .sub { font-size: 12px; color: var(--text-secondary); margin: 0 0 16px; }

/* ---------- hero + KPI row ---------- */
.hero-row {
  display: grid; grid-template-columns: minmax(240px, 1.15fr) 2fr;
  gap: 16px; align-items: stretch;
}
@media (max-width: 860px) { .hero-row { grid-template-columns: 1fr; } }

.hero .label { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.hero .value {
  font-size: 48px; font-weight: 600; line-height: 1.05;
  letter-spacing: -0.025em;                 /* proportional figures, not tabular */
}
.hero .delta { margin-top: 8px; font-size: 14px; }

.kpis {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px;
  background: var(--border); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden;
}
@media (max-width: 640px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi { background: var(--surface-1); padding: 16px 16px 14px; }
.kpi .label { font-size: 12px; color: var(--text-secondary); }
.kpi .value { font-size: 22px; font-weight: 600; margin-top: 4px; letter-spacing: -0.015em; }
.kpi .delta { font-size: 12px; margin-top: 3px; }

.delta { display: inline-flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
.delta.up   { color: var(--delta-up); }
.delta.down { color: var(--delta-down); }
.delta.flat { color: var(--text-secondary); }

/* ---------- alerts ---------- */
.alert-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.alert-head h2 { margin: 0; }
.alert-count {
  font-size: 12px; color: var(--text-secondary);
  border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px;
}

.alert {
  display: grid; grid-template-columns: auto 1fr auto;
  gap: 12px; align-items: start;
  padding: 13px 0; border-top: 1px solid var(--grid);
}
.alert:first-of-type { border-top: none; }
.alert .rail { width: 3px; align-self: stretch; border-radius: 2px; min-height: 38px; }
.alert .body { min-width: 0; }

/* Status is never colour alone: every badge carries an icon AND a word. */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-secondary);
}
.badge .glyph { font-size: 12px; line-height: 1; }
.badge .swatch { width: 8px; height: 8px; border-radius: 2px; }

.alert .title { font-weight: 600; margin: 3px 0 2px; }
.alert .detail { color: var(--text-secondary); font-size: 13px; }
.alert .action {
  font-size: 13px; margin-top: 6px; color: var(--text-primary);
  padding-left: 10px; border-left: 2px solid var(--grid);
}
.alert .when { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

.sev-critical .rail { background: var(--status-critical); }
.sev-serious  .rail { background: var(--status-serious); }
.sev-warning  .rail { background: var(--status-warning); }
.sev-good     .rail { background: var(--status-good); }
.sev-info     .rail { background: var(--status-info); }
.sev-critical .swatch { background: var(--status-critical); }
.sev-serious  .swatch { background: var(--status-serious); }
.sev-warning  .swatch { background: var(--status-warning); }
.sev-good     .swatch { background: var(--status-good); }
.sev-info     .swatch { background: var(--status-info); }

.empty { color: var(--text-secondary); font-size: 13px; padding: 22px 0; text-align: center; }

/* ---------- charts ---------- */
.chart-row { display: grid; grid-template-columns: 1.55fr 1fr; gap: 16px; margin-top: 16px; }
@media (max-width: 940px) { .chart-row { grid-template-columns: 1fr; } }
.card > svg { display: block; width: 100%; overflow: visible; }

.axis-text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.gridline  { stroke: var(--grid); stroke-width: 1; }
.baseline  { stroke: var(--baseline); stroke-width: 1; }
.series-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.series-area { fill: var(--series-1-wash); }
.end-dot { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.bar { fill: var(--series-1); }
.bar-label { fill: var(--text-secondary); font-size: 11px; font-variant-numeric: tabular-nums; }
.bar-name  { fill: var(--text-primary); font-size: 12px; }

.crosshair { stroke: var(--baseline); stroke-width: 1; pointer-events: none; }
.hit { fill: transparent; cursor: crosshair; }

.tooltip {
  position: fixed; z-index: 40; pointer-events: none;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,.14);
  opacity: 0; transition: opacity .1s;
}
.tooltip .tt-label { color: var(--text-secondary); margin-bottom: 3px; }
.tooltip .tt-value { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- table ---------- */
table { width: 100%; border-collapse: collapse; }
th {
  text-align: right; font-size: 11px; font-weight: 500; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-muted);
  padding: 0 10px 8px; border-bottom: 1px solid var(--grid);
  cursor: pointer; user-select: none; white-space: nowrap;
}
th:first-child, td:first-child { text-align: left; padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
th:hover { color: var(--text-secondary); }
th .arrow { opacity: .55; font-size: 9px; }
td {
  text-align: right; padding: 9px 10px;
  border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;         /* columns must align */
}
tbody tr:hover { background: var(--ghost); }
td.sym { font-weight: 600; font-variant-numeric: normal; }
td.sym .exch { font-weight: 400; color: var(--text-muted); font-size: 11px; margin-left: 5px; }
.spark { display: block; }
.spark path { fill: none; stroke: var(--text-muted); stroke-width: 1.5; stroke-linejoin: round; }
.spark path.accent { stroke: var(--series-1); }

/* ---------- settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.field .hint { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.field input, .field select {
  width: 100%; font: inherit; font-size: 13px; padding: 5px 8px;
  border-radius: 7px; border: 1px solid var(--border);
  background: var(--page); color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.notice {
  border: 1px solid var(--border); border-left: 3px solid var(--status-warning);
  border-radius: 8px; padding: 11px 14px; margin-bottom: 16px;
  background: var(--surface-1); font-size: 13px;
}
.notice strong { display: block; margin-bottom: 2px; }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
