:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f1f2f5;
  --text: #16181d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #d62f2f;
  --brand-ink: #ffffff;
  --brand-soft: #fde8e8;
  --shadow: 0 8px 28px rgba(15, 20, 30, .14), 0 1px 3px rgba(15, 20, 30, .08);
  --t1: #e03131; /* 지상식 소화전 */
  --t2: #7048e8; /* 지하식 소화전 */
  --t3: #1c7ed6; /* 급수탑 */
  --t4: #0ca678; /* 저수조 */
  --t5: #d6336c; /* 승하강식 소화전 */
  --t6: #f08c00; /* 비상소화장치 */
  --t0: #868e96;
  --me: #1c7ed6;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #181b21;
  --surface-2: #22262e;
  --text: #f1f3f5;
  --muted: #9aa1ac;
  --line: #2a2f38;
  --brand: #ff5252;
  --brand-soft: #3a1d1f;
  --shadow: 0 8px 28px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .4);
  --t1: #ff6b6b; --t2: #9775fa; --t3: #4dabf7; --t4: #38d9a9; --t5: #f06595; --t6: #ffa94d; --t0: #adb5bd;
  --me: #4dabf7;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  font-family: "Pretendard Variable", Pretendard, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  letter-spacing: -0.01em;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#map { position: fixed; inset: 0; background: var(--bg); z-index: 0; }
.leaflet-control-attribution { font-size: 10px; background: color-mix(in srgb, var(--surface) 80%, transparent) !important; color: var(--muted); }
.leaflet-control-attribution a { color: var(--muted); }
.leaflet-control-zoom { display: none; }
.base-tiles { filter: saturate(.75) contrast(.96); }
:root[data-theme="dark"] .base-tiles { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.88) saturate(.55); }

/* ── 상단 바 ── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 500;
  padding: calc(var(--safe-t) + 12px) 12px 0;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px 6px 6px 6px; height: 54px;
}
.brand-mark {
  flex: none; width: 42px; height: 42px; border-radius: 13px;
  display: grid; place-items: center; background: var(--brand); color: #fff;
}
.brand-mark svg { width: 24px; height: 24px; fill: #fff; stroke: #fff; stroke-width: 0; }
.brand-mark svg path:last-child { stroke-width: 2; fill: none; }
.search { flex: 1; position: relative; display: flex; align-items: center; min-width: 0; }
.search-ico { position: absolute; left: 4px; width: 18px; height: 18px; color: var(--muted); }
.search input {
  width: 100%; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 16px; padding: 10px 6px 10px 28px;
}
.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button { filter: grayscale(1); }
.icon-btn {
  flex: none; width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center;
  color: var(--muted);
}
.icon-btn:active { background: var(--surface-2); }

.results {
  margin-top: 8px; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); max-height: 50vh; overflow-y: auto; padding: 6px;
}
.results button {
  display: flex; width: 100%; text-align: left; gap: 10px; align-items: center;
  padding: 12px; border-radius: 12px;
}
.results button:active { background: var(--surface-2); }
.results .r-ico { flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.results .r-ico svg { width: 18px; height: 18px; }
.results b { display: block; font-weight: 650; font-size: 15px; }
.results small { color: var(--muted); font-size: 12.5px; }
.results .empty { padding: 16px; color: var(--muted); font-size: 14px; text-align: center; }

.chips {
  display: flex; gap: 8px; margin: 10px -12px 0; padding: 0 12px 6px;
  overflow-x: auto; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip-group {
  flex: none; display: flex; gap: 2px; padding: 3px; border-radius: 999px;
  background: var(--surface); box-shadow: var(--shadow);
}
.chip-group button {
  height: 32px; padding: 0 12px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  color: var(--muted); white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, color .15s;
}
.chip-group button.on { background: var(--text); color: var(--surface); }
.chip-group .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
#typeChips button.on { background: var(--surface-2); color: var(--text); }
#typeChips button:not(.on) .dot { opacity: .35; }
#typeChips button:not(.on) { text-decoration: line-through; opacity: .7; }

.area-btn {
  position: fixed; z-index: 450; left: 50%; transform: translateX(-50%);
  top: calc(var(--safe-t) + 128px);
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); color: var(--brand); font-weight: 700; font-size: 14px;
  padding: 10px 16px; border-radius: 999px; box-shadow: var(--shadow);
  animation: pop .2s ease-out;
}
.area-btn svg { width: 16px; height: 16px; stroke-width: 2.4; }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -6px); } }

.fab {
  position: fixed; right: 14px; z-index: 450;
  bottom: calc(var(--sheet-h, 190px) + 14px);
  width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center;
  background: var(--surface); box-shadow: var(--shadow); color: var(--text);
  transition: bottom .28s cubic-bezier(.2,.8,.2,1);
}
.fab.tracking { color: var(--me); }
.fab:active { transform: scale(.95); }

/* ── 하단 시트 ── */
.sheet, .detail {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 600;
  background: var(--surface); border-radius: 22px 22px 0 0;
  box-shadow: 0 -6px 30px rgba(0,0,0,.14);
  display: flex; flex-direction: column;
  height: 88vh; height: 88dvh;
  transform: translateY(calc(100% - var(--sheet-h, 190px)));
  transition: transform .28s cubic-bezier(.2,.8,.2,1);
  padding-bottom: var(--safe-b);
  will-change: transform;
}
.sheet.dragging, .detail.dragging { transition: none; }
.sheet-handle { flex: none; padding: 10px 0 6px; display: grid; place-items: center; touch-action: none; cursor: grab; }
.sheet-handle span { width: 40px; height: 5px; border-radius: 3px; background: var(--line); }
.sheet-head {
  flex: none; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  padding: 2px 18px 12px; touch-action: none;
}
.eyebrow { margin: 0 0 3px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.sheet-head h1 { margin: 0; font-size: 20px; font-weight: 750; letter-spacing: -0.02em; }
.sheet-head h1 em { font-style: normal; color: var(--brand); }
.nearest {
  flex: none; text-align: right; background: var(--brand-soft); color: var(--brand);
  border-radius: 14px; padding: 7px 12px; font-size: 12px; font-weight: 600; line-height: 1.25;
}
.nearest b { display: block; font-size: 18px; font-weight: 800; }

.list { list-style: none; margin: 0; padding: 0 10px 20px; overflow-y: auto; flex: 1; overscroll-behavior: contain; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 12px 10px; border-radius: 14px; cursor: pointer;
}
.item:active, .item.sel { background: var(--surface-2); }
.item + .item { border-top: 1px solid var(--line); }
.item:active + .item, .item.sel + .item { border-top-color: transparent; }
.badge {
  flex: none; width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 15px;
}
.item-main { flex: 1; min-width: 0; }
.item-main b { display: block; font-size: 15.5px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-main small { display: block; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.item-dist { flex: none; text-align: right; }
.item-dist b { display: block; font-size: 16px; font-weight: 750; font-variant-numeric: tabular-nums; }
.item-dist small { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 3px; }
.item-dist small svg { width: 12px; height: 12px; stroke-width: 2.6; }
.list .empty { text-align: center; color: var(--muted); padding: 32px 20px; font-size: 14.5px; line-height: 1.6; }
.list .more { text-align: center; color: var(--muted); padding: 14px; font-size: 13px; }

.skeleton { height: 64px; margin: 6px 0; border-radius: 14px; background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── 상세 시트 ── */
.detail { height: auto; max-height: 70vh; max-height: 70dvh; transform: translateY(105%); z-index: 700; }
.detail.open { transform: translateY(0); }
#detailBody { overflow-y: auto; padding: 0 18px 18px; }
.d-head { display: flex; gap: 14px; align-items: center; }
.d-head .badge { width: 56px; height: 56px; border-radius: 18px; font-size: 20px; }
.d-type { font-size: 13px; font-weight: 700; }
.d-title { margin: 2px 0 0; font-size: 21px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.3; word-break: keep-all; }
.d-close { margin-left: auto; align-self: flex-start; width: 36px; height: 36px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); }
.d-close svg { width: 18px; height: 18px; }
.d-dist {
  display: flex; gap: 8px; margin: 16px 0 14px;
}
.d-dist div { flex: 1; background: var(--surface-2); border-radius: 14px; padding: 10px 12px; }
.d-dist small { display: block; font-size: 12px; color: var(--muted); }
.d-dist b { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.d-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 50px; border-radius: 14px;
  font-weight: 700; font-size: 15px; text-decoration: none; background: var(--surface-2); color: var(--text);
}
.btn svg { width: 19px; height: 19px; }
.btn.primary { background: var(--brand); color: #fff; grid-column: 1 / -1; }
.btn:active { filter: brightness(.94); transform: scale(.99); }
.d-rows { margin: 0; border-top: 1px solid var(--line); }
.d-rows div { display: flex; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--line); font-size: 14.5px; }
.d-rows dt { flex: none; width: 76px; color: var(--muted); }
.d-rows dd { margin: 0; flex: 1; font-weight: 550; word-break: keep-all; overflow-wrap: anywhere; }
.d-rows dd a { color: var(--me); text-decoration: none; font-weight: 650; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12.5px; font-weight: 700; }
.pill.y { background: color-mix(in srgb, var(--t4) 18%, transparent); color: var(--t4); }
.pill.n { background: var(--surface-2); color: var(--muted); }
.d-note { font-size: 12px; color: var(--muted); margin: 12px 0 0; line-height: 1.5; }

/* ── 지도 마커 ── */
.pin { width: 30px; height: 30px; position: relative; }
.pin i {
  position: absolute; inset: 0; border-radius: 50% 50% 50% 4px; transform: rotate(-45deg);
  background: var(--c); border: 2.5px solid #fff; box-shadow: 0 3px 8px rgba(0,0,0,.3);
}
.pin span { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font: 800 12px/1 "Pretendard Variable", sans-serif; }
.pin.sel { z-index: 1000 !important; }
.pin.sel i { transform: rotate(-45deg) scale(1.3); box-shadow: 0 0 0 6px color-mix(in srgb, var(--c) 30%, transparent), 0 4px 10px rgba(0,0,0,.35); }
.pin.sel span { transform: translateY(-2px) scale(1.15); }
.me { width: 22px; height: 22px; border-radius: 50%; background: var(--me); border: 4px solid #fff; box-shadow: 0 0 0 0 rgba(28,126,214,.5), 0 2px 6px rgba(0,0,0,.3); animation: ping 2s infinite; }
.me.manual { background: var(--brand); box-shadow: 0 2px 6px rgba(0,0,0,.3); animation: none; }
@keyframes ping { 70% { box-shadow: 0 0 0 16px rgba(28,126,214,0), 0 2px 6px rgba(0,0,0,.3); } 100% { box-shadow: 0 0 0 0 rgba(28,126,214,0), 0 2px 6px rgba(0,0,0,.3); } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--sheet-h, 190px) + 80px); z-index: 900;
  transform: translate(-50%, 10px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--surface); padding: 11px 16px; border-radius: 12px;
  font-size: 14px; font-weight: 600; max-width: calc(100% - 32px); text-align: center;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 720px) {
  .topbar { right: auto; width: 420px; }
  .sheet, .detail { left: 12px; right: auto; width: 420px; bottom: 12px; border-radius: 22px; height: calc(100vh - 190px); top: auto; }
  .sheet { transform: none !important; }
  .detail { max-height: calc(100vh - 190px); }
  .fab { bottom: 24px !important; }
  .toast { bottom: 32px; }
  .sheet-handle { display: none; }
  .sheet-head { padding-top: 16px; }
}
