/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #111827;
  --surface: #1f2937;
  --surface2: #374151;
  --border: #374151;
  --text: #f9fafb;
  --text-muted: #9ca3af;
  --accent: #ef4444;
  --accent-muted: #fca5a5;
  --sidebar-w: 320px;
  --font: 'Segoe UI', system-ui, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ── Layout ── */
#sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0;
}

#map {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  bottom: 0;
  z-index: 1;
}

/* ── Sidebar Header ── */
#sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border);
}

#sidebar-header h1 {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  letter-spacing: -0.3px;
}

.subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.4;
}

.region {
  font-size: 11px;
  color: var(--accent-muted);
  margin-top: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Stats Panel ── */
#stats-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
}

.stat-box {
  background: var(--surface);
  padding: 14px 12px;
  text-align: center;
}

.stat-box.critical {
  background: #1c0a0a;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.stat-box.critical .stat-value {
  color: #f87171;
}

.stat-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.3;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ── Layer Controls ── */
#layer-controls {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

#layer-controls h3,
#legend h3,
#method-note h3 {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}

.radio-label:hover {
  background: var(--surface2);
  color: var(--text);
}

.radio-label.active {
  background: var(--surface2);
  color: var(--text);
}

.radio-label input[type="radio"] {
  accent-color: var(--accent);
}

#ems-toggle {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  accent-color: #3b82f6;
}

/* ── Legend ── */
#legend {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

#legend-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

#legend-items {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.legend-swatch {
  width: 20px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ── Method Note ── */
#method-note {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex: 1;
}

#method-note p {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 8px;
}

#method-note p:last-child { margin-bottom: 0; }

/* ── Sidebar Footer ── */
#sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

#sidebar-footer a {
  font-size: 12px;
  color: #60a5fa;
  text-decoration: none;
}

#sidebar-footer a:hover { text-decoration: underline; }

/* ── Info Panel ── */
#info-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  width: 260px;
  z-index: 1000;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}

#info-panel.hidden { display: none; }

#info-close {
  position: absolute;
  top: 10px; right: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}

#info-close:hover { color: var(--text); }

#info-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
  padding-right: 20px;
}

#info-table {
  width: 100%;
  border-collapse: collapse;
}

#info-table tr {
  border-bottom: 1px solid var(--border);
}

#info-table tr:last-child { border-bottom: none; }

#info-table td {
  padding: 5px 0;
  font-size: 12px;
}

#info-table td:first-child {
  color: var(--text-muted);
  width: 55%;
}

#info-table td:last-child {
  color: var(--text);
  text-align: right;
  font-weight: 600;
}

/* ── Leaflet overrides ── */
.leaflet-control-zoom a {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

.leaflet-control-zoom a:hover {
  background: var(--surface2) !important;
}

.leaflet-control-attribution {
  background: rgba(17,24,39,0.8) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
}

.leaflet-control-attribution a { color: #60a5fa !important; }

/* ── EMS station popup ── */
.ems-popup {
  font-family: var(--font);
  font-size: 12px;
  color: #111;
}

.ems-popup strong { display: block; margin-bottom: 2px; }

/* ── Mobile ── */
@media (max-width: 768px) {
  :root { --sidebar-w: 100vw; }

  #sidebar {
    height: auto;
    max-height: 45vh;
    bottom: 0;
    top: auto;
    left: 0;
    right: 0;
    width: 100vw;
    border-right: none;
    border-top: 1px solid var(--border);
  }

  #map {
    left: 0;
    bottom: 45vh;
    top: 0;
  }

  #info-panel {
    bottom: calc(45vh + 10px);
    right: 10px;
    width: 220px;
  }
}
