/* Cancer Policy Lab — layout and components. Values come from tokens.css. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: 5rem; }
body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; max-width: 100%; height: auto; }
p { margin: 0; }
h1, h2, h3 { margin: 0; font-family: var(--font-serif); font-weight: 600; text-wrap: balance; }
ul, ol { margin: 0; padding: 0; }

a { color: var(--color-accent); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--color-focus); outline-offset: 3px; border-radius: 2px; }

.skip-link { position: absolute; left: var(--gutter); top: -4rem; background: var(--color-text); color: var(--color-bg); padding: var(--space-2) var(--space-3); z-index: 10; }
.skip-link:focus { top: var(--space-2); }

/* ---------- Page frame ---------- */
.wrap { width: 100%; max-width: var(--page-max); margin-inline: auto; padding-inline: var(--gutter); }

/* Header */
.site-header { border-bottom: 1px solid var(--color-rule); background: var(--color-bg); }
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); min-height: 4.5rem; flex-wrap: wrap; padding-block: var(--space-3); }
.wordmark { font-family: var(--font-serif); font-weight: 600; font-size: 1.25rem; color: var(--color-text); text-decoration: none; letter-spacing: -0.005em; }
.site-nav ul { list-style: none; display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); }
.site-nav a { color: var(--color-text); text-decoration: none; font-size: var(--text-small); }
.site-nav a:hover { text-decoration: underline; }
@media (max-width: 47.99rem) { .site-nav .nav-optional { display: none; } }

/* Sections: label rail + content on wide screens */
.section { padding-block: var(--section-gap); border-top: 1px solid var(--color-rule); }
.section--band { background: var(--color-band); border-top: 0; }
.section-grid { display: grid; grid-template-columns: 1fr; gap: var(--space-4); }
.rail { font-size: var(--text-small); color: var(--color-text-muted); }
.rail .label { font-weight: 600; color: var(--color-text); display: block; }
@media (min-width: 64rem) {
  .section-grid { grid-template-columns: repeat(12, minmax(0, 1fr)); column-gap: var(--space-5); }
  .rail { grid-column: 1 / span 3; padding-top: 0.6rem; }
  .content { grid-column: 4 / span 8; }
  .content--wide { grid-column: 4 / span 9; }
}
.content > * + * { margin-top: var(--space-4); }
.section h2 { font-size: var(--text-h2); line-height: var(--leading-heading); max-width: 22em; }
.lead { font-size: var(--text-lead); line-height: var(--leading-lead); max-width: var(--measure); color: var(--color-text); }
.prose { max-width: var(--measure); }
.muted { color: var(--color-text-muted); }

/* ---------- Hero ---------- */
.hero { padding-block: var(--space-7) var(--section-gap); }
@media (min-width: 64rem) { .hero { padding-top: var(--space-9); } }
.hero h1 { font-size: var(--text-hero); line-height: var(--leading-tight); letter-spacing: -0.015em; max-width: 15em; }
.hero .lead { margin-top: var(--space-5); }
.hero-links { display: flex; flex-wrap: wrap; gap: var(--space-3) var(--space-5); margin-top: var(--space-6); font-size: var(--text-body); font-weight: 600; }
.hero-links a { text-decoration: none; border-bottom: 2px solid currentColor; padding-bottom: 2px; }
@media (min-width: 64rem) { .hero .hero-text { grid-column: 1 / span 10; } }

/* ---------- Themes ---------- */
.themes { list-style: none; display: grid; grid-template-columns: 1fr; gap: var(--space-5) var(--space-6); margin-top: var(--space-6); }
@media (min-width: 48rem) { .themes { grid-template-columns: 1fr 1fr; } }
.themes h3 { font-size: var(--text-h3); line-height: var(--leading-heading); }
.themes p { margin-top: var(--space-2); color: var(--color-text-muted); }

/* ---------- Findings ----------
   The list sits directly in the section grid. On wide screens each finding is a
   12-column row: text in columns 1-5, its figure in columns 6-12. */
.findings { list-style: none; display: grid; gap: var(--space-7); margin-top: var(--space-4); min-width: 0; }
.finding { display: grid; gap: var(--space-5); align-items: start; min-width: 0; }
.finding + .finding { border-top: 1px solid var(--color-rule); padding-top: var(--space-7); }
.finding-text { display: grid; gap: var(--space-3); align-content: start; min-width: 0; }
.finding .source { font-size: var(--text-small); color: var(--color-text-muted); }
.finding h3 { font-size: var(--text-h3); line-height: var(--leading-heading); max-width: 28em; }
.finding-text p { max-width: var(--measure); }
@media (min-width: 64rem) {
  .findings { grid-column: 1 / -1; gap: var(--space-8); margin-top: var(--space-5); }
  .finding { grid-template-columns: repeat(12, minmax(0, 1fr)); column-gap: var(--space-5); }
  .finding + .finding { padding-top: var(--space-8); }
  .finding-text { grid-column: 1 / span 5; }
  .finding .fig { grid-column: 6 / span 7; }
}

/* ---------- Figures ----------
   Charts are HTML/CSS, so every label stays at real size (16px or more) at any width.
   Bars take their length from data: --v (value) over --max (scale end), on a zero-based
   scale. --vw reserves room after the longest bar for its value label. */
.fig {
  --fig-outline: #8C8B85;   /* warm neutral for outlined marks, 3.4:1 on white */
  container: fig / inline-size;
  margin: 0; min-width: 0;
  border-top: 1px solid var(--color-text);
  padding-top: var(--space-3);
}
.fig-title { font-weight: 600; font-size: var(--text-body); line-height: 1.35; max-width: 34em; }
.fig-chart { margin-top: var(--space-4); }
.fig-caption { margin-top: var(--space-4); font-size: var(--text-small); line-height: 1.5; color: var(--color-text-muted); max-width: 46em; overflow-wrap: break-word; }
.fig-plotbox { container: plot / inline-size; min-width: 0; --lw: 6.5rem; --vw: 4.75rem; }
.fig-plotbox--long { --lw: 11rem; --vw: 4rem; }
.fig-label { font-size: var(--text-small); line-height: 1.3; }
.fig-value { font-size: var(--text-small); line-height: 1.3; font-variant-numeric: tabular-nums; white-space: nowrap; }
.fig-unit-label, .fig-note { font-size: var(--text-small); line-height: 1.4; color: var(--color-text-muted); max-width: 34em; }
.fig-unit-label { margin-bottom: var(--space-4); }
.fig-note { margin-top: var(--space-3); }

/* Horizontal bars. Narrow: label above its bar. Wider: label column on the left. */
.fig-bars { list-style: none; display: grid; gap: var(--space-3); --ext: 0px; }
.fig-bars > li, .fig-axis { display: grid; grid-template-columns: minmax(0, 1fr); row-gap: var(--space-1); align-items: center; }
.fig-track { position: relative; display: flex; align-items: center; gap: var(--space-2); min-width: 0; min-height: 1.375rem; }
.fig-track::before { content: ""; position: absolute; left: 0; top: calc(-1 * var(--ext)); bottom: calc(-1 * var(--ext)); width: 1px; background: var(--color-text-muted); }
.fig-bar { flex: none; height: 1.375rem; width: calc(var(--v) / var(--max) * (100% - var(--vw))); background: var(--color-chart-muted); border-radius: 0 4px 4px 0; }
.fig-bar--hi { background: var(--color-accent); }
.fig-axis { margin-top: var(--space-2); }
.fig-axis-ticks { grid-column: -2 / -1; position: relative; height: 1.5rem; font-size: var(--text-small); line-height: 1.5rem; color: var(--color-text-muted); font-variant-numeric: tabular-nums; }
.fig-axis-ticks > span { position: absolute; top: 0; left: calc(var(--t) / var(--max) * (100% - var(--vw))); transform: translateX(-50%); white-space: nowrap; }
.fig-axis-ticks > span:first-child { transform: none; }
@container plot (min-width: 20rem) {
  .fig-plotbox:not(.fig-plotbox--long) .fig-bars { --ext: calc(var(--space-3) / 2); }
  .fig-plotbox:not(.fig-plotbox--long) .fig-bars > li,
  .fig-plotbox:not(.fig-plotbox--long) .fig-axis { grid-template-columns: var(--lw) minmax(0, 1fr); column-gap: var(--space-3); }
}
@container plot (min-width: 30rem) {
  .fig-plotbox--long .fig-bars { --ext: calc(var(--space-3) / 2); }
  .fig-plotbox--long .fig-bars > li,
  .fig-plotbox--long .fig-axis { grid-template-columns: var(--lw) minmax(0, 1fr); column-gap: var(--space-3); }
}

/* Two panels with their own scales (small multiples), side by side when there is room. */
.fig-panels { display: grid; gap: var(--space-5); }
.fig-panel-head { font-size: var(--text-small); line-height: 1.4; color: var(--color-text-muted); margin-bottom: var(--space-3); }
.fig-total { display: block; font-size: 1.75rem; line-height: 1.2; font-weight: 600; color: var(--color-text); }
/* Panels stay stacked inside the findings column so bars keep enough length; side by side only in very wide figures. */
@container fig (min-width: 56rem) {
  .fig-panels { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--space-5); }
}

/* Diverging bars around a dashed zero line. --min/--max set the scale. */
.fig-div { --vw: 5rem; --z: calc((0 - var(--min)) / (var(--max) - var(--min))); }
.fig-div-rows { display: grid; row-gap: var(--space-3); --ext: 0px; --lw: 11.5rem; }
.fig-div-row { display: grid; grid-template-columns: minmax(0, 1fr) var(--vw); column-gap: var(--space-3); row-gap: var(--space-1); align-items: center; }
.fig-div-row > .fig-label { grid-column: 1 / -1; }
.fig-div-row:not(.is-hi, .fig-div-row--group) > .fig-label, .fig-div-row:not(.is-hi) > .fig-value { color: var(--color-text-muted); }
.fig-div-row--group > .fig-label { font-weight: 600; }
.fig-div-row--group > .fig-div-plot { display: none; }
.fig-div-row--group + .fig-div-row { margin-top: calc(-1 * var(--space-2)); }
.fig-div-plot { position: relative; height: 1.375rem; min-width: 0; }
.fig-div-plot::before { content: ""; position: absolute; top: calc(-1 * var(--ext)); bottom: calc(-1 * var(--ext)); left: calc(var(--z) * 100%); border-left: 1px dashed var(--color-text-muted); }
.fig-div-bar {
  position: absolute; top: 0; bottom: 0;
  left: calc((min(var(--v), 0) - var(--min)) / (var(--max) - var(--min)) * 100%);
  width: calc((max(var(--v), 0) - min(var(--v), 0)) / (var(--max) - var(--min)) * 100%);
  background: var(--color-chart-muted); border-radius: 0 4px 4px 0;
}
.fig-div-bar--neg { border-radius: 4px 0 0 4px; }
.fig-div-row.is-hi .fig-div-bar { background: var(--color-accent); }
.fig-div-ticks { grid-column: 1; position: relative; height: 1.5rem; font-size: var(--text-small); line-height: 1.5rem; color: var(--color-text-muted); font-variant-numeric: tabular-nums; }
.fig-div-ticks > span { position: absolute; top: 0; left: calc((var(--t) - var(--min)) / (var(--max) - var(--min)) * 100%); transform: translateX(-50%); white-space: nowrap; }
.fig-div-ticks > span:first-child { transform: none; }
@container plot (min-width: 30rem) {
  .fig-div-rows { --ext: calc(var(--space-3) / 2); }
  .fig-div-row { grid-template-columns: var(--lw) minmax(0, 1fr) var(--vw); }
  .fig-div-row > .fig-label { grid-column: auto; }
  .fig-div-row--group > .fig-div-plot { display: block; height: auto; align-self: stretch; }
  .fig-div-row--group + .fig-div-row { margin-top: 0; }
  .fig-div-ticks { grid-column: 2; }
}
@container plot (min-width: 40rem) {
  .fig-div-rows { --lw: 14rem; }
}

/* Unit chart: one square per item, with a muted context bar kept apart below. */
.fig-units-wrap { display: grid; gap: var(--space-4); align-items: center; }
.fig-units { display: grid; grid-template-columns: repeat(10, 1.25rem); gap: 0.375rem; }
.fig-unit { display: block; width: 1.25rem; height: 1.25rem; background: var(--color-accent); }
.fig-swatch { flex: none; width: 1rem; height: 1rem; background: var(--color-accent); }
.fig-unit--open, .fig-swatch--open { background: var(--color-bg); border: 2px solid var(--fig-outline); }
.fig-stat { font-size: var(--text-small); line-height: 1.4; max-width: 20em; }
.fig-stat-num { display: block; font-size: 2.75rem; line-height: 1.05; font-weight: 600; letter-spacing: -0.01em; margin-bottom: var(--space-2); }
@container fig (min-width: 30rem) {
  .fig-units-wrap { grid-template-columns: auto minmax(0, 1fr); column-gap: var(--space-5); }
  .fig-units { order: -1; }
}
.fig-key { list-style: none; display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-5); margin-top: var(--space-4); font-size: var(--text-small); line-height: 1.4; }
.fig-key li { display: flex; align-items: center; gap: var(--space-2); }
.fig-context { margin-top: var(--space-5); padding-top: var(--space-3); border-top: 1px solid var(--color-rule); font-size: var(--text-small); line-height: 1.4; color: var(--color-text-muted); }
.fig-ctx-bar { display: block; margin-top: var(--space-2); max-width: 24rem; height: 0.75rem; border: 1px solid var(--color-chart-muted); }
.fig-ctx-bar > span { display: block; height: 100%; width: calc(var(--v) / var(--max) * 100%); background: var(--color-chart-muted); }

@media print {
  .fig { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .finding, .fig { break-inside: avoid; }
}

/* Older shared chart rules; .chart is still used on Coverage Watch. */
.chart { margin: var(--space-4) 0 0; max-width: 44rem; }
.chart-title { font-family: var(--font-sans); font-weight: 600; font-size: var(--text-body); line-height: 1.35; }
.chart svg { margin-top: var(--space-3); width: 100%; }
.chart svg text { font-family: var(--font-sans); font-size: 16px; fill: var(--color-text); }
.chart svg .val { font-variant-numeric: tabular-nums; }
.chart figcaption { font-size: var(--text-small); color: var(--color-text-muted); margin-top: var(--space-2); }

/* ---------- Feature band (Coverage Watch) ---------- */
.feature h2 { max-width: 20em; }
.text-link { font-weight: 600; text-decoration: none; border-bottom: 2px solid currentColor; padding-bottom: 2px; }

/* ---------- Publications ---------- */
.filters { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-5); }
.filters button {
  font: inherit; font-size: var(--text-small); color: var(--color-text);
  background: var(--color-bg); border: 1px solid var(--color-rule); border-radius: 999px;
  padding: 0.4rem 1rem; cursor: pointer; min-height: 2.75rem;
}
.filters button[aria-pressed="true"] { background: var(--color-text); color: var(--color-bg); border-color: var(--color-text); }
.pubs { list-style: none; margin-top: var(--space-5); }
.pubs li { padding-block: var(--space-4); border-top: 1px solid var(--color-rule); max-width: 46rem; }
.pubs li:last-child { border-bottom: 1px solid var(--color-rule); }
.pubs a { color: var(--color-text); text-decoration: none; font-weight: 600; line-height: 1.4; }
.pubs a:hover { color: var(--color-accent); text-decoration: underline; }
.pub-meta { display: block; margin-top: var(--space-1); font-size: var(--text-small); color: var(--color-text-muted); line-height: 1.5; }
.pub-meta b { font-weight: 600; color: var(--color-text); }
.pubs li[hidden] { display: none; }
.pubs-more { margin-top: var(--space-5); display: flex; flex-wrap: wrap; gap: var(--space-3) var(--space-5); align-items: center; font-size: var(--text-small); }
.button { font: inherit; font-size: var(--text-small); font-weight: 600; color: var(--color-bg); background: var(--color-text); border: 0; border-radius: 999px; padding: 0.6rem 1.25rem; cursor: pointer; min-height: 2.75rem; }
.button[hidden] { display: none; }

/* ---------- People ---------- */
.person { display: grid; gap: var(--space-5); align-items: start; }
@media (min-width: 48rem) { .person { grid-template-columns: 11rem minmax(0, 1fr); gap: var(--space-6); } }
.headshot {
  width: 11rem; height: auto; aspect-ratio: 1 / 1; object-fit: cover;
  background: var(--color-band); border: 1px solid var(--color-rule);
}
.person h3 { font-size: var(--text-h3); }
.person .role { color: var(--color-text-muted); margin-top: var(--space-1); }
.person .prose > * + * { margin-top: var(--space-3); }
.person .prose { margin-top: var(--space-4); }
.training { list-style: none; font-size: var(--text-small); color: var(--color-text-muted); }
.training li + li { margin-top: var(--space-1); }
.person-links { list-style: none; display: flex; flex-wrap: wrap; gap: 0 var(--space-4); margin-top: var(--space-2); font-size: var(--text-small); }
.person-links a { display: inline-block; padding-block: var(--space-1); }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--color-rule); padding-block: var(--space-6) var(--space-7); font-size: var(--text-small); color: var(--color-text-muted); }
.site-footer .wrap { display: grid; gap: var(--space-3); }
@media (min-width: 48rem) { .site-footer .wrap { grid-template-columns: 1fr auto; } }
.site-footer ul { list-style: none; display: flex; flex-wrap: wrap; gap: var(--space-4); }

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
@media print { .site-nav, .filters, .pubs-more { display: none; } .pubs li[hidden] { display: block; } }

/* HTML bar chart: text stays at real size on every screen */
.bars { list-style: none; margin-top: var(--space-4); display: grid; gap: var(--space-3); }
.bars li { display: grid; grid-template-columns: 6.5rem minmax(0, 1fr); align-items: center; gap: var(--space-3); }
.bars .bar-label { font-size: var(--text-small); }
.bars .bar-track { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.bars .bar { height: 1.75rem; background: var(--color-chart-muted); border-radius: 2px; flex: none; }
.bars .bar--hi { background: var(--color-accent); }
.bars .bar-value { font-size: var(--text-small); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bars .bar-value b { font-weight: 600; }
