.results {
  margin-top: var(--s-5);
  display: grid;
  gap: var(--s-4);
  scroll-margin-top: 72px;
  min-width: 0;
}

/* Let flex/grid text containers shrink instead of forcing horizontal overflow. */
.results-head > div,
.plan,
.plan__head,
.plan__badges,
.legs,
.leg,
.leg__body,
.leg__route,
.switch,
.switch__text,
.status-hero {
  min-width: 0;
}

.leg__meta,
.status-hero__sub,
.results-head__sub {
  overflow-wrap: anywhere;
}

/* Results header */
.results-head {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  box-shadow: var(--shadow);
}

.results-head__title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.results-head__title .mono {
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
  margin-right: 7px;
}

.results-head__sub {
  color: var(--ink-2);
  font-size: 13px;
  margin-top: 3px;
}

.results-head__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: var(--s-3);
  font-size: 13px;
  color: var(--muted);
}

.stat-tiles {
  display: flex;
  gap: var(--s-2);
}

.stat-tile {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s-2) var(--s-3);
  text-align: center;
  min-width: 84px;
}

.stat-tile__value {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}

.stat-tile__label {
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
}

/* Status hero */
.status-hero {
  display: grid;
  gap: var(--s-1);
}

.status-hero__row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  flex: none;
}

.status-word {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.status--full .status-dot {
  background: var(--ok-dot);
}
.status--full .status-word {
  color: var(--ok);
}
.status--partial .status-dot {
  background: var(--warn-dot);
}
.status--partial .status-word {
  color: var(--warn);
}
.status--none .status-dot {
  background: var(--muted);
}
.status--none .status-word {
  color: var(--ink-2);
}

.status-hero__sub {
  font-size: 15px;
  color: var(--ink-2);
  line-height: 1.45;
}

.spinner {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Info banner */
.banner {
  display: flex;
  gap: var(--s-2);
  align-items: flex-start;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--accent-tint);
  border: 1px solid var(--accent-border);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-3);
}

.banner .icon {
  margin-top: 2px;
  color: var(--accent);
}

.section-title {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  margin-top: var(--s-2);
}
.section-title::before {
  content: '// ';
  opacity: 0.55;
}

/* Plans */
.plan-list {
  display: grid;
  gap: var(--s-3);
}

.plan {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  box-shadow: var(--shadow);
  display: grid;
  gap: var(--s-3);
}

.plan--best {
  border-color: var(--accent-border);
  box-shadow: var(--shadow-lift);
}

.plan__head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--s-3);
  align-items: flex-start;
}

.plan__badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.plan__title {
  font-size: 15px;
  font-weight: 700;
  margin-left: 2px;
}

.plan__fare {
  text-align: right;
  display: grid;
}

.plan__fare strong {
  font-size: 18px;
  font-weight: 700;
}

.plan__fare small,
.plan__foot {
  font-size: 12px;
  color: var(--muted);
}

/* Journey ribbon */
.ribbon {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 26px 2px 28px;
  overflow: hidden; /* contain the absolutely-positioned seg/node labels (nowrap) */
}

.ribbon__cap {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  flex: none;
}

.ribbon__track {
  flex: 1;
  display: flex;
  align-items: center;
  min-width: 0;
}

.ribbon__seg {
  position: relative;
  height: 10px;
}

.ribbon__seg--a {
  background: var(--accent);
}
.ribbon__seg--b {
  background: var(--accent-soft);
}
.ribbon__seg--gap {
  height: 0;
  border-top: 3px dashed var(--warn-dot);
  background: none;
}

.ribbon__seg-label {
  position: absolute;
  bottom: 16px;
  left: 0;
  right: 0;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis; /* never spill into neighbouring segments */
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
}

.ribbon__seg--gap .ribbon__seg-label {
  bottom: 9px;
  color: var(--warn);
}

.ribbon__node {
  flex: none;
  width: 18px;
  height: 18px;
  position: relative;
  box-sizing: border-box;
  border-radius: 999px;
  background: var(--surface);
  border: 3px solid var(--ink);
  margin: 0 -3px;
  z-index: 1;
}

.ribbon__node--risky {
  border-color: var(--warn);
}

.ribbon__node-label {
  position: absolute;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-2);
}

.ribbon__node--risky .ribbon__node-label {
  color: var(--warn);
}

/* Legs */
.legs {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.leg {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: var(--border);
  border-radius: var(--r-md);
  padding: 10px 12px;
}

.leg__num {
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13px;
}

.leg__body {
  display: grid;
  gap: 3px;
  flex: 1;
  min-width: 0;
}

.leg__route {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.leg__code {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 15px;
}

.leg__type {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 7px;
}

.leg__time {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-2);
}

.leg__meta {
  font-size: 13px;
  color: var(--ink-2);
}

.leg__meta .mono {
  color: var(--ink);
}

/* Switch row */
.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--soft);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-md);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--ink-2);
}

.switch .icon {
  flex: none;
  color: var(--ink-2);
}

.switch__text strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.switch--risky {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn-ink);
}

.switch--risky .icon {
  color: var(--warn);
}
.switch--risky .switch__text strong {
  color: var(--warn);
}

.switch__tags {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

/* Plan footer */
.plan__foot {
  display: grid;
  gap: 6px;
}

.plan__foot .btn {
  width: 100%;
}

/* States */
.state-card {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  display: grid;
  gap: 4px;
  box-shadow: var(--shadow);
}

.state-card h2,
.state-card h3 {
  font-size: 16px;
}

.state-card p {
  color: var(--ink-2);
  font-size: 14px;
}

.state-card--warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
}
.state-card--warn p {
  color: var(--warn-ink);
}

.state-card--error {
  background: var(--danger-bg);
  border-color: transparent;
  color: var(--danger);
}
.state-card--error p {
  color: var(--danger);
}

.state-card__hint {
  font-weight: 600;
}

.state-card__details {
  margin-top: var(--s-2, 8px);
  font-size: 13px;
}
.state-card__details summary {
  cursor: pointer;
  font-weight: 600;
}
.state-card__details dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 12px;
  margin: 8px 0;
}
.state-card__details dt {
  color: var(--ink-2);
}
.state-card__details dd {
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.setup-card__steps {
  margin: 4px 0;
  padding-left: 20px;
  display: grid;
  gap: 6px;
  font-size: 14px;
  color: var(--warn-ink);
}
.setup-card a {
  color: inherit;
  font-weight: 600;
}

/* Loading: centred card while the first coaches are read */
.loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: min(420px, 60vh);
  padding: var(--s-6) var(--s-4);
  text-align: center;
  background: var(--surface);
  border: var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.loading-card .spinner--lg {
  margin-bottom: var(--s-2);
}
.loading-card__title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.loading-card__title .mono {
  color: var(--accent);
}
.loading-card__sub {
  color: var(--ink-2);
  font-size: 14px;
}
.loading-card .progress {
  width: min(280px, 100%);
  margin-top: var(--s-3);
}
@media (min-width: 1024px) {
  /* Centre it in the visible part of the right column. */
  .loading-card {
    min-height: calc(100vh - var(--header-h) - 2 * var(--s-6));
  }
}

.spinner--lg {
  width: 40px;
  height: 40px;
  border-width: 4px;
}

/* Progress bar: determinate (coach n of N) or an indeterminate sweep */
.progress {
  position: relative;
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--soft);
  overflow: hidden;
}
.progress__fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.3s ease;
}
.progress--indeterminate .progress__fill {
  width: 35%;
  animation: progress-sweep 1.2s ease-in-out infinite;
}
@keyframes progress-sweep {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(300%);
  }
}

/* Progressive (coach-by-coach) loading: stays pinned under the header while you scroll */
.partial-banner {
  position: sticky;
  top: calc(var(--header-h) + 8px);
  z-index: 4;
  display: grid;
  gap: 8px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--accent-border);
  border-radius: var(--r-md, 10px);
  box-shadow: var(--shadow-lift);
  color: var(--ink-2);
  font-size: 14px;
}
.partial-banner__row {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* No extension yet: a friendly setup step, not an error */
.install-card {
  display: grid;
  justify-items: center;
  gap: var(--s-2);
  padding: var(--s-6) var(--s-5);
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--accent-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.install-card__icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent-tint);
  color: var(--accent);
  margin-bottom: var(--s-1);
}
.install-card__icon .icon {
  width: 24px;
  height: 24px;
}
.install-card h2 {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.install-card p {
  color: var(--ink-2);
  font-size: 15px;
  max-width: 44ch;
}
.install-card__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--s-2);
  margin-top: var(--s-3);
}
.install-card__actions .btn--primary {
  min-height: 48px;
  font-size: 16px;
}
.install-card__foot {
  margin-top: var(--s-2);
  font-size: 13px !important;
  color: var(--muted) !important;
}
.install-card__foot a {
  color: var(--accent);
  font-weight: 600;
}

.state-card__actions {
  display: flex;
  justify-content: flex-end;
  margin-top: var(--s-2);
}
.state-card--error .state-card__actions .btn {
  color: var(--danger);
}
.spinner--sm {
  width: 16px;
  height: 16px;
  border-width: 2px;
  flex: none;
}

/* ---------- Berth explorer: vacant berths grouped by coach ---------- */
.berths {
  display: grid;
  gap: var(--s-3);
  min-width: 0;
}

.berths__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-3);
  margin-top: var(--s-2);
}
.berths__head .section-title {
  margin-top: 0;
}

.link-btn {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}
.link-btn:hover {
  text-decoration: underline;
}

.berths__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2) var(--s-3);
}

.seg {
  display: inline-flex;
  flex-wrap: wrap;
  padding: 3px;
  background: var(--soft);
  border: var(--border);
  border-radius: var(--r-pill);
}

.seg-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  font: 600 13px var(--font);
  color: var(--ink-2);
  cursor: pointer;
}
.seg-btn[aria-pressed='true'] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.seg-btn:disabled {
  opacity: 0.45;
  cursor: default;
}
.seg-btn__count {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  font: 500 13px var(--font);
  color: var(--ink-2);
  cursor: pointer;
}
.chip:hover {
  border-color: var(--accent-soft);
}
.chip[aria-pressed='true'] {
  background: var(--accent-tint);
  border-color: var(--accent-border);
  color: var(--accent-ink);
  font-weight: 600;
}

.berths__legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px var(--s-4);
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}
.legend::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-radius: 3px;
  vertical-align: -1px;
}
.legend--full::before {
  background: var(--accent);
}
.legend--partial::before {
  background: var(--accent-soft);
}
.berths__count {
  margin-left: auto;
  font-family: var(--mono);
}

.coach-list {
  display: grid;
  gap: 10px;
}

.coach {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}

.coach__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px var(--s-4);
  cursor: pointer;
  list-style: none;
  border-radius: var(--r-lg);
}
.coach__head::-webkit-details-marker {
  display: none;
}
.coach__head::after {
  content: '';
  flex: none;
  width: 7px;
  height: 7px;
  margin: 0 4px 3px 4px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s;
}
.coach[open] .coach__head::after {
  transform: rotate(-135deg);
  margin-bottom: -3px;
}
.coach__head:hover {
  background: var(--field);
}

.coach__name {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 15px;
}

.coach__cls {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: var(--r-pill);
  background: var(--soft);
  border: 1px solid var(--line);
  color: var(--ink-2);
}

.coach__counts {
  margin-left: auto;
  display: flex;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}
.coach__full {
  color: var(--accent);
  font-weight: 600;
}

.berth-grid {
  list-style: none;
  margin: 0;
  padding: 0 12px 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
}

.berth {
  display: grid;
  gap: 1px;
  align-content: start;
  padding: 8px 9px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent-soft);
  border-radius: 10px;
  min-width: 0;
}
.berth--full {
  background: var(--accent-tint);
  border-color: var(--accent-border);
  border-left-color: var(--accent);
}

.berth__no {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
}

.berth__type {
  font-size: 12px;
  color: var(--ink-2);
}

.berth__spans {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.berth--full .berth__spans {
  color: var(--accent-ink);
  font-weight: 600;
}

.seg-btn:focus-visible,
.chip:focus-visible,
.link-btn:focus-visible,
.coach__head:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (min-width: 720px) {
  .berth-grid {
    grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  }
}
