/* The routing page's design language: the components (list and row, icon badge, chip, segmented control, switch,
   button, popup, sheet head, field and folded fields, status line, toast), each defined once and prefixed `ui-`, built on the tokens of
   forms.css (--space-*, --radius-*, --shadow-*, --amber, --ok, --toast-*). Linked by routing.html after forms.css;
   each element takes a component's class beside its own. Dark values go in `@media (prefers-color-scheme: dark)` blocks, never `[data-theme]`:
   theme.js rewrites those media for the Preferences' choice. */

/* A list: one card of rows (a <ul> or <ol>, or any box), under its title, muted and in sentence case; a hairline between
   its shown rows, none above the first shown (a hidden first child draws none either). */
.ui-list { margin: 0; padding: 0 var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--surface); list-style: none; }
.ui-list-title { margin: var(--space-4) 0 var(--space-2); font-size: 0.85em; font-weight: 600; color: var(--muted); }

/* A row: its leading visual (an icon badge, .ui-row-icon), its text (its name in bold, cut with an ellipsis, over its grey
   line, cut too), a figure at the right, a ⋯ (.ui-row-more) or a › (.ui-row-chevron). As a button or a link, it takes the
   hover's tint, padded so that the tint clears its text, and the map's routing shown is marked by a blue bar at its left.
   A row whose lines must be read whole (a kept trip's places and times), `.ui-row-wrap`, wraps them instead. */
.ui-row { display: flex; align-items: center; gap: var(--space-3); box-sizing: border-box; min-height: 48px; padding: var(--space-2) 0; }
.ui-list > :not([hidden]) ~ :not([hidden]), .ui-row + .ui-row { border-top: 1px solid var(--line); }
:is(button, a).ui-row {
  width: 100%; margin: 0; padding: var(--space-2); border: none; border-radius: var(--radius-s); background: none; color: var(--text);
  font: inherit; text-align: left; text-decoration: none; cursor: pointer;
}
:is(button, a).ui-row:is(:hover, :active):not(:disabled) { background: var(--hover); }
.ui-row[aria-current="true"] { box-shadow: inset 3px 0 0 var(--blue); }
button.ui-row:disabled { color: var(--control-disabled); cursor: not-allowed; }
button.ui-row:disabled :is(.ui-row-name, .ui-row-sub, .ui-row-figure, .ui-row-icon) { color: inherit; }
:is(button, a).ui-row:focus-visible, .ui-row-more:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
.ui-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.ui-row-name { max-width: 100%; overflow: hidden; color: var(--ink); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.ui-row-sub { max-width: 100%; overflow: hidden; color: var(--muted); font-size: 0.85em; text-overflow: ellipsis; white-space: nowrap; }
.ui-row-wrap :is(.ui-row-name, .ui-row-sub) { white-space: normal; overflow-wrap: anywhere; }
.ui-row-figure { flex-shrink: 0; margin-left: auto; color: var(--muted); font-size: 0.85em; font-variant-numeric: tabular-nums; text-align: right; }
.ui-row-more {
  flex-shrink: 0; width: 44px; height: 44px; padding: 0; border: none; border-radius: 50%; background: none; color: var(--ink);
  font: inherit; font-size: 1.3em; line-height: 1; cursor: pointer;
}
.ui-row-more:hover { background: var(--hover); }
.ui-row-chevron { flex-shrink: 0; color: var(--muted); }
/* A row that is a listbox's option (a search's result, in a popup): padded and rounded as a button row, tinted on hover
   and while the arrows choose it (aria-selected), the combobox keeping the focus; no hairline, which the rounded tint
   would bend at its ends, as between a menu's items. */
.ui-row[role="option"] { padding: var(--space-2); border-top: none; border-radius: var(--radius-s); cursor: pointer; }
.ui-row[role="option"]:is(:hover, [aria-selected="true"]) { background: var(--hover); }
/* The option the arrows chose: its tint barely shows on the popup, so a blue bar at its left marks it, as the routing shown. */
.ui-row[role="option"][aria-selected="true"] { box-shadow: inset 3px 0 0 var(--blue); }

/* The page's icons (routing.html's sprite, after <body>): drawn only where used. An SVG ignores `hidden`. */
.icon-sprite { display: none; }

/* An icon badge, a row's leading visual: a 32 px circle holding an 18 px stroke icon of the page's sprite
   (<svg viewBox="0 0 24 24"><use href="#icon-…"/></svg>); blue for the row of the action (data-tone="blue"). */
.ui-row-icon { flex-shrink: 0; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--control); color: var(--ink); }
.ui-row-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ui-row-icon[data-tone="blue"] { background: var(--hover); color: var(--blue-hover); }

/* A chip: a choice among a few (pressed: aria-pressed="true") or an action at once (never pressed). A pill drawn
   32 px tall, reaching a finger's 44 px through its ::before on a touch screen (below); its label wraps rather than
   be cut. The pressed chip's blue text is --blue-hover, at 4.5:1 on its --hover tint in both themes. */
.ui-chip {
  position: relative; box-sizing: border-box; min-height: 32px; max-width: 100%; padding: 2px var(--space-3);
  border: 1px solid var(--line); border-radius: var(--radius-pill); background: var(--surface); color: var(--text);
  font: inherit; font-size: 0.85em; overflow-wrap: anywhere; cursor: pointer;
}
.ui-chip:hover:not(:disabled) { background: var(--hover); }
.ui-chip[aria-pressed="true"] { border-color: var(--blue); background: var(--hover); color: var(--blue-hover); font-weight: 600; }
.ui-chip:disabled { color: var(--control-disabled); cursor: not-allowed; }
.ui-chip:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
/* Chips side by side, wrapping onto as many lines as they need. */
.ui-chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* A segmented control: its options on one track, muted, the chosen one raised and in --ink (a button aria-pressed="true",
   a tab aria-selected="true", or a label holding a checked radio, the radio itself hidden): on a dark track the raised fill barely shows, so the
   text tells the chosen option apart; --muted reads at 4.5:1 on --control in both themes. */
.ui-segmented { display: flex; gap: 2px; padding: 2px; border-radius: var(--radius-s); background: var(--control); }
.ui-segmented > * {
  position: relative; flex: 1 1 0; display: flex; align-items: center; justify-content: center; box-sizing: border-box;
  min-height: 32px; margin: 0; padding: 0 var(--space-2); border: none; border-radius: calc(var(--radius-s) - 2px);
  background: none; color: var(--muted); font: inherit; font-size: 0.9em; font-weight: 600; cursor: pointer;
}
.ui-segmented > :is([aria-pressed="true"], [aria-selected="true"], :has(input:checked)) { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px var(--shadow-ink); }
.ui-segmented > :is(button:focus-visible, :has(input:focus-visible)) { outline: 2px solid var(--blue); outline-offset: 1px; }
.ui-segmented input { position: absolute; opacity: 0; pointer-events: none; }

/* A switch: a checkbox drawn as its track, or a button (aria-pressed) whose track ends it as its ::after; white
   knob, blue once on. */
input.ui-switch, .ui-switch:not(input)::after {
  -webkit-appearance: none; appearance: none; content: ''; flex-shrink: 0; box-sizing: border-box;
  width: 36px; height: 21px; margin: 0; padding: 0; border: none; border-radius: var(--radius-pill);
  background-color: var(--control-off); background-image: radial-gradient(circle at 10.5px 50%, #fff 7.5px, transparent 8px);
  box-shadow: none; cursor: pointer; transition: background-color 0.15s, background-position 0.15s;
}
input.ui-switch:checked, .ui-switch[aria-pressed="true"]::after { background-color: var(--blue); background-position: 15px 0; }
.ui-switch:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* A button: 44 px tall, on --control. `.primary` fills it blue and flat (no glow), a darker blue on a dark page for its
   white to read at 4.5:1 (--primary-fill); `.danger` writes it red, `.danger.primary` fills it red. `.primary-button`, the
   compute bar's and the boat's first save, keeps its class and is drawn as `.ui-button.primary`. */
.ui-button, .primary-button {
  box-sizing: border-box; min-height: 44px; padding: 0 var(--space-4); border: none; border-radius: var(--radius-s);
  background: var(--control); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
}
.ui-button:not(.primary):hover:not(:disabled) { background: var(--hover); }
.ui-button.primary, .primary-button { background: var(--primary-fill); color: #fff; }
:is(.ui-button.primary:not(.danger), .primary-button):hover:not(:disabled) { background: var(--primary-fill-hover); }
.ui-button.danger { color: var(--error); }
.ui-button.danger.primary { background: var(--error); color: var(--surface); }
.ui-button:disabled { opacity: 0.6; cursor: default; }
:is(.ui-button.primary:not(.danger), .primary-button):disabled { opacity: 1; background: var(--blue-disabled); cursor: default; }
.ui-button:focus-visible, .primary-button:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
/* Two (or three) buttons side by side across the width, Cancel first and the action last; one under the other under
   280 px, where each one's basis grows past the width (above, it is negative, so 0), or when a label would wrap: each
   keeps its label on one line, unless the label is wider than the whole width. */
.ui-buttons { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.ui-buttons > * { flex: 1 1 calc((280px - 100%) * 999); min-width: fit-content; }

/* A popup: a card floating over the map or the page, on --surface, its hairline (the edge of a dark popup over the
   night map) and its shadow. A MapLibre popup's className, its content being the card, or a box of its own (the Layers
   popover, the ⋯ actions), whose own rules may place and pad it. A menu (`.ui-popup-menu`) has no tip, so MapLibre's
   square corner on the tip's side goes too. */
:where(.ui-popup:not(.maplibregl-popup)), .ui-popup > .maplibregl-popup-content {
  box-sizing: border-box; padding: 6px; border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--surface);
  color: var(--text); box-shadow: var(--shadow-float);
}
.ui-popup-menu .maplibregl-popup-tip { display: none; }
.ui-popup-menu.maplibregl-popup > .maplibregl-popup-content { border-radius: var(--radius-m); }
/* The tip of a popup pointing at its pin or barb laps over the card's hairline on its side. */
.ui-popup:is(.maplibregl-popup-anchor-top, .maplibregl-popup-anchor-top-left, .maplibregl-popup-anchor-top-right) .maplibregl-popup-tip { margin-bottom: -1px; }
.ui-popup:is(.maplibregl-popup-anchor-bottom, .maplibregl-popup-anchor-bottom-left, .maplibregl-popup-anchor-bottom-right) .maplibregl-popup-tip { margin-top: -1px; }
.ui-popup.maplibregl-popup-anchor-left .maplibregl-popup-tip { margin-right: -1px; }
.ui-popup.maplibregl-popup-anchor-right .maplibregl-popup-tip { margin-left: -1px; }
/* MapLibre's close button (the wind barbs' popup), in the card's top right corner: its hover tint, the page's, rounded as
   the card is inside its hairline, so that it stays within the corner. */
.ui-popup .maplibregl-popup-close-button { border-radius: 0 calc(var(--radius-m) - 1px) 0 var(--radius-s); }
.ui-popup .maplibregl-popup-close-button:hover { background: var(--hover); }

/* A menu's item: its 16 px icon (a stroke icon, or a trip point's dot), then its label, wrapping rather than widening
   the menu past the screen. The emphasized one (data-emphasis), the map menu's next point to place, blue on its tint,
   --blue-hover at 4.5:1 on --hover in both themes. */
.ui-menu-item {
  display: flex; align-items: center; gap: 10px; box-sizing: border-box; width: 100%; min-height: 40px; margin: 0;
  padding: 0 var(--space-3); border: none; border-radius: var(--radius-s); background: none; color: var(--text);
  font: inherit; text-align: left; cursor: pointer;
}
.ui-menu-item:hover { background: var(--hover); }
.ui-menu-item:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
.ui-menu-item[data-emphasis] { background: var(--hover); color: var(--blue-hover); font-weight: 600; }
.ui-menu-icon { flex-shrink: 0; display: grid; place-items: center; width: 16px; height: 16px; color: var(--muted); }
.ui-menu-icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
/* A trip point's dot (forms.css's .trip-dot), without the ring the itinerary draws round it. */
.ui-menu-icon > .trip-dot { box-shadow: none; }

/* A sheet's head: on a sheet from the foot of a vertical screen, its grabber on a line of its own, then the title and, at
   its right, the actions as blue words (.ui-sheet-action, no fill: --blue reads at 4.5:1 on the panel and the surface,
   --blue-hover on the hover's tint) or a ✕ (.ui-sheet-close); a grey line under the title tells more (.ui-sheet-sub).
   A dialog has the same head without the grabber. A grid, so that a menu as wide as its content (the ⋯ actions) is as
   wide as the longer of its title and grey line, not their sum. */
.ui-sheet-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: var(--space-2); }
.ui-sheet-grabber { grid-column: 1 / -1; position: relative; height: var(--space-4); }
.ui-sheet-grabber::before {
  content: ''; position: absolute; top: 0; left: 50%; width: 36px; height: 5px; margin-left: -18px; border-radius: 3px;
  background: var(--muted); opacity: 0.5;
}
.ui-sheet-title { min-width: 0; margin: 0; font-size: 1.1em; font-weight: 700; color: var(--ink); overflow-wrap: anywhere; }
.ui-sheet-sub { grid-column: 1; margin: 2px 0 0; color: var(--muted); font-size: 0.85em; }
.ui-sheet-action {
  flex-shrink: 0; display: inline-flex; align-items: center; gap: 4px; box-sizing: border-box; min-height: 44px; padding: 0 var(--space-2);
  border: none; border-radius: var(--radius-s); background: none; color: var(--blue); font: inherit; font-size: 0.9em;
  font-weight: 600; text-decoration: none; cursor: pointer;
}
.ui-sheet-action[hidden] { display: none; }
.ui-sheet-action:hover:not(:disabled) { background: var(--hover); color: var(--blue-hover); }
.ui-sheet-action:disabled { color: var(--control-disabled); cursor: default; }
.ui-sheet-close {
  flex-shrink: 0; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: none; border-radius: 50%;
  background: none; color: var(--muted); cursor: pointer;
}
.ui-sheet-close:hover { background: var(--hover); color: var(--ink); }
.ui-sheet-close svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.ui-sheet-action:focus-visible, .ui-sheet-close:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }

/* A field: its label above (.ui-field-label, muted), its control 4 px under it (forms.css's input), the next field 12 px
   under that. A label holding its control, or a box holding a label and its control. */
.ui-field { display: block; margin: 0; font-size: inherit; font-weight: 400; color: var(--text); }
.ui-field + .ui-field { margin-top: var(--space-3); }
.ui-field-label { display: block; margin: 0; font-size: 0.85em; font-weight: 500; color: var(--muted); }
.ui-field-label + *, .ui-field > :is(input, select, textarea) { margin-top: var(--space-1); }

/* Fields folded under one line: a <details> without frame, its summary a + then its words in blue, 44 px tall, a − once
   open, its fields unfolding in place. */
.ui-more { margin: 0; padding: 0; border: none; border-radius: 0; background: none; box-shadow: none; }
.ui-more > summary {
  display: block; box-sizing: border-box; min-height: 44px; padding: var(--space-3) 0; color: var(--blue); font-size: 0.9em;
  font-weight: 600; letter-spacing: normal; text-transform: none; list-style: none; cursor: pointer;
}
.ui-more > summary::-webkit-details-marker { display: none; }
.ui-more > summary::before {
  content: ''; display: inline-block; width: 11px; height: 11px; margin-right: var(--space-2); vertical-align: 0;
  background: linear-gradient(currentColor, currentColor) center / 100% 2px no-repeat, linear-gradient(currentColor, currentColor) center / 2px 100% no-repeat;
}
.ui-more[open] > summary::before { background: linear-gradient(currentColor, currentColor) center / 100% 2px no-repeat; }
.ui-more[open] > summary { margin-bottom: var(--space-1); }
.ui-more > summary:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* A status line: what a screen tells of its state, 0.85em in the body's font (a <pre>'s too), muted. Its tone, in
   data-tone: `ok` green, led by a ✓ no screen reader reads; `waiting` and `offline` amber on their band, what waits;
   `error` red, without fill. Never a box with a border; an empty one draws no band. */
.ui-status { color: var(--muted); font-family: inherit; font-size: 0.85em; line-height: 1.4; }
.ui-status[data-tone="ok"] { color: var(--ok); }
.ui-status[data-tone="ok"]::before { content: '✓'; content: '✓' / ''; margin-right: var(--space-1); font-weight: 700; }
.ui-status:is([data-tone="waiting"], [data-tone="offline"]) { padding: 6px 10px; border-radius: var(--radius-s); background: var(--amber-bg); color: var(--amber); }
.ui-status[data-tone="error"] { color: var(--error); }
.ui-status:empty { padding: 0; background: none; }

/* A toast: a band inverted from the page (its ink as ground), opaque over whatever it covers, rounded and floating, 44 px
   tall; its text, then its action bold in --toast-action without underline, and its ✕ when it has one. The undo toasts
   and the toasts at the top of the screen; the map's notifications are .map-toast (routing.html). One shows at a time in
   a place. */
.ui-toast {
  display: flex; align-items: center; gap: var(--space-3); box-sizing: border-box; min-height: 44px; margin: 0; padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-m); background: var(--toast-bg); color: var(--toast-ink); box-shadow: var(--shadow-float); line-height: 1.3;
}
.ui-toast[hidden] { display: none; }
.ui-toast-text { flex: 1; min-width: 0; }
/* Its action and its ✕ 44 px tall, as tall as the band: they lap over its padding rather than heighten it. */
.ui-toast-action {
  flex-shrink: 0; min-height: 44px; margin: calc(var(--space-2) * -1) 0; padding: 0 var(--space-2); border: none; border-radius: var(--radius-s);
  background: none; color: var(--toast-action); font: inherit; font-weight: 700; text-decoration: none; white-space: nowrap; cursor: pointer;
}
.ui-toast-text + .ui-toast-action { margin-left: auto; }
.ui-toast-close {
  display: grid; place-items: center; flex-shrink: 0; width: 44px; height: 44px; margin: calc(var(--space-2) * -1) calc(var(--space-2) * -1) calc(var(--space-2) * -1) 0;
  padding: 0; border: none; border-radius: var(--radius-s); background: none; color: var(--toast-ink); cursor: pointer;
}
.ui-toast-close svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.ui-toast :is(.ui-toast-action, .ui-toast-close):focus-visible { outline: 2px solid var(--toast-action); outline-offset: -2px; }

/* A finger's reach, 44 px, on a touch screen. */
@media (pointer: coarse) {
  .ui-chip::before { content: ''; position: absolute; inset: -7px 0; }
  /* Wrapped chips' reaches meeting, not overlapping. */
  .ui-chips { row-gap: 14px; }
  .ui-segmented > * { min-height: 40px; }
  /* An option drawn smaller still (the timeline's sort, over its axis) reaches 44 px above and below itself. */
  .ui-segmented > *::before { content: ''; position: absolute; inset: min(0px, calc((100% - 44px) / 2)) 0; }
  .ui-menu-item { min-height: 44px; }
}
