:root {
  --bg: #edf3f6;
  --surface: #ffffff;
  --surface-muted: #f7fafc;
  --ink: #0f172a;
  --muted: #526273;
  --line: #dbe4ee;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --danger: #b91c1c;
  --warning: #d97706;
  --below: #cbd5e1;
  --focus: #0ea5e9;
  --shadow: 0 18px 42px rgba(15, 23, 42, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body,
#root {
  min-height: 100%;
}

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

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

button,
a,
input,
select {
  touch-action: manipulation;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
.map-canvas:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.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;
}

.icon {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.app-shell {
  width: min(100%, 1640px);
  min-height: 100vh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.07);
}

.brand-block {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: var(--radius);
  background: #ccfbf1;
  color: var(--brand-dark);
}

.brand-mark .icon {
  width: 24px;
  height: 24px;
}

.kicker {
  margin: 0 0 4px;
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 32px;
  line-height: 1.08;
}

h2 {
  font-size: 17px;
  line-height: 1.2;
}

.subtitle,
.muted,
.app-footer {
  color: var(--muted);
}

.subtitle {
  margin: 6px 0 0;
  max-width: 760px;
  font-size: 15px;
  line-height: 1.45;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
}

.updated-pill,
.icon-button,
.action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
  font-weight: 750;
  cursor: pointer;
}

.updated-pill {
  background: #ecfeff;
  border-color: #99f6e4;
  color: var(--brand-dark);
  cursor: default;
}

.updated-pill strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.icon-button:hover,
.action-link:hover {
  border-color: #99b5c8;
  background: var(--surface-muted);
}

.action-link.primary {
  background: var(--brand-dark);
  color: #fff;
  border-color: var(--brand-dark);
}

.notice {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid #f8d79d;
  background: #fff7ed;
  color: #92400e;
  font-size: 13px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.stat {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 82px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.stat-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: var(--radius);
  background: #e0f2fe;
  color: #075985;
}

.stat-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.stat-value {
  margin-top: 1px;
  font-size: 24px;
  line-height: 1.1;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.stat-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.date-rail {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 6px;
}

.date-chip {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-areas:
    "day date"
    "count count";
  gap: 2px 8px;
  min-width: 158px;
  min-height: 54px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
}

.date-chip.active {
  border-color: var(--brand);
  background: #ecfdf5;
  box-shadow: inset 0 0 0 1px rgba(15, 118, 110, 0.3);
}

.date-chip-day {
  grid-area: day;
  color: var(--muted);
  font-size: 15px;
  font-weight: 800;
}

.date-chip-date {
  grid-area: date;
  justify-self: end;
  font-size: 15px;
  font-weight: 800;
}

.date-chip-count {
  grid-area: count;
  color: var(--ink);
  font-size: 16px;
  font-weight: 850;
}

.workspace {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(760px, 1fr) minmax(330px, 380px);
  gap: 10px;
  height: clamp(640px, calc(100vh - 310px), 840px);
  min-height: 0;
}

.side-stack {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 8px;
  min-height: 0;
}

.list-panel,
.map-panel,
.detail-panel {
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.list-panel,
.detail-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-heading,
.map-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
}

.count-pill,
.status-badge,
.table-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 999px;
  white-space: nowrap;
  font-weight: 800;
}

.status-badge .icon,
.table-status .icon {
  width: 15px;
  height: 15px;
}

.count-pill {
  min-height: 28px;
  padding: 0 9px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
}

.filters {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.search-box input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
}

.filters select {
  min-height: 44px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0 10px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  min-height: 36px;
}

.toggle-row input {
  width: 22px;
  height: 22px;
  accent-color: var(--brand);
}

.county-list {
  flex: 1 1 auto;
  overflow: auto;
}

.county-row {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 10px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.county-row:hover,
.county-row.selected {
  background: #f1f5f9;
}

.county-row.selected {
  box-shadow: inset 3px 0 0 var(--brand);
}

.risk-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.22);
}

.risk-dot.warning {
  box-shadow: 0 0 0 3px #fee2e2;
}

.risk-dot.near {
  box-shadow: 0 0 0 3px #ffedd5;
}

.risk-dot.below {
  box-shadow: 0 0 0 3px #f1f5f9;
}

.county-main,
.county-metrics {
  display: grid;
  gap: 2px;
}

.county-main {
  min-width: 0;
}

.county-main strong,
.county-main small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.county-main small,
.county-metrics small {
  color: var(--muted);
  font-size: 11px;
}

.county-metrics {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.map-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.map-canvas {
  width: 100%;
  height: 100%;
  min-height: 520px;
}

.map-controls {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.segmented-button {
  min-height: 36px;
  padding: 0 13px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.segmented-button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.12);
}

.legend-inline {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.legend-inline span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-inline i {
  display: inline-block;
  width: 13px;
  height: 13px;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.22);
}

.legend-key.warning,
.legend-key.near {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.75);
}

.leaflet-container {
  font: inherit;
  background: #e7eef5;
}

.leaflet-tooltip {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
}

.detail-panel {
  padding-bottom: 10px;
}

.detail-panel > .muted {
  padding: 12px;
  margin: 0;
  line-height: 1.45;
}

.status-badge {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.status-badge.warning,
.table-status.warning {
  background: #fee2e2;
  color: #991b1b;
}

.status-badge.near,
.table-status.near {
  background: #ffedd5;
  color: #92400e;
}

.status-badge.below,
.table-status.below {
  background: #e2e8f0;
  color: #334155;
}

.status-badge.missing,
.table-status.missing {
  background: #f1f5f9;
  color: #475569;
}

.detail-metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 12px;
}

.detail-metrics div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.detail-metrics span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.detail-metrics strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.meaning-panel {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 10px;
  margin: 0 12px 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.meaning-panel.warning {
  border-color: #fecaca;
  background: #fff1f2;
}

.meaning-panel.near {
  border-color: #fed7aa;
  background: #fff7ed;
}

.meaning-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--brand-dark);
}

.meaning-panel.warning .meaning-icon {
  color: var(--danger);
}

.meaning-panel.near .meaning-icon {
  color: var(--warning);
}

.meaning-panel h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.25;
}

.meaning-panel p {
  margin: 5px 0 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
}

.danger-text {
  color: var(--danger);
}

.forecast-table-wrap {
  overflow: auto;
  padding: 0 12px;
}

.forecast-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.forecast-table th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.forecast-table th,
.forecast-table td {
  padding: 8px 5px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

.current-row {
  background: #ecfdf5;
}

.table-status {
  min-height: 24px;
  padding: 0 9px;
  font-size: 11px;
}

.empty-state,
.loading-screen {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  min-height: 260px;
  padding: 20px;
  text-align: center;
  color: var(--muted);
}

.loading-screen {
  min-height: 100vh;
}

.loading-screen.error {
  color: var(--ink);
}

.loading-screen button {
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
}

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid #cbd5e1;
  border-top-color: var(--brand);
  border-radius: 999px;
  animation: spin 0.75s linear infinite;
}

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

.app-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 2px 10px;
  font-size: 12px;
  line-height: 1.45;
}

.app-footer a {
  color: var(--brand-dark);
  font-weight: 800;
}

@media (max-width: 1180px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(540px, 62vh) auto;
    height: auto;
  }

  .side-stack {
    grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
    grid-template-rows: auto;
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 8px;
    gap: 10px;
  }

  .app-header {
    flex-direction: column;
    padding: 14px;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .updated-pill,
  .icon-button {
    flex: 1 1 auto;
  }

  h1 {
    font-size: 27px;
  }

  .stats-grid,
  .workspace {
    grid-template-columns: 1fr;
  }

  .date-rail {
    position: sticky;
    top: 0;
    z-index: 500;
    margin: 0 -8px;
    padding: 8px;
    background: rgba(237, 243, 246, 0.96);
    border-block: 1px solid rgba(203, 213, 225, 0.72);
    backdrop-filter: blur(8px);
  }

  .side-stack {
    grid-template-columns: 1fr;
  }

  .workspace {
    min-height: 0;
    grid-template-rows: minmax(470px, 58vh) auto;
  }

  .map-panel {
    min-height: 470px;
  }

  .list-panel {
    max-height: 520px;
  }

  .app-footer {
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .brand-block {
    align-items: center;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .subtitle {
    font-size: 14px;
  }

  .updated-pill,
  .icon-button {
    width: 100%;
  }

  .date-chip {
    min-width: 150px;
  }

  .map-controls {
    justify-items: stretch;
  }

  .segmented {
    width: 100%;
  }

  .segmented-button {
    flex: 1 1 0;
  }

  .map-canvas {
    min-height: 420px;
  }

  .detail-metrics {
    grid-template-columns: 1fr;
  }

  .map-toolbar,
  .panel-heading {
    flex-direction: column;
    align-items: stretch;
  }

  .legend-inline {
    justify-content: flex-start;
  }

  .meaning-panel {
    grid-template-columns: 1fr;
  }
}
