/* ==========================================================================
   Design tokens. The palette follows iOS system colours, with maple red as the tint.
   ========================================================================== */
:root {
  --bg: #f2f2f7;            /* grouped background */
  --surface: #ffffff;       /* cells, cards */
  --surface-2: #ebebf0;     /* fills: inputs, inactive controls */
  --text: #000000;
  --muted: #6d6d72;
  --border: #d1d1d6;        /* separators */
  --accent: #d0021b;
  --accent-text: #ffffff;
  --track: #0057e7;
  --plan: #6e6e73;
  --live: #34c759;
  --stale: #8e8e93;
  --danger: #ff3b30;
  --blue: #007aff;
  --glass: rgb(255 255 255 / 0.72);
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 6px 20px rgb(0 0 0 / 0.08);
  --float-shadow: 0 8px 28px rgb(0 0 0 / 0.16), 0 1px 3px rgb(0 0 0 / 0.08);
  --radius: 14px;
  --nav-h: calc(56px + env(safe-area-inset-top));
  --tab-h: 62px;
  --bottom-gap: max(14px, env(safe-area-inset-bottom));
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --text: #ffffff;
    --muted: #98989f;
    --border: #38383a;
    --accent: #ff453a;
    --track: #3d8bff;
    --plan: #a1a1a6;
    --live: #30d158;
    --stale: #8e8e93;
    --danger: #ff453a;
    --blue: #0a84ff;
    --glass: rgb(30 30 32 / 0.72);
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 6px 20px rgb(0 0 0 / 0.35);
    --float-shadow: 0 8px 28px rgb(0 0 0 / 0.5), 0 1px 3px rgb(0 0 0 / 0.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --text: #ffffff;
  --muted: #98989f;
  --border: #38383a;
  --accent: #ff453a;
  --track: #3d8bff;
  --plan: #a1a1a6;
  --live: #30d158;
  --stale: #8e8e93;
  --danger: #ff453a;
  --blue: #0a84ff;
  --glass: rgb(30 30 32 / 0.72);
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 6px 20px rgb(0 0 0 / 0.35);
  --float-shadow: 0 8px 28px rgb(0 0 0 / 0.5), 0 1px 3px rgb(0 0 0 / 0.4);
  color-scheme: dark;
}

/* ==========================================================================
   Base
   ========================================================================== */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.error { color: var(--danger); min-height: 1.2em; margin: 0.4rem 0 0; }
.mono { font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace; font-weight: 500; color: var(--muted); }
.ic { width: 1.25em; height: 1.25em; flex: none; vertical-align: -0.25em; }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; clip-path: inset(50%); pointer-events: none; }
body:not(.owner) .owner-only { display: none !important; }
.empty { color: var(--muted); text-align: center; padding: 2.5rem 1rem; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 60%, transparent); }
  70% { box-shadow: 0 0 0 9px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ==========================================================================
   Header / nav bar
   ========================================================================== */
.top {
  display: flex; align-items: center; gap: 0.75rem 1.5rem;
  padding: max(0.7rem, env(safe-area-inset-top)) 20px 0.7rem;
  background: var(--surface); border-bottom: 0.5px solid var(--border);
  position: relative; z-index: 1200;
}
.brand { min-width: 0; flex: 1; }
.brand h1 { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand h1 > span, .title-btn > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.brand h1 .avatar { width: 28px; height: 28px; font-size: 0.85rem; }
.title-btn { appearance: none; border: 0; background: none; padding: 0; margin: 0; font: inherit; color: inherit; cursor: pointer; display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%; text-align: left; }
.title-chev { width: 18px; height: 18px; color: var(--muted); flex: none; }
.driving-list li { padding: 0; }
.driving-opt { appearance: none; border: 0; background: none; font: inherit; color: var(--text); cursor: pointer; width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px 14px; text-align: left; }
.driving-opt .avatar { width: 30px; height: 30px; font-size: 0.85rem; }
.driving-opt .leg-main { display: flex; flex-direction: column; }
.driving-check { width: 20px; height: 20px; color: var(--accent); }
.status { display: flex; align-items: center; gap: 0.4rem; color: var(--muted); font-size: 0.85rem; margin-top: 0.15rem; min-width: 0; }
.status #status-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--stale); flex: none; }
.status.live { color: color-mix(in srgb, var(--live) 60%, var(--text)); }
.status.live .dot { background: var(--live); animation: pulse 2s infinite; }
.stats { display: flex; gap: 1.75rem; margin: 0; }
.stats div { text-align: right; }
.stats dt { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.stats dd { margin: 0; font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.nav-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  appearance: none; border: 0; background: none; color: var(--accent); cursor: pointer;
  width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
}
.icon-btn .ic { width: 22px; height: 22px; }
.icon-btn:hover { background: var(--surface-2); }

/* Location sharing toggle: grey "Share" when off, green "Live" when on */
.loc-toggle {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-size: 0.88rem; font-weight: 600;
  display: inline-flex; align-items: center; gap: 0.35rem; height: 34px; padding: 0 0.8rem 0 0.65rem; border-radius: 99px;
  background: var(--surface-2); color: var(--text); transition: background 0.2s, color 0.2s;
}
.loc-toggle .ic { width: 17px; height: 17px; }
.loc-toggle[aria-pressed="true"] { background: var(--live); color: #fff; }
.loc-toggle:active { transform: scale(0.96); }

/* ==========================================================================
   Layout (desktop: map + sidebar)
   ========================================================================== */
.layout { flex: 1; display: grid; grid-template-columns: 1fr 420px; min-height: 0; }
.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--surface-2); }
.panel { display: flex; flex-direction: column; min-height: 0; background: var(--bg); border-left: 0.5px solid var(--border); position: relative; }
.tabs { display: flex; gap: 0.25rem; padding: 0.4rem 14px 0; border-bottom: 0.5px solid var(--border); background: var(--surface); overflow-x: auto; scrollbar-width: none; }
.tabs button {
  appearance: none; border: 0; background: none; color: var(--muted); flex: none;
  padding: 0.65rem 0.8rem; font: inherit; font-weight: 600; font-size: 0.95rem; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -0.5px;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tab-body { flex: 1; overflow-y: auto; padding: 14px; overscroll-behavior: contain; }
.tabbar, .radio-seg { display: none; }
body.map-full .layout { grid-template-columns: 1fr; }
body.map-full .panel { display: none; }
body.locked .tabs [data-tab="photos"], body.locked .tabbar [data-screen="photos"] { display: none; }

.foot { display: flex; justify-content: space-between; gap: 1rem; padding: 1.5rem 4px 0.5rem; font-size: 0.8rem; color: var(--muted); }
body.owner .foot { display: none; }
.linkish { appearance: none; border: 0; background: none; color: var(--muted); font: inherit; cursor: pointer; text-decoration: underline; padding: 0; }

/* ==========================================================================
   Map
   ========================================================================== */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .map-detailed .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.88) contrast(0.9); }
  :root:not([data-theme="light"]) .leaflet-control-layers-toggle { filter: invert(1) brightness(0.9); }
}
:root[data-theme="dark"] .map-detailed .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.88) contrast(0.9); }
:root[data-theme="dark"] .leaflet-control-layers-toggle { filter: invert(1) brightness(0.9); }
.leaflet-container { font: inherit; background: var(--surface-2); }
.leaflet-bar, .leaflet-control-layers {
  border: 0 !important; border-radius: 12px !important; overflow: hidden; box-shadow: var(--float-shadow) !important;
  background: var(--glass) !important; backdrop-filter: blur(20px) saturate(180%); -webkit-backdrop-filter: blur(20px) saturate(180%);
}
.leaflet-bar a { background: transparent !important; color: var(--text) !important; border-bottom: 0.5px solid var(--border) !important; width: 38px !important; height: 38px !important; line-height: 38px !important; }
.leaflet-bar a:last-child { border-bottom: 0 !important; }
.leaflet-bar a:hover { background: var(--surface-2) !important; }
.leaflet-control-layers-expanded { color: var(--text); padding: 8px 12px; }
.trip-ctl a { display: grid !important; place-items: center; }
.trip-ctl a .ic { width: 19px; height: 19px; }
.trip-ctl a.on { color: var(--blue) !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); box-shadow: var(--float-shadow); }
.leaflet-popup-content-wrapper { border-radius: 14px; }
.leaflet-popup-content { font-size: 14px; line-height: 1.4; }
.leaflet-popup-content b.mono { color: var(--text); }
.leaflet-container .leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 70%, transparent); color: var(--muted); font-size: 10px; line-height: 1.4; border-radius: 6px 0 0 0; }
.leaflet-control-attribution a { color: inherit; }
body.picking #map { cursor: crosshair; }

.me-marker {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: #fff;
  background: var(--stale); border: 3px solid #fff; box-shadow: 0 2px 8px rgb(0 0 0 / 0.35);
}
.me-marker .ic { width: 18px; height: 18px; }
.me-marker.live { background: var(--live); animation: pulse 2s infinite; }
.photo-marker { position: relative; width: 40px; height: 40px; border-radius: 10px; border: 2px solid #fff; box-shadow: 0 2px 6px rgb(0 0 0 / 0.35); background: #ccc center / cover no-repeat; }
.photo-marker.cluster { width: 48px; height: 48px; border-radius: 12px; }
.photo-marker .count {
  position: absolute; top: -8px; right: -8px; min-width: 21px; height: 21px; padding: 0 5px; border-radius: 11px;
  background: var(--accent); color: #fff; font: 600 11px/17px -apple-system, system-ui, sans-serif; text-align: center; border: 2px solid #fff;
}
.qso-marker { width: 24px; height: 24px; border-radius: 50%; background: var(--blue); color: #fff; display: grid; place-items: center; border: 2px solid #fff; box-shadow: 0 1px 4px rgb(0 0 0 / 0.35); }
.qso-marker .ic { width: 13px; height: 13px; }
.rpt-marker { width: 12px; height: 12px; border-radius: 3px; background: #af52de; border: 2px solid #fff; box-shadow: 0 0 0 1px rgb(0 0 0 / 0.25); }

/* Trip summary card floating over the map; collapses to a slim bar */
.summary {
  position: absolute; z-index: 800; left: 14px; bottom: 26px; width: min(360px, calc(100% - 28px));
  padding: 4px 16px 12px; border-radius: 22px; color: var(--text);
  background: var(--glass); backdrop-filter: blur(28px) saturate(180%); -webkit-backdrop-filter: blur(28px) saturate(180%);
  box-shadow: var(--float-shadow); border: 0.5px solid color-mix(in srgb, var(--border) 55%, transparent);
}
.summary.collapsed { padding: 0 6px 0 14px; border-radius: 99px; width: auto; max-width: calc(100% - 28px); }
.sum-head {
  appearance: none; border: 0; background: none; font: inherit; color: inherit; cursor: pointer; width: 100%;
  display: flex; align-items: center; gap: 8px; padding: 10px 0 6px; text-align: left;
}
.summary.collapsed .sum-head { padding: 10px 2px 10px 0; }
.sum-title { flex: 1; min-width: 0; font-size: 0.95rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sum-title span { color: var(--muted); font-weight: 500; }
.summary.collapsed .sum-title { font-weight: 600; }
.sum-lead { width: 17px; height: 17px; color: var(--blue); }
.sum-speed {
  flex: none; font-size: 0.78rem; font-weight: 700; font-variant-numeric: tabular-nums;
  color: #fff; background: var(--live); padding: 3px 8px; border-radius: 99px;
}
.sum-chev { width: 18px; height: 18px; color: var(--muted); transition: transform 0.2s; flex: none; }
.summary.collapsed .sum-chev { transform: rotate(180deg); }
.sum-stats { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 6px; margin: 2px 0 4px; }
.sum-stats b { display: block; font-size: 1.65rem; font-weight: 700; line-height: 1.05; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.sum-stats span { display: block; font-size: 0.75rem; color: var(--muted); margin-top: 1px; }
.sum-wheel {
  appearance: none; border: 0; background: none; font: inherit; color: var(--text); width: 100%; text-align: left;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 8px 0 0; padding: 0; font-size: 0.85rem; cursor: default;
}
button.sum-wheel { cursor: pointer; }
.sum-wheel > .ic { width: 16px; height: 16px; color: var(--muted); flex: none; }
.sum-wheel > .ic:last-child { margin-left: auto; }
.wheel { display: inline-flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums; color: var(--muted); }
.wheel .avatar { width: 20px; height: 20px; font-size: 0.62rem; }
.wheel.on { color: var(--text); font-weight: 600; }
.wheel.on .avatar { box-shadow: 0 0 0 2px var(--live); }
.sum-via { margin: 6px 0 0; font-size: 0.85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sum-next {
  appearance: none; border: 0; font: inherit; color: var(--text); cursor: pointer; text-align: left; width: 100%;
  display: flex; flex-direction: column; gap: 3px; margin-top: 10px; padding: 10px 12px; border-radius: 14px;
  background: color-mix(in srgb, var(--blue) 9%, transparent);
}
.sum-next-top { display: flex; justify-content: space-between; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--blue); }
.sum-next-top span:last-child { text-transform: none; letter-spacing: 0; font-weight: 600; font-size: 0.8rem; }
.sum-next-name { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 1.05rem; font-weight: 700; }
.sum-next-name .ic { width: 17px; height: 17px; color: var(--muted); flex: none; }
.sum-bar { position: relative; height: 5px; border-radius: 3px; background: color-mix(in srgb, var(--blue) 20%, transparent); margin: 4px 0 1px; overflow: hidden; }
.sum-bar span { position: absolute; inset: 0 auto 0 0; border-radius: 3px; background: var(--blue); }
.sum-next-bottom { display: flex; justify-content: space-between; font-size: 0.76rem; color: var(--muted); }
.sum-next-date { font-size: 0.76rem; color: var(--muted); }
.sum-next.done { flex-direction: row; align-items: center; gap: 8px; background: var(--surface-2); font-weight: 600; font-size: 0.9rem; }
.sum-next.done span { flex: 1; }
.sum-next.done .ic { width: 17px; height: 17px; color: var(--muted); }
.sum-next.done .ic:first-child { color: var(--blue); }
/* The map's OpenStreetMap credit lives here on phones, where the card covers Leaflet's corner. */
.sum-attrib { display: none; margin-top: 8px; font-size: 10px; color: var(--muted); text-align: right; }
.sum-attrib a { color: inherit; }
.map-detailed .credit-ofm { display: none; }
@media (max-width: 820px) { .sum-attrib { display: block; } }

/* ==========================================================================
   Trip plan (map pins, plan sheet, place search)
   ========================================================================== */
.leg-marker {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; color: #fff; font: 700 12px/1 -apple-system, system-ui, sans-serif;
  background: var(--blue); border: 2px solid #fff; box-shadow: 0 1px 4px rgb(0 0 0 / 0.35);
}
.leg-marker.done { background: var(--stale); }
.leg-marker .ic { width: 13px; height: 13px; }
.plan-list { list-style: none; margin: 0 0 14px; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.plan-list li { display: flex; align-items: center; gap: 12px; padding: 11px 12px 11px 14px; border-bottom: 0.5px solid var(--border); }
.plan-list li:last-child { border-bottom: 0; }
.plan-list li.done .leg-main b { color: var(--muted); }
.leg-num { width: 26px; height: 26px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 0.8rem; font-weight: 700; color: #fff; background: var(--blue); }
.plan-list li.done .leg-num { background: var(--stale); }
.leg-num .ic { width: 14px; height: 14px; }
.leg-main { flex: 1; min-width: 0; }
.leg-ctl { display: flex; gap: 0; }
.leg-ctl .del-comment:disabled { opacity: 0.25; cursor: default; }
.plan-results { list-style: none; margin: 8px 0; padding: 0; }
.plan-results:empty { display: none; }
.plan-results button {
  appearance: none; border: 0; background: var(--surface-2); color: var(--text); font: inherit; cursor: pointer; text-align: left;
  width: 100%; padding: 8px 10px; border-radius: 10px; margin-bottom: 6px; display: flex; flex-direction: column;
}
.plan-results button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn.plan-open { margin-bottom: 10px; background: var(--surface); }

/* ==========================================================================
   Feed
   ========================================================================== */
.day { font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 1.4rem 4px 0.55rem; }
.day b { color: var(--text); font-weight: 700; }
.day:first-child { margin-top: 0.2rem; }
.item { background: var(--surface); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; cursor: pointer; box-shadow: 0 0.5px 0 var(--border); }
.item img { display: block; width: 100%; height: auto; max-height: 34rem; object-fit: cover; background: var(--surface-2); }
.item .body { padding: 12px 14px 10px; }
.item .caption { margin: 0 0 8px; white-space: pre-wrap; font-size: 1rem; line-height: 1.4; }
.item .meta { display: flex; align-items: center; gap: 0.5rem; color: var(--muted); font-size: 0.82rem; min-height: 24px; }
.item .meta .when { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta .by { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--text); font-weight: 600; flex: none; }
.item .meta .by + .when { margin-left: -0.2rem; }
.item .meta .by + .when::before { content: "· "; }
.avatar {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; flex: none;
  font-size: 0.72rem; font-weight: 700; color: #fff; background: hsl(var(--h) 55% 46%);
}
img.avatar { object-fit: cover; background: var(--surface-2); }
/* Photo avatars are <img>s; keep the feed's full-width image rule off them. */
.item img.avatar { display: inline-block; width: 24px; height: 24px; max-height: none; }
.avatar-pick { position: relative; margin: 0; cursor: pointer; flex: none; }
.avatar-pick .avatar { width: 40px; height: 40px; font-size: 1rem; }
.avatar-cam {
  position: absolute; right: -3px; bottom: -3px; width: 18px; height: 18px; padding: 3px; border-radius: 50%;
  background: var(--accent); color: #fff; border: 2px solid var(--surface);
}
.leg-num.stop { background: var(--stale); }
/* Commenting is the main action on a post */
.item-actions { border-top: 0.5px solid var(--border); padding: 4px 6px; }
.action-comment {
  appearance: none; border: 0; background: none; cursor: pointer; font: inherit; font-weight: 600; font-size: 0.95rem;
  color: var(--accent); width: 100%; display: flex; align-items: center; justify-content: center; gap: 0.45rem;
  padding: 0.6rem; border-radius: 10px;
}
.action-comment:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.action-comment:disabled { color: var(--muted); cursor: default; background: none; }
.qso-row { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.qso-ico { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; flex: none; color: #fff; background: var(--blue); }
.qso-ico .ic { width: 20px; height: 20px; }
.qso-main { min-width: 0; }
.qso-title { font-weight: 500; }
.qso-title .call, .call { font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace; font-weight: 700; letter-spacing: 0.02em; }
.qso-radio { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }

/* posts */
.post-place {
  appearance: none; border: 0; background: none; cursor: pointer; font: inherit; padding: 0; margin: 0 0 4px;
  display: inline-flex; align-items: center; gap: 4px; color: var(--accent); font-size: 0.82rem; font-weight: 600;
}
.post-place .ic { width: 15px; height: 15px; }
.post-place.stop { background: color-mix(in srgb, var(--accent) 11%, transparent); padding: 3px 9px 3px 7px; border-radius: 999px; }
.post-title { font-size: 1.12rem; font-weight: 700; margin: 0 0 4px; line-height: 1.25; }
.item.post .caption { margin-bottom: 8px; }
.mosaic { display: grid; gap: 2px; grid-template-columns: 1fr 1fr; aspect-ratio: 4 / 3; background: var(--surface-2); }
.mosaic .tile { position: relative; overflow: hidden; min-height: 0; }
.mosaic img { width: 100%; height: 100% !important; max-height: none; object-fit: cover; }
.mosaic.n3 .tile:first-child { grid-row: span 2; }
.mosaic .more-n { position: absolute; inset: 0; display: grid; place-items: center; background: rgb(0 0 0 / 0.45); color: #fff; font-size: 1.6rem; font-weight: 700; pointer-events: none; }
.item.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 30% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 0 0 0 transparent; } }
.item .meta .del-comment { margin-left: auto; }
.post-marker { width: 30px; height: 30px; border-radius: 50% 50% 50% 4px; transform: rotate(-45deg); background: var(--accent); border: 2px solid #fff; box-shadow: 0 2px 6px rgb(0 0 0 / 0.35); display: grid; place-items: center; color: #fff; }
.post-marker .ic { width: 15px; height: 15px; transform: rotate(45deg); }

/* composer sheet */
.post-title-input { font-size: 1.15rem; font-weight: 600; margin: 0 0 8px; }
#post-body { margin: 0 0 10px; resize: vertical; }
.post-loc { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 0 0 12px; font-size: 0.88rem; }
.post-loc > .ic { width: 17px; height: 17px; color: var(--accent); }
#post-place { flex: 1; min-width: 50%; }
#post-delete { margin-top: 12px; }
.stop-toggle { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; color: var(--text); padding: 10px 12px; border-radius: 12px; background: var(--surface-2); cursor: pointer; }
.stop-toggle > .ic { width: 18px; height: 18px; color: var(--accent); flex: none; }
.stop-toggle > span { flex: 1; display: flex; flex-direction: column; gap: 1px; font-size: 0.92rem; }
.stop-toggle small { color: var(--muted); font-size: 0.78rem; }
.stop-toggle:has(input:disabled) { opacity: 0.55; cursor: default; }
/* iOS-style switch */
input[type="checkbox"][role="switch"] {
  appearance: none; flex: none; width: 46px; height: 28px; margin: 0; padding: 0; border: 0; border-radius: 14px; position: relative; cursor: pointer;
  background: color-mix(in srgb, var(--muted) 35%, transparent); transition: background 0.2s; transform: none;
}
input[type="checkbox"][role="switch"]::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 0.3); transition: transform 0.2s;
}
input[type="checkbox"][role="switch"]:checked { background: var(--live); }
input[type="checkbox"][role="switch"]:checked::after { transform: translateX(18px); }
input[type="checkbox"][role="switch"]:disabled { cursor: default; }
input[type="checkbox"][role="switch"]:focus:not(:focus-visible) { outline: none; }
.attach-row { display: flex; gap: 8px; margin: 0 0 12px; }
.attach {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-weight: 600; font-size: 0.93rem; flex: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem; padding: 0.7rem;
  border-radius: 12px; background: var(--surface); color: var(--text);
}
.attach .ic { width: 20px; height: 20px; color: var(--accent); }
.attach:disabled { opacity: 0.5; }
.post-contacts { list-style: none; margin: 0 0 12px; padding: 0; }
.post-contacts:empty { display: none; }
.post-contacts li {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin-bottom: 6px; border-radius: 12px;
  background: color-mix(in srgb, var(--blue) 9%, var(--surface));
}
.post-contacts li > .ic { width: 18px; height: 18px; color: var(--blue); flex: none; }
.post-contacts li > span { flex: 1; min-width: 0; }
.post-contacts small { display: block; color: var(--muted); font-size: 0.8rem; }
.post-contacts.in-feed { margin: 2px 0 10px; }

/* feed events: driver changes and towns passed through */
.event { margin: 0 0 12px; }
.event.shift {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--live) 9%, var(--surface));
}
.event.shift > span:not(.avatar) { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 0.93rem; }
.event.shift .avatar { width: 32px; height: 32px; font-size: 0.85rem; }
.event.shift small { color: var(--muted); font-size: 0.8rem; }
.event time { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.event.towns { list-style: none; padding: 4px 0 4px 14px; margin-left: 6px; border-left: 2px dashed color-mix(in srgb, var(--muted) 45%, transparent); }
.event.towns li { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 0.9rem; }
.event.towns time { width: 4.6em; flex: none; }
.event.towns .ic { width: 15px; height: 15px; color: var(--accent); flex: none; }

.event.shift.editable { cursor: pointer; }
.event.segment {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1.5px dashed color-mix(in srgb, var(--muted) 40%, transparent);
}
.event.segment > .ic { width: 22px; height: 22px; color: var(--muted); flex: none; margin: 0 5px; }
.event.segment > span { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 0.93rem; }
.event.segment small { color: var(--muted); font-size: 0.8rem; }
.title-btn.nudge span { color: var(--accent); }
.leg-date { display: inline-flex; align-items: center; gap: 6px; margin: 4px 0 0; color: var(--muted); }
.leg-date .ic { width: 15px; height: 15px; flex: none; }
.leg-date input { margin: 0; padding: 0.3rem 0.5rem; font-size: 0.85rem; width: auto; }

/* comments (feed and photo viewer) */
.comments { border-top: 0.5px solid var(--border); padding: 10px 14px 12px; cursor: default; }
.comments ul { list-style: none; margin: 0 0 8px; padding: 0; }
.comments li { position: relative; margin-bottom: 8px; font-size: 0.93rem; padding-right: 28px; }
.comments li p { margin: 0.1rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.comments .who { font-weight: 600; }
.comments .when { color: var(--muted); font-size: 0.8rem; margin-left: 0.35rem; }
.badge { font-size: 0.66rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); margin-left: 0.35rem; }
.del-comment {
  appearance: none; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 8px;
  display: inline-grid; place-items: center; opacity: 0.7;
}
.comments .del-comment { position: absolute; right: 0; top: 0; }
.del-comment .ic { width: 15px; height: 15px; }
.del-comment:hover { color: var(--danger); opacity: 1; background: var(--surface-2); }
.more { appearance: none; border: 0; background: none; color: var(--accent); font: inherit; font-size: 0.85rem; font-weight: 500; padding: 0; cursor: pointer; margin-bottom: 8px; }
.comment-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.comment-form input, .comment-form textarea { margin: 0; }
.comment-form input { flex-basis: 100%; }
.comment-form textarea { flex: 1; min-width: 0; resize: none; min-height: 40px; border-radius: 20px; padding: 0.55rem 0.9rem; }
.comment-form .send { width: 40px; height: 40px; padding: 0; border-radius: 50%; }
.comment-form .send .ic { width: 18px; height: 18px; }
.comment-form .as { flex-basis: 100%; font-size: 0.8rem; color: var(--muted); }

/* ==========================================================================
   Photos grid
   ========================================================================== */
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 3px; border-radius: 12px; overflow: hidden; }
.gallery-grid button { appearance: none; border: 0; padding: 0; background: var(--surface-2); aspect-ratio: 1; cursor: pointer; overflow: hidden; }
.gallery-grid img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.2s; }
.gallery-grid button:hover img { transform: scale(1.04); }

/* ==========================================================================
   Radio: repeaters and log (drivers only)
   ========================================================================== */
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem; margin: 0 4px 10px; }
.section-head p { margin: 0; }
.rpt-list, .log-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.rpt-list:empty, .log-list:empty { display: none; }
.rpt-list li {
  display: grid; grid-template-columns: auto 1fr auto; gap: 0.1rem 0.75rem;
  padding: 11px 14px; border-bottom: 0.5px solid var(--border); cursor: pointer;
}
.rpt-list li:last-child, .log-list li:last-child { border-bottom: 0; }
.rpt-freq { font: 600 1rem ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace; font-variant-numeric: tabular-nums; }
.rpt-sub { grid-column: 1 / -1; color: var(--muted); font-size: 0.82rem; }
.rpt-dist { color: var(--muted); font-size: 0.85rem; text-align: right; }
.chip { display: inline-block; font-size: 0.7rem; padding: 0.08rem 0.45rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); margin-right: 0.25rem; }
.rb-link { font-size: 0.78rem; margin-left: 0.25rem; }
.attrib { font-size: 0.75rem; color: var(--muted); margin: 10px 4px; }
.attrib a { color: inherit; }
#rpt-source { margin: -4px 4px 10px; }
#rpt-source:empty { display: none; }
.log-list li { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-bottom: 0.5px solid var(--border); }
.log-main { flex: 1; min-width: 0; }
.log-side { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; text-align: right; }

/* ==========================================================================
   Controls
   ========================================================================== */
.card { background: var(--surface); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.card p { margin: 0 0 0.6rem; }
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.6rem; }
input, select, textarea {
  display: block; width: 100%; margin-top: 0.25rem;
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface-2); border: 0; border-radius: 10px; padding: 0.6rem 0.75rem;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input[type="checkbox"] { display: inline-block; width: auto; margin: 0 0.5rem 0 0; vertical-align: -2px; accent-color: var(--live); transform: scale(1.15); }
input[type="radio"] { display: inline-block; width: auto; margin: 0 0.5rem 0 0; vertical-align: -2px; accent-color: var(--blue); transform: scale(1.15); }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 0; }
label.inline { display: flex; align-items: center; color: var(--text); font-size: 0.93rem; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.65rem; }
.grid .wide { grid-column: 1 / -1; }
.row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.row input { flex: 1; min-width: 0; margin: 0; }
.row.end { justify-content: flex-end; }
.row select { width: auto; margin: 0; }
#share-form input { flex-basis: 100%; }
#share-form select { flex: 1; }
#driver-form input { flex: 1 1 40%; }
.share-list + #driver-form { margin-top: 0.75rem; }
.me-line { margin: 0 4px 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  appearance: none; font: inherit; font-weight: 600; font-size: 0.93rem;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 11%, transparent); border: 0;
  border-radius: 10px; padding: 0.55rem 0.95rem; cursor: pointer; text-decoration: none; margin: 0;
}
.btn .ic { width: 17px; height: 17px; }
.btn:hover { background: color-mix(in srgb, var(--accent) 17%, transparent); }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn.danger { color: var(--danger); background: var(--surface); width: 100%; padding: 0.8rem; }
.btn.small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn.block { width: 100%; padding: 0.85rem; font-size: 1.02rem; border-radius: 14px; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* iOS segmented control */
.seg { display: inline-flex; padding: 2px; border-radius: 9px; background: var(--surface-2); margin-bottom: 0.6rem; }
.seg label, .seg button { margin: 0; color: var(--text); cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span, .seg button {
  display: block; padding: 0.38rem 1rem; font: inherit; font-size: 0.88rem; font-weight: 500;
  border: 0; background: none; border-radius: 7px; text-align: center;
}
.seg input:checked + span, .seg button[aria-selected="true"] { background: var(--surface); box-shadow: 0 1px 3px rgb(0 0 0 / 0.14); font-weight: 600; }
:root[data-theme="dark"] .seg input:checked + span, :root[data-theme="dark"] .seg button[aria-selected="true"] { background: #636366; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .seg input:checked + span,
  :root:not([data-theme="light"]) .seg button[aria-selected="true"] { background: #636366; }
}
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

.share-list { list-style: none; margin: 0.75rem 0 0; padding: 0; }
.share-list li { display: flex; align-items: center; gap: 0.5rem; padding: 0.6rem 0; border-top: 0.5px solid var(--border); }
.share-list .who { flex: 1; min-width: 0; }
.share-list .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-list .expired b { color: var(--muted); text-decoration: line-through; }

/* ==========================================================================
   Driver + button (floats over the map's corner)
   ========================================================================== */
.fab {
  position: fixed; z-index: 1300; right: calc(420px + 22px); bottom: 26px;
  appearance: none; border: 0; cursor: pointer; font: inherit; font-weight: 700; font-size: 0.98rem;
  display: inline-flex; align-items: center; gap: 0.45rem; height: 52px; padding: 0 1.25rem 0 1rem; border-radius: 99px;
  color: #fff; background: var(--accent); box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 40%, transparent), var(--float-shadow);
  transition: transform 0.15s;
}
body:not(.owner) .fab { display: none; }
body.map-full .fab { right: 22px; }
.fab .ic { width: 24px; height: 24px; stroke-width: 2.4; }
.fab:active { transform: scale(0.95); }
.fab .sub { position: absolute; top: -6px; right: -4px; background: var(--text); color: var(--bg); font-size: 0.68rem; font-weight: 600; padding: 1px 7px; border-radius: 99px; white-space: nowrap; }
.fab .sub:empty { display: none; }
.fab.busy .ic { animation: busy 1s ease-in-out infinite alternate; }
@keyframes busy { to { opacity: 0.35; } }

/* ==========================================================================
   Sheets (bottom sheets on phones, centred dialogs on wider screens)
   ========================================================================== */
dialog { border: 0; border-radius: 16px; background: var(--surface); color: var(--text); padding: 1.2rem; box-shadow: var(--float-shadow); width: min(360px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
dialog.sheet {
  padding: 0; background: var(--bg); color: var(--text);
  width: 100%; max-width: 100%; max-height: 92dvh; margin: auto 0 0; border-radius: 14px 14px 0 0;
}
dialog.sheet[open] { display: flex; flex-direction: column; animation: sheet-up 0.28s cubic-bezier(0.2, 0.9, 0.3, 1); }
@keyframes sheet-up { from { transform: translateY(40%); } }
/* No `flex: 1` here: Safari collapses 0%-basis flex items to zero height in an auto-height dialog.
   Content-sized items that may shrink keep the sheet as tall as it needs, up to its max-height. */
.sheet > form { display: flex; flex-direction: column; min-height: 0; flex: 0 1 auto; }
.sheet-head { position: relative; display: flex; align-items: center; justify-content: space-between; padding: 16px 10px 8px 18px; flex: none; }
.sheet-head::before { /* grabber */
  content: ""; position: absolute; top: 6px; left: 50%; width: 36px; height: 5px; margin-left: -18px; border-radius: 3px; background: var(--border);
}
.sheet-head h2 { margin: 0; font-size: 1.15rem; font-weight: 700; }
.sheet-head .icon-btn { width: 32px; height: 32px; background: var(--surface-2); color: var(--muted); }
.sheet-head .icon-btn .ic { width: 17px; height: 17px; }
.sheet-body { flex: 0 1 auto; min-height: 0; overflow-y: auto; padding: 8px 16px 16px; overscroll-behavior: contain; }
.sheet-foot { flex: none; padding: 10px 16px max(12px, env(safe-area-inset-bottom)); border-top: 0.5px solid var(--border); background: var(--bg); }
.sheet .card h3 { margin: 0 0 0.6rem; font-size: 0.95rem; }
@media (min-width: 821px) {
  dialog.sheet { width: min(560px, calc(100vw - 32px)); max-height: 85vh; margin: auto; border-radius: 16px; box-shadow: var(--float-shadow); }
  dialog.sheet[open] { animation: none; }
  .sheet-head::before { display: none; }
  .sheet-foot { padding-bottom: 12px; }
}

input.big { font-size: 1.4rem; font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; padding: 0.65rem 0.8rem; }
.chips-label { margin: 0.25rem 0 0.4rem; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin: 0 -16px 0.2rem; padding-inline: 16px; scrollbar-width: none; }
.chips:empty { display: none; }
.chip-btn {
  appearance: none; flex: none; cursor: pointer; font: inherit; color: var(--text); text-align: left;
  background: var(--surface); border: 1.5px solid transparent; border-radius: 12px; padding: 0.45rem 0.7rem; line-height: 1.25;
}
.chip-btn b { display: block; font: 600 0.98rem ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace; }
.chip-btn span { font-size: 0.75rem; color: var(--muted); }
.chip-btn[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, var(--surface)); }
#qso-attrib { margin: 0.25rem 0 0.75rem; }
details.more { border-top: 0.5px solid var(--border); padding-top: 0.5rem; }
details.more summary { cursor: pointer; color: var(--accent); font-weight: 500; font-size: 0.93rem; padding: 0.3rem 0 0.6rem; }

.photo-preview { list-style: none; margin: 0 0 0.75rem; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.photo-preview:empty { display: none; }
.photo-preview li { display: grid; grid-template-columns: 72px 1fr; gap: 0.75rem; padding: 10px 12px; border-bottom: 0.5px solid var(--border); }
.photo-preview li:last-child { border-bottom: 0; }
.photo-preview img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; background: var(--surface-2); }
.photo-preview input { margin: 0 0 0.3rem; }
.photo-preview .src { font-size: 0.78rem; color: var(--muted); }
.photo-preview .warn { color: var(--danger); }

/* ==========================================================================
   Photo viewer: always dark, edge to edge
   ========================================================================== */
#lightbox {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0;
  border: 0; border-radius: 0; background: #000; color: #fff; box-shadow: none; flex-direction: column;
}
#lightbox[open] { display: flex; }
#lightbox::backdrop { background: #000; }
.lb-stage { position: relative; flex: 1; min-height: 120px; margin-top: env(safe-area-inset-top); touch-action: pan-y pinch-zoom; }
.lb-stage:focus { outline: none; }
/* Absolutely placed so the photo is confined to the stage and never runs under the caption below. */
.lb-stage img { position: absolute; inset: 0; margin: auto; max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.lb-info { flex: none; padding: 12px 16px max(14px, env(safe-area-inset-bottom)); max-width: 820px; width: 100%; margin: 0 auto; max-height: 52dvh; overflow-y: auto; }
.lb-info p { margin: 0 0 0.3rem; white-space: pre-wrap; }
#lightbox-caption { font-size: 1.05rem; }
#lightbox-meta { color: #aeaeb2; font-size: 0.85rem; }
#lightbox-camera { color: #8e8e93; font-size: 0.8rem; margin-bottom: 0.6rem; }
#lightbox-count { margin-left: auto; color: #8e8e93; font-size: 0.85rem; }
.lb-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.lb-info .btn { background: rgb(255 255 255 / 0.12); color: #fff; }
.lb-info .btn:hover { background: rgb(255 255 255 / 0.2); }
.lb-info .btn.lb-comment { background: #fff; color: #000; padding: 0.6rem 1.1rem; border-radius: 99px; }
.lb-info .btn.icon { width: 40px; height: 40px; padding: 0; border-radius: 50%; }
.lb-info .btn.danger { color: #ff453a; width: 40px; }
#lb-comments .comments { border-top: 0.5px solid rgb(255 255 255 / 0.15); padding: 12px 0 0; margin-top: 12px; }
#lb-comments .comments .when, #lb-comments .comment-form .as { color: #8e8e93; }
#lb-comments input, #lb-comments textarea { background: rgb(255 255 255 / 0.12); color: #fff; }
#lb-comments .more { color: #fff; }
.lb-btn {
  position: absolute; z-index: 2; appearance: none; border: 0; cursor: pointer; display: grid; place-items: center;
  background: rgb(40 40 40 / 0.6); color: #fff; width: 40px; height: 40px; border-radius: 50%;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.lb-btn .ic { width: 22px; height: 22px; }
.lb-btn:hover { background: rgb(60 60 60 / 0.8); }
.lb-btn:focus:not(:focus-visible) { outline: none; }
.lb-close { top: max(0.75rem, env(safe-area-inset-top)); right: 0.85rem; }
.lb-prev, .lb-next { top: 40%; }
.lb-prev { left: 0.85rem; }
.lb-next { right: 0.85rem; }
.lb-btn:disabled { opacity: 0; pointer-events: none; }
@media (hover: none) { .lb-prev, .lb-next { display: none; } }
/* Immersive: just the photo */
.lb-info, .lb-btn { transition: opacity 0.2s; }
#lightbox.immersive .lb-info { display: none; }
#lightbox.immersive .lb-btn { opacity: 0; pointer-events: none; }
.lb-stage { cursor: zoom-in; }
#lightbox.immersive .lb-stage { cursor: zoom-out; }

#toast {
  position: fixed; left: 50%; bottom: 3.5rem; transform: translateX(-50%) translateY(20px);
  background: var(--glass); color: var(--text); padding: 0.65rem 1rem; border-radius: 99px; font-size: 0.9rem; font-weight: 500;
  backdrop-filter: blur(24px) saturate(180%); -webkit-backdrop-filter: blur(24px) saturate(180%); box-shadow: var(--float-shadow);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.25s; z-index: 3000; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ==========================================================================
   Phone: a full-screen app shell with a floating tab bar
   ========================================================================== */
@media (max-width: 820px) {
  html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
  body { display: block; font-size: 16px; }
  .desktop-only, .trip-ctl a.desktop-only { display: none !important; }

  /* Frosted nav bar */
  .top {
    position: fixed; top: 0; left: 0; right: 0; height: var(--nav-h); flex-wrap: nowrap; gap: 10px;
    padding: env(safe-area-inset-top) 12px 0 16px;
    background: color-mix(in srgb, var(--bg) 80%, transparent); border-bottom: 0.5px solid color-mix(in srgb, var(--border) 70%, transparent);
    backdrop-filter: blur(20px) saturate(180%); -webkit-backdrop-filter: blur(20px) saturate(180%);
  }
  body[data-screen="map"] .top { background: var(--glass); }
  .brand h1 { font-size: 1.06rem; font-weight: 700; gap: 7px; }
  .brand h1 .avatar { width: 24px; height: 24px; font-size: 0.75rem; }
  .status { font-size: 0.8rem; margin-top: 1px; }
  .stats { display: none; }

  /* One screen at a time; the map stays laid out underneath so Leaflet keeps its size */
  .layout { position: fixed; inset: 0; display: block; }
  .map-wrap { position: absolute; inset: 0; }
  body:not([data-screen="map"]) .map-wrap { visibility: hidden; pointer-events: none; }
  body[data-screen="map"] .panel { display: none; }
  .panel { position: absolute; inset: 0; border: 0; }
  .panel .tabs { display: none; }
  .tab-body {
    position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding: calc(var(--nav-h) + 12px) 14px calc(var(--tab-h) + var(--bottom-gap) + 26px);
  }
  .radio-seg { display: flex; width: 100%; margin-bottom: 14px; }
  .radio-seg button { flex: 1; }

  /* Map chrome sits clear of the floating bars */
  .map-wrap .leaflet-top { top: calc(var(--nav-h) + 4px); }
  .map-wrap .leaflet-bottom { bottom: calc(var(--tab-h) + var(--bottom-gap) + 8px); }
  .summary { left: 12px; right: 12px; width: auto; bottom: calc(var(--tab-h) + var(--bottom-gap) + 14px); }
  body[data-screen="map"] .map-wrap .leaflet-bottom.leaflet-right { bottom: calc(var(--tab-h) + var(--bottom-gap) + 4px); }
  /* The expanded card carries the map credit; collapsed, Leaflet's own credit shows again. */
  body:has(.summary:not([hidden]):not(.collapsed)) .map-wrap .leaflet-bottom.leaflet-right { display: none; }
  .summary.collapsed { right: auto; max-width: calc(100% - 24px); }
  .summary { padding: 2px 14px 10px; }
  .sum-stats b { font-size: 1.4rem; }
  .sum-next { margin-top: 8px; padding: 8px 12px; }

  /* Floating glass tab bar */
  .tabbar {
    display: flex; position: fixed; z-index: 1300; bottom: var(--bottom-gap); left: 50%; transform: translateX(-50%);
    height: var(--tab-h); padding: 5px; gap: 2px; border-radius: 999px;
    background: var(--glass); backdrop-filter: blur(24px) saturate(180%); -webkit-backdrop-filter: blur(24px) saturate(180%);
    box-shadow: var(--float-shadow); border: 0.5px solid color-mix(in srgb, var(--border) 60%, transparent);
  }
  body.owner .tabbar { left: 12px; transform: none; }
  .tabbar button {
    appearance: none; border: 0; background: none; cursor: pointer; font: inherit; color: var(--text);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    min-width: 62px; padding: 0 8px; border-radius: 999px; font-size: 0.66rem; font-weight: 600;
  }
  .tabbar button .ic { width: 23px; height: 23px; }
  .tabbar button[aria-current="page"] { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

  /* Driver +: a round button beside the tab bar */
  .fab { right: 12px; bottom: var(--bottom-gap); width: var(--tab-h); height: var(--tab-h); padding: 0; justify-content: center; }
  .fab .lbl { display: none; }
  .fab .ic { width: 28px; height: 28px; }
  body.owner .tabbar button { min-width: 58px; }

  #toast { top: calc(var(--nav-h) + 10px); bottom: auto; transform: translateX(-50%) translateY(-12px); }
  #toast.show { transform: translateX(-50%) translateY(0); }

  .item { border-radius: 16px; }
  /* Edge to edge, like Photos */
  .gallery-grid { grid-template-columns: repeat(3, 1fr); gap: 2px; border-radius: 0; margin: 0 -14px; }
  #gallery .day { margin-inline: 4px; }
}
@media (max-width: 380px) {
  .tabbar button { min-width: 54px; padding: 0 5px; }
  .loc-toggle span { display: none; }
  .loc-toggle { padding: 0 0.6rem; }
}
