/* Design tokens. Values from the validated reference palette; both modes are
   selected steps, not an automatic flip. Dark is declared twice on purpose:
   the media query covers the OS setting, the [data-theme] scope covers the
   in-page toggle, which must win in both directions. */
:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --success-text: #006300;

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;

  --csat-1: #a32222;
  --csat-2: #e2807c;
  --csat-3: #a8a79b;
  --csat-4: #86b6ef;
  --csat-5: #1c5cab;

  --seq-100: #cde2fb;
  --seq-200: #9ec5f4;
  --seq-300: #6da7ec;
  --seq-400: #3987e5;
  --seq-500: #256abf;
  --seq-600: #184f95;
  --seq-700: #0d366b;

  --status-good: #0ca30c;
  --status-critical: #d03b3b;

  --radius: 10px;
  --shadow: 0 1px 2px 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;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --success-text: #0ca30c;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;

    --csat-1: #f08a8a;
    --csat-2: #a34240;
    --csat-3: #5f5e57;
    --csat-4: #2a6db5;
    --csat-5: #86b6ef;

    --seq-100: #0d366b;
    --seq-200: #104281;
    --seq-300: #184f95;
    --seq-400: #256abf;
    --seq-500: #2a78d6;
    --seq-600: #5598e7;
    --seq-700: #9ec5f4;

    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --success-text: #0ca30c;

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;

  --csat-1: #f08a8a;
  --csat-2: #a34240;
  --csat-3: #5f5e57;
  --csat-4: #2a6db5;
  --csat-5: #86b6ef;

  --seq-100: #0d366b;
  --seq-200: #104281;
  --seq-300: #184f95;
  --seq-400: #256abf;
  --seq-500: #2a78d6;
  --seq-600: #5598e7;
  --seq-700: #9ec5f4;

  --shadow: none;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

a { color: inherit; }

/* ---------- shell ---------- */

.shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 24px 72px;
}

.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 32px 0 20px;
}

.masthead h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.masthead p {
  margin: 4px 0 0;
  color: var(--text-secondary);
  font-size: 13px;
  max-width: 58ch;
}

.theme-toggle {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-1);
  color: var(--text-secondary);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}

.theme-toggle:hover { color: var(--text-primary); }

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: none;
  position: relative;
  padding: 10px 14px 12px;
  border: 0;
  background: none;
  color: var(--text-secondary);
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
  white-space: nowrap;
}

.tab:hover { color: var(--text-primary); }

.tab[aria-selected="true"] {
  color: var(--text-primary);
  font-weight: 600;
}

.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--series-1);
}

.tab.is-placeholder { color: var(--text-muted); font-style: italic; }

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

.project-head { padding: 26px 0 18px; }

.project-head h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.project-head .lede {
  margin: 6px 0 0;
  color: var(--text-secondary);
  max-width: 76ch;
}

.provenance {
  margin: 14px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-1);
  color: var(--text-secondary);
  font-size: 12.5px;
  max-width: 100%;
}

.provenance strong { color: var(--text-primary); font-weight: 600; }

/* ---------- filters ---------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px;
  padding: 16px 0 20px;
}

.field { display: flex; flex-direction: column; gap: 5px; }

.field > label {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-1);
}

.segmented button {
  padding: 5px 11px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text-secondary);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}

.segmented button:hover { color: var(--text-primary); }

.segmented button[aria-pressed="true"] {
  background: var(--text-primary);
  color: var(--surface-1);
  font-weight: 500;
}

.filter-note {
  margin-left: auto;
  align-self: flex-end;
  padding-bottom: 4px;
  color: var(--text-muted);
  font-size: 12px;
}

/* ---------- kpi row ---------- */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat {
  padding: 14px 16px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-1);
  box-shadow: var(--shadow);
}

.stat .label {
  color: var(--text-secondary);
  font-size: 12.5px;
}

.stat .value {
  margin-top: 5px;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.stat .value .unit {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0;
}

.stat .sub {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 12px;
}

/* ---------- chart cards ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
  /* cards size to their content instead of stretching to the tallest in the
     row, so a short chart reads as compact rather than as an empty box */
  align-items: start;
}

.card {
  grid-column: span 12;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 16px 18px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-1);
  box-shadow: var(--shadow);
}

.card.span-6 { grid-column: span 6; }
.card.span-7 { grid-column: span 7; }
.card.span-5 { grid-column: span 5; }

@media (max-width: 900px) {
  .card.span-6, .card.span-7, .card.span-5 { grid-column: span 12; }
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 2px;
}

.card h3 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 600;
}

.card .card-sub {
  margin: 3px 0 14px;
  color: var(--text-secondary);
  font-size: 12.5px;
}

.view-toggle {
  flex: none;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  color: var(--text-secondary);
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
}

.view-toggle:hover { color: var(--text-primary); }

.plot { position: relative; min-width: 0; }

.plot svg { display: block; width: 100%; height: auto; overflow: visible; }

/* Chart chrome */
.grid-line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.axis-line { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.tick-text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.axis-title { fill: var(--text-muted); font-size: 11px; }
.mark-label { fill: var(--text-secondary); font-size: 11.5px; font-weight: 500; }
.mark-label-strong { fill: var(--text-primary); font-size: 12px; font-weight: 600; }

/* ---------- legend ---------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: 12px;
  color: var(--text-secondary);
  font-size: 12px;
}

.legend-item { display: inline-flex; align-items: center; gap: 6px; }

.legend-swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  flex: none;
}

.legend-swatch.line-key {
  width: 14px;
  height: 2px;
  border-radius: 2px;
}

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

.tip {
  position: absolute;
  z-index: 20;
  min-width: 128px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-1);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.16);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.09s linear;
}

.tip[data-show="1"] { opacity: 1; }

.tip .tip-head {
  margin-bottom: 5px;
  color: var(--text-secondary);
  font-size: 11.5px;
}

.tip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 1.5px 0;
  font-size: 12.5px;
}

.tip-key { width: 12px; height: 2px; border-radius: 2px; flex: none; }
.tip-key.block { height: 10px; border-radius: 3px; }
.tip-val {
  margin-left: auto;
  color: var(--text-primary);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.tip-name { color: var(--text-secondary); }

.crosshair { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }

.hit { fill: transparent; cursor: pointer; }
.hit:focus { outline: none; }
.hit:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }

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

.table-wrap { overflow-x: auto; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

table.data th, table.data td {
  padding: 7px 10px;
  text-align: right;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}

table.data th:first-child, table.data td:first-child {
  text-align: left;
  white-space: normal;
}

table.data thead th {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

table.data td { font-variant-numeric: tabular-nums; color: var(--text-secondary); }
table.data td:first-child { color: var(--text-primary); }
table.data tbody tr:last-child td { border-bottom: 0; }

.swatch-cell {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  margin-right: 7px;
  vertical-align: baseline;
}

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

.loading, .empty {
  padding: 48px 0;
  color: var(--text-muted);
  text-align: center;
}

.site-foot {
  margin-top: 40px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
