*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --pg-bg: #f7f7f6;
  --accent: #ff5a5f;
  --accent-2: #ff8a5c;
  --font: "Plus Jakarta Sans", ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --ink: #0a0f1a;
  --ink-soft: #334155;
  --muted: #64748b;
  --surface: #ffffff;
  --border: 1px solid rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 28px rgba(15, 23, 42, 0.08);
  --radius-lg: 22px;
  --radius-md: 16px;
  --page-pad: 20px;
}

html {
  background: var(--pg-bg);
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  padding: 0 0 max(100px, calc(88px + env(safe-area-inset-bottom, 0px))) 0;
  font-family: var(--font);
  background: var(--pg-bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.app-container {
  max-width: 480px;
  margin: 0 auto;
  background: var(--pg-bg);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: calc(52px + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px)
    max(12px, env(safe-area-inset-left, 0px))
    0
    max(12px, env(safe-area-inset-right, 0px));
  background: rgba(247, 247, 246, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
}

.back-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border: none;
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  text-decoration: none;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.08);
  transition: transform 0.2s ease, opacity 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.back-btn:active {
  transform: scale(0.93);
  opacity: 0.8;
}

.back-btn svg {
  width: 22px;
  height: 22px;
  display: block;
}

.header-text {
  flex: 1;
  padding-right: 44px;
  text-align: center;
  min-width: 0;
}

.header-kicker {
  margin: 0;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.header-title {
  margin: 2px 0 0;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--ink);
  line-height: 1.2;
}

.bus-main {
  padding: 20px var(--page-pad) 28px;
}

.hero-copy {
  margin: 0 0 18px;
}

.hero-copy h2 {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.2;
}

.hero-copy p {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
}

.search-card {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: 16px;
}

/* Mobile: From and To are full-width, on separate rows. The swap button is
   taken out of flow and sits on the right, between the two inputs. */
.route-row {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.route-row .field {
  width: 100%;
}

/* keep typed text clear of the swap button */
.route-row input.field-control {
  padding-right: 60px;
}

.field {
  position: relative;
}

.field-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.field-control {
  width: 100%;
  min-height: 54px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.2;
  display: flex;
  align-items: center;
}

.field-control[readonly] {
  color: var(--ink);
}

input.field-control {
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  text-overflow: ellipsis;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

input.field-control::placeholder {
  color: #94a3b8;
  font-weight: 600;
}

input.field-control:focus {
  border-color: rgba(255, 90, 95, 0.55);
  background: #fff;
}

/* City autocomplete dropdown */
.ac-list {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 40;
  width: max(100%, min(320px, calc(100vw - 72px)));
  max-height: 296px;
  margin: 0;
  padding: 6px;
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-soft);
}

.ac-list[hidden] {
  display: none;
}

/* Right-hand field opens leftwards so the wider list stays on screen. */
.route-row .field:last-child .ac-list {
  left: auto;
  right: 0;
}

.ac-option,
.ac-status {
  padding: 11px 12px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}

.ac-option {
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.ac-option mark {
  background: none;
  color: var(--ink);
  font-weight: 800;
}

.ac-option.is-active,
.ac-option:hover {
  background: #f1f5f9;
}

.ac-status {
  color: var(--muted);
  font-weight: 500;
}

.overlay-title {
  margin: 0;
  font-weight: 800;
}

.overlay-copy {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.swap-btn {
  --swap-rot: 0deg;
  position: absolute;
  right: 10px;
  /* centre of the gap between the two inputs (labels sit above each input) */
  top: calc(50% + 10px);
  transform: translateY(-50%);
  z-index: 3;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid #e2e8f0;
  border-radius: 50%;
  background: #fff;
  color: var(--accent);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow 0.15s ease;
}

.swap-btn:active {
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.18);
}

.swap-btn:focus-visible {
  outline: 2px solid rgba(255, 90, 95, 0.6);
  outline-offset: 2px;
}

.swap-btn svg {
  width: 20px;
  height: 20px;
  transform: rotate(var(--swap-rot));
  transition: transform 0.25s ease;
}

.swap-btn.is-flipped svg {
  transform: rotate(calc(var(--swap-rot) + 180deg));
}

@media (prefers-reduced-motion: reduce) {
  .swap-btn svg {
    transition: none;
  }
}

.date-field {
  margin-top: 14px;
  position: relative;
}

.date-display {
  min-height: 54px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid #e2e8f0;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.date-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

.date-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  color: var(--accent);
}

.date-display strong {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.date-display span {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.native-date {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 54px;
  opacity: 0;
  z-index: 2;
  cursor: pointer;
  font-size: 16px;
}

.date-chips {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.date-chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex-shrink: 0;
  border: 1px solid #e2e8f0;
  background: #fff;
  color: var(--ink-soft);
  border-radius: 999px;
  min-height: 40px;
  padding: 0 14px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.chip.is-active {
  background: rgba(255, 90, 95, 0.1);
  border-color: rgba(255, 90, 95, 0.35);
  color: var(--accent);
}

.search-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 16px;
  min-height: 54px;
  border: none;
  border-radius: 16px;
  font-family: var(--font);
  font-size: 17px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.search-btn:disabled {
  opacity: 0.7;
  cursor: wait;
}

.search-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}

.search-btn.is-loading .btn-spinner {
  display: block;
}

.search-error {
  display: none;
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #fef2f2;
  color: #b91c1c;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
}

.search-error.is-visible {
  display: block;
}

.trust-row {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.trust-row span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(10, 15, 26, 0.28);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.overlay.is-visible {
  display: flex;
}

.overlay-card {
  width: min(320px, 100%);
  background: #fff;
  border-radius: 20px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: var(--shadow-soft);
}

.overlay-spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 14px;
  border: 3px solid #ffe1e2;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

.bottom-nav {
  display: flex;
  justify-content: space-around;
  align-items: center;
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.06);
  padding: 8px 8px calc(10px + env(safe-area-inset-bottom, 0px));
  z-index: 100;
  box-sizing: border-box;
  max-width: 450px;
  margin: 0 auto;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: #64748b;
  font-size: 0.7rem;
  font-weight: 500;
  transition: color 0.2s ease;
  cursor: pointer;
  flex: 1;
  min-width: 0;
  padding: 4px 2px;
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}

.nav-icon {
  font-size: 1.4rem;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.nav-icon svg {
  display: block;
  width: 24px;
  height: 24px;
}

.nav-item.active {
  color: #ff6b6b;
}

@media (min-width: 768px) {
  /* Tablet / desktop: From | swap | To on one row again. */
  .route-row {
    display: grid;
    grid-template-columns: 1fr 44px 1fr;
    gap: 8px;
    align-items: end;
  }

  .route-row input.field-control {
    padding-right: 14px;
  }

  .swap-btn {
    --swap-rot: 90deg; /* the arrows point left/right */
    position: static;
    transform: none;
    width: 44px;
    height: 54px;
    border-radius: 14px;
    box-shadow: none;
  }

  .app-container {
    max-width: 720px;
  }

  .app-header {
    min-height: calc(64px + env(safe-area-inset-top, 0px));
    padding-left: 20px;
    padding-right: 20px;
  }

  .header-title {
    font-size: 22px;
  }

  .search-card {
    padding: 22px;
  }

  .hero-copy h2 {
    font-size: 28px;
  }
}

@media (min-width: 1024px) {
  html {
    background: #eef0f4;
  }

  .app-container {
    max-width: 920px;
    background: transparent;
  }

  .app-header {
    min-height: calc(80px + env(safe-area-inset-top, 0px));
    padding-left: 40px;
    padding-right: 40px;
  }

  .header-text {
    text-align: left;
    padding-right: 0;
  }

  .header-title {
    font-size: 30px;
  }

  .bus-main {
    padding: 32px 40px 56px;
  }

  .search-card {
    display: grid;
    grid-template-columns: 1fr 1fr 220px auto;
    gap: 14px;
    align-items: end;
    padding: 24px;
  }

  .route-row {
    grid-column: 1 / 3;
  }

  .date-field {
    margin-top: 0;
  }

  .date-chips {
    grid-column: 1 / -1;
    margin-top: 0;
  }

  .search-btn {
    margin-top: 0;
    min-width: 180px;
  }

  .search-error {
    grid-column: 1 / -1;
  }
}

@media (min-width: 1440px) {
  .app-container {
    max-width: 1040px;
  }
}
