.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.detail-header__info {
  min-width: 220px;
}

.detail-header__info .page-eyebrow {
  margin-bottom: 0.4rem;
}

.detail-header__title {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 0.3rem;
  background: linear-gradient(135deg, var(--text) 0%, var(--text) 55%, var(--accent) 130%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.detail-header__meta {
  color: var(--text-muted);
  margin: 0;
  font-size: 0.9rem;
}

.detail-header__flags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.detail-header__stats {
  display: flex;
  align-items: stretch;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.detail-stat-box {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.35rem;
  min-width: 118px;
  padding: 0.65rem 1rem;
  border: 1px solid color-mix(in srgb, var(--text) 8%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
}

.detail-stat-box__label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

.detail-stat-box__value {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

@media (max-width: 720px) {
  .detail-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .detail-header__stats {
    width: 100%;
  }

  .detail-stat-box {
    flex: 1 1 calc(50% - 0.85rem);
  }
}

.card-heading {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0 0 1rem;
}

.card-empty {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin: 0;
}

.map-card {
  padding: 0;
  overflow: hidden;
}

.map-card__frame {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 0;
}

.map-card--sticky {
  height: 100%;
}

.map-card--sticky .map-card__frame {
  aspect-ratio: unset;
  height: 100%;
}

.map-card--wide {
  padding: 0;
  overflow: hidden;
  margin-bottom: 1.25rem;
}

.map-card--wide .map-card__frame {
  aspect-ratio: unset;
  height: 480px;
}

@media (max-width: 720px) {
  .map-card--wide .map-card__frame {
    height: 320px;
  }
}

.detail-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1.25rem;
  align-items: start;
  margin-bottom: 2rem;
}

.detail-side {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

@media (max-width: 960px) {
  .detail-grid {
    grid-template-columns: 1fr;
  }
}

/* Sticky map layout (order detail) */

.detail-layout {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 1.25rem;
  align-items: start;
}

.detail-layout__content {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-width: 0;
}

/* The column stacks .card--section cards, which carry their own 2rem bottom
   margin for use in a normal flow. Inside this flex column the gap already
   does that job, so the margin only compounds it — the panels sat ~3.25rem
   apart and the map beside them ran far past the last one. */
.detail-layout__content > .card--section {
  margin-bottom: 0;
}

/* Tighter internals to match: on a page of four stacked panels the card's
   1.35rem padding and the heading's 1rem gap are what push the column past
   the map's height. */
.detail-layout__content > .card {
  padding: 1.05rem 1.15rem;
}

.detail-layout__content > .card > .card-heading {
  margin-bottom: 0.7rem;
}

/* Vertical timelines in this column carry the stop and dispatch lists, which
   is where most of its height comes from. A route's stops are short, uniform
   entries — 1.25rem between them is spacing meant for prose-length events. */
.detail-layout__content .timeline__item {
  padding-bottom: 0.8rem;
}

.detail-layout__content .kv-list__row {
  padding: 0.42rem 0;
}

/* The scroll container is .main (height: 100vh - topbar; overflow-y: auto), NOT
   the viewport — so sticky resolves against .main's own padding box. The old
   offsets subtracted the topbar a second time and set a fixed 100vh-based
   height, which left the card shorter than its grid track: with
   `align-items: start` the track keeps its own height, so once the card stuck
   it detached from the track's top and a gap opened above it as the page
   scrolled. Sticking to .main's top with a height measured in that same frame
   keeps the card and its track the same size, so there is nothing to gap. */
.detail-layout__map {
  position: sticky;
  top: 0;
  /* .main's visible height less its 1rem top/bottom padding. */
  height: calc(100vh - var(--topbar-height) - 2rem);
  min-height: 420px;
}

@media (max-width: 960px) {
  .detail-layout {
    grid-template-columns: 1fr;
  }

  .detail-layout__map {
    position: static;
    height: 420px;
  }
}

/* Detail panels */

.detail-columns {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.1rem;
  margin-bottom: 1.25rem;
}

.detail-panel__heading {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
}

.detail-panel__heading svg {
  color: var(--accent);
  flex-shrink: 0;
}

@media (max-width: 960px) {
  .detail-columns {
    grid-template-columns: 1fr;
  }
}

/* Signal coverage */

.signal-card {
  margin-bottom: 1.25rem;
}

.signal-card--flagged {
  border-color: color-mix(in srgb, var(--bad) 45%, var(--border));
}

.signal-card__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}

.signal-card__head .card-heading {
  margin: 0;
}

.signal-card__verdict {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted);
}

.signal-card__verdict--bad {
  color: var(--bad);
}

.signal-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.7rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.signal {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
}

.signal__mark {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  color: var(--good);
  background: var(--good-soft);
}

.signal--flagged .signal__mark {
  color: var(--bad);
  background: var(--bad-soft);
}

.signal--muted .signal__mark {
  color: var(--text-muted);
  background: color-mix(in srgb, var(--text-muted) 14%, transparent);
}

.signal__body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.signal__label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}

.signal--muted .signal__label {
  color: var(--text-muted);
}

.signal__note {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.signal--flagged .signal__note {
  color: var(--bad);
}

.signal-card__verdict--review {
  color: var(--warn);
}

.signal--review .signal__mark {
  color: var(--warn);
  background: var(--warn-soft);
}

.signal--review .signal__note {
  color: var(--warn);
}

/* ── Route progress ──────────────────────────────────────────────────────────
   Sits under the header meta on an order: one bar showing settled vs pending
   stops. Segments are inline-sized from the template (share of total stops), so
   the bar needs no width rules of its own — only the colour and the geometry. */
.route-progress {
  margin-top: 0.85rem;
  max-width: 30rem;
}

.route-progress__bar {
  display: flex;
  height: 7px;
  border-radius: 99px;
  overflow: hidden;
  /* The track IS the "pending" segment — unfilled space reads as outstanding
     work, so pending needs no element of its own. */
  background: color-mix(in srgb, var(--text-muted) 18%, transparent);
}

.route-progress__seg {
  display: block;
  height: 100%;
  transition: width 0.4s ease;
}

.route-progress__seg--good { background: var(--good); }
.route-progress__seg--bad { background: var(--bad); }

.route-progress__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.route-progress__key {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.route-progress__key::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--text-muted) 45%, transparent);
}

.route-progress__key--good::before { background: var(--good); }
.route-progress__key--bad::before { background: var(--bad); }
.route-progress__key--good { color: var(--good); }
.route-progress__key--bad { color: var(--bad); }

/* A stat box whose number is itself the bad news (failed stops, missing
   signals) — tinting the box beats making the reader compare figures. */
.detail-stat-box--bad {
  border-color: color-mix(in srgb, var(--bad) 35%, var(--border));
  background: var(--bad-soft);
}

.detail-stat-box--bad .detail-stat-box__value { color: var(--bad); }

/* Trailing unit on a stat value ("%"), sized down so the figure stays dominant. */
.detail-stat-box__unit {
  font-size: 0.6em;
  font-weight: 600;
  margin-left: 0.1em;
  color: var(--text-muted);
}

/* Count badge beside a card heading, for panels whose length is meaningful. */
.card-heading__count {
  margin-left: auto;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  background: color-mix(in srgb, var(--text-muted) 12%, transparent);
  border-radius: 99px;
  padding: 0.1rem 0.5rem;
}

.stop__seq {
  font-weight: 650;
  color: var(--text);
}

.stop__status--pending { color: var(--text-muted); }

/* ── Courier tracking ────────────────────────────────────────────────────────
   One block per Fleetable dispatch attempt. The left edge carries the outcome
   colour so a rejected attempt is findable when a request has several. */
.courier-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.courier-attempt {
  border: 1px solid var(--border);
  border-left: 3px solid color-mix(in srgb, var(--text-muted) 40%, transparent);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  background: var(--surface-raised);
}

.courier-attempt--good { border-left-color: var(--good); }
.courier-attempt--bad { border-left-color: var(--bad); }

.courier-attempt__head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.courier-attempt__provider {
  font-weight: 650;
  font-size: 0.875rem;
}

.courier-attempt__when {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.courier-attempt__meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.courier-attempt__actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.9rem;
  margin-top: 0.6rem;
}

.courier-attempt__ref {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  font-size: 0.75rem;
}

.courier-attempt__ref-label {
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.65rem;
  font-weight: 600;
}

/* The tracking link is the panel's one action, so it gets accent fill while
   every other control here stays text. A settled attempt's link drops to a
   plain outline — still reachable, no longer inviting. */
.track-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.65rem;
  border-radius: 7px;
  font-size: 0.75rem;
  font-weight: 600;
  text-decoration: none;
  background: var(--accent);
  color: var(--accent-contrast);
  border: 1px solid transparent;
  transition: filter 0.15s ease, background 0.15s ease;
}

.track-btn:hover { filter: brightness(1.08); }

.track-btn--stale {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

.track-btn--stale:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

/* Inline "Track" inside a timeline entry — same affordance, no button weight. */
.track-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-weight: 600;
}

/* ── Route tracker (Fleetable batch) ─────────────────────────────────────────
   The batch's drops as one horizontal run, reusing .timeline--horizontal for
   geometry and adding only the per-outcome colour and the "current" emphasis. */
.route-progress--wide {
  max-width: none;
  margin-bottom: 1rem;
}

.route-tracker {
  /* Narrower than the journey timeline's 200px cards: a drop carries a code, a
     postcode and a status, not a paragraph, and a 40-drop batch should show as
     many at once as it can. */
  scroll-behavior: smooth;
}

.route-tracker .timeline__item {
  width: 150px;
  padding-right: 1.25rem;
}

.route-tracker__stop--done .timeline__marker {
  background: var(--good);
  box-shadow: 0 0 0 3px var(--good-soft);
}

.route-tracker__stop--failed .timeline__marker {
  background: var(--bad);
  box-shadow: 0 0 0 3px var(--bad-soft);
}

.route-tracker__stop--active .timeline__marker {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Not yet attempted: hollow, matching the order page's pending stops. */
.route-tracker__stop--pending .timeline__marker,
.route-tracker__stop--collection .timeline__marker {
  background: var(--bg);
  border: 2px solid color-mix(in srgb, var(--text-muted) 45%, transparent);
  box-shadow: none;
}

.route-tracker__stop--collection {
  opacity: 0.75;
}

/* A settled drop is history; the live one is what the reader came for. */
.route-tracker__stop--done .timeline__body,
.route-tracker__stop--failed .timeline__body {
  opacity: 0.8;
}

.route-tracker__stop--current .timeline__body {
  opacity: 1;
}

.route-tracker__stop--current .timeline__title {
  font-weight: 700;
}

.route-tracker__now {
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.route-tracker__status {
  margin-top: 0.15rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.route-tracker__status--done { color: var(--good); }
.route-tracker__status--failed { color: var(--bad); }
.route-tracker__status--active { color: var(--accent); }
.route-tracker__status--pending { color: var(--text-muted); }

/* Outcome accent on the full drop records below the tracker, so scrolling the
   long list still reads as a sequence of outcomes. Every stop reserves the
   accent's width so nothing shifts sideways between an outcome and a
   collection row; the state rules below only set its colour. */
.stop {
  border-left: 3px solid transparent;
}

.stop--done { border-left-color: var(--good); }
.stop--failed { border-left-color: var(--bad); }
.stop--active { border-left-color: var(--accent); }
.stop--pending { border-left-color: color-mix(in srgb, var(--text-muted) 30%, transparent); }

/* Delivery timings on the tracker. An actual completion time is the fact worth
   reading; a planned window is only a placeholder until then. */
.route-tracker__time {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}

.route-tracker__time--planned {
  font-weight: 400;
  color: var(--text-muted);
}

.stop__settled {
  font-weight: 600;
}

.stop__settled--done { color: var(--good); }
.stop__settled--failed { color: var(--bad); }

/* The full drop records. A batch runs to ~35 stops, and rendered flat that made
   the page several screens tall and pushed the status timeline out of reach —
   so the list is bounded to roughly four drops and scrolls within itself. The
   route tracker above is the at-a-glance view; this is the detail. */
.drop-list {
  max-height: 30rem;
  overflow-y: auto;
  /* Room for the scrollbar so it never sits on top of the outcome accent. */
  padding-right: 0.5rem;
  /* Contains the sticky-free scroll so a drop's own hover/focus ring is not
     clipped against the first/last row. */
  scrollbar-gutter: stable;
}

.drop-list .stop:first-child {
  padding-top: 0;
}
