:root {
  color-scheme: light;
  --ink: #202933;
  --ink-strong: #141a21;
  --muted: #66727f;
  --line: #e5e8ee;
  --panel: #ffffff;
  --paper: #fff9f6;
  --soft: #f6f7f9;
  --brand: #ef101a;
  --brand-dark: #bd0710;
  --brand-orange: #ff5a00;
  --brand-orange-soft: #fff0e7;
  --charcoal: #242d36;
  --blue: #255f78;
  --amber: #f4b43f;
  --warn: #b42318;
  --ok: #087443;
  --radius: 8px;
  --shadow: 0 18px 50px rgba(32, 41, 51, 0.12);
  --shadow-soft: 0 10px 26px rgba(32, 41, 51, 0.09);
  --i-search: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3C/svg%3E");
  --i-external: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 3h6v6'/%3E%3Cpath d='M10 14 21 3'/%3E%3Cpath d='M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6'/%3E%3C/svg%3E");
  --i-refresh: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 12a9 9 0 0 1-15 6.7L3 16'/%3E%3Cpath d='M3 21v-5h5'/%3E%3Cpath d='M3 12a9 9 0 0 1 15-6.7L21 8'/%3E%3Cpath d='M16 8h5V3'/%3E%3C/svg%3E");
  --i-ticket: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 9a3 3 0 0 0 0 6v3a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-3a3 3 0 0 0 0-6V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2Z'/%3E%3Cpath d='M13 5v2'/%3E%3Cpath d='M13 17v2'/%3E%3Cpath d='M13 11v2'/%3E%3C/svg%3E");
  --i-train: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 15V6a3 3 0 0 1 3-3h10a3 3 0 0 1 3 3v9a3 3 0 0 1-3 3H7a3 3 0 0 1-3-3Z'/%3E%3Cpath d='M8 21l2-3'/%3E%3Cpath d='M16 21l-2-3'/%3E%3Cpath d='M4 11h16'/%3E%3Cpath d='M8 7h.01'/%3E%3Cpath d='M16 7h.01'/%3E%3C/svg%3E");
  --i-check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m20 6-11 11-5-5'/%3E%3C/svg%3E");
  --i-x: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 6 6 18'/%3E%3Cpath d='m6 6 12 12'/%3E%3C/svg%3E");
  --i-alert: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 9v4'/%3E%3Cpath d='M12 17h.01'/%3E%3Cpath d='M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z'/%3E%3C/svg%3E");
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, Arial, Helvetica, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(239, 16, 26, 0.035) 0 25%, transparent 25% 50%, rgba(255, 90, 0, 0.035) 50% 75%, transparent 75%) 0 0 / 36px 36px,
    linear-gradient(180deg, #fff9f6 0%, #f4f6f8 56%, #ffffff 100%);
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 1em;
  height: 1em;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

.app-shell {
  width: min(100% - 16px, 1160px);
  margin: 0 auto;
  padding: 8px 0 34px;
}

.search-stage {
  display: grid;
  overflow: hidden;
  border: 1px solid rgba(36, 45, 54, 0.1);
  border-radius: var(--radius);
  background: var(--panel);
  background: color-mix(in srgb, var(--panel) 94%, var(--brand-orange-soft));
  box-shadow: var(--shadow);
}

.stage-content {
  display: grid;
  gap: 18px;
  padding: 16px;
}

.stage-media {
  position: relative;
  min-height: 178px;
  overflow: hidden;
  border-top: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(20, 26, 33, 0.04), rgba(20, 26, 33, 0.34)),
    url("/student-ticket-hero.png") center 48% / cover;
}

.stage-media::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(239, 16, 26, 0.25), transparent 38%),
    linear-gradient(0deg, rgba(20, 26, 33, 0.32), transparent 62%);
}

.media-badge {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 1;
  display: grid;
  min-width: 92px;
  min-height: 64px;
  align-content: center;
  border: 1px solid rgba(255, 255, 255, 0.54);
  border-radius: var(--radius);
  padding: 9px 12px;
  color: #fff;
  background: linear-gradient(135deg, rgba(239, 16, 26, 0.94), rgba(255, 90, 0, 0.9));
  box-shadow: 0 14px 28px rgba(20, 26, 33, 0.22);
}

.media-badge strong {
  font-size: 1.45rem;
  line-height: 1;
}

.media-badge span {
  margin-top: 3px;
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

.app-header {
  display: grid;
  gap: 13px;
  min-width: 0;
}

.brand-lockup {
  display: inline-grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 11px;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  color: var(--ink-strong);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(239, 16, 26, 0.16);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.brand-copy > span {
  color: var(--ink-strong);
  font-size: 1.08rem;
  font-weight: 950;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.brand-copy small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.eyebrow {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  margin-bottom: 0;
  color: var(--brand);
  font-size: 0.8rem;
  font-weight: 900;
  text-transform: uppercase;
}

h1 {
  margin-bottom: 0;
  color: var(--ink-strong);
  font-size: 2.05rem;
  line-height: 1.03;
}

.app-header p:not(.eyebrow) {
  margin-bottom: 0;
  color: #4b5562;
  font-size: 1rem;
  line-height: 1.5;
}

.search-panel {
  display: grid;
  gap: 12px;
}

.field-stack {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  gap: 10px;
  align-items: end;
}

.field-stack label:last-child {
  grid-column: 1 / -1;
}

.date-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 128px;
  gap: 10px;
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: #3e4855;
  font-size: 0.82rem;
  font-weight: 850;
}

.label-text {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  min-width: 0;
  color: var(--charcoal);
}

.label-text .icon {
  color: var(--brand);
}

input,
select {
  width: 100%;
  min-height: 50px;
  border: 1px solid #cfd6df;
  border-radius: var(--radius);
  padding: 0 12px;
  color: var(--ink);
  background-color: #fff;
  font-size: 1rem;
  box-shadow: 0 1px 0 rgba(32, 41, 51, 0.03);
}

select {
  appearance: none;
  padding-right: 38px;
  background-image:
    linear-gradient(45deg, transparent 50%, #5b6571 50%),
    linear-gradient(135deg, #5b6571 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 21px,
    calc(100% - 13px) 21px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

input:focus,
select:focus,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(239, 16, 26, 0.18);
  outline-offset: 2px;
}

.primary-action,
.secondary-action,
.connection-action,
.buy-link,
.swap-button {
  min-height: 50px;
  border-radius: var(--radius);
  padding: 0 14px;
  font-weight: 900;
  cursor: pointer;
  text-decoration: none;
}

.primary-action,
.secondary-action,
.connection-action,
.buy-link {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.15;
}

.primary-action,
.connection-action,
.buy-link {
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-orange));
  box-shadow: 0 10px 22px rgba(239, 16, 26, 0.2);
}

.primary-action:hover,
.connection-action:hover,
.buy-link:hover {
  background: linear-gradient(135deg, var(--brand-dark), #eb4a00);
}

.secondary-action,
.swap-button {
  border: 1px solid #cfd6df;
  color: var(--ink);
  background: #fff;
}

.secondary-action:hover,
.swap-button:hover {
  border-color: rgba(239, 16, 26, 0.34);
  background: #fff6f2;
}

.swap-button {
  display: grid;
  width: 48px;
  padding: 0;
  place-items: center;
  color: var(--brand);
}

.primary-action::before,
.secondary-action::before,
.connection-action::before,
.buy-link::before,
.connection-count::before,
.ticket-badge::before {
  content: "";
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  background: currentColor;
  -webkit-mask: var(--button-icon) center / contain no-repeat;
  mask: var(--button-icon) center / contain no-repeat;
}

.primary-action,
.connection-action {
  --button-icon: var(--i-search);
}

.secondary-action {
  --button-icon: var(--i-refresh);
}

.buy-link {
  --button-icon: var(--i-external);
}

.connection-count {
  --button-icon: var(--i-train);
}

.ticket-badge {
  --button-icon: var(--i-ticket);
}

.ticket-badge.ok {
  --button-icon: var(--i-check);
}

.ticket-badge.bad {
  --button-icon: var(--i-x);
}

.ticket-badge.warn {
  --button-icon: var(--i-alert);
}

button:disabled {
  cursor: progress;
  opacity: 0.64;
}

.hidden {
  display: none;
}

.status-panel,
.connections,
.results {
  margin-top: 12px;
  border: 1px solid rgba(36, 45, 54, 0.1);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-soft);
}

.status-panel {
  padding: 15px;
  border-left: 5px solid var(--brand);
}

.status-panel.error {
  border-left-color: var(--warn);
  color: var(--warn);
}

.status-panel.done {
  border-left-color: var(--ok);
}

.status-head {
  display: flex;
  gap: 12px;
  align-items: center;
}

.status-head strong,
.status-head span {
  display: block;
}

.status-head span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.82rem;
}

.spinner {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border: 3px solid rgba(239, 16, 26, 0.18);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

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

.progress-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.progress-list li {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 10px 11px;
  border: 1px solid #e8edf2;
  border-radius: var(--radius);
  background: #fff;
  color: #344054;
}

.progress-list li::before {
  content: "";
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  margin-top: 7px;
  border-radius: 999px;
  background: var(--brand-orange);
}

.progress-list li.done {
  border-color: rgba(8, 116, 67, 0.28);
  color: var(--ok);
}

.progress-list li.done::before {
  background: var(--ok);
}

.progress-list li.error {
  border-color: rgba(180, 35, 24, 0.28);
  color: var(--warn);
}

.progress-list li.error::before {
  background: var(--warn);
}

.connections,
.results {
  padding: 15px;
}

.connections-head,
.decision {
  display: grid;
  gap: 12px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--line);
}

.connections-head h2,
.decision h2 {
  margin-bottom: 5px;
  color: var(--ink-strong);
  font-size: 1.45rem;
  line-height: 1.14;
}

.connections-head p,
.decision p,
.segment-row p,
.connection-row p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.meta,
.segment-time,
.muted {
  color: var(--muted);
}

.meta,
.segment-time {
  font-size: 0.82rem;
  font-weight: 850;
}

.connections-actions,
.decision-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.connection-count,
.ticket-badge {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: var(--radius);
  padding: 0 12px;
  font-weight: 900;
  line-height: 1.15;
  white-space: nowrap;
}

.connection-count {
  color: #fff;
  background: var(--blue);
}

.connection-list {
  display: grid;
  gap: 10px;
  padding-top: 15px;
}

.connection-row {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fff, #fffaf7);
}

.connection-row.selected {
  border-color: rgba(239, 16, 26, 0.46);
  box-shadow: inset 4px 0 0 var(--brand);
}

.connection-row h3 {
  margin: 4px 0 6px;
  color: var(--ink-strong);
  font-size: 1.45rem;
}

.connection-route {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  color: var(--muted);
}

.connection-route strong {
  min-width: 0;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.handoff-status {
  width: 100%;
  min-height: 18px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.handoff-status.done {
  color: var(--ok);
}

.handoff-status.error {
  color: var(--warn);
}

.empty-state {
  margin-top: 15px;
  padding: 14px;
  border: 1px dashed #c2cad4;
  border-radius: var(--radius);
  background: var(--soft);
}

.empty-state p {
  margin: 6px 0 0;
  color: var(--muted);
}

.decision {
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffaf7;
}

.decision.available {
  border-color: rgba(8, 116, 67, 0.3);
  background: #f1fbf6;
}

.decision.empty {
  border-color: rgba(180, 35, 24, 0.22);
  background: #fff7f5;
}

.ticket-badge.ok {
  color: #fff;
  background: var(--ok);
}

.ticket-badge.bad {
  color: #fff;
  background: var(--warn);
}

.ticket-badge.warn {
  color: #342300;
  background: var(--amber);
}

.result-error,
.interval-error {
  margin-top: 8px;
  color: var(--warn);
  font-weight: 850;
}

.result-grid {
  display: grid;
  gap: 18px;
  padding-top: 16px;
}

.result-grid h2 {
  margin-bottom: 10px;
  color: var(--ink-strong);
  font-size: 1.1rem;
}

.route-list {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.route-list li {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid #edf1f5;
}

.route-list span {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.route-list strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

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

.segment-row {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.segment-row.available {
  border-color: rgba(8, 116, 67, 0.28);
}

.segment-row h3 {
  margin: 5px 0;
  color: var(--ink-strong);
  font-size: 1rem;
}

@media (min-width: 720px) {
  .app-shell {
    width: min(100% - 32px, 1160px);
    padding-top: 20px;
  }

  .search-stage {
    grid-template-columns: minmax(0, 1fr) 390px;
  }

  .stage-content {
    align-content: center;
    padding: 28px;
  }

  .stage-media {
    min-height: 100%;
    border-top: 0;
    border-left: 1px solid var(--line);
    background:
      linear-gradient(90deg, rgba(20, 26, 33, 0.02), rgba(20, 26, 33, 0.34)),
      url("/student-ticket-hero.png") center / cover;
  }

  .field-stack {
    grid-template-columns: minmax(0, 1fr) 48px minmax(0, 1fr);
  }

  .field-stack label:last-child {
    grid-column: auto;
  }

  .date-row {
    grid-template-columns: minmax(0, 1fr) 150px;
  }

  .connection-row {
    grid-template-columns: minmax(0, 1fr) minmax(184px, 0.32fr);
    align-items: center;
  }

  .connections-head,
  .decision {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
  }

  .connections-actions,
  .decision-actions {
    justify-content: flex-end;
  }

  .handoff-status {
    text-align: right;
  }

  .segment-row {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }
}

@media (min-width: 1040px) {
  .stage-content {
    padding: 34px;
  }

  .brand-lockup {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .brand-mark {
    width: 64px;
    height: 64px;
  }

  h1 {
    max-width: 720px;
    font-size: 3rem;
  }

  .result-grid {
    grid-template-columns: minmax(360px, 1.16fr) minmax(280px, 0.84fr);
  }
}

@media (max-width: 520px) {
  h1 {
    font-size: 1.84rem;
  }

  .stage-content,
  .connections,
  .results,
  .status-panel {
    padding: 14px;
  }

  .date-row {
    grid-template-columns: 1fr;
  }

  .connection-action,
  .primary-action,
  .buy-link,
  .secondary-action,
  .ticket-badge,
  .connection-count {
    width: 100%;
  }

  .connections-actions,
  .decision-actions {
    width: 100%;
  }
}
