:root {
  --bg: #0f1220;
  --panel: #171a2b;
  --text: #e8eaf2;
  --muted: #9aa0b5;
  --accent: #4f8cff;
  --ok: #35c68a;
  --warn: #f2b544;
  --danger: #f2545b;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-wrap: break-word;
}

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  padding: 1rem 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid #262a40;
}

.topbar h1 { font-size: 1.2rem; margin: 0; }
.topnav { display: flex; gap: 1rem; margin-left: auto; margin-right: 1rem; }
.topnav a { color: var(--text); text-decoration: none; font-size: 0.9rem; }
.topnav a:hover { color: var(--accent); }
.topnav a.site-link { color: var(--accent); white-space: nowrap; }
.tz { color: var(--muted); font-size: 0.85rem; }

main { padding: 1.5rem; max-width: 1100px; margin: 0 auto; }

.board-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.board-head h2 { margin: 0; }

.daynav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.75rem; font-size: 0.85rem; }
.daynav a { text-decoration: none; }
.daynav a:hover { text-decoration: underline; }
.daynav .today { margin-left: auto; color: var(--muted); }
.daynav .today:hover { color: var(--accent); }

/* The arrivals search form keeps the plain inline layout. */
.search-form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.search-form .reset { color: var(--muted); font-size: 0.85rem; text-decoration: none; padding: 0.4rem 0.2rem; }
.search-form .reset:hover { color: var(--accent); }

/* The board search control: one input-shaped box holding the physical search
   field and the calendar button, so it reads as a single input. */
.search-input {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--bg);
  border: 1px solid #2c3250;
  border-radius: 6px;
  overflow: hidden;
}

.search-input input[type="search"] {
  flex: 1 1 auto;
  min-width: 18rem;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0.4rem 0.6rem;
}

.search-input input[type="search"]:focus { outline: none; }
.search-input:focus-within { border-color: var(--accent); }

.cal-toggle {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  background: transparent;
  border: none;
  border-left: 1px solid #2c3250;
  border-radius: 0;
  color: var(--accent);
  padding: 0 0.6rem;
}

.cal-toggle:hover,
.cal-toggle:focus-visible { color: #fff; background: var(--accent); }

/* Hidden helper that opens the native picker; it is never submitted. */
.date-proxy {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  border: none;
  padding: 0;
}

.search-submit {
  flex: 0 0 auto;
  align-self: stretch;
  background: transparent;
  border: none;
  border-left: 1px solid #2c3250;
  border-radius: 0;
  color: var(--accent);
  padding: 0 0.9rem;
  font-weight: 600;
}

.search-submit:hover,
.search-submit:focus-visible { color: #fff; background: var(--accent); }

input[type="date"], input[type="search"], button {
  background: var(--bg);
  color: var(--text);
  border: 1px solid #2c3250;
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font: inherit;
}

input[type="search"] { min-width: 18rem; }

button { cursor: pointer; background: var(--accent); border-color: var(--accent); color: #fff; }

.count { color: var(--muted); font-size: 0.85rem; margin: 0 0 0.75rem; }

.updated { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  border-radius: 8px;
}

table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 8px; overflow: hidden; }
th, td { padding: 0.6rem 0.8rem; text-align: left; border-bottom: 1px solid #242942; font-size: 0.9rem; }
th { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 0.72rem; letter-spacing: 0.04em; white-space: nowrap; }
tr:last-child td { border-bottom: none; }

.flight-number { font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; }
.flight-count { color: var(--muted); font-variant-numeric: tabular-nums; }
.iata, .empty { color: var(--muted); }

.row-action { white-space: nowrap; }
.row-action a { display: inline-block; padding: 0.25rem 0; }

.status {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: #2a2f4a;
}

.status-scheduled { background: rgba(79, 140, 255, 0.15); color: var(--accent); }
.status-delayed { background: rgba(242, 181, 68, 0.15); color: var(--warn); }
.status-departed { background: rgba(53, 198, 138, 0.15); color: var(--ok); }
.status-cancelled { background: rgba(242, 84, 91, 0.15); color: var(--danger); }

tr.status-cancelled td { color: var(--danger); }

.delay-ontime { color: var(--ok); }
.delay-slight { color: var(--warn); }
.delay-significant { color: var(--danger); font-weight: 700; }
.delay-cancelled { color: var(--muted); }
.delay-unknown { color: var(--muted); }

.board-filters { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.board-filters a {
  text-decoration: none;
  padding: 0.35rem 0.7rem;
  border: 1px solid #2c3250;
  border-radius: 6px;
  font-size: 0.85rem;
}
.board-filters a.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.stats .stat { background: var(--panel); border-radius: 8px; padding: 0.8rem 1rem; }
.stats .stat-value { font-size: 1.4rem; font-weight: 700; }
.stats .stat-label { color: var(--muted); font-size: 0.8rem; }

.flight-info { display: grid; grid-template-columns: 220px 1fr; gap: 0.4rem 1rem; background: var(--panel); padding: 1rem; border-radius: 8px; }
.flight-info dt { color: var(--muted); }
.flight-info dd { margin: 0; }

.footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 1rem; }
.footer .generated { display: block; margin-top: 0.25rem; font-variant-numeric: tabular-nums; }
.error-page { max-width: 560px; margin: 4rem auto; text-align: center; padding: 0 1rem; }
a { color: var(--accent); }

/* ---------- Mobile / narrow screens ---------- */

@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
}

@media (max-width: 640px) {
  .topbar {
    align-items: center;
    padding: 0.75rem 1rem;
    gap: 0.5rem;
  }
  .topbar h1 { font-size: 1rem; flex: 1 1 auto; }
  .topnav {
    order: 3;
    flex: 1 1 100%;
    margin: 0;
    gap: 0.75rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .topnav a { font-size: 0.95rem; padding: 0.35rem 0; white-space: nowrap; }
  .tz { order: 2; margin-left: auto; }

  main { padding: 1rem; }
  .board { width: 100%; }

  /* Stack the page heading above the search control and let it fill the width. */
  .board-head { flex-direction: column; align-items: stretch; gap: 0.75rem; }
  .board-head h2 { font-size: 1.1rem; }
  .search-form { width: 100%; }
  .search-form input[type="search"] {
    flex: 1 1 100%;
    min-width: 0;
    width: 100%;
  }
  .search-form button { flex: 1 1 auto; }
  .search-input { width: 100%; }
  .search-input input[type="search"] {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
  }

  /* 16px prevents iOS Safari from zooming the page on focus. */
  input[type="date"], input[type="search"], button {
    font-size: 16px;
    min-height: 44px;
  }

  .count { margin-bottom: 0.5rem; }

  /* Compact cells so the common case fits without horizontal scrolling. */
  th, td { padding: 0.5rem 0.55rem; font-size: 0.85rem; }
  table.flights { min-width: 0; }

  /* Keep the row identity visible while scrolling wide tables. */
  th:first-child, td:first-child {
    position: sticky;
    left: 0;
    background: var(--panel);
    z-index: 1;
  }
  thead th:first-child { z-index: 2; }
  tr.status-cancelled td:first-child { background: var(--panel); }

  .flight-info { grid-template-columns: 1fr; gap: 0.15rem 0; }
  .flight-info dt { margin-top: 0.5rem; }

  .footer { padding: 0.75rem; }
  .error-page { margin: 2.5rem auto; }
}

/* Very small phones (iPhone SE, 320-360px). */
@media (max-width: 380px) {
  .topbar h1 { font-size: 0.95rem; }
  th, td { padding: 0.45rem 0.5rem; font-size: 0.8rem; }
  .topnav { gap: 0.6rem; }
}

