:root {
  --bg: #f2f4f7;
  --ink: #182330;
  --muted: #83878c;
  --line: #d9dee5;
  --panel: #ffffff;
  --blue: #b7d1ef;
  --blue-strong: #2b7fb8;
  --control: #eef2f6;
  --good: #147447;
  --bad: #b64231;
  --shadow: 0 18px 50px rgba(24, 35, 48, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family:
    Arial, Helvetica, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-header,
main,
footer {
  width: min(1380px, calc(100% - 40px));
  margin: 0 auto;
}

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 0 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: var(--ink);
  font-size: clamp(2.2rem, 5vw, 4.8rem);
  line-height: 0.9;
  letter-spacing: 0;
}

h2 {
  font-size: 1.1rem;
  line-height: 1.2;
}

.eyebrow {
  color: var(--blue-strong);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.source-note {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 0.92rem;
  text-align: right;
}

a {
  color: var(--blue-strong);
  font-weight: 750;
}

.control-band {
  display: grid;
  grid-template-columns: auto minmax(170px, 0.8fr) minmax(230px, 1.5fr);
  gap: 14px;
  align-items: end;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.control-group {
  display: grid;
  gap: 8px;
}

label {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, minmax(70px, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--control);
}

.segment {
  min-height: 42px;
  border: 0;
  border-right: 1px solid var(--line);
  color: #59616b;
  background: transparent;
  cursor: pointer;
}

.segment:last-child {
  border-right: 0;
}

.segment.active {
  color: #fff;
  background: var(--ink);
}

.segment:disabled {
  color: #a4aab1;
  cursor: not-allowed;
}

.segment.active:disabled {
  color: #fff;
}

select,
input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  outline-color: var(--blue-strong);
}

select:disabled {
  color: #9298a0;
  background: #f3f5f7;
  cursor: not-allowed;
}

.trend-panel,
.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.trend-panel {
  margin-top: 16px;
  padding: 34px 42px 22px;
}

.summary-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-top: 16px;
  padding: 22px 0 4px;
}

.summary-header h2 {
  font-size: clamp(2.1rem, 5vw, 4.5rem);
  line-height: 0.95;
}

.summary-header span {
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}

.trend-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.trend-heading h2 {
  font-size: clamp(1.9rem, 3vw, 2.35rem);
  font-weight: 800;
}

.trend-heading p {
  margin-top: 4px;
  color: var(--muted);
  font-size: clamp(1.2rem, 2vw, 1.7rem);
  font-weight: 800;
}

.hero-chart .trend-heading,
.metric-chart-heading {
  padding-left: 9.5%;
}

.trend-heading span {
  color: var(--muted);
  font-size: 0.94rem;
  font-weight: 700;
  white-space: nowrap;
}

.trend-chart {
  min-height: 520px;
}

.hero-chart {
  padding-top: 28px;
}

svg {
  display: block;
  width: 100%;
  height: auto;
}

.grid-line {
  display: none;
}

.axis-line {
  stroke: #28323d;
  stroke-width: 1.25;
  shape-rendering: crispEdges;
}

.axis-tick {
  stroke: #28323d;
  stroke-width: 1.25;
  shape-rendering: crispEdges;
}

.annual-guide {
  stroke: #2b7fb8;
  stroke-width: 2;
  opacity: 0.28;
}

.axis-text,
.month-label,
.year-label,
.source-label,
.compare-value {
  fill: var(--muted);
}

.axis-text {
  fill: #1f252b;
  font-size: 17px;
}

.month-label,
.year-label {
  font-size: 16px;
  text-anchor: end;
}

.year-label {
  fill: #000;
  font-weight: 800;
}

.value-label {
  fill: #050505;
  font-size: 22px;
  font-weight: 400;
}

.compact-value-label {
  font-size: 13px;
  font-weight: 700;
}

.y-axis-label {
  fill: var(--ink);
  font-size: 21px;
}

.source-label {
  fill: #85898e;
  font-size: 20px;
}

.choropleth-panel {
  padding: 30px 42px 24px;
}

.map-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 0 4.5%;
}

.map-heading h2 {
  font-size: clamp(1.9rem, 3vw, 2.35rem);
  line-height: 1.1;
}

.map-heading p {
  margin-top: 5px;
  color: var(--muted);
  font-size: clamp(1.2rem, 2vw, 1.7rem);
  font-weight: 800;
}

.map-control {
  width: min(340px, 38%);
  flex: 0 0 auto;
}

.county-map {
  position: relative;
  width: 100%;
  min-height: 460px;
  margin-top: 16px;
  overflow: hidden;
  background: #f7f8f9;
}

.county-map svg {
  aspect-ratio: 1.86;
}

.county-shape {
  stroke: rgba(255, 255, 255, 0.8);
  stroke-width: 0.45;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition: filter 120ms ease, opacity 120ms ease;
}

.county-shape:hover,
.county-shape.selected {
  opacity: 1;
  stroke: #172330;
  stroke-width: 1.5;
  filter: brightness(0.94) saturate(1.08);
}

.county-shape.selected {
  stroke-width: 2.5;
}

.county-shape.context {
  opacity: 0.38;
}

.state-boundary {
  fill: none;
  stroke: #34414e;
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.state-focus-boundary {
  fill: none;
  stroke: #172330;
  stroke-width: 2.4;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.map-tooltip {
  position: absolute;
  z-index: 2;
  display: grid;
  gap: 3px;
  min-width: 150px;
  max-width: 230px;
  padding: 10px 12px;
  border: 1px solid #cfd5dc;
  border-radius: 6px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 10px 28px rgba(24, 35, 48, 0.16);
  font-size: 0.88rem;
  pointer-events: none;
}

.map-tooltip strong {
  line-height: 1.25;
}

.map-tooltip span {
  color: var(--muted);
  font-weight: 750;
}

.map-tooltip[hidden] {
  display: none;
}

.map-legend {
  display: grid;
  grid-template-columns: auto minmax(70px, 150px) auto minmax(70px, 150px) auto auto;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.map-legend-bar {
  height: 9px;
  background: linear-gradient(90deg, #b95740, #f2eee7);
}

.map-legend-bar.positive {
  background: linear-gradient(90deg, #f2eee7, #197b88);
}

.map-no-data {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 14px;
}

.map-no-data i {
  width: 11px;
  height: 11px;
  background: #dfe3e6;
}

.stack-legend-label {
  fill: #4f555c;
  font-size: 16px;
  font-weight: 700;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 12px 0 16px;
}

.metric-card {
  display: grid;
  gap: 7px;
  min-height: 128px;
  padding: 18px;
}

.metric-card span,
.metric-card small,
.panel-heading span,
footer {
  color: var(--muted);
}

.metric-card span {
  font-size: 0.82rem;
  font-weight: 750;
}

.metric-card strong {
  font-size: clamp(1.5rem, 3vw, 2.35rem);
  line-height: 1;
}

.metric-card small {
  font-weight: 700;
}

.chart-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.chart-grid > .trend-panel {
  margin-top: 0;
}

.metric-chart-card {
  padding: 30px 42px 18px;
}

.metric-chart-heading {
  margin-bottom: 0;
}

.metric-chart-heading h2 {
  font-size: clamp(1.9rem, 3vw, 2.35rem);
}

.metric-chart-heading p {
  color: #85898e;
  font-size: clamp(1.2rem, 2vw, 1.7rem);
}

.metric-chart {
  min-height: 0;
}

.delta-up {
  color: var(--good) !important;
}

.delta-down {
  color: var(--bad) !important;
}

.lower-grid {
  display: grid;
  grid-template-columns: minmax(340px, 0.72fr) minmax(0, 1.28fr);
  gap: 16px;
  margin-top: 16px;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.mini-chart {
  min-height: 310px;
}

.compare-name {
  fill: var(--ink);
  font-size: 13px;
  font-weight: 750;
}

.compare-value {
  font-size: 13px;
}

.legend-label {
  font-size: 18px;
  font-weight: 800;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: var(--muted);
  background: #f5f7fa;
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  width: 100%;
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  white-space: nowrap;
  cursor: pointer;
}

th:first-child .sort-button {
  justify-content: flex-start;
}

.sort-button:focus-visible {
  outline: 2px solid var(--blue-strong);
  outline-offset: 3px;
}

.sort-indicator {
  width: 0;
  height: 0;
  border-right: 4px solid transparent;
  border-left: 4px solid transparent;
  border-top: 6px solid currentColor;
  opacity: 0.25;
}

th[aria-sort="ascending"] .sort-indicator {
  border-top: 0;
  border-bottom: 6px solid currentColor;
  opacity: 1;
}

th[aria-sort="descending"] .sort-indicator {
  opacity: 1;
}

tr:last-child td {
  border-bottom: 0;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
.selected-row {
  background: #edf5fd;
}

.empty {
  display: grid;
  min-height: 180px;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
}

footer {
  padding: 24px 0 36px;
  font-size: 0.86rem;
}

@media (max-width: 980px) {
  .app-header {
    align-items: start;
    flex-direction: column;
  }

  .source-note {
    text-align: left;
  }

  .control-band,
  .summary-grid,
  .chart-grid,
  .lower-grid {
    grid-template-columns: 1fr;
  }

  .trend-panel {
    padding: 24px 18px 18px;
  }

  .summary-header {
    align-items: start;
    flex-direction: column;
  }

  .map-heading {
    align-items: start;
    flex-direction: column;
    padding: 0;
  }

  .map-control {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .app-header,
  main,
  footer {
    width: calc(100% - 24px);
  }

  .segmented {
    grid-template-columns: repeat(2, 1fr);
  }

  .segment:nth-child(2) {
    border-right: 0;
  }

  .trend-heading {
    flex-direction: column;
  }

  .hero-chart .trend-heading,
  .metric-chart-heading {
    padding-left: 0;
  }

  .trend-chart {
    min-height: 300px;
  }

  .choropleth-panel {
    padding: 24px 18px 18px;
  }

  .county-map {
    min-height: 260px;
  }

  .county-map svg {
    min-width: 0;
  }

  .map-legend {
    grid-template-columns: auto minmax(40px, 1fr) auto minmax(40px, 1fr) auto;
  }

  .map-no-data {
    grid-column: 1 / -1;
    justify-self: center;
    margin-left: 0;
  }

  .trend-chart,
  .metric-chart {
    overflow-x: auto;
    overscroll-behavior-inline: contain;
  }

  .trend-chart svg,
  .metric-chart svg {
    width: 760px;
    max-width: none;
  }

  .metric-card {
    min-height: 112px;
  }
}
