:root {
  --bg: #f5f4f0;
  --panel: #ffffff;
  --ink: #1d1c1a;
  --muted: #6d6a64;
  --line: #e3e0d9;
  --soft: #efede7;
  --accent: #0f6e5f;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe9;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .06);
  --radius: 10px;
  --header: 60px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --panel: #1b1b1b;
    --ink: #ecebe8;
    --muted: #9c9993;
    --line: #2d2c2a;
    --soft: #242322;
    --accent: #3cc7ad;
    --accent-ink: #08241f;
    --accent-soft: #163a33;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 4px 16px rgb(0 0 0 / .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.top {
  height: var(--header);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 1001;
}
.brand { min-width: 0; margin-right: auto; }
.brand h1 { font-size: 16px; font-weight: 650; letter-spacing: -.01em; white-space: nowrap; }
.brand h1 span { font-weight: 450; color: var(--muted); }
.brand p { font-size: 12px; }
.count { white-space: nowrap; font-variant-numeric: tabular-nums; }
.count strong { font-size: 16px; }

/* ---------- controls ---------- */
.seg {
  display: inline-flex;
  background: var(--soft);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
.seg button {
  border: 0;
  background: transparent;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  white-space: nowrap;
}
.seg button[aria-selected="true"], .seg button.on {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 2px rgb(0 0 0 / .12);
}
.seg.small button { padding: 3px 8px; font-size: 12px; }

.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.active { border-color: var(--accent); background: var(--accent-soft); }
.link {
  border: 0; background: none; padding: 0; cursor: pointer;
  color: var(--accent); font-size: 13px;
}
.pill {
  display: inline-block; margin-left: 6px; min-width: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  font-size: 11px; line-height: 18px; text-align: center;
}

input[type="search"], select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 8px;
  padding: 7px 10px;
  outline: none;
}
input[type="search"]:focus, select:focus { border-color: var(--accent); }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: calc(100dvh - var(--header));
}
aside {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.filters-scroll { overflow-y: auto; padding: 4px 16px 16px; flex: 1; }
.filters-foot {
  display: flex; gap: 8px; padding: 12px 16px;
  border-top: 1px solid var(--line);
}
.filters-foot .btn { flex: 1; }
main { position: relative; min-width: 0; min-height: 0; }
.view { position: absolute; inset: 0; }
.mobile-only { display: none; }

/* ---------- filter sections ---------- */
.f { padding: 14px 0; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.f:last-child { border-bottom: 0; }
.f-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.f-title { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }

.plan-chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; }
.plan-chip {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 6px 8px;
  text-align: left;
  cursor: pointer;
  display: grid;
  gap: 1px;
  position: relative;
}
.plan-chip::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--c);
}
.plan-chip b { font-weight: 600; font-size: 13px; }
.plan-chip small { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.plan-chip.on { border-color: var(--accent); background: var(--accent-soft); }
.plan-chip.zero { opacity: .45; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips:empty { display: none; }
.chip {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip.on::after { content: " ×"; }
.chip small { color: var(--muted); margin-left: 4px; }
.chip.on small { color: inherit; opacity: .8; }

.facet { display: grid; max-height: 260px; overflow-y: auto; margin: 0 -4px; }
.facet label {
  display: flex; align-items: center; gap: 8px;
  padding: 4px; border-radius: 6px; cursor: pointer;
}
.facet label:hover { background: var(--soft); }
.facet label span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.facet label small { color: var(--muted); font-variant-numeric: tabular-nums; }
.facet .none { color: var(--muted); font-size: 12px; padding: 4px; }
input[type="checkbox"] { accent-color: var(--accent); margin: 0; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }

.origin { display: grid; gap: 6px; margin-top: 4px; }
.origin .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.range { display: grid; gap: 4px; font-size: 13px; }
.range input { width: 100%; accent-color: var(--accent); }

/* ---------- map ---------- */
#map { position: absolute; inset: 0; background: var(--soft); }
.float { position: absolute; top: 12px; right: 12px; z-index: 500; box-shadow: var(--shadow); }
.legend {
  position: absolute; left: 12px; bottom: 24px; z-index: 500;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 8px 10px; display: grid; gap: 3px; font-size: 12px;
}
.legend b { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 2px; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); border: 1.5px solid #fff; box-shadow: 0 0 0 1px rgb(0 0 0 / .25); }
.banner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 600;
  background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 999px; box-shadow: var(--shadow);
}
.banner .link { color: inherit; text-decoration: underline; }
#map.picking { cursor: crosshair; }

.dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--c); border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgb(0 0 0 / .3), 0 1px 3px rgb(0 0 0 / .3);
}
.dot.removed { opacity: .45; border-style: dashed; }
.origin-dot {
  width: 16px; height: 16px; border-radius: 50%; background: #2563eb; border: 3px solid #fff;
  box-shadow: 0 0 0 6px rgb(37 99 235 / .25);
}
.cluster {
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--panel); color: var(--ink);
  border: 3px solid var(--accent);
  font-weight: 650; font-size: 12px;
  box-shadow: var(--shadow);
}

.leaflet-container { font: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.leaflet-popup-content { margin: 12px 14px; width: 260px !important; }
.leaflet-popup-content .place-head { padding-right: 16px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.leaflet-bar a, .leaflet-bar a:hover { background: var(--panel); color: var(--ink); border-color: var(--line); }
.leaflet-control-attribution { font-size: 10px; }
.leaflet-tile-pane { filter: saturate(.75) contrast(.95); }
@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.85) saturate(.6); }
  .leaflet-control-attribution { background: rgb(27 27 27 / .8) !important; color: var(--muted); }
}

/* ---------- place (shared by popup + card) ---------- */
.place { display: grid; gap: 8px; }
.place-head { display: flex; gap: 10px; align-items: flex-start; }
.place-head img {
  width: 40px; height: 40px; border-radius: 8px; object-fit: cover;
  background: var(--soft); flex: none; border: 1px solid var(--line);
}
.place-head > div { flex: 1; min-width: 0; }
.place h3 { font-size: 15px; font-weight: 650; line-height: 1.25; }
.place .sub { color: var(--muted); font-size: 12.5px; }
.plan {
  flex: none; display: grid; justify-items: end;
  font-size: 12px; font-weight: 650; line-height: 1.2;
}
.plan::before { content: ""; width: 28px; height: 4px; border-radius: 2px; background: var(--c); margin-bottom: 3px; }
.plan small { font-weight: 400; color: var(--muted); }
.place .tags { display: flex; flex-wrap: wrap; gap: 4px; }
.place .tags .chip { font-size: 11.5px; padding: 1px 8px; }
.place .meta { font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.badge {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 0 6px; border-radius: 4px;
  background: var(--accent-soft); color: var(--accent);
}
.badge.warn { background: #fde8e8; color: #b42318; }
@media (prefers-color-scheme: dark) { .badge.warn { background: #3a1717; color: #ff9b8f; } }
.place .actions { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; align-items: center; }
.place .actions a { text-decoration: none; }
.place .actions a:hover { text-decoration: underline; }

/* ---------- list ---------- */
#listView { overflow-y: auto; padding: 16px; }
.listbar { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.listbar label { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.listbar select { width: auto; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; align-content: start;
}
.card.removed { opacity: .65; }
.card.removed h3 { text-decoration: line-through; }
.empty { text-align: center; color: var(--muted); padding: 48px 0; }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  :root { --header: 56px; }
  .top { gap: 10px; padding: 0 12px; }
  .brand h1 span, .brand p, .count span { display: none; }
  .count strong { font-size: 14px; }
  .mobile-only { display: inline-flex; align-items: center; }
  .layout { grid-template-columns: 1fr; }
  aside {
    position: fixed; z-index: 1002; inset: var(--header) 0 0 0;
    transform: translateX(-100%); transition: transform .2s ease;
    border-right: 0;
  }
  aside.open { transform: none; }
  .filters-foot { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .legend { bottom: 28px; padding: 6px 8px; grid-template-columns: auto auto; column-gap: 10px; font-size: 11px; }
  .legend b { grid-column: 1 / -1; }
  #listView { padding: 12px; }
  .cards { grid-template-columns: 1fr; }
}
