:root {
  --bg: #fafafa;
  --panel: #fff;
  --border: #e3e3e3;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
  --radius: 6px;
  --sidebar-w: 340px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; color: var(--text); background: var(--bg); }
button { font: inherit; cursor: pointer; }

#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
}
.sidebar-header h1 { margin: 0; font-size: 16px; font-weight: 600; }
#filtered-count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.panel { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.panel:last-child { border-bottom: none; }
.panel h2 { margin: 0 0 10px 0; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.link-btn { background: none; border: none; color: var(--accent); font-size: 12px; padding: 0; }
.link-btn:hover { color: var(--accent-hover); }

.filter-group { margin-bottom: 14px; }
.filter-group:last-child { margin-bottom: 0; }
.filter-label { font-size: 12px; font-weight: 500; color: var(--muted); display: block; margin-bottom: 6px; }
.filter-row { display: flex; gap: 6px; }
.filter-row > * { flex: 1; min-width: 0; }

input[type="text"], input[type="date"], input[type="search"] {
  width: 100%;
  padding: 6px 8px;
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
}
input[type="text"]:focus, input[type="date"]:focus, input[type="search"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

.checklist {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  background: var(--panel);
}
.checklist label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  font-size: 13px;
  border-radius: 3px;
  cursor: pointer;
}
.checklist label:hover { background: rgba(0,0,0,0.04); }
.checklist input { margin: 0; }
.checklist .count { margin-left: auto; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.checklist .swatch { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

details > summary {
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
  color: var(--text);
  user-select: none;
}
details[open] > summary { margin-bottom: 6px; }

.layer-toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.layer-toggle input { margin: 0; }

.toggles { display: flex; flex-wrap: wrap; gap: 6px; }
.toggle {
  font-size: 12px;
  padding: 4px 9px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 999px;
  cursor: pointer;
  color: var(--muted);
}
.toggle.on { background: var(--accent); color: white; border-color: var(--accent); }

#stats {
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-row { display: flex; justify-content: space-between; gap: 8px; }
.stat-row .k { color: var(--muted); }
.stat-row .v { font-variant-numeric: tabular-nums; font-weight: 500; }
.stat-section { margin-top: 8px; }
.stat-section h3 { margin: 8px 0 4px 0; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
.stat-list { list-style: none; padding: 0; margin: 0; font-size: 12px; }
.stat-list li { display: flex; justify-content: space-between; padding: 2px 0; }
.stat-list li .v { color: var(--muted); font-variant-numeric: tabular-nums; }

#map { flex: 1; min-width: 0; }
.maplibregl-popup-content { font-size: 13px; padding: 10px 12px; border-radius: var(--radius); box-shadow: var(--shadow); }
.popup h3 { margin: 0 0 4px 0; font-size: 14px; }
.popup .meta { color: var(--muted); font-size: 12px; line-height: 1.4; }
.popup .meta .row { display: flex; gap: 4px; margin-top: 2px; }
.popup .meta .row strong { color: var(--text); font-weight: 500; }
.popup a { color: var(--accent); text-decoration: none; font-size: 12px; }
.popup .badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 999px; background: rgba(0,0,0,0.06); color: var(--muted); margin-right: 4px; }

#filters-toggle, #stats-toggle { display: none; }

#edit-panel {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  font-size: 13px;
  z-index: 10;
  min-width: 240px;
}
#edit-panel h3 { margin: 0 0 8px 0; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
#edit-panel label { display: block; margin-bottom: 8px; }
#edit-panel input[type="range"] { width: 100%; margin-top: 4px; }
#edit-panel button { background: var(--accent); color: white; border: none; padding: 5px 10px; border-radius: var(--radius); font-size: 12px; }
#edit-panel pre { font-size: 11px; background: #f4f4f4; padding: 8px; border-radius: var(--radius); margin: 8px 0 0 0; overflow-x: auto; }
.muted { color: var(--muted); font-size: 11px; margin: 0; }

#coverage-status {
  position: absolute;
  top: 12px;
  left: calc(var(--sidebar-w) + 12px);
  background: rgba(255,255,255,0.95);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 12px;
  color: var(--muted);
  box-shadow: var(--shadow);
  z-index: 5;
}
@media (max-width: 768px) {
  #coverage-status { left: 12px; top: 12px; }
}

#loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.95);
  font-size: 14px;
  color: var(--muted);
  z-index: 100;
}
#loading.hidden { display: none; }

@media (max-width: 768px) {
  #app { flex-direction: column; }
  #sidebar {
    position: fixed;
    inset: 0;
    width: 100%;
    z-index: 20;
    transform: translateY(100%);
    transition: transform 0.25s ease;
  }
  #sidebar.open { transform: translateY(0); }
  #map { width: 100%; height: 100vh; }
  #filters-toggle, #stats-toggle {
    display: block;
    position: fixed;
    bottom: 16px;
    background: var(--accent);
    color: white;
    border: none;
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 13px;
    box-shadow: var(--shadow);
    z-index: 15;
  }
  #filters-toggle { left: 16px; }
  #stats-toggle { right: 16px; }
  #sidebar.open ~ #filters-toggle::after { content: " ✕"; }
  #edit-panel { top: auto; bottom: 70px; right: 12px; left: 12px; }
}
