/* Phone first. The base rules are the iPhone layout (390pt wide); `min-width: 768px`
 * adds the desktop one. Nothing depends on hover, every tap target is ≥44pt, and every
 * typed-into control is ≥16px so Safari never zooms on focus. */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg-sunken);
  color: var(--text);
  font: var(--t-body) / 1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
  /* Room for the fixed tab bar plus the home indicator. */
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--s4));
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

[x-cloak] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* --- Top bar ------------------------------------------------------------ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: env(safe-area-inset-top) max(var(--s4), env(safe-area-inset-right)) 0
    max(var(--s4), env(safe-area-inset-left));
}

.topbar__inner {
  max-width: var(--shell-max);
  margin: 0 auto;
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: var(--s3);
}

.topbar__title {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__back,
.topbar__action {
  min-height: var(--tap);
  min-width: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-weight: 600;
}

/* --- Content column ----------------------------------------------------- */
.shell {
  max-width: var(--shell-max);
  margin: 0 auto;
  padding: var(--s4) max(var(--s4), env(safe-area-inset-right)) 0
    max(var(--s4), env(safe-area-inset-left));
}

.notice {
  margin: 0 0 var(--s3);
  padding: var(--s3) var(--s4);
  border-radius: var(--r);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  overflow-wrap: anywhere;
}

.notice--success {
  background: var(--ok-bg);
  border-color: transparent;
}

.notice--warning,
.notice--info {
  background: var(--warn-bg);
  border-color: transparent;
}

.notice--error {
  background: var(--bad-bg);
  border-color: transparent;
}

.muted {
  color: var(--text-muted);
}

.small {
  font-size: var(--t-small);
}

/* --- Bottom tab bar (iOS style) ----------------------------------------- */
.tabbar {
  position: fixed;
  inset: auto 0 0;
  z-index: 20;
  display: flex;
  justify-content: space-around;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.tabbar a {
  flex: 1;
  max-width: 160px;
  min-height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
}

.tabbar a[aria-current="page"] {
  color: var(--accent);
}

.tabbar svg {
  width: 24px;
  height: 24px;
}

/* --- Filter chips -------------------------------------------------------- */
.chips {
  display: flex;
  gap: var(--s2);
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 calc(-1 * var(--s4)) var(--s3);
  padding: 0 var(--s4) var(--s1);
  -webkit-overflow-scrolling: touch;
}

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

.chip {
  flex: none;
  min-height: 36px;
  padding: 0 var(--s3);
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  border-radius: var(--r-pill);
  border: 1px solid var(--border-strong);
  background: var(--bg-raised);
  color: var(--text);
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
  /* The visible chip is 36pt; this keeps the tap target at 44. */
  position: relative;
}

.chip::after {
  content: "";
  position: absolute;
  inset: -4px 0;
}

.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-on);
}

/* --- Passenger dots (colour + the name is always nearby) ----------------- */
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex: none;
}

.pax-1 { background: var(--pax-1); }
.pax-2 { background: var(--pax-2); }
.pax-3 { background: var(--pax-3); }
.pax-4 { background: var(--pax-4); }
.pax-5 { background: var(--pax-5); }
.pax-6 { background: var(--pax-6); }

/* --- Day groups and flight cards ---------------------------------------- */
.day {
  margin-bottom: var(--s5);
}

.day__header {
  position: sticky;
  top: calc(52px + env(safe-area-inset-top));
  z-index: 5;
  margin: 0 calc(-1 * var(--s4)) var(--s2);
  padding: var(--s2) var(--s4);
  background: var(--bg-sunken);
  font-size: 15px;
  font-weight: 600;
}

.day__header--today {
  color: var(--accent);
}

.card {
  display: block;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s3) var(--s4);
  margin-bottom: var(--s2);
  color: inherit;
  text-decoration: none;
  min-height: 64px;
}

a.card:active {
  background: var(--bg-sunken);
}

.card--past {
  opacity: 0.75;
}

.card__top {
  display: flex;
  align-items: baseline;
  gap: var(--s3);
}

.card__time {
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.card__flight {
  color: var(--text-muted);
  font-size: 15px;
  white-space: nowrap;
}

.card__top .pill {
  margin-left: auto;
}

.card__route {
  margin-top: 2px;
  font-size: 15px;
}

.card__people {
  margin-top: var(--s2);
  display: flex;
  flex-wrap: wrap;
  gap: var(--s1) var(--s3);
  font-size: var(--t-small);
  color: var(--text-muted);
}

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

.empty {
  text-align: center;
  padding: var(--s6) var(--s4);
  color: var(--text-muted);
}

/* --- Status pills: colour + text, always ---------------------------------- */
.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--quiet-bg);
  color: var(--quiet);
}

.pill--scheduled,
.pill--arrived,
.pill--departed {
  background: var(--ok-bg);
  color: var(--ok);
}

.pill--delayed {
  background: var(--warn-bg);
  color: var(--warn);
}

.pill--cancelled,
.pill--diverted {
  background: var(--bad-bg);
  color: var(--bad);
}

/* --- Detail page --------------------------------------------------------- */
.route {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s4);
  margin-bottom: var(--s3);
}

.route__legs {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: var(--s2);
}

.route__end--arr {
  text-align: right;
}

.route__code {
  font-size: var(--t-big);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.route__city {
  color: var(--text-muted);
  font-size: var(--t-small);
}

.route__time {
  font-size: 18px;
  font-weight: 600;
  margin-top: var(--s2);
  font-variant-numeric: tabular-nums;
}

.route__was {
  text-decoration: line-through;
  color: var(--text-faint);
  font-size: var(--t-small);
}

.route__plane {
  color: var(--text-faint);
  padding-top: 10px;
}

.facts {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  margin: 0 0 var(--s3);
  padding: 0;
  list-style: none;
}

.facts li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s3);
  min-height: var(--tap);
  padding: var(--s2) var(--s4);
  border-bottom: 1px solid var(--border);
}

.facts li:last-child {
  border-bottom: 0;
}

.facts .label {
  color: var(--text-muted);
}

.facts .value {
  text-align: right;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.mono {
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

.section-title {
  margin: var(--s5) 0 var(--s2);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.warning-list {
  margin: 0 0 var(--s3);
  padding: var(--s3) var(--s4);
  list-style: none;
  background: var(--warn-bg);
  border-radius: var(--r);
  font-size: 14px;
}

details.history summary {
  min-height: var(--tap);
  display: flex;
  align-items: center;
  cursor: pointer;
  color: var(--accent);
}

/* --- Buttons and forms ---------------------------------------------------- */
.btn {
  min-height: var(--tap);
  padding: 0 var(--s4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  border-radius: var(--r);
  border: 1px solid var(--border-strong);
  background: var(--bg-raised);
  color: var(--text);
  font: 600 var(--t-input) var(--font);
  text-decoration: none;
  cursor: pointer;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-on);
}

.btn--danger {
  color: var(--bad);
}

.btn--block {
  width: 100%;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  margin: var(--s3) 0;
}

.form {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s4);
}

.field {
  margin-bottom: var(--s4);
}

.field label {
  display: block;
  margin-bottom: var(--s1);
  font-weight: 600;
  font-size: 15px;
}

.field input:not([type="checkbox"]),
.field select,
.field textarea,
.inline-select {
  width: 100%;
  min-height: var(--tap);
  padding: 10px var(--s3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  background: var(--bg);
  color: var(--text);
  font: var(--t-input) var(--font);
}

.field textarea {
  min-height: 96px;
}

.field--check label {
  display: flex;
  align-items: center;
  gap: var(--s3);
  min-height: var(--tap);
  font-weight: 500;
}

.field--check input {
  width: 22px;
  height: 22px;
}

.field .help {
  margin-top: var(--s1);
  font-size: var(--t-small);
  color: var(--text-muted);
}

.field .error {
  margin-top: var(--s1);
  font-size: 14px;
  color: var(--bad);
}

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s3);
}

/* --- Admin lists: stacked cards on phones -------------------------------- */
.rows {
  list-style: none;
  margin: 0 0 var(--s4);
  padding: 0;
}

.row {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s3) var(--s4);
  margin-bottom: var(--s2);
}

.row__name {
  font-weight: 600;
}

.row__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  margin-top: var(--s2);
  align-items: center;
}

.row__actions form {
  display: flex;
  gap: var(--s2);
  align-items: center;
}

.inline-select {
  width: auto;
}

.copy-box {
  font-family: var(--font-mono);
  font-size: 13px;
  word-break: break-all;
  padding: var(--s3);
  border-radius: var(--r);
  background: var(--bg-sunken);
  user-select: all;
  -webkit-user-select: all;
}

/* --- Sign-in -------------------------------------------------------------- */
.signin {
  max-width: 400px;
  margin: 12vh auto 0;
}

.signin h1 {
  font-size: var(--t-big);
  margin: 0 0 var(--s4);
}

.guest-entry {
  margin-top: var(--s5);
  text-align: center;
}

/* --- Wider screens -------------------------------------------------------- */
@media (min-width: 768px) {
  .shell {
    padding-top: var(--s5);
  }

  .route__code {
    font-size: 36px;
  }
}
