:root {
  --bg: #eef4f9;
  --panel: rgba(245, 250, 255, 0.86);
  --panel-strong: rgba(255, 255, 255, 0.92);
  --panel-soft: rgba(231, 241, 249, 0.84);
  --ink: #122033;
  --muted: #5d7088;
  --line: rgba(29, 53, 87, 0.12);
  --accent: #0f8a7b;
  --accent-strong: #0c5f71;
  --accent-soft: rgba(15, 138, 123, 0.12);
  --warn: #d86b37;
  --live: #12a66a;
  --shadow: 0 26px 80px rgba(23, 41, 71, 0.14);
  --shadow-soft: 0 12px 28px rgba(23, 41, 71, 0.08);
  --radius: 24px;
  --radius-sm: 16px;
  --font-display: "Space Grotesk", "Segoe UI", sans-serif;
  --font-body: "Manrope", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(15, 138, 123, 0.24), transparent 30%),
    radial-gradient(circle at 82% 10%, rgba(76, 145, 255, 0.18), transparent 24%),
    radial-gradient(circle at bottom right, rgba(216, 107, 55, 0.16), transparent 24%),
    linear-gradient(145deg, #f6fbff, var(--bg));
}

.map-panel {
  background: transparent;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 440px) minmax(0, 1fr);
  gap: 0;
  width: 100vw;
  height: 100vh;
  padding: 0;
  overflow: hidden;
  align-items: stretch;
  align-content: stretch;
}

.app-shell.is-panel-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.panel,
.map-panel {
  min-height: 0;
  border-radius: 0;
  overflow: hidden;
  box-shadow: none;
  height: 100%;
}

/*
 * W aplikacji z Play mapa sięga pod przezroczysty pasek statusu Androida. Wysokość paska podaje
 * powłoka natywna (--safe-top, ustawiane w app.js); w przeglądarce zmienna jest pusta i nic się nie zmienia.
 */
.map-panel .maplibregl-ctrl-top-left,
.map-panel .maplibregl-ctrl-top-right {
  top: var(--safe-top, 0px);
}

.map-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: var(--safe-top, 0px);
  background: linear-gradient(rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0.35));
  pointer-events: none;
  z-index: 2400;
}

[data-theme="dark"] .map-panel::before {
  background: linear-gradient(rgba(10, 16, 26, 0.7), rgba(10, 16, 26, 0.35));
}

.map-panel {
  display: flex;
  flex-direction: column;
}

.maplibregl-map,
.maplibregl-canvas {
  border-radius: 0;
  width: 100%;
  height: 100%;
}

.maplibregl-ctrl-bottom-right {
  inset: auto 8px 8px auto;
}

.map-credit {
  position: absolute;
  right: 6px;
  bottom: 4px;
  padding: 1px 6px;
  border: 0;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.6);
  color: #3b4a5c;
  font: 500 0.64rem/1.4 var(--font-body);
  cursor: pointer;
  z-index: 2300;
}

[data-theme="dark"] .map-credit {
  background: rgba(15, 22, 32, 0.55);
  color: #c4cfdc;
}

.meta-strip .meta-hidden {
  display: none !important;
}

/* Tekst pogody to span wewnątrz plakietki — bez tego dziedziczył jej ramkę i tło (ramka w ramce). */
.meta-strip .weather-details {
  display: block;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  font-size: 0.74rem;
  opacity: 0.85;
}

.meta-strip .weather-main {
  display: block;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: inherit;
}

.about-dialog {
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 22px 22px 18px;
  border: 0;
  border-radius: var(--radius-sm);
  background: #f7fbff;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.about-dialog::backdrop {
  background: rgba(12, 22, 36, 0.4);
}

.about-close-form {
  position: absolute;
  top: 8px;
  right: 8px;
  margin: 0;
}

.about-close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.about-dialog h2 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  color: var(--accent);
  letter-spacing: 0.08em;
}

.about-lead,
.about-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.about-author {
  margin: 14px 0;
  font-size: 0.92rem;
}

.about-sources {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 0 0 14px;
  font-size: 0.82rem;
}

.about-sources dt {
  color: var(--muted);
}

.about-sources dd {
  margin: 0;
}

.about-links {
  margin: 0 0 12px;
  font-size: 0.85rem;
}

.about-links a {
  color: var(--accent-strong);
  font-weight: 700;
}

.about-subtitle {
  margin: 0 0 6px;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}

.about-legend {
  display: grid;
  gap: 4px;
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
  font-size: 0.82rem;
}

.about-legend li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.about-dot {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(29, 53, 87, 0.18);
}

.panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border: 0;
  backdrop-filter: blur(24px);
  transition:
    transform 0.24s ease,
    opacity 0.24s ease;
}

.panel::-webkit-scrollbar {
  width: 10px;
}

.panel::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(93, 112, 136, 0.26);
}

.app-shell.is-panel-collapsed .panel {
  transform: translateX(calc(-100% - 24px));
  opacity: 0;
  pointer-events: none;
}

.panel-header,
.search-form,
.meta-strip,
.results-panel {
  padding-inline: 22px;
}

.panel-header {
  padding-top: 26px;
}

.panel-collapse-button {
  margin-top: 14px;
  align-self: flex-start;
  border: 1px solid rgba(47, 126, 248, 0.25);
  border-radius: 999px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.75);
  color: var(--text);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  display: none;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 0.92rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}

.eyebrow-button {
  display: inline-flex;
  align-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.eyebrow-button:hover,
.eyebrow-button:focus-visible {
  color: var(--accent-strong);
}

h1,
h2 {
  font-family: var(--font-display);
  letter-spacing: -0.03em;
}

h1 {
  margin: 0;
  font-size: clamp(2.1rem, 3vw, 2.8rem);
  line-height: 0.92;
}

.lede {
  margin: 14px 0 0;
  color: var(--muted);
  line-height: 1.55;
  max-width: 30ch;
}

.search-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 20px;
}

.field-group {
  position: relative;
}

.field-header,
.center-row,
.route-card-top,
.results-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
}

.field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

/* „Wybierz na mapie”: miękki chip z pinezką; podświetlony, gdy czeka na kliknięcie w mapę. */
.map-pick-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 9px;
  border: 0;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition:
    background 0.18s ease,
    color 0.18s ease,
    box-shadow 0.18s ease;
}

.map-pick-chip:hover {
  background: rgba(15, 138, 123, 0.2);
}

.map-pick-chip.is-active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 4px rgba(15, 138, 123, 0.18);
}

.map-pick-icon {
  width: 15px;
  height: 15px;
  fill: currentColor;
  flex-shrink: 0;
}

.field-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-start;
  margin-left: 4px;
}


.input-action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px;
  gap: 8px;
  align-items: stretch;
}

.location-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  padding: 0;
  border-radius: 18px;
}

.location-icon {
  width: 22px;
  height: 22px;
  display: block;
}

label,
.stacked span {
  font-size: 0.92rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  background: var(--panel-strong);
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
  transition:
    border-color 0.18s ease,
    transform 0.18s ease,
    box-shadow 0.18s ease;
}

input:focus,
select:focus {
  outline: none;
  border-color: rgba(15, 138, 123, 0.4);
  box-shadow:
    0 0 0 4px rgba(15, 138, 123, 0.12),
    var(--shadow-soft);
  transform: translateY(-1px);
}

.suggestions {
  position: absolute;
  z-index: 800;
  inset-inline: 0;
  top: calc(100% + 6px);
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(249, 252, 255, 0.98);
  box-shadow: 0 20px 40px rgba(23, 41, 71, 0.14);
  overflow: hidden;
}

.suggestion-button {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  border: 0;
  border-bottom: 1px solid rgba(31, 42, 36, 0.08);
  background: transparent;
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
}

.suggestion-button:last-child {
  border-bottom: 0;
}

.suggestion-button:hover,
.suggestion-button:focus-visible {
  background: var(--accent-soft);
  outline: none;
}

.suggestion-button.is-current-location {
  background: rgba(232, 241, 255, 0.9);
}

/* Jedna linia: etykieta ucinana wielokropkiem, znacznik (np. „Przystanek 01”) po prawej. */
.suggestion-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.suggestion-meta {
  flex: 0 0 auto;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
}

.form-row.center-row {
  justify-content: space-between;
}

.map-state {
  color: var(--muted);
  font-size: 0.84rem;
}

.map-state:empty {
  display: none;
}

/* Kolumny w rem: pola układają się w tyle kolumn, ile się mieści (na wąskim panelu 2 + 1),
   więc wartości i etykiety nie są ucinane ani zawijane — także przy większej czcionce. */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  align-items: end;
  gap: 0.75rem;
}

.stacked {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

/* Przesiadki w osobnym wierszu na całą szerokość — bez „sierotki” w połowie rzędu. */
.form-grid .stacked:nth-child(3) {
  grid-column: 1 / -1;
}

.stacked input,
.stacked select {
  min-width: 0;
  min-height: 3rem;
  height: auto;
}

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button,
.swap-button,
.panel-toggle-button {
  border-radius: 999px;
  padding: 13px 18px;
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    background 0.18s ease,
    border-color 0.18s ease;
}

.primary-button:hover,
.ghost-button:hover,
.swap-button:hover,
.route-card-button:hover {
  transform: translateY(-1px);
}

.primary-button {
  background: linear-gradient(135deg, #2f7ef8, #1f5fcf);
  color: white;
  box-shadow: 0 14px 30px rgba(47, 126, 248, 0.24);
}

.ghost-button,
.swap-button,
.panel-toggle-button {
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  border-color: rgba(29, 53, 87, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}


.swap-button {
  flex: 1 1 auto;
  width: 100%;
  padding: 10px 12px;
  font-size: 0.82rem;
}

.mode-toggle {
  display: flex;
  width: 100%;
  box-sizing: border-box;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(29, 53, 87, 0.06);
  border: 1px solid rgba(29, 53, 87, 0.08);
}

.mode-button {
  flex: 1 1 0;
  text-align: center;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 8px 14px;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition:
    background 0.18s ease,
    color 0.18s ease,
    box-shadow 0.18s ease;
}

.mode-button:hover {
  color: var(--ink);
}

.mode-button.is-active {
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  border-color: rgba(47, 126, 248, 0.24);
  box-shadow: 0 8px 18px rgba(47, 126, 248, 0.16);
}

.toolbar-checkbox .checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 600;
}

.toolbar-checkbox .checkbox-row input {
  width: auto;
  padding: 0;
  box-shadow: none;
}

[data-theme="dark"] .mode-toggle {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] .mode-button.is-active {
  background: rgba(47, 126, 248, 0.32);
  color: #eaf1ff;
  border-color: rgba(47, 126, 248, 0.4);
}

.ghost-button:hover,
.swap-button:hover {
  background: rgba(255, 255, 255, 0.94);
  border-color: rgba(15, 138, 123, 0.16);
}

.meta-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 14px;
}

.meta-strip span {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.82rem;
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
  border: 1px solid rgba(29, 53, 87, 0.06);
}

#weather-badge {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 100%;
  overflow: hidden;
  border-radius: 14px;
  padding: 10px 14px;
  gap: 4px;
}

.weather-main {
  overflow: hidden;
  font-size: 0.85rem;
  font-weight: 800;
  white-space: nowrap;
  text-overflow: ellipsis;
  line-height: 1.2;
}


.results-panel {
  display: flex;
  flex-direction: column;
  padding-top: 18px;
  padding-bottom: 22px;
}

.results-header {
  align-items: flex-start;
}

.results-header.is-stop-mode {
  flex-direction: column;
  align-items: stretch;
}

.results-header.is-stop-mode .results-toolbar {
  order: -1;
  justify-content: flex-start;
  width: 100%;
}

.results-header h2 {
  margin: 0;
  font-size: 1.35rem;
}

.results-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.results-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}

.toolbar-field {
  min-width: 180px;
}

.results {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 14px;
}

.route-card {
  margin: 0;
}

.route-card-button,
.departure-card {
  width: 100%;
  border: 1px solid rgba(29, 53, 87, 0.06);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.72);
  padding: 16px;
  text-align: left;
  box-shadow: var(--shadow-soft);
  transition:
    border-color 0.18s ease,
    background 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.18s ease;
}

.route-card-button {
  cursor: pointer;
}

.departure-card.is-clickable {
  cursor: pointer;
}

.departure-card.is-loading,
.stop-popup-departure.is-loading {
  opacity: 0.72;
  cursor: wait;
}

.route-card.is-active .route-card-button {
  border-color: rgba(47, 126, 248, 0.28);
  background: rgba(245, 249, 255, 0.98);
  box-shadow: 0 18px 38px rgba(47, 126, 248, 0.14);
}

.route-duration,
.departure-time {
  margin: 0;
  font-weight: 800;
  font-size: 1.1rem;
  color: #1f5fcf;
}

.route-times,
.route-metrics,
.departure-meta,
.departure-note {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.route-steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.step-chip {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(245, 249, 255, 0.96);
  border: 1px solid rgba(47, 126, 248, 0.08);
}

.step-chip.transit {
  background: rgba(232, 241, 255, 0.96);
  border-color: rgba(47, 126, 248, 0.16);
}

.step-chip {
  transition: border-color 0.3s ease, background 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease;
}

.step-chip.is-current-step {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.08);
  box-shadow: 0 0 0 1px #10b981, inset 0 0 12px rgba(16, 185, 129, 0.1);
  transform: scale(1.02);
}

.step-chip.is-current-step .step-badge {
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulse-green 2s infinite;
  background: #10b981 !important;
}

.step-badge {
  min-width: 46px;
  border-radius: 999px;
  padding: 6px 10px;
  text-align: center;
  font-weight: 800;
  background: #2f7ef8;
  color: white;
}

.step-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--ink);
}

.step-meta {
  color: var(--muted);
  font-size: 0.84rem;
}

.line-badges,
.departure-top {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.line-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 800;
  color: white;
}

/* --- Karta połączenia: nagłówek z plakietką „Najlepsze” i chipem oczekiwania --- */

.route-card-top {
  justify-content: space-between;
  width: 100%;
  align-items: flex-start;
}

.route-card-headline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.route-best-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 10px;
  background: linear-gradient(135deg, #10b981, #0d9488);
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: 0 8px 16px rgba(16, 185, 129, 0.28);
}

.route-best-badge[hidden] {
  display: none;
}

.route-wait {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  margin: 6px 0 0;
  border-radius: 999px;
  padding: 3px 10px;
  background: rgba(47, 126, 248, 0.1);
  color: #1f5fcf;
  font-size: 0.76rem;
  font-weight: 700;
}

.route-wait:empty {
  display: none;
}

.route-card.is-best .route-card-button {
  border-color: rgba(16, 185, 129, 0.45);
  box-shadow: 0 18px 38px rgba(16, 185, 129, 0.16);
}

/* --- Szkielet ładowania wyników --- */

/* Animacja oczekiwania na wyniki: autobus jedzie po „drodze”, pod spodem opis etapu. */
.search-loader {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 18px 16px 6px;
}

.search-loader-track {
  position: relative;
  width: min(260px, 80%);
  height: 34px;
  overflow: hidden;
}

.search-loader-road {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 6px;
  height: 4px;
  border-radius: 999px;
  background: repeating-linear-gradient(90deg, var(--accent) 0 14px, transparent 14px 26px);
  opacity: 0.35;
  animation: search-loader-road 0.9s linear infinite;
}

.search-loader-bus {
  position: absolute;
  bottom: 6px;
  left: 50%;
  width: 30px;
  height: 30px;
  transform: translateX(-50%);
  animation: search-loader-bounce 0.9s ease-in-out infinite;
}

.search-loader-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 600;
  text-align: center;
  min-height: 1.2em;
}

@keyframes search-loader-road {
  from { background-position: 0 0; }
  to { background-position: -26px 0; }
}

@keyframes search-loader-bounce {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-2px); }
}

@media (prefers-reduced-motion: reduce) {
  .search-loader-road,
  .search-loader-bus {
    animation: none;
  }
}

.route-skeleton {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid rgba(29, 53, 87, 0.06);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.72);
  padding: 16px;
  box-shadow: var(--shadow-soft);
}

.route-skeleton-line {
  height: 14px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    rgba(203, 218, 235, 0.55) 25%,
    rgba(226, 236, 247, 0.9) 37%,
    rgba(203, 218, 235, 0.55) 63%
  );
  background-size: 400% 100%;
  animation: route-skeleton-shimmer 1.4s ease-in-out infinite;
}

.route-skeleton-line.wide {
  width: 55%;
  height: 20px;
}

.route-skeleton-line.short {
  width: 32%;
}

@keyframes route-skeleton-shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}

.departure-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.departure-headline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.departure-offset {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  max-width: 120px;
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(228, 238, 247, 0.9);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
}

/* Odjazd „na już” (<= 5 min) delikatnie pulsuje, żeby nie przegapić autobusu. */
.departure-card.is-soon .departure-offset {
  background: rgba(16, 185, 129, 0.16);
  color: #0d6b4d;
  animation: departure-soon-pulse 1.8s ease-in-out infinite;
}

@keyframes departure-soon-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.34);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
  }
}

.empty-state {
  border-radius: 22px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  border: 1px solid rgba(29, 53, 87, 0.06);
  box-shadow: var(--shadow-soft);
}

.map-panel {
  position: relative;
  height: 100%;
  background: transparent;
  border: 0;
}

.panel-toggle-button {
  position: absolute;
  left: 18px;
  bottom: 18px;
  transform: none;
  z-index: 1200;
  min-width: 168px;
  background: rgba(12, 32, 51, 0.82);
  color: white;
  border-color: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(14px);
  box-shadow: 0 16px 32px rgba(12, 32, 51, 0.28);
}

.maplibregl-ctrl-group .map-gps-button {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  background: rgba(255, 255, 255, 0.96);
  color: #1f5fcf;
  cursor: pointer;
}

.map-gps-button .location-icon {
  width: 20px;
  height: 20px;
}

.map-gps-button:hover {
  background: rgba(240, 246, 255, 1);
}

.map-gps-button:disabled {
  opacity: 0.72;
  cursor: wait;
}

.panel-toggle-button:hover {
  transform: translateY(-1px);
  background: rgba(12, 32, 51, 0.92);
}

#map {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
}

.maplibregl-map {
  font-family: var(--font-body);
  background: #dce8f0;
}

.maplibregl-canvas {
  outline: none;
}

.current-location-marker {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.82;
  filter: drop-shadow(0 3px 8px rgba(31, 95, 207, 0.18));
}

.current-location-icon {
  width: 18px;
  height: 18px;
  display: block;
}

.maplibregl-popup-content {
  border-radius: 18px;
  box-shadow: 0 16px 34px rgba(23, 41, 71, 0.16);
  padding: 14px 16px;
}

.maplibregl-popup-close-button {
  color: var(--muted);
  padding: 8px 10px 0 0;
}

.maplibregl-popup-tip {
  border-top-color: rgba(255, 255, 255, 0.96);
}

.maplibregl-ctrl-group {
  border: 0;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 14px 30px rgba(23, 41, 71, 0.16);
}

.maplibregl-ctrl-group button {
  width: 38px;
  height: 38px;
}


.maplibregl-ctrl-logo {
  display: none !important;
}


.map-pin-label {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 80px;
  gap: 4px;
}

.map-pin-dot {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid white;
  box-shadow: 0 8px 18px rgba(23, 41, 71, 0.22);
  background: #2f7ef8;
}

.map-pin-text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 68px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(245, 249, 255, 0.94);
  border: 1px solid rgba(47, 126, 248, 0.18);
  color: #1f5fcf;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.2;
  box-shadow: 0 8px 16px rgba(23, 41, 71, 0.12);
}

/* Skala zależna od zoomu (--live-scale ustawiane w setupMap): pomniejszamy też obszar dotyku. */
.live-vehicle-marker-shell {
  position: absolute;
  left: 50%;
  top: 50%;
  display: block;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%) scale(var(--live-scale, 1));
  transform-origin: center center;
}

/* Autobusy na żywo zawsze nad przystankami i znacznikami trasy, ale pod dymkami. */
.maplibregl-marker.live-vehicle-marker {
  z-index: 3;
}

.maplibregl-popup {
  z-index: 5;
}

.live-vehicle-marker {
  width: calc(44px * var(--live-scale, 1));
  height: calc(44px * var(--live-scale, 1));
  will-change: transform;
  transform-origin: center center;
  backface-visibility: hidden;
}

.live-vehicle-bus {
  width: 44px;
  height: 44px;
  display: block;
  filter: drop-shadow(0 10px 18px rgba(13, 107, 77, 0.22));
}

.live-vehicle-line {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.1;
  text-align: center;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

/*
 * Numer linii trafia dokładnie w środek szyby autobusu: okno w `bus-live.svg`
 * zajmuje w pionie ~y=14..34 z viewBoxu 64, czyli środek na 37,5% wysokości
 * markera (44px). Wcześniej stał wyżej (top: 8px) i „uciekał” z okna.
 */
.live-vehicle-line-in-window {
  top: 37.5%;
  left: 50%;
  min-width: 18px;
  padding: 0 2px;
  transform: translate(-50%, -50%);
  color: #0d6b4d;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.9);
}

.stop-popup {
  min-width: 220px;
}

.stop-popup-header {
  margin-bottom: 10px;
  color: var(--ink);
}

.stop-popup-header small,
.stop-popup-empty {
  color: var(--muted);
}

.stop-popup-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* Przy „całym dniu” lista ma kilkadziesiąt kursów — przewija się w popupie, zamiast wychodzić poza mapę. */
  max-height: min(520px, calc(100dvh - 260px));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
}

.stop-popup-departure {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(29, 53, 87, 0.08);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.9);
  cursor: pointer;
  text-align: left;
}

.stop-popup-departure:hover {
  background: rgba(240, 248, 252, 1);
  border-color: rgba(15, 138, 123, 0.22);
}

.stop-popup-line {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border-radius: 999px;
  color: white;
  font-weight: 800;
}

.stop-popup-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stop-popup-text small {
  color: var(--muted);
}

.preview-stop-tooltip {
  border: 0;
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(47, 126, 248, 0.92);
  color: white;
  font-weight: 700;
  font-size: 0.76rem;
  box-shadow: 0 10px 24px rgba(47, 126, 248, 0.22);
}

.preview-stop-tooltip::before {
  display: none;
}

.preview-stop-marker {
  position: relative;
  width: 0;
  height: 0;
  pointer-events: none;
}

.preview-stop-marker-dot {
  position: absolute;
  left: 0;
  top: 0;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 4px solid #2f7ef8;
  background: #ffffff;
  box-shadow: 0 10px 22px rgba(47, 126, 248, 0.22);
  transform: translate(-50%, -50%);
}

.preview-stop-marker-label {
  position: absolute;
  left: 14px;
  top: 0;
  transform: translateY(-50%);
  border: 0;
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(47, 126, 248, 0.92);
  color: white;
  font-weight: 700;
  font-size: 0.76rem;
  line-height: 1;
  white-space: nowrap;
  box-shadow: 0 10px 24px rgba(47, 126, 248, 0.22);
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 10px;
    gap: 10px;
  }

  .map-panel {
    height: calc(100vh - 20px);
  }

  .panel {
    position: absolute;
    inset: 10px auto 10px 10px;
    width: min(420px, calc(100vw - 20px));
    height: auto;
    z-index: 1300;
  }

  .app-shell.is-panel-collapsed .panel {
    transform: translateX(calc(-100% - 18px));
  }
}

@media (pointer: coarse), (hover: none) {
  /* Mapa na telefonie ma ~58% wysokości, a popup otwiera się pod przystankiem — niższa lista mieści się w mapie. */
  /* Mapa zajmuje ~58% ekranu; lista wypełnia ją, zostawiając miejsce na nagłówek okienka. */
  .stop-popup-list {
    max-height: max(22vh, min(440px, calc(58dvh - 190px)));
  }

  .field-header {
    gap: 6px;
  }

  .field-actions {
    margin-left: 0;
  }

  .panel,
  .map-panel {
    box-shadow: none;
  }

  .map-panel .maplibregl-canvas,
  .map-panel .maplibregl-map {
    border-radius: 0;
  }
  .app-shell {
    grid-template-columns: 1fr;
    /* 100dvh to faktycznie widoczna wysokość (bez pasków przeglądarki), więc mapa i panel
       wypełniają cały ekran — wcześniej rezerwowany pusty pasek 5vh zostawał na dole. */
    grid-template-rows: minmax(0, 58fr) minmax(0, 42fr);
    height: 100vh;
    height: 100dvh;
    padding: 0;
    gap: 0;
  }

  .map-panel {
    order: 0;
    grid-row: 1;
    border-radius: 0;
    margin: 0;
  }

  .map-panel {
    height: auto;
    min-height: 0;
  }

  .panel {
    position: relative;
    grid-row: 2;
    inset: auto;
    width: auto;
    height: auto;
    max-height: none;
    min-height: 0;
    /* W aplikacji z Play panel sięga pod pasek nawigacji — ostatnie elementy muszą być nad nim. */
    padding-bottom: var(--safe-bottom, 0px);
    border-radius: 0;
    margin: 0;
    z-index: 2100;
  }

  .app-shell.is-panel-collapsed .panel {
    transform: translateY(calc(100% + 24px));
    height: 0;
    max-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
  }

  .panel-header,
  .search-form,
  .meta-strip,
  .results-panel {
    padding-inline: 16px;
  }

  .meta-strip {
    gap: 10px;
  }

  .meta-strip span {
    font-size: 0.88rem;
    padding: 10px 14px;
  }

  #weather-badge {
    width: 100%;
  }

  .weather-main {
    font-size: 0.95rem;
  }


  /* Kolumny liczone w rem: przy większej czcionce systemowej pola same zawijają się do
     jednej kolumny zamiast ucinać wartości. Wysokość pól rośnie z tekstem (min-height). */
  .form-grid {
    grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
    gap: 0.75rem;
  }

  .stacked {
    min-width: 0;
  }

  .stacked span {
    font-size: 0.85rem;
    line-height: 1.25;
  }

  .stacked input,
  .stacked select {
    min-width: 0;
    min-height: 3rem;
    height: auto;
    padding: 0.6rem 0.9rem;
    line-height: 1.35;
    font-size: 1rem;
  }

  .mode-button {
    padding: 0.55rem 0.8rem;
    line-height: 1.25;
    font-size: 0.9rem;
  }

  .field-header,
  .center-row,
  .route-card-top,
  .results-header,
  .departure-headline {
    align-items: flex-start;
    flex-direction: column;
  }

  .field-header {
    flex-direction: row;
    align-items: center;
  }

  .field-actions {
    gap: 6px;
  }

  .actions,
  .results-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-field {
    min-width: 0;
    width: 100%;
  }

  .panel-toggle-button {
    right: auto;
    left: 12px;
    top: auto;
    bottom: max(12px, calc(env(safe-area-inset-bottom, 0px) + 12px));
    width: 36px;
    height: 36px;
    min-width: 0;
    border-radius: 999px;
    padding: 0;
    font-size: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3200;
    opacity: 1;
    visibility: visible;
  }

  .panel-collapse-button {
    display: none;
  }

  .panel-toggle-button::before {
    content: "▾";
    font-size: 18px;
    color: white;
  }

  .app-shell.is-panel-collapsed {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) 0;
  }

  .app-shell.is-panel-collapsed .panel {
    transform: translateY(100%);
    pointer-events: none;
    display: none;
  }

  .app-shell.is-panel-collapsed .map-panel {
    grid-row: 1;
    height: 100%;
  }

  .app-shell.is-panel-collapsed .panel-toggle-button {
    top: auto;
    bottom: calc(12px + var(--safe-bottom, 0px));
  }

  /* Po zwinięciu panelu mapa sięga pod pasek nawigacji Androida — podpis mapy nad nim. */
  .app-shell.is-panel-collapsed .map-credit {
    bottom: calc(4px + var(--safe-bottom, 0px));
  }

  .app-shell.is-panel-collapsed .panel-toggle-button::before {
    content: "▴";
  }

  /* Wpisywanie adresu: klawiatura zabiera dół ekranu, więc panel zajmuje całą wysokość,
     a mapa chowa się do czasu wyboru adresu. */
  .app-shell.is-typing {
    grid-template-rows: 0 minmax(0, 1fr);
  }

  .app-shell.is-typing .map-panel {
    visibility: hidden;
  }

  .app-shell.is-typing .panel-toggle-button {
    display: none;
  }

  /* Zapas pod listą podpowiedzi, żeby pole dało się przewinąć na samą górę panelu. */
  .app-shell.is-typing .search-form {
    padding-bottom: 60vh;
  }
}

/* Baner aktualizacji aplikacji (Google Play In-App Updates) */
.update-banner {
  position: fixed;
  /* Nad panelem formularza (2100) i paskiem statusu (2400), u góry — nie zasłania przycisków panelu. */
  z-index: 3100;
  left: 12px;
  right: 12px;
  top: calc(12px + var(--safe-top, 0px));
  max-width: 460px;
  margin-inline: auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-radius: 20px;
  background: var(--panel-strong);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: 0 18px 44px rgba(23, 41, 71, 0.22);
  backdrop-filter: blur(14px);
  opacity: 0;
  transform: translateY(-16px);
  transition:
    opacity 0.28s ease,
    transform 0.28s ease;
}

.update-banner[hidden] {
  display: none;
}

.update-banner.is-visible {
  opacity: 1;
  transform: none;
}

.update-banner-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.update-banner-icon svg {
  width: 1.4rem;
  height: 1.4rem;
}

.update-banner-body {
  flex: 1 1 10rem;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.update-banner-body strong {
  font-size: 0.98rem;
  line-height: 1.25;
}

.update-banner-body span {
  font-size: 0.84rem;
  line-height: 1.35;
  color: var(--muted);
}

.update-banner-progress {
  margin-top: 0.4rem;
  height: 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  overflow: hidden;
}

.update-banner-progress span {
  display: block;
  height: 100%;
  width: 8%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  transition: width 0.3s ease;
}

.update-banner-progress[hidden] {
  display: none;
}

.update-banner-actions {
  flex: 1 1 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

.update-banner-actions button[hidden] {
  display: none;
}

.update-banner-primary,
.update-banner-later {
  flex: 0 1 auto;
  max-width: 100%;
  min-height: 2.5rem;
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
}

.update-banner-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
}

.update-banner-later {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}

[data-theme="dark"] .update-banner {
  background: #232a33;
  color: #f0f0f0;
  border-color: #333;
}

[data-theme="dark"] .update-banner-body span,
[data-theme="dark"] .update-banner-later {
  color: #b6c2d1;
}

@media (prefers-reduced-motion: reduce) {
  .update-banner {
    transition: none;
  }
}

/* Pasek bez znanego postępu: przesuwający się odcinek zamiast stojącego paska. */
.update-banner-progress.is-indeterminate span {
  width: 35%;
  animation: update-banner-slide 1.3s ease-in-out infinite;
}

@keyframes update-banner-slide {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(290%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .update-banner-progress.is-indeterminate span {
    animation: none;
    width: 60%;
  }
}
