/* Springwater Plow — design system per references/DESIGN-R2.md.
 * The :root token values below are CONTRACTUAL: tests/test_design.py asserts
 * every one of them verbatim. Do not "improve" the palette. */
:root {
  --bg-0: #0b0f14;        /* page background */
  --bg-1: #11161d;        /* header/nav */
  --surface: #161d26;     /* cards, panels */
  --surface-2: #1d2631;   /* hover, inputs */
  --line: rgba(255,255,255,0.08);
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #f79916;      /* brand orange — primary buttons, links, focus */
  --accent-ink: #14100a;  /* text on accent */
  --focus: rgba(247,153,22,0.55);
  --green: #2ea043;  --yellow: #eaea0b;  --blue: #3b82f6;
  --purple: #8b5cf6;  --orange: #f79916;  --red: #ef4444;  --tan: #c49d62;
  --cyan: #22d3ee;    /* watch pins */
  --radius-s: 6px;  --radius-m: 10px;  --radius-l: 14px;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 24px; --space-6: 32px;
  --shadow-1: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-2: 0 4px 16px rgba(0,0,0,0.45);
  --ease: 150ms ease;
}

* { box-sizing: border-box; }
/* R2-F3: app shell. The header is a 48px flex item and every page fills the
 * space that is left, so the document itself is exactly one viewport tall
 * (no more 48px of dead scroll below the fold on any page). */
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;            /* body */
  line-height: 1.5;
  font-weight: 400;
  background: var(--bg-0);
  color: var(--text);
}
main { flex: 1 1 auto; min-height: 0; }
a { color: var(--accent); text-decoration: none; }
/* R2-F6: links must not rely on colour alone — the underline appears on hover
 * *and* on keyboard focus (the footer "Create one"/"Log in" links are the
 * plainest case, but this is global so every link behaves the same). */
a:hover, a:focus-visible { text-decoration: underline; }
h1, h2, h3 { font-weight: 700; }
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.skip-link {
  position: absolute;
  left: var(--space-2);
  top: -40px;
  z-index: 2000;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: var(--space-2) var(--space-3);
  transition: top var(--ease);
}
.skip-link:focus-visible { top: var(--space-2); }

/* --- Header (48px, --bg-1) ------------------------------------------- */
.app-header {
  height: 48px;
  flex: 0 0 auto;             /* R2-F3: fixed-height bar, never shrinks */
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
  gap: var(--space-3);
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text);
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
}
.brand .brand-mark { color: var(--accent); font-size: 18px; }
.header-nav { display: flex; align-items: center; gap: var(--space-3); }
.header-nav a { color: var(--muted); font-weight: 600; font-size: 14px; }
.header-nav a:hover, .header-nav a[aria-current="page"] {
  color: var(--text);
  text-decoration: none;
}
.user-chip { position: relative; }
.user-chip-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: var(--space-1) var(--space-3);
  cursor: pointer;
  transition: background var(--ease);
}
.user-chip-btn:hover { background: var(--surface-2); }
.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
}
.user-menu {
  position: absolute;
  right: 0;
  top: calc(100% + var(--space-2));
  min-width: 160px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-2);
  padding: var(--space-1);
  display: none;
  z-index: 1500;
}
.user-menu.open { display: block; }
.user-menu button, .user-menu a {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  font: inherit;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-s);
  cursor: pointer;
}
.user-menu button:hover, .user-menu a:hover {
  background: var(--surface-2);
  text-decoration: none;
}

/* --- Buttons ------------------------------------------------------------ */
.btn {
  display: inline-block;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-s);
  padding: var(--space-2) var(--space-4);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease),
              opacity var(--ease);
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #ffab2e; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--red); color: #ffffff; }
.btn-danger:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* --- Forms ---------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.field input, .field select {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  padding: var(--space-2) var(--space-3);
  /* Inputs default to a size=20 intrinsic width; inside flex rows that
   * min-content can push the whole page wider than a 390px viewport. */
  min-width: 0;
}
.field input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
/* R2-F4: a saved secret is shown masked (R15) as the placeholder while the
 * value stays empty. settings.js puts .field-filled on any field that has a
 * mask or a typed value, which promotes it to --text; the muted gray is left
 * for fields that are genuinely empty. */
.field input::placeholder { color: var(--muted); opacity: 1; }
.field input.field-filled { color: var(--text); }
.field input.field-filled::placeholder { color: var(--text); opacity: 1; }
/* Show/hide toggle inside the token field. */
.field-input { position: relative; display: flex; }
.field-input input {
  flex: 1 1 auto;
  padding-right: calc(var(--space-5) + var(--space-1));
}
.field-eye {
  position: absolute;
  right: var(--space-1);
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-s);
}
.field-eye:hover { color: var(--text); background: var(--surface-2); }
.field-error { font-size: 12px; color: var(--red); min-height: 1em; }

/* --- Cards ----------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-1);
  padding: var(--space-4);
}
.card-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0 0 var(--space-3);
}

/* --- Badges (bucket colors at 18% alpha bg, bucket color text) ------------ */
.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}
/* R2-F8: the green badge is the one operators actually act on ("1 h or less"),
 * and --green (#2ea043) on the 18%-tinted pill only reaches ~3.9:1. The pill
 * fill is unchanged; the text is the brighter mint from DESIGN-R2's palette
 * family (#86efac), which measures ~9.4:1 on the composited pill. */
.badge-green  { background: rgba(46,160,67,0.18);  color: #86efac; }
.badge-yellow { background: rgba(234,234,11,0.18); color: var(--yellow); }
.badge-blue   { background: rgba(59,130,246,0.18); color: var(--blue); }
.badge-purple { background: rgba(139,92,246,0.18); color: var(--purple); }
.badge-orange { background: rgba(247,153,22,0.18); color: var(--orange); }
.badge-red    { background: rgba(239,68,68,0.18);  color: var(--red); }
.badge-tan    { background: rgba(196,157,98,0.18); color: var(--tan); }
.badge-unknown { background: rgba(139,152,165,0.18); color: var(--muted); }

/* --- Toasts (fixed bottom-right stack, auto-dismiss 4 s) ------------------ */
.toast-stack {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 3000;
  max-width: 340px;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-2);
  color: var(--text);
  padding: var(--space-3) var(--space-4);
  font-size: 14px;
  animation: toast-in 150ms ease;
}
.toast-error { border-left-color: var(--red); }
.toast-ok { border-left-color: var(--green); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* --- Empty state / skeleton ------------------------------------------------ */
.empty-state {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: var(--space-6) var(--space-4);
}
.skeleton {
  height: 16px;
  border-radius: var(--radius-s);
  background: linear-gradient(90deg, var(--surface-2) 25%,
                              var(--line) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  margin: var(--space-2) 0;
}
@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* --- Modal (dimmed overlay, centered card) ---------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2500;
}
.modal.open { display: flex; }
.modal .modal-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-2);
  padding: var(--space-5);
  max-width: 420px;
  width: calc(100% - var(--space-6));
}
.modal .modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

/* --- Toggle (36px pill switch, checked = --accent) ---------------------------- */
.toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex: 0 0 auto;
}
.toggle input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.toggle .toggle-track {
  position: absolute;
  inset: 0;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: background var(--ease);
  pointer-events: none;
}
.toggle .toggle-track::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform var(--ease), background var(--ease);
}
.toggle input:checked + .toggle-track {
  background: var(--accent);
  border-color: var(--accent);
}
.toggle input:checked + .toggle-track::after {
  transform: translateX(16px);
  background: var(--accent-ink);
}
.toggle input:focus-visible + .toggle-track {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* --- Table (watch list rows) -------------------------------------------------- */
/* R2-F7: these tables were auto-layout, so a long address squeezed Bucket/ETA
 * into 90/92/43/33px columns and one row measured 137px tall (4-line stacks,
 * top-aligned cells, × detached at the row top). Fixed layout + explicit
 * column widths make the address the only flexible column, Bucket/ETA can never
 * wrap, every cell sits on the row's middle line and the delete button is
 * centred in its cell. The row height is now bounded: the tallest thing in a
 * row is either one line of 16px address (22.4px) or the 28px × target, so a
 * single-line row is 28 + 2*4px padding + 1px rule = 37px and the worst case
 * (the address is clamped at two lines) is 2*22.4 + 8 + 1 = 53.8px. */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  table-layout: fixed;
}
.table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: var(--space-1) var(--space-2);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  overflow-wrap: anywhere;
}
.table td {
  padding: var(--space-1) var(--space-2);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.table tr:hover td { background: var(--surface-2); }
/* Column widths in DESIGN-R2 §3 order (address, badge, ETA, delete): the
 * address is the flexible column and the other three take the ~30/18/8% shares
 * the review prescribes. On the 640px settings column those shares are
 * comfortable (163/98/43px) and the address keeps ~239px, so a real address is
 * one line. */
.table .col-addr { width: auto; }
.table .col-bucket { width: 30%; }
.table .col-eta { width: 18%; }
.table .col-del { width: 8%; }
/* Bucket + ETA are short fixed strings — they must never wrap. */
.table .col-bucket, .table .col-eta { white-space: nowrap; }
/* The address breaks instead of pushing the row wider, and is capped at two
 * lines so a long address cannot re-create the 4-line stack. */
.table .addr {
  font-size: 16px;
  line-height: 1.4;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
/* R3-F2: the geocoder's canonical display name, muted under the typed
 * address; it inherits the address cell's two-line clamp. */
.table .addr .addr-resolved {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
/* Delete cell: the button is centred in the cell (and vertically, via the
 * td's vertical-align: middle) instead of floating at the row top. Its own
 * gutters are the tighter --space-1 so an 8% column still clears the 28px
 * target (8% of the 543px settings table = 43px - 8px = 35px of content box). */
.table .col-del {
  text-align: center;
  padding-left: var(--space-1);
  padding-right: var(--space-1);
}
/* The 340px map sidebar is the hard case: its table is only ~258px wide, and
 * there 30/18/8% (77/46/21px) is narrower than the "not serviced" badge
 * (89.5px measured), a worst-case "~720 min" (61px measured; predict.ETA_MAX_MIN
 * clamps the ETA to 12 h) and the 28px × target — the columns would clip or run
 * into each other. In the sidebar the three fixed columns therefore get
 * content-sized px widths with a 2px gutter and the address keeps the remaining
 * 66px (58px of content box, enough for "Main St" at 56.2px on one line),
 * wrapping to at most two lines (54px) exactly as the review allows. */
#panel .table th, #panel .table td {
  padding-left: var(--space-1);
  padding-right: var(--space-1);
}
#panel .table .col-bucket, #panel .table .col-eta, #panel .table .col-del {
  padding-left: 2px;
  padding-right: 2px;
}
#panel .table .col-bucket { width: 72px; }   /* R2-F7b: short badge label (<=68px) + 2*2px gutter */
#panel .table .col-eta { width: 66px; }      /* 61px "~720 min" + 2*2px */
/* R2-F7b: in the narrow sidebar the address is a single ellipsised line — the
 * full address is available in the pin tooltip and the row title, so the row
 * stays a tidy 37px line instead of a 2-line stack with an orphaned "45". */
#panel .table .addr {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  -webkit-line-clamp: unset;
}
#panel .table .col-del { width: 32px; }      /* 28px target + 2*2px */
/* R2-F7: the × is a flex box so it sits dead centre of its cell (the td is
 * text-align: center horizontally, vertical-align: middle vertically) instead
 * of hanging off the row top.
 * R2-F8: it is also a real 28x28 target (measured 28x28 in headless Chrome;
 * the old padding-only box was 24x24 with a 16px glyph) with the glyph at 18px,
 * and it brightens to --text on both hover and keyboard focus, with a visible
 * focus ring so the row is reachable without a mouse. */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--radius-s);
  transition: color var(--ease), background var(--ease);
}
.icon-btn:hover,
.icon-btn:focus-visible {
  color: var(--text);
  background: var(--surface-2);
}
.icon-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

/* --- Map page layout ----------------------------------------------------------- */
/* R2-F3: .map-page is a flex child of the shell (no 100vh of its own), so the
 * map + panel row exactly fills the height under the 48px header. */
.map-page {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
.map-row { display: flex; flex: 1; min-height: 0; overflow: hidden; }
#map { flex: 1 1 auto; min-width: 320px; overflow: hidden; }
#panel {
  flex: 0 0 340px;
  overflow-y: auto;           /* R2-F3: the panel scrolls, not the document */
  padding: var(--space-4);
  border-left: 1px solid var(--line);
  background: var(--bg-0);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
#panel .card + .card { margin-top: 0; }
@media (max-width: 900px) {
  .map-row { flex-direction: column; }
  #map { height: 55vh; flex: 0 0 auto; }
  #panel { flex: 1 1 auto; border-left: none; border-top: 1px solid var(--line); }
}

/* --- Auth pages (centered card, max-width 380px, --shadow-2) ------------------ */
/* R2-F3: centres the card in the space left under the header (100vh here made
 * the page 48px taller than the viewport). */
.auth-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  overflow: auto;
}
.auth-card {
  margin: auto;               /* auto margins centre without clipping */
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-2);
  padding: var(--space-5);
}
.auth-card h1 { font-size: 28px; margin: 0 0 var(--space-2); }
.auth-card .auth-sub { color: var(--muted); margin: 0 0 var(--space-4); }
.auth-card form { display: flex; flex-direction: column; gap: var(--space-4); }
.auth-links {
  margin-top: var(--space-4);
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}

/* --- Settings page (centered column max-width 640px) ---------------------------- */
.settings-wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  flex: 1 1 auto;             /* R2-F3: fill under the header, scroll in place */
  min-height: 0;
  overflow: auto;
}
.settings-wrap h1 { font-size: 28px; margin: 0; }
.settings-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-1);
  padding: var(--space-5);
}
.settings-card h2 {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 var(--space-4);
}
.settings-card .fields {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.setting-row .setting-label { font-weight: 600; }
.setting-row .setting-help {
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
}
.settings-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-4);
  align-items: center;
}
/* R2-F2: address management card — add field beside its button, watch rows
 * reuse the .table / .badge / .icon-btn components from the map panel. */
.settings-card .settings-help {
  font-size: 13px;
  color: var(--muted);
  margin: calc(0px - var(--space-3)) 0 var(--space-4);
}
/* R2-F8: 12px (--space-3) between the address input and the Add button —
 * --space-2 read as one clumped control. */
.addr-form {
  display: flex;
  align-items: flex-end;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
/* min-width:0 so the input's size=20 intrinsic width cannot stretch the
 * form (and on narrow screens the whole page) past its container. */
.addr-form .field { flex: 1 1 auto; min-width: 0; }
.addr-form .btn { flex: 0 0 auto; }

/* --- Leaflet / map specifics ---------------------------------------------------- */
.leaflet-container { background: var(--bg-0); }
/* Dark basemap without a paid tile provider (DESIGN-R2 §4) */
.leaflet-tile-pane {
  filter: invert(0.92) hue-rotate(180deg) brightness(0.9) contrast(0.9) saturate(0.7);
}
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-2);
}
.leaflet-tooltip.watch-tip {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}
.leaflet-control-attribution {
  background: rgba(17, 22, 29, 0.8) !important;
  color: var(--muted) !important;
}
.leaflet-control-attribution a { color: var(--accent) !important; }

/* Plow markers: SVG arrow rotated to heading (0° = north), --accent stroke */
.plow-marker { background: none; border: none; }
.plow-arrow { width: 22px; height: 22px; display: block; }
.plow-arrow svg {
  width: 22px;
  height: 22px;
  display: block;
  transform-origin: 50% 50%;
}
.plow-arrow svg path { stroke: var(--accent); stroke-width: 2; fill: none; }
/* R2-F5: a stale plow keeps the same arrow shape and stays in the plow glyph
 * family — it is muted (--muted stroke, 55% opacity), never the near-white the
 * inherited --text colour made it look like against the dark basemap. Fresh
 * plows keep the --accent stroke plus the pulse ring. */
.plow-marker.stale {
  color: var(--muted);          /* nothing here may inherit --text */
  opacity: 0.55;
}
.plow-marker.stale .plow-arrow svg path {
  stroke: var(--muted);
  fill: none;
}
.plow-marker.fresh .plow-arrow svg path { fill: rgba(247,153,22,0.25); }
.plow-pulse {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  animation: plow-pulse 2s ease-out infinite;
  pointer-events: none;
}
@keyframes plow-pulse {
  from { transform: scale(0.6); opacity: 0.9; }
  to   { transform: scale(1.9); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .plow-pulse { animation: none; opacity: 0.5; }
  .skeleton, .toast { animation: none; }
}

/* Watch markers: --cyan teardrop (22px) + address label chip */
.watch-pin { background: none; border: none; }
.watch-pin-shape {
  width: 22px;
  height: 22px;
  margin: 0 auto;
  background: var(--cyan);
  border: 2px solid rgba(11, 15, 20, 0.9);
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: var(--shadow-1);
}
/* Base chip look. The truncating rules below are overridden for the real pin
 * tooltip by .leaflet-tooltip.watch-chip (R2-F8) — see that block. */
.watch-chip {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font-size: 12px;
  padding: 1px 8px;
  text-align: center;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* R2-F8: the pin chip used to clip at 140px with an ellipsis, so the address an
 * operator pinned was never readable ("1234 Wellington Sprotet Road, Well…" —
 * 260px of text in a 124px box). The tooltip now gets a wider box and wraps to
 * two lines instead of truncating, and the stadium radius becomes --radius-s so
 * wrapped text is not clipped by the pill corners. */
.leaflet-tooltip.watch-chip {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  color: var(--text);
  font-size: 12px;
  padding: var(--space-1) var(--space-2);
  max-width: 320px;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  line-height: 1.35;
}
.leaflet-tooltip.watch-chip::before { display: none; }

/* Selected segment halo (colour/weight set by Leaflet; DESIGN-R2 §4) */
.segment-halo { opacity: 0.9; }
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Offline chip (one-time, on tileerror) */
.tile-offline-chip {
  position: absolute;
  top: var(--space-2);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: var(--space-1) var(--space-2);
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
}

/* Legend: bottom-left card, swatch + label + live count, "as of HH:MM EDT" */
.map-legend {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow-1);
  padding: var(--space-3);
  font-size: 12px;
  color: var(--text);
  line-height: 1.6;
  min-width: 150px;
}
.map-legend .legend-title {
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-1);
}
.map-legend .legend-items { list-style: none; margin: 0; padding: 0; }
.map-legend .legend-items li {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 1px 0;
}
.map-legend .legend-items li .legend-count {
  margin-left: auto;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.map-legend .swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  flex: 0 0 auto;
}
.map-legend .legend-asof {
  margin-top: var(--space-2);
  color: var(--muted);
  font-size: 12px;
}

/* Sidebar lists */
.kv div { padding: 2px 0; font-size: 14px; }
.kv b { color: var(--muted); font-weight: 600; }
.list { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.list li {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-1) 0;
  border-bottom: 1px solid var(--line);
}
.list li:last-child { border-bottom: none; }
/* F6: Recent Transitions feed scrolls instead of clipping the last entry */
#event-feed { max-height: 18rem; overflow-y: auto; }
#next-list li { justify-content: flex-start; }
#watch-form { display: flex; flex-direction: column; gap: var(--space-3); }
#watch-form .form-row { display: flex; gap: var(--space-2); }
#watch-form .form-row .btn { flex: 0 0 auto; }
#watch-form .field { flex: 1 1 auto; }
.msg { color: var(--muted); font-size: 12px; min-height: 1em; }

/* R3-F6: the legend collapse chip is a mobile affordance only — on desktop
 * the card is always expanded and the chip is hidden. */
.map-legend .legend-toggle { display: none; }

/* --- R3-F6: mobile pass (390px) --------------------------------------------
 * Fixes the vision audit at 390px: ellipsised username, collapsible legend,
 * >=44px tap targets, natural-flow panel below the map, single-line addresses.
 * Additive only — desktop rules above are untouched. */
@media (max-width: 480px) {
  /* Header: the 13px wordmark + nav + 140px chip still measured ~441px at
   * 390px (audit: "brand+nav+user chip don't fit"), so below 480px the wordmark
   * is dropped and only the snowflake mark remains as the home link (the
   * anchors carry aria-label="Springwater Plow" for the accessible name).
   * Username ellipsises instead of clipping. */
  .app-header { padding: 0 var(--space-2); gap: var(--space-2); }
  .brand { font-size: 0; gap: 0; }
  .brand .brand-mark { font-size: 18px; }
  .user-chip-btn { min-height: 44px; max-width: 140px; overflow: hidden; }
  .user-chip-btn .user-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }
  /* Nav links: tighter spacing, but the tap target stays >= 44px */
  .header-nav { gap: 0; }
  .header-nav a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 var(--space-3);
  }
  /* Watch panel flows naturally below the map; the document scrolls */
  .map-row { overflow: visible; }
  #map { height: 50vh; }
  #panel { flex: 0 0 auto; overflow-y: visible; }
  #event-feed { max-height: none; }
  /* Legend collapsed by default behind a compact chip */
  .map-legend { min-width: 0; max-width: 220px; padding: var(--space-2); }
  .map-legend .legend-toggle {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 var(--space-3);
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--text);
    font: inherit;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
  }
  .map-legend .legend-body { display: none; }
  .map-legend.legend-open .legend-body { display: block; }
  .map-legend.legend-open .legend-toggle { margin-bottom: var(--space-2); }
  /* >= 44px touch targets: Leaflet zoom, row delete, toggle switches.
   * The .leaflet-touch selector is needed because on touch devices Leaflet
   * adds .leaflet-touch to the map pane and its own
   * `.leaflet-touch .leaflet-bar a` rule (0,2,1) sets 30px — a plain
   * `.leaflet-control-zoom a` (0,1,1) loses to it. */
  .leaflet-control-zoom a,
  .leaflet-touch .leaflet-control-zoom a {
    width: 44px; height: 44px; line-height: 44px;
  }
  .icon-btn { width: 44px; height: 44px; }
  #panel .table .col-del { width: 48px; }
  /* The settings table's 8% delete column (~29px at 390px) is narrower than
   * the 44px target — give it a fixed 44px + 2*--space-1 gutter. */
  .table .col-del { width: 52px; }
  .toggle input {
    top: -12px;
    bottom: -12px;
    left: -8px;
    right: -8px;
    width: auto;
    height: auto;
  }
  /* Address cells: single-line ellipsis (full text in the row title) */
  .table .addr {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    -webkit-line-clamp: unset;
  }
}
