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

:root {
  --bg: #0d0d0f;
  --surface: #16161a;
  --surface2: #1e1e24;
  --border: #2a2a35;
  --text: #e8e8f0;
  --text-muted: #7070a0;
  --accent: #e63946;
  --accent2: #f4a261;
  --accent3: #06d6a0;
  --accent4: #457b9d;
  --risk-very-low: #1a1a2e;
  --risk-low: #16213e;
  --risk-moderate: #f4a261;
  --risk-high: #e07020;
  --risk-very-high: #e63946;
  --font: 'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --header-h: 64px;
  --panel-w: 280px;
}

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

/* ── Header ──────────────────────────────────────────────────────────── */
#header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  height: var(--header-h);
  background: rgba(13,13,15,0.96);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 16px;
  gap: 24px;
  backdrop-filter: blur(8px);
}

.header-left { flex-shrink: 0; }

.header-eyebrow {
  font-size: 10px; font-weight: 500; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 2px;
}

#header h1 { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }

.header-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

#stat-bar {
  display: flex; gap: 20px; align-items: center;
  padding-left: 20px; border-left: 1px solid var(--border);
  flex: 1; overflow-x: auto;
}

.stat-item { text-align: center; min-width: 64px; }

.stat-value {
  display: block; font-size: 16px; font-weight: 700;
  font-family: var(--mono); color: var(--text); white-space: nowrap;
}

.stat-value.verdict { color: var(--accent3); }

.stat-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

/* ── Map ──────────────────────────────────────────────────────────────── */
#map {
  position: fixed;
  top: var(--header-h); left: 0; right: 0;
  bottom: 0; z-index: 1;
}

/* ── Controls ─────────────────────────────────────────────────────────── */
#controls {
  position: fixed;
  top: calc(var(--header-h) + 12px);
  left: 12px;
  z-index: 900;
  background: rgba(22,22,26,0.97);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  width: 190px;
  backdrop-filter: blur(8px);
}

.controls-title {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--text-muted); margin-bottom: 10px;
}

.layer-toggle {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 5px;
  cursor: pointer; transition: background 0.15s; margin-bottom: 2px;
  font-size: 12px; font-weight: 500;
}

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

.layer-toggle input { display: none; }

.dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}

hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }

.overlay-toggle .dot { border-radius: 2px; }

/* ── Legend ───────────────────────────────────────────────────────────── */
#legend {
  position: fixed;
  bottom: 24px;
  left: 12px;
  z-index: 900;
  background: rgba(22,22,26,0.97);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  min-width: 160px;
  backdrop-filter: blur(8px);
}

.legend-title {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--text-muted); margin-bottom: 8px;
}

.legend-item {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 5px; font-size: 11px;
}

.legend-swatch {
  width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0;
}

/* ── Info Panel ───────────────────────────────────────────────────────── */
#info-panel {
  position: fixed;
  top: calc(var(--header-h) + 12px);
  right: 12px;
  z-index: 900;
  background: rgba(22,22,26,0.97);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  width: var(--panel-w);
  max-height: calc(100vh - var(--header-h) - 24px);
  overflow-y: auto;
  backdrop-filter: blur(8px);
}

.info-heading {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--text-muted); margin-bottom: 8px;
}

#info-panel p {
  font-size: 12px; line-height: 1.6; color: #b0b0c8; margin-bottom: 12px;
}

.finding-box {
  background: var(--surface2); border-radius: 6px;
  padding: 8px 10px; margin-bottom: 6px;
}

.finding-box.confirmed { border-left: 3px solid var(--accent3); }

.finding-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 3px; }

.finding-value { font-size: 12px; font-weight: 600; font-family: var(--mono); color: var(--text); }

.source-list { list-style: none; padding: 0; }

.source-list li {
  font-size: 11px; color: #9090b0;
  padding: 3px 0; border-bottom: 1px solid var(--border);
}

.source-list li:last-child { border-bottom: none; }

/* Tract detail */
#info-back {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); border-radius: 5px; padding: 4px 10px;
  cursor: pointer; font-size: 11px; margin-bottom: 12px;
}

#info-back:hover { background: var(--border); }

.tract-risk-badge {
  display: inline-block; padding: 4px 12px; border-radius: 20px;
  font-size: 12px; font-weight: 700; margin-bottom: 12px;
}

.tract-table { width: 100%; border-collapse: collapse; }

.tract-table tr td {
  padding: 5px 4px; font-size: 11px;
  border-bottom: 1px solid var(--border);
}

.tract-table tr td:first-child { color: var(--text-muted); width: 55%; }
.tract-table tr td:last-child { font-family: var(--mono); font-weight: 600; text-align: right; }

/* ── Loading ──────────────────────────────────────────────────────────── */
#loading {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}

.loading-inner { text-align: center; }

.spinner {
  width: 40px; height: 40px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 0 auto 16px;
}

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

.loading-text { color: var(--text-muted); font-size: 13px; }

/* ── Leaflet overrides ────────────────────────────────────────────────── */
.leaflet-control-zoom {
  border: 1px solid var(--border) !important;
  border-radius: 6px !important;
  overflow: hidden;
}

.leaflet-control-zoom a {
  background: rgba(22,22,26,0.97) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

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

.leaflet-popup-content-wrapper {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  color: var(--text) !important;
  font-family: var(--font) !important;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5) !important;
}

.leaflet-popup-tip { background: var(--surface) !important; }

.leaflet-popup-content { margin: 10px 12px !important; }

/* ── Scrollbar ────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #stat-bar { display: none; }
  #info-panel { display: none; }
  :root { --panel-w: 240px; }
}
