:root {
  --ink: #10303a;      /* deep blue-green text */
  --ink-2: #345560;
  --muted: #5f7880;
  --line: #d5e2e4;
  --line-2: #ebf2f2;
  --tint: #f2f8f7;
  --panel: #ffffff;
  --accent: #17697f;   /* teal-blue: controls, active states */
  --accent-2: #0f5466;
  --c1: #1f5fa8;       /* public: blue */
  --c2: #1f8a5a;       /* private nonprofit: green */
  --c3: #6cbfd9;       /* for-profit: sky */
  --radius: 8px;
  --shadow: 0 1px 2px rgb(16 48 58 / .08), 0 4px 16px rgb(16 48 58 / .10);
  --panel-w: 380px;
  --top-h: 56px;
  font-family: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #e8f0ef; }
body { font-size: 15px; line-height: 1.45; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

#map { position: fixed; inset: 0; }

/* Top bar ----------------------------------------------------------- */
.topbar {
  position: fixed; top: 12px; left: 12px; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 8px; max-width: calc(100vw - 80px);
}
.search { flex: 0 0 280px; }
.search input {
  width: 100%; height: 40px; padding: 0 12px 0 36px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--tint) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%235f7880' stroke-width='2'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='m11 11 3.5 3.5'/%3E%3C/svg%3E") no-repeat 12px 50%;
  font-size: 16px;
}
.search input:focus { outline: none; border-color: var(--accent); background-color: #fff; box-shadow: 0 0 0 3px rgb(23 105 127 / .15); }
.filter-buttons {
  display: flex; gap: 6px; align-items: center; min-width: 0;
  overflow-x: auto; scrollbar-width: none;
}
.filter-buttons::-webkit-scrollbar { display: none; }
.fbtn {
  flex: none; height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; background: #fff;
  cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; font-size: 14px;
}
.fbtn::after {
  content: ""; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translateY(-2px); opacity: .6;
}
.fbtn:hover { border-color: var(--ink-2); }
.fbtn[aria-expanded="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.fbtn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.fbtn.active::after { opacity: 1; }
.reset-btn { flex: none; height: 40px; padding: 0 12px; border: 1px solid transparent; border-radius: 6px; background: none; color: var(--accent); cursor: pointer; font-size: 14px; font-weight: 600; white-space: nowrap; }
.reset-btn:hover { background: var(--tint); }

/* Filter popover ---------------------------------------------------- */
.popover {
  position: fixed; z-index: 6; width: 340px; max-height: calc(100dvh - 100px);
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.popover-body { padding: 14px 16px 8px; overflow-y: auto; overscroll-behavior: contain; }
.popover-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px; border-top: 1px solid var(--line-2);
}
.popover-count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; margin-right: auto; }
.clear-btn { height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; }
.clear-btn:hover { border-color: var(--ink-2); }
.done-btn { height: 36px; padding: 0 18px; border: 0; border-radius: 6px; background: var(--accent); color: #fff; cursor: pointer; font-weight: 600; }
.done-btn:hover { background: var(--accent-2); }
.popover h3 { font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 0 0 8px; }
.popover .group + .group { margin-top: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none;
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 14px; color: var(--muted);
}
.chip input:checked + span { border-color: var(--accent); color: var(--ink); background: #e3f1f1; font-weight: 500; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip .dot { opacity: .35; }
.chip input:checked + span .dot { opacity: 1; }
.popover select { width: 100%; height: 40px; border: 1px solid var(--line); border-radius: 6px; padding: 0 8px; background: #fff; font-size: 16px; }
.popover .note { font-size: 12px; color: var(--muted); margin: 14px 0 4px; }

.range + .range { margin-top: 18px; }
.range-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 28px; }
.range-label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.popover .range-head select { width: auto; height: 28px; font-size: 13px; padding: 0 4px; }
.range-value { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.range-value.active { color: var(--accent); font-weight: 600; }
.dual { position: relative; height: 32px; }
.dual .track, .dual .fill { position: absolute; top: 14px; height: 4px; border-radius: 2px; }
.dual .track { left: 11px; right: 11px; background: var(--line); }
.dual .fill { background: var(--accent); }
.dual input {
  position: absolute; inset: 0; width: 100%; margin: 0; background: none; height: 32px;
  pointer-events: none; -webkit-appearance: none; appearance: none;
}
.dual input::-webkit-slider-thumb {
  -webkit-appearance: none; pointer-events: auto; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; border: 2px solid var(--accent); cursor: grab; box-shadow: 0 1px 3px rgb(0 0 0 / .15);
}
.dual input::-moz-range-thumb {
  pointer-events: auto; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; border: 2px solid var(--accent); cursor: grab;
}
.dual input:focus-visible { outline: none; }
.dual input:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgb(23 105 127 / .3); }
.dual input::-webkit-slider-runnable-track { background: none; }
.dual input::-moz-range-track { background: none; }

/* Panel ------------------------------------------------------------- */
.panel {
  position: fixed; z-index: 4; left: 12px; top: calc(12px + var(--top-h) + 10px); bottom: 12px; width: var(--panel-w);
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden;
}
.panel.min { bottom: auto; }
.panel.min .view { display: none; }
.panel-head {
  flex: none; display: flex; align-items: center; gap: 10px; width: 100%; height: 48px; padding: 0 14px;
  background: none; border: 0; border-bottom: 1px solid var(--line-2); cursor: pointer; text-align: left;
}
.panel.min .panel-head { border-bottom: 0; }
.panel-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.chev {
  width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-135deg) translateY(-2px); flex: none;
}
.panel.min .chev { transform: rotate(45deg) translateY(-2px); }
.grip { display: none; }
.view { flex: 1; overflow-y: auto; padding: 10px 14px 20px; overscroll-behavior: contain; }

.list-tools { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.inview { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.list-tools select { height: 32px; font-size: 13px; border: 1px solid var(--line); border-radius: 6px; background: #fff; padding: 0 6px; }

.results { list-style: none; margin: 0 -6px; padding: 0; }
.results li + li { border-top: 1px solid var(--line-2); }
.result {
  display: grid; grid-template-columns: 10px 1fr auto; gap: 1px 10px; align-items: baseline;
  width: 100%; text-align: left; background: none; border: 0; padding: 9px 6px; cursor: pointer; border-radius: 6px;
}
.result:hover { background: var(--tint); }
.result .dot { align-self: center; grid-row: span 2; }
.result .name { font-weight: 500; line-height: 1.3; }
.result .where { grid-column: 2; font-size: 13px; color: var(--muted); }
.result .metric { grid-row: 1 / span 2; grid-column: 3; align-self: center; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; text-align: right; }
.result .metric small { display: block; font-size: 11px; color: var(--muted); }
.results.near .dot { opacity: .45; }
.results.near .name { color: var(--ink-2); }
.results.near .metric { color: var(--accent); }
.empty { color: var(--muted); padding: 14px 0; font-size: 14px; }
.more-btn {
  width: 100%; margin-top: 8px; height: 38px; background: #fff; border: 1px solid var(--line);
  border-radius: 6px; cursor: pointer; font-size: 14px;
}
.more-btn:hover { background: var(--tint); }
.near-head { font-size: 14px; margin: 22px 0 2px; }
.near-note { font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.source { font-size: 12px; color: var(--muted); margin-top: 22px; padding-top: 10px; border-top: 1px solid var(--line-2); }
.source p { margin: 0 0 6px; }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.c1 { background: var(--c1); }
.dot.c2 { background: var(--c2); }
.dot.c3 { background: var(--c3); }
.dot.near { background: var(--c1); opacity: .35; }

/* Detail ------------------------------------------------------------ */
.back-btn { background: none; border: 0; padding: 4px 0; color: var(--muted); font-size: 13px; cursor: pointer; }
.back-btn::before { content: "‹ "; }
.back-btn:hover { color: var(--ink); text-decoration: underline; }

.gallery { margin: 8px -14px 0; position: relative; }
.slides {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none;
  aspect-ratio: 16 / 10; background: var(--line-2);
}
.slides::-webkit-scrollbar { display: none; }
.slides figure { flex: 0 0 100%; margin: 0; scroll-snap-align: center; }
.slides img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery .nav {
  position: absolute; top: calc(50% - 10px); transform: translateY(-50%); width: 34px; height: 34px; border-radius: 50%;
  border: 0; background: rgb(255 255 255 / .92); box-shadow: 0 1px 4px rgb(0 0 0 / .25); cursor: pointer;
  display: grid; place-items: center; padding: 0;
}
.gallery .nav::before { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--ink); border-bottom: 2px solid var(--ink); }
.gallery .prev { left: 10px; } .gallery .prev::before { transform: rotate(135deg); margin-left: 4px; }
.gallery .next { right: 10px; } .gallery .next::before { transform: rotate(-45deg); margin-right: 4px; }
.gallery .nav:disabled { opacity: 0; pointer-events: none; }
.gallery .counter {
  position: absolute; right: 10px; bottom: 30px; background: rgb(16 48 58 / .72); color: #fff;
  font-size: 12px; padding: 1px 8px; border-radius: 10px; font-variant-numeric: tabular-nums;
}
.credit { font-size: 11px; color: var(--muted); padding: 4px 14px 0; height: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.credit a { color: inherit; }
.gallery.loading .slides { animation: shimmer 1.2s ease-in-out infinite alternate; }
@keyframes shimmer { from { background: var(--line-2); } to { background: var(--line); } }

.detail-name { font-size: 21px; line-height: 1.25; margin: 12px 0 2px; font-weight: 700; letter-spacing: -0.01em; }
.detail-alias { color: var(--muted); font-size: 14px; margin: 0; }
.detail-place { margin: 4px 0 10px; color: var(--ink-2); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.tag { font-size: 12px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 5px; }
.tag .dot { width: 8px; height: 8px; }
.links { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.links a { font-size: 13px; text-decoration: none; border: 1px solid var(--line); border-radius: 6px; padding: 7px 11px; color: var(--ink); }
.links a:hover { border-color: var(--ink-2); }
.links a.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.links a.primary:hover { background: var(--accent-2); }

.stat-group { margin-top: 18px; }
.stat-group h3 { font-size: 14px; margin: 0 0 4px; font-weight: 700; }
.stat-group dl { margin: 0; display: grid; grid-template-columns: 1fr auto; }
.stat-group dt, .stat-group dd { padding: 6px 0; border-bottom: 1px solid var(--line-2); margin: 0; font-size: 14px; }
.stat-group dt { color: var(--ink-2); }
.stat-group dt small { display: block; font-size: 12px; color: var(--muted); }
.stat-group dd { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; padding-left: 12px; }
.stat-group dd.na { color: #9fb0b4; font-weight: 400; }
.stat-group .foot { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.similar { list-style: none; padding: 0; margin: 0; }
.similar button {
  width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line-2);
  padding: 8px 0; cursor: pointer; display: flex; gap: 8px; align-items: center; font-size: 14px;
}
.similar button:hover .s-name { text-decoration: underline; }
.similar .s-where { color: var(--muted); font-size: 13px; margin-left: auto; white-space: nowrap; padding-left: 8px; }

/* Map overlays ------------------------------------------------------ */
.legend {
  position: fixed; right: 12px; bottom: 54px; z-index: 3; background: rgb(255 255 255 / .95);
  border-radius: 6px; box-shadow: var(--shadow); padding: 6px 10px;
  display: flex; gap: 12px; font-size: 12px; color: var(--ink-2);
}
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend .dot { width: 9px; height: 9px; }
.maplibregl-popup.hover-tip .maplibregl-popup-content {
  padding: 6px 9px; font: 500 13px/1.3 "Public Sans", system-ui, sans-serif; color: var(--ink);
  border-radius: 6px; box-shadow: 0 1px 4px rgb(0 0 0 / .18);
}
.hover-tip small { display: block; color: var(--muted); font-weight: 400; }
.hover-tip em { display: block; color: var(--accent); font-style: normal; font-size: 12px; margin-top: 2px; }
.maplibregl-ctrl-top-right { top: 12px; }
.maplibregl-ctrl-attrib { font-size: 11px; }

/* Phone ------------------------------------------------------------- */
@media (max-width: 760px) {
  :root { --top-h: 100px; }
  .topbar {
    top: 0; left: 0; right: 0; max-width: none; border-radius: 0 0 var(--radius) var(--radius);
    flex-direction: column; align-items: stretch; gap: 8px;
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  }
  .search { flex: none; }
  .filter-buttons { margin: 0 -10px; padding: 0 10px; }
  .fbtn { height: 36px; padding: 0 11px; font-size: 14px; }
  .reset-btn { height: 36px; }
  .maplibregl-ctrl-top-right { top: calc(var(--top-h) + env(safe-area-inset-top) + 2px); }

  .popover {
    left: 8px !important; right: 8px; width: auto; top: calc(var(--top-h) + env(safe-area-inset-top) + 6px) !important;
    max-height: calc(100dvh - var(--top-h) - env(safe-area-inset-top) - 80px);
  }

  .panel {
    left: 0; right: 0; bottom: 0; top: auto; width: auto; height: 46dvh;
    border-radius: 14px 14px 0 0; padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -2px 16px rgb(16 48 58 / .14); transition: height .22s ease;
  }
  .panel.expanded { height: calc(100dvh - var(--top-h) - env(safe-area-inset-top) - 10px); }
  .panel.min { height: calc(56px + env(safe-area-inset-bottom)); bottom: 0; }
  .panel.dragging { transition: none; }
  .panel-head { height: 56px; position: relative; padding-top: 8px; touch-action: none; }
  .grip { display: block; position: absolute; top: 7px; left: 50%; margin-left: -20px; width: 40px; height: 4px; border-radius: 2px; background: var(--line); }
  .chev { display: none; }
  .legend { display: none; }
  .gallery .nav { display: none; }
  .maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { bottom: calc(56px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
