/* ── Design tokens ──────────────────────────────────────────────────────── */
:root {
  --c-brand:       #2c5f8a;
  --c-brand-light: #4a87b8;
  --c-brand-dark:  #1a3f5f;
  --c-accent:      #e05c2a;
  --c-bg:          #f8f9fb;
  --c-surface:     #ffffff;
  --c-border:      #d8dde6;
  --c-text:        #1a1d23;
  --c-text-muted:  #5a6070;
  --c-green:       #2a7a4b;
  --c-red:         #c0392b;
  --c-amber:       #d4810a;

  --stage-definitive:      #2a7a4b;
  --stage-early-efficacy:  #2c5f8a;
  --stage-feasibility:     #d4810a;
  --stage-development:     #888;

  --radius: 6px;
  --shadow: 0 1px 4px rgba(0,0,0,.12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "SFMono-Regular", Consolas, monospace;
}

/* ── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-size: 15px;
  color: var(--c-text);
  background: var(--c-bg);
  line-height: 1.5;
}

a { color: var(--c-brand); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible { outline: 2px solid var(--c-brand); outline-offset: 2px; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.site-header {
  background: var(--c-brand-dark);
  color: #fff;
  padding: 1rem 1.5rem;
}
.site-header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: .25rem;
}
.site-header .subtitle {
  font-size: .85rem;
  opacity: .8;
}

/* ── Provenance banner ───────────────────────────────────────────────────── */
.provenance-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1.5rem;
  padding: .5rem 1.5rem;
  background: var(--c-brand);
  color: #e8f0f8;
  font-size: .8rem;
}
.provenance-bar strong { color: #fff; }

/* ── Layout ─────────────────────────────────────────────────────────────── */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ── Section card ────────────────────────────────────────────────────────── */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin: 1rem 0;
  box-shadow: var(--shadow);
}
.card h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--c-brand-dark);
  margin-bottom: 1rem;
  padding-bottom: .5rem;
  border-bottom: 2px solid var(--c-brand-light);
}

/* ── Controls row ────────────────────────────────────────────────────────── */
.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1.5rem;
  align-items: center;
  margin-bottom: 1.25rem;
}

/* ── Domain tabs ─────────────────────────────────────────────────────────── */
.domain-tabs { display: flex; gap: .35rem; }
.tab {
  padding: .45rem 1.1rem;
  border: 1.5px solid var(--c-brand);
  border-radius: 999px;
  background: transparent;
  color: var(--c-brand);
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tab:hover { background: var(--c-brand-light); color: #fff; }
.tab.active, .tab[aria-selected="true"] { background: var(--c-brand); color: #fff; }
.tab:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; }

/* ── View selector ───────────────────────────────────────────────────────── */
.view-group { display: flex; align-items: center; gap: .5rem; }
.view-group label { font-size: .85rem; color: var(--c-text-muted); font-weight: 500; }
select {
  padding: .4rem .75rem;
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-surface);
  font-size: .85rem;
  color: var(--c-text);
  cursor: pointer;
}
select:focus { outline: 2px solid var(--c-brand); border-color: var(--c-brand); }

/* ── Forest plot ─────────────────────────────────────────────────────────── */
.forest-outer {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}
#forest-svg {
  display: block;
  min-width: 640px;
}

/* Study rows */
.forest-study-label {
  font-size: 11.5px;
  fill: var(--c-text);
}
.forest-measure-label {
  font-size: 10px;
  fill: var(--c-text-muted);
}
.forest-ci-line { stroke-width: 1.5px; stroke-linecap: round; }
.forest-square { rx: 2; ry: 2; }
.forest-diamond { stroke-width: 1.5; }
.forest-pi-line { stroke-dasharray: 5 3; stroke-width: 1.5; opacity: .7; }
.forest-refline { stroke: #999; stroke-dasharray: 3 3; stroke-width: 1; }
.forest-axis path, .forest-axis line { stroke: var(--c-border); }
.forest-axis text { font-size: 10px; fill: var(--c-text-muted); }

.forest-col-header { font-size: 11px; font-weight: 600; fill: var(--c-text-muted); }
.forest-col-value  { font-size: 11px; fill: var(--c-text); font-family: var(--mono); }
.forest-col-value.pooled { font-weight: 700; fill: var(--c-brand-dark); }

/* Stage colours */
.stage-definitive     { fill: var(--stage-definitive); }
.stage-early_efficacy { fill: var(--stage-early-efficacy); }
.stage-feasibility_pilot { fill: var(--stage-feasibility); }
.stage-development    { fill: var(--stage-development); }

.group-label {
  font-size: 11px;
  font-weight: 700;
  fill: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* ── Stage legend ─────────────────────────────────────────────────────────── */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem .9rem;
  margin-top: .75rem;
  font-size: .8rem;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: .3rem;
}
.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}
.swatch-definitive     { background: var(--stage-definitive); }
.swatch-early_efficacy { background: var(--stage-early-efficacy); }
.swatch-feasibility_pilot { background: var(--stage-feasibility); }
.swatch-development    { background: var(--stage-development); }

/* ── Summary stats bar ────────────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem 1.25rem;
  font-size: .85rem;
  margin-top: 1rem;
  padding-top: .75rem;
  border-top: 1px solid var(--c-border);
  color: var(--c-text-muted);
}
.stats-bar strong { color: var(--c-text); }

/* ── Study table ─────────────────────────────────────────────────────────── */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: .75rem;
}
.filter-row select { font-size: .82rem; }
.filter-row input {
  padding: .4rem .75rem;
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius);
  font-size: .82rem;
  width: 200px;
}
.filter-row input:focus { outline: 2px solid var(--c-brand); border-color: var(--c-brand); }

.study-table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .83rem;
}
thead th {
  background: var(--c-bg);
  border-bottom: 2px solid var(--c-border);
  padding: .5rem .65rem;
  text-align: left;
  font-weight: 600;
  color: var(--c-text-muted);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
}
thead th button {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  font: inherit;
  padding: 0;
}
tbody tr { border-bottom: 1px solid var(--c-border); }
tbody tr:hover { background: #f0f4f8; }
tbody td { padding: .45rem .65rem; vertical-align: top; }
td.num { text-align: right; font-family: var(--mono); font-size: .81rem; }
td.g-val { font-family: var(--mono); font-size: .81rem; font-weight: 600; }
td.g-val.neg { color: var(--c-green); }
td.g-val.pos { color: var(--c-red); }

.badge {
  display: inline-block;
  padding: .12rem .45rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-stage-definitive     { background: #d4edda; color: var(--c-green); }
.badge-stage-early_efficacy { background: #d8eaf7; color: var(--c-brand); }
.badge-stage-feasibility_pilot { background: #fdecd1; color: var(--c-amber); }
.badge-stage-development    { background: #e8e8e8; color: #555; }

/* ── World map ────────────────────────────────────────────────────────────── */
#world-map-svg { display: block; width: 100%; }
.map-country { fill: #dde8f0; stroke: #fff; stroke-width: .5; }
.map-country:hover { fill: #b8d0e8; }
.map-study-dot { cursor: pointer; transition: r .2s; }
.map-study-dot:hover { filter: brightness(1.2); }
.map-tooltip {
  position: absolute;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: .4rem .65rem;
  font-size: .8rem;
  pointer-events: none;
  box-shadow: var(--shadow);
  z-index: 100;
  max-width: 200px;
}

/* ── Footer ──────────────────────────────────────────────────────────────── */
footer {
  background: var(--c-brand-dark);
  color: #cad8e8;
  padding: 1.5rem;
  margin-top: 2rem;
  font-size: .85rem;
}
.footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  max-width: 900px;
}
footer h3 { font-size: .9rem; color: #fff; margin-bottom: .4rem; }
footer a { color: #9bbdd8; }
footer a:hover { color: #fff; }
footer code {
  display: block;
  background: rgba(0,0,0,.25);
  border-radius: 4px;
  padding: .4rem .6rem;
  font-size: .78rem;
  font-family: var(--mono);
  color: #d5e8f8;
  margin-top: .35rem;
  overflow-x: auto;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 680px) {
  .site-header h1 { font-size: 1.1rem; }
  .controls-row { gap: .5rem; }
  .card { padding: 1rem; }
}

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