:root {
  /* Emergency-services calm: warm slate, paper, signal red, navy, deep teal */
  --paper: #F4ECD8;
  --paper-2: #EDE3CB;
  --ink: #1B1A17;
  --ink-2: #2E2C27;
  --muted: #6E6A60;
  --faint: #B6AE9A;
  --rule: #C9BFA8;
  --rule-strong: #8C8470;
  --signal: #B5322A;       /* primary IFD red, used sparingly */
  --signal-deep: #7E1F19;
  --navy: #2E5A78;
  --teal: #0F7A6A;
  --gold: #A8770F;
  --plum: #5C3F7A;
  --shadow-1: 0 1px 2px rgba(27,26,23,.06), 0 4px 14px rgba(27,26,23,.06);
  --shadow-2: 0 2px 6px rgba(27,26,23,.10), 0 12px 32px rgba(27,26,23,.10);
  --radius: 8px;
  --radius-sm: 4px;
  --sidebar-w: 360px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: "Satoshi", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-feature-settings: "ss01", "cv11";
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  overflow: hidden;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--ink);
  color: var(--paper);
  border-bottom: 1px solid #000;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { color: var(--paper); flex: 0 0 auto; }
.brand-text h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
  font-family: "Satoshi", sans-serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-text p {
  margin: 0;
  font-size: 12px;
  color: rgba(244,236,216,0.7);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.menu-btn {
  display: none;
  background: transparent;
  color: var(--paper);
  border: 1px solid rgba(244,236,216,0.3);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  cursor: pointer;
}

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: calc(100vh - 57px);
  height: calc(100dvh - 57px);
}
.sidebar {
  border-right: 1px solid var(--rule);
  background: var(--paper-2);
  overflow-y: auto;
  padding: 18px 18px 32px;
  scrollbar-gutter: stable;
}
.map-wrap { position: relative; }
#map {
  width: 100%;
  height: 100%;
  background: #DCD2BA;
}

/* ---------- Panels ---------- */
.panel { padding-bottom: 18px; margin-bottom: 18px; border-bottom: 1px solid var(--rule); }
.panel:last-of-type { border-bottom: none; }
.panel-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  margin: 0 0 6px;
  color: var(--ink);
}
.panel-title .muted { color: var(--muted); font-weight: 500; letter-spacing: 0.06em; text-transform: none; }
.panel-help {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}

/* ---------- Filters ---------- */
.filters { display: flex; flex-direction: column; gap: 4px; }
.filters.compact { display: grid; grid-template-columns: 1fr; gap: 2px; }
.filter-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  font-size: 14px;
}
.filter-row:hover { background: rgba(27,26,23,0.05); }
.filter-row input { accent-color: var(--ink); width: 14px; height: 14px; margin: 0; }
.swatch {
  width: 12px; height: 12px; border-radius: 999px;
  border: 1.5px solid rgba(27,26,23,0.35);
  flex: 0 0 auto;
}
.filter-row .label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.filter-row .count {
  font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Select ---------- */
.select-wrap { position: relative; }
.select-wrap::after {
  content: "";
  position: absolute; right: 12px; top: 50%;
  width: 8px; height: 8px;
  border-right: 1.5px solid var(--ink);
  border-bottom: 1.5px solid var(--ink);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
#districtSelect {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  font-family: inherit;
  font-size: 14px;
  padding: 9px 32px 9px 12px;
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  color: var(--ink);
  cursor: pointer;
}
#districtSelect:focus { outline: 2px solid var(--ink); outline-offset: 1px; }

.unit-list {
  list-style: none; padding: 0; margin: 12px 0 0;
  display: flex; flex-wrap: wrap; gap: 6px;
}
.unit-list li {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11.5px;
  padding: 3px 8px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 999px;
  color: var(--ink-2);
  letter-spacing: 0.02em;
}
.unit-list li.matched { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* ---------- Legend ---------- */
.legend-list { list-style: none; padding: 0; margin: 0 0 10px; display: flex; flex-direction: column; gap: 6px; }
.legend-list li { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-2); }
.legend-list .swatch { width: 14px; height: 14px; }
.legend-list .approx-icon {
  width: 14px; height: 14px;
  background: var(--paper);
  border: 1.5px dashed var(--ink);
  border-radius: 50%;
}
.legend-note {
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-2);
  background: var(--paper);
  border-left: 3px solid var(--signal);
  padding: 10px 12px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.legend-note em { font-style: italic; }

.sidebar-footer p {
  margin: 0;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.5;
}

/* ---------- Markers ---------- */
.station-marker {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid var(--paper);
  box-shadow: 0 1px 2px rgba(0,0,0,0.4), 0 2px 6px rgba(0,0,0,0.18);
  display: grid; place-items: center;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 9.5px;
  font-weight: 700;
  color: var(--paper);
  letter-spacing: 0;
  line-height: 1;
}
.station-marker.approx {
  border-style: dashed;
  border-color: var(--paper);
  outline: 2px dotted rgba(0,0,0,0.5);
  outline-offset: -1px;
}
.station-marker.battalion-highlight {
  box-shadow: 0 0 0 4px rgba(0,0,0,0.18), 0 0 0 7px rgba(255,255,255,0.6), 0 2px 8px rgba(0,0,0,0.25);
}
.station-marker.district-match {
  box-shadow: 0 0 0 3px rgba(255,255,255,0.7), 0 0 0 6px var(--ink);
}
.station-marker.dimmed { opacity: 0.28; }

/* ---------- Popups ---------- */
.leaflet-popup-content-wrapper {
  background: var(--paper);
  color: var(--ink);
  border-radius: 8px;
  box-shadow: var(--shadow-2);
  border: 1px solid var(--rule);
}
.leaflet-popup-tip { background: var(--paper); border: 1px solid var(--rule); }
.leaflet-popup-content {
  margin: 14px 16px;
  font-size: 13px;
  line-height: 1.55;
  width: 280px !important;
}
.popup .pop-dept {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 4px;
  color: var(--paper);
  margin-bottom: 8px;
}
.popup h3 {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
}
.popup .area {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}
.popup .addr {
  font-size: 12.5px;
  color: var(--ink-2);
  margin: 0 0 10px;
}
.popup .row-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 10px;
  margin-bottom: 4px;
}
.popup .chips { display: flex; flex-wrap: wrap; gap: 4px; }
.popup .chip {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px;
  padding: 2px 7px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink-2);
}
.popup .chip.ems { background: #EFE2C9; border-color: var(--signal); color: var(--signal-deep); }
.popup .chip.batt { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.popup .confidence {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px;
  margin-top: 10px;
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--paper-2);
  color: var(--ink-2);
  border: 1px solid var(--rule);
}
.popup .confidence.high  { border-color: #6F8E5A; color: #3F5A2A; background:#E8EFD9; }
.popup .confidence.medium{ border-color: #B68A3C; color: #6E4F0F; background:#F2E5C4; }
.popup .confidence.low,
.popup .confidence.flag-approx { border-color: var(--signal); color: var(--signal-deep); background:#F2D9D4; }
.popup .notes {
  font-size: 12px;
  color: var(--ink-2);
  background: var(--paper-2);
  padding: 8px 10px;
  border-radius: 4px;
  border-left: 3px solid var(--rule-strong);
  margin-top: 10px;
}
.popup .sources {
  margin-top: 10px;
  font-size: 12px;
}
.popup .sources a {
  color: var(--signal-deep);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.popup .sources a:hover { color: var(--ink); }
.popup .sources span + span::before { content: " · "; color: var(--faint); }

/* Leaflet attribution restyle */
.leaflet-control-attribution {
  background: rgba(244,236,216,0.85) !important;
  color: var(--ink-2) !important;
  font-size: 11px !important;
}
.leaflet-control-attribution a { color: var(--signal-deep) !important; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  body { overflow: auto; }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .brand-text p { display: none; }
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    height: calc(100vh - 57px);
    height: calc(100dvh - 57px);
  }
  .sidebar {
    position: absolute;
    top: 57px;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1050;
    transform: translateY(-100%);
    transition: transform 240ms ease;
    border-right: none;
    border-bottom: 1px solid var(--rule);
    box-shadow: var(--shadow-2);
  }
  .sidebar.open { transform: translateY(0); }
  .map-wrap { grid-row: 1; }
  .leaflet-popup-content { width: 240px !important; }
}
