/* 디자인 기준
   1) expense-map/design/DESIGN.md (getdesign "uber"): 흑백 + 회색, 알약 모양 버튼, 16px 카드
   2) expense-map/design/reference/ 화면 시안(A~F)의 배치·크기·기호
   값은 :root 변수에 모아 둔다. */
:root {
  --ink: #000000;
  --white: #ffffff;
  --muted: #5e5e5e;
  --subtle: #afafaf;
  --soft: #efefef;
  --line: #e2e2e2;
  --link: #0000ee;
  --r-sm: 8px;
  --r-xl: 16px;
  --r-pill: 999px;
  --float: 0 3px 14px rgba(0, 0, 0, .07);
  --float-strong: 0 4px 16px rgba(0, 0, 0, .16);
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Malgun Gothic", "Noto Sans KR", sans-serif;
  --panel-w: 400px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --top: calc(var(--safe-t) + 10px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--soft); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.5;
  font-synthesis: none; -webkit-text-size-adjust: 100%; overflow: hidden; overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; border: 0; background: transparent; font-weight: 500; padding: 0; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
button svg { pointer-events: none; }
svg { display: block; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

/* 공통 부품 */
.circle {
  width: 48px; height: 48px; border-radius: var(--r-pill); display: grid; place-items: center; background: var(--white); flex: none;
}
.circle svg { width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.circle:active { background: var(--line); }
.floating { box-shadow: var(--float); }
.pill {
  border-radius: var(--r-pill); min-height: 44px; padding: 0 16px; display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; white-space: nowrap; background: var(--soft); font-weight: 500; font-size: 14px; flex: none;
}
.pill.active, .pill.primary { background: var(--ink); color: var(--white); }
.badge {
  display: inline-flex; align-items: center; font-size: 12px; line-height: 22px; border-radius: var(--r-pill); padding: 0 8px;
  font-weight: 500; background: var(--ink); color: var(--white); white-space: nowrap; vertical-align: middle;
}
.badge.light { background: var(--soft); color: var(--ink); }
.chevron { width: 16px; height: 16px; flex: none; align-self: center; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 지도 ---------- */
#map { position: fixed; inset: 0; z-index: 0; background: var(--soft); }
.map-gray .leaflet-tile-pane { filter: grayscale(1) brightness(1.06) contrast(.88); }
.leaflet-container { font-family: var(--font); background: var(--soft); }
.leaflet-control-attribution { font-size: 10px; background: rgba(255, 255, 255, .7) !important; }
.leaflet-control-scale-line { border-color: var(--muted); color: var(--muted); font-size: 10px; background: rgba(255,255,255,.6); }

/* ---------- 상단: 검색 + 필터 ---------- */
.topbar { position: fixed; z-index: 1000; top: var(--top); left: 16px; right: 0; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.search-row { display: flex; gap: 8px; margin-right: 16px; }
.searchbox {
  flex: 1; min-width: 0; height: 48px; border-radius: var(--r-pill); display: flex; align-items: center; gap: 10px;
  background: var(--white); padding: 0 16px; box-shadow: var(--float);
}
.searchbox input { border: 0; outline: none; width: 100%; min-width: 0; background: transparent; font-size: 16px; }
.searchbox input::placeholder { color: var(--muted); opacity: 1; }
.searchbox input::-webkit-search-cancel-button { -webkit-appearance: none; }
.sb-ico { width: 22px; height: 22px; flex: none; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; }
.sb-btn { width: 24px; height: 44px; display: none; place-items: center; flex: none; }
.sb-btn svg { width: 20px; height: 20px; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.cancel { display: none; font-size: 14px; min-width: 44px; height: 48px; place-items: center; flex: none; }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 10px 16px 10px 0; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chips .pill { background: var(--white); box-shadow: var(--float); }
.chips .pill.active { background: var(--ink); color: var(--white); }

/* 검색 중 (휴대폰: 전체 화면 검색 페이지) */
.search-page {
  position: fixed; z-index: 990; inset: 0; background: var(--white);
  padding: calc(var(--top) + 64px) 20px 24px; overflow-y: auto;
}
.section-label { font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.suggest { list-style: none; margin: 0; padding: 0; }
.suggest li { display: flex; gap: 14px; align-items: center; border-bottom: 1px solid var(--line); padding: 16px 0; min-height: 84px; cursor: pointer; }
.suggest li[aria-selected="true"] { background: #f7f7f7; }
.suggest .circle { background: var(--soft); }
.suggest .s-text { flex: 1; min-width: 0; }
.suggest .s-type { font-size: 14px; color: var(--muted); }
.suggest strong { display: block; font-size: 16px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest .s-sub { font-size: 14px; color: var(--muted); margin-top: 2px; }
.search-foot { margin-top: 24px; font-size: 14px; line-height: 1.7; color: var(--muted); }
body.searching .searchbox { background: var(--soft); box-shadow: none; padding-left: 12px; }
body.searching .sb-ico, body.searching #infoBtn, body.searching .chips { display: none; }
body.searching .sb-back, body.searching .cancel { display: grid; }
body.searching .sb-clear { display: grid; }

/* ---------- 지도 도구 ---------- */
.map-tools {
  position: fixed; z-index: 900; right: 16px; bottom: calc(var(--sheet-h, 55vh) + 16px);
  display: flex; flex-direction: column; gap: 6px; transition: bottom .25s ease, opacity .2s;
}
.wide-only { display: none !important; }
body[data-sheet="full"] .map-tools { opacity: 0; pointer-events: none; }

/* ---------- 아래 시트(휴대폰) ---------- */
.sheet {
  position: fixed; z-index: 950; left: 0; right: 0; bottom: 0; height: var(--sheet-h, 55vh);
  background: var(--white); border-radius: var(--r-xl) var(--r-xl) 0 0; box-shadow: 0 -3px 18px rgba(0, 0, 0, .05);
  display: flex; flex-direction: column; transition: height .25s ease; padding-bottom: var(--safe-b);
}
.sheet.dragging { transition: none; }
.grab { flex: none; height: 20px; display: grid; place-items: center; cursor: grab; touch-action: none; }
.grab::after { content: ''; width: 36px; height: 4px; background: var(--line); border-radius: 8px; }
.sheet-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 20px 28px; overscroll-behavior: contain; scrollbar-width: none; }
.sheet-body::-webkit-scrollbar { display: none; }
.detail-close { position: fixed; z-index: 1001; top: calc(var(--top) + 24px); right: 16px; }
/* 휴대폰 상세 화면: 검색창 대신 닫기 버튼 */
body.detail .topbar { display: none; }

/* ---------- 넓은 화면(아이패드·PC): 왼쪽 고정 패널 ---------- */
@media (min-width: 820px) {
  .wide-only { display: flex !important; }
  .map-tools .wide-only { display: grid !important; }
  .topbar { left: calc(var(--panel-w) + 24px); top: calc(var(--safe-t) + 24px); }
  .search-row { margin-right: 24px; }
  .searchbox { flex: none; width: 360px; }
  .chips { flex-wrap: wrap; overflow: visible; padding-top: 12px; }
  .sheet {
    top: 0; left: 0; bottom: 0; right: auto; width: var(--panel-w); height: auto; border-radius: 0;
    box-shadow: none; border-right: 1px solid var(--line); padding-top: var(--safe-t);
  }
  .grab { display: none; }
  .brand { height: 80px; align-items: center; gap: 10px; padding: 0 24px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex: none; }
  .brand strong { font-size: 20px; font-weight: 700; letter-spacing: -.6px; }
  .brand-icon { width: 32px; height: 32px; background: var(--ink); border-radius: var(--r-pill); display: grid; place-items: center; }
  .brand-icon svg { width: 18px; height: 18px; fill: none; stroke: var(--white); stroke-width: 2; }
  .sheet-body { padding: 0 24px 24px; }
  .panel-foot { display: block !important; flex: none; font-size: 12px; color: var(--muted); line-height: 1.7; padding: 16px 24px 22px; border-top: 1px solid var(--line); }
  .detail-close { position: absolute; top: calc(var(--safe-t) + 96px); right: 16px; box-shadow: none; background: var(--soft); width: 44px; height: 44px; }
  body.detail .topbar { display: block; }
  .map-tools { right: 24px; bottom: 32px; }
  .search-page {
    inset: auto; top: calc(var(--safe-t) + 80px); left: calc(var(--panel-w) + 24px); width: 420px; max-height: 70vh;
    border-radius: var(--r-xl); box-shadow: var(--float-strong); padding: 16px 20px;
  }
  body.searching .chips { display: none; }
  body.searching #infoBtn { display: none; }
  body.searching .searchbox { background: var(--white); box-shadow: var(--float-strong); }
  body.searching .cancel { background: var(--white); border-radius: var(--r-pill); box-shadow: var(--float); padding: 0 14px; }
  .leaflet-bottom.leaflet-left { left: calc(var(--panel-w) + 16px); }
}
@media (max-width: 819px) { .leaflet-control-scale { display: none; } }

/* ---------- 패널: 지역(홈) ---------- */
.region-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
h1, h2 { margin: 0; font-size: 24px; line-height: 1.3; font-weight: 700; letter-spacing: -.8px; word-break: keep-all; }
.clear-region { font-size: 14px; color: var(--muted); white-space: nowrap; display: inline-flex; gap: 5px; align-items: center; min-height: 44px; font-weight: 400; }
.clear-region svg { width: 14px; height: 14px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.region-meta { color: var(--muted); font-size: 14px; line-height: 1.5; margin-top: 2px; }
.tabs { display: flex; border-bottom: 1px solid var(--line); margin-top: 14px; }
.tabs button { width: 50%; min-height: 44px; border-bottom: 3px solid transparent; margin-bottom: -1px; color: var(--muted); }
.tabs button[aria-selected="true"] { border-color: var(--ink); color: var(--ink); font-weight: 700; }
.sort-row { padding: 12px 0 8px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sort {
  background: var(--soft); border: 0; border-radius: var(--r-pill); font-size: 14px; height: 44px; padding: 0 34px 0 16px; max-width: 270px;
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%23000' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 14px;
}
.count-label { font-size: 14px; color: var(--muted); white-space: nowrap; }
.categories { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 12px; }
.categories::-webkit-scrollbar { display: none; }
.list { list-style: none; margin: 0; padding: 0; }
.restaurant-row { display: flex; gap: 12px; padding: 14px 0; border-top: 1px solid var(--line); align-items: flex-start; min-height: 88px; cursor: pointer; }
.restaurant-row:active, .institution-item:active { background: #f7f7f7; }
.order { font-weight: 700; font-size: 18px; width: 22px; padding-top: 1px; flex: none; text-align: center; }
.row-content { flex: 1; min-width: 0; }
.row-name { font-weight: 700; letter-spacing: -.45px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 16px; line-height: 24px; word-break: keep-all; }
.row-stats, .row-date { font-size: 14px; color: var(--muted); line-height: 21px; letter-spacing: -.2px; }
.row-stats { margin-top: 3px; }
.institution-item { display: flex; gap: 12px; align-items: center; padding: 14px 0; border-top: 1px solid var(--line); cursor: pointer; }
.institution-item > .ico { width: 26px; height: 26px; flex: none; }
.institution-item p { margin: 4px 0 0; font-size: 14px; line-height: 1.5; color: var(--muted); }
.more { width: 100%; margin: 12px 0; }
.empty { padding: 30px 0; font-size: 14px; line-height: 1.7; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }

/* ---------- 패널: 식당·기관 상세 ---------- */
.detail-heading { margin-top: 6px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding-right: 52px; }
.detail-heading .badge { font-size: 14px; line-height: 26px; padding: 0 10px; }
.address { font-size: 14px; color: var(--muted); margin-top: 8px; line-height: 1.5; }
.map-links { display: flex; gap: 8px; margin-top: 18px; }
.map-links a { flex: 1; }
.map-links svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 20px 0; }
.metric { background: var(--soft); border-radius: var(--r-xl); min-height: 78px; padding: 13px 10px 12px; }
.metric-label { color: var(--muted); font-size: 14px; line-height: 1.4; white-space: nowrap; }
.metric-value { font-size: 22px; font-weight: 700; letter-spacing: -.7px; margin-top: 7px; line-height: 1.1; white-space: nowrap; }
.metric-value span { font-size: 14px; font-weight: 400; margin-left: 2px; }
.metric.date .metric-value { font-size: 14px; letter-spacing: -.45px; margin-top: 13px; }
.section-title { display: flex; justify-content: space-between; align-items: center; margin: 4px 0 10px; }
.section-title h3 { margin: 0; font-size: 16px; font-weight: 700; }
.section-title span { font-size: 14px; color: var(--muted); }
.detail-section { margin-bottom: 18px; }
.visit { border-top: 1px solid var(--line); padding: 11px 0; }
.visit-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 14px; line-height: 1.5; font-weight: 700; }
.visit p { font-size: 14px; color: var(--muted); line-height: 1.5; margin: 3px 0 0; }
.note { font-size: 12px; color: var(--muted); line-height: 1.6; margin: 12px 0 0; }
.institution-kind { margin-top: 10px; font-size: 14px; display: flex; gap: 8px; align-items: center; color: var(--muted); }
.institution-kind .ico { width: 22px; height: 22px; }
.period-box { margin-top: 18px; border-radius: var(--r-xl); background: var(--soft); padding: 14px 16px; font-size: 14px; line-height: 1.5; }
.period-box > div { display: flex; justify-content: space-between; gap: 12px; }
.period-box > div + div { margin-top: 5px; }
.period-box span { color: var(--muted); }
.rank-head { padding: 16px 0 0; border-top: 1px solid var(--line); margin-top: 18px; }

/* ---------- 지도 기호 ---------- */
.pin, .food { background: none; border: 0; }
.pin .shape { width: 26px; height: 26px; margin: 9px; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .25)); }
.pin.sel .shape { transform: scale(1.3); }
.pin .pin-name {
  position: absolute; top: 40px; left: 50%; transform: translateX(-50%); white-space: nowrap; padding: 5px 9px; background: var(--white);
  border-radius: var(--r-sm); font-size: 12px; line-height: 1.2; font-weight: 700; box-shadow: var(--float); pointer-events: none; display: none;
}
.labels .pin.has .pin-name, .labels-all .pin .pin-name, .pin.sel .pin-name { display: block; }
.food { display: grid !important; place-items: center; }
.food-dot {
  width: 10px; height: 10px; background: var(--ink); border: 2px solid var(--white); border-radius: 100%; box-sizing: content-box;
  display: grid; place-items: center; color: var(--white); font-size: 14px; font-weight: 700; line-height: 1; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.food-dot.favorite { width: 14px; height: 14px; outline: 1px solid var(--ink); outline-offset: 2px; }
.food-dot.selected { width: 28px; height: 28px; border-width: 3px; outline: 2px solid var(--ink); outline-offset: 0; }
.food-dot.selected svg { width: 16px; height: 16px; fill: none; stroke: var(--white); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.rank-mode .food-dot { width: 28px; height: 28px; }
.rank-mode .food-dot.favorite { outline-offset: 1px; }
.rank-mode .food-dot.selected { width: 36px; height: 36px; outline: 2px solid var(--ink); }

/* ---------- 정보 창 ---------- */
dialog { border: 0; padding: 0; border-radius: var(--r-xl); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: var(--float-strong); color: var(--ink); background: var(--white); }
dialog::backdrop { background: rgba(0, 0, 0, .33); }
.dlg { padding: 16px 24px 24px; font-size: 16px; line-height: 1.6; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; }
.dlg-head .circle { background: var(--soft); width: 44px; height: 44px; }
.dlg h3 { font-size: 18px; margin: 24px 0 8px; }
.dlg p { margin: 8px 0; }
.dlg ol, .dlg ul { padding-left: 20px; margin: 8px 0; }
.dlg code { background: var(--soft); padding: 2px 6px; border-radius: var(--r-sm); font-size: 14px; }
.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; }
.legend div { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.legend .ico { width: 22px; height: 22px; }
.legend .rank-mode, .legend .dot-mode { width: 40px; display: grid; place-items: center; }
.muted { color: var(--muted); }
.warn { font-size: 14px; color: var(--muted); }

/* ---------- 알림 ---------- */
.toast {
  position: fixed; z-index: 3000; left: 20px; right: 20px; bottom: calc(var(--safe-b) + 28px); margin: 0 auto; max-width: 420px;
  background: var(--ink); color: var(--white); padding: 14px 18px; border-radius: var(--r-xl); font-size: 14px; text-align: center;
}
