/* 인원 추산기 */
:root {
  --ink: #171c33;
  --ink-2: #4a5170;
  --ink-3: #7a8098;
  --line: #e3e5ee;
  --bg: #f4f5f9;
  --card: #ffffff;
  --navy: #1f2a5c;
  --accent: #3a4fd8;
  --accent-ink: #ffffff;
  --accent-soft: #eceffd;
  --sun: #ffd166;
  --g: #1f9d55;
  --y: #e0b000;
  --o: #ef7d1a;
  --r: #d6343a;
  --g-soft: #e5f6ec;
  --y-soft: #fdf6d8;
  --o-soft: #fdeedd;
  --r-soft: #fbe5e6;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(23, 28, 51, .06), 0 6px 24px rgba(23, 28, 51, .08);
  --appbar-h: 64px;
  --panel-w: 400px;
  font-family: "Pretendard Variable", Pretendard, system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); overflow: hidden; word-break: keep-all; overflow-wrap: anywhere; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* 상단 바 */
.appbar {
  height: var(--appbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 20px;
  background: var(--navy); color: #fff;
  position: relative; z-index: 1200;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 36px; height: 36px; flex: none; color: #2c3a7a; }
.brand-text { min-width: 0; }
.brand h1 { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: -0.02em; }
.brand p { margin: 1px 0 0; font-size: 13px; color: #c9cfee; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge-unofficial {
  flex: none; font-size: 12px; font-weight: 600; padding: 6px 10px; border-radius: 999px;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.22); color: #e9ecff;
}

/* 레이아웃 */
.layout { display: flex; height: calc(100% - var(--appbar-h)); }
.map-wrap { position: relative; flex: 1; min-width: 0; }
#map { position: absolute; inset: 0; background: #e9eaef; }
.panel {
  width: var(--panel-w); flex: none; background: var(--bg);
  border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0;
}
.panel-scroll { overflow-y: auto; padding: 14px 14px 28px; display: flex; flex-direction: column; gap: 12px; overscroll-behavior: contain; }
.sheet-handle { display: none; }

/* 지도 위 검색 */
.map-top {
  position: absolute; top: 14px; left: 14px; right: 14px; z-index: 1000;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none; max-width: 460px;
}
.map-top > * { pointer-events: auto; }
.search {
  position: relative; display: flex; align-items: center; gap: 6px;
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 4px 4px 4px 12px;
  border: 1px solid var(--line);
}
.search-ico { width: 20px; height: 20px; color: var(--ink-3); flex: none; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; height: 42px; font-size: 15px; }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.search-btn {
  height: 40px; padding: 0 16px; border: 0; border-radius: 10px; background: var(--navy); color: #fff; font-weight: 700; font-size: 14px;
}
.search-btn:disabled { opacity: .6; cursor: progress; }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(58,79,216,.18), var(--shadow); }
.search-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); margin: 0; padding: 6px; list-style: none;
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow); border: 1px solid var(--line);
  max-height: 300px; overflow-y: auto;
}
.search-results li button {
  width: 100%; text-align: left; border: 0; background: transparent; padding: 10px 10px; border-radius: 10px; display: block;
}
.search-results li button:hover, .search-results li button:focus-visible { background: var(--accent-soft); outline: none; }
.search-results .r-name { display: block; font-weight: 700; font-size: 14px; }
.search-results .r-addr { display: block; font-size: 12px; color: var(--ink-3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-results .r-empty { padding: 10px; font-size: 14px; color: var(--ink-2); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card);
  font-size: 14px; font-weight: 600; box-shadow: 0 1px 3px rgba(23,28,51,.1);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip-ghost { color: var(--ink-2); }

/* 그리기 도구 */
.drawbar {
  position: absolute; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 1000;
  background: var(--card); border-radius: 18px; box-shadow: var(--shadow); border: 1px solid var(--line);
  padding: 12px; width: min(560px, calc(100% - 28px));
  display: flex; flex-direction: column; gap: 10px;
}
.draw-hint { margin: 0; font-size: 14px; color: var(--ink-2); line-height: 1.45; text-align: center; }
.draw-hint b { color: var(--ink); }
.draw-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.btn {
  min-height: 46px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line); background: #fff;
  font-weight: 700; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn svg { width: 18px; height: 18px; }
.btn:hover { border-color: #c8cbe0; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #2f43c4; border-color: #2f43c4; }
.btn-quiet { background: var(--bg); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, .chip:focus-visible, .preset:focus-visible, .sheet-handle:focus-visible, .search-btn:focus-visible {
  outline: 3px solid rgba(58,79,216,.45); outline-offset: 2px;
}

/* 지도 그리기 요소 */
.leaflet-container { font-family: inherit; }
.map-wrap.is-drawing .leaflet-container { cursor: crosshair; }
.vtx { background: transparent; border: 0; }
.vtx span {
  position: absolute; left: 50%; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px;
  border-radius: 50%; background: #fff; border: 3px solid var(--vc, var(--accent)); box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.vtx.first span { width: 20px; height: 20px; margin: -10px 0 0 -10px; }
.vtx.first.can-close span { background: var(--sun); border-color: var(--navy); animation: pulse 1.6s ease-in-out infinite; }
.vtx.editable { cursor: grab; }
.vtx.editable:active { cursor: grabbing; }
.mid { background: transparent; border: 0; }
.mid span {
  position: absolute; left: 50%; top: 50%; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%;
  background: rgba(255,255,255,.92); border: 1.5px solid var(--vc, var(--accent)); color: var(--vc, var(--accent));
  font: 700 14px/15px system-ui, sans-serif; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,209,102,.9); } 50% { box-shadow: 0 0 0 8px rgba(255,209,102,0); } }
.leaflet-tooltip.poly-label {
  background: var(--navy); color: #fff; border: 0; border-radius: 10px; padding: 6px 10px; font-weight: 800; font-size: 14px;
  box-shadow: 0 2px 10px rgba(0,0,0,.25); white-space: nowrap;
}
.leaflet-tooltip.poly-label::before { display: none; }
.leaflet-tooltip.poly-label small { display: block; font-weight: 500; font-size: 11px; color: #c9cfee; }

/* 카드 공통 */
.card { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); padding: 16px; }
.card-title { margin: 0 0 4px; font-size: 16px; font-weight: 800; letter-spacing: -0.01em; }
.card-desc { margin: 0 0 12px; font-size: 13px; color: var(--ink-3); }
.eyebrow { margin: 0; font-size: 13px; font-weight: 700; color: var(--ink-2); }

/* 안내 */
.notice { background: #fbf8ef; border-color: #eee3c4; padding: 12px 14px; }
.notice-title { margin: 0 0 6px; font-size: 13px; font-weight: 800; color: #6b5310; }
.notice ul { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.55; color: #4b4126; }

/* 결과 */
.result { --bc: var(--ink-3); --bs: var(--bg); border-top: 5px solid var(--bc); padding-top: 14px; }
.result[data-band="g"] { --bc: var(--g); --bs: var(--g-soft); }
.result[data-band="y"] { --bc: var(--y); --bs: var(--y-soft); }
.result[data-band="o"] { --bc: var(--o); --bs: var(--o-soft); }
.result[data-band="r"] { --bc: var(--r); --bs: var(--r-soft); }
.result-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.band-chip { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--bs); color: var(--ink); border: 1px solid var(--bc); white-space: nowrap; }
.result-number { margin: 6px 0 0; font-size: 40px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.result-unit { font-size: 22px; margin-left: 2px; font-weight: 700; }
.result-sub { margin: 4px 0 12px; font-size: 13px; color: var(--ink-2); min-height: 1.4em; }
.formula { background: var(--bg); border-radius: 12px; padding: 10px 12px; }
.formula p { margin: 0; }
.formula-words { font-size: 12px; color: var(--ink-3); font-weight: 600; }
.formula-nums { font-size: 16px; font-weight: 700; margin-top: 3px !important; font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 0; }
.stats div { min-width: 0; }
.stats dt { font-size: 11px; color: var(--ink-3); font-weight: 600; }
.stats dd { margin: 2px 0 0; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.result-foot { margin: 12px 0 0; font-size: 11.5px; color: var(--ink-3); }
.warn { margin: 10px 0 0; font-size: 13px; color: #8a2a12; background: var(--o-soft); border-radius: 10px; padding: 8px 10px; }

/* 밀도 기준 */
.presets { display: grid; gap: 8px; }
.preset {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; text-align: left;
  border: 1.5px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 12px; min-height: 56px;
}
.preset:hover { border-color: #c4c9e6; }
.preset[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.preset .p-dot { width: 10px; height: 10px; border-radius: 50%; }
.preset .p-name { font-weight: 700; font-size: 14px; display: block; }
.preset .p-src { font-size: 11.5px; color: var(--ink-3); display: block; margin-top: 2px; }
.preset .p-val { font-weight: 800; font-size: 14px; white-space: nowrap; font-variant-numeric: tabular-nums; text-align: right; }
.preset .p-val small { display: block; font-weight: 500; font-size: 11px; color: var(--ink-3); }

.slider-row { margin-top: 14px; }
.slider-label { font-size: 13px; font-weight: 700; color: var(--ink-2); }
.slider-inputs { display: flex; align-items: center; gap: 12px; margin-top: 6px; }
.slider-inputs input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); height: 32px; }
.num-wrap { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--ink-2); }
.num-wrap input { width: 78px; height: 42px; border: 1px solid var(--line); border-radius: 10px; padding: 0 8px; font-weight: 700; font-size: 15px; text-align: right; }
.num-wrap input:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(58,79,216,.18); }

.legend { margin-top: 14px; }
.legend-bar { position: relative; display: flex; height: 10px; border-radius: 999px; overflow: visible; }
.legend-bar .seg { width: var(--w); height: 100%; }
.legend-bar .seg:first-child { border-radius: 999px 0 0 999px; }
.legend-bar .seg:nth-child(4) { border-radius: 0 999px 999px 0; }
.seg.g, .dot.g { background: var(--g); } .seg.y, .dot.y { background: var(--y); }
.seg.o, .dot.o { background: var(--o); } .seg.r, .dot.r { background: var(--r); }
.legend-marker {
  position: absolute; top: -5px; width: 6px; height: 20px; margin-left: -3px; border-radius: 3px;
  background: var(--ink); box-shadow: 0 0 0 2px #fff; transition: left .15s;
}
.legend-ticks { position: relative; height: 18px; font-size: 11px; color: var(--ink-3); margin-top: 4px; }
.legend-ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.legend-ticks span:first-child { transform: none; }
.legend-ticks span:last-child { transform: translateX(-100%); }
.legend-keys { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 4px; font-size: 12.5px; color: var(--ink-2); }
.legend-keys b { color: var(--ink); margin-right: 4px; }
.legend-keys .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.legend-note { margin: 8px 0 0; font-size: 11.5px; color: var(--ink-3); }

/* 밀도 그림 */
.visual { display: flex; flex-direction: column; align-items: center; }
#densitySvg { width: 100%; max-width: 250px; height: auto; display: block; }
#densitySvg .person { transition: opacity .2s; }
.visual-caption { margin: 8px 0 0; font-weight: 700; font-size: 14px; }
.visual-note { margin: 4px 0 0; font-size: 12px; color: var(--ink-3); text-align: center; }

/* 비교 */
.compare { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.compare li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 6px; border-radius: 8px; font-size: 13.5px; }
.compare li.on { background: var(--accent-soft); font-weight: 700; }
.compare .c-name { color: var(--ink-2); }
.compare li.on .c-name { color: var(--ink); }
.compare .c-num { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.tips { margin: 6px 0 0; padding-left: 18px; font-size: 13px; line-height: 1.6; color: var(--ink-2); }
.sources ol { margin: 6px 0 0; padding-left: 18px; font-size: 12.5px; line-height: 1.6; color: var(--ink-2); }
.sources .fine { margin: 10px 0 0; font-size: 11.5px; color: var(--ink-3); line-height: 1.55; }

.toast {
  position: fixed; left: 50%; top: calc(var(--appbar-h) + 14px); transform: translateX(-50%); z-index: 1500;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow); max-width: calc(100% - 32px);
}

/* 모바일: 하단 시트 */
@media (max-width: 820px) {
  :root { --appbar-h: 56px; --peek: 196px; }
  .appbar { padding: 0 14px; }
  .brand-mark { width: 30px; height: 30px; }
  .brand h1 { font-size: 17px; }
  .brand p { font-size: 11.5px; white-space: normal; line-height: 1.3; }
  .badge-unofficial { display: none; }
  .layout { display: block; position: relative; }
  .map-wrap { position: absolute; left: 0; right: 0; top: 0; bottom: var(--peek); }
  .map-top { top: 10px; left: 10px; right: 10px; max-width: none; }
  .chip { height: 34px; padding: 0 12px; font-size: 13px; }
  .drawbar { bottom: 12px; padding: 10px; border-radius: 16px; }
  .draw-hint { font-size: 13px; }
  .btn { min-height: 46px; padding: 0 14px; font-size: 15px; flex: 1 1 auto; }

  .panel {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto; z-index: 1100;
    height: min(82dvh, calc(100dvh - var(--appbar-h) - 8px));
    border-left: 0; border-radius: 20px 20px 0 0; box-shadow: 0 -6px 30px rgba(23,28,51,.18);
    transform: translateY(calc(100% - var(--peek))); transition: transform .28s cubic-bezier(.2,.8,.2,1);
  }
  .panel.open { transform: translateY(0); }
  .sheet-handle {
    display: flex; flex-direction: column; align-items: center; gap: 4px; width: 100%; border: 0; background: transparent;
    padding: 8px 0 4px; flex: none; touch-action: none;
  }
  .grip { width: 40px; height: 5px; border-radius: 3px; background: #c9ccd9; }
  .sheet-handle-label { font-size: 12px; color: var(--ink-3); font-weight: 600; }
  .panel-scroll { padding: 4px 12px calc(24px + env(safe-area-inset-bottom)); }
  .panel:not(.open) .panel-scroll { overflow: hidden; }
  .notice { order: 3; }
  .result { order: 1; padding: 12px 14px; }
  .panel-scroll > .card:nth-child(3) { order: 2; }
  .panel-scroll > .card:nth-child(4) { order: 4; } /* 사진·영상으로 세기 */
  .panel-scroll > .card:nth-child(5) { order: 5; }
  .panel-scroll > .card:nth-child(6) { order: 6; }
  .panel-scroll > .card:nth-child(7) { order: 7; }
  .panel-scroll > .card:nth-child(8) { order: 8; }
  .media-actions .btn { flex: 1 1 auto; }
  .result-number { font-size: 32px; margin-top: 2px; }
  .result-unit { font-size: 18px; }
  .result-sub { margin: 2px 0 8px; }
  .formula { padding: 8px 10px; }
  .formula-nums { font-size: 15px; }
  .toast { top: calc(var(--appbar-h) + 100px); }
}
@media (max-width: 380px) {
  .brand p { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* 지도 바탕을 조금 차분하게 해서 그린 영역이 잘 보이도록 */
.leaflet-tile-pane { filter: saturate(.55) contrast(.96) brightness(1.03); }
@media (max-width: 820px) {
  .drawbar { bottom: 30px; }
  .leaflet-bottom .leaflet-control-scale { margin-bottom: 8px; }
}

/* 상단 바: 사진·영상 바로가기 */
.appbar-right { display: flex; align-items: center; gap: 8px; flex: none; }
.appbar-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 999px;
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.28); color: #fff; font-size: 13px; font-weight: 700;
}
.appbar-btn:hover { background: rgba(255,255,255,.2); }
.appbar-btn:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }
.appbar-btn svg { width: 18px; height: 18px; flex: none; }

/* 사진·영상으로 세기 */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.media-card { scroll-margin-top: 12px; }
.media-card.flash { animation: mediaFlash 1.2s ease-out; }
@keyframes mediaFlash { 0% { box-shadow: 0 0 0 0 rgba(58,79,216,.5); } 100% { box-shadow: 0 0 0 12px rgba(58,79,216,0); } }
.privacy-line {
  display: flex; gap: 8px; align-items: flex-start; margin: 0 0 12px; padding: 9px 11px; border-radius: 10px;
  background: var(--accent-soft); color: #26307a; font-size: 13px; font-weight: 600; line-height: 1.45;
}
.privacy-line svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.media-pick { display: flex; gap: 8px; flex-wrap: wrap; }
.media-pick .media-file-btn { flex: 1 1 auto; cursor: pointer; }
.media-pick input:focus-visible + .btn, .media-file-btn:focus-within { outline: 3px solid rgba(58,79,216,.45); outline-offset: 2px; }
.media-status { margin: 10px 0 0; font-size: 13px; color: var(--ink-2); background: var(--bg); border-radius: 10px; padding: 8px 10px; line-height: 1.45; }
.media-status.busy::before {
  content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 7px; vertical-align: -1px;
  border: 2px solid #c4c9e6; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite;
}
.media-status.error { background: var(--r-soft); color: #8a1f24; }
@keyframes spin { to { transform: rotate(360deg); } }
.media-stage { margin-top: 12px; border-radius: 12px; overflow: hidden; background: #10142a; }
.photo-canvas { display: block; width: 100%; height: auto; max-height: 60vh; object-fit: contain; }
.video-wrap { position: relative; line-height: 0; }
.video-wrap video { display: block; width: 100%; height: auto; max-height: 60vh; }
.video-overlay { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }
.media-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.media-note { margin: 8px 0 0; font-size: 12px; color: var(--ink-3); line-height: 1.5; }
.progress { margin-top: 10px; }
.progress-bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progress-text { margin: 5px 0 0; font-size: 12.5px; color: var(--ink-2); font-weight: 600; font-variant-numeric: tabular-nums; }
.media-result { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.media-number { font-size: 34px; }
.media-result .result-sub { margin-bottom: 0; }
.media-result .stats { margin-top: 10px; }
.btn-small { min-height: 38px; font-size: 13.5px; padding: 0 12px; margin-top: 10px; }
.media-limits { margin: 12px 0 0; padding-left: 18px; font-size: 12.5px; line-height: 1.55; color: var(--ink-2); }
@media (max-width: 820px) {
  .appbar-btn { height: 36px; padding: 0 10px; font-size: 12.5px; }
}
@media (max-width: 480px) {
  .appbar-btn span { display: none; }
  .appbar-btn { width: 40px; height: 40px; padding: 0; justify-content: center; }
  .appbar-btn svg { width: 20px; height: 20px; }
}
