:root {
  --bg: #f6f8fb;
  --bg-accent: #eef2f9;
  --surface: #ffffff;
  --surface-2: #f9fafc;
  --ink: #1f2933;
  --ink-soft: #52606d;
  --ink-faint: #7b8794;
  --border: #e1e5ea;
  --border-soft: #edf0f4;
  --accent: #2563eb;
  --accent-ink: #1d4ed8;
  --accent-soft: #eef4ff;
  --up: #d6336c;        /* increase / under-priced */
  --up-bg: #fde7ef;
  --down: #0f9d58;      /* decrease / over-priced */
  --down-bg: #e4f6ec;
  --worst: #b8860b;
  --worst-bg: #fdf6e3;
  --worst-border: #e6b800;
  --code-bg: #eef1f5;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 12px rgba(15, 23, 42, 0.05);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05);
  --radius: 10px;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --max-width: 1100px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --bg-accent: #161b22;
    --surface: #161b22;
    --surface-2: #1b2129;
    --ink: #e6edf3;
    --ink-soft: #a8b3bf;
    --ink-faint: #768390;
    --border: #2a313a;
    --border-soft: #21272f;
    --accent: #58a6ff;
    --accent-ink: #79b8ff;
    --accent-soft: #16263f;
    --up: #ff7b9c;
    --up-bg: #3a1726;
    --down: #56d364;
    --down-bg: #122b1b;
    --worst: #e3b341;
    --worst-bg: #2a2410;
    --worst-border: #6b5618;
    --code-bg: #1f2630;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.25rem;
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--code-bg);
  padding: 0.08em 0.35em;
  border-radius: 4px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Header / nav ---- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.site-title {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.site-title:hover { text-decoration: none; color: var(--accent-ink); }
.site-nav { display: flex; gap: 1.25rem; }
.site-nav a { color: var(--ink-soft); font-weight: 500; }
.site-nav a:hover { color: var(--accent-ink); }
.site-nav a.active { color: var(--accent-ink); font-weight: 600; }

/* ---- Run selector banner ---- */
/* A strip above the hero for switching between pre-rendered run pages. */
.run-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.85rem;
  margin-bottom: 1.25rem;
  padding: 0.6rem 0.95rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  font-size: 0.9rem;
}
.run-bar-label {
  color: var(--ink-faint);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.75rem;
}
.run-bar-single { font-weight: 600; color: var(--ink); }
.run-bar-meta { margin-left: auto; color: var(--ink-faint); }
/* Viewing an older (non-latest) run: amber accent to flag it. */
.run-bar-older { border-color: var(--worst-border); background: var(--worst-bg); }
.run-bar-older .run-bar-meta { color: var(--worst); font-weight: 600; }

/* Custom dropdown (button + listbox) — fully styled so the font matches the
   page open and closed, unlike a native <select> whose popup uses the OS font. */
.run-dropdown { position: relative; display: inline-block; }
.run-dropdown-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.7rem;
  line-height: 1.3;
  cursor: pointer;
}
.run-dropdown-toggle:hover { border-color: var(--accent); }
.run-dropdown-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* CSS-drawn chevron; inherits a var color so it adapts to light/dark for free. */
.run-dropdown-chevron {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--ink-faint);
  transition: transform 0.15s ease;
}
.run-dropdown-toggle[aria-expanded="true"] .run-dropdown-chevron { transform: rotate(180deg); }

.run-dropdown-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 20;
  min-width: 100%;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  white-space: nowrap;
}
.run-dropdown-list[hidden] { display: none; }
.run-dropdown-option {
  display: block;
  padding: 0.35rem 0.6rem;
  border-radius: 5px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink);
}
.run-dropdown-option:hover { background: var(--bg-accent); text-decoration: none; }
.run-dropdown-option:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.run-dropdown-option.is-current { color: var(--accent-ink); font-weight: 600; }
.run-dropdown-noscript a { margin-right: 0.6rem; }

/* ---- Main / sections ---- */
main { padding: 1.5rem 1.25rem 3rem; }
main.container { padding-left: 1.25rem; padding-right: 1.25rem; }

/* Constrain page content to the methodology text width (80ch), left-aligned
   within the full-width container — header/footer chrome stays full width.
   This is what .prose already does on the methodology page; applying it to
   every direct child of main makes the dashboard items match that width.

   `ch` resolves against each element's OWN font-size, so a child set below 1rem
   would land short of the measure the 1rem blocks use. Such a child declares
   --measure-scale as its font-size ratio (see .note) and the cap is divided by it,
   which reproduces 80ch-at-1rem. Note this rule outranks a bare class selector
   (0-1-1 vs 0-1-0), so the scale has to travel as a property, not an override. */
main.container > * { max-width: calc(80ch / var(--measure-scale, 1)); }

section { margin: 2.25rem 0; }
section:first-child { margin-top: 1.25rem; }

h1 {
  font-size: 1.85rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 0 0 0.6rem;
}
h2 {
  font-size: 1.3rem;
  letter-spacing: -0.01em;
  margin: 0 0 0.9rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}
h2.h2-lg { font-size: 1.6rem; }
h3 { font-size: 1.05rem; margin: 0 0 0.6rem; }

.lede { color: var(--ink-soft); font-size: 1.05rem; max-width: 72ch; }

/* ---- Hero ---- */
.hero {
  background:
    radial-gradient(120% 140% at 100% 0%, var(--accent-soft) 0%, transparent 55%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.6rem 1.5rem;
}

/* ---- Goal targets table (the Summary section) ----
   One row per goal (a component sum over a set of receiver cases), one column per
   client. Cells own their pass/amber/fail tint, so the row stripe and hover must
   not paint over them. */
.goal-intro {
  color: var(--ink-soft);
  font-size: 0.92rem;
  max-width: 80ch;
  margin: 0 0 0.9rem;
}
.goal-table tbody tr:nth-child(even),
.goal-table tbody tr:hover { background: none; }
/* The row's identity is a short name (header tint); the component sum it stands
   for is the cell's tooltip, so the column stays narrow. */
.goal-table .goal-name {
  background: var(--bg-accent);
  vertical-align: middle;
  font-weight: 600;
  white-space: normal;
  max-width: 16rem;
}
.goal-table .goal-target { font-weight: 700; }
/* pass = at or under the goal, mid = up to GOAL_MID_MARGIN over, fail = beyond,
   nodata = no fit for that client. Kept in sync with collect_goals(). */
.goal-pass { background: rgba(15, 157, 88, 0.82); color: #fff; font-weight: 600; }
.goal-mid { background: rgba(184, 134, 11, 0.85); color: #fff; font-weight: 600; }
.goal-fail { background: rgba(201, 42, 42, 0.82); color: #fff; font-weight: 600; }
.goal-nodata { color: var(--ink-faint); }
/* Softer tints on the dark background — same hues, less glare. */
@media (prefers-color-scheme: dark) {
  .goal-pass { background: rgba(15, 157, 88, 0.62); }
  .goal-mid { background: rgba(184, 134, 11, 0.68); }
  .goal-fail { background: rgba(201, 42, 42, 0.62); }
}

/* ---- Hover info (data-tip) ----
   Native `title` tooltips don't render in every browser/embedding, so hover info
   is drawn by charts.js's initTooltips() instead: any [data-tip] element gets a
   single shared .js-tooltip div, positioned in fixed coordinates (immune to the
   .table-scroll wrapper's overflow, which would otherwise clip an absolutely
   positioned tooltip near a table's edge). */
[data-tip] { cursor: help; }
.js-tooltip {
  position: fixed;
  z-index: 1000;
  max-width: 320px;
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  background: var(--ink);
  color: var(--surface);
  font-size: 0.8rem;
  line-height: 1.35;
  box-shadow: var(--shadow-sm);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.08s ease;
}
.js-tooltip.is-visible { opacity: 1; }

/* ---- Summary ---- */
.takeaway {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 0.85rem 1.1rem;
}
.caveats {
  background: var(--worst-bg);
  border: 1px solid var(--worst-border);
  border-radius: var(--radius);
  padding: 0.7rem 1.1rem;
  margin-top: 1rem;
}
.caveats ul { margin: 0.3rem 0 0; padding-left: 1.2rem; }
.preliminary-warning {
  background: var(--worst-bg);
  border: 1px solid var(--worst-border);
  border-left: 4px solid var(--worst-border);
  border-radius: var(--radius);
  padding: 0.7rem 1.1rem;
  margin: 0 0 1.2rem;
}
.caveats-ok { color: var(--ink-soft); margin-top: 1rem; }
/* Sub-1rem font, so --measure-scale carries the ratio: `main.container > *` reads it
   to keep this box the same width as the 1rem blocks around it (see that rule), and
   the max-width here does the same for a .note nested deeper — e.g. inside .prose on
   the methodology page, where the container rule doesn't reach. */
.note {
  --measure-scale: 0.92;
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.7rem 1.1rem;
  margin: 0 0 1.2rem;
  color: var(--ink-soft);
  font-size: calc(var(--measure-scale) * 1rem);
  max-width: calc(80ch / var(--measure-scale));
}
.table-note {
  color: var(--ink-soft);
  font-size: 0.85rem;
  margin-top: 0.6rem;
}
/* Lateral-scroll hint above wide tables that overflow their container. */
.table-scroll-hint {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 0.5rem;
  color: var(--ink-faint);
  font-size: 0.82rem;
  font-style: italic;
}

/* ---- Table filters ---- */
.table-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 0.9rem;
}
.table-filter {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
}
.table-filter select {
  font: inherit;
  font-size: 0.85rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 0.6rem;
  cursor: pointer;
}
.table-filter select:hover { border-color: var(--accent); }
.table-filter select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.table-filter-empty {
  margin: 0;
  align-self: center;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

/* ---- Tables ---- */
.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 0.9rem;
  overflow: hidden;
}
.table-scroll > .data-table { border: none; }
.data-table:not(.table-scroll .data-table) {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.data-table th,
.data-table td {
  padding: 0.55rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}
.data-table thead th {
  background: var(--bg-accent);
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: 0.01em;
  color: var(--ink-soft);
  position: sticky;
  top: 0;
}
.data-table tbody tr { transition: background 0.1s ease; }
.data-table tbody tr:nth-child(even) { background: var(--surface-2); }
.data-table tbody tr:hover { background: var(--accent-soft); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Change cells (colored deltas) ---- */
.chg { font-weight: 600; font-variant-numeric: tabular-nums; }
.chg-up { color: var(--up); }
.chg-down { color: var(--down); }
.chg-flat { color: var(--ink-faint); }

/* ---- Worst-case highlight ---- */
.worst-case,
.data-table tbody tr.worst-case:nth-child(even) {
  background: var(--worst-bg) !important;
}
.worst-case td {
  border-bottom-color: var(--worst-border);
  font-weight: 600;
}
.worst-case td:first-child {
  box-shadow: inset 3px 0 0 var(--worst-border);
}

/* ---- Charts ---- */
.chart-block {
  margin-bottom: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.1rem 0.75rem;
}
.chart-block h3 { margin-bottom: 0.75rem; color: var(--ink-soft); }
.chart {
  width: 100%;
  min-height: 380px;
}
.chart-row {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}
.chart-row .chart-block {
  flex: 1 1 0;
  min-width: 0;
  margin-bottom: 0;
}
.no-data { color: var(--ink-soft); text-align: center; padding: 2rem; }

/* ---- Prose (methodology) ---- */
.prose { max-width: 80ch; }
.prose ul, .prose ol { padding-left: 1.4rem; }
.prose li { margin: 0.35rem 0; }
.formula {
  background: var(--code-bg);
  border-radius: var(--radius);
  padding: 0.7rem 1.1rem;
  font-size: 1rem;
}

/* ---- Footer ---- */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 0.85rem;
  padding: 1.25rem 0 2rem;
}
.site-footer .repro { margin: 0 0 0.35rem; }
.site-footer code { background: var(--bg-accent); }
.repro-note { margin: 0; }

/* ---- Trends page ---- */
.trends-filters { align-items: flex-start; gap: 1.5rem; }
.trends-section { margin-top: 2rem; }
.muted { color: var(--ink-soft); font-size: 0.9rem; }
.warning {
  background: var(--worst-bg);
  border: 1px solid var(--worst-border);
  border-left: 4px solid var(--worst-border);
  border-radius: var(--radius);
  padding: 0.7rem 1rem;
  margin: 0.5rem 0;
}
.toggle-set {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.3rem 0.75rem 0.55rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  margin: 0;
}
.toggle-set legend {
  font-size: 0.78rem;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
  padding: 0 0.3rem;
}
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--ink);
  cursor: pointer;
}
.trend-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 2rem;
  margin-bottom: 1rem;
  padding: 0.6rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.trend-legend-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.9rem;
}
.trend-legend-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.trend-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--ink);
}
.trend-legend-line { flex: none; }

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  margin-bottom: 1rem;
  padding: 0.6rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--ink);
}
.chart-legend-swatch {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 2px;
}

.poor-flag { color: var(--up); font-weight: 700; }
.binding-tag {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: 0.05rem 0.4rem;
  letter-spacing: 0.02em;
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
  .header-inner { min-height: 0; padding: 0.5rem 0; }
  h1 { font-size: 1.45rem; }
  h2 { font-size: 1.15rem; }
  .data-table { font-size: 0.82rem; }
  .data-table th, .data-table td { padding: 0.4rem 0.55rem; }
  .chart-row { flex-direction: column; gap: 0; }
  .chart-row .chart-block { margin-bottom: 1.5rem; }
}
