/* app.css — reset, layout, nav, forms, table, buttons, toast, modal.
   One file for the whole app (docs/ARCHITECTURE.md §8) — every view in assets/js/views/
   is built from the shared component classes below (`.card`, `.btn*`, `.field*`,
   `.table*`, `.badge*`, `.record-stat*`, `.track-card*`, `.bookmark-row*`, `.modal*`…),
   so this file is the single place a visual redesign happens. Rewritten 2026-08-08 for a
   "commercial, not homemade" design pass (requested directly, see git history) — same
   selectors throughout (no JS view had to change to pick this up), new tokens/values:
   an indigo→violet brand gradient instead of flat blue, a taller radius/shadow scale for
   a softer "premium SaaS" surface language, and small entrance/hover motion. Every
   `[hidden]`-specificity and positioning fix documented inline below is a real bug found
   during earlier phases' real-device testing — those mechanisms are preserved exactly;
   only the colours/spacing/radii around them changed. */

:root {
  /* Brand: indigo → violet, used sparingly (primary actions, focus, active nav, live
     status) rather than washed across the UI — the "clean SaaS" direction chosen over a
     bolder all-gradient look, so the accent still reads as an accent. */
  --color-bg: #f6f6fb;
  --color-surface: #ffffff;
  --color-surface-2: #f1f1f9; /* tiles/rows nested inside a card — one step down from surface */
  --color-border: #e6e6f2;
  --color-border-strong: #d7d8ea;
  --color-text: #16161f;
  --color-muted: #6b6e85;
  --color-primary: #5f4de5;
  --color-primary-600: #3620db;
  --gradient-primary: linear-gradient(135deg, #5f4de5 0%, #7161e8 100%);
  --color-danger: #c41c21;
  --color-danger-hover: #9d161a;
  --color-success: #0e7644;
  --color-warning: #945900;
  --color-warning-bg: #fdf3e2;

  /* --- Fill tokens (2026-08-09 contrast fix) ---------------------------------------
     `--color-primary`/`--color-danger`/`--color-success` above are tuned for *text on
     this theme's own surface* (links, badge text, focus rings) — in dark mode that
     correctly means a bright pastel, readable against a near-black background. The four
     tokens below are for the opposite case: white text/icons painted *on top of* a
     solid or gradient fill (buttons, the active nav pill, toasts, the checked activity
     card, …). A bright dark-mode pastel fails badly there (e.g. the old dark gradient's
     light stop, #ae8ffb, was only 2.6:1 against white — the bug this section fixes).
     Fill tokens are therefore **not redefined per theme** — one dark-enough value per
     hue, used identically in light and dark, the same way most products keep a primary
     CTA colour stable across themes rather than re-tuning it to "blend in". Every value
     here was chosen to clear WCAG AA (4.5:1) against white with margin. Keep any new
     "white text on a filled surface" component pointed at these, not at the bare
     `--color-primary`/`--color-danger`/`--color-success` above. */
  --color-primary-fill: #5f4de5;
  --gradient-primary-fill: linear-gradient(135deg, #5f4de5 0%, #7161e8 100%);
  --color-danger-fill: #c41c21;
  --color-success-fill: #0e7644;

  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
  --radius-full: 999px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
  --space-6: 48px;

  /* Soft, diffuse, faintly brand-tinted shadows (rgba mixed toward the primary hue's dark
     end rather than plain black) — the small thing that makes flat cards read as "raised
     surfaces" instead of "boxes with a border". */
  --shadow-xs: 0 1px 2px rgba(30, 20, 70, 0.05);
  --shadow-sm: 0 2px 8px rgba(30, 20, 70, 0.06), 0 1px 2px rgba(30, 20, 70, 0.04);
  --shadow: 0 10px 26px rgba(30, 20, 70, 0.09), 0 2px 6px rgba(30, 20, 70, 0.05);
  --shadow-lg: 0 22px 50px rgba(30, 20, 70, 0.16), 0 6px 16px rgba(30, 20, 70, 0.08);
  --shadow-primary: 0 10px 24px rgba(95, 77, 229, 0.32);

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-pop: cubic-bezier(0.34, 1.4, 0.64, 1);
  --transition: 180ms var(--ease);
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0d0e14;
    --color-surface: #161822;
    --color-surface-2: #1e2130;
    --color-border: #282b3d;
    --color-border-strong: #383c54;
    --color-text: #f2f2f8;
    --color-muted: #9599b0;
    /* Nudged slightly brighter than the original redesign's #8b7cfa/#f2555b (2026-08-09):
       both were marginally under 4.5:1 against their own badge pills' tinted background
       (badge--invited/badge--disabled sit on a 15%-mixed tint over the dark surface, not
       the plain surface colour) — this is the text-role token, see the fill-token block
       above for the separate "white on a filled surface" problem this was reported for. */
    --color-primary: #9082fa;
    --color-primary-600: #cac4fd;
    --gradient-primary: linear-gradient(135deg, #8b7cfa 0%, #ae8ffb 100%);
    --color-danger: #f35e64;
    --color-danger-hover: #ef262e;
    --color-success: #2dd4a7;
    --color-warning: #fbbf24;
    --color-warning-bg: #3a2a0d;
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.35);
    --shadow: 0 12px 30px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 26px 60px rgba(0, 0, 0, 0.55);
    /* Matches --gradient-primary-fill's constant hue (not the brighter text-role
       --color-primary above) — every element pairing this shadow with a fill background
       now uses that fill token, so the glow should echo its colour, not the theme's. */
    --shadow-primary: 0 12px 28px rgba(95, 77, 229, 0.45);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0 0 var(--space-2);
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: -0.01em;
}

h1 {
  font-size: clamp(1.375rem, 1.2rem + 0.6vw, 1.625rem);
  font-weight: 800;
}

h2 {
  font-size: 1.05rem;
}

h3 {
  font-size: 0.9rem;
}

p {
  margin: 0 0 var(--space-3);
}

a {
  color: var(--color-primary);
}

.muted {
  color: var(--color-muted);
}

::selection {
  background: var(--color-primary-fill);
  color: #fff;
}

/* Brand-coloured native controls for free — one line covers every plain checkbox/radio in
   the app (admin bulk-select, "Include deleted", "auto-start", the merge checkbox…)
   without touching any of their markup. `.activity-option`'s radios stay visually hidden
   regardless (own custom look), so this never shows there. */
input[type='checkbox'],
input[type='radio'] {
  accent-color: var(--color-primary);
}

/* Screen-reader-only text: keeps a real accessible name/label in the DOM for anything
   that's gone icon-only visually (the nav bar below is the first user of this). */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- App shell / nav ------------------------------------------------------------ */

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Icon-only, always-one-row nav bar — structure unchanged from earlier phases (a brand
   wordmark/name here wrapped to a second row on an iPhone-width viewport before; see the
   in-code history for why it was dropped), just restyled: a translucent, blurred bar that
   stays legible over whatever's scrolled underneath it, and a softer pill behind the
   active icon instead of a flat colour swap. */
.app-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: color-mix(in srgb, var(--color-surface) 88%, transparent);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  /* Stacks below the fixed #connectivity-status banner (ui.js sets --connectivity-offset
     to that banner's live rendered height) instead of both pinning to top:0 and occluding
     each other. */
  top: var(--connectivity-offset, 0px);
  z-index: 800;
}

.app-nav__links {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto; /* a safety valve, not the intended layout: see the width budget note below */
}

.nav-link {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  text-decoration: none;
  color: var(--color-muted);
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.nav-link:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.nav-icon {
  width: 21px;
  height: 21px;
}

.nav-link--active {
  color: #fff;
  background: var(--gradient-primary-fill);
  box-shadow: var(--shadow-primary);
}

.nav-link--active:hover {
  color: #fff;
  background: var(--gradient-primary-fill);
}

.app-nav__user {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
}

.main-content {
  flex: 1;
  padding: var(--space-4);
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

.empty-state {
  padding: var(--space-6) 0;
  text-align: center;
  color: var(--color-muted);
}

.empty-state h1 {
  color: var(--color-text);
}

/* --- Auth pages ------------------------------------------------------------------ */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  position: relative;
  overflow: hidden;
  background: var(--color-bg);
}

/* Two large, softly blurred brand-colour blobs behind the card — decorative only
   (the card itself is fully opaque), the one deliberate flourish on the pages a
   first-time user meets before anything else in the app. `pointer-events: none` +
   negative z-index keep them out of the way of the real, interactive card on top. */
.auth-page::before,
.auth-page::after {
  content: '';
  position: absolute;
  z-index: 0;
  width: 46vmax;
  height: 46vmax;
  border-radius: 50%;
  filter: blur(70px);
  pointer-events: none;
  opacity: 0.35;
}

.auth-page::before {
  top: -18vmax;
  left: -14vmax;
  background: var(--color-primary);
}

.auth-page::after {
  bottom: -20vmax;
  right: -16vmax;
  background: #f7b0e0;
  opacity: 0.22;
}

@media (prefers-color-scheme: dark) {
  .auth-page::after {
    opacity: 0.14;
  }
}

.auth-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.brand-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-3);
  border-radius: var(--radius);
  background: var(--gradient-primary-fill);
  box-shadow: var(--shadow-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.brand-mark svg {
  width: 28px;
  height: 28px;
}

.auth-card h1 {
  text-align: center;
}

.auth-card h1 + p.muted {
  text-align: center;
}

.auth-links {
  margin-top: var(--space-3);
  text-align: center;
  margin-bottom: 0;
}

.notice {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font-size: 0.83rem;
  color: var(--color-muted);
}

/* --- Cards ------------------------------------------------------------------------ */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
}

/* --- Forms -------------------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
}

.field span {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-muted);
}

.field input,
.field select,
.field textarea {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color var(--transition), box-shadow var(--transition);
}

/* Custom chevron, native <select> otherwise unstyled — one small detail that stops every
   dropdown in the app looking like an unstyled OS default next to the redesigned inputs
   around it. `appearance: none` needs the -webkit- prefix for Safari/iOS, this app's one
   real target platform (CLAUDE.md). Data-URI SVG so it needs no extra asset/request. */
.field select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b6e85' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 34px;
}

.field textarea {
  resize: vertical;
  min-height: 60px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 22%, transparent);
}

.field--error input,
.field--error select,
.field--error textarea {
  border-color: var(--color-danger);
}

.field-error-text {
  margin: 0;
  font-size: 0.8rem;
  color: var(--color-danger);
}

.field-hint {
  margin-top: calc(var(--space-1) * -1);
  margin-bottom: var(--space-3);
  font-size: 0.8rem;
  color: var(--color-muted);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-3);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

/* --- Buttons ------------------------------------------------------------------ */

.btn {
  font: inherit;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  background: var(--color-surface-2);
  color: var(--color-text);
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition), transform 100ms var(--ease);
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

/* "Large touch targets for use while moving" (docs/ROADMAP.md Phase 7 accessibility
   pass) — 44px is Apple's Human Interface Guidelines minimum tappable size, applied to
   .btn--block specifically (Start Recording, Stop, activate/reset-password) rather than
   every .btn: those are the controls someone is realistically tapping while walking,
   cycling, or driving, not the dense admin tables' small row-action buttons — a blanket
   min-height there would visually break tables already built and verified in earlier
   phases for comparatively little real accessibility gain. */
.btn--block {
  min-height: 50px;
  width: 100%;
}

/* A consistent, visible focus ring on every interactive control (buttons, links, form
   controls not already covered by the more specific .field input:focus rule below) —
   keyboard/switch-control navigation shouldn't rely on each browser's own default, which
   varies in visibility and is suppressed entirely by some mobile browsers. */
a:focus-visible,
.btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.btn--primary {
  background: var(--gradient-primary-fill);
  border-color: transparent;
  color: #fff;
  box-shadow: var(--shadow-primary);
}

/* Darkens on hover (brightness < 1), not lightens — the pre-fix version brightened,
   which on the (already contrast-tight) fill colour could only make white text/icons
   harder to read, never easier; darkening is the only direction guaranteed to keep
   contrast at or above the base state, in both themes. */
.btn--primary:hover:not(:disabled) {
  filter: brightness(0.92);
  box-shadow: 0 12px 28px color-mix(in srgb, var(--color-primary-fill) 40%, transparent);
}

.btn--secondary {
  background: var(--color-surface);
  border-color: var(--color-border);
}

.btn--secondary:hover:not(:disabled) {
  border-color: var(--color-primary);
  background: var(--color-surface-2);
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
  padding: 6px 10px;
  font-weight: 500;
}

.btn--ghost:hover:not(:disabled) {
  background: var(--color-surface-2);
}

.btn--danger {
  background: var(--color-danger-fill);
  border-color: var(--color-danger-fill);
  color: #fff;
}

/* Same darken-only-on-hover reasoning as .btn--primary above, rather than swapping to
   the theme-adaptive --color-danger-hover (which brightened in dark mode — the same
   class of bug this pass fixes elsewhere). */
.btn--danger:hover:not(:disabled) {
  filter: brightness(0.88);
}

.btn--ghost.btn--danger {
  background: transparent;
  color: var(--color-danger);
}

.btn--ghost.btn--danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--color-danger) 12%, transparent);
}

/* --- Admin: page header, create panel, table ----------------------------------- */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

.page-header h1 {
  margin: 0;
}

.create-panel {
  margin-bottom: var(--space-4);
}

.invite-result {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
}

.invite-link code {
  background: var(--color-surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  word-break: break-all;
}

.table-wrap {
  overflow-x: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
}

.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

.table th,
.table td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.table th {
  color: var(--color-muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr {
  transition: background var(--transition);
}

.table tbody tr:hover td {
  background: var(--color-surface-2);
}

.row-actions {
  display: flex;
  gap: var(--space-1);
  justify-content: flex-end;
}

/* A small circular initial badge ahead of a user's name (admin-users.js) — the one bit of
   "real product" polish a plain text table can't offer on its own. Colour is derived from
   the name itself (hashAccent() in that file) so the same person's initial reads the same
   colour every time the table re-renders, without storing a colour anywhere. */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  margin-right: var(--space-2);
  vertical-align: middle;
  flex: none;
}

.role-select {
  font: inherit;
  font-size: 0.85rem;
  padding: 4px 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
}

.role-select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  background: var(--color-surface-2);
  color: var(--color-muted);
}

.badge--active {
  background: color-mix(in srgb, var(--color-success) 15%, transparent);
  color: var(--color-success);
}

.badge--invited {
  background: color-mix(in srgb, var(--color-primary) 15%, transparent);
  color: var(--color-primary);
}

.badge--disabled {
  background: color-mix(in srgb, var(--color-danger) 15%, transparent);
  color: var(--color-danger);
}

/* --- Toasts --------------------------------------------------------------------- */

.toast-container {
  position: fixed;
  bottom: var(--space-4);
  right: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 1000;
}

.toast {
  background: var(--color-text);
  color: var(--color-bg);
  padding: 12px var(--space-3);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px) scale(0.98);
  transition: opacity 0.2s, transform 0.2s;
  max-width: 320px;
}

.toast--visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.toast--error {
  background: var(--color-danger-fill);
  color: #fff;
}

.toast--success {
  background: var(--color-success-fill);
  color: #fff;
}

/* --- Modal ------------------------------------------------------------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 10, 25, 0.5);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3);
  z-index: 1100;
  animation: overlay-in 150ms var(--ease);
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-4);
  max-width: 380px;
  width: 100%;
  animation: modal-in 200ms var(--ease-pop);
}

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .modal-overlay,
  .modal {
    animation: none;
  }
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

/* --- Recording (Phase 2, docs/ROADMAP.md) ----------------------------------------- */

.notice--warning {
  border-color: var(--color-danger);
  color: var(--color-danger);
}

.record-acquiring {
  text-align: center;
  padding: var(--space-6) var(--space-3);
}

.record-card {
  max-width: 720px;
  margin: 0 auto;
}

/* "Record" (h1) / status badge / track name, all on the header's one row (requested
   2026-08-08 — was title-then-badge-on-two-rows, wasting a full row on a phone screen
   already tight during recording). `.page-header`'s own flex-wrap:wrap is overridden
   here: this row must never wrap per that request, so the track name truncates with an
   ellipsis instead — see `.record-header-status__name` below. */
.record-page-header {
  flex-wrap: nowrap;
  margin-bottom: 8px;
}

.record-page-header h1 {
  flex: none;
  margin: 0;
}

.record-header-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  overflow: hidden;
}

.record-header-status__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-status-badge {
  display: inline-flex;
  align-items: center;
  flex: none;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--color-success-fill), #0b846e);
  color: #fff;
}

.record-status-badge--paused {
  background: var(--color-surface-2);
  color: var(--color-muted);
}

.record-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  margin-right: 6px;
  animation: record-pulse 1.6s ease-in-out infinite;
}

@keyframes record-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
  .record-status-dot {
    animation: none;
  }
}

/* Ten uniform tiles (Avg Speed/Speed/Max Speed/Altitude/Elapsed/Distance/Points/Accuracy/
   Heading/Elevation Gain, in that DOM order) in a 2-column grid at every width — was 3
   columns, dropped to 2 (see record.js's docblock above recordingHtml()) because a 1/3-
   width tile didn't have room for a 3-digit speed value (e.g. "108.3 km/h") at 1.25rem
   bold without wrapping/overflowing. 2 columns is, like the 3-column layout it replaces,
   not a mobile-width override — 10 divides evenly by 2 at any screen size, so there's no
   wider-screen layout worth switching to either. */
.record-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  width: 100%;
  margin-bottom: 10px;
}

.record-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  min-height: 0;
  padding: 7px 4px 6px;
  background: var(--color-surface-2);
  border-radius: var(--radius);
  transition: background var(--transition);
}

/* A small emoji glyph per tile — no new asset, no SVG upkeep, and it matches an idiom this
   app already uses elsewhere (bookmark icons, "Copy GPS" 📍, the rename ✏️ button) rather
   than inventing a second icon system next to ui.js's hand-drawn nav set. Purely
   decorative (aria-hidden in record.js) — the text label below still carries the name. */
.record-stat__icon {
  font-size: 0.9rem;
  line-height: 1;
  opacity: 0.9;
}

/* line-height explicitly tightened (not just inherited from body's 1.55) — at that
   inherited line-height these two lines alone accounted for most of a tile's height,
   which is why the previous font-size-only pass wasn't enough to fit ten tiles on one
   iPhone screen; 1.15 still leaves comfortable line spacing for text this short. */
.record-stat__value {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.record-stat__label {
  font-size: 0.58rem;
  color: var(--color-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1.15;
}

/* The "Heading" tile is a real <button> (opens the compass modal) among otherwise
   inert <div> tiles — same tile look, but interactive: no border/font styling of its
   own to inherit from the browser's default button appearance. */
.record-stat--heading {
  font: inherit;
  color: inherit;
  border: none;
  cursor: pointer;
}

.record-stat--heading:hover {
  background: var(--color-border);
}

.mini-arrow {
  display: block;
  width: 18px;
  height: 18px;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (prefers-reduced-motion: reduce) {
  .mini-arrow {
    transition: none;
  }
}

.mini-arrow__svg {
  width: 100%;
  height: 100%;
  fill: var(--color-danger);
}

.record-stat--no-heading .mini-arrow__svg {
  fill: var(--color-muted);
}

.record-stat--no-heading .record-stat__value {
  color: var(--color-muted);
  font-weight: 400;
}

/* --- Compass (full dial, in the modal opened from the "Heading" tile) -------------
   Shows direction of travel (GPS heading), not device/magnetometer orientation — see
   assets/js/views/record.js's compassHtml() docblock. */

.compass-modal {
  max-width: 300px;
}

.compass {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  max-width: 220px;
  margin: 0 auto;
}

.compass__svg {
  width: 100%;
  height: auto;
}

.compass__rim {
  fill: var(--color-surface-2);
  stroke: var(--color-border);
  stroke-width: 2;
}

.compass__tick {
  stroke: var(--color-border);
  stroke-width: 2;
}

.compass__tick--major {
  stroke: var(--color-muted);
  stroke-width: 3;
}

.compass__label {
  font-size: 16px;
  font-weight: 700;
  fill: var(--color-muted);
  text-anchor: middle;
  dominant-baseline: middle;
}

.compass__label--n {
  fill: var(--color-danger);
}

.compass__needle {
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  /* Bug fix: the needle used to render nowhere near its own heading readout (reported
     against a real device — screenshot showed the arrow pointing well away from the
     "330° NNW" text next to it), and this was worse than a wrong pivot: confirmed with a
     side-by-side test render (every heading 0-350°, this exact markup/CSS), the needle
     was outright invisible at most angles and warped at the rest. Cause: this rule used
     to also set `transform-origin: 100px 100px`. record.js sets rotation via the SVG
     *presentation attribute* (`transform="rotate(deg 100 100)"` on the <g>, the
     three-argument SVG rotate-about-a-point form) — but the moment a `transform-origin`
     is declared in CSS on that same element, browsers stop reading the attribute as SVG
     syntax and reinterpret it as a *CSS* transform value instead, where `rotate()` only
     takes one argument. The trailing "100 100" isn't valid there, so the whole computed
     transform came out broken rather than merely off-center — changing which *box*
     `transform-origin` measured against (view-box, fill-box, border-box — all tried)
     made no difference, because the origin declaration itself was the problem. Simplest
     fix, confirmed correct at every heading in that same test render: don't declare
     `transform-origin` here at all, and let the presentation attribute's own built-in
     rotate-about-(100,100) apply exactly as SVG defines it. */
}

@media (prefers-reduced-motion: reduce) {
  .compass__needle {
    transition: none;
  }
}

.compass__needle-face--north {
  fill: var(--color-danger);
}

.compass__needle-face--south {
  fill: var(--color-muted);
}

.compass__hub {
  fill: var(--color-text);
  stroke: var(--color-surface);
  stroke-width: 2;
}

.compass__readout {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.compass--no-heading .compass__needle {
  opacity: 0.3;
}

.compass--no-heading .compass__readout {
  color: var(--color-muted);
  font-weight: 400;
}

.activity-picker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: var(--space-2);
}

.activity-option {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 14px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-2);
  font-weight: 600;
  font-size: 0.85rem;
  text-align: center;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform 100ms var(--ease);
}

.activity-option__icon {
  font-size: 1.3rem;
  line-height: 1;
}

.activity-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.activity-option:has(input:checked) {
  border-color: transparent;
  background: var(--gradient-primary-fill);
  color: #fff;
  box-shadow: var(--shadow-primary);
}

.activity-option:active {
  transform: scale(0.97);
}

.activity-option:has(input:focus-visible) {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* --- Dashboard actions (Phase 3) ------------------------------------------------- */

.dashboard-actions {
  display: flex;
  justify-content: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin: 0;
}

/* --- Track list (Phase 3, docs/ROADMAP.md "Maps and lists") ---------------------- */

.track-filters {
  display: grid;
  grid-template-columns: 2fr repeat(3, 1fr);
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.track-filters__search,
.track-filters select {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
}

.track-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-3);
}

.track-card {
  position: relative;
  display: block;
  text-align: left;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}

.track-card:hover,
.track-card:focus-visible {
  border-color: var(--color-primary);
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.track-card:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.track-card__map {
  height: 140px;
  background: var(--color-surface-2);
  /* Leaflet needs an explicit, already-laid-out size before init (map.js's
     invalidateSize() call in tracks.js covers the async-content edge case) — this fixed
     height is what makes that size non-zero on first paint. */
}

.track-card__map--error {
  display: flex;
  align-items: center;
  justify-content: center;
}

.track-card__map--error::after {
  content: 'Map unavailable';
  color: var(--color-muted);
  font-size: 0.85rem;
}

.track-card__body {
  padding: var(--space-3);
}

.track-card__title-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.track-card__title-row h3 {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.track-card__meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-2);
  margin-top: var(--space-1);
  font-size: 0.85rem;
}

.track-card__stats {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-border);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}

.track-loading {
  text-align: center;
  padding: var(--space-3);
}

/* --- Track detail (Phase 3) ------------------------------------------------------- */

.detail-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.dropdown {
  position: relative;
}

.dropdown__menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-1);
  flex-direction: column;
  min-width: 140px;
  z-index: 10;
}

/* `[hidden]` and `.dropdown__menu` are equal-specificity class/attribute selectors, so
   without this the `display: flex` below would win the cascade (author styles load after
   the UA stylesheet) and the menu would render permanently open regardless of the
   `hidden` attribute track-detail.js toggles — caught by a real rendered screenshot
   during Phase 3 verification, not visible from the DOM/JS logic alone. */
.dropdown__menu:not([hidden]) {
  display: flex;
  animation: dropdown-in 120ms var(--ease-pop);
}

@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .dropdown__menu:not([hidden]) {
    animation: none;
  }
}

.dropdown__menu a {
  padding: var(--space-2) var(--space-2);
  border-radius: calc(var(--radius-sm) - 2px);
  text-decoration: none;
  color: var(--color-text);
  font-size: 0.9rem;
}

.dropdown__menu a:hover {
  background: var(--color-surface-2);
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.detail-map-card {
  padding: 0;
  overflow: hidden;
  margin-bottom: var(--space-4);
  position: relative;
  cursor: pointer;
}

.detail-map {
  height: 420px;
}

.detail-chart-card {
  margin-bottom: var(--space-4);
}

.chart-wrap {
  position: relative;
  height: 260px;
}

.shares-list {
  margin: 0;
  padding-left: var(--space-4);
}

/* --- Bookmarks (Phase 4) ----------------------------------------------------------- */

.bookmark-filters {
  grid-template-columns: 2fr repeat(2, 1fr);
}

.bookmark-layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: var(--space-4);
  align-items: start;
}

.bookmark-list-pane {
  min-width: 0;
}

.bookmark-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.bookmark-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}

.bookmark-row:hover {
  border-color: var(--color-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.bookmark-row--active {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px var(--color-primary);
}

.bookmark-row__swatch {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  margin-top: 5px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}

.bookmark-row__body {
  flex: 1;
  min-width: 0;
}

.bookmark-row__title-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.bookmark-row__description {
  margin: var(--space-1) 0;
  overflow-wrap: anywhere;
}

/* views/bookmark-detail.js's full-page counterpart to `.bookmark-row__description` above —
   deliberately does NOT redeclare font-size/color/line-height/margin: on that page it's a
   plain paragraph in the page flow (same role as views/track-detail.js's own undecorated
   `<p>${track.notes}</p>`), so it already inherits the base `p` rule's margin and the body
   text's colour/line-height for free, exactly like that counterpart does. Only picks up
   `.bookmark-row__description`'s overflow-wrap safeguard, since a user-entered description
   can just as easily be one long unbroken string here as in the row. */
.bookmark-detail__description {
  overflow-wrap: anywhere;
}

.bookmark-row__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  font-size: 0.85rem;
}

/* One horizontal, wrapping row of same-size buttons (Open in Google Maps, Copy GPS,
   Share/Edit/Delete) below the row's meta line — nested inside `.bookmark-row__body` now,
   not a separate flex column beside it, so every action reads as one consistent group
   rather than "info actions" (a plain link) split visually from "owner actions" (buttons
   in their own column). */
.bookmark-row__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-top: var(--space-2);
}

.bookmark-map-card {
  padding: 0;
  overflow: hidden;
  position: sticky;
  top: var(--space-3);
}

.bookmark-map {
  height: 520px;
  cursor: pointer;
}

/* The "find a place to bookmark" search (Nominatim) sits above the map inside the same
   card — a normal-flow toolbar row, not overlaid on the map itself, so it never competes
   with map dragging/tapping for touch input. */
.map-search {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-3) 0;
}

.map-search__input {
  flex: 1;
  min-width: 0;
}

/* Absolutely positioned so it overlays the map below the toolbar rather than pushing it
   down — the card's own `overflow: hidden` (above) clips it at the card's edge, and
   `max-height`/`overflow-y` keep a long result set scrollable within that instead of
   spilling past it. */
.map-search__results {
  position: absolute;
  z-index: 500; /* above Leaflet's own panes (max ~650 for popups, but well above tile/marker panes) */
  /* `top` is set from JS (wireMapSearch()), not a fixed value here — the search bar's
     rendered height (font size, theme) isn't a constant this stylesheet can predict. */
  left: var(--space-3);
  right: var(--space-3);
  max-height: 260px;
  overflow-y: auto;
  margin: 0;
  padding: var(--space-1);
  list-style: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.map-search__result {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-2);
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.map-search__result:hover {
  background: var(--color-surface-2);
}

.map-search__empty {
  padding: var(--space-2);
}

/* Overrides Leaflet's default `.leaflet-div-icon` white box/border, which `L.divIcon`
   would otherwise apply — createBookmarkIcon() supplies its own fully-styled SVG pin, so
   the wrapping div itself should stay invisible. */
.bookmark-marker {
  background: transparent;
  border: none;
}

.bookmark-modal {
  max-width: 480px;
}

.bookmark-modal__location {
  margin-top: calc(var(--space-2) * -1);
}

.swatch-picker,
.icon-picker {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-1);
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 100ms var(--ease);
}

.swatch--selected {
  border-color: var(--color-text);
  transform: scale(1.12);
}

.icon-swatch {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.icon-swatch--selected {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 1px var(--color-primary);
}

/* --- Groups (Phase 9, dropdown layout 2026-09-21) -----------------------------------
   Reuses .bookmark-layout/.bookmark-row/.bookmark-map-card wholesale for the detail pane
   (a group's item list is shaped exactly like the bookmarks list, just mixing tracks and
   bookmarks) — only the group-select dropdown and the small colour-swatch pickers below
   are genuinely new. The old scrollable sidebar list (.groups-layout/.groups-sidebar/
   .group-list/.group-row and friends) is gone — a native <select> (below) replaced it, so
   the detail pane is now the page's only column, full width. */

/* Lives in the page-header row now (title left, this form right, one row — requested
   2026-08-08; was its own row inside the old sidebar card, costing a full row there for
   no benefit). `.groups-page-header` below forces that row to never wrap; the input is
   the one flexible part, shrinking via min-width:0 rather than pushing the "+ Add"
   button off a narrow phone's screen. */
.groups-page-header {
  flex-wrap: nowrap;
}

.groups-page-header h1 {
  flex: none;
}

.groups-new-form {
  display: flex;
  gap: var(--space-1);
  flex: 1;
  min-width: 0;
  max-width: 280px;
}

.groups-new-form input {
  flex: 1;
  min-width: 0;
}

/* The group picker itself (replaces the old sidebar list, 2026-09-21) — a native <select>
   rather than a rebuilt custom widget: this app already has one real dropdown pattern
   (ui.js's wireDropdown(), used for the track-detail Export menu), but that's an
   open/close *action menu* of links, not a bound single-value control with a `change`
   event — a plain <select> is the simpler, more accessible fit for "pick one group",
   and its own `change` event drives selectGroup() exactly like clicking a sidebar row
   used to. */
/* Visibility/sort bar above #group-select (2026-09-21, groups sharing) — same two-select
   shape as .track-filters/.bookmark-filters minus their search box, so it gets its own
   lighter grid rather than reusing a 4-column one sized for those pages' extra fields. */
.groups-filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.groups-filter-row select {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
}

.groups-select-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.groups-select-row__label {
  font-weight: 600;
  flex: none;
}

.group-select {
  flex: 1;
  max-width: 380px; /* echoes .groups-detail__body's item-list column width below */
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b6e85' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 34px;
}

/* Compact 2026-08-08 refinement: was 3 rows (name+Add/Remove, then Select/Deselect
   alone, then the track/bookmark count alone below that) — the count and the
   Select-all/Deselect-all pair now share one row instead of each wasting a whole row
   to itself, and the card's own padding/gap is trimmed to match (this header is just a
   compact status strip, not a content card). */
.groups-detail__header {
  padding: var(--space-3);
  margin-bottom: var(--space-2);
}

.groups-detail__header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.groups-detail__header-row h2 {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
}

.groups-detail__swatch {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
}

/* Row 2: item count on the left, Select all/Deselect all on the right — the
   groups-detail__header's docblock above. */
.groups-detail__header-row2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: var(--space-1);
}

.groups-detail__header-row2 p {
  margin: 0;
}

.groups-detail__body {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: var(--space-4);
  align-items: start;
}

/* `.bookmark-list-pane`'s same grid-item overflow fix (line ~1400 above) — missing here
   despite `.groups-detail__body` reusing that exact same grid-template-columns and the
   same `.bookmark-list` markup wholesale (this section's own docblock). Without it, a
   grid item defaults to `min-width: auto`, so a long unbroken track/bookmark name in the
   list can force this column wider than its `minmax(280px, 380px)` track (and, below the
   860px breakpoint where the grid collapses to one column, wider than the viewport). */
.groups-detail__list-pane {
  min-width: 0;
}

/* Sort control for the selected group's own track+bookmark list (2026-09-21, groups
   sharing) — small and right-aligned, sitting above the list itself rather than competing
   with .groups-detail__header's own name/action-button rows for space. */
.groups-item-sort-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.groups-item-sort-row label {
  font-size: 0.85rem;
  color: var(--color-muted);
}

.groups-item-sort-row select {
  font: inherit;
  font-size: 0.85rem;
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
}

/* The checkbox list shared by group-picker.js (per-item "which groups") and groups.js's
   "Add items…" modal — same shape/spacing as .swatch-picker/.icon-picker above, just a
   vertical checkbox list instead of a row of swatches. */
.group-picker-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  max-height: 320px;
  overflow-y: auto;
  margin-top: var(--space-1);
}

.group-picker-list__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
}

.group-picker-list__item:hover {
  background: var(--color-surface-2);
}

.group-picker-list__swatch {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

@media (max-width: 860px) {
  .groups-detail__body {
    grid-template-columns: 1fr;
  }
  /* .bookmark-map-card's own static-position/order-first mobile override (below, same
     860px breakpoint) already applies here too — reused, not repeated. */
}

/* --- Sharing (Phase 5) / Admin data management (Phase 5b) ------------------------- */

.admin-banner {
  background: var(--color-warning-bg);
  color: var(--color-warning);
  border: 1px solid var(--color-warning);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-3);
  font-size: 0.9rem;
}

.btn--icon {
  padding: 2px 6px;
  font-size: 0.9rem;
  vertical-align: middle;
}

.btn--small {
  padding: 5px 12px;
  font-size: 0.85rem;
}

.rename-form {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  margin: 0;
}

.rename-form input {
  font: inherit;
  font-size: 1.25rem;
  font-weight: 700;
  padding: 4px 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
}

.shares-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-1) 0;
}

.field--inline {
  flex-direction: row;
  align-items: center;
  gap: var(--space-1);
}

.admin-tabs {
  display: flex;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
}

.admin-tab--active {
  background: var(--gradient-primary-fill);
  border-color: transparent;
  color: #fff;
}

/* Bug fix: real-device testing of the merge feature (views/tracks.js) found this bar
   showing permanently, with nothing selected, regardless of the `hidden` attribute
   tracks.js/admin-data.js toggle — a real contributor, on top of the checkbox's tap
   target fixed above, to merging feeling broken/unusable. Same cause and same fix as the
   `.dropdown__menu:not([hidden])` rule below: an unconditional `display: flex` here
   outranks the UA stylesheet's `[hidden] { display: none }` at equal specificity, so it
   always won. */
.admin-bulk-bar:not([hidden]) {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: color-mix(in srgb, var(--color-primary) 8%, var(--color-surface-2));
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-3);
}

.admin-bulk-bar span {
  color: var(--color-muted);
  font-size: 0.85rem;
  margin-right: auto;
}

/* Lives in the card's title row (cardHtml()), not floating over the mini-map — a real
   floating checkbox there was, per real-use feedback, sometimes not visible at all
   (nothing to do with tap-target size, the previous fix here: a grid of only
   shared-with-me tracks renders zero checkboxes when the control only exists for owned
   tracks, which reads identically to "the checkbox is broken"). Always rendered now
   (disabled, with a reason, when not selectable) — see cardHtml()'s docblock. 44px+ tap
   target (Apple HIG's minimum) on the label, not the checkbox's own ~13px box. */
.track-card__select {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin: -6px 0 -6px -6px; /* the extra tap-target padding shouldn't widen the row's own gap */
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.track-card__select:has(input:disabled) {
  cursor: not-allowed;
  opacity: 0.35;
}

.track-card__select input {
  width: 20px;
  height: 20px;
}

/* --- PWA: update prompt, offline/pending-sync indicator (Phase 7) ----------------- */

.update-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1100; /* above .toast-container (1000) — an update prompt shouldn't be missed under a toast */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--color-text);
  color: var(--color-bg);
  font-size: 0.9rem;
  flex-wrap: wrap;
}

.connectivity-status {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 900; /* below toasts/update banner, above ordinary page content */
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  text-align: center;
  padding: 6px var(--space-3);
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.connectivity-status__sync-btn {
  font-weight: 600;
}

.connectivity-status--offline {
  background: var(--color-danger-fill);
  color: #fff;
}

/* --- Editing (Phase 6) ------------------------------------------------------------ */

.edit-panel {
  margin-top: var(--space-4);
}

.edit-panel__group {
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-border);
}

.edit-panel__group:first-of-type {
  border-top: none;
  padding-top: var(--space-2);
}

.edit-panel__group h3 {
  margin: 0 0 var(--space-1);
  font-size: 0.95rem;
}

.edit-panel__group .form-row {
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

/* --- Responsive ------------------------------------------------------------------ */

@media (max-width: 640px) {
  .main-content {
    padding: var(--space-3);
  }
  .activity-picker {
    grid-template-columns: repeat(3, 1fr);
  }
  /* One row, always — the grid above (search on its own row, selects 2-up below) took 3
     rows on an iPhone-width screen. `overflow-x: auto` is a safety valve matching the
     nav bar's own pattern (ui.js's navHtml() docblock), not the intended fit: the
     shrunk widths below were sized to actually fit a 393px viewport without scrolling. */
  .track-filters {
    display: flex;
    flex-wrap: nowrap;
    gap: var(--space-1);
    overflow-x: auto;
  }
  .track-filters__search {
    flex: 1 1 76px;
    min-width: 0;
    padding: 8px 10px;
    font-size: 0.85rem;
  }
  .track-filters select {
    flex: 1 1 0;
    min-width: 0;
    padding: 8px 4px;
    font-size: 0.8rem;
  }
  .groups-filter-row {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-1);
  }
  .groups-filter-row select {
    padding: 8px 6px;
    font-size: 0.8rem;
  }
  .detail-stats {
    grid-template-columns: repeat(2, 1fr);
  }
  .detail-map {
    height: 280px;
  }
  .bookmark-layout {
    grid-template-columns: 1fr;
  }
  .bookmark-map-card {
    position: static;
    order: -1; /* the map first on a phone — dropping a pin needs it on screen without scrolling past the list */
  }
  .bookmark-map {
    height: 320px;
  }
  .bookmark-row {
    flex-wrap: wrap;
  }
}

/* --- Fullscreen map overlay (map/fullscreen.js, requested 2026-09-21) -------------------- */

/* Leaflet tiles are <img> elements, and iOS Safari shows its own native "Save Photo / Copy"
   long-press callout on images — without this, that native callout intercepts a long-press
   on the map before Leaflet's TapHold handler can simulate the `contextmenu` event that
   "long-press to bookmark" (views/track-detail.js's handleMapBookmarkTap()) listens for. */
.leaflet-container img {
  -webkit-touch-callout: none;
}

.map-fullscreen-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  /* `100dvh` (not `inset: 0`'s implicit `bottom: 0`) deliberately — on iOS Safari (not an
     installed PWA, where the browser's own address bar/bottom toolbar is still on screen),
     a `position: fixed` element sized via `inset: 0`/`bottom: 0` is sized against the "large"
     viewport as if that toolbar were hidden, even while it's actually still covering part of
     the screen. That pushed bottom-anchored content — `.map-picker__confirm`'s "Use this
     location"/"📍 Bookmark this point"/"📍 Add bookmark here" button below — off the visible
     screen and unreachable. `100dvh` (dynamic viewport height) tracks the toolbar live, so
     `bottom`-anchored children stay within whatever's actually visible. The `100vh` line first
     is a fallback for browsers that don't understand `dvh` — they ignore the next line and
     keep this one. */
  height: 100vh;
  height: 100dvh;
  /* Above ordinary page content/nav (.app-nav is 800) and #connectivity-status (900), but
     BELOW .toast-container (1000) and .modal-overlay/.update-banner (1100) — unlike every
     other overlay in this app, this one can itself stay open while a *further* modal opens
     on top of it (views/track-detail.js's "bookmark this point" openBookmarkForm(), called
     from a tap on the still-open fullscreen map) or a toast fires (that same flow's "Bookmark
     saved." toast) — both need to render above this, not disappear behind it. */
  z-index: 950;
  background: var(--color-surface);
}

.map-fullscreen__map {
  position: absolute;
  inset: 0;
  /* z-index (not just position) is required here to make this element establish its own
     stacking context. Without it, Leaflet's internal panes/control-container carry their
     own z-index values (tilePane 200 up to the control container's 1000) that are NOT
     contained by this div — they leak into the parent .map-fullscreen-overlay stacking
     context and paint OVER .map-fullscreen__topbar's z-index:2, hiding the close button
     visually (it still received clicks, since its DOM position was correct — only the
     paint order was wrong). Giving this element its own stacking context traps every
     Leaflet z-index inside it, so only ITS OWN z-index (1, below the topbar's 2) is what
     competes with siblings. */
  z-index: 1;
}

.map-fullscreen__topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: calc(env(safe-area-inset-top, 0px) + var(--space-2)) calc(env(safe-area-inset-right, 0px) + var(--space-2))
    var(--space-2) calc(env(safe-area-inset-left, 0px) + var(--space-2));
}

.map-fullscreen__close {
  flex: none;
  /* Pushes the button to the topbar's right edge in both modes: in picker mode the
     flex:1 1 auto search box already fills the space to its left (this is then a
     no-op), but in non-picker mode this button is the topbar's ONLY child, so without
     this it sits flush top-left — directly under Leaflet's default topleft
     zoomControl (see map.js's createMap(), which sets no position override) and
     becomes visually and click-overlapped with the +/- zoom buttons. */
  margin-left: auto;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-lg);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.map-picker__search {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

.map-picker__search-input {
  width: 100%;
  height: 44px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  box-shadow: var(--shadow-lg);
  padding: 0 var(--space-3);
  font-size: 1rem;
}

.map-picker__results {
  position: absolute;
  top: calc(100% + var(--space-1));
  left: 0;
  right: 0;
  margin: 0;
  padding: var(--space-1);
  list-style: none;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 260px;
  overflow-y: auto;
}

.map-picker__result {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
}

.map-picker__result:hover,
.map-picker__result:focus {
  background: var(--color-surface-2);
}

.map-picker__confirm {
  position: absolute;
  left: 50%;
  /* `translate` (a separate CSS property from `transform`, not `transform: translateX(...)`)
     — deliberate. This button also carries `.btn`'s classes, and `.btn:active:not(:disabled)`
     / `.btn:disabled` both set `transform` with higher specificity than this single-class
     rule, so a `transform`-based centering here gets silently wiped out the instant the user
     presses the button (`:active` fires on press, before the click registers) — on desktop
     that visibly shifted the button out from under the cursor at the exact moment of the
     click, missing the press entirely. `translate` composes independently of `transform`, so
     centering survives `.btn`'s own press/disabled transform changes. */
  translate: -50% 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + var(--space-3));
  z-index: 2;
  min-height: 48px;
  padding-left: var(--space-4);
  padding-right: var(--space-4);
  box-shadow: var(--shadow-lg);
}

@media (max-width: 480px) {
  .map-fullscreen__topbar {
    flex-wrap: wrap;
  }
  .map-picker__confirm {
    left: var(--space-3);
    right: var(--space-3);
    translate: none;
    width: calc(100% - var(--space-3) * 2);
  }
}
