:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-2: #f5f7f9;
  --ink: #16202e;
  --muted: #5b6676;
  --line: #dde3ea;
  --primary: #16202e;
  --on-primary: #ffffff;
  --warn: #b3261e;
  --shadow: 0 10px 30px rgba(22, 32, 46, 0.14);
  --radius: 12px;
  --font: 'IBM Plex Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  --sheet-peek: 132px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1218;
    --surface: #151c25;
    --surface-2: #1b2430;
    --ink: #e6ebf1;
    --muted: #9aa6b6;
    --line: #273342;
    --primary: #e6ebf1;
    --on-primary: #10161e;
    --warn: #ff8a80;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
  .leaflet-tile-pane { filter: brightness(0.78) contrast(1.08) saturate(0.85); }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
[hidden] { display: none !important; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* ---------- 레이아웃 ---------- */
.app { position: relative; height: 100dvh; overflow: hidden; }
.map-wrap { position: absolute; inset: 0; }
#map { position: absolute; inset: 0; background: var(--surface-2); }
#map.picking, #map.picking .leaflet-interactive { cursor: crosshair; }

.panel {
  position: absolute; z-index: 1100; left: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
  transition: height 0.25s ease;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.panel[data-sheet='peek'] { height: var(--sheet-peek); }
.panel[data-sheet='half'] { height: 50dvh; }
.panel[data-sheet='full'] { height: 90dvh; }
.panel[data-sheet='peek'] .panel-body { display: none; }

.sheet-handle { border: 0; background: none; padding: 8px 0 2px; display: grid; place-items: center; }
.sheet-handle span { width: 40px; height: 5px; border-radius: 3px; background: var(--line); }

@media (min-width: 900px) {
  .panel, .panel[data-sheet] {
    top: 12px; bottom: 12px; left: 12px; right: auto; width: 400px; height: auto;
    border-radius: var(--radius);
  }
  .panel[data-sheet='peek'] .panel-body { display: block; }

  .sheet-handle { display: none; }
  .map-wrap { left: 424px; }
  .navbar { left: 16px; right: auto; width: min(440px, calc(100% - 32px)); }
}

.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 6px 16px 10px; }
.brand h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -0.02em; text-wrap: balance; }
.brand .sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.head-actions { position: relative; display: flex; gap: 6px; flex-shrink: 0; }

/* ---------- 버튼 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-size: 13.5px; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn-ghost { background: transparent; }
.icon-btn { width: 36px; padding: 0; }
.icon-btn svg { width: 18px; height: 18px; fill: currentColor; }
.btn-day { background: var(--c); border-color: var(--c); color: #fff; }
.btn-add { width: 100%; margin-top: 12px; border-style: dashed; color: var(--muted); }

.menu {
  position: absolute; top: 42px; right: 0; z-index: 10; min-width: 240px;
  display: flex; flex-direction: column; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.menu > * { text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 8px; font-size: 14px; cursor: pointer; }
.menu > *:hover { background: var(--surface-2); }
.menu-file input { display: none; }

.chip {
  min-height: 30px; padding: 0 11px; border-radius: 999px; font-size: 13px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.chip:disabled { opacity: 0.35; }
.chip-select { padding-right: 6px; }
.chip-danger { color: var(--warn); }
.chip-danger.is-confirm { background: var(--warn); color: var(--surface); border-color: var(--warn); }

/* ---------- 탭 ---------- */
.tabs {
  display: flex; gap: 6px; padding: 0 16px 10px; overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid var(--line);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex-shrink: 0; display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-size: 13.5px; font-weight: 600;
}
.tab.is-active { background: var(--c); border-color: var(--c); color: #fff; }
.tab:first-child.is-active { color: var(--surface); }
.tab-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.tab.is-active .tab-dot { background: #fff; }
.tab-star { color: var(--c); }
.tab.is-active .tab-star { color: #fff; }
.count { font-family: var(--mono); font-size: 12px; opacity: 0.8; }

.panel-body { flex: 1; overflow-y: auto; padding: 14px 16px 28px; overscroll-behavior: contain; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.fineprint { color: var(--muted); font-size: 12px; margin: 14px 0 0; }
.warn { color: var(--warn); font-style: normal; }

.sync-status {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line); font-size: 12.5px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.sync-status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.sync-status[data-state='saved']::before { background: #2f9e44; }
.sync-status[data-state='saving']::before { background: #f59f00; }
.sync-status[data-state='offline']::before, .sync-status[data-state='auth']::before { background: var(--warn); }

.lock {
  position: fixed; inset: 0; z-index: 3000; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(6px);
}
.lock-card {
  width: min(360px, 100%); display: grid; gap: 12px; padding: 22px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
.lock-card h2 { margin: 0; font-size: 20px; letter-spacing: -0.02em; }
.lock-card p { margin: 0; font-size: 14px; color: var(--muted); }
.lock-card .warn { min-height: 1.2em; color: var(--warn); }


/* ---------- 전체 보기 ---------- */
.overview { display: flex; flex-direction: column; gap: 10px; }
.day-card {
  display: grid; gap: 2px; text-align: left; width: 100%;
  padding: 12px 14px 12px 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface);
  box-shadow: inset 4px 0 0 var(--c);
}
.day-card:hover { background: var(--surface-2); }
.day-card-date { font-weight: 700; color: var(--c); font-size: 13px; }
.day-card-title { font-weight: 700; font-size: 16px; }
.day-card-route { color: var(--muted); font-size: 13px; line-height: 1.45; }
.day-card-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------- 하루 타임라인 ---------- */
.day-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.day-head h2 { margin: 0; font-size: 18px; color: var(--c); letter-spacing: -0.01em; }
.day-head h2 span { color: var(--ink); }
.day-meta { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }

.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.stop { position: relative; }
.stop-main {
  display: flex; gap: 12px; width: 100%; text-align: left;
  border: 0; background: none; padding: 6px 4px; border-radius: 10px;
}
.stop-main:hover { background: var(--surface-2); }
.stop-num {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; background: var(--c); color: #fff; font-size: 13px; font-weight: 500;
  box-shadow: 0 0 0 3px var(--surface);
}
.stop-text { display: grid; gap: 1px; min-width: 0; }
.stop-line { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.stop-time { font-size: 13px; color: var(--c); font-weight: 500; }
.stop-name { font-weight: 600; font-size: 15px; }
.stop-kind { font-size: 11.5px; color: var(--muted); letter-spacing: 0.02em; }
.stop-note { font-size: 13px; color: var(--muted); }
.stop-more { padding: 4px 0 8px 44px; display: grid; gap: 8px; }
.stop-link { font-size: 13px; color: var(--ink); }
.stop-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.leg { display: flex; align-items: center; gap: 8px; padding: 2px 0 2px 17px; }
.leg-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; text-align: left;
  border: 0; background: none; padding: 6px 8px 6px 22px; border-radius: 10px;
  border-left: 3px solid var(--c);
}
.leg-main:hover, .leg.is-active .leg-main { background: var(--surface-2); }
.leg.is-active .leg-main { box-shadow: inset 0 0 0 1.5px var(--c); }
.leg-text { display: grid; min-width: 0; }
.leg-sum { font-size: 12.5px; color: var(--ink); }
.leg-stations { font-size: 12px; color: var(--muted); }
.leg-go { flex-shrink: 0; font-size: 12.5px; font-weight: 600; color: var(--c); text-decoration: none; padding: 6px 8px; }
.leg-go:hover { text-decoration: underline; }

.leg-mode { flex-shrink: 0; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-2); color: var(--c); }
.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.mode-train { background: var(--c); color: #fff; }

/* ---------- 폼 ---------- */
.form-row { list-style: none; }
.stop-form {
  display: grid; gap: 10px; margin: 8px 0; padding: 14px;
  border: 1.5px solid var(--c); border-radius: var(--radius); background: var(--surface);
}
.field { display: grid; gap: 4px; min-width: 0; border: 0; margin: 0; padding: 0; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 600; }
.field em { font-style: normal; margin-left: 6px; }
.field input, .field select {
  width: 100%; min-height: 38px; padding: 6px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface-2);
  font-size: 16px; /* iOS 확대 방지 */
}
.field-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.loc-row { display: flex; gap: 6px; flex-wrap: wrap; }
.loc-row input { flex: 1 1 180px; }
.results { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 4px; }
.results button { width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface-2); padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.results button:hover { border-color: var(--c); }
.form-actions { display: flex; gap: 8px; }

/* ---------- 지도 위 요소 ---------- */
.map-tools { position: absolute; z-index: 1000; right: 10px; top: 84px; display: grid; gap: 8px; }
.map-btn {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.map-btn svg { width: 20px; height: 20px; stroke: currentColor; fill: currentColor; }
.map-btn svg path, .map-btn svg circle[fill='none'] { fill: none; }
.leaflet-top.leaflet-right { top: env(safe-area-inset-top, 0px); }
.leaflet-control-zoom a { background: var(--surface) !important; color: var(--ink) !important; border-color: var(--line) !important; }

.pick-hint {
  position: absolute; z-index: 1200; top: calc(12px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 14px; border-radius: 999px;
  background: var(--primary); color: var(--on-primary); font-weight: 600; font-size: 14px; box-shadow: var(--shadow); white-space: nowrap;
}
.pick-hint .btn { min-height: 30px; color: var(--on-primary); border-color: currentColor; }

.pin-wrap { background: none; border: 0; }
.pin {
  display: grid; place-items: center; width: 100%; height: 100%; border-radius: 999px;
  background: var(--c); color: #fff; font: 600 12px/1 var(--mono); letter-spacing: -0.04em;
  border: 2.5px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35);
}
.pin-small { font-size: 10px; border-width: 2px; }
.pin-wish { font-size: 12px; }
.pin-active { outline: 3px solid var(--c); outline-offset: 2px; }

.leaflet-popup-content-wrapper { border-radius: 12px; background: var(--surface); color: var(--ink); }
.leaflet-popup-tip { background: var(--surface); }
.leaflet-popup-content { margin: 12px 14px; font-family: var(--font); }
.pop strong { display: block; font-size: 14px; }
.pop-meta { font-size: 12px; color: var(--muted); }
.pop p { margin: 6px 0 0; font-size: 13px; }
.pop-links { display: flex; gap: 12px; margin-top: 8px; }
.pop-links a { font-weight: 600; font-size: 13px; }

.navbar {
  position: absolute; z-index: 1150; left: 12px; right: 12px;
  top: calc(12px + env(safe-area-inset-top, 0px));
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
}
.nav-inner { padding: 10px 14px 12px; border-top: 4px solid var(--c); margin-top: -4px; border-radius: var(--radius) var(--radius) 0 0; }
.nav-top { display: flex; justify-content: space-between; align-items: center; }
.nav-step { font-size: 12px; color: var(--muted); }
.nav-close { border: 0; background: none; color: var(--muted); font-size: 13px; padding: 4px; }
.nav-route { display: flex; gap: 12px; margin-top: 4px; }
.nav-route .leg-mode { width: 36px; height: 36px; border-radius: 10px; }
.nav-from { margin: 0; font-size: 12.5px; color: var(--muted); }
.nav-to { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.nav-to .num { font-size: 14px; color: var(--c); font-weight: 500; }
.nav-sum { margin: 2px 0 0; font-size: 13px; }
.nav-note { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.nav-actions { display: flex; gap: 6px; margin-top: 10px; }
.nav-actions .btn { flex: 1; padding: 0 8px; }
.nav-actions .btn-primary { background: var(--c); border-color: var(--c); color: #fff; }

.toast {
  position: fixed; z-index: 2000; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--sheet-peek) + 16px + env(safe-area-inset-bottom, 0px));
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 999px;
  background: var(--primary); color: var(--on-primary); font-size: 14px; font-weight: 600; box-shadow: var(--shadow);
}
@media (min-width: 900px) { .toast { bottom: 24px; } }

@media (max-width: 420px) {
  .brand h1 { font-size: 17px; }
  .field-row { grid-template-columns: 1fr 1fr; }
  .field-row .field:last-child { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  .panel { transition: none; }
}
