:root {
  --ink: #17211d;
  --muted: #6f7771;
  --paper: #f6f3ec;
  --white: #fffdf8;
  --red: #c72134;
  --red-dark: #9f1728;
  --green: #1d6149;
  --line: #dedbd2;
  --shadow: 0 18px 45px rgba(30, 39, 34, .15);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; color: var(--ink); background: var(--paper); font-family: Inter, "Noto Sans TC", "PingFang TC", system-ui, sans-serif; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.skip-link { position: fixed; top: -60px; left: 1rem; z-index: 9999; padding: .7rem 1rem; color: white; background: var(--ink); }
.skip-link:focus { top: 1rem; }

.app-shell { display: grid; grid-template-columns: minmax(340px, 420px) 1fr; height: 100dvh; overflow: hidden; }
.sidebar { display: flex; flex-direction: column; min-width: 0; overflow-y: auto; background: var(--white); border-right: 1px solid var(--line); z-index: 500; }
.brand { display: grid; grid-template-columns: 48px 1fr auto; gap: .85rem; align-items: center; padding: 1.35rem 1.5rem 1.15rem; border-bottom: 1px solid var(--line); }
.brand-mark { display: grid; place-items: center; width: 48px; height: 48px; color: white; background: var(--red); border-radius: 3px 14px 3px 3px; font-family: Georgia, serif; font-size: 1.9rem; font-weight: 700; }
.brand h1 { margin: .1rem 0 0; font-family: Georgia, "Noto Serif TC", serif; font-size: 1.55rem; letter-spacing: .04em; }
.eyebrow { margin: 0; color: var(--red); font-size: .62rem; font-weight: 800; letter-spacing: .16em; }
.status-dot { width: 9px; height: 9px; background: #41a67b; border-radius: 50%; box-shadow: 0 0 0 4px rgba(65,166,123,.14); }
.mobile-panel-close, .mobile-map-controls { display: none; }

.search-section, .results { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--line); }
.section-heading, .results-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: .85rem; }
.section-heading > div, .results-heading > div { display: flex; align-items: baseline; gap: .65rem; }
.section-heading h2, .results-heading h2 { margin: 0; font-family: Georgia, "Noto Serif TC", serif; font-size: 1.08rem; }
.step { color: var(--red); font-size: .68rem; font-weight: 800; letter-spacing: .08em; }
.icon-button, .text-button { color: var(--red); background: transparent; border: 0; cursor: pointer; }
.icon-button { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 50%; font-size: 1.4rem; }
.text-button { font-size: .8rem; text-decoration: underline; text-underline-offset: 3px; }

.search-box { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .5rem; padding: .35rem .4rem .35rem .85rem; background: var(--paper); border: 1px solid transparent; border-radius: 8px; }
.search-box:focus-within { border-color: var(--red); box-shadow: 0 0 0 3px rgba(199,33,52,.1); }
.search-box input { min-width: 0; padding: .6rem .2rem; background: transparent; border: 0; outline: 0; }
.search-box button { padding: .6rem .85rem; color: white; background: var(--ink); border: 0; border-radius: 6px; cursor: pointer; font-weight: 700; }
.search-box.dark { color: white; background: var(--ink); }
.search-box.dark input { color: white; }
.search-box.dark input::placeholder { color: #b9c0bb; }
.search-box.dark button { background: var(--red); }
.location-label { margin: .65rem 0 0; color: var(--muted); font-size: .75rem; }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; margin-top: .85rem; }
.filters label { color: var(--muted); font-size: .68rem; font-weight: 700; letter-spacing: .03em; }
.filters select { display: block; width: 100%; margin-top: .3rem; padding: .58rem .65rem; color: var(--ink); background: var(--white); border: 1px solid var(--line); border-radius: 6px; }

.results { flex: 1; min-height: 220px; overflow-y: auto; }
.result-count { color: var(--muted); font-size: .75rem; }
.result-list { display: grid; gap: .7rem; }
.result-card { width: 100%; padding: 1rem; text-align: left; color: inherit; background: var(--white); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; transition: .18s ease; }
.result-card:hover, .result-card:focus-visible { transform: translateY(-2px); border-color: #b8b4aa; box-shadow: 0 8px 22px rgba(28,37,32,.08); outline: none; }
.result-card-top { display: flex; justify-content: space-between; gap: 1rem; }
.result-card h3 { margin: 0; font-family: Georgia, "Noto Serif TC", serif; font-size: 1rem; }
.result-card .distance { flex: none; color: var(--red); font-size: .72rem; font-weight: 800; }
.result-card p { margin: .35rem 0 0; color: var(--muted); font-size: .76rem; line-height: 1.45; }
.location-badge { display: inline-block; margin-top: .55rem; padding: .18rem .45rem; color: #315f4d; background: #e8f4ed; border-radius: 999px; font-size: .65rem; font-weight: 800; }
.location-badge.pending { color: #7b5b1d; background: #fff3d7; }
.empty-state { padding: 2rem 1rem; text-align: center; color: var(--muted); background: var(--paper); border-radius: 8px; }
.empty-state strong { display: block; margin-bottom: .45rem; color: var(--ink); font-family: Georgia, "Noto Serif TC", serif; }
.empty-state p { margin: 0; font-size: .78rem; line-height: 1.6; }
.sidebar-footer { display: flex; justify-content: space-between; gap: 1rem; padding: .85rem 1.5rem; color: var(--muted); background: var(--paper); font-size: .59rem; }

.map-panel { position: relative; min-width: 0; min-height: 420px; }
#map { position: absolute; inset: 0; overflow: hidden; background: #d8ded7; }
/* Critical Leaflet fallbacks keep tiles/markers contained if CDN CSS is late
   or unavailable. The full upstream stylesheet still enhances controls. */
.leaflet-pane, .leaflet-tile, .leaflet-marker-icon, .leaflet-marker-shadow,
.leaflet-tile-container, .leaflet-pane > svg, .leaflet-pane > canvas {
  position: absolute; top: 0; left: 0;
}
.leaflet-pane { z-index: 400; }
.leaflet-tile-pane { z-index: 200; }
.leaflet-overlay-pane { z-index: 400; }
.leaflet-shadow-pane { z-index: 500; }
.leaflet-marker-pane { z-index: 600; }
.leaflet-tooltip-pane { z-index: 650; }
.leaflet-popup-pane { z-index: 700; }
.leaflet-tile { visibility: hidden; user-select: none; }
.leaflet-tile-loaded { visibility: inherit; }
.leaflet-top, .leaflet-bottom { position: absolute; z-index: 1000; pointer-events: none; }
.leaflet-top { top: 0; }
.leaflet-right { right: 0; }
.leaflet-bottom { bottom: 0; }
.leaflet-left { left: 0; }
.leaflet-control { position: relative; z-index: 800; pointer-events: auto; }
.leaflet-marker-icon, .leaflet-marker-shadow { user-select: none; }
.leaflet-control-zoom.leaflet-bar {
  overflow: hidden;
  background: var(--white);
  border: 1px solid rgba(23, 33, 29, .2);
  border-radius: 9px;
  box-shadow: 0 7px 20px rgba(23, 33, 29, .18);
}
.leaflet-control-zoom.leaflet-bar a {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  color: var(--ink);
  background: var(--white);
  border: 0;
  border-radius: 0;
  line-height: 1;
  text-decoration: none;
  font-family: Inter, system-ui, sans-serif;
  font-size: 1.35rem;
  font-weight: 600;
}
.leaflet-control-zoom.leaflet-bar a + a { border-top: 1px solid var(--line); }
.leaflet-control-zoom.leaflet-bar a:hover,
.leaflet-control-zoom.leaflet-bar a:focus-visible { color: var(--red); background: var(--paper); outline: none; }
.leaflet-control-zoom.leaflet-bar a:focus-visible { box-shadow: inset 0 0 0 3px rgba(199, 33, 52, .18); }
.leaflet-control-zoom.leaflet-bar a.leaflet-disabled { color: #a9aea9; background: #f0eee8; cursor: default; }
.map-topbar { position: absolute; z-index: 450; top: 1rem; left: 50%; display: flex; gap: 1rem; align-items: center; padding: .6rem .8rem; transform: translateX(-50%); color: var(--ink); background: rgba(255,253,248,.94); border: 1px solid rgba(222,219,210,.9); border-radius: 999px; box-shadow: var(--shadow); font-size: .72rem; backdrop-filter: blur(12px); }
.legend { color: var(--muted); }
.legend i { display: inline-block; width: 8px; height: 8px; margin-right: .25rem; background: var(--red); border-radius: 50%; }
.map-actions { position: absolute; z-index: 450; bottom: 1.5rem; left: 50%; display: flex; gap: .6rem; transform: translateX(-50%); }
.floating-button { padding: .72rem 1rem; color: var(--ink); background: var(--white); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow); cursor: pointer; white-space: nowrap; font-size: .78rem; font-weight: 700; }
.floating-button.primary { color: white; background: var(--red); border-color: var(--red); }
.member-pin { display: grid; place-items: center; width: 34px !important; height: 34px !important; margin: -17px 0 0 -17px !important; color: white; background: var(--red); border: 3px solid var(--white); border-radius: 50% 50% 50% 10%; box-shadow: 0 5px 12px rgba(80,20,30,.3); transform: rotate(-45deg); }
.member-pin span { transform: rotate(45deg); font-size: .7rem; font-weight: 800; }
.marker-cluster-small, .marker-cluster-medium, .marker-cluster-large { background: rgba(199,33,52,.2); }
.marker-cluster-small div, .marker-cluster-medium div, .marker-cluster-large div { color: white; background: var(--red); }
.marker-cluster { background-clip: padding-box; border-radius: 20px; }
.marker-cluster div { width: 30px; height: 30px; margin: 5px; text-align: center; border-radius: 15px; }
.marker-cluster span { line-height: 30px; }

.member-dialog { width: min(520px, calc(100% - 2rem)); padding: 0; color: var(--ink); background: var(--white); border: 0; border-radius: 12px; box-shadow: 0 30px 80px rgba(15,24,20,.3); }
.member-dialog::backdrop { background: rgba(18,29,24,.54); backdrop-filter: blur(3px); }
.member-dialog article { position: relative; padding: 2rem; }
.dialog-close { position: absolute; top: 1rem; right: 1rem; width: 36px; height: 36px; color: var(--muted); background: var(--paper); border: 0; border-radius: 50%; cursor: pointer; font-size: 1.4rem; }
.dialog-kicker { margin: 0 3rem .5rem 0; color: var(--red); font-size: .7rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.member-dialog h2 { margin: 0; font-family: Georgia, "Noto Serif TC", serif; font-size: 1.75rem; line-height: 1.2; }
.member-name { margin: .45rem 0 1.4rem; color: var(--muted); }
.member-details { display: grid; gap: .65rem; margin: 0; padding: 1rem 0; border-block: 1px solid var(--line); }
.member-details div { display: grid; grid-template-columns: 58px 1fr; gap: .7rem; }
.member-details dt { color: var(--muted); font-size: .72rem; }
.member-details dd { margin: 0; font-size: .85rem; }
.location-options { margin:.85rem 0 0; }
.location-options > p { margin:0 0 .45rem; color:var(--muted); font-size:.72rem; font-weight:700; }
.location-options > div { display:flex; flex-wrap:wrap; gap:.4rem; }
.location-option { padding:.45rem .65rem; color:var(--ink); background:var(--paper); border:1px solid var(--line); border-radius:999px; cursor:pointer; font-size:.72rem; font-weight:700; }
.location-option.active { color:white; background:var(--green); border-color:var(--green); }
.location-status { margin: .85rem 0 0; padding: .7rem .8rem; color: #315f4d; background: #e8f4ed; border-radius: 7px; font-size: .78rem; font-weight: 700; }
.location-status.pending { color: #7b5b1d; background: #fff3d7; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; margin-top: 1.25rem; }
.action-link { display: block; padding: .8rem 1rem; text-align: center; color: var(--ink); background: transparent; border: 1px solid var(--line); border-radius: 7px; cursor: pointer; text-decoration: none; font-weight: 800; }
.action-link.primary { color: white; background: var(--red); border-color: var(--red); }
.action-link[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.navigation-options { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; margin-top: .65rem; }
.navigation-options a { padding: .7rem; text-align: center; color: var(--green); background: #edf6f0; border-radius: 7px; text-decoration: none; font-size: .8rem; font-weight: 700; }
.bni-profile { display: inline-block; margin-top: 1.15rem; color: var(--ink); text-decoration-thickness: 1px; text-underline-offset: 4px; font-size: .8rem; }
.toast { position: fixed; z-index: 2000; bottom: 1.5rem; left: 50%; max-width: calc(100% - 2rem); padding: .8rem 1rem; transform: translateX(-50%); color: white; background: var(--ink); border-radius: 7px; box-shadow: var(--shadow); font-size: .8rem; }

@media (max-width: 760px) {
  html, body { width: 100%; height: 100%; overflow: hidden; }
  .app-shell { position: relative; display: block; width: 100%; height: 100dvh; min-height: 0; overflow: hidden; }
  .sidebar {
    position: fixed; z-index: 1200; right: 0; bottom: 0; left: 0;
    display: flex; max-height: min(88dvh, 760px); overflow-y: auto;
    background: var(--white); border: 0; border-radius: 20px 20px 0 0;
    box-shadow: 0 -18px 55px rgba(15,24,20,.24);
    transform: translateY(calc(100% + 24px)); visibility: hidden;
    transition: transform .22s ease, visibility 0s linear .22s;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .mobile-panel-open .sidebar { transform: translateY(0); visibility: visible; transition-delay: 0s; }
  .brand { flex: none; padding: 1rem; background: var(--white); }
  .brand-mark { width: 42px; height: 42px; }
  .brand h1 { font-size: 1.3rem; }
  .brand .status-dot { display: none; }
  .mobile-panel-close { display: grid; place-items: center; width: 44px; height: 44px; color: var(--muted); background: var(--paper); border: 0; border-radius: 50%; cursor: pointer; font-size: 1.55rem; }
  .search-section, .results { padding: 1rem; }
  .location-section, .member-section { flex: none; background: var(--white); }
  .results { flex: none; min-height: 240px; overflow: visible; background: var(--white); }
  .sidebar-footer { flex: none; padding-inline: 1rem; }
  .map-panel { position: absolute; inset: 0; width: 100%; height: 100dvh; min-height: 0; }
  .mobile-map-controls { position: absolute; z-index: 1050; top: max(.75rem, env(safe-area-inset-top)); right: .75rem; left: .75rem; display: flex; justify-content: space-between; gap: .6rem; pointer-events: none; }
  .mobile-map-controls button { min-height: 44px; padding: .65rem .9rem; color: var(--ink); background: rgba(255,253,248,.96); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow); cursor: pointer; pointer-events: auto; font-size: .78rem; font-weight: 800; backdrop-filter: blur(12px); }
  .mobile-map-controls button:first-child { color: white; background: var(--red); border-color: var(--red); }
  .map-topbar { top: calc(max(.75rem, env(safe-area-inset-top)) + 54px); max-width: calc(100% - 1.5rem); white-space: nowrap; }
  .leaflet-top.leaflet-left { top: calc(max(.75rem, env(safe-area-inset-top)) + 104px); left: .75rem; }
  .leaflet-top.leaflet-left .leaflet-control { margin: 0; }
  .leaflet-control-zoom.leaflet-bar a { width: 44px; height: 44px; font-size: 1.35rem; }
  .leaflet-control-attribution { max-width: calc(100vw - 1rem); white-space: normal; text-align: right; font-size: .58rem; line-height: 1.25; }
  .map-actions { bottom: calc(1rem + env(safe-area-inset-bottom)); width: calc(100% - 1.5rem); justify-content: center; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters select { min-height: 44px; }
  .search-box input { font-size: 16px; }
  .member-dialog { width: 100%; max-width: none; max-height: calc(94dvh - env(safe-area-inset-top)); margin: auto 0 0; border-radius: 20px 20px 0 0; }
  .member-dialog article { max-height: calc(94dvh - env(safe-area-inset-top)); overflow-y: auto; padding: 1.5rem 1rem calc(1.25rem + env(safe-area-inset-bottom)); }
  .dialog-close { min-width: 44px; min-height: 44px; top: .75rem; right: .75rem; }
  .member-dialog h2 { padding-right: 2.75rem; font-size: 1.45rem; }
  .dialog-actions, .navigation-options { grid-template-columns: 1fr; }
  .action-link, .navigation-options a { min-height: 46px; }
}

@media (max-width: 380px) {
  .eyebrow { font-size: .55rem; letter-spacing: .1em; }
  .filters { grid-template-columns: 1fr; }
  .map-topbar .legend { display: none; }
  .sidebar-footer { flex-wrap: wrap; }
}

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