:root {
  --bg: #ffffff;
  --surface: #f5f6f8;
  --line: #e6e8eb;
  --text: #191f28;
  --muted: #6b7684;
  --brand: #1f6feb;
  --brand-soft: #e8f0fe;
  --accent: #ffcd00;
  --t-public: #1f6feb;   /* 공중화장실 */
  --t-open: #12a150;     /* 개방화장실 */
  --t-simple: #f08c00;   /* 간이화장실 */
  --t-mobile: #9c36b5;   /* 이동화장실 */
  --t-etc: #6b7684;
  --shadow: 0 4px 18px rgba(0, 0, 0, .12);
  --radius: 14px;
  --panel-w: 380px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
a { color: var(--brand); }
button { font: inherit; cursor: pointer; }
.muted { color: var(--muted); }

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

/* ---------- 패널 ---------- */
.panel {
  position: fixed; z-index: 10;
  top: 12px; left: 12px; bottom: 12px;
  width: var(--panel-w);
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sheet-handle { display: none; }
.panel-head { padding: 16px 18px 10px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { width: 34px; height: 34px; color: var(--brand); flex: none; }
.brand h1 { font-size: 18px; margin: 0; letter-spacing: -0.02em; }
.brand p { margin: 2px 0 0; font-size: 12.5px; }

/* 검색 */
.search {
  position: relative; margin: 4px 14px 8px;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border-radius: 10px; padding: 0 10px;
  border: 1px solid transparent;
}
.search:focus-within { border-color: var(--brand); background: #fff; }
.search > svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.search input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  height: 42px; font: inherit; font-size: 15px; color: var(--text);
}
.search input::-webkit-search-cancel-button { display: none; }
.icon-btn { border: 0; background: none; font-size: 20px; color: var(--muted); padding: 0 4px; }
.search-results {
  position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 6px);
  background: #fff; border-radius: 10px; box-shadow: var(--shadow);
  max-height: 360px; overflow: auto; padding: 6px 0;
}
.sr-group { font-size: 11.5px; color: var(--muted); padding: 8px 14px 4px; font-weight: 600; }
.sr-item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 14px; }
.sr-item:hover, .sr-item.active { background: var(--surface); }
.sr-item b { display: block; font-size: 14px; font-weight: 600; }
.sr-item span { display: block; font-size: 12px; color: var(--muted); margin-top: 1px; }
.sr-empty { padding: 10px 14px; font-size: 13px; color: var(--muted); }

/* 필터 */
.filters { padding: 2px 14px 10px; border-bottom: 1px solid var(--line); }
.chip-row { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 3px 0; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 5px;
  height: 32px; padding: 0 11px; border-radius: 16px;
  border: 1px solid var(--line); background: #fff; color: var(--text);
  font-size: 13px; white-space: nowrap;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.chip .cnt { color: var(--muted); font-size: 11.5px; }
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: #fff; }
.chip[aria-pressed="true"] .cnt { color: #c9cdd2; }
.tier-chip .dot { background: var(--c); width: 10px; height: 10px; }
.tier-chip[aria-pressed="true"] { background: var(--c); border-color: var(--c); color: #fff; font-weight: 600; }
.tier-chip[aria-pressed="true"] .dot { background: #fff; }
.tier-chip[aria-pressed="false"] { color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 2px 10px; margin: 4px 0 6px; font-size: 11.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.legend .legend-note { color: #a0a7b0; }

/* 목록 */
.view { flex: 1; min-height: 0; overflow-y: auto; }
.list-head { display: flex; align-items: baseline; justify-content: space-between; padding: 12px 18px 6px; font-size: 14px; }
.list-head span { font-size: 12px; }
.list { list-style: none; margin: 0; padding: 0 6px 10px; }
.list li {
  padding: 11px 12px; border-radius: 10px; cursor: pointer;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px;
}
.list li:hover, .list li.hover { background: var(--surface); }
.tier-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c); margin-right: 6px; vertical-align: 1px; }
.cnt-dot { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 600; color: var(--c); margin-left: 6px; }
.cnt-dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.live-hint { margin: 0 14px 6px; padding: 8px 10px; border-radius: 8px; background: var(--surface); font-size: 12px; color: var(--muted); }
.li-name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-dist { font-size: 13px; font-weight: 600; color: var(--brand); text-align: right; }
.li-sub { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-tags { grid-column: 1 / -1; display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.tag { font-size: 11px; padding: 2px 6px; border-radius: 5px; background: var(--surface); color: #4e5968; }
.tag.tier { color: #fff; font-weight: 600; }
.tag.ok { background: #fff4e6; color: #c25e00; }
.empty { padding: 24px 18px; text-align: center; font-size: 13.5px; color: var(--muted); line-height: 1.6; }
.list li.list-group { display: block; cursor: default; background: none; padding: 14px 12px 4px; font-size: 13px; font-weight: 700; color: var(--c); }
.list li.list-group span { font-weight: 400; font-size: 12px; color: var(--muted); margin-left: 4px; }
.list li.more-note { display: block; cursor: default; background: none; }
.more-note { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0 12px; }

/* 상세 */
.back-btn { border: 0; background: none; color: var(--muted); padding: 12px 16px 4px; font-size: 14px; }
#detail { padding: 4px 18px 18px; }
.d-type { display: inline-block; font-size: 12px; color: #fff; padding: 3px 8px; border-radius: 6px; }
.d-name { font-size: 21px; margin: 8px 0 4px; letter-spacing: -0.02em; line-height: 1.3; }
.d-addr { font-size: 14px; margin: 0; }
.d-jibun { font-size: 12.5px; margin: 2px 0 0; }
.d-dist { font-size: 13px; color: var(--brand); font-weight: 600; margin-top: 6px; }
.d-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin: 14px 0; }
.d-actions a, .d-actions button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  height: 58px; border-radius: 10px; border: 1px solid var(--line); background: #fff;
  color: var(--text); text-decoration: none; font-size: 12.5px;
}
.d-actions a.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
.d-actions svg { width: 20px; height: 20px; }
.d-trust { background: var(--s); border-left: 4px solid var(--c); border-radius: 8px; padding: 10px 12px; margin: 0 0 14px; font-size: 13px; line-height: 1.55; }
.d-trust b { display: block; color: var(--c); font-size: 13.5px; margin-bottom: 2px; }
.d-trust .tier-dot { margin-right: 5px; }
.d-trust p { margin: 2px 0 0; color: #333d4b; }
.d-trust p.tip { color: var(--muted); }
.d-roadview { height: 170px; border-radius: 10px; overflow: hidden; background: var(--surface); margin-bottom: 14px; position: relative; }
.d-roadview .rv-label { position: absolute; z-index: 2; left: 8px; top: 8px; font-size: 11px; background: rgba(0,0,0,.6); color: #fff; padding: 2px 6px; border-radius: 4px; }
.d-sec { border-top: 1px solid var(--line); padding: 12px 0; }
.d-sec h3 { font-size: 13px; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.d-row { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; padding: 3px 0; }
.d-row span:first-child { color: var(--muted); flex: none; }
.d-row span:last-child { text-align: right; }
.fix-grid { display: grid; grid-template-columns: auto 1fr 1fr 1fr; gap: 0; font-size: 13.5px; text-align: center; }
.fix-grid > div { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.fix-grid .h { color: var(--muted); font-size: 12px; }
.fix-grid .l { text-align: left; color: var(--muted); }
.feat-list { display: flex; flex-wrap: wrap; gap: 6px; }
.feat { font-size: 12.5px; padding: 5px 9px; border-radius: 8px; background: var(--brand-soft); color: #1a4fa8; }
.feat.off { background: var(--surface); color: #a0a7b0; text-decoration: line-through; }

.panel-foot { font-size: 11px; padding: 8px 14px; border-top: 1px solid var(--line); }
.panel-foot a { color: inherit; }

/* ---------- 지도 위 요소 ---------- */
.map-fabs { position: fixed; z-index: 9; right: 14px; bottom: 28px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.fab {
  height: 46px; min-width: 46px; border-radius: 23px; border: 0; background: #fff; color: var(--text);
  box-shadow: var(--shadow); display: inline-flex; align-items: center; justify-content: center; padding: 0 12px;
}
.fab svg { width: 22px; height: 22px; }
.fab.active { color: var(--brand); }
.fab-wide { background: var(--text); color: #fff; font-weight: 600; font-size: 14px; padding: 0 16px; }

.pin {
  position: relative; width: 30px; height: 38px; cursor: pointer;
  transform-origin: 50% 100%; transition: transform .12s;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.25));
}
.pin svg { width: 100%; height: 100%; display: block; }
.pin:hover { transform: scale(1.12); }
.pin.selected { transform: scale(1.35); }
.pin.dim { opacity: .55; }

.cluster {
  cursor: pointer;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 13px; letter-spacing: -0.02em;
  background: var(--brand); border: 3px solid rgba(255,255,255,.9); opacity: .92;
  box-shadow: 0 2px 8px rgba(0,0,0,.25); transition: transform .12s;
}
.cluster:hover { transform: scale(1.08); }

.me-dot { width: 18px; height: 18px; position: relative; }
.me-dot::before { content: ""; position: absolute; inset: 0; border-radius: 50%; background: var(--brand); border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); z-index: 1; }
.me-dot::after { content: ""; position: absolute; inset: -14px; border-radius: 50%; background: rgba(31,111,235,.25); animation: pulse 2s ease-out infinite; }
@keyframes pulse { from { transform: scale(.4); opacity: 1; } to { transform: scale(1.3); opacity: 0; } }

.toast {
  position: fixed; z-index: 30; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: rgba(25, 31, 40, .92); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  max-width: calc(100% - 32px); text-align: center;
}

/* ---------- 설정 화면 ---------- */
.setup { position: fixed; inset: 0; z-index: 50; background: rgba(245,246,248,.96); display: flex; align-items: center; justify-content: center; padding: 16px; }
.setup-card { background: #fff; border-radius: 16px; box-shadow: var(--shadow); padding: 24px; max-width: 520px; width: 100%; }
.setup-card h2 { margin: 0 0 12px; font-size: 19px; }
.setup-card ol { padding-left: 20px; font-size: 14px; line-height: 1.7; margin: 0 0 14px; }
.setup-card code { background: var(--surface); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.setup-error { color: #d9480f; font-size: 13.5px; background: #fff4e6; padding: 10px 12px; border-radius: 8px; }
#setupForm { display: flex; gap: 8px; }
#setupForm input { flex: 1; min-width: 0; height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; font: inherit; }
#setupForm button { height: 44px; border: 0; border-radius: 10px; background: var(--accent); padding: 0 16px; font-weight: 600; }

/* ---------- 모바일: 바텀시트 ---------- */
@media (max-width: 760px) {
  .panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto;
    border-radius: 18px 18px 0 0;
    height: 46vh; transition: height .25s ease;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .panel[data-sheet="min"] { height: 196px; }
  .panel[data-sheet="full"] { height: calc(100vh - 56px); height: calc(100dvh - 56px); }
  .sheet-handle { display: flex; justify-content: center; padding: 8px 0 2px; cursor: grab; touch-action: none; }
  .sheet-handle span { width: 40px; height: 5px; border-radius: 3px; background: #d1d6db; }
  .panel-head { display: none; }
  .search { margin-top: 6px; }
  .panel.detail-mode .filters { display: none; }
  .panel-foot { display: none; }
  .map-fabs { bottom: calc(46vh + 14px); right: 12px; transition: bottom .25s ease; }
  body[data-sheet="min"] .map-fabs { bottom: 210px; }
  body[data-sheet="full"] .map-fabs { display: none; }
  .toast { bottom: calc(46vh + 70px); }
}
