:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #14171c;
  --muted: #6b7280;
  --line: #e3e6ec;
  --accent: #009ee3;
  --accent-dark: #0079ad;
  --late: #d92d20;
  --live: #067647;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html {
  /* iOS Safari: fekvő tájolásnál ne nagyítsa fel a szöveget. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  -webkit-tap-highlight-color: rgba(0, 158, 227, 0.15);
  background:
    radial-gradient(1100px 420px at 50% -180px, #d9f1fb 0%, transparent 70%),
    var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  line-height: 1.45;
}

main {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  /* A biztonsági sávok (iPhone notch, home indicator) miatt max()/env(). */
  padding: calc(40px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    calc(64px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

/* Érintéssel vezérelt eszközön ne legyen dupla koppintásos nagyítás. */
button,
input {
  touch-action: manipulation;
}

.hero h1 {
  margin: 0;
  font-size: clamp(30px, 6vw, 44px);
  letter-spacing: -0.02em;
}

.hero h1 span {
  color: var(--accent);
}

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

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 12px 30px -24px rgba(16, 24, 40, 0.6);
}

.places {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: end;
}

.field {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > span {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.field input {
  width: 100%;
  min-height: 46px;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px; /* iOS: 16 px alatt a fókuszáláskor automatikusan ránagyít. */
  color: inherit;
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 10px;
  appearance: none;
  -webkit-appearance: none;
}

.field input:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.swap {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 18px;
  cursor: pointer;
}

.swap:hover {
  background: #f0f7fb;
  border-color: var(--accent);
}

.suggestions {
  position: absolute;
  z-index: 10;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: min(260px, 45dvh);
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 18px 40px -20px rgba(16, 24, 40, 0.45);
}

.suggestion {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  font: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

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

.suggestion:hover {
  background: #f0f7fb;
}

/* ---------- gyorsgombok ---------- */

.quick {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.quick-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quick-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 4px 2px 10px;
  background: #eef7fc;
  border: 1px solid #cfe8f6;
  border-radius: 999px;
}

.quick-go {
  padding: 4px 2px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-dark);
  background: none;
  border: 0;
  cursor: pointer;
}

.quick-go:hover {
  text-decoration: underline;
}

.quick-icon {
  width: 22px;
  height: 22px;
  font-size: 12px;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.quick-icon:hover {
  color: var(--ink);
  background: #dcecf5;
}

.quick-new {
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-dark);
  background: none;
  border: 1px dashed #b9d9ea;
  border-radius: 999px;
  cursor: pointer;
}

.quick-new:hover {
  background: #eef7fc;
  border-color: var(--accent);
}

.quick-editor {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding: 12px;
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.quick-editor[hidden] {
  display: none;
}

.quick-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

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

.quick-save {
  padding: 8px 16px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 9px;
  cursor: pointer;
}

.quick-save:hover {
  background: var(--accent-dark);
}

.quick-cancel {
  padding: 8px 14px;
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
}

.quick-error {
  color: var(--late);
  font-size: 13px;
}

.quick-error[hidden] {
  display: none;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

.radio {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}

.check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.actions #time {
  width: 6.5rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  padding: 9px 10px;
  font: inherit;
  font-size: 16px; /* iOS: fókuszáláskor ne nagyítson rá a mezőre. */
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfcfd;
  appearance: none;
  -webkit-appearance: none;
}

.actions #time.is-idle {
  cursor: text;
  opacity: 0.45;
}

.go {
  margin-left: auto;
  padding: 12px 26px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}

.go:hover {
  background: var(--accent-dark);
}

.status {
  margin: 18px 2px 10px;
  color: var(--muted);
  font-size: 14px;
}

.results {
  display: grid;
  /* minmax(0, 1fr): a kártya ne tudja a saját min-content szélességére feszíteni az oldalt. */
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

.card {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: #3d4b5c;
  border-radius: 7px;
}

.summary {
  display: flex;
  flex-direction: column;
  margin-left: auto;
  text-align: right;
}

.summary strong {
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

.summary small,
.destinations {
  color: var(--muted);
  font-size: 13px;
}

.destinations {
  margin: 10px 0 2px;
}

.legs {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.leg {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.leg-main {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
}

.leg-main small {
  color: var(--muted);
  font-size: 12px;
}

.leg-times {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 6px;
  font-variant-numeric: tabular-nums;
}

.leg-times strong {
  font-size: 15px;
}

.leg-place {
  font-weight: 600;
}

.leg-arrow {
  color: var(--muted);
}

.leg-via,
.leg-next {
  color: var(--muted);
  font-size: 12px;
}

/* A jelző és a két gomb egy csoportja (mobilon külön sorba kerül). */
.leg-actions {
  display: flex;
  flex: 0 0 auto;
  align-self: center;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.leg-map {
  flex: 0 0 auto;
  align-self: center;
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
}

.leg-map:hover {
  border-color: #009ee3;
}

.leg-pin {
  flex: 0 0 auto;
  align-self: center;
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  filter: grayscale(1);
  opacity: 0.7;
}

.leg-pin:hover,
.leg-pin[aria-pressed='true'] {
  filter: none;
  opacity: 1;
  border-color: #009ee3;
}

/* Szakasz-diagram: melyik két megálló között jár éppen a jármű. */
.leg-segment {
  display: flex;
  width: fit-content;
  max-width: min(340px, 100%);
  align-items: center;
  gap: 5px;
  margin-top: 5px;
  padding: 2px 8px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--muted);
  background: #f5fafd;
  border: 1px solid #e2eef6;
  border-radius: 999px;
}

.leg-segment[hidden] {
  display: none;
}

.leg-segment .seg-stop {
  flex: 0 1 auto;
  max-width: 44%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A vonal szélessége a kijelzőhöz igazodik, így mobilon is marad hely a megállóneveknek. */
.leg-segment .seg-track {
  position: relative;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: clamp(64px, 22vw, 108px);
  height: 15px;
}

.leg-segment .seg-track::before {
  content: '';
  position: absolute;
  left: 2px;
  right: 2px;
  top: 50%;
  border-top: 2px dotted #bcd8e8;
  transform: translateY(-1px);
}

/* Végpont-pöttyök a szakasz két végén. */
.leg-segment .seg-track::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 2px 50%, #7fb2cd 2px, transparent 2.2px),
    radial-gradient(circle at calc(100% - 2px) 50%, #7fb2cd 2px, transparent 2.2px);
}

.leg-segment .seg-badge,
.leg-segment .seg-vehicle {
  position: relative;
  z-index: 1;
}

.leg-segment .seg-badge {
  padding: 0 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2px;
  border-radius: 999px;
  box-shadow: 0 0 0 2px #f5fafd;
}

.leg-segment .seg-vehicle {
  padding: 0 2px;
  font-size: 11px;
  line-height: 1;
  background: #f5fafd;
  border-radius: 3px;
  box-shadow: 0 0 0 2px #f5fafd;
}

.vehicle-map {
  margin: 0;
  display: grid;
  gap: 10px;
}

.vehicle-map-frame {
  width: 100%;
  height: min(60vh, 420px);
  height: min(60dvh, 420px);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.vehicle-caption {
  display: grid;
  gap: 2px;
}

.vehicle-map-link {
  color: #0072a8;
  font-size: 13px;
}

.leg-next {
  margin-top: 1px;
}

.leg.walk {
  color: var(--muted);
}

.walk-icon {
  width: 34px;
  text-align: center;
}

.live,
.late {
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  white-space: nowrap;
}

.live {
  color: var(--live);
  background: #e7f6ee;
}

.late {
  color: var(--late);
  background: #fdecea;
}

.board {
  margin-top: 30px;
}

.board h2 {
  margin: 0 0 10px;
  font-size: 17px;
}

.board-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}

.departure {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-width: 0;
  padding: 8px 6px;
  font: inherit;
  color: inherit;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.departure:hover {
  background: #f0f7fb;
}

.departure:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

.departure:last-child {
  border-bottom: 0;
}

.departure-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.departure-main strong {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.departure-main small {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.departure-time {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  white-space: nowrap;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.muted {
  margin: 6px;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- indulás részletei (modal) ---------- */

body.modal-open {
  overflow: hidden;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 24, 40, 0.45);
}

.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100vh - 40px);
  /* iOS Safari: a dinamikus eszköztár miatt 100dvh a valódi látható magasság. */
  max-height: calc(100dvh - 40px);
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 30px 60px -30px rgba(16, 24, 40, 0.7);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.modal-title {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.modal-close {
  flex: none;
  margin-left: auto;
  width: 32px;
  height: 32px;
  font: inherit;
  color: var(--muted);
  background: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--ink);
  border-color: var(--accent);
}

/* A modál kártyája maga a keret, ezért a benne lévő útvonal-kártya keret nélküli. */
.modal-body .card {
  padding: 0;
  border: 0;
}

/* Kitűzött térkép: a jobb alsó sarokban marad, az oldalt nem blokkolja. */
.modal.is-pinned {
  inset: auto 16px 16px auto;
  display: block;
  padding: 0;
}

.modal.is-pinned .modal-backdrop {
  display: none;
}

.modal.is-pinned .modal-card {
  width: min(380px, calc(100vw - 24px));
  max-height: min(70vh, 620px);
  border-color: var(--accent);
  box-shadow: 0 16px 40px -16px rgba(16, 24, 40, 0.5);
}

.modal.is-pinned .modal-title::before {
  content: '📌 ';
}

/* ---------- mobil (iPhone) ---------- */

@media (max-width: 620px) {
  /* A modál alulról kinyíló lap, így kézre esik és nem lóg ki a kijelzőből. */
  .modal {
    place-items: end stretch;
    padding: 0;
  }

  .modal-card {
    width: 100%;
    max-height: calc(100vh - env(safe-area-inset-top) - 12px);
    max-height: calc(100dvh - env(safe-area-inset-top) - 12px);
    padding: 16px max(16px, env(safe-area-inset-right))
      calc(16px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    border-radius: 18px 18px 0 0;
    border-bottom: 0;
  }

  .modal-close {
    width: 40px;
    height: 40px;
  }

  /* Kitűzött panel: a home indicator fölött maradjon, oldalt biztonsági sávval. */
  .modal.is-pinned {
    inset: auto max(8px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }

  .modal.is-pinned .modal-card {
    max-height: min(70vh, 620px);
    max-height: min(70dvh, 620px);
    border-radius: var(--radius);
  }

  .vehicle-map-frame {
    height: min(52vh, 380px);
    height: min(52dvh, 380px);
  }
}

@media (max-width: 620px) {
  /* Két mező egymás alatt, a csere gomb a jobb szélen a két mező között – így nem foglal külön sort. */
  .places {
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 8px;
  }

  .places > .field:nth-of-type(1) {
    grid-column: 1;
    grid-row: 1;
  }

  .places > .field:nth-of-type(2) {
    grid-column: 1;
    grid-row: 2;
  }

  .swap {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: center;
    justify-self: end;
    width: 40px;
    height: 40px;
  }

  .go {
    margin-left: 0;
    width: 100%;
  }

  .quick-fields {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  main {
    padding-top: calc(24px + env(safe-area-inset-top));
  }

  .hero h1 {
    font-size: clamp(28px, 9vw, 36px);
  }

  .hero p {
    margin-bottom: 18px;
    font-size: 15px;
  }

  .panel {
    padding: 14px;
  }

  .card {
    padding: 14px;
  }

  /* A járatcímkék és az idő ne szoruljon egy sorba. */
  .card-head {
    align-items: flex-start;
    gap: 6px 10px;
  }

  .summary {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 8px;
    width: 100%;
    margin-left: 0;
    text-align: left;
  }

  .summary strong {
    font-size: 16px;
  }

  /* Mobilon a sor rács: bal oldalt a járatjelvény, jobbra a szöveg, alatta a gombok. */
  .leg {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
    column-gap: 10px;
    row-gap: 6px;
  }

  .leg-main {
    grid-column: 2;
  }

  .leg-actions {
    grid-column: 2;
    justify-self: end;
    margin-left: 0;
  }

  /* Nagyobb érintőfelület a 📌 és 🗺 gomboknak. */
  .leg-pin,
  .leg-map {
    width: 38px;
    height: 38px;
  }

  /* Keskeny kijelzőn kevesebb belső margó, hogy a megállónevek ne csonkuljanak. */
  .leg-segment {
    max-width: 100%;
    gap: 4px;
    padding: 2px 6px;
  }

  .quick-go {
    max-width: 58vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .departure {
    gap: 10px;
    padding: 10px 4px;
  }
}
