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

:root {
  --sidebar-w: 320px;
  --green: #2d6a4f;
  --green-light: #52b788;
  --bg: #0e1117;
  --surface: #181e2a;
  --surface2: #1e2535;
  --text: #e8eaf0;
  --text-muted: #8a93a8;
  --accent: #e63946;
  --border: #2a3345;
  --font: 'Segoe UI', system-ui, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--green-light); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ───────────────────────────────────────────────── */
body {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0;
  scroll-behavior: smooth;
}

#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

#map {
  flex: 1;
  height: 100vh;
}

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

#sidebar-header h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--green-light);
  letter-spacing: 0.5px;
}

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

/* ── Section headings ─────────────────────────────────────── */
#sidebar h2 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  padding: 14px 18px 8px;
  border-bottom: 1px solid var(--border);
}

/* ── Layer Controls ───────────────────────────────────────── */
#layer-controls {
  padding-bottom: 4px;
}

.layer-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
  font-size: 13px;
  color: var(--text-muted);
}

.layer-toggle:hover { background: var(--surface2); color: var(--text); }
.layer-toggle.active { color: var(--text); }

.layer-toggle input[type="checkbox"] {
  display: none;
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.15);
}

/* ── Stats Panel ──────────────────────────────────────────── */
#stats-panel {
  padding: 0 0 4px;
  border-bottom: 1px solid var(--border);
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  margin: 0;
}

.stat {
  background: var(--surface2);
  padding: 14px 12px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.stat-val {
  font-size: 22px;
  font-weight: 700;
  color: var(--green-light);
  line-height: 1;
}

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

.footnote {
  font-size: 10px;
  color: var(--text-muted);
  padding: 8px 18px;
  line-height: 1.5;
}

/* ── Info Panel ───────────────────────────────────────────── */
#info-panel {
  border-bottom: 1px solid var(--border);
}

#info-content {
  padding: 12px 18px;
  font-size: 13px;
}

#info-content .muted {
  color: var(--text-muted);
  font-style: italic;
}

.info-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--green-light);
  margin-bottom: 8px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.info-row:last-child { border: none; }
.info-row .lbl { color: var(--text-muted); }
.info-row .val { font-weight: 500; }

.transit-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-yes { background: #1a4731; color: #52b788; }
.badge-no  { background: #3d1a1a; color: #e07070; }

/* ── HOLC Note ────────────────────────────────────────────── */
#holc-note {
  padding: 14px 18px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
  border-bottom: 1px solid var(--border);
}

#holc-note p { margin-bottom: 8px; }
#holc-note code {
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
  color: var(--text);
}

/* ── Footer ───────────────────────────────────────────────── */
footer {
  margin-top: auto;
  padding: 14px 18px;
  font-size: 10px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  line-height: 1.8;
}

/* ── Legend ───────────────────────────────────────────────── */
#legend {
  position: absolute;
  bottom: 24px;
  right: 16px;
  background: rgba(14,17,23,0.92);
  border: 1px solid #2a3345;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 11px;
  color: #e8eaf0;
  z-index: 1000;
  backdrop-filter: blur(4px);
  min-width: 150px;
  display: none;
}

#legend.visible { display: block; }
#legend h3 { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: #8a93a8; margin-bottom: 6px; }
#legend hr { border-color: #2a3345; margin: 8px 0; }

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.legend-box {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 2px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.1);
}

.legend-circle {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Leaflet overrides ─────────────────────────────────────── */
.leaflet-popup-content-wrapper {
  background: #181e2a;
  color: #e8eaf0;
  border: 1px solid #2a3345;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.leaflet-popup-tip { background: #181e2a; }
.leaflet-popup-content { font-size: 13px; margin: 12px 14px; }
.leaflet-popup-content b { color: #52b788; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 640px) {
  body { flex-direction: column; }
  #sidebar {
    width: 100%;
    min-width: unset;
    height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  #map { height: 60vh; }
  #legend { display: none !important; }
}
