/* ==========================================================================
   London Bus Tracker — styles.css
   Mobile-first. Catppuccin Mocha palette. Inter for UI, JetBrains Mono
   for anything numeric/time-based (countdowns, distances, stop codes).
   ========================================================================== */

:root {
  /* Catppuccin Mocha */
  --base: #1e1e2e;
  --mantle: #181825;
  --crust: #11111b;
  --text: #cdd6f4;
  --subtext1: #bac2de;
  --subtext0: #a6adc8;
  --overlay2: #9399b2;
  --overlay1: #7f849c;
  --overlay0: #6c7086;
  --surface2: #585b70;
  --surface1: #45475a;
  --surface0: #313244;
  --blue: #89b4fa;
  --lavender: #b4befe;
  --sapphire: #74c7ec;
  --sky: #89dceb;
  --teal: #94e2d5;
  --green: #a6e3a1;
  --yellow: #f9e2af;
  --peach: #fab387;
  --maroon: #eba0ac;
  --red: #f38ba8;
  --mauve: #cba6f7;
  --pink: #f5c2e7;

  --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;

  --header-h: 56px;
  --tabbar-h: 64px;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--base);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

body {
  padding-top: calc(var(--header-h) + var(--safe-t));
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b));
  min-height: 100dvh;
}

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

input, select {
  font-family: inherit;
  color: inherit;
}

a { color: var(--sapphire); }

::selection { background: var(--mauve); color: var(--crust); }

:focus-visible {
  outline: 2px solid var(--sapphire);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- Header ---------- */

.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--header-h) + var(--safe-t));
  padding-top: var(--safe-t);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-inline: 16px;
  background: color-mix(in srgb, var(--mantle) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--surface0);
  z-index: 50;
}

.app-header__brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: -0.01em; }
.app-header__mark { font-size: 1.15rem; }
.app-header__title { font-size: 1.05rem; }

.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 50%;
  font-size: 1.05rem;
  color: var(--subtext1);
}
.icon-btn:active { background: var(--surface0); }

/* ---------- Offline banner ---------- */

.offline-banner {
  position: fixed;
  top: calc(var(--header-h) + var(--safe-t));
  left: 0; right: 0;
  z-index: 49;
  background: var(--yellow);
  color: var(--crust);
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  padding: 6px 8px;
}

/* ---------- Main / views ---------- */

.app-main {
  padding: 14px 16px 24px;
  max-width: 640px;
  margin-inline: auto;
  min-height: calc(100dvh - var(--header-h) - var(--tabbar-h));
}

.view-title {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 4px 0 12px;
}

.view-subtitle {
  color: var(--subtext0);
  font-size: 0.88rem;
  margin: -6px 0 16px;
}

/* ---------- Tab bar ---------- */

.tab-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  background: color-mix(in srgb, var(--mantle) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--surface0);
  z-index: 50;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--overlay1);
  font-size: 0.68rem;
  font-weight: 600;
}

.tab-btn__icon { font-size: 1.25rem; filter: grayscale(1); opacity: 0.7; }

.tab-btn.is-active { color: var(--sapphire); }
.tab-btn.is-active .tab-btn__icon { filter: none; opacity: 1; }

/* ---------- Cards ---------- */

.card {
  background: var(--mantle);
  border: 1px solid var(--surface0);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 10px;
}

.card--pressable { transition: transform 0.08s ease, background 0.15s ease; }
.card--pressable:active { transform: scale(0.98); background: var(--surface0); }

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* ---------- Stop card ---------- */

.stop-card__name { font-weight: 600; font-size: 0.95rem; }
.stop-card__meta { color: var(--overlay1); font-size: 0.78rem; margin-top: 2px; font-family: var(--font-mono); }
.stop-card__lines { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.line-chip {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.72rem;
  background: var(--surface0);
  color: var(--sky);
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--surface1);
}

.star-btn {
  font-size: 1.15rem;
  color: var(--overlay0);
  padding: 4px;
  line-height: 1;
}
.star-btn.is-active { color: var(--yellow); }

/* ---------- Arrivals list ---------- */

.arrival-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--surface0);
}
.arrival-row:last-child { border-bottom: none; }

.arrival-row__line {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.85rem;
  background: var(--blue);
  color: var(--crust);
  min-width: 42px;
  text-align: center;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.arrival-row__dest { flex: 1; min-width: 0; }
.arrival-row__dest-name { font-size: 0.88rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.arrival-row__dest-sub { font-size: 0.74rem; color: var(--overlay1); margin-top: 1px; }

.arrival-row__time {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--green);
  min-width: 44px;
  text-align: right;
  flex-shrink: 0;
}
.arrival-row__time.is-due { color: var(--red); }
.arrival-row__time small { display: block; font-size: 0.6rem; font-weight: 500; color: var(--overlay1); }

/* ---------- Route group (favorites, grouped by line) ---------- */

.route-group__header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 18px 0 8px;
}
.route-group__header:first-child { margin-top: 4px; }
.route-group__badge {
  font-family: var(--font-mono);
  font-weight: 700;
  background: var(--mauve);
  color: var(--crust);
  padding: 3px 9px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}
.route-group__stop { font-size: 0.8rem; color: var(--subtext0); }

/* ---------- Search / inputs ---------- */

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--mantle);
  border: 1px solid var(--surface1);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin-bottom: 14px;
}
.search-field input {
  flex: 1;
  background: none;
  border: none;
  font-size: 0.92rem;
  outline: none;
}
.search-field input::placeholder { color: var(--overlay0); }

.field-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--subtext0);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
  display: block;
}

.text-input, .select-input {
  width: 100%;
  background: var(--mantle);
  border: 1px solid var(--surface1);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font-size: 0.92rem;
  margin-bottom: 14px;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  width: 100%;
}
.btn--primary { background: var(--mauve); color: var(--crust); }
.btn--primary:active { background: var(--pink); }
.btn--ghost { background: var(--surface0); color: var(--text); }
.btn--ghost:active { background: var(--surface1); }
.btn--danger { color: var(--red); background: transparent; border: 1px solid var(--surface1); }
.btn--sm { padding: 8px 12px; font-size: 0.8rem; width: auto; }

/* ---------- Empty / loading / error states ---------- */

.empty-state, .loading-state, .error-state {
  text-align: center;
  padding: 44px 18px;
  color: var(--subtext0);
}
.empty-state__icon, .loading-state__icon, .error-state__icon { font-size: 2rem; display: block; margin-bottom: 10px; }
.empty-state__title { font-weight: 600; color: var(--text); margin-bottom: 4px; }
.error-state { color: var(--red); }

.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--surface1);
  border-top-color: var(--sapphire);
  border-radius: 50%;
  margin: 0 auto 10px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, var(--surface0) 25%, var(--surface1) 37%, var(--surface0) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--radius-sm);
  height: 64px;
  margin-bottom: 10px;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ---------- Tabs (Inbound/Outbound) ---------- */

.segment {
  display: flex;
  background: var(--surface0);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin: 12px 0;
}
.segment__btn {
  flex: 1;
  padding: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: 6px;
  color: var(--subtext0);
}
.segment__btn.is-active { background: var(--mauve); color: var(--crust); }

/* ---------- Maps ---------- */

.map {
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface0);
}
.map--inline { height: 240px; margin-bottom: 12px; }
.map--modal { height: 46vh; border-radius: var(--radius-md); }

.map-note {
  font-size: 0.78rem;
  color: var(--overlay1);
  padding: 10px 2px 4px;
  line-height: 1.4;
}

/* Leaflet dark tuning */
.leaflet-container { background: var(--surface0); font-family: var(--font-ui); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--mantle); color: var(--text); }
.leaflet-control-zoom a { background: var(--mantle) !important; color: var(--text) !important; border-color: var(--surface1) !important; }

.bus-marker {
  width: 26px; height: 26px;
  background: var(--peach);
  border: 2px solid var(--crust);
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 0.9rem;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--peach) 30%, transparent);
}

/* ---------- Route stop list ---------- */

.stop-seq { margin-top: 10px; }
.stop-seq__item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  border-left: 2px solid var(--surface1);
  padding-left: 16px;
  margin-left: 6px;
  position: relative;
}
.stop-seq__item::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 50%;
  transform: translateY(-50%);
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--sapphire);
}
.stop-seq__item:first-child::before,
.stop-seq__item:last-child::before { background: var(--green); width: 10px; height: 10px; left: -6px; }
.stop-seq__name { font-size: 0.86rem; }

/* ---------- Itinerary cards (planner) ---------- */

.itinerary-card__route {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.95rem;
}
.itinerary-card__arrow { color: var(--overlay1); }
.itinerary-card__routes { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

.compare-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--surface0);
  margin-bottom: 8px;
}
.compare-row.is-best { border: 1px solid var(--green); background: color-mix(in srgb, var(--green) 12%, var(--surface0)); }
.compare-row__line { font-family: var(--font-mono); font-weight: 700; color: var(--sky); }
.compare-row__total { font-family: var(--font-mono); font-weight: 700; font-size: 1.05rem; }
.compare-row__breakdown { font-size: 0.72rem; color: var(--overlay1); margin-top: 2px; }
.best-badge { font-size: 0.65rem; font-weight: 700; color: var(--green); text-transform: uppercase; letter-spacing: 0.03em; }

/* ---------- Onboarding ---------- */

.onboard-step { animation: fadein 0.2s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.onboard-progress { display: flex; gap: 6px; margin-bottom: 18px; }
.onboard-progress__dot { flex: 1; height: 4px; border-radius: 2px; background: var(--surface1); }
.onboard-progress__dot.is-done { background: var(--mauve); }

/* ---------- Modal (bottom sheet) ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--crust) 65%, transparent);
  display: flex;
  align-items: flex-end;
}
.modal[hidden] { display: none; }
.modal__sheet {
  width: 100%;
  max-height: 88dvh;
  background: var(--base);
  border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(20px + var(--safe-b));
  overflow-y: auto;
  animation: sheet-up 0.22s ease;
  border: 1px solid var(--surface0);
  border-bottom: none;
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0.4; } to { transform: none; opacity: 1; } }
.modal__handle { width: 36px; height: 4px; background: var(--surface1); border-radius: 2px; margin: 6px auto 10px; }
.modal__header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal__header h2 { font-size: 1.05rem; margin: 0; }
.modal__body { padding-bottom: 8px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface1);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.82rem;
  z-index: 120;
  box-shadow: 0 6px 20px rgba(0,0,0,0.35);
}
.toast[hidden] { display: none; }

/* ---------- Utility ---------- */

.flex-between { display: flex; align-items: center; justify-content: space-between; }
.mt-0 { margin-top: 0; }
.text-muted { color: var(--overlay1); }
.hint { font-size: 0.76rem; color: var(--overlay1); margin-top: 4px; }
.divider { height: 1px; background: var(--surface0); margin: 16px 0; }

.geo-btn-row { display: flex; gap: 8px; margin-bottom: 14px; }
.geo-btn-row .btn { width: auto; flex: 1; }

@media (min-width: 640px) {
  .app-main { padding-top: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
