:root {
  --ink: #18231d;
  --muted: #6c776f;
  --line: #e5e9e6;
  --panel: #ffffff;
  --soft: #f4f7f4;
  --green: #1d7a4a;
  --green-2: #2f9461;
  --green-soft: #e9f5ee;
  --yellow: #f4c45f;
  --shadow: 0 18px 50px rgba(24, 35, 29, .12);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: Inter, Pretendard, "Noto Sans KR", "Malgun Gothic", sans-serif; color: var(--ink); background: #eef2ef; }
button, input { font: inherit; }
button { cursor: pointer; }

.app-shell { height: 100vh; display: grid; grid-template-columns: 390px 1fr; overflow: hidden; }
.sidebar { background: var(--panel); display: flex; flex-direction: column; min-width: 0; z-index: 1000; box-shadow: 8px 0 30px rgba(31, 50, 39, .08); }
.brand { display: grid; grid-template-columns: 44px 1fr 36px; gap: 12px; align-items: center; padding: 22px 22px 14px; }
.brand-mark { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; background: var(--green); color: #fff; font-weight: 900; font-size: 23px; font-style: italic; transform: skew(-5deg); }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: -.5px; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.icon-btn { border: 0; width: 36px; height: 36px; border-radius: 10px; background: var(--soft); color: var(--ink); font-size: 16px; }
.icon-btn:hover { background: var(--green-soft); }


.tabs { display: grid; grid-template-columns: repeat(4, 1fr); padding: 0 18px; border-bottom: 1px solid var(--line); gap: 4px; }
.tab { position: relative; padding: 12px 2px; border: 0; background: transparent; color: #7c867f; font-size: 11px; font-weight: 700; white-space: nowrap; }
.tab::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 2px; background: transparent; border-radius: 2px; }
.tab.active { color: var(--green); }
.tab.active::after { background: var(--green); }
.count { display: inline-grid; place-items: center; min-width: 16px; height: 16px; margin-left: 2px; border-radius: 999px; background: var(--green-soft); color: var(--green); font-size: 9px; }

.panels { overflow-y: auto; flex: 1; }
.panel { display: none; padding: 22px 22px 28px; }
.panel.active { display: block; animation: panelIn .18s ease-out; }
@keyframes panelIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.section-head { margin-bottom: 22px; }
.eyebrow { margin: 0 0 5px; font-size: 10px; color: var(--green); font-weight: 900; letter-spacing: 1.3px; }
.section-head h2, .modal-card h2 { margin: 0; font-size: 23px; letter-spacing: -.7px; }
.section-head > p:last-child { margin: 7px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }

.field-label { display: block; margin: 18px 0 8px; font-size: 12px; font-weight: 800; }
.search-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.search-row input, .modal-input { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: #fafcfb; padding: 11px 12px; outline: none; color: var(--ink); }
.search-row input:focus, .modal-input:focus { border-color: var(--green-2); box-shadow: 0 0 0 3px rgba(47,148,97,.10); }

.primary-btn, .secondary-btn, .ghost-btn { border-radius: 12px; padding: 11px 14px; font-weight: 800; border: 0; transition: .15s ease; }
.primary-btn { background: var(--green); color: white; box-shadow: 0 8px 20px rgba(29, 122, 74, .18); }
.primary-btn:hover { background: #17683e; transform: translateY(-1px); }
.secondary-btn { background: var(--green-soft); color: var(--green); }
.secondary-btn:hover { background: #dff1e6; }
.ghost-btn { background: white; border: 1px solid var(--line); color: var(--ink); }
.ghost-btn:hover { background: var(--soft); }
.full { width: 100%; }
#generateCustomBtn, #generateTodayBtn { margin-top: 22px; padding: 13px 16px; }
#useMyLocationBtn { margin-top: 8px; padding: 9px 12px; font-size: 12px; }

.status-card { margin-top: 10px; padding: 11px 12px; border-radius: 12px; background: var(--green-soft); color: #2b593f; font-size: 12px; line-height: 1.45; }
.status-card.muted { background: var(--soft); color: var(--muted); }
.status-card.error { background: #fff0ee; color: #a3443c; }

.chip-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.chip { border: 1px solid var(--line); background: white; border-radius: 12px; padding: 10px 4px; font-weight: 800; color: #5f6962; }
.chip.active { color: var(--green); border-color: #9bc9ae; background: var(--green-soft); }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 13px; background: var(--soft); }
.segmented button { border: 0; padding: 9px 8px; border-radius: 10px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 800; }
.segmented button.active { background: white; color: var(--green); box-shadow: 0 2px 8px rgba(24,35,29,.08); }

.preference-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.preference-card { text-align: left; display: grid; gap: 2px; padding: 13px; border-radius: 15px; border: 1px solid var(--line); background: white; color: var(--ink); }
.preference-card.active { border-color: #9bc9ae; background: var(--green-soft); }
.pref-icon { font-size: 18px; margin-bottom: 2px; }
.preference-card strong { font-size: 12px; }
.preference-card small { color: var(--muted); font-size: 10px; line-height: 1.3; }

.daily-card { margin: 18px 0 0; border: 1px solid #f2dfab; background: #fff9ea; border-radius: 14px; padding: 13px; display: grid; gap: 4px; }
.daily-card span { font-size: 10px; color: #a37516; font-weight: 900; letter-spacing: .5px; }
.daily-card strong { font-size: 12px; }
.daily-card small { font-size: 10px; color: #806d45; }

.company-card { display: flex; gap: 12px; align-items: center; padding: 14px; background: var(--soft); border-radius: 15px; }
.company-dot { width: 38px; height: 38px; flex: 0 0 38px; border-radius: 13px; background: var(--green); position: relative; }
.company-dot::after { content: "S"; color: white; font-weight: 900; position: absolute; inset: 0; display: grid; place-items: center; }
.company-card div:last-child { display: grid; gap: 3px; }
.company-card strong { font-size: 13px; }
.company-card span { font-size: 11px; color: var(--muted); }
.walk-note { font-size: 10px; color: var(--muted); line-height: 1.45; }
.walk-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.walk-card { border: 1px solid var(--line); background: white; border-radius: 14px; padding: 13px 8px; display: grid; gap: 3px; text-align: center; }
.walk-card:hover, .walk-card.featured { border-color: #9bc9ae; background: var(--green-soft); }
.walk-card span { font-size: 20px; font-weight: 900; color: var(--green); letter-spacing: -1px; }
.walk-card strong { font-size: 10px; }
.walk-card small { color: var(--muted); font-size: 9px; }

.saved-list { display: grid; gap: 10px; }
.saved-empty { padding: 30px 14px; border: 1px dashed #ccd4ce; border-radius: 16px; text-align: center; color: var(--muted); font-size: 12px; line-height: 1.6; }
.saved-card { border: 1px solid var(--line); border-radius: 15px; padding: 14px; display: grid; gap: 9px; background: white; }
.saved-card:hover { border-color: #bed7c8; box-shadow: 0 8px 22px rgba(29,122,74,.07); }
.saved-card-head { display: flex; justify-content: space-between; gap: 10px; }
.saved-card h3 { margin: 0; font-size: 13px; }
.saved-meta { color: var(--muted); font-size: 10px; }
.saved-actions { display: flex; gap: 6px; }
.saved-actions button { flex: 1; border: 0; border-radius: 9px; padding: 8px; font-size: 10px; font-weight: 800; }
.saved-view { background: var(--green-soft); color: var(--green); }
.saved-delete { background: #f6f6f6; color: #8a918c; }

.sidebar-footer { padding: 12px 22px 16px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; color: #929a94; font-size: 10px; }
.text-btn { border: 0; background: transparent; color: var(--green); font-size: 10px; font-weight: 800; }

.map-area { position: relative; min-width: 0; }
#map { width: 100%; height: 100%; background: #dfe7e1; }
.leaflet-control-zoom { border: 0 !important; box-shadow: 0 8px 24px rgba(24,35,29,.16) !important; }
.leaflet-control-zoom a { border: 0 !important; color: var(--ink) !important; }

.map-topbar { position: absolute; z-index: 800; top: 18px; left: 18px; right: 18px; display: flex; justify-content: space-between; pointer-events: none; }
.scope-pill, .map-action, .map-hint { pointer-events: auto; border-radius: 999px; background: rgba(255,255,255,.94); box-shadow: 0 8px 26px rgba(24,35,29,.12); backdrop-filter: blur(9px); }
.scope-pill { padding: 9px 12px; font-size: 11px; font-weight: 800; display: flex; align-items: center; gap: 7px; }
.scope-pill span { width: 7px; height: 7px; background: #4db977; border-radius: 50%; box-shadow: 0 0 0 4px rgba(77,185,119,.15); }
.map-action { border: 0; padding: 9px 13px; font-size: 11px; font-weight: 800; color: #6d766f; }
.map-hint { position: absolute; z-index: 800; left: 50%; bottom: 20px; transform: translateX(-50%); padding: 9px 13px; color: #5e6961; font-size: 11px; white-space: nowrap; }

.route-summary { position: absolute; z-index: 850; right: 22px; bottom: 22px; width: min(390px, calc(100% - 44px)); background: rgba(255,255,255,.97); border-radius: 22px; box-shadow: var(--shadow); padding: 20px; backdrop-filter: blur(16px); }
.hidden { display: none !important; }
.summary-close { position: absolute; right: 14px; top: 14px; border: 0; width: 30px; height: 30px; border-radius: 50%; background: var(--soft); color: #777; font-size: 19px; }
.route-kicker { color: var(--green); font-size: 10px; font-weight: 900; letter-spacing: 1px; }
.route-summary h3 { margin: 5px 34px 14px 0; font-size: 20px; letter-spacing: -.5px; }
.route-stats { display: grid; grid-template-columns: repeat(3,1fr); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.route-stats > div { padding: 11px 8px; text-align: center; border-right: 1px solid var(--line); }
.route-stats > div:last-child { border-right: 0; }
.route-stats strong { font-size: 17px; }
.route-stats span { display: block; margin-top: 2px; color: var(--muted); font-size: 9px; }
.route-summary > p { margin: 13px 0 9px; color: #59645c; font-size: 12px; line-height: 1.55; }
.route-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.route-tags span { padding: 5px 8px; border-radius: 999px; background: var(--green-soft); color: var(--green); font-size: 9px; font-weight: 800; }
.summary-actions { display: grid; grid-template-columns: 1.2fr 1fr; gap: 8px; margin-top: 15px; }
.route-notice { display: block; margin-top: 10px; color: #8a918c; font-size: 9px; line-height: 1.45; }

.loading-overlay { position: absolute; z-index: 900; inset: 0; background: rgba(238,244,240,.72); display: flex; flex-direction: column; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.loader { width: 38px; height: 38px; border: 4px solid #cfe2d5; border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; margin-bottom: 12px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay strong { font-size: 14px; }
.loading-overlay span { margin-top: 5px; color: var(--muted); font-size: 11px; }

.modal { border: 0; padding: 0; border-radius: 22px; width: min(520px, calc(100% - 32px)); box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(17, 28, 21, .48); backdrop-filter: blur(3px); }
.modal-card { position: relative; padding: 24px; }
.modal-card h2 { margin-bottom: 8px; }
.modal-copy { color: var(--muted); font-size: 12px; line-height: 1.55; }
.modal-close { position: absolute; right: 16px; top: 16px; width: 32px; height: 32px; border-radius: 50%; border: 0; background: var(--soft); font-size: 20px; }
.modal-row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.api-state { margin: 14px 0 6px; font-size: 11px; font-weight: 800; color: var(--green); }
.modal-card > small { color: var(--muted); line-height: 1.45; }
.help-card ol { padding-left: 20px; color: #566159; font-size: 12px; line-height: 1.7; }
.help-note { border-radius: 12px; background: #fff7e8; padding: 12px; color: #775d2b; font-size: 11px; line-height: 1.5; }

.custom-start-marker { width: 22px; height: 22px; border-radius: 50%; background: white; border: 6px solid var(--green); box-shadow: 0 4px 14px rgba(29,122,74,.35); }
.poi-marker { width: 9px; height: 9px; border-radius: 50%; background: #f0b746; border: 2px solid white; box-shadow: 0 2px 6px rgba(0,0,0,.25); }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; grid-template-rows: 54% 46%; }
  .sidebar { order: 2; box-shadow: 0 -8px 26px rgba(24,35,29,.10); }
  .map-area { order: 1; }
  .tabs { padding-top: 4px; }
  .panel { padding: 16px 18px 26px; }
  .route-summary { left: 12px; right: 12px; bottom: 12px; width: auto; max-height: 80%; overflow: auto; }
  .map-topbar { top: 10px; left: 10px; right: 10px; }
  .map-hint { bottom: 10px; }
}


/* v2 · precise start / waypoint controls */
.two-btn-row { display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-top:8px; }
.field-help { display:block; margin-top:7px; color:var(--muted); line-height:1.45; }
.waypoint-box { margin-top:14px; padding:12px; border:1px solid var(--line); border-radius:14px; background:#fbfcfb; }
.waypoint-head { display:flex; align-items:flex-start; justify-content:space-between; gap:10px; margin-bottom:10px; }
.waypoint-head small { display:block; color:var(--muted); margin-top:2px; line-height:1.35; }
.field-label.compact { margin:0; }
.small-btn { padding:8px 10px; font-size:11px; white-space:nowrap; }
.waypoint-list { display:flex; flex-direction:column; gap:7px; margin-top:9px; }
.waypoint-empty { padding:8px 4px; color:var(--muted); font-size:11px; text-align:center; }
.waypoint-item { display:grid; grid-template-columns:24px 1fr auto; gap:8px; align-items:center; padding:8px; border:1px solid var(--line); border-radius:10px; background:white; }
.waypoint-num { width:24px; height:24px; display:grid; place-items:center; border-radius:50%; background:#fff0c8; color:#7b5a00; font-weight:900; font-size:11px; }
.waypoint-text { min-width:0; }
.waypoint-text strong { display:block; font-size:11px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.waypoint-text small { display:block; margin-top:2px; color:var(--muted); }
.waypoint-actions { display:flex; gap:4px; }
.waypoint-actions button { width:27px; height:27px; border:1px solid var(--line); border-radius:8px; background:white; cursor:pointer; }
.waypoint-actions button:hover { background:var(--soft); }
.waypoint-mode { background:#fff8df !important; border-color:#ddb93b !important; color:#7d6200 !important; }
.custom-waypoint-marker { width:24px; height:24px; border-radius:50% 50% 50% 0; transform:rotate(-45deg); background:#e4ad22; border:3px solid white; box-shadow:0 3px 8px rgba(0,0,0,.24); }
.custom-waypoint-marker span { display:block; transform:rotate(45deg); text-align:center; line-height:18px; font-size:10px; font-weight:900; color:#493300; }
.distance-ok { color:#1d7a4a; font-weight:800; }

/* v4 · desktop sidebar scroll + clearer API status */
.sidebar { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }
.panels {
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: scroll;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}
.panels::-webkit-scrollbar { width: 10px; }
.panels::-webkit-scrollbar-track { background: #f6f8f6; }
.panels::-webkit-scrollbar-thumb { background: #c8d3cc; border: 2px solid #f6f8f6; border-radius: 999px; }
.panels::-webkit-scrollbar-thumb:hover { background: #aebdb3; }
.panel { min-height: min-content; padding-bottom: 44px; }
.api-state.secondary { margin-top: 6px; }
.api-refresh-btn { margin: 10px 0 8px; padding: 9px 12px; }
@media (max-width: 900px) {
  .sidebar { height: auto; min-height: 0; }
  .panels { overflow-y: auto; }
}

/* v5 · persistent sidebar scroller + route guidance */
.panels-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}
.panels {
  height: 100%;
  min-height: 0;
  overflow-y: auto !important;
  overflow-x: hidden;
  padding-right: 10px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.panels::-webkit-scrollbar { display: none; width: 0; height: 0; }
.sidebar-scroll-rail {
  position: absolute;
  z-index: 15;
  top: 8px;
  right: 5px;
  bottom: 8px;
  width: 7px;
  border-radius: 999px;
  background: #e7ece8;
  box-shadow: inset 0 0 0 1px rgba(35, 72, 49, .04);
  cursor: pointer;
}
.sidebar-scroll-thumb {
  position: absolute;
  top: 0;
  left: 0;
  width: 7px;
  min-height: 44px;
  border-radius: 999px;
  background: #8fa99a;
  box-shadow: 0 1px 4px rgba(28, 73, 46, .18);
  cursor: grab;
  touch-action: none;
}
.sidebar-scroll-thumb:active { cursor: grabbing; background: #658674; }
.sidebar-scroll-rail.is-disabled { opacity: .25; pointer-events: none; }

.route-legend {
  position: absolute;
  z-index: 820;
  top: 58px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid rgba(28, 64, 43, .10);
  border-radius: 12px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 6px 20px rgba(32,58,42,.10);
  color: #4f5d54;
  font-size: 10px;
  backdrop-filter: blur(8px);
}
.route-legend b { font-weight: 800; }
.legend-start, .legend-finish {
  width: 19px;
  height: 19px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  font-size: 9px;
  font-weight: 900;
  color: white;
}
.legend-start { background: #167346; }
.legend-finish { background: #d65743; }
.legend-arrow { color: #167346; font-size: 16px; line-height: 1; }

.route-point-marker {
  min-width: 42px;
  height: 28px;
  padding: 0 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid white;
  border-radius: 999px;
  color: #fff;
  font-size: 10px;
  font-weight: 900;
  white-space: nowrap;
  box-shadow: 0 4px 13px rgba(0,0,0,.25);
}
.route-point-marker.start { background: #167346; }
.route-point-marker.finish { background: #d65743; }
.route-point-marker.loop { min-width: 62px; background: #167346; }
.route-direction-arrow {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255,255,255,.94);
  border: 2px solid #167346;
  color: #167346;
  font-size: 17px;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(22,115,70,.25);
  transform-origin: center;
}

@media (max-width: 900px) {
  .panels-wrap { min-height: 0; }
  .panels { height: 100%; padding-right: 10px; overflow-y: auto !important; }
  .sidebar-scroll-rail { right: 4px; }
  .route-legend { top: 50px; left: 10px; }
}

/* v6: 동일경로 왕복 반환점 표시 */
.legend-turn {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #f3a536;
  color: #fff;
  font-weight: 900;
  font-size: 13px;
}
.route-point-marker.turn {
  background: #f3a536;
  color: #fff;
  border-color: #fff;
  min-width: 58px;
}
#routeType button { font-size: 13px; }

/* v7: neutral public-facing footer */
.sidebar-footer { justify-content: flex-end; }
