/* trip — live tracking screen, dual perspective (v2). Full-bleed map, glass
   back button, spring bottom sheet with timeline / person / chat / rating
   states; driver stage bar + location-sharing chip. Tokens only — no
   hardcoded colours (member colours arrive as inline user data). */

.trip { background: var(--bg); }

/* Text-grade status colours. --accent-strong / --good / --bad are fill-grade:
   fine as marks and chips, but under 4.5:1 as small text on the light palette.
   Mixing them toward --text grades them for text; the dark palette's originals
   already pass (11.8:1 amber), so dark keeps them. Token-derived only. */
.trip {
  --trip-accent-text: color-mix(in srgb, var(--accent-strong) 62%, var(--text));
  --trip-accent-hero: color-mix(in srgb, var(--accent-strong) 80%, var(--text));
  --trip-good-text: color-mix(in srgb, var(--good) 68%, var(--text));
  --trip-bad-text: color-mix(in srgb, var(--bad) 78%, var(--text));
}
@media (prefers-color-scheme: dark) {
  .trip {
    --trip-accent-text: var(--accent-strong);
    --trip-accent-hero: var(--accent-strong);
    --trip-good-text: var(--good);
    --trip-bad-text: var(--bad);
  }
}
.trip-map { position: absolute; inset: 0; z-index: 0; }
/* Elevated ground colour so not-yet-loaded tile area reads as intentional
   basemap ground, not a black seam, while tiles stream in. Two classes to
   outrank map3d's runtime-injected .gm-map { background: var(--bg) }. */
.trip .trip-map.gm-map { background: var(--bg-elev-1); }
/* Waiting state: no driver, no car — the map sits back while we ask around. */
.trip .trip-map.subdued { filter: saturate(0.4); opacity: 0.85; }

/* Attribution: bottom-right sits behind the sheet on a full-bleed map, so park
   it top-right beside the back button — same treatment as the book screen. */
.trip-map .leaflet-bottom.leaflet-right {
  bottom: auto;
  top: calc(var(--safe-top) + var(--s-3) + 44px + var(--s-1));
  right: var(--s-2);
}

/* ---- floating back button ---- */
.trip-back {
  position: absolute; z-index: 700;
  top: calc(var(--safe-top) + var(--s-3)); left: var(--s-4);
  width: 44px; height: 44px; border-radius: var(--r-full);
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg-elev-1) 86%, transparent);
  backdrop-filter: blur(16px) saturate(1.3); -webkit-backdrop-filter: blur(16px) saturate(1.3);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-2);
  color: var(--text);
  transition: transform var(--t-fast) var(--ease);
}
.trip-back:active { transform: scale(0.92); }
.trip-back svg { width: 22px; height: 22px; }

/* Toast offset now lives in base.css (below the header band, all screens). */

/* ---- sheet ---- */
.trip-sheet { z-index: 600; }
.trip-sheet-body { display: flex; flex-direction: column; }
.trip-skel { padding: var(--s-2) 0 var(--s-3); }

.trip-head { display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-1) 0 var(--s-3); }
.trip-title { font-size: var(--fs-xl); font-weight: var(--fw-bold); letter-spacing: -0.02em; }
/* .trip-brand colour arrives inline (member colour mixed toward --text). */
.trip-sub { font-size: var(--fs-sm); color: var(--text-2); margin-top: 2px; }
.trip-head .pill { margin-top: 4px; flex-shrink: 0; }
/* One colour for the live pill across accepted/arriving/in_progress — the
   base per-status pills recolour mid-trip with no meaning change. Green,
   matching the pulse-dot. */
.trip-head .pill-live { background: var(--good-dim); color: var(--trip-good-text); }
/* Waiting pill: base.css's --accent-strong is fill-grade — text-grade it here. */
.trip-head .pill-requested { color: var(--trip-accent-text); }

/* ---- stepped timeline ---- */
.trip-steps { display: flex; padding: 0 0 var(--s-4); }
.trip-step { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.trip-step-track {
  position: relative; width: 100%;
  display: flex; align-items: center; justify-content: center; height: 20px;
}
.trip-step-track::before, .trip-step-track::after {
  content: ''; position: absolute; top: 50%; height: 2px; border-radius: 1px;
  background: var(--line-strong); width: calc(50% - 12px);
  transition: background var(--t-med) var(--ease);
}
.trip-step-track::before { left: 0; transform: translateY(-50%); }
.trip-step-track::after { right: 0; transform: translateY(-50%); }
.trip-step:first-child .trip-step-track::before,
.trip-step:last-child .trip-step-track::after { display: none; }

.trip-step-dot {
  width: 18px; height: 18px; border-radius: 50%; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-elev-2); border: 2px solid var(--line-strong);
  color: var(--on-accent);
  transition: background var(--t-med) var(--ease), border-color var(--t-med) var(--ease),
    box-shadow var(--t-med) var(--ease);
}
.trip-step-dot svg { width: 11px; height: 11px; stroke-width: 3; }
.trip-step-label {
  font-size: 10px; font-weight: var(--fw-semi); letter-spacing: 0.02em;
  color: var(--text-2); white-space: nowrap; max-width: 100%; overflow: hidden;
  transition: color var(--t-med) var(--ease);
}

.trip-step.done .trip-step-dot { background: var(--accent); border-color: var(--accent); }
.trip-step.done .trip-step-track::before,
.trip-step.done .trip-step-track::after,
.trip-step.live .trip-step-track::before { background: var(--accent); }
.trip-step.done .trip-step-label { color: var(--text-2); }
.trip-step.live .trip-step-label { color: var(--trip-accent-text); }
.trip-step.live .trip-step-dot {
  background: var(--accent-dim); border-color: var(--accent); color: var(--accent);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 10%, transparent);
}
.trip-step.live .trip-step-dot .pulse-dot { background: var(--accent); }

/* Cancel controls: text-graded red (raw --bad composited on --bad-dim is
   3.9-4.4:1 on light; dark resets --trip-bad-text to raw --bad above). */
.trip-cancel, .trip-cancel-confirm { color: var(--trip-bad-text); }
.trip-cancel-confirm .btn-danger,
.trip-cancel.btn-danger { color: var(--trip-bad-text); }

/* ---- person card (driver ↔ rider) ---- */
.trip-driver { padding: var(--s-3) var(--s-4); cursor: pointer; transition: background var(--t-fast) var(--ease); }
.trip-driver:active { background: var(--bg-elev-2); }
/* Member colour arrives inline as the avatar background; this is the
   no-colour fallback. */
.trip-driver-avatar { background: var(--bg-elev-2); border: 1px solid var(--line-strong); }
/* neutral SVG fallback when the avatar emoji is missing */
.trip-avatar-mark { display: flex; align-items: center; justify-content: center; color: var(--text-2); }
.trip-avatar-mark svg { width: 20px; height: 20px; }
.avatar-sm .trip-avatar-mark svg { width: 16px; height: 16px; }
.trip-driver-name { font-size: var(--fs-lg); font-weight: var(--fw-semi); }
.trip-driver-sub { font-size: var(--fs-sm); color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trip-plate {
  font-size: var(--fs-xs); font-weight: var(--fw-bold); letter-spacing: 0.08em;
  background: var(--bg-elev-3); border: 1px solid var(--line-strong);
  border-radius: 6px; padding: 4px 8px; color: var(--text-2);
}
.trip-chat-btn {
  background: var(--accent); color: var(--on-accent);
  width: 40px; min-width: 40px; height: 40px; min-height: 40px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.trip-chat-btn svg { width: 20px; height: 20px; }

.trip-msg-preview {
  display: flex; align-items: baseline; gap: var(--s-2);
  margin-top: var(--s-3); padding-top: var(--s-3);
  border-top: 1px solid var(--line);
  font-size: var(--fs-sm); min-width: 0;
}
.trip-msg-who { font-weight: var(--fw-semi); color: var(--text-2); flex-shrink: 0; }
.trip-msg-body { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.trip-msg-empty .trip-msg-body { color: var(--text-3); }
.trip-msg-time { color: var(--text-3); font-size: var(--fs-xs); flex-shrink: 0; }

/* ---- asking card (rider, requested) ---- */
.trip-ask { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-4); }
.trip-ask-avatars { display: flex; flex-shrink: 0; }
.trip-ask-avatar { border: 2px solid var(--bg-elev-1); background: var(--bg-elev-2); }
.trip-ask-avatar + .trip-ask-avatar { margin-left: -12px; }
/* the "we've texted…" line is a sentence, not a datum — let it wrap */
.trip-ask .trip-driver-sub { white-space: normal; }

/* ---- stat strip ---- */
.trip-stats {
  display: flex; margin-top: var(--s-3);
  background: var(--bg-elev-1); border: 1px solid var(--line); border-radius: var(--r-md);
}
.trip-stat {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: var(--s-3) var(--s-2);
}
.trip-stat + .trip-stat { border-left: 1px solid var(--line); }
.trip-stat-v { font-size: var(--fs-lg); font-weight: var(--fw-bold); letter-spacing: -0.01em; }
.trip-stat-v small { font-size: var(--fs-xs); font-weight: var(--fw-med); color: var(--text-2); margin-left: 1px; }
.trip-stat-k { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-2); font-weight: var(--fw-semi); white-space: nowrap; }

/* ---- route block ---- */
.trip-route { display: flex; gap: var(--s-3); margin-top: var(--s-3); padding: var(--s-1) var(--s-1) 0; }
.trip-route-glyph {
  display: flex; flex-direction: column; align-items: center;
  padding-top: 7px; width: 12px; flex-shrink: 0;
}
.trip-route-dot { width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--accent); flex-shrink: 0; }
.trip-route-line { width: 2px; flex: 1; margin: 3px 0; border-radius: 1px;
  background: repeating-linear-gradient(to bottom, var(--line-strong) 0 3px, transparent 3px 7px); }
.trip-route-sq { width: 8px; height: 8px; border-radius: 2px; background: var(--text); flex-shrink: 0; }
.trip-route-labels { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--s-4); }
.trip-route-row { display: flex; align-items: baseline; gap: var(--s-2); min-width: 0; }
.trip-route-name { font-size: var(--fs-md); font-weight: var(--fw-med); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trip-route-tag { font-size: var(--fs-xs); color: var(--text-2); flex-shrink: 0; margin-left: auto; }

/* ---- note / reason ---- */
/* Labelled info row (caps micro-label like the stat keys) — deliberately not
   a full-width rounded field, which read as a disabled message input. */
.trip-note {
  display: flex; align-items: baseline; gap: var(--s-3);
  margin-top: var(--s-3); padding: var(--s-2) var(--s-1) 0;
  border-top: 1px solid var(--line);
}
.trip-note-k {
  font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-2); font-weight: var(--fw-semi); flex-shrink: 0;
}
.trip-note-body {
  font-size: var(--fs-sm); color: var(--text-2); font-style: italic;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}

/* ---- driver stage bar + location chip ---- */
.trip-stagebar { display: flex; gap: var(--s-2); margin-top: var(--s-4); }
.trip-stagebar .trip-stage-btn { flex: 1; }
.trip-overflow {
  width: 50px; min-width: 50px; height: 50px; min-height: 50px; flex-shrink: 0;
  background: var(--bg-elev-2); border: 1px solid var(--line-strong); color: var(--text-2);
  border-radius: var(--r-md);
}

.trip-geo {
  align-self: center;
  display: inline-flex; align-items: center; gap: var(--s-2);
  margin-top: var(--s-3); padding: 5px 12px;
  border-radius: var(--r-full);
  background: var(--good-dim); color: var(--trip-good-text);
  font-size: var(--fs-xs); font-weight: var(--fw-semi);
  animation: screen-in var(--t-med) var(--ease-out);
}
.trip-geo .pulse-dot { background: var(--good); }
/* An error the driver must notice: warning colours, no pulse-dot (not live). */
.trip-geo.err { background: var(--bad-dim); color: var(--trip-bad-text); }
.trip-geo[hidden] { display: none; }

.trip-hint { margin-top: var(--s-4); font-size: var(--fs-sm); color: var(--text-2); text-align: center; }

/* ---- cancel ---- */
.trip-cancel { margin-top: var(--s-4); }
.trip-cancel-confirm {
  display: flex; align-items: center; gap: var(--s-2);
  margin-top: var(--s-4); padding: var(--s-2) var(--s-2) var(--s-2) var(--s-4);
  background: var(--bad-dim); border: 1px solid color-mix(in srgb, var(--bad) 25%, transparent);
  border-radius: var(--r-md);
  font-size: var(--fs-sm); font-weight: var(--fw-semi); color: var(--bad);
  animation: screen-in var(--t-fast) var(--ease-out);
}
.trip-cancel-confirm span { flex: 1; }
.trip-cancel-confirm .btn-danger { background: var(--bad); color: var(--text-invert); }

/* ---- chat mode ---- */
/* The sheet sizes to the thread (map stays visible above); max-height caps a
   long thread, and the list scrolls only once it overflows. */
.trip-sheet.chat .trip-sheet-body { max-height: min(62vh, 520px); }
.trip-chat-head {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 0 0 var(--s-3); border-bottom: 1px solid var(--line);
}
.trip-chat-back { color: var(--text-2); }
.trip-chat-list {
  flex: 0 1 auto; min-height: 88px;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: var(--s-2);
  padding: var(--s-4) var(--s-1);
}
.trip-chat-list > .empty:first-child { margin: 0; padding: var(--s-6); }
.trip-bubble-row { display: flex; align-items: flex-end; gap: var(--s-2); max-width: 86%; animation: bubble-in var(--t-med) var(--ease-out); }
.trip-bubble-row.mine { align-self: flex-end; flex-direction: row-reverse; }
@keyframes bubble-in { from { opacity: 0; transform: translateY(8px) scale(0.97); } to { opacity: 1; transform: none; } }
.trip-bubble {
  background: var(--bg-elev-2); border: 1px solid var(--line);
  border-radius: var(--r-md); border-bottom-left-radius: 6px;
  padding: var(--s-2) var(--s-3);
  font-size: var(--fs-md); line-height: 1.4;
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.trip-bubble-row.mine .trip-bubble {
  background: var(--accent); border-color: transparent; color: var(--on-accent);
  border-radius: var(--r-md); border-bottom-right-radius: 6px;
}
.trip-bubble-time { font-size: 10px; color: var(--text-3); align-self: flex-end; }
.trip-bubble-row.mine .trip-bubble-time { color: color-mix(in srgb, var(--on-accent) 78%, transparent); }
.trip-chat-input { display: flex; align-items: center; gap: var(--s-2); padding-top: var(--s-3); border-top: 1px solid var(--line); }
.trip-chat-input .field { flex: 1; min-height: 46px; }
.trip-send {
  background: var(--accent); color: var(--on-accent);
  width: 46px; min-width: 46px; height: 46px; min-height: 46px; flex-shrink: 0;
  transition: transform var(--t-fast) var(--ease-spring);
}
.trip-send:active { transform: scale(0.9); }
.trip-send svg { width: 21px; height: 21px; }

/* ---- completed / earned ---- */
.trip-earned {
  position: relative; overflow: hidden; text-align: center;
  padding: var(--s-5) var(--s-4) var(--s-4);
  background: var(--bg-elev-1); border: 1px solid var(--line); border-radius: var(--r-md);
  animation: earned-in var(--t-slow) var(--ease-spring);
}
@keyframes earned-in { from { opacity: 0; transform: translateY(14px) scale(0.97); } to { opacity: 1; transform: none; } }
.trip-earned-glow {
  position: absolute; inset: -40% -20% auto; height: 130%;
  background: radial-gradient(ellipse at 50% 0%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 65%);
  pointer-events: none;
}
.trip-earned-icon { color: var(--accent); margin-bottom: var(--s-1); }
.trip-earned-icon svg { width: 26px; height: 26px; }
.trip-earned-num {
  font-size: var(--fs-hero); font-weight: var(--fw-bold); letter-spacing: -0.03em;
  color: var(--trip-accent-hero); line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.trip-earned-label { font-size: var(--fs-sm); color: var(--text-2); font-weight: var(--fw-med); }
.trip-earned-bal { margin-top: var(--s-2); font-size: var(--fs-xs); color: var(--text-3); }
.trip-earned-bal strong { color: var(--text-2); }
/* Rider side of the same ledger event: miles paid, told honestly — no glow,
   neutral ink. */
.trip-earned.spent .trip-earned-num { color: var(--text); }
.trip-earned.spent .trip-earned-icon { color: var(--text-3); }

/* ---- rating ---- */
.trip-rate { padding-top: var(--s-2); }
.trip-rate-label { padding-left: 0; padding-right: 0; text-align: center; }
.trip-stars { display: flex; justify-content: center; gap: var(--s-2); padding: var(--s-1) 0 var(--s-3); }
.trip-star {
  width: 48px; height: 48px; border-radius: var(--r-full);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3);
  transition: color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.trip-star svg { width: 34px; height: 34px; }
.trip-star:active { transform: scale(0.88); }
.trip-star.on { color: var(--accent); }
.trip-star.pop { animation: star-pop 320ms var(--ease-spring); }
@keyframes star-pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }
.trip-comment { margin-bottom: var(--s-3); }

.trip-rated {
  display: flex; align-items: center; gap: var(--s-3);
  margin-top: var(--s-3); padding: var(--s-3) var(--s-4);
  background: var(--bg-elev-1); border: 1px solid var(--line); border-radius: var(--r-md);
  animation: screen-in var(--t-med) var(--ease-out);
}
.trip-rated-check {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background: var(--good-dim); color: var(--good);
  display: flex; align-items: center; justify-content: center;
}
.trip-rated-check svg { width: 18px; height: 18px; }
.trip-rated-title { font-size: var(--fs-md); font-weight: var(--fw-semi); }
.trip-rated-stars { display: flex; align-items: center; gap: var(--s-2); margin-top: 2px; min-width: 0; }
.trip-star-row { display: inline-flex; gap: 1px; }
.trip-star-row svg { width: 14px; height: 14px; }
.trip-star-row span { color: var(--bg-elev-3); }
.trip-star-row span.on { color: var(--accent); }
.trip-rated-comment {
  font-size: var(--fs-xs); color: var(--text-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.trip-done-btn { margin-top: var(--s-4); }

/* narrow phones: keep the plate (which-car-is-mine datum) but wrap it onto its
   own line under the name, chat button staying top-right */
@media (max-width: 344px) {
  .trip-driver .row { flex-wrap: wrap; }
  /* Guarantee the name block real width so line 1 overflows and the plate
     actually wraps — without this the plate's max-content basis fits inline
     and the name column gets crushed to a sliver instead. 96px holds
     "Graeme" at 17px semibold. */
  .trip-driver .grow { min-width: 96px; }
  .trip-chat-btn { order: 3; }
  .trip-plate {
    order: 4; flex-basis: 100%; max-width: max-content;
    font-size: 10px; padding: 2px 6px;
    margin-left: 56px; /* align under the name (avatar 44 + gap 12) */
    margin-top: -6px;
  }
  .trip-step-label { font-size: 9px; }
  .trip-stat-k { font-size: 9px; letter-spacing: 0.03em; } /* stat keys must fit a third-width tile */
}
