:root {
  /* Palette. Neutrals are tinted toward the brand blue (hue ~250,
   * chroma 0.008-0.016) so backgrounds and borders feel cohesive with
   * the accent without reading as "tinted". The accent is a saturated
   * cobalt; all chrome (active nav, focus rings, progress, selection,
   * map polyline, primary CTAs) routes through it. */
  /* Lifted off near-black: at oklch(0.15) (≈#0b0d10) the GPU dithers the dark
   * fill into a faint two-tone stripe (≈#090b0e/#0d0f11) across large bare-bg
   * areas (login, open export panel). Raising it a few levels clears the
   * near-black dithering zone while staying clearly darker than --panel, so
   * cards still read as lighter surfaces. Flat sRGB hex (keeps a faint blue
   * tint: blue > red); --panel* stay oklch — they're lighter and don't band. */
  --bg: #15171c;
  --panel: oklch(0.20 0.010 250);
  --panel-2: oklch(0.25 0.012 250);
  --panel-3: oklch(0.30 0.014 250);
  --border: oklch(0.32 0.014 250);
  --border-hover: oklch(0.40 0.016 250);
  --text: oklch(0.94 0.008 250);
  --muted: oklch(0.66 0.018 250);

  /* Accent: cobalt. Sits a touch brighter than the legacy #4c8dff
   * (≈ oklch 0.65/0.18) so dark text passes WCAG AA on top — the
   * original white-on-cobalt was a 2.5:1 contrast fail. */
  --accent: oklch(0.68 0.19 258);
  --accent-08: oklch(0.68 0.19 258 / 0.08);
  --accent-10: oklch(0.68 0.19 258 / 0.10);
  --accent-18: oklch(0.68 0.19 258 / 0.18);
  --accent-35: oklch(0.68 0.19 258 / 0.35);
  --accent-45: oklch(0.68 0.19 258 / 0.45);
  --accent-85: oklch(0.68 0.19 258 / 0.85);
  --on-accent: oklch(0.15 0.008 250); /* dark text on cobalt buttons */

  /* Semantic. --err comes in two lightnesses because the saturated red
   * used to fail AA contrast for text (audit flagged 4.12:1). The
   * lighter --err-text is for inline error copy; --err itself stays
   * for fills and borders. */
  --ok: oklch(0.74 0.16 145);
  --warn: oklch(0.82 0.16 85);
  --skip: oklch(0.72 0.11 300);   /* skipped: a distinct muted violet */
  --err: oklch(0.62 0.20 28);
  --err-text: oklch(0.76 0.18 28);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
[hidden] { display: none !important; }
body {
  font-family: -apple-system, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* Visually-hidden but reachable by screen readers.
 * Used for the password field label and for any future
 * decorative-icon labels. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Skip-to-content link. Off-screen until a keyboard user
 * tabs to it, at which point it floats over the header. */
.skip-link {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 8px 14px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  z-index: 10000;
  transform: translateY(-200%);
  transition: transform 160ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.skip-link:focus-visible {
  transform: translateY(0);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-35);
}

/* Universal focus ring. The desktop browser default is a 2px
 * grey outline that vanishes against --panel; this replaces it
 * with the brand accent at every interactive surface that
 * doesn't already define its own focus style. Uses :focus-visible
 * so mouse clicks don't get a permanent ring. */
:where(
  button,
  a,
  input,
  select,
  textarea,
  summary,
  [tabindex]
):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}
.icon-btn:focus-visible,
.settings-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
nav a:focus-visible {
  outline-offset: 0;
  background: var(--accent-10);
}
.settings-nav-link:focus-visible {
  outline-offset: -2px;
}
a { color: var(--accent); text-decoration: none; }
button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}
button:hover { background: var(--panel-3); }
input, select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 8px;
  border-radius: 6px;
}
/* Every native check/radio gets the brand amber. The settings pane
 * and journey-check rules used to set this individually; this base
 * declaration covers the filter strips, clip-pair ticks, queue-day
 * checkboxes, and modal autoplay too. */
input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--accent);
}

/* Reusable tooltip — positioned on <body> by the Tooltips block in app.js.
 * pointer-events:none so it never steals hover or affects layout. */
.tooltip {
  position: fixed; z-index: 1000; max-width: 280px;
  padding: 6px 9px; border-radius: 6px;
  background: var(--panel-3); color: var(--text);
  border: 1px solid var(--border);
  font-size: 0.8rem; line-height: 1.35;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.tooltip[hidden] { display: none; }
.tooltip::after {
  content: ""; position: absolute; left: var(--tip-arrow, 50%);
  transform: translateX(-50%); border: 6px solid transparent;
}
.tooltip[data-placement="top"]::after {
  top: 100%; border-top-color: var(--panel-3);
}
.tooltip[data-placement="bottom"]::after {
  bottom: 100%; border-bottom-color: var(--panel-3);
}

.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0;
  border-radius: 50%;
}
.icon-btn:hover { background: var(--panel-3); }
.icon-btn.active { color: var(--ok); border-color: var(--ok); }
/* Waiting: match the sync-status badge's amber so the button and badge
 * read as the same state. */
.icon-btn.waiting { color: var(--warn); border-color: var(--warn); }
.icon-btn.triaging { color: var(--accent); border-color: var(--accent); }
/* When the syncing icon is the visible one, give it a gentle
 * continuous spin so the button reads as "in progress". */
.icon-btn.active #sync-icon-sync:not([hidden]) {
  animation: vfs-spin 1.6s linear infinite;
  transform-origin: 50% 50%;
}
.icon-btn.triaging #sync-icon-sync:not([hidden]) {
  animation: vfs-spin 1.6s linear infinite;
  transform-origin: 50% 50%;
}
@keyframes vfs-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
/* In "waiting" state we still show the sync icon, but static. The
 * .active class drives the spin; .waiting suppresses it. */
#sync-toggle.waiting #sync-icon-sync {
  animation: none;
}
#sync-toggle.error #sync-icon-warning {
  /* Subtle pulse on the warning icon so the user notices a fault state
   * without it being too aggressive. */
  animation: warn-pulse 2s ease-in-out infinite;
}
@keyframes warn-pulse {
  0%, 100% { opacity: 0.9; }
  50% { opacity: 0.6; }
}
.icon-btn.paused {
  color: var(--err-text);
  border-color: var(--err);
  animation: pulse-red 2s ease-in-out infinite;
}
@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 4px oklch(0.62 0.20 28 / 0.3); }
  50% { box-shadow: 0 0 12px oklch(0.62 0.20 28 / 0.7); }
}
.cancel-btn {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 18px; padding: 0 4px;
  line-height: 1;
}
.cancel-btn:hover { color: var(--err-text); }
.current-header {
  display: flex; align-items: center; gap: 8px;
}
.current-header .spacer { flex: 1; }
.view { min-height: 100vh; }
.error { color: var(--err-text); margin-top: 8px; min-height: 1em; }

/* Login */
#login { display: flex; align-items: center; justify-content: center; }
#login-form {
  background: var(--panel);
  padding: 32px;
  border-radius: 12px;
  border: 1px solid var(--border);
  min-width: 320px;
}
#login-form h1 { margin-top: 0; }
#login-form input { width: 100%; margin: 8px 0; }
#login-form button {
  width: 100%;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  padding: 10px 12px;
}
#login-form button:hover { filter: brightness(1.06); background: var(--accent); }

/* App chrome */
/* The bar itself is full-bleed: background + border span the viewport. */
#app header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
/* The content inside is constrained to the same 1400px column as <main>
 * and centred, so the brand / nav / actions line up with the page body
 * on wide screens instead of hugging the viewport edge. */
#app header .header-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 24px;
}
#app header h1 { margin: 0; font-size: 18px; }
nav a {
  padding: 6px 12px;
  border-radius: 6px;
}
nav a.active { background: var(--panel-2); }

/* Settings cog — top-right icon link. Same 34x34 footprint as
 * the sync-toggle .icon-btn but its own active/hover styling so
 * it doesn't pick up the icon-btn's "syncing-green" treatment. */
.settings-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid transparent;
  transition: color 120ms ease, background 120ms ease,
              border-color 120ms ease;
}
.settings-link:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}
.settings-link.active {
  color: var(--text);
  background: var(--panel-2);
  border-color: var(--border);
}
.spacer { flex: 1; }
.status {
  display: inline-flex; align-items: center;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 12px;
}
/* Four-state sync status badge. Colors reuse the existing palette so
 * dark/light themes stay coherent — extend the palette only if a
 * future revision adds new accent tokens. */
.status.downloading { color: var(--ok); border-color: var(--ok); }
.status.triaging    { color: var(--accent); border-color: var(--accent); }
.status.waiting     { color: var(--warn); border-color: var(--warn); }
.status.paused      { color: var(--err-text); border-color: var(--err); }
.status.error {
  color: #ffffff;
  background: #7f1d1d;
  border-color: #7f1d1d;
}

main {
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

/* Filters */
.filters {
  display: flex; flex-wrap: wrap; gap: 12px;
  padding: 12px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 8px;
  margin-bottom: 16px;
  align-items: center;
}
.filters label {
  display: flex; flex-direction: column;
  font-size: 12px; color: var(--muted); gap: 2px;
}
.archive-filters .spacer { flex: 1; }
.archive-filters .kind-label { flex-direction: row; }
.archive-filters .loc-filter { align-items: center; gap: 6px; }
.archive-filters .loc-filter select { max-width: 170px; }

.archive-actions {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;
  padding: 6px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
  position: sticky;
  top: 8px;
  /* Leaflet's control container is at z-index 1000 (zoom buttons
   * and attribution); we have to clear that, not just the panes
   * (which top out around 700). 1100 puts the bar reliably
   * above every Leaflet layer. */
  z-index: 1100;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  transition: border-color 160ms ease, box-shadow 160ms ease,
              background 160ms ease;
}
/* "Live" treatment kicks in only when there's a selection.
 * The accent tint is layered ABOVE the opaque panel — using it
 * as background-color directly would let map tiles bleed through
 * the bar when it sits over a journey map. */
.archive-actions.has-selection {
  border-color: var(--accent);
  background:
    linear-gradient(
      to right,
      var(--accent-08),
      transparent 40%
    ),
    var(--panel);
  box-shadow: 0 6px 16px oklch(0 0 0 / 0.45);
}
.archive-actions .spacer { flex: 1; }
/* Grouped action buttons: Originals / Joined / PIP, each with a
 * small muted label and short single/double-letter buttons so the
 * whole set stays on one bar. */
.archive-actions .action-group {
  display: inline-flex; align-items: center; gap: 4px;
}
.archive-actions .action-label {
  font-size: 12px; color: var(--muted);
  font-weight: 500; margin-right: 2px;
}
.archive-actions .action-group button {
  min-width: 34px;
}
.archive-actions #selection-count {
  font-size: 12px;
  color: var(--text); font-weight: 500;
  font-variant-numeric: tabular-nums;
  margin-left: 4px;
}
.archive-actions #selection-count:empty { display: none; }
.archive-actions.has-selection #selection-count {
  color: var(--accent);
}
/* Inline Export jobs toggle in the action bar.
 * Styled to look like a clickable summary line — muted text,
 * caret on the left, hover lifts to full text colour. */
.exports-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  border-radius: 6px;
}
.exports-toggle:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}
.exports-toggle .caret {
  font-size: 10px;
  width: 10px;
}

/* Drop-down panel below the action bar, populated by JS.
 * Sticks just under the (also-sticky) action bar so the jobs
 * table follows the user down the page. top:50px deliberately
 * overlaps the bar's bottom edge by a few px so there's no
 * visible gap between them; z-index 1099 sits one below the
 * action bar's 1100 so the bar visually covers that overlap. */
.exports-panel {
  margin: 0 0 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  position: sticky;
  top: 50px;
  z-index: 1099;
  max-height: 50vh;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}
.exports-panel[hidden] { display: none; }
.exports-panel.just-submitted {
  animation: exports-flash 1.6s ease-out;
}
@keyframes exports-flash {
  0%   { box-shadow: 0 0 0 2px var(--accent-85),
                     0 0 24px var(--accent-45); }
  100% { box-shadow: 0 0 0 0 transparent,
                     0 0 0 transparent; }
}
.exports-table { width: 100%; border-collapse: collapse; }
.exports-table th, .exports-table td {
  padding: 7px 10px; text-align: left; vertical-align: middle;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.exports-table th { color: var(--muted); font-weight: 500; }
.exports-table tbody tr:last-child td { border-bottom: none; }
.exports-table tbody tr:hover { background: var(--panel-2); }
.state-queued   { color: var(--muted); }
.state-running  { color: var(--accent); }
.state-paused   { color: var(--warn, #d8a200); }
.state-cancelled { color: var(--warn); }

/* Type badge — small accent-tinted pill. */
.export-type {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-10);
  border: 1px solid var(--accent-35);
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

/* Status cell — state text + slim inline progress bar. */
.export-status .export-err { color: var(--err-text); }
.export-progress {
  margin-top: 5px;
  height: 4px;
  width: 100%;
  max-width: 160px;
  background: var(--panel-3);
  border-radius: 999px;
  overflow: hidden;
}
.export-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
  transition: width 200ms ease;
}
.export-stage {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
}

/* Footage cell — date range + clip count. */
.export-footage { white-space: nowrap; }
.export-count { color: var(--muted); }
/* Length + size: compact numeric columns, aligned figures. */
.export-length, .export-size {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

/* Actions — right-aligned icon buttons; the trailing delete button
 * lines up in a column across rows, with download just left of it. */
.exports-actions-col { width: 1%; }
.export-actions { text-align: right; white-space: nowrap; }
.export-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  vertical-align: middle;
  text-decoration: none;
}
.export-action + .export-action { margin-left: 4px; }
.export-action:hover { background: var(--panel-3); color: var(--text); }
.export-delete:hover { color: var(--err-text); }
/* Reserves the download slot so the bin never shifts. */
.export-action--empty { visibility: hidden; cursor: default; }

/* Day cards */
.day {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  overflow: hidden;
  transition: border-color 120ms ease, background 120ms ease;
}
.day:hover { border-color: var(--border-hover); }
.day-header {
  padding: 14px 18px;
  cursor: pointer;
  display: flex;
  gap: 14px;
  align-items: baseline;
}
.day-header:hover { background: rgba(255, 255, 255, 0.015); }
.day-header .day-check {
  flex: 0 0 auto;
  align-self: center;
  margin: 0;
  cursor: pointer;
  accent-color: var(--accent);
}
/* The date is the strongest landmark on the archive page;
 * it deserves more weight than the metadata that follows it.
 * Pre-bolder this was 15px/600 (≈1.07× the 14px body — flat).
 * Bumping to 18px/700 puts the scale ratio at 1.28× which is the
 * lower bound of the impeccable typography law (≥1.25× per step). */
.day-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}
.day-header .meta {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.day-header .meta .sep {
  color: var(--border-hover);
  margin: 0 6px;
}
.day-body { padding: 16px 18px; border-top: 1px solid var(--border); }
.day-body[hidden] { display: none; }

.clip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.clip-pair {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  overflow: hidden;
}
.clip-pair .time {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.005em;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.clip-pair .time label { flex: 1 1 auto; }
.clip-pair .time .kind-badge { font-weight: 500; }
.clip-pair .thumbs {
  /* auto-fit yields 2 equal columns for F+R days and 3 for
     3-camera (F+R+T/I) days; the 80px floor keeps thumbs from
     collapsing to icon size on narrow viewports. */
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 4px;
  margin: 6px 0;
}
.clip-pair img {
  width: 100%; aspect-ratio: 16/9; object-fit: cover;
  background: var(--bg); border-radius: 4px; cursor: pointer;
}
/* Filmstrip hover-scrub overlay: sits exactly over the static thumbnail (the
   image area only, not the filename label below it). pointer-events:none so
   the thumbnail's own click-to-open handler still fires. Hidden until the
   sprite has loaded (.is-ready) and the tile is hovered; the shared
   .film-scrub rules drive the scrub animation. */
.clip-pair .thumb { position: relative; }
.clip-pair .thumb .film-scrub {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 4px;
  background-color: #000;
  opacity: 0;
  pointer-events: none;
}
.clip-pair .thumb:hover .film-scrub.is-ready { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  /* No motion → no benefit; keep the static thumbnail. */
  .clip-pair .thumb:hover .film-scrub.is-ready { opacity: 0; }
}
/* Filenames are debug-y data; fade them and clip to one line.
 * Hover reveals the full string via the title attribute on the
 * label element (set in the renderer). */
/* Per-clip filename labels are noise in the archive grid — the new
 * Download Actions selection + journey context identify clips instead. */
.clip-pair .label { display: none; }
.clip-pair .thumb.remote {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 16 / 9;            /* match a real thumb's footprint */
  background: repeating-linear-gradient(
    45deg, var(--panel), var(--panel) 8px, var(--bg) 8px, var(--bg) 16px);
  opacity: 0.85;
}
.clip-pair .thumb.remote .remote-badge {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 14px;
  opacity: 0.8;
}
.clip-pair .thumb.remote .remote-badge svg { display: block; }
.clip-pair .thumb.remote.state-pending     .remote-badge { color: var(--accent); }
.clip-pair .thumb.remote.state-downloading .remote-badge { color: var(--accent); }
.clip-pair .thumb.remote.state-failed      .remote-badge { color: var(--err); }
.clip-pair .thumb.remote.state-skipped     .remote-badge { color: var(--muted); }
.clip-pair .thumb.remote.state-skipped { opacity: 0.5; }
.clip-pair .thumb.remote.geofence .remote-badge { color: var(--accent); }
.clip-pair .thumb.remote .remote-badge .spin { animation: vfs-spin 1.6s linear infinite; transform-origin: 50% 50%; }
.clip-pair .thumb.remote .unskip-btn {
  position: absolute;
  bottom: 6px;
  right: 6px;
  font-size: 11px;
  padding: 2px 8px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--muted);
  border-radius: 4px;
  cursor: pointer;
}
.clip-pair .thumb.remote .unskip-btn:hover { border-color: var(--accent); }
.clip-pair .thumb.remote .unskip-btn:disabled { opacity: 0.5; cursor: default; }
.clip-pair.flash {
  outline: 2px solid var(--accent);
  animation: flash-pulse 1.5s ease-out;
}
@keyframes flash-pulse {
  0%   { box-shadow: 0 0 28px var(--accent-85); }
  100% { box-shadow: 0 0 0 transparent; }
}

#map { height: 340px; border-radius: 8px; margin: 16px 0; }
.home-marker { color: var(--accent); display: block; }
.home-marker-wrap { display: flex; align-items: center; justify-content: center; }
.journey-title .start-label svg,
.journey-title .end-label svg,
.stop-label svg { vertical-align: -2px; margin-right: 3px; color: var(--accent); }

.journey-table {
  width: 100%; border-collapse: collapse;
  background: var(--panel-2); border-radius: 6px; overflow: hidden;
}
.journey-table th, .journey-table td {
  padding: 8px 12px; text-align: left;
  border-bottom: 1px solid var(--border); font-size: 13px;
}

/* Journey cards (per-journey map + clips) */
.journey-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 16px 0;
  overflow: hidden;
}
/* Tighter spacing for collapsed cards so a long day reads as a list. */
.journey-card.collapsible { margin: 6px 0; }
.journey-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  flex-wrap: wrap;
  /* Reserve the Timeline button's row height (only drive cards carry it) so a
     button-less stop / ungrouped header is the same height as a drive's. With
     box-sizing: border-box this clamps every header — whatever its padding — to
     one height; align-items: center keeps the content vertically centred. */
  min-height: 50px;
}
.journey-card.collapsible .journey-header {
  cursor: pointer;
  user-select: none;
  transition: background 120ms ease;
}
.journey-card.collapsible .journey-header:hover {
  background: rgba(255, 255, 255, 0.025);
}
.journey-header .caret {
  color: var(--muted);
  font-size: 12px;
  width: 12px;
  flex: 0 0 auto;
}
/* "Select all" tick in the journey/stop card header. */
.journey-header .journey-check {
  flex: 0 0 auto;
  margin: 0;
  cursor: pointer;
  accent-color: var(--accent);
}
.journey-body {
  border-top: 1px solid var(--border);
}
.journey-body[hidden] { display: none; }
.journey-header strong { font-size: 14px; }
.journey-title {
  display: inline-flex; align-items: center; gap: 8px;
  flex-wrap: wrap; max-width: 100%;
}
.journey-arrow { color: var(--muted); }
.start-label, .end-label, .stop-label {
  overflow-wrap: anywhere;
}
/* tabular-nums keeps every HH:MM:SS range the same width, so the journey-title
   column starts at the same x on drive and stop cards. */
.journey-header .journey-times {
  color: var(--text); font-size: 13px;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}
.journey-header .journey-meta {
  color: var(--muted); font-size: 12px;
  margin-left: auto;
}
.journey-map {
  height: 560px;
  border-bottom: 1px solid var(--border);
}
.journey-map .leaflet-interactive { cursor: pointer; }
.journey-card .clip-grid { padding: 12px; }

.stop-card .journey-header { background: rgba(241, 196, 15, 0.05); }
/* In the stop-card header the icon sits in the right-hand action slot — the
   same place the Timeline button occupies on drive cards (8px past the meta,
   matching the button's margin). */
.stop-card .journey-header .stop-icon {
  font-size: 14px; color: var(--warn);
  flex: 0 0 auto; margin-left: 8px;
}
.stop-card .journey-map { height: 200px; }

/* Drives are the spine of the day: accent rail + graded header wash + bold title.
   Stops recede (the existing faint amber header stays; just dim + tighten it). */
.journey-card.drive { border-left: 3px solid var(--accent); }
.journey-card.drive .journey-header {
  background: linear-gradient(to right, var(--accent-18), transparent 55%), var(--panel-2);
}
.journey-card.drive .journey-title { font-weight: 700; }
.stop-card .journey-header { opacity: 0.85; padding: 6px 14px; }

.stop-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: 6px;
  margin: 8px 0;
  color: var(--muted);
  font-size: 12px;
  flex-wrap: wrap;
}
.stop-banner .stop-icon { font-size: 14px; }
.stop-banner strong { color: var(--text); }
.stop-banner .stop-where { font-family: "SF Mono", monospace; }
.stop-banner .stop-when { margin-left: auto; }

.other-clips-head {
  margin: 20px 0 8px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
}

#pagination {
  display: flex; gap: 8px; justify-content: center;
  padding: 16px;
}

/* Page header — used by both archive and downloads views.
 * The h2 carries the page title; .view-header allows future
 * trailing widgets (counts, controls) via flex slots. */
.view-header {
  display: flex; align-items: baseline; gap: 12px;
  margin: 4px 0 16px;
}
.view-header h2 {
  margin: 0;
  flex: 1;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.015em;
}
.badge {
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 999px;
  color: var(--muted); font-size: 12px;
}
.current {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 16px; margin-bottom: 16px;
}
.current .bar {
  height: 8px; background: var(--panel-2); border-radius: 4px;
  overflow: hidden; margin-top: 8px;
}
.current .bar > div {
  height: 100%; background: var(--accent); width: 0%;
  transition: width 0.2s;
}
.queue-filters {
  display: flex; gap: 10px; margin-bottom: 12px;
  align-items: center; flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.queue-filters #q-filter {
  flex: 1 1 220px;
  min-width: 200px;
}
.filter-sep {
  width: 1px;
  height: 22px;
  background: rgba(255, 255, 255, 0.12);
  margin: 0 6px;
  flex: 0 0 auto;
}
.recent-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px;
}
.queue-meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 12px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.session-stats {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
#queue { width: 100%; border-collapse: collapse; }
#queue th.sortable {
  cursor: pointer; user-select: none; white-space: nowrap;
}
#queue th.sortable:hover { color: var(--accent); }
#queue th.sortable::after {
  content: ""; display: inline-block; width: 0; margin-left: 4px;
}
#queue th.sortable.sort-asc::after { content: " \25B2"; font-size: 10px; }
#queue th.sortable.sort-desc::after { content: " \25BC"; font-size: 10px; }
#queue th, #queue td {
  padding: 8px; text-align: left;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
#queue tbody tr:hover { background: var(--panel-2); }
.pagination {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 16px 0;
}
.state-pending    { color: var(--muted); }
.state-downloading { color: var(--accent); }
.state-done       { color: var(--ok); }
.state-failed     { color: var(--err-text); }
.state-gone       { color: var(--warn); }
.state-skipped    { color: var(--skip); }
.order-cell { text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Downloads — accordion by day */
.queue-day-header { gap: 12px; }
.queue-day-header h3 {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.005em;
}
.queue-day-header .meta { flex: 0 0 auto; }
.state-breakdown {
  flex: 1;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  font-variant-numeric: tabular-nums;
}
.state-breakdown span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--muted);
  white-space: nowrap;
}
.state-breakdown span::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--muted);
}
.state-breakdown .state-pending {
  color: var(--muted);
}
.state-breakdown .state-pending::before {
  background: var(--muted);
}
.state-breakdown .state-downloading {
  color: var(--accent);
  border-color: var(--accent-35);
  background: var(--accent-08);
}
.state-breakdown .state-downloading::before {
  background: var(--accent);
}
.state-breakdown .state-done {
  color: var(--ok);
}
.state-breakdown .state-done::before {
  background: var(--ok);
}
.state-breakdown .state-failed {
  color: var(--err-text);
  border-color: oklch(0.62 0.20 28 / 0.30);
  background: oklch(0.62 0.20 28 / 0.06);
}
.state-breakdown .state-failed::before {
  background: var(--err);
}
.state-breakdown .state-gone {
  color: var(--warn);
}
.state-breakdown .state-gone::before {
  background: var(--warn);
}
.state-breakdown .state-skipped {
  color: var(--skip);
}
.state-breakdown .state-skipped::before {
  background: var(--skip);
}
.queue-day-header .caret { color: var(--muted); font-size: 12px; }
.queue-day-header .qd-check { margin: 0; cursor: pointer; }
.queue-day-header .qd-check:disabled { cursor: not-allowed; opacity: 0.4; }
.queue-day-stale .queue-day-header h3,
.queue-day-stale .queue-day-header .meta { opacity: 0.6; }
.queue-day-body { padding: 8px 16px 16px; }

/* Downloads — hour tier nested inside a day body */
.queue-hours { display: flex; flex-direction: column; gap: 2px; }
.queue-hour {
  border-left: 2px solid var(--border);
  margin-left: 6px;
}
.queue-hour-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  cursor: pointer;
  border-radius: 6px;
}
.queue-hour-header:hover { background: rgba(255, 255, 255, 0.015); }
.queue-hour-header .caret { color: var(--muted); font-size: 12px; }
.queue-hour-header .qh-check { margin: 0; cursor: pointer; }
.queue-hour-header .qh-check:disabled { cursor: not-allowed; opacity: 0.4; }
.queue-hour-header .hour-label {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  min-width: 104px;
}
.queue-hour-header .meta { flex: 0 0 auto; color: var(--muted); font-size: 12px; }
.queue-hour-body { padding: 4px 0 8px 18px; }

.queue-items { width: 100%; border-collapse: collapse; }
.queue-items th, .queue-items td {
  padding: 6px 8px; text-align: left;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.queue-items th { color: var(--muted); font-weight: 500; }
.queue-items tbody tr:hover { background: var(--panel-2); }
.queue-items .qi-check { cursor: pointer; }

.kind-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text);
  padding: 0 6px;
  user-select: none;
}
.kind-label input { margin: 0; cursor: pointer; }

.kind-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  white-space: nowrap;
}
/* Camera-pair badges. Front uses brand amber (headlamp), rear uses
 * a deep teal — opposite enough on the colour wheel to read at a glance,
 * close enough in lightness that neither dominates. Parking / event /
 * read-only stay semantic. The text-on-fill colour for kind-R isn't the
 * accent because saturated red would clash with kind-event. */
.kind-badge.kind-F { color: var(--accent); border-color: var(--accent); }
.kind-badge.kind-R {
  color: oklch(0.76 0.10 200);
  border-color: oklch(0.50 0.08 200);
}
/* Third camera (telephoto or interior — never both on one device)
 * shares a magenta clear of ok-green 145, rear-teal 200, accent,
 * warn and err hues. */
.kind-badge.kind-T,
.kind-badge.kind-I {
  color: oklch(0.76 0.11 315);
  border-color: oklch(0.52 0.09 315);
}
.kind-badge.kind-parking { color: var(--warn); border-color: var(--warn); }
.kind-badge.kind-event { color: var(--err-text); border-color: var(--err); }
.kind-badge.kind-ro {
  color: oklch(0.70 0.04 250);
  border-color: oklch(0.45 0.04 250);
}

/* Modal — must sit above the sticky archive-actions bar
 * (z-index: 1100) and the sticky exports panel (1099) so the
 * video player isn't clipped or underlapped when a journey card
 * happens to be expanded behind it. */
#modal {
  position: fixed; inset: 0; background: oklch(0.10 0.010 250 / 0.82);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000;
}
.modal-inner {
  background: var(--panel); border-radius: 12px;
  padding: 16px; max-width: 90vw; max-height: 90vh;
  position: relative;
}
.modal-inner video { max-width: 80vw; max-height: 80vh; display: block; }
#modal-close {
  position: absolute; top: 8px; right: 8px;
  background: none; border: none; font-size: 24px; color: var(--text);
}
.modal-nav {
  display: flex; gap: 8px; justify-content: center;
  margin-top: 10px;
}
.modal-nav button {
  min-width: 110px;
}
.modal-nav button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
#modal-toggle { min-width: 130px; }
.modal-autoplay {
  display: flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 13px;
  padding: 0 8px; user-select: none; cursor: pointer;
}
.modal-autoplay input { cursor: pointer; }

/* Logs tab */
.logs-toolbar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px; flex-wrap: wrap;
}
.logs-toolbar .logs-level-label {
  display: flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 13px;
}
.logs-toolbar select,
.logs-toolbar input[type="search"] {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 8px; font-size: 13px;
}
.logs-toolbar input[type="search"] { min-width: 180px; }
.logs-list {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 70vh; overflow: auto;   /* x too: long lines scroll sideways */
  padding: 6px 0;
  font-family: "SF Mono", "Menlo", monospace;
  font-size: 12px; line-height: 1.6;
}
.logs-empty { padding: 16px; color: var(--muted); font-size: 13px; }
.logs-footer { margin-top: 10px; }
.logs-footer button[disabled] { opacity: 0.5; cursor: default; }
/* Rows grow to their content so the widest line drives the scroll
 * width, but never shrink below the viewport (so short rows still
 * get a full-width hover band). */
.log-line { padding: 1px 14px; width: max-content; min-width: 100%; box-sizing: border-box; }
.log-head {
  display: flex; gap: 10px; align-items: baseline;
  white-space: nowrap;
}
.log-head.has-exc { cursor: pointer; }
/* Caret sits in its own column right after the timestamp; the column
 * is always present (even on rows without an exception) so the level
 * column stays aligned. The glyph only shows on .has-exc rows. */
.log-caret { flex: 0 0 1em; color: var(--muted); text-align: center; }
.log-head.has-exc .log-caret::before { content: "▸"; }
.log-line.open .log-head.has-exc .log-caret::before { content: "▾"; }
.log-ts { color: var(--muted); flex: 0 0 auto; }
.log-level { flex: 0 0 70px; font-weight: 600; }
.log-logger { color: var(--muted); flex: 0 0 auto; }
.log-msg { color: var(--text); flex: 1 1 auto; }
.log-line.log-info    .log-level { color: var(--muted); }
.log-line.log-warning .log-level { color: var(--warn); }
.log-line.log-error   .log-level,
.log-line.log-critical .log-level { color: var(--err-text); }
.log-exc {
  display: none;
  margin: 4px 0 8px 14px; padding: 8px 12px;
  background: var(--bg); border-left: 2px solid var(--border);
  white-space: pre-wrap; color: var(--muted);
}
.log-line.open .log-exc { display: block; }

/* On a narrow screen, let each entry wrap instead of forcing a
 * sideways scroll for every line: the timestamp/caret/level/logger
 * sit on the first line and the message wraps full-width beneath,
 * indented. Horizontal scroll stays available (overflow:auto on the
 * list, overflow-wrap as the break of last resort) so an unbreakable
 * token is still reachable. */
@media (max-width: 720px) {
  .log-line { width: auto; min-width: 0; }
  .log-head { flex-wrap: wrap; white-space: normal; }
  .log-msg {
    flex: 1 1 100%;
    white-space: normal;
    overflow-wrap: anywhere;
    padding-left: 1.5em;
  }
}

/* Settings */
.settings-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 28px;
  align-items: start;
}

.settings-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1px;
  position: sticky;
  top: 24px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.settings-nav-link {
  padding: 8px 12px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.005em;
  transition: color 120ms ease, background 120ms ease;
}
.settings-nav-link:hover {
  color: var(--text);
  background: var(--panel-2);
}
/* Active settings nav: tinted-amber fill + accent text. The previous
 * 2px inset side-stripe was an absolute-ban anti-pattern (audit flag);
 * this treatment is now consistent with the mobile pill rail and
 * reads as an obvious "current" state without the stripe. */
.settings-nav-link.active {
  color: var(--accent);
  background: var(--accent-10);
  font-weight: 500;
}

.settings-pane {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 32px;
  min-height: 480px;
}

.settings-pane h3 {
  margin: 0 0 18px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.005em;
}
.settings-pane h3 + .form-row { margin-top: 0; }
.settings-pane h3:not(:first-child) {
  margin-top: 36px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.settings-pane .form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 20px;
  max-width: 420px;
}
/* Checkbox rows render inline so the label sits next to the box. */
.settings-pane .form-row:has(> input[type="checkbox"]:only-of-type),
.settings-pane .form-row:has(> label > input[type="checkbox"]) {
  flex-direction: row-reverse;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

.settings-pane label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
/* Labels paired with a checkbox read as sentences, so drop the
 * uppercase field-metadata treatment. Covers both DOM shapes:
 * label-as-sibling (renderField) and label-wraps-input
 * (renderSecuritySection). */
.settings-pane .form-row:has(> input[type="checkbox"]:only-of-type) > label,
.settings-pane label:has(input) {
  font-size: 14px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
}
.settings-pane label:has(input) {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.settings-pane input[type="text"],
.settings-pane input[type="number"],
.settings-pane input[type="password"],
.settings-pane select {
  font-size: 14px;
  padding: 8px 10px;
  width: 100%;
}
.settings-pane input:focus-visible,
.settings-pane select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-18);
}

/* Native checkboxes get the compact 16px treatment; .switch toggles keep
 * their own 44x24 sizing (this rule outspecifies .switch, so exclude it). */
.settings-pane input[type="checkbox"]:not(.switch) {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
}

.settings-pane .hint {
  font-size: 12px;
  color: var(--muted);
  margin: 6px 0 1.5rem;
  max-width: 60ch;
  line-height: 1.55;
}
.settings-pane .hint.ok { color: var(--ok); }
.settings-pane .hint.bad { color: var(--err-text); }

.settings-pane button {
  font-size: 13px;
  min-width: 80px;
}
.settings-pane button#pw-save,
.settings-pane button#restart-now {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
.settings-pane button#pw-save:hover,
.settings-pane button#restart-now:hover {
  filter: brightness(1.06);
}
.settings-pane button#rotate-secret {
  background: transparent;
  color: var(--err-text);
  border-color: oklch(0.62 0.20 28 / 0.40);
}
.settings-pane button#rotate-secret:hover {
  background: oklch(0.62 0.20 28 / 0.08);
  border-color: var(--err);
}

/* Read-only system block */
.settings-pane dl.readonly {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 10px 24px;
  margin: 0 0 18px;
  padding: 16px 20px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.settings-pane dl.readonly dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  align-self: center;
}
.settings-pane dl.readonly dd {
  margin: 0;
  color: var(--text);
  font-family: "SF Mono", "Menlo", monospace;
  font-size: 13px;
}

.settings-footer {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin: 28px -32px -28px;
  padding: 14px 32px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  border-radius: 0 0 10px 10px;
  z-index: 10;
}
.settings-footer #settings-pending-summary {
  flex: 1;
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
}
.settings-footer .primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
.settings-footer .primary:hover { filter: brightness(1.06); }

.restart-required-chip {
  display: inline-block;
  padding: 2px 7px;
  margin-left: 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--warn);
  background: rgba(241, 196, 15, 0.08);
  border: 1px solid rgba(241, 196, 15, 0.35);
  border-radius: 3px;
  vertical-align: middle;
}

.banner-restart {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 10px 20px;
  background: rgba(241, 196, 15, 0.12);
  border-bottom: 1px solid rgba(241, 196, 15, 0.45);
  color: var(--warn);
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  z-index: 100;
}

/* ============================================================
 * Responsive adaptations
 *
 * Three content-driven breakpoints, picked from where the
 * desktop layout actually breaks rather than from device classes:
 *   1024px  shrink chrome, reclaim padding from the map cards
 *    720px  header wraps; settings sidebar becomes a top pill rail;
 *           sticky bars stop being sticky; clip cells relax
 *    480px  phone portrait: status pill loses its label,
 *           clip grid pins to two columns, captions hide
 *
 * Plus two input-method queries (pointer/hover) that apply at any
 * size, because a touch laptop at 1366px still needs 44px targets.
 * ============================================================ */

/* Coarse pointer: floor every standard hit-area at 44px without
 * resizing the visible glyph. Keeps the desktop density unchanged
 * for mouse users. */
@media (pointer: coarse) {
  /* 16px is the threshold below which iOS Safari zooms the page in when a
   * control gains focus (body text is 14px). Bumping touch form controls to
   * 16px stops that auto-zoom on its own — the viewport meta's user-scalable=no
   * is belt-and-braces for Android double-tap/pinch and is ignored by iOS. */
  input, select, textarea { font-size: 16px; }
  .icon-btn { width: 44px; height: 44px; }
  .settings-link { width: 44px; height: 44px; }
  nav a { padding: 10px 14px; }
  #logout { min-height: 36px; padding: 8px 14px; }
  .settings-nav-link { padding: 12px 14px; }
  .settings-pane button { min-height: 36px; }
  .cancel-btn { min-width: 36px; min-height: 36px; padding: 0 10px; }
  .modal-nav button { min-height: 44px; }
  #modal-close {
    width: 40px; height: 40px;
    border-radius: 8px;
    font-size: 22px;
  }
  .day-header { padding: 16px 18px; }
  #pagination button,
  .pagination button { min-width: 44px; min-height: 44px; }
}

/* No real hover: kill the hover-bound surface changes so they
 * don't latch on tap and look stuck. */
@media (hover: none) {
  .day:hover { border-color: var(--border); }
  .day-header:hover { background: transparent; }
  .journey-card.collapsible .journey-header:hover { background: transparent; }
  #queue tbody tr:hover,
  .queue-items tbody tr:hover { background: transparent; }
  .settings-nav-link:hover { color: var(--muted); background: transparent; }
  .settings-nav-link.active:hover { color: var(--text); background: var(--panel-2); }
  .settings-link:hover { color: var(--muted); background: transparent; }
  .exports-toggle:hover { color: var(--muted); background: transparent; }
  .icon-btn:hover { background: var(--panel-2); }
  button:hover { background: var(--panel-2); }
  .clip-pair:hover .label { opacity: 0.75; }
}

/* === <= 1024px : small laptops, tablet landscape === */
@media (max-width: 1024px) {
  main { padding: 20px 16px; }
  /* Keep the header content inset matching main's reduced padding. */
  #app header .header-inner { padding-left: 16px; padding-right: 16px; }
  .journey-map { height: 420px; }
  #map { height: 280px; }
}

/* === <= 720px : tablet portrait, large phones === */
@media (max-width: 720px) {
  main { padding: 16px 12px; }

  /* Header reorders: brand + actions on row 1, nav on its own row.
   * The spacer (which was eating 1900px on desktop) is dropped, and
   * nav links stretch so the two tabs are equal-weight thumb targets. */
  #app header .header-inner {
    flex-wrap: wrap;
    gap: 8px 10px;
    padding: 10px 14px;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  #app header .header-inner > .spacer { display: none; }
  #app header h1 { flex: 0 1 auto; margin-right: auto; }
  #app header nav {
    order: 10;
    flex: 1 1 100%;
    display: flex;
    gap: 4px;
  }
  nav a { flex: 1; text-align: center; }

  /* Filter rows: compact padding, drop the spacer so wrap is even. */
  .filters,
  .queue-filters,
  .archive-actions { padding: 10px; }
  .filters .spacer,
  .queue-filters .spacer,
  .archive-actions .spacer,
  .archive-filters .spacer { display: none; }

  /* Sticky bars stop earning their keep on a short viewport. */
  .archive-actions {
    position: static;
    box-shadow: none;
  }
  .exports-panel {
    position: static;
    max-height: none;
  }

  /* Settings: collapse to one column. The vertical sidebar
   * becomes a horizontally-scrolling pill rail so all sections
   * remain one tap away without a hamburger detour. The desktop's
   * inset accent stripe is swapped for a tinted fill at this
   * breakpoint, which also clears the side-stripe anti-pattern
   * the audit flagged. */
  .settings-layout {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .settings-sidebar {
    position: static;
    top: auto;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 4px;
    padding: 6px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    mask-image: linear-gradient(
      to right,
      transparent 0,
      black 16px,
      black calc(100% - 16px),
      transparent 100%
    );
  }
  .settings-sidebar::-webkit-scrollbar { display: none; }
  .settings-nav-link {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 8px 14px;
  }
  .settings-nav-link.active {
    box-shadow: none;
    background: var(--accent-10);
    color: var(--accent);
  }
  .settings-pane {
    padding: 20px 18px;
    min-height: 320px;
  }
  .settings-footer {
    margin: 20px -18px -20px;
    padding: 12px 18px;
  }
  .settings-pane dl.readonly {
    grid-template-columns: 1fr;
    gap: 4px 0;
    padding: 14px 16px;
  }
  .settings-pane dl.readonly dt { margin-top: 10px; }
  .settings-pane dl.readonly dt:first-of-type { margin-top: 0; }

  /* Day rows: the meta block wraps below the date instead of
   * fighting it for one row. */
  .day-header {
    flex-wrap: wrap;
    gap: 4px 12px;
    padding: 14px;
  }
  .day-header h3 { flex: 1 1 100%; }
  .day-body { padding: 14px; }

  /* Journey + stop cards. */
  .journey-header {
    padding: 12px;
    gap: 8px 10px;
  }
  .journey-header .journey-meta {
    margin-left: 0;
    flex: 1 1 100%;
  }
  .journey-map { height: 320px; }
  .stop-card .journey-map { height: 180px; }
  #map { height: 240px; }
  .journey-card .clip-grid { padding: 10px; }

  /* Clip grid: tighter floor so two thumbs fit at ~375px. */
  .clip-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
  }
  .clip-pair { padding: 6px; }

  /* Downloads queue is 8 columns wide. Rather than reshuffle into
   * a card layout (and lose column alignment), let the table
   * scroll horizontally inside its day body. The table keeps its
   * natural density for users who can scroll; the day header,
   * filters, and meta above it remain pinned to the page. */
  .queue-day-body { padding: 8px 10px 12px; }
  .queue-day-body table.queue-items {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
  }
  .queue-hour-body { padding: 4px 0 8px 8px; }
  .queue-hour-body table.queue-items {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
  }
  .exports-table-wrap,
  .exports-panel { overflow-x: auto; }
  .exports-table { min-width: 620px; }

  /* Downloads breakdown pills wrap below the date instead of
   * crowding the row. */
  .queue-day-header { flex-wrap: wrap; }
  .queue-day-header h3 { flex: 1 1 auto; }
  .queue-hour-header { flex-wrap: wrap; }
  .queue-hour-header .hour-label { flex: 1 1 auto; }
  .state-breakdown {
    flex: 1 1 100%;
    justify-content: flex-start;
    margin-top: 4px;
  }

  /* Modal: respect safe-area, cap video by small-vh so the close
   * button stays in reach above the iOS chrome. */
  .modal-inner {
    padding: 12px;
    padding-top: max(12px, env(safe-area-inset-top));
    max-width: calc(100vw - 16px);
  }
  .modal-inner video {
    max-width: calc(100vw - 24px);
    max-height: 60svh;
  }
  .modal-nav {
    flex-wrap: wrap;
    gap: 6px;
  }
  .modal-nav button {
    flex: 1 1 calc(50% - 6px);
    min-width: 0;
  }

  /* Restart banner sits above a possible iOS notch. */
  .banner-restart {
    padding-top: max(10px, env(safe-area-inset-top));
  }

  /* Login form is fluid below its desktop minimum. */
  #login-form {
    min-width: 0;
    width: min(360px, 100% - 32px);
    padding: 24px;
  }
}

/* === <= 480px : phone portrait === */
@media (max-width: 480px) {
  main { padding: 12px 10px; }

  #app header .header-inner { padding: 8px 10px; }
  #app header h1 { font-size: 16px; }

  /* The "Dashcam offline / online" pill drops its label and
   * becomes a coloured dot. Colour already carried the meaning;
   * the word was redundant at thumb scale. */
  .status {
    font-size: 0;
    padding: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--muted);
    border: none;
  }
  .status.downloading { background: var(--ok); }
  .status.triaging    { background: var(--accent); }
  .status.waiting     { background: var(--warn); }
  .status.paused      { background: var(--err); }
  .status.error       { background: #7f1d1d; }

  .day-header h3 { font-size: 14px; }
  .day-header .meta { font-size: 11px; }
  .journey-title { font-size: 13px; }

  /* Two-up clip grid. The 16:9 thumbs stay legible at ~170px. */
  .clip-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }
  /* The filename caption is debug ergonomics, not user ergonomics.
   * Already faded on desktop; on phone it fights the time label
   * for every pixel. Hide it. */
  .clip-pair .label { display: none; }

  /* Action buttons wrap two-up rather than overflowing. */
  .archive-actions button {
    flex: 1 1 calc(50% - 4px);
  }

  /* Pagination chips: thumb-sized. */
  #pagination button,
  .pagination button {
    min-width: 44px;
    min-height: 44px;
  }
}

/* === Very narrow / iPhone SE class (<= 380px) === */
@media (max-width: 380px) {
  main { padding: 10px 8px; }
  .day-header { padding: 12px 10px; }
  .journey-header { padding: 10px; }
  .clip-grid { gap: 4px; }
  .filters,
  .archive-actions,
  .queue-filters { padding: 8px; }
}

/* ============================================================
 * Hardening
 * ============================================================ */

/* Hit-area floor for the smallest visible controls. Even with a
 * mouse, a 24x24 close button at viewport top-right is a frequent
 * miss. The visible glyph stays the same; a transparent padded
 * area extends the click zone. */
.cancel-btn {
  min-width: 28px;
  min-height: 28px;
  padding: 0 6px;
}
#modal-close {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 22px;
  line-height: 1;
}
#modal-close:hover { background: rgba(255, 255, 255, 0.06); }

/* Flex children that hold long strings need min-width: 0 so they
 * can shrink below their natural content size and let the text's
 * own overflow-wrap take over. Without this, a 90-character
 * journey label pushes its row out instead of wrapping. */
.journey-title,
.day-header .meta,
.clip-pair .label,
#app header h1 {
  min-width: 0;
}

/* Reduced motion. Vestibular-disorder accessibility (WCAG 2.3.3).
 * The repeating animations — the sync spinner and the red-pulse
 * pause halo — are the worst offenders; both communicate state
 * the user has another channel for (icon shape, button colour),
 * so we stop them outright and shorten the few one-shot
 * transitions that remain. The selection-flash and exports-flash
 * are kept as instant outlines so users still get feedback. */
@media (prefers-reduced-motion: reduce) {
  .icon-btn.active #sync-icon-sync:not([hidden]) { animation: none; }
  .icon-btn.paused {
    animation: none;
    box-shadow: 0 0 0 1px var(--err);
  }
  #sync-toggle.error #sync-icon-warning {
    animation: none;
    opacity: 0.9;
  }
  .clip-pair.flash { animation: none; }
  .exports-panel.just-submitted { animation: none; }
  .skip-link { transition: none; }
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
 * MQTT settings panel
 * ============================================================ */
#mqtt-panel { margin-top: 1rem; }
#mqtt-panel .mqtt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .25rem; }
#mqtt-panel .pw-wrap { display: flex; gap: .25rem; }
#mqtt-panel .pw-wrap input { flex: 1; }
#mqtt-status { display: flex; align-items: center; gap: .5rem; margin: .8rem 0; }
#mqtt-status .dot { width: .7rem; height: .7rem; border-radius: 50%; display: inline-block; flex-shrink: 0; }
#mqtt-status .dot.green  { background: var(--ok); }
#mqtt-status .dot.amber  { background: var(--warn); }
#mqtt-status .dot.red    { background: var(--err); }
#mqtt-status .dot.grey   { background: var(--muted); }
.mqtt-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }
.mqtt-actions .primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

/* ============================================================
 * Storage usage card (Settings → Archive Retention)
 * ============================================================ */
.storage-usage {
  margin: 0.5rem 0 1.25rem;
  padding: 0.75rem 0.9rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.storage-usage-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.storage-usage-label {
  font-weight: 600;
  font-size: 0.9rem;
}
.storage-usage-value {
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
  color: var(--muted);
}
.storage-usage-bar {
  position: relative;
  height: 8px;
  background: var(--panel-3);
  border-radius: 4px;
  overflow: hidden;
}
.storage-usage-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.4s ease, background 0.3s ease;
}
.storage-usage-fill.over-threshold {
  background: var(--err);
}
.storage-usage-threshold {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: var(--warn);
  pointer-events: auto;
}
.storage-usage-mode {
  margin: 0.5rem 0 0;
}

/* ---- Import recordings modal ---- */
#import-modal {
  position: fixed; inset: 0; z-index: 1500;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: oklch(0.10 0.008 250 / 0.62);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  animation: import-fade 160ms ease;
}
#import-modal.hidden { display: none; }
@keyframes import-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes import-rise {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to   { opacity: 1; transform: none; }
}

#import-modal .modal-card {
  width: min(520px, 100%); max-height: 88vh; overflow: auto;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 24px 60px oklch(0 0 0 / 0.55);
  padding: 22px 24px 24px;
  animation: import-rise 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

#import-modal .modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-bottom: 14px; margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
#import-modal .modal-head h2 {
  margin: 0; font-size: 1.15rem; letter-spacing: -0.01em;
}
#import-modal .modal-x {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0; flex-shrink: 0;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted);
  transition: background 140ms ease, color 140ms ease;
}
#import-modal .modal-x:hover { background: var(--panel-3); color: var(--text); }

/* Tabs — underline, muted until active */
#import-modal .tabs {
  display: flex; gap: 4px; margin: 0 0 18px; border-bottom: 1px solid var(--border);
}
#import-modal .import-tab {
  padding: 8px 14px; margin-bottom: -1px;
  border: 0; background: transparent; cursor: pointer;
  color: var(--muted); font-size: 0.92rem; font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: color 140ms ease, border-color 140ms ease;
}
#import-modal .import-tab:hover { color: var(--text); }
#import-modal .import-tab.active { color: var(--text); border-bottom-color: var(--accent); }

#import-modal .tab-pane.hidden { display: none; }
#import-modal .pane-lead {
  margin: 0 0 14px; color: var(--muted); font-size: 0.9rem; line-height: 1.5;
}
#import-modal code {
  font-family: "SF Mono", "Menlo", monospace; font-size: 0.85em;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 5px;
}

/* Upload dropzone (native input visually hidden, label is the target) */
#import-modal #import-files {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
#import-modal .dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  text-align: center; padding: 30px 20px;
  border: 1.5px dashed var(--border-hover); border-radius: 12px;
  background: var(--panel-2); cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease;
}
#import-modal .dropzone:hover { border-color: var(--accent); background: var(--accent-08); }
#import-modal #import-files:focus-visible + .dropzone {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-35);
}
#import-modal .dropzone.has-files {
  border-style: solid; border-color: var(--accent); background: var(--accent-08);
}
#import-modal .dropzone.dragging {
  border-style: solid; border-color: var(--accent); background: var(--accent-18);
}
#import-modal .dropzone-icon { color: var(--accent); }
#import-modal .dropzone-title { font-weight: 600; font-size: 0.98rem; }
#import-modal .dropzone-hint { color: var(--muted); font-size: 0.82rem; line-height: 1.45; }

/* Folder path row */
#import-modal .field-row { display: flex; gap: 8px; align-items: stretch; }
#import-modal .field-row input { flex: 1; }
#import-modal #import-folder-path {
  font-family: "SF Mono", "Menlo", monospace; font-size: 0.85rem;
}

/* Manifest line */
#import-modal .manifest {
  margin: 14px 0 0; font-size: 0.88rem; color: var(--muted);
  max-height: 30vh; overflow: auto;
}
#import-modal .manifest:empty { margin: 0; }
/* Breathing room above the pane's action button, regardless of whether
   the manifest line is populated (it collapses when empty). */
#import-modal .tab-pane > .btn { margin-top: 20px; }

/* Buttons (scoped to the modal) */
#import-modal .btn {
  padding: 9px 16px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  font-weight: 500; font-size: 0.92rem; cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, filter 140ms ease;
}
#import-modal .btn:hover { background: var(--panel-3); border-color: var(--border-hover); }
#import-modal .btn.primary {
  background: var(--accent); border-color: var(--accent); color: var(--on-accent);
  font-weight: 600;
}
#import-modal .btn.primary:hover { filter: brightness(1.07); }
#import-modal .btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }
#import-modal .btn.hidden { display: none; }

/* Progress */
#import-modal .progress { margin-top: 18px; }
#import-modal .progress.hidden { display: none; }
#import-modal .progress .bar {
  height: 8px; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 999px; overflow: hidden;
}
#import-modal .progress .bar span {
  display: block; height: 100%; width: 0; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-85), var(--accent));
  transition: width 220ms ease;
}
#import-modal #import-status {
  margin: 10px 0 0; font-size: 0.85rem; color: var(--muted);
  font-family: "SF Mono", "Menlo", monospace;
}

/* Summary card */
#import-modal .summary {
  margin-top: 18px; padding: 14px 16px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  font-size: 0.9rem; line-height: 1.6; color: var(--text);
}
#import-modal .summary.hidden { display: none; }

/* "Import recordings" launcher in the Download-manager header */
.import-launch {
  margin-left: auto; align-self: center;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 14px; border-radius: 8px;
  background: var(--accent-08); border: 1px solid var(--accent-35); color: var(--accent);
  font-weight: 600; font-size: 0.9rem; cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}
.import-launch:hover { background: var(--accent-18); border-color: var(--accent); }
.import-launch svg { flex-shrink: 0; }

/* ---------- Timeline view ---------- */
#view-timeline { display: flex; flex-direction: column; gap: 10px;
  --tl-label-w: 86px; --tl-gap: 8px;
  /* Fill the viewport below the app header (92px) + main padding (16+16). */
  min-height: calc(100vh - 124px);
  min-height: calc(100dvh - 124px); }
.tl-track-head .tl-track-label { width: auto; flex: 1 1 auto; min-width: 0;
  padding-left: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-head { display: flex; align-items: center; gap: 12px; }
.tl-back { font-size: 20px; color: var(--accent); text-decoration: none; line-height: 1; }
.tl-title { font-weight: 600; }
.tl-map-toggle { margin-left: auto; }
.tl-stage { display: flex; gap: 0; background: #000; border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden; min-height: 240px;
  flex: 1 1 auto; }   /* grow to fill the viewport-height section */
.tl-preview { flex: 3 1 0; position: relative; display: flex; align-items: center;
  justify-content: center; background: #000; min-height: 240px; }
/* Absolutely positioned so the video's intrinsic aspect-ratio height never
   drives the flex column taller than the viewport (it only fills its box). */
.tl-preview video { position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; }
/* Editor-only PiP placeholder: a green box over the contained video rect,
   positioned in JS (renderPipOverlay) so it tracks the letterboxed video
   area, not the container box. Not real footage — just a stand-in. */
.tl-pip-overlay { position: absolute; z-index: 2; display: none;
  align-items: center; justify-content: center; box-sizing: border-box;
  border: 2px solid var(--ok); background: rgba(46, 204, 113, 0.22);
  color: #eafff2; font-size: 12px; font-weight: 700; letter-spacing: .04em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .6); border-radius: 4px;
  pointer-events: none; overflow: hidden; }
.tl-preview-empty { color: var(--muted); font-size: 13px; letter-spacing: .04em; }
/* Grow into the horizontal space the letterboxed video leaves unused,
   while the preview (flex 3) stays the dominant pane. */
.tl-map { flex: 2 1 0; min-width: 300px; max-width: 640px;
  border-left: 1px solid var(--border); }
.tl-stage.map-hidden .tl-map, .tl-stage.no-map .tl-map { display: none; }
.tl-transport { display: flex; align-items: center; gap: 12px; }
.tl-play { width: 34px; height: 34px; border-radius: 50%; padding: 0; }
.tl-tc { font-variant-numeric: tabular-nums; color: var(--text); }
.tl-spacer { flex: 1; }
.tl-zbtn { width: 30px; height: 30px; padding: 0; }
.tl-ruler { position: relative; height: 18px; color: var(--muted);
  font-size: 11px; font-variant-numeric: tabular-nums; }
.tl-tick { position: absolute; transform: translateX(-50%); white-space: nowrap; }
/* Anchor the end labels inward so they don't clip at the edges. */
.tl-tick:first-child { transform: none; }
.tl-tick:last-child { transform: translateX(-100%); }
.tl-tracks { position: relative; background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 0; overflow: hidden; touch-action: none;
  user-select: none; min-height: 60px; }
.tl-track { display: flex; align-items: center; gap: var(--tl-gap); height: 54px; }
.tl-track-label { width: var(--tl-label-w); flex: none; padding-left: 8px;
  color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .04em; }
.tl-strip { position: relative; flex: 1; height: 48px; overflow: hidden;
  border-radius: 5px; background: var(--bg); }
.tl-clip { position: absolute; top: 0; height: 48px; border-right: 1px solid var(--bg);
  background-color: var(--panel-2); background-repeat: no-repeat; background-position: 0 0; }
.tl-clip.has-strip { background-color: transparent; }
/* Placeholder while the filmstrip generates: the clip thumbnail (set as the
   block background) under a dim + shimmer overlay that fades out once the
   real strip loads. */
.tl-clip.tl-ph::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(rgba(0, 0, 0, .35), rgba(0, 0, 0, .35)),
    linear-gradient(100deg, transparent 35%, rgba(255, 255, 255, .16) 50%,
                    transparent 65%);
  background-size: 100% 100%, 220% 100%;
  background-repeat: no-repeat;
  opacity: 0; transition: opacity .35s ease;
}
.tl-clip.tl-ph.loading::after {
  opacity: 1;
  animation: tl-shimmer 1.2s linear infinite;
}
@keyframes tl-shimmer {
  from { background-position: 0 0, -110% 0; }
  to   { background-position: 0 0, 210% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .tl-clip.tl-ph.loading::after { animation: none; }
}
.tl-playhead { position: absolute; top: 4px; bottom: 4px; width: 2px;
  left: calc(var(--tl-label-w) + var(--tl-gap));
  background: #fff; box-shadow: 0 0 6px #fff; pointer-events: auto;
  cursor: ew-resize; z-index: 5; }
.tl-empty { color: var(--muted); font-size: 13px; padding: 16px; }
.journey-open-tl { margin-left: 8px; background: var(--accent);
  color: var(--on-accent); border: 1px solid var(--accent); border-radius: 6px;
  padding: 4px 12px; font-weight: 600; cursor: pointer; }
.journey-open-tl:hover { background: var(--accent-85); border-color: var(--accent-85); }

/* Timeline: stack preview over map on narrow screens */
@media (max-width: 640px) {
  .tl-stage { flex-direction: column; }
  .tl-map { flex: none; width: 100%; height: 200px; border-left: none;
    border-top: 1px solid var(--border); }
  #view-timeline { --tl-label-w: 72px; }
  .tl-track-label { font-size: 10px; }
}

/* ---------- Timeline editor (Phase 3B) ---------- */
/* .tl-sel / .tl-switch share the playhead's left origin (the label
   gutter) so they align with the clip strips and the playhead. */
.tl-sel { position: absolute; top: 2px; bottom: 2px; z-index: 3;
  left: calc(var(--tl-label-w) + var(--tl-gap));
  border-left: 2px solid var(--accent); border-right: 2px solid var(--accent);
  pointer-events: none; }
.tl-switch { position: absolute; top: 0; bottom: 0; width: 0; z-index: 4;
  left: calc(var(--tl-label-w) + var(--tl-gap));
  border-left: 2px dashed #fff; pointer-events: none; }
.tl-switch-grip { position: absolute; top: 50%; left: -10px;
  transform: translateY(-50%); width: 20px; height: 20px; background: #fff;
  color: #10131a; border-radius: 5px; font-size: 12px; text-align: center;
  line-height: 20px; pointer-events: auto; cursor: ew-resize; }
/* Delete badge above the grip: removes the switch (merges the two segments). */
.tl-switch-del { position: absolute; top: 2px; left: -9px; width: 18px;
  height: 18px; background: var(--err-text, #ff5a5a); color: #fff;
  border-radius: 50%; font-size: 13px; text-align: center; line-height: 17px;
  pointer-events: auto; cursor: pointer; opacity: .85; }
.tl-switch-del:hover { opacity: 1; }
/* Per-segment shading overlays inside each track strip. */
.tl-ov { position: absolute; top: 0; bottom: 0; pointer-events: none; z-index: 1; }
.tl-ov-dim { background: rgba(0, 0, 0, 0.7); }
.tl-ov-outside { background: rgba(0, 0, 0, 0.85); }
.tl-track.tl-active .tl-track-label { color: var(--ok); }
.tl-track.tl-disabled { height: 20px; }
.tl-track.tl-disabled .tl-strip { opacity: .25; filter: grayscale(1); height: 16px; }
.tl-track.tl-disabled .tl-track-label { color: var(--muted); }
.tl-actions { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap;
  padding: 12px 2px 2px; }
.tl-grp { display: flex; align-items: center; gap: 6px; }
.tl-abtn { padding: 5px 11px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--panel-2); color: var(--text); font-size: 12px; line-height: 1.4; }
.tl-abtn:hover { background: var(--panel-3); border-color: var(--border-hover); }
.tl-abtn.primary { background: var(--accent); color: var(--on-accent);
  border-color: var(--accent); font-weight: 600; }
.tl-abtn.primary:hover { background: var(--accent-85); }
.tl-abtn.ghost { color: var(--muted); }
.tl-selinfo { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.tl-track-toggle { width: 26px; height: 15px; border-radius: 8px; flex: none;
  border: 1px solid var(--border); background: var(--panel-3); position: relative;
  cursor: pointer; margin-right: 2px; }
.tl-track-toggle.on { background: var(--ok); border-color: var(--ok); }
.tl-track-toggle::after { content: ""; position: absolute; top: 1px; left: 1px;
  width: 11px; height: 11px; border-radius: 50%; background: #10131a; transition: .15s; }
.tl-track-toggle.on::after { left: 12px; }
.tl-track-head { display: flex; align-items: center; gap: 6px; flex: none;
  width: var(--tl-label-w); padding-left: 8px; }

/* Timeline keyboard-shortcuts cheat-sheet (toggled with "?") */
#tl-shortcuts {
  position: fixed;
  inset: 0;
  z-index: 2100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
}
#tl-shortcuts[hidden] { display: none; }
#tl-shortcuts .tl-sc-card {
  background: var(--panel, #1e1e24);
  color: var(--text, #f0f0f0);
  border: 1px solid var(--border, #3a3a44);
  border-radius: 10px;
  padding: 20px 24px;
  min-width: 280px;
  max-width: 90vw;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
#tl-shortcuts h3 { margin: 0 0 12px; font-size: 1.05rem; }
#tl-shortcuts dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 18px;
  margin: 0;
}
#tl-shortcuts dt {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 600;
  white-space: nowrap;
  text-align: right;
}
#tl-shortcuts dd { margin: 0; }

/* ---- Filmstrip hover-scrub (shared) --------------------------------- */
/* A filmstrip sprite is a horizontal montage of N frames. Showing one tile at
   a time and stepping across the tiles on hover gives a scrub preview. The
   tile count varies (export sprites are a fixed 10; clip sprites scale with
   duration), so sizing is driven by the --frames custom property and the
   steps(N) timing is set inline per element (CSS steps() can't read a var).
   Shared by the export-jobs thumb and the archive clip tiles. */
.film-scrub {
  background-repeat: no-repeat;
  background-position: 0 0;
  background-size: calc(var(--frames, 10) * 100%) 100%;
}
@keyframes film-scrub-anim {
  from { background-position-x: 0%; }
  to   { background-position-x: 100%; }
}
/* Scrub only once a sprite is loaded (.is-ready) and the element — or, for the
   archive overlay, its .clip-pair .thumb ancestor — is hovered. The timing
   function steps(N, jump-none) is supplied inline by applyFilmstripScrub(). */
.film-scrub.is-ready:hover,
.clip-pair .thumb:hover .film-scrub.is-ready {
  animation-name: film-scrub-anim;
  animation-duration: 1.2s;
  animation-iteration-count: infinite;
}
@media (prefers-reduced-motion: reduce) {
  .film-scrub.is-ready:hover,
  .clip-pair .thumb:hover .film-scrub.is-ready { animation: none; }
}

/* Export-job filmstrip preview: one 16:9 tile that scrubs through its 10-frame
   sprite on hover via the shared .film-scrub primitive. */
.export-preview-col { width: 136px; }
.export-thumb {
  width: 128px;
  height: 72px;
  border-radius: 4px;
  background-color: #000;
}
/* Only finished jobs' thumbs are clickable (they carry data-job-id and open
   the export in the player modal). */
.export-thumb[data-job-id] { cursor: pointer; }
.export-thumb--empty {
  background: none;
}
/* While a finished job's filmstrip is still being generated, show a shimmer
   placeholder in the same tile. It carries data-job-id so it's click-to-play;
   it swaps to the real strip on the export_preview_ready event. Override the
   film-scrub sprite sizing and the :hover scrub (no sprite loaded yet, so
   scrubbing would show nothing). */
.export-thumb--loading,
.export-thumb--loading:hover {
  background-color: var(--panel-2);
  background-image: linear-gradient(
    100deg,
    transparent 30%,
    rgba(255, 255, 255, 0.07) 50%,
    transparent 70%
  );
  background-repeat: no-repeat;
  background-size: 200% 100%;
  animation: export-shimmer 1.3s ease-in-out infinite;
}
@keyframes export-shimmer {
  from { background-position-x: 150%; }
  to   { background-position-x: -150%; }
}
@media (prefers-reduced-motion: reduce) {
  .export-thumb--loading,
  .export-thumb--loading:hover { animation: none; }
}

/* ---- Toasts ---------------------------------------------------------- */
#toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 11000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  font-size: 13px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast--in { opacity: 1; transform: translateY(0); }
.toast--success { border-left-color: var(--ok); }
.toast--error { border-left-color: var(--err); }
.toast__msg { flex: 1 1 auto; }
.toast__action {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
  white-space: nowrap;
}
.toast__action:hover { text-decoration: underline; }
.toast__close {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
}
.toast__close:hover { color: var(--text); }
@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; transform: none; }
}

/* ---------- Camera control tab ---------- */
.camera-status { margin: 4px 0 12px; color: var(--muted); }
.camera-status.error { color: var(--err-text); }
.cam-facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px; margin-bottom: 18px;
}
.cam-facts > div {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 2px;
}
.cam-facts span { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
.cam-facts b { font-weight: 600; word-break: break-word; }
.cam-group {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 16px 14px; margin: 0 0 16px;
}
.cam-group legend { padding: 0 8px; color: var(--accent); font-weight: 600; }
/* label | status | control. The status takes the flexible middle column so
 * the control is always the last column, flush-right. Row height comes from
 * the label's padding, keeping rows uniform regardless of control height. */
.cam-row {
  display: grid; grid-template-columns: auto 1fr auto;
  align-items: center; gap: 12px;
  border-top: 1px solid var(--border);
}
.cam-group .cam-row:first-of-type { border-top: none; }
.cam-row label { color: var(--text); padding: 14px 0; }
.cam-row select { width: 200px; }
.cam-row-status { font-size: 0.82rem; justify-self: start; }
.cam-row-status.ok { color: var(--ok); }
.cam-row-status.error { color: var(--err-text); }
.cam-row-status.pending { color: var(--muted); }
@media (max-width: 560px) {
  /* The 3-column grid doesn't stack cleanly: the (usually empty) status cell
   * leaves dead vertical space and the control gets no breathing room. Use a
   * wrapping flex row instead — compact controls (toggle, current value, the
   * ⓘ note) stay on the label's line pinned right; the wide select drops to its
   * own full-width line below. Row rhythm moves from the label's padding onto
   * the row, so both lines sit evenly inside the row's top/bottom borders. */
  .cam-row {
    display: flex; flex-wrap: wrap; align-items: center;
    justify-content: space-between; gap: 8px 12px;
    padding: 12px 0;
  }
  .cam-row label { flex: 1 1 auto; padding: 0; }
  .cam-row-status { order: 3; flex-basis: 100%; }
  .cam-row-status:empty { display: none; }
  .cam-row select { order: 4; width: 100%; flex: 1 1 100%; }
  .cam-row .switch,
  .cam-current,
  .cam-note { flex: 0 0 auto; }
}

/* ---------- Camera tab polish ---------- */
.cam-loading { color: var(--muted); padding: 16px 2px; }
.cam-pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 0.82rem; font-weight: 600;
}
.cam-pill.on  { background: color-mix(in oklch, var(--ok) 22%, transparent); color: var(--ok); }
.cam-pill.off { background: var(--panel-3); color: var(--muted); }

/* disabled (not-adjustable-now) rows: show current value + reason */
.cam-row.disabled label { color: var(--muted); }
.cam-current { color: var(--text); font-variant-numeric: tabular-nums; justify-self: end; }
/* Not-adjustable reason: a small ⓘ marker after the label; the reason is
 * revealed by the data-tip tooltip (hover/focus/tap). */
.cam-note {
  justify-self: start; color: var(--muted);
  font-size: 0.95rem; cursor: help; line-height: 1;
}
.cam-row.disabled { opacity: 0.85; }

/* App-wide toggle switch for ON/OFF checkboxes (settings, archive filters,
 * camera rows). Drops onto a plain <input type="checkbox" class="switch">
 * — no wrapper element needed. Selection checkboxes keep the native box. */
.switch {
  appearance: none; -webkit-appearance: none; margin: 0;
  box-sizing: border-box; flex: 0 0 auto; vertical-align: middle;
  position: relative; width: 44px; height: 24px; border-radius: 999px;
  cursor: pointer; background: var(--panel-3); border: 1px solid var(--border);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.switch::before {
  content: ""; position: absolute; height: 18px; width: 18px; left: 2px; top: 2px;
  border-radius: 50%; background: var(--muted);
  transition: transform 0.15s ease, background 0.15s ease;
}
.switch:checked { background: var(--accent-45); border-color: var(--accent); }
.switch:checked::before { transform: translateX(20px); background: var(--on-accent); }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- Named locations list (Settings → GPS) --- */
.loc-list { margin: 8px 0 4px; }
.loc {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 7px 0;
  background: var(--panel);
  overflow: hidden;
}
.loc.open { border-color: var(--accent); }
.loc-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
}
.loc-ico { color: var(--accent); display: inline-flex; }
.loc-name { font-weight: 600; color: var(--text); }
.loc-badge {
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 10px;
  border: 1px solid transparent;
}
.loc-badge.home { color: var(--warn); border-color: var(--warn); }
.loc-badge.excl { color: var(--accent); border-color: var(--accent-45); }
.loc-meta {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.loc-caret { color: var(--muted); }
.loc-editor {
  border-top: 1px solid var(--border);
  padding: 12px;
  background: var(--panel-2);
}
.loc-map { height: 220px; border-radius: 8px; margin: 0 0 10px; }
.loc-actions { display: flex; gap: 8px; margin-top: 12px; }
.loc-del-btn { margin-left: auto; color: var(--err-text); border-color: var(--err); }
.loc-add {
  width: 100%;
  border: 1px dashed var(--border-hover);
  border-radius: 8px;
  padding: 11px;
  margin-top: 9px;
  background: transparent;
  color: var(--muted);
}
.loc-add:hover { background: var(--panel-2); color: var(--text); }
.loc-empty { margin: 8px 2px; }
.switch:disabled { opacity: 0.5; cursor: default; }
.clip-action-group { display: flex; align-items: center; gap: 6px; }
.clip-action-group select { max-width: 190px; }
/* The Downloads bar reuses .clip-action-group; give its label the same muted
   treatment as the archive action label so the two bars read identically. */
.queue-filters .action-label {
  font-size: 12px; color: var(--muted);
  font-weight: 500; margin-right: 2px;
}

/* GPS triage badge — per-file indicator in the Downloads queue table. */
.gps-badge {
  display: inline-block;
  min-width: 1.2em;
  text-align: center;
  font-weight: 600;
  border-radius: 4px;
  padding: 0 4px;
}
.gps-badge.gps-ok      { color: var(--ok); }
.gps-badge.gps-none    { color: var(--muted); }
.gps-badge.gps-pending { color: var(--muted); opacity: 0.7; }
.queue-items td.gps-cell { text-align: center; }

/* Journey completion pie — small conic-gradient circle in the journey header. */
.journey-pie {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  vertical-align: -2px;
  margin-right: 8px;
  background: var(--panel);
  box-shadow: inset 0 0 0 1px var(--border);
}
.journey-pie::before {
  content: "";
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: conic-gradient(var(--muted) calc(var(--pp) * 1%), transparent 0);
}
.journey-pie.is-complete::before {
  background: var(--ok);
}
