:root {
  --ink: #1c2430;
  --muted: #5c6775;
  --paper: #f4f1ea;
  --panel: #fbfaf6;
  --line: #e2dbd0;
  --accent: #0f6e62;
  --accent-ink: #08473f;
  --district: #9f1239;
  --highlight: #d97706;
  --shadow: 0 10px 30px rgba(28, 36, 48, 0.08);
  --panel-width: 390px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", "Helvetica Neue", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

#app {
  display: flex;
  height: 100%;
  min-height: 100vh;
}

#panel {
  width: var(--panel-width);
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 2;
}

.brand { padding: 18px 18px 8px; }
.eyebrow {
  margin: 0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--accent);
  font-weight: 700;
}
h1 { margin: 4px 0 0; font-size: 26px; line-height: 1.1; font-weight: 720; }
.corte { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px 18px;
}
.stat {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 10px 8px;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.stat:hover, .stat.is-on { border-color: var(--accent); }
.stat-value {
  display: block;
  font-size: 22px;
  font-weight: 760;
  letter-spacing: -0.03em;
  color: var(--accent-ink);
}
.stat-label { display: block; font-size: 12px; font-weight: 700; margin-top: 2px; }
.stat-note { display: block; font-size: 11px; color: var(--muted); }

.search { display: block; padding: 0 18px 10px; }
.search input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
}
.search input:focus { outline: 2px solid rgba(15, 110, 98, 0.35); border-color: var(--accent); }

.layers {
  margin: 0 18px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px 10px;
  background: #fff;
}
.layers legend { font-size: 12px; font-weight: 700; padding: 0 4px; }
.layers label {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 13px;
  padding: 3px 0;
  cursor: pointer;
}

.tabs { display: flex; gap: 6px; padding: 0 18px 8px; }
.tab {
  flex: 1;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 6px 4px;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  color: var(--muted);
}
.tab.is-on { background: var(--accent); color: #fff; border-color: var(--accent); }

.detail {
  margin: 0 18px 8px;
  padding: 10px 12px;
  background: #fff8ee;
  border: 1px solid #f3d7b0;
  border-radius: 12px;
  font-size: 13px;
}
.detail h2 { margin: 0 0 4px; font-size: 16px; }
.detail p { margin: 4px 0; }
.detail ul { margin: 6px 0 0; padding-left: 18px; max-height: 120px; overflow: auto; }
.detail button {
  margin-top: 8px;
  border: 0;
  background: transparent;
  color: var(--accent-ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
}

.list {
  flex: 1;
  overflow: auto;
  padding: 0 10px 8px;
  min-height: 120px;
}
.row {
  width: calc(100% - 16px);
  margin: 0 8px 6px;
  text-align: left;
  border: 1px solid transparent;
  background: #fff;
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.row:hover, .row.is-on { border-color: var(--accent); }
.row b { display: block; font-size: 14px; }
.row span { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.hint { color: var(--muted); font-size: 12px; padding: 4px 16px 10px; }

.sources {
  border-top: 1px solid var(--line);
  padding: 10px 18px 14px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}
.sources p { margin: 0 0 6px; }

#map-wrap { position: relative; flex: 1; min-width: 0; }
#map { height: 100%; width: 100%; background: #d7e0dc; }

#panel-toggle {
  position: absolute;
  z-index: 500;
  top: 12px;
  right: 12px;
  border: 0;
  background: #fff;
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.legend {
  position: absolute;
  z-index: 500;
  right: 12px;
  bottom: 28px;
  background: rgba(251, 250, 246, 0.95);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 12px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 4px;
}
.legend strong { font-size: 12px; }
.legend span { display: flex; align-items: center; gap: 8px; }
.swatch { width: 18px; height: 10px; border-radius: 2px; display: inline-block; }
.swatch.district { background: transparent; border: 3px solid var(--district); height: 8px; }
.swatch.section { background: rgba(15, 110, 98, 0.35); border: 1px solid #1c2430; }
.swatch.highlight { background: rgba(217, 119, 6, 0.7); }
.swatch.street { background: #1d4ed8; height: 3px; }

.sec-label {
  background: none !important;
  border: none !important;
  font-size: 11px;
  font-weight: 800;
  color: #1c2430;
  text-shadow: -1px 0 #fff, 1px 0 #fff, 0 -1px #fff, 0 1px #fff, 0 0 4px #fff;
  width: auto !important;
  height: auto !important;
  white-space: nowrap;
}
.sec-label.is-hot { color: #9a3412; }

.leaflet-popup-content { margin: 10px 12px; font-size: 13px; }
.leaflet-popup-content h3 { margin: 0 0 4px; font-size: 15px; }
.leaflet-popup-content p { margin: 2px 0; }

#loading {
  position: fixed;
  inset: 0;
  background: var(--paper);
  display: grid;
  place-items: center;
  font-size: 18px;
  z-index: 20;
}
#loading.is-hidden { display: none; }

body.panel-closed #panel { display: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

@media (max-width: 860px) {
  #app { flex-direction: column-reverse; }
  #panel { width: 100%; height: 46vh; border-right: 0; border-top: 1px solid var(--line); }
  #map-wrap { height: 54vh; }
  body.panel-closed #map-wrap { height: 100vh; }
}
