:root {
  --bg: #f4f4f3;
  --surface: #ffffff;
  --surface-2: #f7f7f6;
  --ink: #141414;
  --ink-2: #3a3a3a;
  --muted: #767676;
  --line: #e6e6e4;
  --line-strong: #cfcfcc;
  --danger: #c92a2a;
  --range: #ebebe8;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .08), 0 1px 3px rgba(0, 0, 0, .06);
  --peek: 188px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

#map { position: fixed; inset: 0; background: #ececea; }

/* ------------------------------------------------------------------ top bar */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + var(--safe-t)) 16px 6px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand {
  margin: 0; font-size: 17px; font-weight: 750; letter-spacing: -.02em;
  background: var(--surface); padding: 8px 12px; border-radius: 999px; box-shadow: var(--shadow);
}
.brand span { font-weight: 400; color: var(--muted); margin-left: 2px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 999px; border: 0;
  background: var(--surface); box-shadow: var(--shadow);
  display: grid; place-items: center;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px; border-radius: 999px; font-weight: 600;
  border: 1px solid var(--line-strong); background: var(--surface);
  white-space: nowrap;
}
a.btn { color: var(--ink); text-decoration: none; }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); box-shadow: var(--shadow); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn-small { height: 32px; padding: 0 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
@media (max-width: 479px) {
  #btn-add { width: 40px; padding: 0; }
  #btn-add .btn-label { display: none; }
}

/* ------------------------------------------------------------------ filters */
.filter-menu {
  position: fixed; right: 16px; top: calc(62px + var(--safe-t)); z-index: 4;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
}
.filter-toggle {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 10px 0 12px;
  border: 0; border-radius: 999px; background: var(--surface); box-shadow: var(--shadow);
  font-size: 14px; font-weight: 600;
}
.filter-toggle svg { width: 16px; height: 16px; }
.filter-toggle .chev { color: var(--muted); transition: transform .2s; }
.filter-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }
.filter-count {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--ink); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}
.filters {
  width: 264px; max-width: calc(100vw - 32px);
  max-height: calc(100dvh - var(--peek) - var(--safe-b) - var(--safe-t) - var(--timeline-h) - 150px); overflow-y: auto;
  display: grid; gap: 14px; padding: 14px;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
}
.filter-title { display: block; margin-bottom: 8px; font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.filter-group .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.filter-select {
  width: 100%; height: 36px; padding: 0 10px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--surface); font-size: 14px; font-weight: 550;
}
.filter-reset { justify-self: start; }
.filter-group-sep { border-top: 1px solid var(--line); padding-top: 14px; }
.filter-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.filter-title-row .filter-title { margin: 0; text-transform: none; letter-spacing: 0; font-size: 13.5px; color: var(--ink); font-weight: 650; }
.filter-group-sep > * + * { margin-top: 10px; }
.filter-hint { margin: 8px 0 0; font-size: 12px; color: var(--muted); line-height: 1.35; }

.switch { position: relative; flex: none; width: 38px; height: 22px; }
.switch input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 11px; background: var(--line-strong); transition: background .2s; }
.switch span::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .2s;
}
.switch input:checked + span { background: var(--ink); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }

.theme-switch { display: flex; gap: 3px; padding: 3px; border-radius: 10px; background: var(--surface-2); }
.theme-switch button {
  flex: 1; height: 30px; padding: 0 4px; border: 0; border-radius: 8px; background: transparent;
  font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.theme-switch button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.legend { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.legend-bar { flex: 1; height: 8px; border-radius: 4px; box-shadow: inset 0 0 0 1px var(--line); }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 13px; font-weight: 550; color: var(--ink-2);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
}
.chip[aria-pressed="false"] { color: var(--muted); background: rgba(255, 255, 255, .7); }
.chip[aria-pressed="false"] .swatch, .chip[aria-pressed="false"] .dash { opacity: .3; }
.swatch { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dash { width: 22px; height: 6px; flex: none; }

/* ------------------------------------------------------------------ bottom sheet */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  height: min(86dvh, 760px);
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -6px 30px rgba(0, 0, 0, .10);
  display: flex; flex-direction: column;
  transform: translateY(calc(100% - var(--peek) - var(--safe-b)));
  transition: transform .28s cubic-bezier(.2, .8, .2, 1);
  touch-action: pan-y;
}
.sheet[data-state="open"] { transform: translateY(0); }
.sheet.dragging { transition: none; }
.sheet-handle {
  flex: none; border: 0; background: none; padding: 10px 0 4px; width: 100%;
  display: grid; place-items: center; touch-action: none;
}
.sheet-handle span { width: 40px; height: 5px; border-radius: 3px; background: var(--line-strong); }
.tabs { flex: none; display: flex; gap: 4px; padding: 4px 16px 10px; }
.tabs button {
  flex: 1; height: 36px; border: 0; border-radius: 10px; background: var(--surface-2);
  font-weight: 600; color: var(--muted);
}
.tabs button[aria-selected="true"] { background: var(--ink); color: #fff; }
.tabs .count { font-weight: 500; opacity: .7; }
.tabs .sheet-collapse {
  display: none; flex: none; width: 36px; height: 36px; border: 0; border-radius: 10px;
  background: transparent; color: var(--muted); place-items: center;
}
.tabs .sheet-collapse:hover { color: var(--ink); background: var(--surface-2); }
.sheet-collapse svg { transition: transform .2s; }
.sheet-body { flex: 1; overflow-y: auto; padding: 0 16px calc(24px + var(--safe-b)); -webkit-overflow-scrolling: touch; }

/* Keep map attribution above the peeking sheet and the timeline. */
:root { --timeline-h: 78px; }
.maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { bottom: calc(var(--peek) + var(--safe-b) + var(--timeline-h) + 8px); }

/* ------------------------------------------------------------------ timeline */
.timeline {
  position: fixed; z-index: 5; left: 16px; right: 16px;
  bottom: calc(var(--peek) + var(--safe-b) + 10px);
  padding: 8px 18px 6px;
  display: flex; align-items: center; gap: 14px;
  /* No box: the map shows through, and only the controls take clicks. */
  pointer-events: none;
}
.tl-inner { position: relative; flex: 1; min-width: 0; padding-top: 20px; }
.tl-play {
  pointer-events: auto; flex: none; width: 40px; height: 40px; margin-top: 4px; border: 0; border-radius: 50%;
  display: grid; place-items: center; background: var(--ink); color: #fff; box-shadow: var(--shadow);
}
.tl-play svg { width: 16px; height: 16px; }
.tl-play svg path { fill: currentColor; }
.timeline.playing .tl-play svg path { fill: none; stroke-width: 3; }
.tl-bubble {
  position: absolute; top: 0; white-space: nowrap;
  font-size: 12px; font-weight: 650; font-variant-numeric: tabular-nums;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 6px #fff;
}
.tl-track { position: relative; height: 28px; touch-action: none; cursor: pointer; outline: none; pointer-events: auto; }
.tl-track::before {
  content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 4px; margin-top: -2px;
  border-radius: 2px; background: rgba(255, 255, 255, .85); box-shadow: 0 0 0 1px rgba(0, 0, 0, .12), 0 1px 3px rgba(0, 0, 0, .15);
}
.tl-ticks { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
/* Trip periods: the same size and colour in every timeline mode. */
.tl-tick { position: absolute; top: 50%; height: 16px; margin-top: -8px; min-width: 3px; border-radius: 2px; opacity: .9; box-shadow: 0 0 0 1px rgba(255, 255, 255, .8); }
.tl-range { position: absolute; top: 50%; height: 4px; margin-top: -2px; border-radius: 2px; pointer-events: none; background: rgba(20, 20, 20, .35); }
/* The "tail": fades in towards the handle. */
.timeline[data-mode="window"] .tl-range { height: 6px; margin-top: -3px; background: linear-gradient(to right, rgba(20, 20, 20, 0), var(--ink)); }
.tl-handle {
  position: absolute; z-index: 2; top: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--ink); box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
  pointer-events: none; transition: transform .12s;
}
.timeline.dragging .tl-handle, .tl-track:focus-visible .tl-handle { transform: scale(1.18); }
/* "Show all": no handle, just highlighted travel periods (tap one to select the trip). */
.tl-legend { display: flex; position: absolute; transition: opacity .15s; top: 0; left: 0; gap: 12px; font-size: 12px; font-weight: 650;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 6px #fff; }
.tl-legend span { display: inline-flex; align-items: center; gap: 5px; }
.tl-legend i { width: 10px; height: 10px; border-radius: 3px; box-shadow: 0 0 0 1px rgba(255, 255, 255, .8); }
/* Fades out while the date label above the handle would overlap it. */
.tl-legend.tl-legend-hidden { opacity: 0; }
.timeline[data-mode="all"] .tl-bubble,
.timeline[data-mode="all"] .tl-range,
.timeline[data-mode="all"] .tl-handle { display: none; }
.timeline[data-mode="all"] .tl-track { cursor: default; }
.timeline[data-mode="all"] .tl-ticks { pointer-events: auto; }
.timeline[data-mode="all"] .tl-tick { cursor: pointer; }
.timeline[data-mode="all"] .tl-tick:hover { opacity: 1; transform: scaleY(1.2); }

/* Year filter: tick one or more years. */
.year-checks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 10px; }
.year-checks .check { font-size: 13.5px; font-variant-numeric: tabular-nums; }
.year-checks .year-all { grid-column: 1 / -1; }
.tl-labels {
  display: flex; justify-content: space-between; font-size: 11px; font-weight: 600; color: var(--ink-2);
  font-variant-numeric: tabular-nums; text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 6px #fff;
}

/* ------------------------------------------------------------------ stats */
.hero { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 2px 2px 14px; }
.hero-num { font-size: 44px; font-weight: 750; letter-spacing: -.04em; line-height: 1; font-variant-numeric: tabular-nums; }
.hero-label { color: var(--muted); font-size: 14px; }
.hero-label strong { color: var(--ink); font-weight: 650; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tile { background: var(--surface-2); border-radius: 12px; padding: 12px; min-width: 0; }
.tile-num { font-size: 24px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile-num small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.tile-label { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.tile-wide { grid-column: 1 / -1; }

.section-title { margin: 22px 2px 10px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 90px 1fr auto; align-items: center; gap: 10px; font-size: 13.5px; }
.bar-row .name { display: flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--ink); border-radius: 4px; min-width: 2px; }
.bar-row .val { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.stat-list { display: grid; }
.stat-row {
  display: grid; grid-template-columns: 1fr auto 64px; align-items: center; gap: 12px;
  padding: 8px 2px; font-size: 13.5px; border-bottom: 1px solid var(--line);
}
.stat-row:last-child { border-bottom: 0; }
.stat-row-2 { grid-template-columns: 1fr auto; }
.stat-row .name small { color: var(--muted); font-size: 12px; margin-left: 2px; }
.stat-row .name { display: flex; align-items: center; gap: 8px; }
.stat-row .val { font-variant-numeric: tabular-nums; text-align: right; }
.stat-row .val:last-child { color: var(--muted); }
.empty { color: var(--muted); padding: 24px 4px; text-align: center; }
.empty .btn { margin-top: 12px; }

/* ------------------------------------------------------------------ trips list */
.trip-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.trip-card {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  display: grid; grid-template-columns: 4px 1fr; gap: 12px; background: var(--surface);
  cursor: pointer;
}
.trip-card.selected { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.trip-card .stripe { border-radius: 2px; }
.trip-card h3 { margin: 0; font-size: 15.5px; font-weight: 650; }
.trip-meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.trip-people { display: flex; align-items: center; gap: 5px; margin-top: 3px; font-size: 13px; font-weight: 550; color: var(--ink-2); }
.trip-people .part { font-weight: 450; color: var(--muted); }
.leg-more-body { display: grid; gap: 10px; }
.trip-people svg { width: 14px; height: 14px; color: var(--muted); }
.trip-route { font-size: 13px; color: var(--ink-2); margin-top: 6px; line-height: 1.5; }
.stay-days {
  display: inline-block; font-size: 11px; font-weight: 700; color: var(--ink-2);
  background: var(--surface-2); padding: 0 5px; border-radius: 5px; line-height: 17px;
}
.trip-route .arrow { color: var(--muted); margin: 0 3px; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.tag { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.trip-actions { display: flex; gap: 4px; margin-top: 8px; margin-left: -12px; }
.year-head { margin: 18px 2px 8px; font-size: 13px; font-weight: 700; color: var(--muted); }
.trip-order { margin-bottom: 14px; }
.trip-order + .year-head { margin-top: 0; }
.year-head:first-child { margin-top: 0; }

/* ------------------------------------------------------------------ dialogs */
.dialog {
  border: 0; padding: 0; background: var(--surface); color: var(--ink);
  width: 100%; max-width: 100%; height: 100%; max-height: 100%; margin: 0;
}
.dialog::backdrop { background: rgba(20, 20, 20, .35); }
.dialog-small { height: auto; margin: auto; width: calc(100% - 32px); max-width: 420px; border-radius: 18px; }
.dialog form { display: flex; flex-direction: column; height: 100%; }
.dialog-head {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(12px + var(--safe-t)) 16px 12px; border-bottom: 1px solid var(--line);
}
.dialog-small .dialog-head { padding-top: 14px; }
.dialog-head h2 { margin: 0; font-size: 17px; }
.dialog-body { flex: 1; overflow-y: auto; padding: 16px; display: grid; gap: 14px; align-content: start; }
.dialog-foot {
  flex: none; display: flex; gap: 8px; align-items: center;
  padding: 12px 16px calc(12px + var(--safe-b)); border-top: 1px solid var(--line);
}
.dialog-foot .spacer { flex: 1; }

.field { display: grid; gap: 6px; }
.field > span, .label { font-size: 12.5px; font-weight: 650; color: var(--ink-2); }
.field small { color: var(--muted); font-weight: 400; }
.input, .field input, .field select, .field textarea {
  width: 100%; height: 44px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--surface);
  font-size: 16px; /* prevents iOS zoom on focus */
  outline: none;
}
.field textarea { height: 80px; padding: 10px 12px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--ink); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.segmented { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; }
.segmented label { flex: 1; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; border-radius: 8px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.segmented input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.segmented input:focus-visible + span { outline: 2px solid var(--ink); }

.legs { display: grid; gap: 10px; }
.leg { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: grid; gap: 10px; background: var(--surface-2); }
/* Date range picker */
.daterange { display: grid; gap: 8px; }
.dr-toggle {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 4px;
  border: 1px solid var(--line-strong); border-radius: 12px; padding: 4px;
}
.dr-half { border: 0; background: transparent; text-align: left; padding: 6px 10px; border-radius: 9px; display: grid; gap: 1px; }
.dr-half small { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.dr-half strong { font-size: 15.5px; font-weight: 650; }
.dr-half.placeholder strong { color: var(--muted); font-weight: 500; }
.dr-half.active { background: var(--surface-2); box-shadow: inset 0 0 0 1.5px var(--ink); }
.dr-arrow { color: var(--muted); }
.dr-panel { position: relative; border: 1px solid var(--line); border-radius: 14px; padding: 10px 8px 8px; }
.dr-nav { position: absolute; top: 6px; left: 6px; right: 6px; display: flex; justify-content: space-between; pointer-events: none; }
.dr-nav button {
  pointer-events: auto; width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: transparent; display: grid; place-items: center;
}
.dr-nav button:hover { background: var(--surface-2); }
.dr-months { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.dr-title { text-align: center; font-weight: 650; line-height: 26px; margin-bottom: 6px; }
.dr-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); row-gap: 2px; }
.dr-wd { text-align: center; font-size: 11.5px; font-weight: 600; color: var(--muted); padding-bottom: 4px; }
.dr-cell { height: 40px; display: grid; place-items: center; }
.dr-day {
  width: min(38px, 100%); aspect-ratio: 1; border-radius: 50%; border: 0; background: transparent; padding: 0;
  font-size: 14.5px; font-variant-numeric: tabular-nums;
}
.dr-day:hover { box-shadow: inset 0 0 0 1.5px var(--ink); }
.dr-cell.is-today .dr-day { font-weight: 800; text-decoration: underline; text-underline-offset: 3px; }
.dr-cell.in-range { background: var(--range); }
.dr-cell.is-start.has-range { background: linear-gradient(to right, transparent 50%, var(--range) 50%); }
.dr-cell.is-end.has-range { background: linear-gradient(to left, transparent 50%, var(--range) 50%); }
.dr-cell.is-start .dr-day, .dr-cell.is-end .dr-day { background: var(--ink); color: #fff; font-weight: 700; }
.dr-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; padding: 0 4px; font-size: 13.5px; color: var(--muted); }
@media (max-width: 519px) {
  .dr-months { grid-template-columns: 1fr; }
  .dr-month:nth-child(2) { display: none; }
}

.leg-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.leg-actions .btn { padding: 0 10px; min-width: 0; }
.form-hint { margin: 0; font-size: 13px; color: var(--muted); }

.leg-insert {
  display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%;
  height: 30px; border: 1px dashed var(--line-strong); border-radius: 999px;
  background: transparent; color: var(--muted); font-size: 12.5px; font-weight: 600;
}
.leg-insert svg { width: 14px; height: 14px; }
.leg-insert:hover { color: var(--ink); border-color: var(--ink); }
.leg-head { display: flex; align-items: center; justify-content: space-between; }
.leg-head strong { font-size: 13px; }
.leg .field input, .leg .field select { background: var(--surface); }
.stay { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stay-label { display: grid; font-size: 13.5px; font-weight: 650; color: var(--ink-2); min-width: 0; }
.stay-label > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stay-label small { font-size: 12px; font-weight: 400; color: var(--muted); }
.stepper {
  flex: none; display: flex; align-items: center; height: 40px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); overflow: hidden;
}
.stepper button { width: 38px; height: 100%; border: 0; background: transparent; font-size: 18px; color: var(--ink-2); }
.stepper button:active { background: var(--surface-2); }
.stepper input {
  width: 48px; height: 100%; border: 0; text-align: center; font-size: 16px; font-weight: 650;
  background: transparent; outline: none; -moz-appearance: textfield;
}
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.leg-more summary { font-size: 13px; color: var(--muted); cursor: pointer; padding: 2px 0; }
.leg-more[open] summary { margin-bottom: 10px; }

.place { position: relative; }
.place-box {
  display: flex; align-items: center; gap: 8px; height: 44px; padding-right: 12px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface);
}
.place-box:focus-within { border-color: var(--ink); }
.field .place-box input {
  flex: 1; min-width: 0; height: 42px; border: 0; background: transparent; text-overflow: ellipsis;
}
.place-country {
  flex: none; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12.5px; font-weight: 600; color: var(--muted);
  background: var(--surface-2); padding: 3px 8px; border-radius: 999px;
}
.place:not(.is-set) .place-country, .place-country:empty { display: none; }
.place-country .cn-code { display: none; letter-spacing: .04em; }
@media (max-width: 479px) {
  .place-country .cn-full { display: none; }
  .place-country .cn-code { display: inline; }
}
.place.is-set .place-box::after { content: "✓"; font-weight: 700; color: var(--ink); }
.place-results {
  position: absolute; z-index: 20; left: 0; right: 0; top: 100%; margin: 4px 0 0; padding: 4px;
  list-style: none; background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 12px; box-shadow: var(--shadow); max-height: 260px; overflow-y: auto;
}
.place-results li { padding: 8px 10px; border-radius: 8px; display: grid; gap: 1px; cursor: pointer; }
.place-results li:hover, .place-results li.active { background: var(--surface-2); }
.place-results small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.place-results .muted { color: var(--muted); cursor: default; }

.people-input {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  min-height: 44px; padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: 10px;
}
.people-input:focus-within { border-color: var(--ink); }
.people-input input { flex: 1; min-width: 120px; border: 0; outline: none; height: 30px; font-size: 16px; padding: 0 4px; }
.person { display: inline-flex; align-items: center; gap: 4px; background: var(--ink); color: #fff; padding: 3px 4px 3px 10px; border-radius: 999px; font-size: 13px; }
.person button { border: 0; background: transparent; color: inherit; width: 20px; height: 20px; border-radius: 50%; padding: 0; line-height: 1; }

.color-row { display: flex; align-items: center; gap: 10px; }
.color-row input[type="color"] { width: 44px; height: 36px; padding: 0; border: 1px solid var(--line-strong); border-radius: 8px; background: none; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); }

.form-warning { background: #fff8e1; color: #6b4e00; border-radius: 10px; padding: 10px 12px; font-size: 13.5px; }
.form-warning ul { margin: 4px 0; padding-left: 18px; }
.form-error { background: #fff4f4; color: var(--danger); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; }
.form-error ul { margin: 4px 0 0; padding-left: 18px; }

.toast {
  position: fixed; left: 50%; top: calc(110px + var(--safe-t)); transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow);
}

/* Map popup */
.maplibregl-popup-content { border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow); font: inherit; }
.popup-title { font-weight: 650; }
.popup-meta { color: var(--muted); font-size: 12.5px; }

/* ------------------------------------------------------------------ larger screens */
@media (min-width: 900px) {
  :root { --peek: 0px; }
  .sheet {
    top: 70px; left: 16px; bottom: 16px; width: 380px; height: auto;
    border-radius: 18px; transform: none; box-shadow: var(--shadow);
  }
  .sheet-handle { display: none; }
  .tabs { padding-top: 14px; }
  .maplibregl-ctrl-bottom-left { left: 404px; }
  .maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { bottom: calc(var(--timeline-h) + 20px); }
  .timeline { left: 412px; bottom: 16px; }
  .tabs .sheet-collapse { display: grid; }
  /* Collapsed: just the tab row, and the timeline spans the full width. */
  /* Collapsed: folds left into a slim vertical strip with sideways tab labels. */
  .panel-collapsed .sheet { width: 52px; bottom: auto; }
  .panel-collapsed .sheet-body { display: none; }
  .panel-collapsed .tabs { flex-direction: column; align-items: center; gap: 6px; padding: 8px; }
  .panel-collapsed .tabs .sheet-collapse { order: -1; }
  .panel-collapsed .tabs button[data-tab] {
    flex: none; width: 36px; height: auto; padding: 14px 0;
    writing-mode: vertical-rl; transform: rotate(180deg);
  }
  .panel-collapsed .tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--ink); }
  .panel-collapsed .sheet-collapse svg { transform: rotate(180deg); }
  .panel-collapsed .timeline { left: 16px; }
  .panel-collapsed .maplibregl-ctrl-bottom-left { left: 0; }
  .dialog:not(.dialog-small) { width: 560px; height: min(92vh, 900px); margin: auto; border-radius: 18px; }
  .dialog-head { padding-top: 14px; }
}

/* ------------------------------------------------------------------ whose map */
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.view-switch {
  height: 36px; max-width: 46vw; padding: 0 10px; border: 0; border-radius: 999px;
  background: var(--surface); box-shadow: var(--shadow); font-size: 13px; font-weight: 600;
}
body.viewing-other .view-switch { background: var(--ink); color: #fff; }
@media (max-width: 479px) {
  body:has(.view-switch:not([hidden])) .brand span { display: none; }
  .view-switch { max-width: 40vw; }
}
