/* The planner (#/plan), design C section 3.1: map rail, Layers popup, the
   one route sheet. Components (.btn, .seg, .chip, .shortcut, .icon-btn) are
   css/components.css; the tokens are css/tokens.css. */

/* ---------- map attribution on the theme's chrome ---------- */
#view-plan .maplibregl-ctrl-attrib,
#view-plan .maplibregl-ctrl-attrib.maplibregl-compact {
  background: var(--attrib-bg);
  color: var(--attrib-text);
}
#view-plan .maplibregl-ctrl-attrib a { color: var(--attrib-link); }

/* ---------- switch (a checkbox with role="switch") ---------- */
.plan-switch {
  appearance: none;
  box-sizing: content-box;
  width: 44px;
  height: 26px;
  margin: 0 -8px 0 0;
  border: 9px solid transparent;
  background-clip: padding-box;
  border-radius: var(--r-pill);
  background-color: var(--line-strong);
  position: relative;
  flex: none;
  cursor: pointer;
  transition: background-color .15s var(--ease);
}
.plan-switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 2px var(--knob-shadow);
  transition: translate .15s var(--ease);
}
.plan-switch:checked { background-color: var(--accent); }
.plan-switch:checked::after { translate: 18px 0; background: var(--knob-on); }
.plan-switch:focus-visible { outline: 2px solid var(--focus); outline-offset: -6px; }
[data-theme='contrast'] .plan-switch { outline: 2px solid var(--text); outline-offset: -9px; }

/* ---------- Layers popup (#187) ---------- */
/* js/views/plan/foldout.js sets top / right / max-width from the button on
   open (the rail is as wide as the phone pill); these are the fallback. */
.plan-rail .plan-layers {
  position: absolute;
  top: 0;
  right: calc(100% + 8px);
  max-width: calc(100vw - 16px);
  max-height: min(78vh, calc(100dvh - var(--topbar-h) - 32px));
  overflow-y: auto;
}
.plan-layers {
  box-sizing: border-box;
  width: 340px;
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 14px 18px 18px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-float);
  overscroll-behavior: contain;
}
.plan-layers.hidden { display: none; }
.plan-layers-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-right: -8px; }
.plan-layers-title { margin: 0; font: 700 var(--fs-18)/1.2 var(--font-display); }
.plan-layers-h { margin: 6px 0 -2px; font: 650 var(--fs-13)/1.3 var(--font-display); color: var(--text-2); }
.plan-layer-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  margin: 0;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-size: var(--fs-16);
  font-weight: 400;
  cursor: pointer;
}
.plan-layer-row .grow { flex: 1; min-width: 0; }
.plan-poi-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.plan-poi-chip { gap: 6px; }
.plan-poi-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 0 1.5px var(--surface); }
.plan-shade-seg { display: flex; }
.plan-shade-seg > button { flex: 1; }
@media (max-width: 699px) {
  .plan-layers { width: calc(100vw - 24px); }
}

/* ---------- map chrome: status, zoom, rail, phone pill (design C 3.1) ----------
   js/views/plan/sheet.js sets --plan-card-w, --plan-handle-* and
   --plan-sheet-h on #view-plan and toggles .plan-docked (900 px and wider)
   or .plan-bottom; nothing here repeats the breakpoint. Chrome floats on the
   map in solid surfaces, never text straight on the map (#156). */
.plan-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
#view-plan { --plan-edge: 16px; --plan-free-left: calc(var(--plan-edge) * 2 + var(--plan-card-w)); }
#view-plan.plan-bottom { --plan-edge: 12px; --plan-free-left: var(--plan-edge); }
#plan-status {
  position: absolute;
  z-index: 16;
  top: calc(var(--plan-edge) + var(--tap) + 8px);
  left: var(--plan-free-left);
  right: calc(var(--plan-edge) + var(--tap) + 12px);
  max-width: 560px;
}
.plan-rail {
  position: absolute;
  z-index: 14;
  top: var(--plan-edge); /* O17: the zoom pair sits inside the rail now */
  right: var(--plan-edge);
  display: grid;
  justify-items: end;
  gap: 8px;
}
/* D3: the phone pill (js/views/plan/coverage_layer.js), top left beside the
   card; tap to expand at any width. */
.plan-phone-pill {
  position: absolute;
  z-index: 15;
  top: var(--plan-edge);
  left: var(--plan-free-left);
  max-width: min(280px, calc(100% - var(--plan-free-left) - var(--tap) - 2 * var(--plan-edge)));
  background: var(--map-chrome);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: calc(var(--tap) / 2);
  box-shadow: var(--shadow);
  font: 650 var(--fs-13)/1.2 var(--font-display);
}
.plan-phone-pill[hidden] { display: none; }
.plan-phone-pill.expanded { border-radius: var(--r-2); }
.plan-phone-pill-toggle {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: var(--tap);
  padding: 0 14px; background: none; border: 0; color: inherit; font: inherit;
  text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer;
}
.plan-phone-pill-toggle::before {
  content: ''; flex: none; width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-3); box-shadow: 0 0 0 3px color-mix(in srgb, var(--text-3) 25%, transparent);
}
.plan-phone-pill[data-dot='on'] .plan-phone-pill-toggle::before {
  background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent);
}
.plan-phone-pill:not(.expanded) .plan-phone-pill-lines { display: none; }
.plan-phone-pill-lines { padding: 0 14px 10px; font: 400 var(--fs-13)/1.4 var(--font-body); color: var(--text-2); }
#view-plan.plan-docked #plan-admin-panel { right: auto; left: var(--plan-free-left); top: calc(var(--plan-edge) + var(--tap) + 8px); }
#view-plan.plan-bottom #plan-admin-panel { right: auto; left: 8px; top: 120px; width: min(320px, calc(100% - 80px)); }
#view-plan.plan-bottom .maplibregl-ctrl-bottom-right,
#view-plan.plan-bottom .maplibregl-ctrl-bottom-left { bottom: var(--plan-sheet-h, 0px); }
/* A failed basemap's retry is a full tap target. */
#view-plan .map-load-error .btn, #view-plan .map-load-error button { min-height: var(--tap); }

/* ---------- the ONE plan card: a docked card, or a bottom sheet (#185) ---------- */
.plan-sheet {
  position: absolute;
  z-index: 12;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-float);
  overflow: hidden;
}
#view-plan.plan-docked .plan-sheet {
  top: var(--plan-edge);
  left: var(--plan-edge);
  bottom: var(--plan-edge);
  width: var(--plan-card-w);
  border-radius: var(--r-3);
}
#view-plan.plan-bottom .plan-sheet {
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 56%;
  border-radius: var(--r-3) var(--r-3) 0 0;
  border-bottom: 0;
}
/* Collapsed: the handle, the head and the numbers; the map gets the rest. */
#view-plan.plan-bottom .plan-sheet[data-detent='collapsed'] { max-height: min(34%, 260px); }
.plan-handle {
  display: none;
  place-items: center;
  flex: none;
  width: 100%;
  height: var(--plan-handle-hit);
  padding: 0;
  background: transparent;
  border: 0;
  cursor: pointer;
}
.plan-handle::before {
  content: '';
  width: var(--plan-handle-w);
  height: var(--plan-handle-h);
  border-radius: calc(var(--plan-handle-h) / 2);
  background: var(--line-strong);
}
#view-plan.plan-bottom .plan-handle { display: grid; }
.plan-sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  gap: var(--s-4);
  align-content: start;
  padding: 20px 20px 28px;
}
#view-plan.plan-bottom .plan-sheet-body { padding: 0 16px calc(24px + env(safe-area-inset-bottom)); }
/* The global label and summary rules are for the old forms: the card sets its own. */
.plan-sheet-body label { margin: 0; }
.plan-sheet-body input:not([type='checkbox']):not([type='radio']), .plan-sheet-body select { margin: 0; }

/* 1. Back + more */
.plan-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.plan-back {
  display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); padding: 0 8px 0 0;
  background: none; border: 0; color: var(--accent-ink); font: 650 var(--fs-13)/1 var(--font-display); cursor: pointer;
}
.plan-more-wrap { position: relative; margin-left: auto; }
.plan-more-menu {
  position: absolute;
  z-index: 3;
  top: calc(100% + 4px);
  right: 0;
  display: grid;
  min-width: 220px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  box-shadow: var(--shadow-float);
}
.plan-more-menu.hidden { display: none; }
.plan-more-menu button {
  min-height: var(--tap);
  padding: 0 12px;
  background: transparent;
  color: var(--text);
  border: 0;
  border-radius: var(--r-1);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.plan-more-menu button:hover:not(:disabled) { background: var(--surface-2); }
.plan-more-menu button:disabled { color: var(--text-3); cursor: not-allowed; }

/* 2. the title */
.plan-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font: 750 var(--fs-18)/1.2 var(--font-display);
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 3. result */
.plan-result-block { display: grid; gap: var(--s-3); }
.plan-result {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 14px 0;
  border-block: 2px dashed var(--line);
}
.plan-result > div { display: grid; gap: 2px; min-width: 0; }
.plan-num {
  font: 750 var(--fs-22)/1.1 var(--font-display);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}
.plan-num-label { font-size: var(--fs-13); color: var(--text-2); }
.plan-meta { margin: 0; font-size: var(--fs-13); color: var(--text-2); }
.plan-meta:empty { display: none; }
.seed-pin {
  min-height: var(--tap);
  min-width: var(--tap);
  margin: 0 4px;
  padding: 0 10px;
  border-radius: var(--r-pill);
  border: 1px dashed var(--line-strong);
  background: transparent;
  color: var(--accent-ink);
  font: 700 var(--fs-13)/1 var(--font-mono);
  cursor: pointer;
}
.seed-pin:hover { background: var(--accent-soft); }

/* the small headings of the stack */
.plan-h { margin: 0; font: 650 var(--fs-13)/1.3 var(--font-display); color: var(--text-2); letter-spacing: 0; }

.plan-field { display: grid; gap: 6px; min-width: 0; }

/* 9. tools */
.plan-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.plan-tools .icon-btn:disabled { opacity: .45; cursor: not-allowed; }
.plan-clear { margin-left: auto; }

/* 10. disclosures */
.plan-disc { border-top: 1px solid var(--line); padding-top: 4px; min-width: 0; }
.plan-disc > summary {
  list-style: none; display: flex; align-items: center; gap: 8px; min-height: var(--tap); padding: 0;
  color: var(--text); font: 700 var(--fs-16)/1.2 var(--font-display); cursor: pointer;
}
.plan-disc > summary::-webkit-details-marker { display: none; }
.plan-disc > summary > span:first-child { flex: 1 1 auto; }
.plan-disc > summary > .ic { color: var(--text-2); rotate: 90deg; transition: rotate .15s var(--ease); }
.plan-disc[open] > summary > .ic { rotate: -90deg; }
.plan-disc[open] { display: grid; gap: 10px; padding-bottom: 8px; }
.plan-disc .count { font: 600 var(--fs-13)/1 var(--font-mono); color: var(--text-2); }
.plan-disc-inline { border-top: 0; padding-top: 0; }
.plan-disc-inline > summary { font: 600 var(--fs-14)/1.2 var(--font-body); color: var(--text-2); }
/* O6: the search field is busy from the first searching keystroke until an answer. */
.search-wrap.is-busy::after {
  content: ''; position: absolute; top: calc(var(--tap) / 2 - 8px); right: 12px;
  width: 16px; height: 16px; border: 2px solid var(--line-strong); border-top-color: var(--accent);
  border-radius: 50%; animation: plan-spin .7s linear infinite; pointer-events: none;
}
.search-wrap.is-busy input { padding-right: 40px; }
.search-wrap.is-busy input::-webkit-search-cancel-button { display: none; }
@keyframes plan-spin { to { rotate: 360deg; } }
@media (prefers-reduced-motion: reduce) { .search-wrap.is-busy::after, .leg-spinner { animation-duration: 2s; } }

/* O11: the route lab, collapsed, is one icon button (its own look, P-A4). */
.plan-lab-toggle {
  display: grid; place-items: center; flex: none; width: 44px; height: 44px; margin: 0; padding: 0;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--r-2);
  box-shadow: var(--shadow); cursor: pointer;
}
.plan-lab-toggle:hover { background: var(--surface-2); }
.plan-lab-toggle[aria-expanded='true'] { box-shadow: none; }
#plan-admin-panel.collapsed { padding: 0; background: none; border: 0; backdrop-filter: none; }
#plan-admin-panel.collapsed #plan-admin-title { display: none; }

/* Curves and elevation (#171: the surface strip is the band in the SVG) */
.plan-legend { margin: 0; font-size: var(--fs-13); color: var(--text-2); }
.legend-swatch { display: inline-block; width: 14px; height: 3px; margin: 0 4px 0 10px; vertical-align: middle; }
.legend-swatch:first-child { margin-left: 0; }
.legend-curv { background: var(--accent); }
.legend-elev { background: #539bf5; }
#plan-profile-svg { display: block; width: 100%; height: 96px; cursor: crosshair; }
/* The band lives inside the SVG; the box grows with the viewBox. */
#plan-profile-svg.has-surface { height: 110px; }
.plan-readout { margin: 0; min-height: 1.5em; font-size: var(--fs-13); color: var(--text-2); }
#plan-surface-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--text-2); }
#plan-surface-legend .surface-swatch {
  display: inline-block; width: 14px; height: 8px; border-radius: 3px; margin-right: 6px; vertical-align: middle;
}
.pc-grid { stroke: var(--line); stroke-width: 1; }
.pc-label { fill: var(--text-2); font-size: 10px; font-family: var(--font-mono); }
.pc-curv-label { fill: color-mix(in srgb, var(--accent) 60%, var(--text)); }
.pc-elev-label { fill: color-mix(in srgb, #539bf5 60%, var(--text)); }
.pc-curv-line { stroke: var(--accent); stroke-width: 1.5; fill: none; }
.pc-elev-line { stroke: #539bf5; stroke-width: 1.5; fill: none; }
.pc-cursor { stroke: var(--text); stroke-width: 1; stroke-dasharray: 3 2; }
.profile-hover-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--text); border: 2px solid var(--accent);
  box-shadow: 0 0 4px #00000088;
}

@media (min-width: 900px) and (max-width: 1100px) {
  #view-plan.plan-docked { --plan-card-w: 372px !important; }
}
@media (max-width: 380px) {
  .plan-title { font-size: 1.4rem; }
  .plan-num { font-size: 1.1rem; }
}

/* ---------- the point popup (#186): a floating card like the Layers popup ---------- */
.plan-popup { z-index: 3; } /* above the map controls it may overlap */
.plan-popup .maplibregl-popup-content {
  border-radius: var(--r-3);
  box-shadow: var(--shadow-float);
  font: inherit;
  font-size: var(--fs-14);
}
.plan-popup .popup-title { font-weight: 600; }
.plan-popup .point-actions button { min-height: var(--tap); border-radius: var(--r-2); font-size: var(--fs-14); font-weight: 500; }
.plan-popup .point-actions button:disabled { color: var(--text-3); cursor: default; }
.plan-popup .point-popup .point-actions { gap: 0; }
.plan-bottom .plan-popup { max-width: min(260px, 60vw) !important; } /* beats maplibre's inline maxWidth */
.plan-popup .point-popup .point-actions button { padding: 0 10px; }

/* ---------- W3: the trip planner (decision 2, 8; Opus A list, Opus B dock) ---------- */
/* The sheet is a column: the body takes what the result bar leaves, and only
   the planner's list region scrolls (8.3). The bottom sheet budgets the
   sheet AND the bar together: at most 60 % of the viewport, so the map keeps
   40 % (amendment 5). */
/* 100% is #view-plan (the screen below the top bar): the map keeps 40 % of
   the SCREEN whatever the bar takes. */
#view-plan.plan-bottom .plan-sheet { max-height: calc(100% - 40svh); }
#view-plan.plan-bottom.plan-where-open .plan-sheet { max-height: calc(100% - 8px); height: calc(100% - 8px); }
.plan-sheet-body { display: flex; flex-direction: column; gap: 10px; overflow: hidden; padding: 14px 16px 12px; }
#view-plan.plan-bottom .plan-sheet-body { padding: 12px 16px 6px; gap: 6px; }
/* The handle keeps its 44 px hit (#138) but floats over the head's middle,
   so it costs the sheet no row of its own. */
#view-plan.plan-bottom.plan-entered .plan-handle { position: absolute; z-index: 2; top: 0; left: 50%; width: 96px; margin-left: -48px; align-items: start; padding-top: 6px; }
#view-plan.plan-bottom:not(.plan-entered) .plan-sheet-body { padding-top: 0; }
#view-plan.plan-bottom .plan-page { gap: 6px; }
.plan-sheet-body > .hidden, .plan-planner > .hidden, .plan-scroll > .hidden { display: none; }
.plan-planner, .plan-page { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.plan-scroll, .plan-page-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: grid; gap: 10px; align-content: start;
}
/* Collapsed on a phone: the head and the bar; the map gets the rest. */
#view-plan.plan-bottom .plan-sheet[data-detent='collapsed'] :is(.plan-scroll, .plan-add-row, .plan-page-body, .leg-tabs, .plan-where-list, .plan-dock-row) { display: none; }
#view-plan.plan-bottom .plan-sheet[data-detent='collapsed'] { max-height: calc(100% - 40svh); }
/* On a phone the bar carries the numbers; the tiles stay on the docked card. */
#view-plan.plan-bottom .plan-result { display: none; }

/* Every selector reads as tappable: a border and a chevron (8.6). */
.selector {
  display: inline-flex; align-items: center; justify-content: space-between; gap: 6px; min-height: 32px; max-width: 100%;
  padding: 0 10px; background: var(--surface); color: var(--text); border: 1.5px solid var(--line-strong);
  border-radius: var(--r-1); font: 600 var(--fs-13)/1.2 var(--font-body); cursor: pointer; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.selector:hover { border-color: var(--accent); }
.selector .ic { flex: none; color: var(--text-2); }
.ic-xs { width: 12px; height: 12px; }
#plan-trip-settings { flex: none; min-height: var(--tap); }

/* the start dock */
.plan-dock { display: grid; gap: 10px; }
.plan-dock-where {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 0 14px;
  background: var(--surface-2); color: var(--text-2); border: 1.5px solid var(--line-strong); border-radius: var(--r-pill);
  font: 600 var(--fs-16)/1 var(--font-display); text-align: left; cursor: text;
}
.plan-dock-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.plan-dock-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); padding: 0 8px;
  background: var(--surface); color: var(--text); border: 1.5px solid var(--line); border-radius: var(--r-2);
  font: 650 var(--fs-13)/1.1 var(--font-display); cursor: pointer; min-width: 0;
}
.plan-dock-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-dock-btn .ic { flex: none; color: var(--accent-ink); }
.plan-dock-btn:hover, .plan-dock-where:hover { border-color: var(--accent); }

/* "Where to?" */
.plan-where-to { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.plan-where-head { display: flex; align-items: center; gap: 6px; }
.plan-where-head .search-wrap { flex: 1 1 auto; }
.plan-where-head input { width: 100%; min-height: var(--tap); }
.plan-where-list { list-style: none; margin: 0; padding: 0; display: grid; }
.plan-where-row {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 4px 6px;
  background: none; border: 0; border-bottom: 1px solid var(--line); color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.plan-where-row .grow { display: grid; gap: 2px; min-width: 0; }
.plan-where-row .muted { font-size: var(--fs-13); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-where-row .ic { color: var(--accent-ink); }
.search-results.search-inline { position: static; flex: 1 1 auto; min-height: 0; max-height: none; box-shadow: none; }

/* the stop list */
.stop-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.stop-row { display: flex; align-items: center; gap: 6px; min-height: 40px; min-width: 0; }
.stop-num {
  flex: none; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%;
  background: #7db4ec; color: #0d1117; font: 700 12px/1 var(--font-body);
}
.stop-num.start { background: #4cc38a; }
.stop-num.end { background: #ff6b62; }
.stop-num.pass { background: transparent; color: var(--text-2); font-size: 15px; }
.stop-main { flex: 1 1 auto; min-width: 0; display: grid; gap: 1px; }
.stop-line { display: flex; align-items: center; gap: 6px; min-width: 0; }
.stop-line .stop-name { flex: 0 1 auto; min-width: 0; }
.stop-times { font-size: var(--fs-12); line-height: 1.2; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stop-name { font-weight: 650; font-size: var(--fs-14); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stop-meta { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: var(--fs-12); color: var(--text-2); }
.stop-times { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stop-chip { min-height: 26px; padding: 0 6px; font-size: var(--fs-12); flex: none; }
.stop-chip.set { border-color: var(--accent); color: var(--accent-ink); }
.pass-row { opacity: .7; min-height: 34px; }
.stop-handle {
  flex: none; width: 24px; min-height: 36px; padding: 0; background: none; border: 0; color: var(--text-3);
  font-size: 16px; cursor: grab; touch-action: none;
}
.stop-tail { flex: none; display: flex; align-items: center; gap: 4px; }
.stop-kind {
  min-height: 28px; padding: 0 8px; border-radius: var(--r-pill); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text-2); font: 650 11px/1 var(--font-body); cursor: pointer; white-space: nowrap;
}
.stop-kind.pass { border-style: dashed; }
.stop-remove {
  width: 28px; height: 28px; padding: 0; border-radius: 50%; border: 1px solid var(--line); background: none;
  color: var(--text-2); font-size: 15px; line-height: 1; cursor: pointer; position: relative;
}
.stop-remove::after, .stop-kind { position: relative; }
.stop-remove::after { content: ''; position: absolute; inset: -8px 0; }
.stop-remove:hover { color: var(--danger); border-color: var(--danger); }
.stop-list.stop-dragging { cursor: grabbing; }
.stop-row.drop-before { box-shadow: inset 0 2px 0 0 var(--accent); }
.stop-row.drop-after { box-shadow: inset 0 -2px 0 0 var(--accent); }
.leg-row { padding-left: 30px; }
.leg-btn {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 44px; padding: 3px 6px 3px 10px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--r-2); font: inherit; text-align: left; cursor: pointer;
}
.leg-btn:hover { border-color: var(--line-strong); border-left-color: var(--accent); }
.leg-lines { flex: 1 1 auto; min-width: 0; display: grid; gap: 1px; }
.leg-line1 { font: 650 var(--fs-13)/1.25 var(--font-body); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leg-line2 { font-size: var(--fs-12); line-height: 1.25; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leg-metrics { flex: none; font: 600 var(--fs-12)/1.2 var(--font-body); color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.leg-chev { flex: none; color: var(--text-3); }
.leg-spinner {
  flex: none; width: 14px; height: 14px; border: 2px solid var(--line-strong); border-top-color: var(--accent);
  border-radius: 50%; animation: plan-spin .7s linear infinite;
}
.plan-add-row { display: flex; align-items: center; gap: 6px; padding-left: 30px; }
.plan-add-row .search-wrap { flex: 1 1 auto; min-width: 0; }
.plan-add-row input { width: 100%; min-height: 40px; }
.plan-add-row .plan-tools { flex: none; flex-wrap: nowrap; }
.plan-add-row .plan-tools .selector { min-height: 40px; }
.plan-add-row .search-results { bottom: 100%; top: auto; margin: 0 0 2px; }
.plan-add-row .plan-more-menu { top: auto; bottom: calc(100% + 4px); right: 0; min-width: 180px; }
.keep-adjusting { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 12px; row-gap: 2px; margin: 0; padding: 6px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.keep-adjusting-label { font-size: var(--fs-14); }
.keep-adjusting-hint { grid-column: 1 / -1; }

/* the result bar */
.plan-result-bar {
  flex: none; display: flex; align-items: center; gap: 10px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--surface);
}
.plan-result-bar.hidden { display: none; }
.plan-bar-text { flex: 1 1 auto; min-width: 0; display: grid; gap: 2px; }
.plan-bar-stats { font: 750 var(--fs-16)/1.2 var(--font-display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.plan-bar-arrival { font-size: var(--fs-12); color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plan-bar-arrival:empty { display: none; }
.plan-bar-actions { flex: none; display: flex; gap: 6px; }
.plan-bar-actions .btn { min-height: var(--tap); padding: 0 12px; white-space: nowrap; }

/* the page heads (leg page, Trip settings) */
.plan-page-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.plan-page-titles { flex: 1 1 auto; min-width: 0; display: grid; }
.plan-page-title { margin: 0; font: 750 var(--fs-16)/1.2 var(--font-display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-page-titles .plan-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leg-tabs { flex: none; }
.leg-tabs > button { padding: 0 4px; }
.leg-tab { display: grid; gap: 10px; align-content: start; }
.leg-tab-head, .leg-select-row, .trip-set-row { display: flex; align-items: center; gap: 8px; min-height: var(--tap); }
.leg-tab-head .grow, .leg-select-row .grow, .trip-set-row .grow { flex: 1 1 auto; min-width: 0; }
.trip-set-row .selector { flex: 0 1 60%; min-height: var(--tap); }
.way-switch { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; border-radius: var(--r-pill); background: var(--surface-2); border: 1.5px solid var(--line-strong); }
.way-opt {
  min-height: 40px; border: 0; border-radius: var(--r-pill); background: transparent; color: var(--text-2);
  font: 650 var(--fs-14)/1.1 var(--font-display); cursor: pointer;
}
.way-opt[aria-checked='true'] { background: var(--accent); color: var(--on-accent); }
.way-opt:disabled { opacity: .45; cursor: not-allowed; }
.goal-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: start; }
.goal-left { display: grid; gap: 6px; min-width: 0; }
.goal-right { display: grid; gap: 4px; justify-items: center; }
.goal-right .plan-meta { max-width: 150px; text-align: center; }
.goal-field { grid-template-columns: 1fr auto; align-items: center; }
.goal-field .plan-h { grid-column: 1 / -1; }
.goal-field input { min-height: var(--tap); width: 100%; }
.avoid-changed { font-size: var(--fs-12); color: var(--accent-ink); font-weight: 650; }
.trail-slider input[type='range'] { width: 100%; }
.trail-ticks { display: flex; justify-content: space-between; font-size: var(--fs-12); color: var(--text-2); }

/* the direction dial (decision 13): eight cardinals on a circle, Any inside */
.dir-dial { position: relative; width: 140px; height: 140px; border-radius: 50%; border: 1.5px solid var(--line-strong); background: var(--surface-2); flex: none; }
.dir-btn {
  position: absolute; width: 36px; height: 36px; margin: -18px 0 0 -18px; padding: 0; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: 700 11px/1 var(--font-body); cursor: pointer;
}
.dir-btn[aria-checked='true'] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.dir-n { left: 50%; top: 16%; } .dir-ne { left: 76%; top: 26%; } .dir-e { left: 84%; top: 50%; } .dir-se { left: 76%; top: 74%; }
.dir-s { left: 50%; top: 84%; } .dir-sw { left: 24%; top: 74%; } .dir-w { left: 16%; top: 50%; } .dir-nw { left: 24%; top: 26%; }
.dir-any { left: 50%; top: 50%; width: 48px; margin-left: -24px; border-radius: var(--r-pill); }

/* the profile list (decision 9) */
.profile-list { display: grid; gap: 6px; }
.profile-row { display: grid; gap: 4px; }
.profile-pick {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 48px; padding: 6px 10px;
  background: var(--surface-2); color: var(--text); border: 1.5px solid var(--line); border-radius: var(--r-2);
  font: inherit; text-align: left; cursor: pointer;
}
.profile-pick[aria-checked='true'] { border-color: var(--accent); background: var(--accent-soft); }
.profile-text { flex: 1 1 auto; min-width: 0; display: grid; gap: 1px; }
.profile-name { font: 700 var(--fs-14)/1.2 var(--font-display); }
.profile-star { color: var(--accent-ink); }
.profile-blurb, .profile-avoids { font-size: var(--fs-12); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-avoids.custom { color: var(--accent-ink); font-weight: 650; }
.profile-check { flex: none; color: var(--accent-ink); font-weight: 800; }
.profile-reset { justify-self: end; }
.profile-customize { display: inline-flex; align-items: center; min-height: var(--tap); color: var(--accent-ink); font-weight: 650; }

/* the time sheets */
.plan-time-sheet, .plan-time-fields, .plan-stay-list { display: grid; gap: 10px; }
.plan-time-fields { grid-template-columns: 1fr 1fr; }
.plan-time-fields.hidden { display: none; }
.plan-time-fields select, .plan-time-fields input { width: 100%; min-height: var(--tap); }
.plan-stay-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.plan-stay-choice {
  min-height: var(--tap); border-radius: var(--r-2); border: 1.5px solid var(--line); background: var(--surface-2);
  color: var(--text); font: 650 var(--fs-14)/1 var(--font-body); cursor: pointer;
}
.plan-stay-choice[aria-checked='true'] { border-color: var(--accent); background: var(--accent-soft); }
.plan-collections { display: grid; gap: 4px; }
.plan-day-ribbon[hidden] { display: none; }

/* The bar (the card is 404 px wide too): the numbers on one line, the two
   labelled buttons below, so DE labels never squeeze the numbers. */
.plan-result-bar { flex-wrap: wrap; gap: 6px; padding: 6px 16px calc(6px + env(safe-area-inset-bottom)); }
.plan-bar-text { flex: 1 1 100%; display: flex; align-items: baseline; gap: 10px; }
.plan-bar-stats { font-size: var(--fs-14); }
.plan-bar-arrival { margin-left: auto; }
.plan-bar-actions { flex: 1 1 100%; }
.plan-bar-actions > * { flex: 1 1 0; min-width: 0; }
.plan-bar-actions .btn { padding: 0 8px; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 559px) {
  .stop-row { min-height: 30px; }
  .stop-chip { min-height: 24px; }
  .pass-row { min-height: 30px; }
  .stop-handle { min-height: 28px; width: 20px; }
  .stop-remove, .stop-kind { height: 26px; min-height: 26px; }
  .stop-chip { min-height: 24px; height: 24px; }
  .stop-remove { width: 26px; }
  .leg-row { padding-left: 26px; }
  .plan-add-row { padding-left: 26px; }
  .leg-btn { min-height: 30px; padding: 1px 4px 1px 8px; }
  #view-plan.plan-bottom.plan-entered .plan-sheet-body { padding-top: 8px; gap: 4px; }
  #view-plan.plan-bottom .plan-page { gap: 4px; }
  .plan-add-row input, .plan-add-row .plan-tools .selector { min-height: 36px; }
  .leg-line1, .leg-line2 { line-height: 1.15; }
  .stop-list { gap: 1px; }
  .plan-scroll { gap: 4px; }
}
/* A phone's head (8.3 budget): Back is its universal icon, the title and
   Trip settings share one compact row. */
@media (max-width: 559px) {
  #plan-back { min-height: 36px; padding: 0; }
  #plan-back span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  #plan-back .ic { width: 22px; height: 22px; }
  .plan-title { font-size: var(--fs-16); }
  #plan-trip-settings { min-height: 34px; }
  .plan-result-bar { padding: 4px 16px calc(4px + env(safe-area-inset-bottom)); gap: 4px; }
  .plan-bar-stats, .plan-bar-arrival { line-height: 1.1; }
  .plan-bar-actions .btn { min-height: 40px; }
}

/* ---------- W4: leg row status (decision 11) ---------- */
.leg-btn.status-reduced { border-color: var(--accent); border-left-color: var(--accent); background: var(--accent-soft); }
.leg-btn.status-reduced .leg-line2 { color: var(--accent-ink); font-weight: 650; }
.leg-btn.status-failed { border-color: var(--danger); border-left-color: var(--danger); background: var(--danger-soft); }
.leg-btn.status-failed .leg-line1 { color: var(--danger); }
.leg-btn.status-failed .leg-line2 { color: var(--text); }
.leg-row.leg-revealed .leg-btn { outline: 2px solid var(--accent); outline-offset: 1px; }
/* E5: the leg rows or the round trip's status line say it instead. */
#plan-status.plan-status-covered { display: none !important; }

/* ---------- W4: the round trip screen (Opus B screen 7) ---------- */
.plan-round-trip { flex: none; display: grid; gap: 8px; min-width: 0; }
.rt-r1, .rt-r5 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.rt-menu-wrap { position: relative; min-width: 0; display: grid; }
.rt-sel { width: 100%; min-height: var(--tap); justify-content: flex-start; }
.rt-sel-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; text-align: left; }
.rt-menu-wrap .plan-more-menu { left: 0; right: auto; min-width: 220px; }
.rt-search { position: relative; }
.rt-search input { width: 100%; min-height: var(--tap); }
.rt-goal { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: start; }
.rt-goal-left { display: grid; gap: 8px; min-width: 0; align-content: start; }
.rt-kind > button { padding: 0 6px; min-width: 0; }
.rt-value { display: flex; align-items: center; gap: 8px; min-height: var(--tap); min-width: 0; }
.rt-value input { flex: 0 1 120px; min-width: 0; min-height: var(--tap); }
.rt-value input[type='time'] { flex: 0 0 auto; }
.rt-value .field-unit { flex: none; margin: 0; }
.rt-approx { flex: 1 1 auto; min-width: 0; font-size: var(--fs-13); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rt-approx:empty { display: none; }
.rt-explain { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: var(--tap); align-content: center; }
.rt-keep { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: var(--tap); margin: 0; cursor: pointer; }
.rt-keep-label { min-width: 0; font: 650 var(--fs-14)/1.2 var(--font-body); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rt-keep .plan-switch { flex: none; }
.rt-dial .dir-dial { margin: 0; }
/* R4: two lines reserved, whatever it says. */
.rt-status {
  min-height: calc(2 * 1.3 * var(--fs-13)); display: flex; align-items: center; font-size: var(--fs-13); line-height: 1.3;
  color: var(--text-2); overflow: hidden;
}
.rt-status.status-failed { color: var(--danger); font-weight: 600; }
.rt-status.status-outOfRange { color: var(--accent-ink); font-weight: 600; }
.rt-status-btn {
  width: 100%; min-height: calc(2 * 1.3 * var(--fs-13)); padding: 0 8px; text-align: left; cursor: pointer;
  background: var(--accent-soft); color: var(--accent-ink); border: 1px solid var(--accent); border-radius: var(--r-1);
  font: 650 var(--fs-13)/1.3 var(--font-body);
}
.rt-r5 .btn { min-height: var(--tap); padding: 0 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-tonal { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn-tonal:disabled { opacity: .5; }

/* ---------- W4: Save & share (Opus B tile grid) ---------- */
.dlg-share .dlg-body { display: grid; gap: 8px; }
.share-sheet { display: grid; gap: 8px; }
.share-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.share-row.wide { grid-template-columns: minmax(0, 1fr); }
.share-tile {
  display: grid; gap: 2px; align-content: center; min-height: 56px; min-width: 0; padding: 8px 10px; text-align: left;
  background: var(--surface-2); color: var(--text); border: 1.5px solid var(--line-strong); border-radius: var(--r-2); cursor: pointer;
}
.share-tile:hover:not(:disabled) { border-color: var(--accent); }
.share-tile:disabled { opacity: .55; cursor: not-allowed; }
.share-tile.guarded { border-color: var(--accent); }
/* A label or sublabel may wrap to a second line rather than be cut (the
   app's rule above 1.0; German on a 375 px phone needs it). */
.share-tile-label, .share-tile-sub { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.share-tile-label { font: 700 var(--fs-14)/1.2 var(--font-display); }
.share-tile-sub { font-size: var(--fs-12); line-height: 1.25; color: var(--text-2); }
.share-tile-sub.reason { color: var(--accent-ink); font-weight: 650; }
.share-note { margin-top: 2px; }

/* The round trip on a phone (binding amendment 6): R2-R3 share their
   height with the dial beside them; the whole screen and the bar keep 40 %
   of the screen for the map at 375 x 667, so the controls are compact and
   the details below (curves, blocks, reports) live on the docked card and
   taller screens. */
#view-plan.plan-bottom .plan-round-trip { gap: 4px; }
@media (max-width: 559px) {
  .rt-r1, .rt-r5 { gap: 6px; }
  .rt-sel { min-height: 34px; }
  .rt-goal { gap: 8px; }
  .rt-goal-left { gap: 3px; }
  .rt-kind { padding: 1px; }
  .rt-kind > button { min-height: 28px; font-size: var(--fs-12); }
  .rt-value { min-height: 30px; }
  .rt-value input { min-height: 30px; height: 30px; padding-block: 0; }
  .rt-explain { min-height: 30px; font-size: var(--fs-12); line-height: 1.2; }
  .rt-keep { min-height: 30px; }
  .rt-keep-label { font-size: var(--fs-13); }
  /* The whole row is the switch's hit area (its label): no extra halo. */
  .rt-keep .plan-switch { border-top-width: 2px; border-bottom-width: 2px; }
  .rt-dial .dir-dial { width: 96px; height: 96px; }
  .rt-dial .dir-btn { width: 25px; height: 25px; margin: -12.5px 0 0 -12.5px; font-size: 10px; }
  .rt-dial .dir-any { width: 38px; margin-left: -19px; }
  .rt-status, .rt-status-btn { min-height: calc(2 * 1.2 * var(--fs-12)); font-size: var(--fs-12); line-height: 1.2; }
  .rt-r5 .btn { min-height: 38px; }
}
@media (max-width: 899px) and (max-height: 760px) {
  #view-plan.plan-bottom.plan-round .plan-scroll { display: none; }
}

/* #246: a Stop's address line (the app's detail style), one line. */
.stop-address { display: block; min-width: 0; font-size: var(--fs-12); line-height: 1.2; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* The 375 x 667 budget (8.3: 3 Stops show unscrolled with Add stop): on a
   phone the address line is compact and costs its row no extra gap. */
@media (max-width: 559px) {
  .stop-main:has(.stop-address) { gap: 0; }
  .stop-address { font-size: 11px; line-height: 1.1; }
  .stop-row:has(.stop-address) .stop-chip { height: 22px; min-height: 22px; }
}
