/* ---------- Color and type tokens ---------- */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  /* chart series (fixed order) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-light: #9ec5f4;   /* lighter step of series-1, for "before" / ranges */
  --negative: #e34948;
  --reference: #898781;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-light: #184f95;
    --negative: #e66767;
    --reference: #898781;
  }
}

/* ---------- Base ---------- */
* { 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: 15px;
  line-height: 1.5;
}

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

h1 { font-size: 26px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0; }
code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.92em;
  background: var(--grid);
  padding: 1px 5px;
  border-radius: 4px;
}

/* ---------- Header and tabs ---------- */
.page-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: 28px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.subtitle { margin: 4px 0 18px; color: var(--text-secondary); }

.tabs { display: flex; gap: 4px; overflow-x: auto; }

.tab {
  font: inherit;
  font-weight: 600;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 10px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--text-primary); }
.tab.is-active { color: var(--text-primary); border-bottom-color: var(--series-1); }
.tab:focus-visible, select:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

/* ---------- Layout ---------- */
main.wrap { padding-top: 24px; padding-bottom: 24px; }

.panel { display: none; }
.panel.is-active { display: block; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 16px;
  min-width: 0;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

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

.note { margin: 12px 0 0; color: var(--text-secondary); font-size: 13.5px; }
.note.outside { margin: -6px 2px 16px; }

/* ---------- Stat tiles ---------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.tiles-inline { grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 16px 0 0; }

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}
.tiles-inline .tile { background: var(--page); }

.tile-value { font-size: 28px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.15; }
.tile-label { color: var(--text-secondary); font-size: 13.5px; margin-top: 4px; }
.tile-detail { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }

/* ---------- Overview ---------- */
.findings { margin: 12px 0 0; padding-left: 22px; }
.findings li { margin-bottom: 10px; }
.findings strong { font-weight: 700; }

.stages {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.stage {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--page);
}
.stage-num { color: var(--text-muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.stage-title { font-weight: 700; margin: 2px 0 4px; }
.stage-text { color: var(--text-secondary); font-size: 13px; }
.stage code { display: inline-block; margin-top: 8px; font-size: 11.5px; }

.page-links {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.page-link {
  display: block;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--page);
  text-decoration: none;
  color: inherit;
}
.page-link:hover { border-color: var(--series-1); }
.page-link-title { display: block; font-weight: 700; color: var(--series-1); }
.page-link-text { display: block; color: var(--text-secondary); font-size: 13px; margin-top: 4px; }

/* ---------- Controls ---------- */
.control { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); font-size: 13.5px; }

select {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--axis);
  border-radius: 6px;
  padding: 5px 8px;
}

/* ---------- Charts ---------- */
.chart-box { position: relative; width: 100%; }
.h-220 { height: 220px; }
.h-260 { height: 260px; }
.h-300 { height: 300px; }
.h-320 { height: 320px; }
.h-340 { height: 340px; }
.h-420 { height: 420px; }
.h-760 { height: 760px; }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; margin-top: 12px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

th {
  text-align: left;
  color: var(--text-secondary);
  font-weight: 600;
  padding: 6px 10px 6px 0;
  border-bottom: 1px solid var(--axis);
  white-space: nowrap;
}
td { padding: 7px 10px 7px 0; border-bottom: 1px solid var(--grid); vertical-align: top; }
tr:last-child td { border-bottom: none; }

th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.muted { color: var(--text-secondary); }

/* small bar inside a table cell */
.cell-bar { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.cell-bar-track { width: 70px; height: 8px; background: var(--grid); border-radius: 4px; overflow: hidden; }
.cell-bar-fill { height: 100%; background: var(--series-1); border-radius: 4px; }

/* ---------- Footer ---------- */
.page-footer { color: var(--text-muted); font-size: 12.5px; padding-bottom: 32px; }

/* ---------- Small screens ---------- */
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; gap: 0; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stages, .page-links { grid-template-columns: 1fr; }
  .page-header { position: static; }
}
@media (max-width: 520px) {
  .tiles, .tiles-inline { grid-template-columns: 1fr; }
  h1 { font-size: 22px; }
}
