:root {
  --orange: #e55a18;
  --orange-dark: #a63c0b;
  --charcoal: #4a4a4a;
  --ink: #1d1d1d;
  --muted: #666666;
  --line: #d9d9d9;
  --soft: #f6f4f1;
  --paper: #ffffff;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.45;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 36px;
}

.visual-header { margin-bottom: 22px; }
.brand-line, .eyebrow {
  color: var(--orange-dark);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
}
.brand-line span { color: var(--charcoal); margin: 0 6px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(28px, 4vw, 44px); line-height: 1.1; }
h2 { margin-bottom: 5px; font-size: clamp(22px, 3vw, 30px); line-height: 1.2; }
h3 { margin-bottom: 2px; font-size: 18px; }
.visual-header > p, .section-note, .map-panel > p, .grid-help, .data-footer { color: var(--muted); }

.controls {
  display: flex;
  align-items: end;
  gap: 10px;
  padding: 14px 0 8px;
  border-top: 1px solid var(--line);
}
.controls label, .grid-search { font-size: 13px; font-weight: 700; color: var(--charcoal); }
select, input, button {
  min-height: 42px;
  border: 1px solid #999;
  border-radius: 3px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
}
select, input { padding: 8px 10px; }
select { min-width: min(340px, 70vw); }
button { padding: 8px 16px; cursor: pointer; font-weight: 700; }
button:hover, button:focus-visible { border-color: var(--orange); color: var(--orange-dark); }

.section-intro {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 16px;
}
.section-intro .eyebrow { margin-bottom: 4px; }
.section-note { max-width: 410px; margin-bottom: 3px; font-size: 14px; }
.selection-help { margin: 0 0 22px; color: var(--muted); font-size: 12px; }
.map-options-row { margin: 10px 0 18px; padding: 12px 14px; background: var(--soft); }
.map-options-row .map-metric-control { max-width: 610px; margin: 0; }

.map-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px; }
.map-panel { min-width: 0; }
.map-panel > p { font-size: 13px; margin-bottom: 8px; }
.map-metric-control { display: grid; gap: 4px; color: var(--charcoal); font-size: 12px; font-weight: 700; }
.map-metric-control select { width: 100%; min-width: 0; min-height: 38px; font-size: 13px; }
.map-panel svg { display: block; width: 100%; height: auto; min-height: 360px; background: #eee9e3; border: 1px solid #d5cec5; }
.map-layer { transform-origin: 0 0; }
.county-shape {
  stroke: #f7f4ef;
  stroke-width: 1;
  cursor: pointer;
  vector-effect: non-scaling-stroke;
  transition: opacity .15s ease, stroke-width .15s ease;
}
.county-shape.is-dimmed { opacity: .3; }
.county-shape:hover, .county-shape:focus-visible { stroke: var(--ink); stroke-width: 2; outline: none; }
.county-shape.is-selected { opacity: 1; stroke: var(--orange-dark); stroke-width: 3; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-swatch { width: 18px; height: 11px; border: 1px solid rgba(0,0,0,.12); }

.county-summary {
  margin: 30px 0 38px;
  padding: 22px 0;
  border-top: 2px solid var(--charcoal);
  border-bottom: 1px solid var(--line);
}
.county-summary .eyebrow { margin-bottom: 3px; }
.summary-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 18px; margin-top: 18px; }
.metric-label { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.metric-value { display: block; margin-top: 3px; font-size: 23px; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric-detail { color: var(--muted); font-size: 12px; }
.summary-interpretation { margin: 16px 0 0; max-width: 900px; }

.grid-intro { align-items: end; }
.grid-search { display: grid; gap: 4px; min-width: min(310px, 100%); }
.grid-help { margin-bottom: 12px; font-size: 13px; }
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); }
table { width: 100%; min-width: 0; table-layout: fixed; border-collapse: separate; border-spacing: 0; font-size: 12px; }
th, td { padding: 9px 5px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:last-child, td:last-child { border-right: 0; }
thead th { position: sticky; top: 0; z-index: 2; background: var(--charcoal); color: #fff; font-size: 12px; }
th button { min-height: 0; padding: 0; border: 0; color: inherit; background: transparent; font-size: inherit; line-height: 1.2; white-space: normal; }
th button:hover, th button:focus-visible { color: #fff; text-decoration: underline; }
th:first-child, td:first-child { position: sticky; left: 0; text-align: left; }
th:first-child { z-index: 3; }
th:first-child, td:first-child { width: 13%; }
tbody td:first-child { z-index: 1; background: var(--paper); font-weight: 700; }
tbody tr { cursor: pointer; }
tbody tr:hover td:first-child, tbody tr:focus-within td:first-child { color: var(--orange-dark); }
tbody tr.is-selected td { box-shadow: inset 0 2px 0 var(--orange), inset 0 -2px 0 var(--orange); }
tbody tr.is-selected td:first-child { color: var(--orange-dark); }
.cell-button { width: 100%; min-height: 0; padding: 0; border: 0; background: transparent; text-align: inherit; font-size: inherit; font-variant-numeric: tabular-nums; }
.arrow { display: inline-block; width: 14px; text-align: center; font-weight: 700; }

.data-footer { margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--line); font-size: 12px; }
.data-footer p { margin-bottom: 7px; }
a { color: var(--orange-dark); text-underline-offset: 2px; }

.tooltip {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  max-width: 280px;
  padding: 10px 12px;
  background: var(--ink);
  color: #fff;
  border-radius: 3px;
  box-shadow: 0 5px 18px rgba(0,0,0,.22);
  font-size: 12px;
}
.tooltip strong { display: block; margin-bottom: 4px; font-size: 13px; }
.tooltip-line { display: flex; justify-content: space-between; gap: 16px; }

body.view-maps #grid-section { display: none; }
body.view-grid #map-section { display: none; }
body.view-maps .visual-header, body.view-grid .visual-header { display: none; }
body.view-maps .app-shell, body.view-grid .app-shell { padding-top: 12px; }
body.view-grid .county-summary { margin-top: 8px; }

@media (max-width: 760px) {
  .app-shell { width: min(100% - 22px, 1180px); padding-top: 18px; }
  .controls, .section-intro { align-items: stretch; flex-direction: column; gap: 10px; }
  select { min-width: 0; width: 100%; }
  .map-grid { grid-template-columns: 1fr; gap: 34px; }
  .map-panel svg { min-height: 330px; }
  .summary-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-search { min-width: 0; width: 100%; }
  table { min-width: 980px; }
}

@media (max-width: 430px) {
  .controls { display: grid; }
  .summary-metrics { grid-template-columns: 1fr; gap: 11px; }
}

@media print {
  .controls, #grid-section, .data-footer { display: none !important; }
  .app-shell { width: 100%; padding: 0; }
  .map-grid { grid-template-columns: 1fr 1fr; }
  .map-panel svg { min-height: 300px; }
}
