:root {
  --paper: #f4f0e7;
  --paper-2: #fbf8f2;
  --ink: #1c1915;
  --muted: #6f675d;
  --line: #e3d9cb;
  --copper: #9a3412;
  --copper-ink: #7c2d12;
  --chip: #efe6d8;
  --shadow: 0 10px 30px rgba(48, 32, 16, 0.08);
  --sans: "Avenir Next", "Segoe UI", "PingFang SC", "Noto Sans SC", "Microsoft YaHei",
    "WenQuanYi Micro Hei", "Droid Sans Fallback", sans-serif;
  --sidebar: 372px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }

#app {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 12px 16px;
  background: var(--paper-2);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }
.mark {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 9px;
  background:
    linear-gradient(#fff, #fff) center 22px / 14px 2px no-repeat,
    linear-gradient(#fff, #fff) center 16px / 10px 2px no-repeat,
    linear-gradient(#fff, #fff) center 10px / 6px 2px no-repeat,
    var(--copper);
}
.brand h1 { font-size: 20px; letter-spacing: 0.01em; font-weight: 650; }
.brand p { color: var(--muted); font-size: 13px; }
.header-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.count {
  background: var(--chip);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.view-toggle { display: flex; background: var(--chip); border-radius: 999px; padding: 3px; }
.view-toggle button {
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 6px 12px;
}
.view-toggle button[aria-selected="true"] { background: var(--ink); color: #fff; }
.btn {
  border: 1px solid var(--copper);
  background: var(--copper);
  color: #fff;
  border-radius: 999px;
  padding: 7px 12px;
}
.btn.ghost { background: transparent; color: var(--copper-ink); }
.btn.tiny { padding: 5px 10px; font-size: 13px; background: #fff; color: var(--ink); border-color: var(--line); }
.btn:hover { filter: brightness(1.05); }
.textish { border: 0; background: transparent; color: var(--copper-ink); padding: 0; text-decoration: underline; text-underline-offset: 2px; }

.banner {
  padding: 8px 16px;
  background: #fde8d8;
  color: #7c2d12;
  border-bottom: 1px solid #f3c7a8;
}
.banner.error { background: #fee2e2; color: #7f1d1d; border-color: #fecaca; }

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
}

.sidebar {
  min-height: 0;
  overflow: hidden;
  padding: 14px 14px 12px;
  border-right: 1px solid var(--line);
  background: var(--paper-2);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sidebar-controls {
  overflow: auto;
  flex: 0 1 54%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 2px;
}
.search, .filters label, .color-mode label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.search input, .filters input, .filters select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--ink);
}
.search input:focus, .filters input:focus, .filters select:focus {
  outline: 2px solid #fdba74;
  border-color: var(--copper);
}
.color-mode, .filters {
  border: 1px solid var(--line);
  border-radius: 12px;
  margin: 0;
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #fff;
}
.color-mode legend { padding: 0 4px; font-size: 13px; color: var(--muted); }
.color-mode label { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.check { flex-direction: row !important; align-items: center; gap: 8px; color: var(--ink) !important; }
.hint { color: var(--muted); font-size: 12px; margin: 0; }
.coverage {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  color: #7c2d12;
}
.coverage strong { display: block; margin-bottom: 4px; }
.coverage p + p { margin-top: 6px; }

.results {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.results .result-list { overflow: auto; min-height: 0; }
.results-head { display: flex; justify-content: space-between; align-items: baseline; }
.results h2 { font-size: 14px; font-weight: 650; }
.result-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.result-list button {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 8px;
  align-items: start;
}
.result-list button.is-active { border-color: var(--copper); box-shadow: inset 3px 0 0 var(--copper); }
.result-list .dot { width: 10px; height: 10px; border-radius: 99px; margin-top: 4px; border: 1px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.15); }
.result-list strong { display: block; font-weight: 650; }
.result-list small { color: var(--muted); }

.stage { position: relative; min-height: 0; min-width: 0; }
#mapWrap, #map { height: 100%; }
#mapWrap { position: relative; }
.map-tools { position: absolute; z-index: 500; top: 12px; right: 12px; }
.legend {
  position: absolute;
  z-index: 500;
  left: 12px;
  bottom: 28px;
  background: rgba(255, 252, 247, 0.95);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  min-width: 168px;
  max-width: 280px;
  max-height: 46vh;
  overflow: auto;
  box-shadow: var(--shadow);
  font-size: 13px;
}
.legend h3 { margin: 0 0 6px; font-size: 13px; }
.legend ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.legend li { display: flex; gap: 8px; align-items: center; }
.swatch { width: 12px; height: 12px; border-radius: 99px; border: 1px solid rgba(0,0,0,.15); flex: none; }

.table-wrap[hidden] { display: none !important; }
.table-wrap { height: 100%; display: flex; flex-direction: column; background: var(--paper); }
.table-scroll { min-height: 0; overflow: auto; flex: 1; }
table { border-collapse: collapse; width: max-content; min-width: 100%; background: #fff; }
th, td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; white-space: nowrap; font-size: 13.5px; }
th {
  position: sticky;
  top: 0;
  background: #f6f1e8;
  z-index: 1;
  font-weight: 650;
}
th button { border: 0; background: transparent; padding: 0; display: inline-flex; gap: 4px; align-items: center; }
th button:hover { color: var(--copper-ink); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 28px 16px; color: var(--muted); }
.linkish { color: var(--copper-ink); }

.leaflet-container { background: #e7e1d6; font-family: var(--sans); }
.leaflet-popup-content-wrapper {
  border-radius: 12px;
  background: #fffdf9;
  color: var(--ink);
  box-shadow: var(--shadow);
}
.leaflet-popup-content { margin: 12px 14px; width: 280px; }
.leaflet-popup-content h3 { margin: 0 0 2px; font-size: 16px; line-height: 1.3; }
.leaflet-popup-content .addr { color: var(--muted); margin-bottom: 8px; font-size: 13px; }
.popup-table { width: 100%; border-collapse: collapse; }
.popup-table th { position: static; background: transparent; font-weight: 500; color: var(--muted); width: 46%; white-space: normal; padding: 4px 6px 4px 0; font-size: 12.5px; border: 0; }
.popup-table td { white-space: normal; padding: 4px 0; border: 0; font-size: 13px; }
.popup-table a { color: var(--copper-ink); }
.popup-note { margin-top: 8px; font-size: 12px; color: var(--muted); }
.cluster-icon { background: transparent; border: 0; }
.cluster-bubble {
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--copper);
  color: #fff;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

body.mode-table #mapWrap { display: none; }
body.mode-table #tableWrap { display: flex; }
body.mode-table .results { display: none; }

@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: auto minmax(280px, 1fr); }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); max-height: 48vh; overflow: auto; }
  .sidebar-controls { flex: none; overflow: visible; }
  .results { flex: none; }
  .results .result-list { overflow: visible; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .brand p { display: none; }
  .leaflet-popup-content { width: 230px; }
  body.mode-table .sidebar { max-height: none; }
  body.mode-table .workspace { grid-template-rows: auto minmax(0, 1fr); }
}
