/* ============================================================
   styles.css — Milestone 2.2
   Design system for the U.S. Migration Explorer.

   Color palette:
     --bg          #fffafa  Snowy white page background
     --surface     #ffffff  Card / panel surfaces
     --accent-bg   #e2f2f0  Very light bluish-green accent fills
     --accent      #b8860b  Dark goldenrod — interactive highlights
     --accent-dark #8a6408  Hover / active state for goldenrod elements
     --text        #2a2f36  Soft black body text
     --text-muted  #6b7280  Secondary / caption text
     --border      #dde3e9  Subtle borders between panels
     --shadow      rgba(42,47,54,0.08)  Drop-shadow base

   Typography: Inter (Google Fonts)
   ============================================================ */

/* ────────────────────────────────────────────────────────────
   1. DESIGN TOKENS
──────────────────────────────────────────────────────────── */
:root {
  /* Colors */
  --bg: #fffafa;
  --surface: #ffffff;
  --accent-bg: #e2f2f0;
  --accent: #b8860b;
  --accent-dark: #8a6408;
  --accent-light: #f5e9c8;
  --text: #2a2f36;
  --text-muted: #6b7280;
  --border: #dde3e9;
  --shadow-sm: 0 1px 3px rgba(42, 47, 54, 0.08);
  --shadow-md: 0 4px 12px rgba(42, 47, 54, 0.10);

  /* Map interactive states */
  --region-hover: rgba(184, 134, 11, 0.15);
  --region-primary: rgba(184, 134, 11, 0.55);
  --region-secondary: rgba(184, 134, 11, 0.30);

  /* Spacing scale */
  --sp-xs: 4px;
  --sp-sm: 8px;
  --sp-md: 16px;
  --sp-lg: 24px;
  --sp-xl: 36px;

  /* Layout */
  --header-h: 64px;
  --controls-h: 72px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  /* Transitions */
  --t-fast: 120ms ease;
  --t-normal: 220ms ease;
  --t-slow: 360ms ease;
}


/* ────────────────────────────────────────────────────────────
   2. RESET & BASE
──────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 400;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  /* Removed grid layout to rely on standard block layout with sticky header */
}

/* Screen-reader utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}


/* ────────────────────────────────────────────────────────────
   3. HEADER
──────────────────────────────────────────────────────────── */


#site-subtitle {
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-nav {
  display: flex;
  gap: var(--sp-md);
  margin-left: auto;
}

.nav-link {
  text-decoration: none;
  color: var(--text);
  font-weight: 500;
  font-size: 0.875rem;
  padding: 8px 16px;
  border-radius: 9999px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: background var(--t-fast), color var(--t-fast);
}

.nav-link:hover {
  background: var(--accent-bg);
  color: var(--accent-dark);
}

.nav-link.active {
  font-weight: 700;
  color: #000000;
  background-color: #a0b8d6;
  border-color: #708896;
}

/* ────────────────────────────────────────────────────────────
   4. CONTROL BAR
──────────────────────────────────────────────────────────── */
#page-map,
#chart-individual,
#chart-pair,
#page-guide {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}



.map-middle-layout {
  display: flex;
  flex-direction: row;
  flex: 1;
  min-height: 0;
}

#control-bar {
  flex-shrink: 0;
  width: 320px;
  height: 100%;
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 9;
  overflow-y: auto;
}

.controls-inner {
  height: auto;
  padding: var(--sp-lg);
  display: flex;
  flex-direction: column;
  gap: var(--sp-xl);
}

/* Generic control group */
.control-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
  border: none;
  /* reset <fieldset> */
  padding: 0;
  /* reset <fieldset> */
  min-width: 0;
}

.control-label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── 4a. Radio buttons ───────────────────────────────────── */
.radio-group {
  display: flex;
  gap: 2px;
  background: var(--accent-bg);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: var(--sp-xs);
  padding: 4px 12px;
  border-radius: calc(var(--radius-sm) - 2px);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
  user-select: none;
}

/* Hide native radio */
.radio-label input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

/* Custom dot */
.radio-custom {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--text-muted);
  transition: border-color var(--t-fast), background var(--t-fast);
  flex-shrink: 0;
}

/* Checked state — pill highlight */
.radio-label:has(input:checked) {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.radio-label:has(input:checked) .radio-custom {
  border-color: var(--accent);
  background: var(--accent);
}

.radio-label:hover:not(:has(input:checked)) {
  background: rgba(255, 255, 255, 0.6);
  color: var(--text);
}

/* Focus-visible ring for keyboard navigation */
.radio-label:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── 4b. Year slider ─────────────────────────────────────── */
#year-control {
  flex: 0 0 100%;
  box-sizing: border-box;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-md) var(--sp-xl);
  margin-top: var(--sp-md);
}

#year-display {
  color: var(--accent);
  font-weight: 600;
}

#year-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
  margin-top: 6px;
  transition: background var(--t-fast);
  position: relative;
  z-index: 2;
}

/* Filled track uses a CSS gradient updated via JS (--slider-pct custom property) */
#year-slider {
  background: linear-gradient(to right,
      var(--accent) 0%,
      var(--accent) var(--slider-pct, 0%),
      var(--border) var(--slider-pct, 0%),
      var(--border) 100%);
}

/* Thumb — Webkit */
#year-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  box-shadow: 0 1px 3px rgba(184, 134, 11, 0.25);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}

#year-slider::-webkit-slider-thumb:hover,
#year-slider:focus::-webkit-slider-thumb {
  transform: scale(1.25);
  box-shadow: 0 2px 6px rgba(184, 134, 11, 0.40);
}

/* Thumb — Firefox */
#year-slider::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  box-shadow: 0 1px 3px rgba(184, 134, 11, 0.25);
  cursor: pointer;
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}

#year-slider::-moz-range-thumb:hover {
  transform: scale(1.25);
}

/* Tick labels */
.slider-tick-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.6875rem;
  color: var(--text-muted);
  margin-top: 2px;
  padding: 0 2px;
}

/* ── 4c. Metric select ───────────────────────────────────── */
#metric-control {
  width: 140px;
  min-width: 140px;
}

#metric-stat-control {
  min-width: 260px;
}

#metric-category-select,
#ind-metric-category-select,
#pair-metric-category-select {
  width: 140px;
  min-width: 140px;
}

/* ── Slider Layout & Tick Marks ── */
.slider-track-container {
  position: relative;
  padding-bottom: 24px;
}

.slider-ticks {
  position: absolute;
  top: 15px;
  left: 6.5px;
  right: 6.5px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 1;
}

.tick {
  position: relative;
  width: 2px;
  height: 6px;
  background: var(--text-muted);
}

.tick-label {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  font-size: 0.65rem;
  color: var(--text-muted);
  line-height: 1.1;
  white-space: nowrap;
}

/* ── 4d. Zoom slider ─────────────────────────────────────── */
#zoom-control {
  min-width: 150px;
  max-width: 200px;
}

#zoom-display {
  color: var(--text);
  font-weight: 600;
}

/* Track */
#zoom-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  margin-top: 6px;
  transition: background var(--t-fast);
  background: linear-gradient(to right,
      var(--text-muted) 0%,
      var(--text-muted) var(--zoom-pct, 0%),
      var(--border) var(--zoom-pct, 0%),
      var(--border) 100%);
}

/* Thumb — Webkit */
#zoom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--text-muted);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}

#zoom-slider::-webkit-slider-thumb:hover,
#zoom-slider:focus::-webkit-slider-thumb {
  transform: scale(1.25);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

/* Thumb — Firefox */
#zoom-slider::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--text-muted);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}

#zoom-slider::-moz-range-thumb:hover {
  transform: scale(1.25);
}

select {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  padding: 6px 32px 6px 10px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 10px center;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

select:hover {
  border-color: var(--accent);
}

select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}


/* ────────────────────────────────────────────────────────────
   5. MAIN LAYOUT — full-width map
──────────────────────────────────────────────────────────── */
#main-layout {
  flex: 1;
  overflow: hidden;
}


/* ────────────────────────────────────────────────────────────
   6. MAP PANEL (left)
──────────────────────────────────────────────────────────── */
#map-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  position: relative;
  height: 100%;
}

/* SVG map fills the available space */
#map {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* D3 injects an <svg> here — make it fill the container */
#map svg {
  width: 100%;
  height: 100%;
  display: block;
}


/* D3-rendered region fill paths */
#map path.region {
  stroke: none;
  /* borders handled by the border layer */
  transition: fill var(--t-normal);
  cursor: pointer;
}

/* Hover state — thick dark line, scoped to regions only */
#map path.region:hover {
  stroke: #2a2f36 !important;
  /* Uses the --text color variable */
  stroke-width: 2.5px !important;
}

/* Border-layer paths are decorative overlays — never intercept pointer events */
#map .layer-borders path {
  pointer-events: none;
}

#map path.region--primary {
  stroke: var(--accent);
  stroke-width: 2px;
}

#map path.region--secondary {
  stroke: var(--accent);
  stroke-width: 1.5px;
  stroke-dasharray: 4 2;
}

/* ── Status bar ─────────────────────────────────────────── */
#map-status-bar {
  padding: 6px var(--sp-md);
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 0.8125rem;
  color: var(--text-muted);
  min-height: 32px;
  display: flex;
  align-items: center;
}

/* ── Color-scale legend ─────────────────────────────────── */
#bottom-bar {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

#map-legend {
  display: none;
  /* hidden until D3 sets the gradient & bounds */
  align-items: center;
  gap: var(--sp-sm);
  padding: 6px var(--sp-md) 8px;
  background: var(--surface);
}

.legend-bound {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 36px;
}

#legend-min {
  text-align: right;
}

#legend-max {
  text-align: left;
}

#legend-gradient {
  flex: 1;
  height: 10px;
  border-radius: 5px;
  /* D3 will replace this with the actual color-scale gradient */
  background: linear-gradient(to right,
      #d4e9f0, #b8d9e8, #7ab7d4, #3d8bbf, #1a5e9e, #b8860b);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.08);
}


/* Placeholder */
.chart-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.chart-placeholder p {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.6;
  padding: var(--sp-md);
  background: var(--accent-bg);
  border-radius: var(--radius-md);
}


/* ────────────────────────────────────────────────────────────
   8. TOOLTIP (injected by D3 into <body>)
──────────────────────────────────────────────────────────── */
.map-tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-sm) var(--sp-md);
  box-shadow: var(--shadow-md);
  font-size: 0.8125rem;
  color: var(--text);
  max-width: 220px;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--t-fast), transform var(--t-fast);
  z-index: 100;
}

.map-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.map-tooltip strong {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text);
}

.map-tooltip .tooltip-value {
  color: var(--accent);
  font-weight: 600;
}


/* ────────────────────────────────────────────────────────────
   9. RESPONSIVE
──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .controls-inner {
    gap: var(--sp-md);
    padding: var(--sp-sm) var(--sp-md);
  }

  #metric-control {
    max-width: 100%;
    flex: 1 1 100%;
  }
}

@media (max-width: 600px) {
  #site-subtitle {
    display: none;
  }

  .controls-inner {
    flex-wrap: wrap;
  }

  #year-control {
    min-width: 160px;
  }
}




/* ────────────────────────────────────────────────────────────
   11. LOADING OVERLAY (injected by script.js)
──────────────────────────────────────────────────────────── */
#loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 250, 250, 0.82);
  backdrop-filter: blur(3px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-md);
  z-index: 50;
}

#loading-overlay[hidden] {
  display: none;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--accent-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-msg {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
}


/* ────────────────────────────────────────────────────────────
   12. PHASE 6 — INDIVIDUAL REGION TREND CHART
──────────────────────────────────────────────────────────── */

/*
 * The body grid originally locks the main row to 1fr (filling the viewport
 * exactly). The chart section lives OUTSIDE #main-layout, so we allow the
 * body to scroll naturally beyond the viewport when the chart is present.
 */
body {
  min-height: 100dvh;
  height: auto;
  overflow-y: auto;
  /* 6 rows: header, toc, map-page, individual chart, pair chart, guide */
  grid-template-rows: var(--header-h) 100dvh 100dvh 100dvh 100dvh auto;
  grid-template-areas:
    "header"
    "toc"
    "map-page"
    "charts"
    "pair"
    "guide";
}

/* ── Section shell ───────────────────────────────────────── */
#chart-individual {
  background: var(--bg);
  border-top: 2px solid var(--border);
  padding: var(--sp-md) var(--sp-lg);
  /* Reduced padding to maximize chart size */
  display: flex;
  flex-direction: column;
  gap: var(--sp-md);
  /* Reduced gap */
  height: 100dvh;
  width: 100vw;
  box-sizing: border-box;
}

/* ── Section header ──────────────────────────────────────── */
.chart-section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-sm);
}

#page-map .chart-section-header {
  padding: var(--sp-md) var(--sp-lg);
  max-width: 1800px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
}

.chart-section-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chart-section-heading {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

/* Goldenrod accent bar before the heading */
.chart-section-heading::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 0.95em;
  background: var(--accent);
  border-radius: 2px;
  vertical-align: middle;
  margin-right: var(--sp-sm);
  margin-bottom: 2px;
}

.chart-section-subtitle {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-left: calc(4px + var(--sp-sm));
  /* align under heading text after accent bar */
}

/* ── Controls row ────────────────────────────────────────── */
.chart-controls-row {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: var(--sp-lg);
  padding: var(--sp-md) var(--sp-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.chart-control-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
  min-width: 0;
}

/* Region selector — moderately wide */
#ind-region-select {
  min-width: 220px;
  max-width: 320px;
}

/* Metric selectors — same as map's */
#ind-metric-stat-select,
#pair-metric-stat-select {
  min-width: 260px;
  max-width: 380px;
}

/* Clear button */
.chart-clear-btn {
  padding: 6px 16px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast);
  white-space: nowrap;
  align-self: flex-end;
  /* bottom-align with the selects */
}

.chart-clear-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

.chart-clear-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Chart area ──────────────────────────────────────────── */
#chart-individual-area {
  position: relative;
  flex: 1;
  /* Forces the box to stretch */
  min-height: 0;
  /* CRITICAL: Prevents the chart from overflowing the viewport height */
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Placeholder — centered message card */
.chart-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--sp-xl);
  pointer-events: none;
}

.chart-placeholder p {
  font-size: 0.9375rem;
  color: var(--text-muted);
  line-height: 1.6;
  max-width: 30ch;
}

/* SVG container fills the remaining card space */
#chart-individual-svg-container {
  flex: 1;
  min-height: 340px;
  width: 100%;
}

/* D3 injects an SVG — make it fill the container */
#chart-individual-svg-container svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ── D3 axis text ────────────────────────────────────────── */
.ind-chart-axis text {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.6875rem;
  fill: var(--text-muted);
}

.ind-chart-axis path,
.ind-chart-axis line {
  stroke: var(--border);
}

/* Y-axis label */
.ind-chart-y-label {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  fill: var(--text-muted);
}

/* Grid lines */
.ind-chart-grid line {
  stroke: var(--border);
  stroke-dasharray: 3 3;
  stroke-opacity: 0.7;
}

.ind-chart-grid path {
  stroke: none;
}

/* ── Floating tooltip (shared with future Phase 7 chart) ─── */
#chart-tooltip {
  position: absolute;
  display: none;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  box-shadow: var(--shadow-md);
  font-size: 0.8125rem;
  color: var(--text);
  z-index: 200;
  max-width: 220px;
  line-height: 1.4;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
  #chart-individual {
    padding: var(--sp-lg) var(--sp-md);
  }

  .chart-controls-row {
    padding: var(--sp-md);
    gap: var(--sp-md);
  }

  .region-combobox,
  #ind-metric-stat-select,
  #pair-metric-stat-select {
    min-width: 240px;
    /* Increased from 180px so the placeholder is still readable on tablets */
    max-width: 100%;
  }
}

@media (max-width: 600px) {
  .chart-controls-row {
    flex-direction: column;
    align-items: stretch;
  }

  .region-combobox,
  #ind-metric-stat-select,
  #pair-metric-stat-select,
  #metric-category-select,
  #ind-metric-category-select,
  #pair-metric-category-select {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .chart-clear-btn {
    align-self: flex-start;
  }
}

/* ── Multi-Region Selection (Phase 8) ────────────────────── */
.ind-combobox-row {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-sm);
}

.chart-add-btn {
  padding: 6px 12px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--surface);
  background: var(--accent);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity var(--t-fast), transform var(--t-fast);
  white-space: nowrap;
}

.chart-add-btn:hover {
  opacity: 0.9;
}

.chart-add-btn:active {
  transform: scale(0.97);
}

.chart-add-btn:disabled {
  background: var(--border);
  border-color: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
  transform: none;
}

.selected-regions-container {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-sm);
  margin-top: var(--sp-md);
  width: 100%;
}

.region-bubble {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--surface);
  border: 1.5px solid;
  /* Color applied via JS based on schemePaired */
  border-radius: 16px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.bubble-remove-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bubble-remove-btn:hover {
  color: #dc2626;
  /* Red on hover */
}

/* ────────────────────────────────────────────────────────────
   13. PHASE 7 — PAIRWISE REGION TREND CHART
──────────────────────────────────────────────────────────── */

#chart-pair {
  background: var(--bg);
  border-top: 2px solid var(--border);
  padding: var(--sp-md) var(--sp-lg);
  display: flex;
  flex-direction: column;
  gap: var(--sp-md);
  height: 100dvh;
  width: 100vw;
  box-sizing: border-box;
}

#chart-pair-area {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#chart-pair-svg-container {
  flex: 1;
  min-height: 340px;
  width: 100%;
}

#chart-pair-svg-container svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ────────────────────────────────────────────────────────────
   14. STATISTIC DESCRIPTION
──────────────────────────────────────────────────────────── */
.statistic-description {
  margin: var(--sp-sm) var(--sp-lg);
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
  font-style: italic;
}

/* ────────────────────────────────────────────────────────────
   15. PLACEHOLDER HIDDEN FIX
   CSS display: flex on .chart-placeholder can override the
   browser's default [hidden] = display: none.
──────────────────────────────────────────────────────────── */
.chart-placeholder[hidden] {
  display: none !important;
}


/* ────────────────────────────────────────────────────────────
   15. REGION COMBOBOX
──────────────────────────────────────────────────────────── */

/* Wrapper provides the positioning context for the dropdown */
.region-combobox {
  position: relative;
  min-width: 280px;
  /* Increased from 220px to fit the full placeholder text */
  max-width: 400px;
  /* Slightly increased to give the bar more room to stretch */
}

/* Text input styled to look like the app's <select> elements */
.region-combobox-input {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  padding: 6px 30px 6px 10px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  /* Arrow icon — same SVG used by the native <select> override above */
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 10px center;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: text;
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  box-sizing: border-box;
}

.region-combobox-input::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

.region-combobox-input:hover {
  border-color: var(--accent);
}

.region-combobox-input:focus,
.region-combobox-input[aria-expanded="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.region-combobox-input:disabled {
  background-color: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.7;
}

/* Dropdown listbox panel */
.region-combobox-listbox {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 500;
  background: var(--surface);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  max-height: 280px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.region-combobox-listbox[hidden] {
  display: none;
}

/* Scrollbar for the listbox */
.region-combobox-listbox::-webkit-scrollbar {
  width: 6px;
}

.region-combobox-listbox::-webkit-scrollbar-track {
  background: transparent;
}

.region-combobox-listbox::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* Section group labels ("Selected", "States", "Counties") */
.region-group-label {
  padding: 5px 10px 3px;
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border-top: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 1;
}

.region-group-label:first-child {
  border-top: none;
}

/* Individual option rows */
.region-option {
  padding: 7px 12px;
  font-size: 0.875rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: background var(--t-fast);
}

.region-option:hover {
  background: var(--accent-light);
}

/* Active = currently selected region */
.region-option--active {
  color: var(--accent);
  font-weight: 600;
}

/* Highlighted = keyboard cursor position */
.region-option--highlighted {
  background: var(--accent-light);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* No-results / hint rows */
.region-option--no-results {
  color: var(--text-muted);
  font-style: italic;
  cursor: default;
  font-size: 0.8125rem;
}

.region-option--no-results:hover {
  background: none;
}

/* ── Navigation Arrows & Wrappers ────────────────────────── */
.chart-controls-wrapper {
  display: flex;
  align-items: flex-end;
  /* Keeps the arrow bottom-aligned with the inputs */
  gap: var(--sp-md);
  width: 100%;
}

.chart-controls-wrapper .chart-controls-row {
  flex: 1;
  /* Shorten control panel to make space for the up arrow */
}

.nav-arrow {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  color: var(--accent);
  font-size: 24px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform var(--t-fast), background var(--t-fast), color var(--t-fast);
}

.nav-arrow:hover {
  background: var(--accent);
  color: var(--surface);
  transform: scale(1.1);
}

.map-nav-arrows {
  position: absolute;
  right: var(--sp-lg);
  top: 50%;
  transform: translateY(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: var(--sp-sm);
}

/* Pairwise Combobox Layout */
.pair-combobox-group {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: var(--sp-md);
}


/* ────────────────────────────────────────────────────────────
   15. MILESTONE 9.3 — INSTRUCTIONS & GLOSSARY
──────────────────────────────────────────────────────────── */

#page-guide {
  background: var(--bg);
  overflow-y: auto;
  border-top: 2px solid var(--border);
  padding: var(--sp-lg) var(--sp-xl);
  display: flex;
  flex-direction: column;
  gap: var(--sp-md);
  width: 100vw;
  box-sizing: border-box;
  min-height: 100dvh;
}

.guide-nav-row {
  display: flex;
  gap: var(--sp-sm);
  align-items: center;
}

.guide-content-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.guide-columns {
  display: flex;
  flex-direction: column;
  gap: var(--sp-lg);
}

.guide-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.guide-card-heading {
  font-size: 1rem;
  font-weight: 700;
  color: var(--surface);
  background: var(--accent);
  padding: var(--sp-sm) var(--sp-md);
  letter-spacing: -0.01em;
}

.guide-card-body {
  padding: var(--sp-md) var(--sp-lg);
  font-size: 0.875rem;
  line-height: 1.65;
  color: var(--text);
}

.guide-card-body p {
  margin-bottom: var(--sp-sm);
}

.guide-card-body ul {
  margin: var(--sp-xs) 0 var(--sp-sm) var(--sp-lg);
  padding: 0;
}

.guide-card-body ul li {
  margin-bottom: var(--sp-xs);
}

.guide-subheading {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--accent-dark);
  margin-top: var(--sp-md);
  margin-bottom: var(--sp-xs);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--accent-light);
}

.guide-card-body .guide-subheading:first-child {
  margin-top: 0;
}

/* ── Glossary definition list ────────────────────────────── */
.glossary-list {
  margin: 0;
  padding: 0;
}

.glossary-list dt {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--accent-dark);
  margin-top: var(--sp-md);
  padding-bottom: 2px;
  border-bottom: 1px solid var(--accent-light);
}

.glossary-list dt:first-child {
  margin-top: 0;
}

.glossary-list dd {
  margin: var(--sp-xs) 0 0 0;
  padding: 0;
  font-size: 0.8125rem;
  line-height: 1.6;
  color: var(--text);
}

.glossary-list code {
  background: var(--accent-bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.8em;
  font-family: 'Menlo', 'Consolas', monospace;
}

@media (max-width: 900px) {
  #page-guide {
    padding: var(--sp-md);
  }
}