:root {
  --bg: #f6f4f0;
  --panel: #ffffff;
  --ink: #1f2328;
  --muted: #6b7280;
  --line: #e7e3dc;
  --soft: #f3f0ea;
  --accent: #d9480f;
  --ok: #2b8a3e;
  --warn: #e67700;
  --danger: #c92a2a;
  --sidebar-w: 380px;
  --sa-top: env(safe-area-inset-top, 0px);
  --sa-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- 레이아웃 ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100vh; height: 100dvh; }
.sidebar {
  position: relative; display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-right: 1px solid var(--line); z-index: 2;
}
.map-wrap { position: relative; min-width: 0; }
#map { height: 100%; width: 100%; }

/* ---------- 공통 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 10px;
  font-size: 13px; cursor: pointer; color: var(--ink); text-decoration: none; min-height: 32px; white-space: nowrap;
}
.row > .btn, .sb-foot > .btn { flex: none; }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.btn.sm { min-height: 26px; padding: 2px 8px; font-size: 12px; }
.icon-btn {
  flex: none; width: 34px; height: 34px; border: 1px solid var(--line); background: #fff; border-radius: 9px;
  display: grid; place-items: center; cursor: pointer; color: var(--ink);
}
.icon-btn svg { width: 18px; height: 18px; }
.row { display: flex; gap: 8px; align-items: flex-end; }
.row > * { min-width: 0; }
.fld { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); flex: 1; margin-bottom: 10px; }
.fld small { color: var(--muted); font-size: 11px; }
.fld input, .fld select, .fld textarea, .search input, .sb-foot input, .sb-foot select {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: #fff;
  font-size: 15px; color: var(--ink); min-height: 36px;
}
.fld textarea { resize: vertical; min-height: 56px; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.5; }
.stack { display: grid; gap: 8px; margin: 12px 0; }

/* ---------- 헤더 ---------- */
.sb-head { padding: calc(14px + var(--sa-top)) 16px 10px; border-bottom: 1px solid var(--line); }
.head-row { display: flex; align-items: center; gap: 6px; }
.head-row.sub { margin-top: 6px; justify-content: space-between; }
.trip-title {
  flex: 1; min-width: 0; font-size: 20px; font-weight: 700; border: none; outline: none; background: transparent; padding: 0;
}
.trip-dates { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.trip-dates input { border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; background: transparent; font-size: 13px; }
.sync { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.sync::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #adb5bd; }
.sync[data-s="synced"]::before { background: var(--ok); }
.sync[data-s="saving"]::before { background: var(--warn); }
.sync[data-s="offline"]::before { background: #868e96; }
.sync[data-s="auth"]::before, .sync[data-s="error"]::before { background: var(--danger); }

.banner { margin: 10px 16px 0; padding: 10px 12px; border-radius: 10px; background: #fff4e6; color: #8a3c00; font-size: 13px; line-height: 1.5; }
.banner button { margin-top: 6px; }

.views { display: flex; gap: 4px; padding: 10px 16px 0; border-bottom: 1px solid var(--line); }
.views button {
  flex: 1; border: none; background: none; padding: 8px 0 10px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; font-weight: 600;
}
.views button.active { color: var(--ink); border-bottom-color: var(--ink); }
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.scroll { flex: 1; overflow-y: auto; padding: 8px 16px 16px; min-height: 0; }

/* ---------- 날짜 탭 ---------- */
.day-tabs { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.day-tab {
  flex: none; border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 6px 11px; cursor: pointer; font-size: 13px; color: var(--muted);
  display: flex; align-items: center; gap: 6px; min-height: 32px;
}
.day-tab .dot { width: 8px; height: 8px; border-radius: 50%; }
.day-tab .wx { font-size: 12px; }
.day-tab.active { color: #fff; border-color: transparent; }
.day-tab.today:not(.active) { border-color: var(--ink); color: var(--ink); }
.day-tab.add { border-style: dashed; }

/* ---------- 타임라인 ---------- */
.timeline { flex: 1; overflow-y: auto; padding: 4px 16px 16px; min-height: 0; }
.day-summary { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 10px 0 4px; flex-wrap: wrap; }
.day-summary h2 { font-size: 15px; margin: 0; }
.day-summary .meta { color: var(--muted); font-size: 12px; }
.day-summary .meta a { color: inherit; }
.weather { font-size: 12.5px; color: var(--muted); padding-bottom: 6px; }

.stop { display: grid; grid-template-columns: 46px 28px 1fr; gap: 0 8px; position: relative; cursor: pointer; padding: 8px 0; }
.stop .time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; padding-top: 3px; text-align: right; }
.stop .rail { position: relative; display: flex; justify-content: center; }
.stop .rail::before { content: ""; position: absolute; top: 0; bottom: -8px; width: 2px; background: var(--line); }
.stop.first .rail::before { top: 12px; }
.stop.last .rail::before { bottom: calc(100% - 12px); }
.stop .num {
  position: relative; width: 24px; height: 24px; border-radius: 50%; color: #fff;
  font-size: 12px; font-weight: 700; display: grid; place-items: center;
}
.stop .num.home { background: #212529 !important; border-radius: 6px; }
.stop .num.home svg, .stop .num.wish svg { width: 15px; height: 15px; }
.stop .num.wish { background: #868e96 !important; }
.stop .body { border-radius: 10px; padding: 2px 8px 6px; margin: -2px 0; transition: background .15s; min-width: 0; }
.stop:hover .body, .stop.selected .body { background: var(--soft); }
.stop .name { font-weight: 600; word-break: keep-all; overflow-wrap: anywhere; }
.stop .ja { font-size: 12px; color: var(--muted); }
.stop .memo { color: var(--muted); font-size: 12.5px; margin-top: 2px; white-space: pre-wrap; }
.stop .tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: #f1ede6; color: var(--muted); margin-left: 6px; vertical-align: 1px; font-weight: 400; }
.stop .resv { margin-top: 4px; font-size: 12px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.stop .resv code { background: var(--soft); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.stop .resv a { color: #1971c2; }
.stop .who { font-size: 11px; color: #adb5bd; margin-top: 2px; }
.stop .actions { display: none; gap: 4px; margin-top: 8px; flex-wrap: wrap; }
.stop.selected .actions { display: flex; }
.stop .actions .btn { min-height: 30px; padding: 3px 9px; font-size: 12.5px; }
.stop .actions select { border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 12.5px; min-height: 30px; }
.stop.past { opacity: .45; }
.stop.next .body { box-shadow: inset 3px 0 0 var(--accent); background: #fff4e6; }
.stop .next-badge { display: inline-block; font-size: 11px; font-weight: 700; color: #fff; background: var(--accent); border-radius: 4px; padding: 1px 6px; margin-right: 6px; vertical-align: 1px; }
.leg { grid-column: 3; font-size: 11.5px; color: #adb5bd; padding: 0 8px; margin: -2px 0; }
.empty { color: var(--muted); text-align: center; padding: 32px 0; line-height: 1.7; }
.empty .btn { margin-top: 8px; }

.sb-foot {
  border-top: 1px solid var(--line); padding: 10px 16px calc(10px + var(--sa-bottom));
  display: flex; gap: 8px; align-items: center;
}
.money-form { flex-wrap: wrap; }
.money-form select { flex: 0 0 92px; }
.money-form #mTitle { flex: 1 1 80px; }
.money-form #mAmount { flex: 0 0 84px; }

/* ---------- 지출 / 준비물 ---------- */
.fx { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); padding: 8px 0; }
.fx input { width: 70px; border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; font-size: 13px; }
.total { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 12px; border-radius: 10px; background: var(--soft); margin-bottom: 8px; }
.total b { font-size: 18px; }
.group-h { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); padding: 12px 0 4px; border-bottom: 1px solid var(--line); }
.item { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--soft); }
.item .grow { flex: 1; min-width: 0; }
.item .amt { font-variant-numeric: tabular-nums; text-align: right; }
.item .amt small { display: block; color: var(--muted); font-size: 11.5px; }
.item .x { border: none; background: none; color: #adb5bd; font-size: 18px; cursor: pointer; padding: 4px 6px; }
.item input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--ink); }
.item.done .grow { color: #adb5bd; text-decoration: line-through; }

/* ---------- 시트 (편집 / 설정) ---------- */
.sheet {
  position: fixed; top: 0; bottom: 0; left: 0; width: var(--sidebar-w); z-index: 1500; background: var(--panel);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: calc(14px + var(--sa-top)) 16px 10px; border-bottom: 1px solid var(--line); }
.sheet-head h3 { margin: 0; font-size: 16px; }
.sheet-body { flex: 1; overflow-y: auto; padding: 14px 16px; }
.sheet-foot { padding: 10px 16px calc(10px + var(--sa-bottom)); border-top: 1px solid var(--line); }
.search { margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px dashed var(--line); }
.search .row { align-items: center; }
.results { display: grid; gap: 4px; margin-top: 6px; }
.results button {
  text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 9px; cursor: pointer;
}
.results button b { display: block; font-size: 13.5px; }
.results button span { font-size: 12px; color: var(--muted); }
.results .msg { font-size: 12px; color: var(--muted); padding: 4px 2px; }
.res { margin-bottom: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.res summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.res[open] summary { margin-bottom: 8px; }
.coord { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.coord.set { color: var(--ok); }

/* ---------- 지도 오버레이 ---------- */
.map-toolbar {
  position: absolute; top: calc(10px + var(--sa-top)); right: 10px; z-index: 500; max-width: calc(100% - 20px);
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end;
  background: #fff; padding: 6px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,.12);
}
.toolbar-opts { display: flex; gap: 4px; align-items: center; }
.toolbar-opts label { display: flex; align-items: center; gap: 4px; font-size: 12.5px; padding: 0 4px; cursor: pointer; white-space: nowrap; }
.legend { display: flex; gap: 2px; align-items: center; flex-wrap: wrap; }
.legend button {
  display: flex; align-items: center; gap: 5px; border: 1px solid transparent; background: none;
  border-radius: 6px; padding: 3px 7px; font-size: 12.5px; cursor: pointer; color: var(--ink); min-height: 28px;
}
.legend button.active { border-color: var(--line); background: var(--soft); font-weight: 600; }
.legend .swatch { width: 16px; height: 4px; border-radius: 2px; }
.pick-banner {
  position: absolute; top: calc(64px + var(--sa-top)); left: 50%; transform: translateX(-50%); z-index: 600;
  background: var(--accent); color: #fff; padding: 8px 8px 8px 14px; border-radius: 999px; font-weight: 500;
  box-shadow: 0 2px 10px rgba(0,0,0,.2); white-space: nowrap; display: flex; gap: 8px; align-items: center;
}
.pick-banner button { border: none; background: rgba(255,255,255,.25); color: #fff; border-radius: 999px; padding: 3px 10px; cursor: pointer; }
.map-wrap.picking #map { cursor: crosshair; }
/* 지도 전체화면 켜기/끄기 */
.map-toggle {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 500;
  display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 6px 14px; font-size: 13px; font-weight: 600; box-shadow: 0 2px 8px rgba(0,0,0,.18); cursor: pointer; color: var(--ink);
}
.map-toggle svg { width: 15px; height: 15px; }
.app.map-full { grid-template-columns: 1fr; }
.app.map-full .sidebar { display: none; }
.app.map-full .map-toggle { bottom: calc(22px + var(--sa-bottom)); }

.pin {
  width: 28px; height: 28px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  display: grid; place-items: center; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.pin span { transform: rotate(45deg); color: #fff; font-weight: 700; font-size: 12px; }
.pin.sel { outline: 3px solid rgba(0,0,0,.3); outline-offset: 2px; }
.pin.wish { background: #868e96; opacity: .9; }
.home-pin {
  width: 34px; height: 34px; border-radius: 9px; background: #212529; color: #fff;
  display: grid; place-items: center; border: 2px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,.4);
}
.home-pin svg { width: 20px; height: 20px; }
.home-pin.sel { outline: 3px solid rgba(0,0,0,.3); outline-offset: 2px; }
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: #1c7ed6; border: 3px solid #fff; box-shadow: 0 0 0 2px rgba(28,126,214,.35), 0 1px 4px rgba(0,0,0,.3); }
.leaflet-control.locate a { display: grid; place-items: center; width: 34px; height: 34px; color: #1c7ed6; cursor: pointer; background: #fff; }
.leaflet-control.locate a.on { background: #e7f5ff; }
.leaflet-control.locate svg { width: 18px; height: 18px; }
.leaflet-popup-content { margin: 10px 12px; font-size: 13px; line-height: 1.5; }
.leaflet-popup-content .pop-actions { display: flex; gap: 6px; margin-top: 6px; }
.leaflet-popup-content .pop-actions a { color: #1971c2; }

/* ---------- 크게 보기 ---------- */
.bigview {
  position: fixed; inset: 0; z-index: 2000; background: #fff;
  display: grid; place-items: center; padding: calc(24px + var(--sa-top)) 20px calc(24px + var(--sa-bottom));
}
.bv-inner { width: 100%; max-width: 720px; text-align: center; }
.bv-ja { font-size: clamp(34px, 10vw, 64px); font-weight: 800; line-height: 1.25; word-break: keep-all; overflow-wrap: anywhere; }
.bv-addr { font-size: clamp(20px, 5.5vw, 32px); margin-top: 18px; line-height: 1.45; overflow-wrap: anywhere; }
.bv-ko { font-size: 15px; color: var(--muted); margin-top: 18px; }
.bv-actions { display: flex; gap: 10px; justify-content: center; margin-top: 28px; flex-wrap: wrap; }
.bv-actions .btn { min-height: 44px; padding: 8px 18px; font-size: 15px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--sa-bottom)); transform: translateX(-50%); z-index: 3000;
  background: #212529; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13.5px; max-width: calc(100% - 32px);
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}

/* ---------- 모바일: 지도 위, 패널 아래 ---------- */
@media (max-width: 760px) {
  /* 지도는 위에 고정, 아래 일정 패널만 스크롤 */
  .app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
  .map-wrap { order: 1; flex: none; height: 40vh; height: 40svh; }
  .sidebar { order: 2; display: block; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; border-right: none; border-top: 1px solid var(--line); }
  .view { display: block; }
  .timeline, .scroll { overflow: visible; flex: none; padding: 4px 12px 8px; }
  .sb-foot { position: sticky; bottom: 0; background: var(--panel); z-index: 5; }
  .sb-head { padding: 10px 12px 8px; }
  .trip-title { font-size: 18px; }
  .banner { margin: 8px 12px 0; padding: 8px 10px; font-size: 12.5px; }
  .views { padding: 4px 12px 0; }
  .views button { padding: 8px 0; }
  .day-tabs { padding: 8px 12px; gap: 5px; }
  .day-tab { padding: 5px 9px; font-size: 12.5px; }
  .map-toolbar { left: 8px; right: 8px; top: calc(8px + var(--sa-top)); max-width: none; justify-content: space-between; padding: 4px; gap: 2px; }
  .legend button { padding: 3px 5px; font-size: 12px; }
  .toolbar-opts label { font-size: 12px; }
  #fitBtn { min-height: 28px; padding: 2px 8px; font-size: 12px; }
  .map-toggle { bottom: 10px; }
  /* 지도 전체화면 */
  .app.map-full .map-wrap { position: fixed; inset: 0; height: auto; z-index: 1000; }
  /* 편집·설정 시트는 화면 전체 */
  .sheet { width: auto; right: 0; border-right: none; }
  .sheet-head { padding-top: calc(12px + var(--sa-top)); }
}

/* 장소 사이 거리 줄 */
.stop-leg { display: grid; grid-template-columns: 46px 28px 1fr; gap: 0 8px; }
.stop-leg > div:nth-child(2) { position: relative; }
.stop-leg > div:nth-child(2)::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--line); }
.stop-leg .leg { padding: 0 8px; margin: 0; }

/* 탭 줄 오른쪽 설정 버튼 */
.views { align-items: center; }
.views .gear { flex: none; width: 34px; height: 34px; border: none; background: none; color: var(--muted); padding: 0; margin-left: 4px; position: relative; }
.views .gear:hover { color: var(--ink); }
/* 연결 문제(오프라인·비밀번호·오류)일 때만 작은 점 */
.views .gear[data-alert]::after { content: ""; position: absolute; top: 5px; right: 4px; width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--panel); }
.views .gear[data-alert="offline"]::after { background: #868e96; }
.views .gear[data-alert="auth"]::after, .views .gear[data-alert="error"]::after { background: var(--danger); }
.sheet .sync { display: inline-flex; font-weight: 600; color: var(--ink); }
.sep-line { border: none; border-top: 1px solid var(--line); margin: 6px 0 14px; }

/* 날짜·후보 한 줄 토글 */
.day-bar { display: flex; align-items: center; gap: 6px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.seg { flex: 1; min-width: 0; display: flex; gap: 2px; padding: 3px; background: var(--soft); border-radius: 10px; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: 1 0 auto; position: relative; border: none; background: none; border-radius: 8px; padding: 7px 8px; min-height: 34px;
  font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.seg button::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--c); margin-right: 5px; vertical-align: 2px; }
.seg button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg .today-dot { position: absolute; top: 3px; right: 4px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.day-bar .gear { flex: none; width: 34px; height: 34px; border: none; background: none; color: var(--muted); padding: 0; position: relative; display: grid; place-items: center; cursor: pointer; }
.day-bar .gear svg { width: 19px; height: 19px; }
.day-bar .gear:hover { color: var(--ink); }
.day-bar .gear[data-alert]::after { content: ""; position: absolute; top: 5px; right: 4px; width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--panel); }
.day-bar .gear[data-alert="offline"]::after { background: #868e96; }
.day-bar .gear[data-alert="auth"]::after, .day-bar .gear[data-alert="error"]::after { background: var(--danger); }
.today-badge { display: inline-block; font-size: 11px; font-weight: 700; color: #fff; background: var(--accent); border-radius: 4px; padding: 1px 6px; vertical-align: 2px; margin-left: 4px; }
@media (max-width: 760px) { .day-bar { padding: 8px 12px; } .seg button { padding: 7px 6px; font-size: 12.5px; } }
