:root {
  --bg: #f6f3ec;
  --panel: #fffdf8;
  --ink: #14213d;
  --muted: #5d6475;
  --line: #e4ded1;
  --accent: #b5121b;
  --accent-ink: #fff;
  --chip: #f0ebe0;
  --shadow: 0 10px 30px rgba(20, 33, 61, 0.16);
  --radius: 14px;
  color-scheme: light;
}
:root[data-theme='night'] {
  --bg: #0f1424;
  --panel: #161c30;
  --ink: #eef0f7;
  --muted: #9aa2b8;
  --line: #2a3250;
  --accent: #ff5a4e;
  --accent-ink: #160d0c;
  --chip: #212944;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.45 Inter, system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}
#map { position: fixed; inset: 0; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- panel (left column on desktop, bottom sheet on phones) ---------- */
.panel {
  position: fixed;
  top: 16px;
  left: 16px;
  bottom: 16px;
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 16px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 2;
}
.grab { display: none; }
.eyebrow { margin: 0; font-size: 11.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
h1 { margin: 2px 0 0; font-size: 26px; letter-spacing: -0.02em; }
h2 { margin: 0; font-size: 18px; }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}
.search:focus-within { border-color: var(--ink); }
.search svg { width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; flex: none; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; padding: 11px 0; }

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 2px; flex: none; }
.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--chip);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.chip[aria-pressed='true'] { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.chip .dot { width: 20px; height: 20px; font-size: 10px; border-width: 1px; box-shadow: none; }

.list { list-style: none; margin: 0 -8px; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
.list li button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.list li button:hover, .list li button:focus-visible { background: var(--chip); outline: none; }
.list .name { font-weight: 600; }
.list .sub { display: block; font-size: 12.5px; color: var(--muted); }
.list .empty { padding: 16px 8px; color: var(--muted); }

.dot {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  border: 2px solid var(--panel);
  box-shadow: 0 0 0 1px var(--line);
}

.card { display: flex; flex-direction: column; gap: 12px; }
.card[hidden] { display: none; }
.card-title { display: flex; gap: 12px; align-items: center; }
.card-title .dot { width: 40px; height: 40px; font-size: 18px; }
.card-title p { margin: 0; font-size: 13px; }
.note { margin: 0; padding: 10px 12px; background: var(--chip); border-radius: 10px; font-size: 13.5px; }
.route-box { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
.route-box select { padding: 9px 10px; border: 1.5px solid var(--line); border-radius: 9px; background: var(--bg); }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.route-msg { margin: 0; font-size: 14px; }
.route-msg strong { font-size: 20px; }
.route-msg:empty { display: none; }

/* ---------- turn-by-turn directions ---------- */
#nav-start { display: flex; align-items: center; justify-content: center; gap: 6px; }
#nav-start svg { width: 16px; height: 16px; fill: currentColor; }
.steps { list-style: none; margin: 4px 0 0; padding: 0; border-top: 1px solid var(--line); }
.steps li + li { border-top: 1px solid var(--line); }
.steps button {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 4px;
  border: 0;
  background: none;
  text-align: left;
  font-size: 13.5px;
  cursor: pointer;
}
.steps button:hover { background: var(--chip); }
.steps button.current { background: var(--chip); font-weight: 600; box-shadow: inset 3px 0 0 #0369a1; }
.step-icon { display: inline-grid; place-items: center; width: 26px; height: 26px; color: #0369a1; }
.step-icon svg { width: 22px; height: 22px; fill: currentColor; }
.step-dist { color: var(--muted); font-size: 12.5px; white-space: nowrap; }

.nav {
  position: fixed;
  top: 16px;
  left: 400px;
  width: min(520px, calc(100vw - 496px));
  z-index: 3;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: var(--panel);
}
.nav-now { display: flex; gap: 14px; align-items: center; padding: 14px 16px; background: #075985; color: #fff; }
.nav-icon { flex: none; display: grid; place-items: center; width: 48px; height: 48px; }
.nav-icon svg { width: 44px; height: 44px; fill: #fff; color: #fff; }
.nav-icon svg [fill='var(--panel)'] { fill: #075985; }
.nav-dist { font-size: 22px; font-weight: 700; line-height: 1.15; }
.nav-text { font-size: 16px; line-height: 1.3; }
.nav-then { display: flex; align-items: center; gap: 6px; padding: 6px 16px; background: #0c4a6e; color: #e0f2fe; font-size: 13.5px; }
.nav-then[hidden] { display: none; }
.nav-then .step-icon { color: #e0f2fe; width: 20px; height: 20px; }
.nav-then .step-icon svg { width: 18px; height: 18px; }
.nav-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 16px; font-size: 14px; }
.nav-foot .btn { padding: 6px 16px; }

.btn {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1.5px solid var(--ink);
  background: transparent;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.link { border: 0; background: none; padding: 0; cursor: pointer; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.back { align-self: flex-start; text-decoration: none; color: var(--muted); }
.panel-foot { display: flex; justify-content: space-between; gap: 8px; padding-top: 8px; border-top: 1px solid var(--line); flex: none; }

/* ---------- path editor (?edit) ---------- */
.editor { display: flex; flex-direction: column; gap: 10px; min-height: 0; flex: 1; overflow-y: auto; overflow-x: hidden; }
.editor > * { flex: none; }
.editor[hidden] { display: none; }
.editor p { margin: 0; }
.editor code { font-size: 12px; background: var(--chip); padding: 1px 5px; border-radius: 5px; }
.editor .list { margin: 0; overflow: visible; }
.editor .list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px; border-radius: 8px; }
.editor .list li:hover { background: var(--chip); }
.editor .list .del { border: 0; background: none; color: var(--accent); cursor: pointer; font-weight: 600; }
.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1.5px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { padding: 9px; border: 0; background: transparent; font-weight: 600; cursor: pointer; }
.seg button[aria-pressed='true'] { background: var(--ink); color: var(--panel); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
body.editing .search, body.editing .chips, body.editing #list, body.editing #card, body.editing .pin { display: none !important; }
body.editing #map canvas { cursor: crosshair; }

/* ---------- floating buttons ---------- */
.fabs { position: fixed; right: 16px; bottom: 32px; display: flex; flex-direction: column; gap: 8px; z-index: 2; }
.fab {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.fab[aria-pressed='true'] { background: var(--ink); color: var(--panel); }
.fab svg { width: 20px; height: 20px; fill: currentColor; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.fab.on { color: #2f6bff; }

.toast {
  position: fixed;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--panel);
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 5;
}

/* ---------- map markers ---------- */
.pin {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: transform 0.15s;
}
.pin:hover { transform: scale(1.15); }
.pin.selected { transform: scale(1.35); box-shadow: 0 0 0 4px rgba(181, 18, 27, 0.35), 0 2px 6px rgba(0, 0, 0, 0.35); }
.pin.faded { opacity: 0.25; }

.maplibregl-ctrl-attrib { font-size: 11px; }

/* ---------- phones ---------- */
@media (max-width: 767px) {
  .nav { top: 10px; left: 10px; right: 10px; width: auto; }
  .nav-dist { font-size: 20px; }
  .nav-text { font-size: 15px; }
  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: 46svh;
    border-radius: 18px 18px 0 0;
    padding: 8px 16px calc(10px + env(safe-area-inset-bottom));
    transition: height 0.25s ease;
  }
  .panel.tall { height: 82svh; }
  .panel.short { height: 132px; }
  /* The whole top strip of the sheet is the handle: easy to hit, and drags don't scroll the page. */
  .grab { display: block; flex: none; width: calc(100% + 32px); height: 30px; margin: -8px -16px -6px; padding: 0; border: 0; background: none; cursor: grab; touch-action: none; }
  .grab span { display: block; width: 44px; height: 5px; margin: 10px auto 0; border-radius: 3px; background: var(--muted); opacity: 0.55; }
  .panel.dragging { transition: none; }
  .panel-head { display: none; }
  /* --sheet is the sheet's live height, set from app.js. */
  .fabs { bottom: calc(var(--sheet, 46svh) + 12px); right: 12px; }
  .panel.tall ~ .fabs { display: none; }
}
