/* ═══════════════════════════════════════════════════════════════════════════
   Mental Health Radar — Dark dashboard theme
   ═══════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

/* ─── Design tokens ─────────────────────────────────────────────────────── */
:root {
  --bg:          #0b1017;
  --surface:     #111925;
  --surface-2:   #172030;
  --border:      #233448;
  --text:        #daeaf8;
  --muted:       #6090b4;
  --accent:      #38bdf8;
  --accent-dim:  rgba(56, 189, 248, 0.09);
  --accent-glow: 0 0 14px rgba(56, 189, 248, 0.22);

  /* Risk level palette — v4 equal-interval bands */
  --thriving:  #4ade80;
  --stable:    #7dd3fc;
  --oecd-base: #fde68a;
  --severe:    #fb923c;
  --crisis:    #f87171;

  --radius: 8px;
  --gap: 1.25rem;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", "Fira Code", ui-monospace, "Cascadia Code", monospace;
}

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

html { font-size: 16px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.55;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Very subtle scanline — just a hint of texture */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 3px,
    rgba(0, 0, 0, 0.025) 3px,
    rgba(0, 0, 0, 0.025) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

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

/* ─── Header ────────────────────────────────────────────────────────────── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.9rem 10%;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  isolation: isolate;          /* Safari: force own stacking context above map */
  -webkit-transform: translateZ(0);  /* Safari: force GPU compositing layer */
  transform: translateZ(0);
  box-sizing: border-box;
  width: 100%;
}

.site-logo {
  font-family: var(--sans);
  font-size: 1.34rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-shrink: 0;
}

.logo-icon {
  display: flex;
  align-items: center;
  color: var(--accent);
  flex-shrink: 0;
}
.logo-accent { color: var(--accent); }

/* LIVE badge */
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.39rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 0.15rem 0.55rem;
  background: rgba(56, 189, 248, 0.12);
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  flex-shrink: 0;
  animation: live-pulse 1.8s ease-in-out infinite;
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 5px #4ade80; }
  50%       { opacity: 0.2; box-shadow: none; }
}


.site-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  flex-shrink: 1;
  min-width: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Plain nav link (Dashboard) */
.nav-link {
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  padding: 0.3rem 0.6rem;
  text-decoration: none;
  transition: color 0.15s;
}
.nav-link:hover,
.nav-link.active { color: var(--text); text-decoration: none; }

/* Modal-trigger buttons */
.nav-btn {
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.32rem 0.75rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  white-space: nowrap;
}
.nav-btn:hover {
  color: var(--text);
  border-color: rgba(56, 189, 248, 0.4);
  background: var(--accent-dim);
}
.nav-btn--primary {
  color: #0f172a;
  background: linear-gradient(135deg, #38bdf8 0%, #22d3ee 100%);
  border-color: #38bdf8;
  font-size: 0.92rem;
  font-weight: 700;
  padding: 0.5rem 1.1rem;
  letter-spacing: 0.02em;
  box-shadow: 0 0 14px rgba(56,189,248,0.45), 0 0 4px rgba(56,189,248,0.25);
  animation: tools-pulse 3s ease-in-out infinite;
  transition: color 0.15s, background 0.15s, box-shadow 0.15s, transform 0.15s;
}
.nav-btn--primary:hover {
  background: linear-gradient(135deg, #7dd3fc 0%, #38bdf8 100%);
  box-shadow: 0 0 24px rgba(56,189,248,0.7), 0 0 8px rgba(56,189,248,0.4);
  transform: scale(1.04);
}
@keyframes tools-pulse {
  0%, 100% { box-shadow: 0 0 14px rgba(56,189,248,0.45), 0 0 4px rgba(56,189,248,0.25); }
  50%       { box-shadow: 0 0 22px rgba(56,189,248,0.7), 0 0 8px rgba(56,189,248,0.35); }
}

/* ─── Main layout ───────────────────────────────────────────────────────── */
main {
  flex: 1;
  padding: var(--gap) 1.5rem 0.25rem;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* ─── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  position: relative;
}

/* Subtle corner accents */
.card::before {
  content: '';
  position: absolute;
  top: -1px; left: -1px;
  width: 16px; height: 16px;
  border-top: 1px solid rgba(56, 189, 248, 0.3);
  border-left: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: var(--radius) 0 0 0;
  pointer-events: none;
}
.card::after {
  content: '';
  position: absolute;
  bottom: -1px; right: -1px;
  width: 16px; height: 16px;
  border-bottom: 1px solid rgba(56, 189, 248, 0.3);
  border-right: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 0 0 var(--radius) 0;
  pointer-events: none;
}

.card-title {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.75rem;
}
.card-title::before {
  content: '// ';
  color: var(--accent);
  opacity: 0.6;
}

/* ─── Map ───────────────────────────────────────────────────────────────── */
.map-card {
  border-left: none;
  border-right: none;
  border-radius: 0;
  padding: 0 1.5rem;
  height: calc(100dvh - 52px - 120px);
}

.map-card::before,
.map-card::after { display: none; }

#map-container {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#map-container svg {
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 0;
}

.state-path {
  stroke: #111925;
  stroke-width: 0.25;
  cursor: pointer;
  transition: opacity 0.15s, stroke 0.15s;
}

/* Admin1 subnational borders — hidden in global view; JS sets inline stroke
   on the selected country's regions via _setCountryAdminContext(iso2). */
.state-path.admin1-path {
  stroke: none;
  stroke-width: 0;
}
/* Fallback for US drill-down (inline styles from JS take precedence) */
.us-state-context .admin1-path {
  stroke: #374151;
  stroke-width: 0.25;
}
.state-path:hover    { opacity: 0.85; stroke: var(--text); stroke-width: 0.5; }
.state-path.selected { stroke: #000000; stroke-width: 2.5; opacity: 1; }

/* ─── Map bottom-left overlay (title + legend stacked) ─────────────────── */
.map-bottom-left {
  position: absolute;
  bottom: 0.6rem;
  left: 1.5rem;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.map-card .card-title {
  margin: 0;
}

/* ─── Map legend — horizontal row along bottom ──────────────────────────── */
.map-legend {
  display: flex;
  flex-wrap: wrap;
  flex-direction: row;
  gap: 0.4rem 1rem;
  margin: 0;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ─── Tooltip ───────────────────────────────────────────────────────────── */
#map-tooltip {
  position: fixed;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.82rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s;
  z-index: 200;
  max-width: 200px;
}

#map-tooltip.visible { opacity: 1; }
#map-tooltip .tt-state { font-weight: 600; color: var(--text); }
#map-tooltip .tt-score { color: var(--muted); font-size: 0.76rem; }

/* ─── Trend section ─────────────────────────────────────────────────────── */
.trend-section canvas { height: 160px; max-height: 160px; }

/* ─── State panel (reused classes for state-info-bar) ───────────────────── */
.panel-empty {
  color: var(--muted);
  font-size: 0.875rem;
  padding: 1rem 0;
}

/* State info bar */
.state-info-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.state-info-bar.hidden { display: none; }

.state-info-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.state-info-updated {
  font-size: 0.72rem;
  color: var(--muted);
  margin-left: auto;
}

/* Domains card */
.domains-section-card { display: flex; flex-direction: column; gap: 0.4rem; }

/* Expand button */
.expand-domains-btn {
  align-self: flex-start;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.72rem;
  font-family: var(--mono);
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  margin-top: 0.25rem;
}
.expand-domains-btn:hover { color: var(--text); border-color: var(--accent); }
.expand-domains-btn.hidden { display: none; }

/* Collapsed rest */
.domains-rest.hidden { display: none; }
.movers-section.hidden { display: none; }

.panel-composite-score {
  font-family: var(--mono);
  font-size: 2.8rem;
  font-weight: 700;
  line-height: 1;
  margin-left: auto;
}

.panel-risk-badge {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.3rem 0.6rem;
  border-radius: 5px;
  background: rgba(255,255,255,0.07);
}

/* SYNDEMIC badge */
.syndemic-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fde68a;
  background: rgba(253, 230, 138, 0.1);
  border: 1px solid rgba(253, 230, 138, 0.3);
  border-radius: 5px;
  padding: 0.25rem 0.5rem;
}

/* CONFIDENCE badge — /10 score with colour tier and component tooltip */
.confidence-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.70rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.22rem 0.55rem;
  border-radius: 5px;
  border: 1px solid transparent;
  cursor: default;
  white-space: nowrap;
  /* colour, border-color and background are set inline from Python-emitted values */
}

/* BVI modifier pill */
.bvi-pill {
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.bvi-value { font-weight: 600; color: var(--text); }

/* ─── Domain bars ───────────────────────────────────────────────────────── */
.domains-section { display: flex; flex-direction: column; gap: 0.48rem; }

.domain-item {
  display: flex;
  flex-direction: column;
}

#domains-top4, #domains-rest {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.6rem 1.5rem;
}

.domains-title {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.domains-title::before {
  content: '// ';
  color: var(--accent);
  opacity: 0.6;
}

.domain-row {
  display: grid;
  grid-template-columns: 1.5rem 1fr 2.5rem;
  align-items: center;
  gap: 0.4rem;
}

.domain-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  flex-shrink: 0;
}

.domain-name {
  font-size: 0.74rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.domain-score-val {
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 600;
  text-align: right;
}

/* ─── Top signals ───────────────────────────────────────────────────────── */
.signals-section {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.6;
}
.signals-section strong { color: var(--text); }

/* ─── State sparkline ───────────────────────────────────────────────────── */
.sparkline-section { display: flex; flex-direction: column; gap: 0.4rem; }

.sparkline-section .spark-label {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.sparkline-section .spark-label::before {
  content: '// ';
  color: var(--accent);
  opacity: 0.6;
}

.sparkline-section canvas { max-height: 70px; }

/* ─── Last-updated notice ───────────────────────────────────────────────── */
.last-updated {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: auto;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

/* ─── Score denom (/100 suffix) ─────────────────────────────────────────── */
.score-denom {
  font-family: var(--mono);
  font-size: 1rem;
  color: var(--muted);
}

/* ─── Domain list rows (Image-2 style) ──────────────────────────────────── */
.domain-list-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}
.domain-list-row:last-child { border-bottom: none; }

.domain-list-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 0 0 230px;
  min-width: 0;
}

.domain-list-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.domain-list-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.domain-list-source {
  font-size: 0.7rem;
  color: var(--muted);
  display: flex;
  align-items: baseline;
  min-width: 0;
}

.source-text {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.domain-list-source .freshness {
  flex-shrink: 0;
}

.domain-list-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}

.domain-bar-track {
  flex: 1;
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  overflow: hidden;
}

.domain-bar-fill {
  height: 100%;
  border-radius: 1px;
}

/* wrapper takes all flex space; position:relative required by Chart.js responsive mode */
.domain-sparkline-wrap {
  flex: 1;
  min-width: 0;
  position: relative;
  height: 28px;
}

.domain-sparkline {
  display: block;
  width: 100%;
  height: 100%;
}

/* ─── Freshness tier badges ──────────────────────────────────────────────── */
.freshness {
  font-size: 0.65rem;
  margin-left: 0.35rem;
  cursor: help;
}

.freshness.realtime { color: #4ade80; }
.freshness.recent   { color: #4ade80; }
.freshness.structural { color: #a78bfa; }

/* Pulsing dot for real-time only */
.freshness.realtime::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  margin-right: 3px;
  vertical-align: middle;
  animation: freshness-pulse 2s ease-in-out infinite;
}

/* Static dot for recent */
.freshness.recent::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  margin-right: 3px;
  vertical-align: middle;
}

/* Static dot for structural */
.freshness.structural::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #a78bfa;
  margin-right: 3px;
  vertical-align: middle;
}

@keyframes freshness-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Freshness tooltip — rendered to <body> via JS to avoid overflow:hidden clipping */
.freshness-tip {
  position: fixed;
  background: var(--bg-card, #1e1e2e);
  color: var(--fg, #e2e8f0);
  border: 1px solid var(--border, #334155);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 0.6rem;
  max-width: 280px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 9999;
  line-height: 1.4;
}
.freshness-tip.visible { opacity: 1; }

.domain-list-score {
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 700;
  min-width: 2rem;
  text-align: right;
}

/* ─── Risk level helpers ────────────────────────────────────────────────── */
[data-risk="Thriving"]   { color: var(--thriving);  }
[data-risk="Stable"]     { color: var(--stable);    }
[data-risk="OECD Base"]  { color: var(--oecd-base); }
[data-risk="Severe"]     { color: var(--severe);    }
[data-risk="Crisis"]     { color: var(--crisis);    }

/* ─── Footer ────────────────────────────────────────────────────────────── */
footer {
  background: var(--bg);
  padding: 0 0 0.25rem;
}
.footer-actions {
  display: flex;
  gap: 1.25rem;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 0 1.5rem;
  box-sizing: border-box;
}
.footer-btn {
  flex: 1;
  font-family: var(--sans);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid rgba(56, 189, 248, 0.5);
  border-radius: 8px;
  padding: 0.85rem 0;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.1);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.footer-btn:hover {
  color: var(--accent);
  border-color: rgba(56, 189, 248, 0.5);
  background: var(--accent-dim);
}

/* ─── Modals ────────────────────────────────────────────────────────────── */
dialog.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  max-width: 700px;
  width: 95vw;
  max-height: 84vh;
  padding: 0;
  overflow: hidden;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.65), var(--accent-glow);
  /* Centre in viewport regardless of browser defaults */
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
}
dialog.modal::backdrop {
  background: rgba(6, 10, 18, 0.85);
  backdrop-filter: blur(3px);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.modal-title {
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.modal-close {
  background: none;
  border: 1px solid transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.25rem 0.4rem;
  border-radius: 5px;
  transition: color 0.15s, border-color 0.15s;
}
.modal-close:hover { color: var(--text); border-color: var(--border); }

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  max-height: calc(84vh - 57px);
  line-height: 1.7;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.modal-body::-webkit-scrollbar {
  width: 5px;
}
.modal-body::-webkit-scrollbar-track {
  background: transparent;
}
.modal-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 99px;
}
.modal-body::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

/* Typography inside modals */
.modal-body h2 {
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: #8ecef4;
  margin: 1.1rem 0 0.3rem;
}
.modal-body h2:first-child { margin-top: 0; }

.modal-body h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin: 1rem 0 0.35rem;
}

.modal-body p {
  font-size: 0.88rem;
  color: rgba(218, 234, 248, 0.72);
  margin-bottom: 0.6rem;
}
.modal-body p strong { color: var(--text); }
.modal-body p em    { color: var(--text); font-style: normal; }
.modal-body a { color: var(--accent); }

.modal-body ul, .modal-body ol {
  padding-left: 1.5rem;
  margin-bottom: 0.7rem;
  color: var(--muted);
  font-size: 0.88rem;
}
.modal-body li { margin-bottom: 0.28rem; }

/* API endpoint rows */
.api-endpoint {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.8rem;
  margin-bottom: 0.45rem;
  font-family: var(--mono);
  font-size: 0.78rem;
}
.api-endpoint code { color: var(--accent); word-break: break-all; }
.ep-method {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #0b1017;
  background: var(--accent);
  padding: 0.1rem 0.38rem;
  border-radius: 3px;
  flex-shrink: 0;
}

/* Advanced Tools CTA */
.tools-cta {
  display: block;
  margin-top: 1.5rem;
  padding: 0.85rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  text-decoration: none;
  transition: color 0.15s, border-color 0.15s;
}
.tools-cta:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* Full Methodology link */
.methodology-link {
  display: block;
  margin-top: 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--accent-dim);
  border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: var(--radius);
  color: var(--accent);
  font-size: 0.92rem;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  letter-spacing: 0.02em;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.methodology-link:hover {
  background: rgba(56, 189, 248, 0.15);
  border-color: rgba(56, 189, 248, 0.7);
  box-shadow: var(--accent-glow);
}

/* Formula blocks */
.modal-body .formula-block,
.formula-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent);
  border-radius: 6px;
  padding: 0.8rem 1rem;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text);
  margin: 0.75rem 0;
  overflow-x: auto;
  white-space: pre;
}

/* Tables */
.domain-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin: 0.75rem 0;
}
.domain-table th {
  text-align: left;
  border-bottom: 1px solid var(--border);
  padding: 0.4rem 0.5rem;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.domain-table td {
  padding: 0.38rem 0.5rem;
  border-bottom: 1px solid rgba(35, 52, 72, 0.6);
  color: var(--muted);
  vertical-align: top;
}
.domain-table td:first-child { color: var(--text); }

/* ─── Static content pages ──────────────────────────────────────────────── */
.content-page {
  max-width: 760px;
  margin: 2rem auto;
  padding: 0 1.5rem;
  line-height: 1.7;
}

.content-page h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.content-page .subtitle {
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 2rem;
}

.content-page h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 2rem 0 0.75rem;
  color: var(--accent);
}

.content-page h3 {
  font-size: 0.92rem;
  font-weight: 600;
  margin: 1.25rem 0 0.4rem;
  color: var(--text);
}

.content-page p { margin-bottom: 0.75rem; color: var(--muted); }
.content-page p strong { color: var(--text); }

.content-page ul, .content-page ol {
  padding-left: 1.5rem;
  margin-bottom: 1rem;
  color: var(--muted);
}
.content-page li { margin-bottom: 0.3rem; }

.content-page hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

.content-page code {
  font-family: var(--mono);
  font-size: 0.82em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.1em 0.4em;
  border-radius: 3px;
  color: var(--text);
  white-space: nowrap;
}

.content-page pre.formula-block {
  margin: 1rem 0 1.5rem;
}

/* Table of contents */
.toc {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin: 1.5rem 0 2.5rem;
}
.toc-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.75rem;
}
.toc ol {
  padding-left: 1.25rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.9;
}
.toc li { margin-bottom: 0; }
.toc a { color: var(--accent); text-decoration: none; }
.toc a:hover { text-decoration: underline; }

/* ─── Loading spinner ───────────────────────────────────────────────────── */
.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 200px;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.875rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .site-header { padding: 0.6rem 1rem; gap: 0.4rem; }
  main { padding: var(--gap) 1rem; }
  .site-logo { font-size: 1.05rem; }
  .site-nav { gap: 0.3rem; }
  .nav-btn { font-size: 0.75rem; padding: 0.28rem 0.5rem; }
  .live-badge { display: none; }

  /* Map card: flex column so legend flows below map, not overlaid */
  .map-card {
    height: auto;
    padding: 0;
    display: flex;
    flex-direction: column;
  }
  /* Map container: takes the viewBox aspect ratio "160 40 720 363" */
  #map-container {
    height: 52dvh;
    flex-shrink: 0;
  }

  /* Legend: compact 2-column grid to fit within the short map strip */
  .map-legend {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.15rem 0.5rem;
  }
  .legend-item   { font-size: 0.62rem; }
  .legend-swatch { width: 9px; height: 9px; }
  /* Legend: static flow below map */
  .map-bottom-left {
    position: static;
    padding: 0.4rem 0.6rem 0.3rem;
    gap: 0.15rem;
  }
  .map-card .card-title { font-size: 0.58rem; }
}

/* ─── Domain sparkline ──────────────────────────────────────────────────── */
.domain-spark {
  grid-column: 1 / -1;
  height: 40px;
  margin-top: 0.1rem;
}
.domain-spark svg polyline {
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ─── Signal attribution ────────────────────────────────────────────────── */
.domain-attribution {
  grid-column: 1 / -1;
  font-size: 0.66rem;
  color: var(--muted);
  margin-top: -0.1rem;
  margin-bottom: 0.25rem;
  padding-left: 0.1rem;
}

/* ─── BVI description ───────────────────────────────────────────────────── */
.bvi-desc {
  font-size: 0.68rem;
  color: var(--muted);
  font-style: italic;
  margin-top: 0.2rem;
}

/* ─── Hero Card ──────────────────────────────────────────────────────────── */
.hero-card { padding: 1.25rem; }

.hero-layout {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

.hero-metric { flex: 0 0 auto; }

.hero-label {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.4rem;
}
.hero-label::before { content: '// '; color: var(--accent); opacity: 0.6; }

.hero-number-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.hero-number {
  font-family: var(--mono);
  font-size: 4rem;
  font-weight: 700;
  line-height: 1;
}

.hero-denom {
  font-family: var(--mono);
  font-size: 1.25rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.hero-risk-badge {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 0.25rem 0.55rem;
  border-radius: 5px;
}

.hero-stats {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.hero-stats .stat-highlight { color: var(--text); font-weight: 600; }

/* Alert Level Band Bar */
.hero-alert { flex: 1; min-width: 260px; }

.alert-band-bar {
  display: flex;
  gap: 3px;
  margin-top: 0.4rem;
}

.alert-band {
  flex: 1;
  font-family: var(--mono);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-align: center;
  padding: 0.45rem 0.2rem;
  border-radius: 4px;
  border: 1px solid transparent;
  color: var(--muted);
  background: var(--surface-2);
  opacity: 0.4;
  transition: opacity 0.25s, background 0.25s, border-color 0.25s;
  cursor: default;
}

.alert-band.active {
  opacity: 1;
  color: #0b1017;
  border-color: transparent;
}

/* ─── Signals Grid ───────────────────────────────────────────────────────── */
.signals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}

.signal-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.signal-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.signal-icon {
  display: flex;
  align-items: center;
  color: var(--accent);
  flex-shrink: 0;
}

.signal-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.signal-live-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  font-family: var(--mono);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  padding: 0.12rem 0.4rem;
  border-radius: 3px;
  flex-shrink: 0;
}

.signal-live-badge--realtime {
  color: #4ade80;
  border: 1px solid #4ade8060;
  background: rgba(74, 222, 128, 0.1);
}

.signal-live-badge--recent {
  color: #4ade80;
  border: 1px solid #4ade8040;
  background: transparent;
}

.signal-live-badge--structural {
  color: #a78bfa;
  border: 1px solid #a78bfa40;
  background: rgba(167, 139, 250, 0.06);
}

.signal-live-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.signal-live-badge--realtime .signal-live-dot {
  animation: live-pulse 1.8s ease-in-out infinite;
}

/* ─── Global Movers card ─────────────────────────────────────────────────── */
.movers-section { padding: 1rem 1.25rem; }

.movers-period-badge {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  margin-left: 0.5rem;
  vertical-align: middle;
}

.movers-stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.movers-col-title {
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.mover-delta--worsening { color: #f87171 !important; }
.mover-delta--improving  { color: #4ade80 !important; }

.mover-spark-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.movers-empty {
  font-size: 0.82rem;
  color: var(--muted);
  padding: 0.5rem 0;
}

.signal-desc {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.45;
}

.signal-meta {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--muted);
  margin-top: auto;
}
