:root {
  --bg: #ffffff;
  --fg: #1d2421;
  --muted: #66706b;
  --line: #e2e6e3;
  --hover: #f3f5f4;
  --accent: #2f6f4f;
  --sidebar-w: 320px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171b19;
    --fg: #e6ebe8;
    --muted: #98a39d;
    --line: #2b322e;
    --hover: #222825;
    --accent: #7cc49d;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
}

#sidebar {
  width: var(--sidebar-w);
  flex: none;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--bg);
  z-index: 1000;
}
#sidebar header { padding: 16px 16px 12px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.brand img { flex: none; object-fit: contain; }
#sidebar h1 { margin: 0; font-size: 18px; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
#filter {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}
#layers { flex: 1; overflow-y: auto; padding: 4px 0 12px; }
#sidebar footer {
  display: flex;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}
a { color: var(--accent); }
.muted { color: var(--muted); padding: 0 16px; }

.group > summary {
  cursor: pointer;
  padding: 10px 16px 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  list-style-position: inside;
}
.layer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 16px;
}
.layer:hover { background: var(--hover); }
.layer label { flex: 1; display: flex; align-items: center; gap: 8px; cursor: pointer; min-width: 0; }
.layer .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer .count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.swatch { width: 14px; height: 14px; flex: none; border-radius: 3px; border: 2px solid; }
.swatch.point { border-radius: 50%; }
.swatch.line { height: 4px; border-width: 0; border-radius: 2px; }
.zoom {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 4px;
  font-size: 14px;
  visibility: hidden;
}
.layer:hover .zoom, .layer.on .zoom { visibility: visible; }
.layer.loading .count::after { content: " …"; }
.layer.error .count { color: #c0392b; }

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

#toggle-sidebar {
  display: none;
  position: absolute;
  top: 10px;
  left: 54px;
  z-index: 1100;
  width: 34px;
  height: 34px;
  border: 2px solid rgba(0,0,0,.2);
  border-radius: 4px;
  background: #fff;
  font-size: 16px;
  cursor: pointer;
}

.popup table { border-collapse: collapse; font-size: 12px; }
.popup th { text-align: left; padding: 2px 8px 2px 0; color: #66706b; font-weight: 500; vertical-align: top; }
.popup td { padding: 2px 0; }
.popup h3 { margin: 0 0 6px; font-size: 13px; }
.leaflet-popup-content { max-height: 320px; overflow-y: auto; }

.leaflet-tooltip.feature-tip {
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: rgba(23, 27, 25, .92);
  color: #f1f4f2;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .3);
  width: max-content;
  max-width: 320px;
  white-space: normal;
}
.leaflet-tooltip-top.feature-tip::before { border-top-color: rgba(23, 27, 25, .92); }
.tip strong { display: block; font-size: 13px; margin-bottom: 2px; }
.tip table { border-collapse: collapse; font-size: 12px; margin-top: 4px; }
.tip th { text-align: left; padding: 1px 10px 1px 0; color: #a9b4ae; font-weight: 500; vertical-align: top; white-space: nowrap; }
.tip td { padding: 1px 0; }
.tip-layer { display: block; margin-top: 5px; font-size: 11px; color: #8d9892; }

@media (max-width: 720px) {
  #sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    width: min(var(--sidebar-w), 85vw);
    transform: translateX(-100%);
    transition: transform .2s;
    box-shadow: 2px 0 12px rgba(0,0,0,.2);
  }
  body.sidebar-open #sidebar { transform: none; }
  #toggle-sidebar { display: block; }
  body.sidebar-open #toggle-sidebar { left: calc(min(var(--sidebar-w), 85vw) + 10px); }
}
