:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #1d1d1b;
  --muted: #6b6963;
  --line: #e2dfd8;
  --accent: #2f6f9f;
  --accent-ink: #ffffff;
  --good: #2e7d4f;
  --warn: #b26a00;
  --bad: #b3261e;
  --pin: #2f6f9f;
  --pin-muted: #b9b6ae;
  --radius: 8px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15161a; --panel: #1e2026; --ink: #ebe9e3; --muted: #a09d95; --line: #2f323a;
    --accent: #6ea8d6; --accent-ink: #0e1116; --pin-muted: #5a5d66;
  }
}
:root[data-theme="dark"] {
  --bg: #15161a; --panel: #1e2026; --ink: #ebe9e3; --muted: #a09d95; --line: #2f323a;
  --accent: #6ea8d6; --accent-ink: #0e1116; --pin-muted: #5a5d66;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.45 var(--sans); color: var(--ink); background: var(--bg); }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.app { display: grid; grid-template-columns: minmax(340px, 440px) 1fr; height: 100%; }
.panel { overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; min-width: 0; touch-action: pan-y; background: var(--panel); border-right: 1px solid var(--line); padding: 16px; }
.panel > * { max-width: 100%; }
body { overflow-x: hidden; }
.map { min-height: 300px; }
#map { width: 100%; height: 100%; }

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 45vh 1fr; }
  .map { order: -1; }
  .panel { border-right: 0; border-top: 1px solid var(--line); }
}

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.brand .logo { width: 36px; height: 36px; flex: 0 0 auto; border-radius: 8px; }
h1 { font-size: 20px; margin: 0 0 2px; }
.tagline { color: var(--muted); margin: 0; font-size: 13px; font-style: italic; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 8px; }

.field { margin-bottom: 10px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 3px; }
.field input[type="text"], .field input[type="url"], .field input[type="datetime-local"],
.field input[type="number"], .field select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg);
}
.row { display: flex; gap: 8px; align-items: end; }
.row > .field { flex: 1; margin-bottom: 0; }
.row.tight { align-items: center; }
/* Inputs inside a button row must be allowed to shrink; iOS date inputs
   otherwise keep their intrinsic width and run off the right edge. */
.row.tight > input { flex: 1 1 0; min-width: 0; width: auto; max-width: 100%; }
.row.tight > .btn { flex: 0 0 auto; }
/* A full-width primary button inside a row shares the row instead of forcing
   the row wider than the panel (which scrollIntoView could then scroll). */
.row.tight > .btn.primary { flex: 1 1 auto; width: auto; min-width: 0; }
/* Icon buttons beside a text box match its height. */
.row.tight > .btn.icon { align-self: stretch; display: inline-flex; align-items: center; justify-content: center; min-width: 38px; padding: 0 10px; }
/* Small number boxes inside toggle labels use the same field styling. */
.toggle input[type="number"] { width: 60px; padding: 6px 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
.inline { display: inline-flex; gap: 6px; align-items: center; }

.btn { padding: 8px 12px; border: 1px solid var(--line); background: var(--bg); border-radius: var(--radius); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; width: 100%; padding: 10px; }
.btn.small { padding: 4px 8px; font-size: 13px; }
.btn.icon { padding: 8px; line-height: 1; }
.btn:disabled { opacity: .5; cursor: default; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.tabs button { background: none; border: 0; padding: 6px 10px; border-bottom: 2px solid transparent; color: var(--muted); }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tab { display: none; }
.tab.active { display: block; }

.suggest { position: relative; }
.suggest ul {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 20; margin: 0; padding: 4px 0; list-style: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0,0,0,.12);
  max-height: 240px; overflow-y: auto;
}
.suggest li { padding: 6px 10px; cursor: pointer; font-size: 14px; }
.suggest li:hover, .suggest li[aria-selected="true"] { background: var(--bg); }
.suggest li .kind { color: var(--muted); font-size: 12px; margin-left: 6px; }

.waypoints .row { margin-bottom: 6px; }
.waypoints input.dwell { width: 64px; flex: 0 0 auto; padding: 8px 6px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
.waypoints .unit { font-size: 12.5px; color: var(--muted); flex: 0 0 auto; }
.waypoints .btn.move { min-width: 30px; padding: 0 6px; }
.waypoints .btn.move:disabled { opacity: .3; }
.duration input[type="number"] { width: 72px; flex: 0 0 auto; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
.duration span { color: var(--muted); font-size: 13px; }

.hint { font-size: 12.5px; color: var(--muted); margin: 4px 0 0; }
.warn { color: var(--warn); }
.err { color: var(--bad); }
.hint.err { font-size: 13.5px; font-weight: 600; margin-top: 6px; }
.hint.info { margin: 6px 0 10px; padding: 6px 8px; background: var(--bg); border-radius: var(--radius); }
h2 + .hint.info { margin-top: 0; }
.info-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px;
  margin-left: 6px; padding: 0; border: 1px solid var(--muted); border-radius: 50%; background: none;
  color: var(--muted); font: italic 700 10px/1 Georgia, serif; vertical-align: middle; cursor: pointer;
}
.info-btn[aria-expanded="true"] { background: var(--muted); color: var(--panel); }
.spinner {
  display: inline-block; width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; vertical-align: middle; animation: spin .8s linear infinite;
}
.btn.primary .spinner { border-color: rgba(255,255,255,.35); border-top-color: var(--accent-ink); }
@keyframes spin { to { transform: rotate(360deg); } }
.route-summary { font-size: 13px; margin: 8px 0 0; padding: 8px 10px; background: var(--bg); border-radius: var(--radius); }
.itinerary { list-style: none; margin: 0 0 8px; padding: 4px 10px 6px; background: var(--bg); border-radius: 0 0 var(--radius) var(--radius); font-size: 12.5px; }
.route-summary:not([hidden]) + .itinerary { border-top: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); }
.itinerary li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 3px 0; align-items: baseline; }
.itinerary .place { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.itinerary .times { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.itinerary .times b { color: var(--ink); font-weight: 600; }
.itinerary .times .tz { margin-left: 5px; padding: 0 5px; border: 1px solid var(--line); border-radius: 999px; font-size: 11px; color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border: 1px solid var(--line); border-radius: 999px; font-size: 13px; cursor: pointer; background: var(--bg); }
.chip input { margin: 0; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip .n { opacity: .7; font-size: 12px; }
details.more summary { cursor: pointer; color: var(--muted); font-size: 13px; margin: 6px 0; }

.filters .row { margin-bottom: 8px; }
.filters .field label { font-size: 12.5px; }
.toggle { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 14px; }

.status { font-size: 13px; color: var(--muted); min-height: 18px; margin: 8px 0; }
.share-url { width: 100%; margin-top: 6px; padding: 6px 8px; font-size: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
.status.err { color: var(--bad); }

.summary { font-size: 13px; color: var(--muted); margin-bottom: 8px; }

.results { list-style: none; margin: 0; padding: 0; }
.result { padding: 10px 8px; border-top: 1px solid var(--line); cursor: pointer; }
.result:hover, .result.selected { background: var(--bg); }
.result.miss { opacity: .6; }
.result .name { font-weight: 600; }
.result .where { color: var(--muted); font-size: 13px; }
.result .numbers { display: flex; gap: 12px; margin-top: 4px; font-size: 14px; }
.num { font-variant-numeric: tabular-nums; }
.num.good { color: var(--good); } .num.warn { color: var(--warn); } .num.bad { color: var(--bad); }
.result .flags { font-size: 12px; color: var(--warn); margin-top: 3px; }
.result .links { font-size: 12.5px; margin-top: 5px; display: flex; gap: 10px; flex-wrap: wrap; }
.result.miss .links { display: none; }
.result.selected .links { display: flex; }

.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.dot.on { background: var(--pin); } .dot.off { background: var(--pin-muted); }

.pin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.35); }
.pin.on { background: var(--pin); }
.pin.off { background: var(--pin-muted); }
.pin.sel { transform: scale(1.5); }

.leaflet-popup-content { font: 13px/1.4 var(--sans); }
.leaflet-popup-content .name { font-weight: 600; font-size: 14px; }

footer { margin-top: 18px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; }
footer p { margin: 4px 0; }
