/* ── Design tokens (from the validated data-viz reference palette) ── */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #256abf;
  --accent-ink: #184f95;
  --good: #006300;
  --nodata: #e6e5e0;

  /* Sequential blue ramp — magnitude (overall score) */
  --seq-1: #cde2fb;
  --seq-2: #9ec5f4;
  --seq-3: #6da7ec;
  --seq-4: #3987e5;
  --seq-5: #256abf;
  --seq-6: #184f95;
  --seq-7: #0d366b;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.06);
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --accent-ink: #6da7ec;
    --good: #0ca30c;
    --nodata: #2c2c2a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --accent: #3987e5;
  --accent-ink: #6da7ec;
  --good: #0ca30c;
  --nodata: #2c2c2a;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--page);
  line-height: 1.5;
}
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }

/* ── Header ── */
.site-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem clamp(1rem, 3vw, 2rem) 0.75rem;
  max-width: 1400px;
  margin: 0 auto;
}
.site-header h1 { font-size: clamp(1.4rem, 3vw, 1.9rem); display: flex; align-items: center; gap: 0.4rem; }
.logo-mark { font-size: 1.1em; line-height: 1; }
.tagline { margin: 0.25rem 0 0; color: var(--text-secondary); max-width: 46ch; }
.theme-toggle {
  flex: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 999px;
  width: 40px; height: 40px;
  font-size: 1.2rem;
  cursor: pointer;
}
.theme-toggle:hover { color: var(--text-primary); }

/* ── Header actions + What's new ── */
.header-actions { flex: none; display: flex; align-items: center; gap: 0.5rem; }
.whatsnew-btn {
  position: relative;
  display: inline-flex; align-items: center; gap: 0.35rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 0 0.85rem; height: 40px;
  font-size: 0.85rem; font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.whatsnew-btn:hover { color: var(--text-primary); }
.whatsnew-badge {
  min-width: 18px; height: 18px; padding: 0 5px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px;
  background: #d03b3b; color: #fff;
  font-size: 0.7rem; font-weight: 700; line-height: 1;
}

/* ── Modal (What's new) ── */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 1rem; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45); }
.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: 85vh; overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.1rem 1.25rem 1.4rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.modal-head h2 { font-size: 1.15rem; }
.modal-close {
  flex: none; border: none; background: none; color: var(--muted);
  font-size: 1.1rem; cursor: pointer; line-height: 1; padding: 0.25rem;
}
.modal-close:hover { color: var(--text-primary); }

/* ── Changelog entries ── */
.changelog { list-style: none; margin: 0.9rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.85rem; }
.changelog-entry { border-top: 1px solid var(--border); padding-top: 0.85rem; }
.changelog-entry:first-child { border-top: none; padding-top: 0; }
.cl-meta { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.3rem; }
.cl-title { font-weight: 650; color: var(--text-primary); }
.cl-body { margin: 0.2rem 0 0; line-height: 1.45; }
.tag {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em;
  padding: 0.12rem 0.45rem; border-radius: 999px; white-space: nowrap;
}
.tag-data { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent-ink); }
.tag-weighting { background: color-mix(in srgb, #8a5cf6 20%, transparent); color: #7a4fe0; }
.tag-ui { background: color-mix(in srgb, #0ca30c 18%, transparent); color: #0a8a0a; }
:root[data-theme="dark"] .tag-weighting { color: #b49bff; }
:root[data-theme="dark"] .tag-ui { color: #4fd44f; }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .tag-weighting { color: #b49bff; }
  :root:where(:not([data-theme="light"])) .tag-ui { color: #4fd44f; }
}

.banner {
  max-width: 1400px;
  margin: 0.5rem auto 0;
  padding: 0.6rem 1rem;
  background: color-mix(in srgb, #eda100 22%, var(--surface));
  border: 1px solid color-mix(in srgb, #eda100 45%, var(--border));
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--text-primary);
  width: calc(100% - clamp(2rem, 6vw, 4rem));
}

/* ── Layout ── */
.layout {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr) minmax(280px, 360px);
  gap: 1rem;
  max-width: 1400px;
  margin: 1rem auto;
  padding: 0 clamp(1rem, 3vw, 2rem);
  align-items: start;
}
@media (max-width: 1080px) {
  .layout { grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); }
  .map-panel { grid-column: 1 / -1; order: 3; }
}
@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .map-panel { order: 0; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}
.panel-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.panel-head h2 { font-size: 1.05rem; }
.link-btn {
  border: none; background: none; color: var(--accent); cursor: pointer;
  font: inherit; font-size: 0.85rem; padding: 0;
}
.link-btn:hover { text-decoration: underline; }

/* ── Sliders ── */
.sliders { display: flex; flex-direction: column; gap: 1rem; margin-top: 0.75rem; }
.slider-row label { display: flex; justify-content: space-between; align-items: baseline; font-weight: 550; }
.slider-row .weight-val {
  font-variant-numeric: tabular-nums;
  color: var(--accent-ink);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  border-radius: 6px; padding: 0 0.4rem; min-width: 1.8rem; text-align: center;
}
.slider-row input[type="range"] { width: 100%; accent-color: var(--accent); margin-top: 0.35rem; cursor: pointer; }
.slider-row .metric-hint { color: var(--muted); font-size: 0.75rem; }

/* ── Variant picker (e.g. rent by bedroom count) ── */
.variant-pick { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.4rem; }
.variant-label { color: var(--muted); font-size: 0.75rem; white-space: nowrap; }
.seg {
  display: inline-flex; border: 1px solid var(--border); border-radius: 999px;
  overflow: hidden; background: var(--surface);
}
.seg-btn {
  border: none; background: transparent; color: var(--text-secondary);
  font: inherit; font-size: 0.75rem; font-variant-numeric: tabular-nums;
  padding: 0.2rem 0.6rem; cursor: pointer; border-right: 1px solid var(--border);
}
.seg-btn:last-child { border-right: none; }
.seg-btn:hover { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.seg-btn.active { background: var(--accent); color: #fff; font-weight: 600; }

/* ── Map ── */
.map-container { width: 100%; }
.map-wrap { position: relative; width: 100%; }
.map-container svg { width: 100%; height: auto; display: block; touch-action: none; cursor: grab; }
.map-container svg:active { cursor: grabbing; }
.map-controls {
  position: absolute; top: 8px; right: 8px;
  display: flex; flex-direction: column; gap: 4px;
}
.map-btn {
  width: 30px; height: 30px; display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface) 88%, transparent); color: var(--text-primary);
  font-size: 1.05rem; line-height: 1; cursor: pointer; backdrop-filter: blur(2px);
}
.map-btn:hover { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); border-color: var(--accent); }
.area path {
  stroke: var(--surface);
  stroke-width: 0.4;
  transition: fill 0.12s ease;
  cursor: pointer;
}
.area path:hover { stroke: var(--text-primary); stroke-width: 1; }
.area path.selected { stroke: var(--text-primary); stroke-width: 1.4; }

/* ── View toggle ── */
.view-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.vt-btn {
  border: none; background: var(--surface); color: var(--text-secondary);
  font: inherit; font-size: 0.82rem; padding: 0.3rem 0.8rem; cursor: pointer;
}
.vt-btn.active { background: var(--accent); color: #fff; }

/* ── Rating filter chips ── */
.chips { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.75rem; }
.chip {
  display: flex; align-items: center; gap: 0.5rem;
  border: 1px solid var(--border); background: var(--surface); color: inherit;
  font: inherit; font-size: 0.86rem; text-align: left;
  padding: 0.45rem 0.6rem; border-radius: var(--radius-sm); cursor: pointer; width: 100%;
}
.chip:hover { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.chip.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--surface)); font-weight: 600; }
.chip .swatch { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.chip .chip-count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ── Unit markers on the map ── */
.unit-marker { stroke: var(--surface); stroke-width: 0.8; cursor: pointer; transition: r 0.1s ease; }
.unit-marker:hover { stroke: var(--text-primary); stroke-width: 1.2; }
.unit-marker.selected { stroke: var(--text-primary); stroke-width: 1.6; }

/* GP cluster bubbles: a coloured circle with a count, split on zoom */
.cluster-bubble { stroke: var(--surface); stroke-width: 1; opacity: 0.9; cursor: zoom-in; }
.cluster-bubble:hover { stroke: var(--text-primary); stroke-width: 1.4; opacity: 1; }
.cluster-count { fill: #fff; font-weight: 700; pointer-events: none; -webkit-user-select: none; user-select: none; }

/* ── Rating badge (in unit list / detail) ── */
.rating-badge {
  display: inline-block; font-size: 0.72rem; font-weight: 650;
  padding: 0.05rem 0.45rem; border-radius: 999px; color: #fff; white-space: nowrap;
}

/* ── Trend indicator ── */
.trend { font-size: 0.8rem; vertical-align: middle; cursor: help; }
.trend.up { color: #0ca30c; }
.trend.down { color: #d03b3b; }
.trend.flat { color: var(--muted); }

/* ── Rating history chart ── */
.chart-wrap { margin: 0.6rem 0 0.2rem; }
.rating-chart { width: 100%; height: auto; display: block; }
.rating-chart .ch-grid { stroke: var(--gridline); stroke-width: 1; }
.rating-chart .ch-ylabel { fill: var(--muted); font-size: 9px; text-anchor: end; }
.rating-chart .ch-xlabel { fill: var(--muted); font-size: 9px; }
.rating-chart .ch-line { fill: none; stroke: var(--text-secondary); stroke-width: 2; stroke-linejoin: round; }
.rating-chart .ch-dot { stroke: var(--surface); stroke-width: 1.2; cursor: pointer; }
.rating-chart .ch-dot.sel { stroke: var(--text-primary); stroke-width: 1.6; }

/* ── Key-question breakdown ── */
.kq-block { margin-top: 0.6rem; }
.kq-head { font-size: 0.82rem; margin-bottom: 0.35rem; }
.kq-list { display: flex; flex-direction: column; gap: 3px; }
.kq-item { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; font-size: 0.82rem; }
.kq-badge { font-size: 0.7rem; font-weight: 650; color: #fff; padding: 0.05rem 0.45rem; border-radius: 999px; white-space: nowrap; }
.kq-badge.kq-none { background: transparent; color: var(--muted); border: 1px solid var(--border); font-weight: 500; }

/* ── Overall (whole-hospital) assessment context ── */
.overall-block { margin-top: 0.6rem; padding: 0.5rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.overall-block.concern { border-color: color-mix(in srgb, #d03b3b 45%, var(--border)); background: color-mix(in srgb, #d03b3b 8%, var(--surface)); }

/* Area detail → shortlist of nearest maternity units */
.mat-shortlist { margin: 0.4rem 0 0.7rem; }
.mat-shortlist-head { font-size: 0.82rem; font-weight: 600; margin-bottom: 0.3rem; }
.mini-unit-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.mini-unit {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 0.5rem;
  width: 100%; text-align: left; padding: 0.35rem 0.45rem;
  background: var(--surface-2, color-mix(in srgb, var(--accent) 5%, var(--surface)));
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: inherit; font: inherit; cursor: pointer;
}
.mini-unit:hover:not(.nolink) { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.mini-unit.nolink { cursor: default; opacity: 0.75; }
.mini-unit .mu-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.mini-unit .mu-meta { color: var(--muted); font-size: 0.76rem; white-space: nowrap; }

/* GP-practices block: rating-mix bar + example rows */
.gp-block .gp-summary, .mat-shortlist .gp-summary { font-size: 0.82rem; margin-bottom: 0.35rem; }
.gp-age-note { margin: -0.1rem 0 0.4rem; line-height: 1.35; }
.gp-stale { color: var(--warn, #b26a00); font-weight: 600; } /* rating older than GP_STALE_YEARS */
.gp-bar { display: flex; height: 9px; border-radius: 5px; overflow: hidden; margin-bottom: 0.4rem; background: var(--border); }
.gp-bar .gp-seg { height: 100%; }
.gp-block .mini-unit-list li {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 0.5rem;
  padding: 0.28rem 0.45rem;
  background: var(--surface-2, color-mix(in srgb, var(--accent) 5%, var(--surface)));
  border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.82rem;
}
.gp-block .mini-unit-list .mu-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.gp-block .mini-unit-list .mu-meta { color: var(--muted); font-size: 0.76rem; white-space: nowrap; }
.gp-block .mini-unit-list a { text-decoration: none; }

.legend { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.5rem; }
.legend-label { font-size: 0.75rem; color: var(--muted); }
.legend-bar {
  flex: 1; height: 10px; border-radius: 5px;
  background: linear-gradient(90deg, var(--seq-1), var(--seq-2), var(--seq-3), var(--seq-4), var(--seq-5), var(--seq-6), var(--seq-7));
}

.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--text-primary);
  color: var(--surface);
  padding: 0.35rem 0.55rem;
  border-radius: 6px;
  font-size: 0.8rem;
  z-index: 20;
  box-shadow: var(--shadow);
  transform: translate(-50%, calc(-100% - 10px));
  white-space: nowrap;
}
.tooltip b { font-variant-numeric: tabular-nums; }

/* ── Ranking ── */
.ranking { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; max-height: 620px; overflow-y: auto; }
.rank-item {
  display: grid; grid-template-columns: 1.6rem 1fr auto; align-items: center; gap: 0.5rem;
  width: 100%; text-align: left;
  border: none; background: none; color: inherit; font: inherit;
  padding: 0.4rem 0.5rem; border-radius: var(--radius-sm); cursor: pointer;
}
.rank-item:hover, .rank-item.selected { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.rank-item .rank-num { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.rank-item .rank-name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-item .rank-nation { color: var(--muted); font-size: 0.75rem; }
.rank-item .rank-score {
  font-variant-numeric: tabular-nums; font-weight: 650;
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.score-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ── Detail ── */
.detail { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.85rem; margin-bottom: 0.85rem; background: color-mix(in srgb, var(--accent) 5%, var(--surface)); }
.detail h3 { font-size: 1.1rem; }
.detail .detail-sub { color: var(--muted); font-size: 0.8rem; margin: 0.1rem 0 0.6rem; }
.detail .overall-badge { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.4rem; }
.domain-block { margin-top: 0.7rem; }
.domain-block .domain-row { display: flex; justify-content: space-between; font-size: 0.85rem; font-weight: 550; }
.bar { height: 7px; border-radius: 4px; background: var(--gridline); overflow: hidden; margin-top: 3px; }
.bar > span { display: block; height: 100%; border-radius: 4px; background: var(--accent); }
.metric-line { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--text-secondary); padding: 1px 0 1px 0.75rem; }
.metric-line .mv { font-variant-numeric: tabular-nums; color: var(--muted); }
.detail .close-detail { float: right; }

/* ── Footer ── */
.site-footer { max-width: 1400px; margin: 1.5rem auto 3rem; padding: 0 clamp(1rem, 3vw, 2rem); }
.site-footer summary { cursor: pointer; font-weight: 550; }
.sources-list { list-style: none; padding: 0; margin: 0.75rem 0 0; display: grid; gap: 0.5rem; }
.sources-list li { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.5rem 0.7rem; font-size: 0.82rem; }
.sources-list .src-name { font-weight: 600; }
.sources-list .src-meta { color: var(--muted); }
.sources-list a { color: var(--accent); }
.badge { display: inline-block; font-size: 0.68rem; font-weight: 650; padding: 0.05rem 0.4rem; border-radius: 999px; vertical-align: middle; }
.badge.synthetic { background: color-mix(in srgb, #eda100 25%, var(--surface)); color: var(--text-primary); border: 1px solid color-mix(in srgb, #eda100 45%, var(--border)); }
.badge.real { background: color-mix(in srgb, var(--good) 18%, var(--surface)); color: var(--good); font-variant-numeric: tabular-nums; }
