:root {
  --bg: #f6f4f1;
  --surface: #ffffff;
  --text: #1f1d1b;
  --muted: #7a746e;
  --line: #e4e0db;
  --brand: #e2521d;
  --shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 2px 8px rgba(0, 0, 0, .08);

  --in: #e2521d;
  --low: #c98a00;
  --out: #a39d97;

  --title-font: "Jua", "Pretendard", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1b1a;
    --surface: #262524;
    --text: #efece8;
    --muted: #a19a93;
    --line: #3a3836;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 2px 8px rgba(0, 0, 0, .35);
    --out: #6b6662;
  }
}

* { box-sizing: border-box; }
html, body, #map { height: 100%; margin: 0; }
body {
  font-family: "Pretendard", -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
#map { background: var(--bg); }

/* 상단 카드 */
.card {
  position: absolute; z-index: 1000;
  top: max(12px, env(safe-area-inset-top)); left: 12px;
  width: 360px; max-width: calc(100% - 24px);
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.head { display: flex; align-items: center; gap: 10px; }
.logo { flex-shrink: 0; display: block; }
.card h1 {
  margin: 0;
  font-family: var(--title-font); font-weight: 400;
  font-size: 20px; line-height: 1.2; color: var(--text);
}

/* 지역 검색 */
.search { position: relative; margin-top: 10px; }
.search input {
  width: 100%; height: 40px; padding: 0 36px 0 12px;
  font: inherit; font-size: 15px; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.search input::-webkit-search-cancel-button { display: none; }
.search .clear {
  position: absolute; right: 4px; top: 4px;
  width: 32px; height: 32px; border: 0; border-radius: 6px;
  background: none; color: var(--muted); font-size: 18px; cursor: pointer;
}
.search .clear:hover { color: var(--text); }
.search .clear[hidden] { display: none; }
.search-msg { margin: 6px 2px 0; font-size: 13px; color: var(--muted); }
.search-msg:empty { display: none; }

.chips { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 12px; }
.chips li { font-size: 13px; color: var(--muted); }
.chips li b { color: var(--text); font-weight: 700; }

/* 판매처 목록 */
.stores { margin-top: 10px; border-top: 1px solid var(--line); }
.stores[hidden] { display: none; }
.stores summary {
  list-style: none; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 2px 2px; font-size: 13px; font-weight: 600; color: var(--muted);
}
.stores summary::-webkit-details-marker { display: none; }
.stores summary::after { content: "⌄"; font-size: 16px; line-height: 1; }
.stores[open] summary::after { transform: rotate(180deg); }
.stores ul { list-style: none; margin: 6px 0 0; padding: 0; max-height: 40vh; overflow-y: auto; }
.stores li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 6px; border-radius: 6px; cursor: pointer; font-size: 14px;
}
.stores li:hover, .stores li:focus-visible { background: var(--bg); outline: none; }
.stores .name { margin-right: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dist { flex-shrink: 0; font-size: 12px; color: var(--muted); }
.tag { flex-shrink: 0; min-width: 36px; text-align: right; font-size: 13px; font-weight: 700; color: var(--c); }
.tag.out { color: var(--muted); }

/* 빈 상태 */
.empty {
  position: absolute; z-index: 1000; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  padding: 22px 28px; text-align: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.empty[hidden] { display: none; }
.empty img { display: block; margin: 0 auto 10px; }
.empty p { margin: 0; font-size: 17px; font-weight: 700; }
.empty small { display: block; margin-top: 4px; color: var(--muted); font-size: 13px; }

/* 지도 컨트롤 */
.leaflet-control-zoom { border: 1px solid var(--line) !important; box-shadow: var(--shadow) !important; border-radius: 8px !important; overflow: hidden; }
.leaflet-control-zoom a {
  width: 40px !important; height: 40px !important; line-height: 40px !important;
  background: var(--surface) !important; color: var(--text) !important; border-color: var(--line) !important;
}
.leaflet-bottom.leaflet-right { margin-bottom: env(safe-area-inset-bottom); }
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 80%, transparent) !important; color: var(--muted); font-size: 10px; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.tiles-dark { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.9); }

.locate {
  width: 42px; height: 42px; margin-bottom: 8px !important;
  display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
  background: var(--surface); color: var(--text);
}
.locate:hover { color: var(--brand); }
.locate.busy { color: var(--muted); }

/* 핀 */
.in  { --c: var(--in); }
.low { --c: var(--low); }
.out { --c: var(--out); }

.pin {
  position: absolute;
  transform: translate(-50%, calc(-100% - 6px));
  display: flex; align-items: center; gap: 4px;
  padding: 3px 8px 3px 3px;
  border-radius: 6px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 13px; font-weight: 700; white-space: nowrap;
  cursor: pointer;
}
.pin::after {
  content: ""; position: absolute; left: 50%; bottom: -5px;
  width: 8px; height: 8px; background: inherit;
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  transform: translateX(-50%) rotate(45deg);
}
.pin img { width: 20px; height: 20px; display: block; }
.pin.in { background: var(--in); border-color: var(--in); color: #fff; }
.pin.in::after { border-color: var(--in); }
.pin.out { color: var(--muted); }
.pin.out img { filter: grayscale(1); opacity: .7; }

.cluster {
  position: absolute; transform: translate(-50%, -50%);
  min-width: 34px; height: 34px; padding: 0 8px;
  display: grid; place-items: center; border-radius: 17px;
  background: var(--in); color: #fff; border: 2px solid var(--surface);
  font-weight: 700; font-size: 13px;
  box-shadow: var(--shadow);
}

.me {
  position: absolute; transform: translate(-50%, -50%);
  width: 16px; height: 16px; border-radius: 50%;
  background: #2f6fde; border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}
.spot {
  position: absolute; transform: translate(-50%, -100%);
  width: 14px; height: 14px; border-radius: 50% 50% 50% 0;
  background: var(--text); border: 2px solid var(--surface);
  rotate: -45deg; margin-top: -4px;
}

/* 팝업 */
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); }
.leaflet-popup-content-wrapper { border-radius: 10px; box-shadow: var(--shadow); padding: 0; }
.leaflet-popup-content { margin: 12px 14px; font: inherit; min-width: 150px; }
.leaflet-popup-tip { box-shadow: none; }
.leaflet-container a.leaflet-popup-close-button { display: none; }

.store h2 { margin: 0 0 4px; font-size: 16px; font-weight: 700; }
.badge { font-size: 15px; font-weight: 700; color: var(--c); }
.out .badge, .badge.out { color: var(--muted); }
.store time { display: block; margin-top: 4px; font-size: 12px; color: var(--muted); }

@media (max-width: 480px) {
  .card { left: 8px; right: 8px; width: auto; max-width: none; }
}
.cluster.out { background: var(--out); color: #fff; }
.stores li.more { cursor: default; color: var(--muted); font-size: 12px; justify-content: center; }
.stores li.more:hover { background: none; }
