:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --ink: #14171c;
  --ink-2: #4a5160;
  --ink-3: #7b8394;
  --line: #e2e5ea;
  --accent: #0039a6;
  --accent-ink: #ffffff;
  --accent-soft: #e8eefb;
  --good: #0a7d43;
  --good-soft: #e3f5ea;
  --ai: #6b3fd4;
  --ai-soft: #f0eafc;
  --warn: #a15c00;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #171b22;
    --surface-2: #1e232c;
    --ink: #eef0f4;
    --ink-2: #b4bac6;
    --ink-3: #8a91a0;
    --line: #2a303b;
    --accent: #6f9bff;
    --accent-ink: #0b1020;
    --accent-soft: #1b2740;
    --good: #4cc98a;
    --good-soft: #15301f;
    --ai: #b79bff;
    --ai-soft: #251d3d;
    --warn: #f0b35a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }

.app { display: grid; grid-template-columns: minmax(360px, 440px) 1fr; height: 100vh; height: 100dvh; }
.panel { overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; border-right: 1px solid var(--line); }
.map-wrap { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: var(--surface-2); }

.brand { display: flex; align-items: center; gap: 12px; padding: 4px 2px 2px; }
.brand h1 { font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.brand p { color: var(--ink-2); font-size: 13px; }
.logo {
  width: 38px; height: 38px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: #0039a6; color: #fff; font-weight: 700; font-size: 20px;
}

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.section-label { display: block; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 8px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; }
.hint { color: var(--ink-3); font-size: 12.5px; }
.hint:empty { display: none; }
.link { border: 0; background: none; color: var(--accent); padding: 0; font-size: 12.5px; }
.link:hover { text-decoration: underline; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 9px; padding: 8px 14px; font-weight: 600; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .55; cursor: default; filter: none; }
.btn.ai-btn { color: var(--ai); border-color: color-mix(in srgb, var(--ai) 35%, var(--line)); background: var(--ai-soft); }

input[type=search], input[type=date], input[type=time], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 9px; padding: 8px 10px; outline: none;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
textarea { resize: vertical; min-height: 54px; }

/* AI box */
.ai { border-color: color-mix(in srgb, var(--ai) 30%, var(--line)); }
.ai .section-label { color: var(--ai); }
.ai-row { display: flex; gap: 8px; align-items: stretch; }
.ai-row .btn { align-self: stretch; }
.examples { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.examples button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--ink-2); text-align: left; }
.examples button:hover { border-color: var(--ai); color: var(--ai); }
.ai .hint { margin-top: 8px; }
.ai.off textarea, .ai.off .examples button { opacity: .6; }
.hint.error { color: #c0392b; }
code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 0 4px; font-size: 12px; }

/* Trip list */
.trip { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; }
.trip:empty { display: none; }
.trip li { display: flex; align-items: center; gap: 10px; padding: 7px 0; position: relative; }
.trip li + li::before { content: ""; position: absolute; left: 11px; top: -9px; height: 18px; border-left: 2px dotted var(--ink-3); }
.num { width: 24px; height: 24px; flex: none; border-radius: 50%; background: var(--ink); color: var(--surface); display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.trip .name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trip .sub { display: block; font-weight: 400; color: var(--ink-3); font-size: 12px; }
.icon-btn { border: 0; background: none; color: var(--ink-3); width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center; font-size: 15px; line-height: 1; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

.add-stop { width: 100%; color: var(--accent); }
.picker[hidden] { display: none; }
.picker { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0; scrollbar-width: none; }
.chips button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 11px; font-size: 12.5px; white-space: nowrap; color: var(--ink-2); }
.chips button[aria-selected=true] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.places { list-style: none; margin: 0; padding: 0; max-height: 216px; overflow-y: auto; border: 1px solid var(--line); border-radius: 9px; }
.places li button { width: 100%; display: flex; justify-content: space-between; gap: 10px; align-items: center; border: 0; background: none; padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); }
.places li:last-child button { border-bottom: 0; }
.places li button:hover { background: var(--accent-soft); }
.places .pname { font-weight: 600; }
.places .parea { color: var(--ink-3); font-size: 12px; white-space: nowrap; }
.places .add { color: var(--accent); font-weight: 700; font-size: 12px; flex: none; }
.places .empty { padding: 12px; color: var(--ink-3); }

/* Controls */
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: none; padding: 5px 11px; border-radius: 7px; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.seg button[aria-checked=true] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.when-inputs { display: flex; gap: 6px; flex: 1; min-width: 220px; }
.prefs { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.prefs summary { cursor: pointer; font-weight: 600; color: var(--ink-2); list-style-position: inside; }
.prefs summary span { font-weight: 400; color: var(--ink-3); font-size: 12.5px; margin-left: 4px; }
.pref { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.pref > span, .pref > label { color: var(--ink-2); font-size: 13px; }
.pref select { width: auto; }
.slider { display: flex; align-items: center; gap: 8px; }
.slider output { min-width: 52px; text-align: right; font-variant-numeric: tabular-nums; }
.check { display: flex; gap: 8px; align-items: center; margin-top: 12px; color: var(--ink-2); font-size: 13px; }

/* Results */
#results { display: flex; flex-direction: column; gap: 12px; }
.leg-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 6px 2px 0; }
.leg-head h2 { font-size: 15px; font-weight: 700; }
.leg-head h2 .arrow { color: var(--ink-3); font-weight: 400; margin: 0 4px; }
.leg-head .after { color: var(--ink-3); font-size: 12.5px; white-space: nowrap; }
.stay-note { text-align: center; color: var(--ink-3); font-size: 12.5px; }

.opt { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.opt.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.opt-main { width: 100%; text-align: left; border: 0; background: none; padding: 12px 14px; display: block; }
.opt:not(.selected) .opt-main:hover { background: var(--surface-2); }
.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }
.tags:empty { display: none; }
.tag { font-size: 11px; font-weight: 700; letter-spacing: .02em; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.tag.best { background: var(--good-soft); color: var(--good); border-color: transparent; }
.tag.ai { background: var(--ai-soft); color: var(--ai); border-color: transparent; }
.opt-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.times { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.times .arrow { color: var(--ink-3); font-weight: 400; margin: 0 3px; }
.dur { font-weight: 700; white-space: nowrap; }
.dur small { display: block; font-weight: 400; color: var(--ink-3); text-align: right; font-size: 12px; }
.chain { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-top: 8px; color: var(--ink-3); font-size: 12.5px; }
.chain .sep { opacity: .6; }
.walk-chip { display: inline-flex; align-items: center; gap: 3px; }
.walk-chip svg { width: 13px; height: 13px; }
.bullet { display: inline-grid; place-items: center; min-width: 22px; height: 22px; border-radius: 50%; font-weight: 700; font-size: 12.5px; padding: 0 3px; line-height: 1; }
.bus { display: inline-block; border-radius: 5px; font-weight: 700; font-size: 12px; padding: 3px 6px; line-height: 1.1; white-space: nowrap; }

.stops { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin-top: 10px; font-size: 13px; }
.stops dt { color: var(--ink-3); font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding-top: 2px; }
.stops dd { margin: 0; min-width: 0; }
.stops dd b { font-weight: 600; }
.stops dd span { color: var(--ink-2); }

.ai-reason { margin: 0 14px 12px; padding: 9px 11px; border-radius: 9px; background: var(--ai-soft); color: var(--ink); font-size: 13px; }
.ai-reason b { color: var(--ai); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; display: block; margin-bottom: 2px; }

.steps { list-style: none; margin: 0; padding: 4px 14px 12px; border-top: 1px solid var(--line); }
.steps li { display: grid; grid-template-columns: 64px 22px 1fr; gap: 8px; padding: 8px 0 0; align-items: start; }
.steps .t { color: var(--ink-2); font-variant-numeric: tabular-nums; font-size: 12.5px; text-align: right; padding-top: 1px; white-space: nowrap; }
.steps .dot { display: grid; place-items: center; color: var(--ink-3); padding-top: 1px; }
.steps .dot svg { width: 15px; height: 15px; }
.steps .what { min-width: 0; }
.steps .what b { font-weight: 600; }
.steps .what small { display: block; color: var(--ink-3); font-size: 12.5px; }
.steps .what .later { color: var(--good); }

.banner { border-radius: var(--radius); padding: 12px 14px; font-size: 13.5px; border: 1px solid var(--line); background: var(--surface); }
.banner.ai { background: var(--ai-soft); border-color: transparent; }
.banner.ai b { display: block; color: var(--ai); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 3px; }
.banner.warn { color: var(--warn); }
.summary-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.summary-bar .total { color: var(--ink-2); font-size: 13px; }
.summary-bar .total b { color: var(--ink); }
.skeleton { height: 96px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: sh 1.1s linear infinite; border: 1px solid var(--line); }
@keyframes sh { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

.foot { color: var(--ink-3); font-size: 11.5px; padding: 4px 2px 12px; }

/* Map */
.leaflet-container { font: inherit; }
.basemap { filter: saturate(.55) contrast(.95) brightness(1.03); }
@media (prefers-color-scheme: dark) {
  .basemap { filter: invert(1) hue-rotate(180deg) saturate(.45) brightness(.9) contrast(.9); }
}
.pin { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: #14171c; color: #fff; font-weight: 700; font-size: 12.5px; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .45); }
.stop-label { background: #fff; color: #14171c; border-radius: 6px; padding: 2px 7px; font-size: 11.5px; font-weight: 700; white-space: nowrap; box-shadow: 0 1px 4px rgba(0, 0, 0, .35); border: 1px solid rgba(0, 0, 0, .15); transform: translate(-50%, -150%); display: inline-block; }
.stop-label i { font-style: normal; color: #0a7d43; margin-right: 4px; text-transform: uppercase; font-size: 10px; letter-spacing: .05em; }
.stop-label.exit i { color: #b3261e; }
.leaflet-tooltip.place-tip { font-weight: 600; }
.leaflet-popup-content { margin: 10px 12px; }
.leaflet-popup-content button { margin-top: 6px; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 38vh auto; height: auto; }
  .map-wrap { grid-row: 1; height: 38vh; position: sticky; top: 0; z-index: 500; }
  .panel { grid-row: 2; border-right: 0; overflow: visible; }
}

.brand-text { flex: 1; min-width: 0; }
.nav-link { color: var(--accent); font-size: 12.5px; text-decoration: none; white-space: nowrap; }
.nav-link:hover { text-decoration: underline; }
