:root {
  --sidebar-width: 320px;
  --header-height: 56px;
  --color-bg: #f7f7f5;
  --color-surface: #ffffff;
  --color-surface-2: #ffffff;
  --color-border: #d8d8d4;
  --color-text: #1a1a1a;
  --color-muted: #666;
  --color-accent: #2c7a3d;
  --color-overlay: rgba(0, 0, 0, 0.06);
  --color-overlay-hover: rgba(0, 0, 0, 0.12);
  --color-overlay-strong: rgba(0, 0, 0, 0.18);
  --color-warn-bg: #ede8d0;
  --color-warn-border: #d6cfa8;
  --color-warn-text: #4a432d;
  --color-stale: #bc6c25;
  --color-shadow-lg: rgba(0, 0, 0, 0.18);
  --color-shadow-sm: rgba(0, 0, 0, 0.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #14171a;
    --color-surface: #1f2328;
    --color-surface-2: #272c32;
    --color-border: #3a4047;
    --color-text: #e8e8e6;
    --color-muted: #9aa0a8;
    --color-accent: #5db86d;
    --color-overlay: rgba(255, 255, 255, 0.08);
    --color-overlay-hover: rgba(255, 255, 255, 0.15);
    --color-overlay-strong: rgba(255, 255, 255, 0.25);
    --color-warn-bg: #3a3526;
    --color-warn-border: #5a503a;
    --color-warn-text: #d8cba0;
    --color-stale: #d8843a;
    --color-shadow-lg: rgba(0, 0, 0, 0.55);
    --color-shadow-sm: rgba(0, 0, 0, 0.35);
  }
}
html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family:
    system-ui,
    -apple-system,
    sans-serif;
  font-size: 16px;
  color: var(--color-text);
}
@media (min-width: 721px) {
  body:not(.native) {
    zoom: 1.15;
    height: calc(100vh / 1.15);
  }
}
body {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: calc(
      var(--header-height) + env(safe-area-inset-top, 0px)
    ) 1fr;
  height: 100vh;
  overflow: hidden;
}
body.sidebar-collapsed {
  grid-template-columns: 0 1fr;
}

header {
  grid-column: 1 / -1;
  grid-row: 1;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: env(safe-area-inset-top, 0px)
    calc(12px + env(safe-area-inset-right, 0px)) 0
    calc(12px + env(safe-area-inset-left, 0px));
  gap: 12px;
  z-index: 2;
}

.sidebar-pull {
  position: fixed;
  top: calc(50% - 40px);
  width: 30px;
  height: 80px;
  border: none;
  border-radius: 0 8px 8px 0;
  background: var(--color-accent);
  color: white;
  cursor: pointer;
  z-index: 3;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 2px 2px 8px var(--color-shadow-sm);
  left: env(safe-area-inset-left, 0px);
  transition: left 220ms ease;
}
body:not(.sidebar-collapsed) .sidebar-pull {
  left: calc(var(--sidebar-width) + env(safe-area-inset-left, 0px));
}
.sidebar-pull span {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}
@media (min-width: 721px) {
  body:not(.native) .sidebar-pull {
    display: none;
  }
}
header h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 700;
}
header .search {
  flex: 1;
  max-width: 400px;
  position: relative;
}
header .search input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 12px;
  font-size: 14px;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  outline: none;
}
header .search input:focus {
  border-color: var(--color-accent);
}
header .search .status {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--color-muted);
}
header button.icon {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  height: 36px;
  padding: 0 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
header button.icon:hover {
  background: var(--color-bg);
}
header button.icon.glow,
header .search input.glow {
  animation: btn-glow 3.5s cubic-bezier(0.45, 0, 0.55, 1) infinite;
  will-change: box-shadow, opacity;
}
@keyframes btn-glow {
  0% { box-shadow: 0 0 4px 0px #83bca9; opacity: 0.85; }
  40% { box-shadow: 0 0 12px 3px #83bca9; opacity: 1; }
  100% { box-shadow: 0 0 4px 0px #83bca9; opacity: 0.85; }
}
@media (prefers-color-scheme: dark) {
  @keyframes btn-glow {
    0%, 100% { box-shadow: 0 0 4px var(--color-accent); }
    50% { box-shadow: 0 0 14px var(--color-accent); }
  }
}
header .toggle {
  display: inline-block;
}
@media (max-width: 720px) {
  :root {
    --sidebar-width: 220px;
  }
  body {
    grid-template-rows: 1fr calc(
      var(--header-height) + env(safe-area-inset-bottom, 0px)
    );
  }
  header {
    grid-row: 2;
    border-bottom: none;
    border-top: 1px solid var(--color-border);
    padding: 0 calc(12px + env(safe-area-inset-right, 0px))
      env(safe-area-inset-bottom, 0px)
      calc(12px + env(safe-area-inset-left, 0px));
  }
  header h1 {
    display: none;
  }
  .maplibregl-ctrl-top-right {
    top: env(safe-area-inset-top, 8px);
  }
  body.detail-open:not(.sidebar-collapsed) .sidebar-pull {
    top: 8px;
  }
}

.sidebar {
  grid-column: 1;
  grid-row: 2;
  background: var(--color-bg);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  padding: 16px 16px 64px;
}
body.sidebar-collapsed .sidebar {
  display: none;
}
.sidebar h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted);
  margin: 18px 0 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar h2:first-child {
  margin-top: 0;
}
/* In-h2 secondary note (e.g. "(where listed)"). margin-right: auto absorbs the
   parent's space-between so the note sits next to the h2 text instead of
   floating to the right edge. */
.sidebar h2 .note {
  color: var(--color-muted);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  margin-left: 6px;
  margin-right: auto;
}
.sidebar label.row-spaced {
  margin-top: 4px;
}
.sidebar .link-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: var(--color-accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-left: 8px;
  margin-right: auto;
}
.sidebar .link-btn:hover {
  text-decoration: underline;
}
.sidebar label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}
.sidebar label input {
  cursor: pointer;
}
.sidebar .swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.sidebar .category-row {
  display: flex;
  align-items: center;
}
.sidebar .category-row label {
  padding: 5px 0;
}
.sidebar .help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-left: 8px;
  border-radius: 50%;
  background: var(--color-overlay);
  color: var(--color-muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.sidebar .help:hover {
  background: var(--color-accent);
  color: white;
}
.sidebar .help:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}
.sidebar .chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.sidebar .chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  font-size: 13px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: 14px;
  cursor: pointer;
  user-select: none;
}
.sidebar .chip input {
  display: none;
}
.sidebar .chip:has(input:checked) {
  background: var(--color-accent);
  color: white;
  border-color: var(--color-accent);
}
.sidebar .radius-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.sidebar .radius-row input[type="range"] {
  flex: 1;
}
.sidebar .radius-row .val {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--color-muted);
  min-width: 50px;
  text-align: right;
}
.sidebar .anchor {
  font-size: 12px;
  color: var(--color-muted);
  margin-top: 4px;
}
.sidebar .anchor button {
  background: none;
  border: none;
  padding: 0;
  color: var(--color-accent);
  text-decoration: underline;
  cursor: pointer;
  font-size: 12px;
}
.sidebar .counts {
  font-size: 12px;
  color: var(--color-muted);
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
}

#map {
  grid-column: 2;
  grid-row: 2;
  position: relative;
}
body.sidebar-collapsed #map {
  grid-column: 1 / -1;
}
@media (max-width: 720px) {
  .sidebar {
    grid-row: 1;
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
  }
  #map {
    grid-row: 1;
  }
}

/* ---------- detail panel ---------- */
.detail {
  position: absolute;
  top: 12px;
  right: 12px;
  bottom: 12px;
  width: 360px;
  max-width: calc(100% - 24px);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: 10px;
  box-shadow:
    0 10px 30px var(--color-shadow-lg),
    0 2px 6px var(--color-shadow-sm);
  z-index: 5;
  display: flex;
  flex-direction: column;
  transform: translateX(calc(100% + 24px));
  transition:
    transform 220ms ease,
    opacity 220ms ease;
  opacity: 0;
  pointer-events: none;
}
.detail.open {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}
.detail .close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--color-overlay);
  color: var(--color-text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}
.detail .close:hover {
  background: var(--color-overlay-hover);
}
.detail .scroll {
  overflow-y: auto;
  padding: 20px 20px 24px;
  flex: 1;
}
.detail .dir-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: white;
  margin-bottom: 10px;
}
.detail .dir-pill .help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.2);
  color: white;
  text-decoration: none;
  font-size: 10px;
  font-weight: 700;
}
.detail .dir-pill .help:hover {
  background: rgba(0, 0, 0, 0.35);
}
.detail h2.name {
  margin: 0 0 4px;
  font-size: 20px;
  line-height: 1.25;
  font-weight: 700;
  padding-right: 36px;
}
.detail .address {
  font-size: 13px;
  color: var(--color-muted);
  margin-bottom: 14px;
}
.detail .phone-display {
  font-size: 14px;
  color: var(--color-text);
  margin-bottom: 14px;
}
.detail .actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.detail .actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 10px;
  background: var(--color-accent);
  color: white;
  text-decoration: none;
  border-radius: 6px;
  font-weight: 600;
  font-size: 13px;
  text-align: center;
}
.detail .actions a:hover {
  filter: brightness(0.95);
}
.detail .actions a.secondary {
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.detail .actions a.secondary:hover {
  background: var(--color-bg);
}
.detail .actions a.full {
  grid-column: 1 / -1;
}
.detail .stale {
  font-size: 12px;
  color: var(--color-warn-text);
  background: var(--color-warn-bg);
  border: 1px solid var(--color-warn-border);
  padding: 8px 10px;
  border-radius: 6px;
  margin-bottom: 16px;
  line-height: 1.4;
}
.detail .section {
  border-top: 1px solid var(--color-border);
  padding-top: 12px;
  margin-top: 12px;
}
.detail .section:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}
.detail .section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted);
  margin: 0 0 6px;
}
.detail .meta {
  margin: 0;
  font-size: 13px;
  color: var(--color-text);
  line-height: 1.5;
}
.detail .meta dt {
  font-weight: 600;
  margin-top: 6px;
  color: var(--color-muted);
  font-size: 12px;
}
.detail .meta dt:first-child {
  margin-top: 0;
}
.detail .meta dd {
  margin: 0 0 2px;
}
.detail .updated {
  font-size: 12px;
  color: var(--color-muted);
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
}
.detail .updated.outdated {
  color: var(--color-stale);
  font-weight: 600;
}
.detail .empty-contact {
  font-size: 12px;
  color: var(--color-muted);
  margin-bottom: 14px;
  font-style: italic;
}

@media (max-width: 720px) {
  .detail {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    max-height: calc(75vh - var(--header-height));
    border-radius: 14px 14px 0 0;
    transform: translateY(100%);
  }
  .detail.open {
    transform: translateY(0);
  }
  .detail::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--color-overlay-strong);
  }
  .detail .scroll {
    padding-top: 22px;
  }
}

@media (max-width: 720px) {
  .maplibregl-ctrl-bottom-right {
    bottom: -4px;
  }
}

/* ---------- MapLibre controls (light/dark) ---------- */
.maplibregl-ctrl-group {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}
.maplibregl-ctrl-group button {
  background-color: var(--color-surface);
}
.maplibregl-ctrl-group button:not(:disabled):hover {
  background-color: var(--color-bg);
}
.maplibregl-ctrl-group button + button {
  border-top: 1px solid var(--color-border);
}
.maplibregl-ctrl-attrib.maplibregl-compact {
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 10px;
  opacity: 0.5;
  transition: opacity 0.3s;
}
.maplibregl-ctrl-attrib.maplibregl-compact:hover,
.maplibregl-ctrl-attrib.maplibregl-compact.maplibregl-compact-show {
  opacity: 1;
}
.maplibregl-ctrl-attrib a {
  color: var(--color-text);
}
.maplibregl-ctrl-attrib-button {
  background-color: var(--color-surface);
}
@media (prefers-color-scheme: dark) {
  .maplibregl-ctrl-icon,
  .maplibregl-ctrl-attrib-button {
    filter: invert(0.92) hue-rotate(180deg);
  }
  .maplibregl-popup-content {
    background: var(--color-surface);
    color: var(--color-text);
  }
  .maplibregl-popup-tip {
    border-top-color: var(--color-surface);
    border-bottom-color: var(--color-surface);
  }
}

/* ---------- Splash ---------- */
.splash-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  transition: opacity 0.3s;
}
.splash-overlay.visible {
  display: flex;
}
.splash-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}
.splash {
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: 14px;
  padding: 28px 28px 22px;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 8px 32px var(--color-shadow-lg);
}
.splash h2 {
  margin: 0 0 14px;
  font-size: 20px;
}
.splash p {
  margin: 0 0 22px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--color-muted);
}
.splash-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.splash-actions button {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.splash-actions button:hover {
  background: var(--color-overlay-hover);
}
.splash-actions button.primary {
  background: var(--color-accent);
  color: white;
  border-color: var(--color-accent);
}
.splash-actions button.primary:hover {
  opacity: 0.9;
}
