:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6ec;
  --text: #14181f;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #e7edfd;
  --good: #12805c;
  --warn: #b45309;
  --bad: #be123c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
}
[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #151b24;
  --surface-2: #1c2430;
  --border: #262f3d;
  --text: #e7ecf3;
  --muted: #93a1b3;
  --accent: #6ea8fe;
  --accent-soft: #1b2a44;
  --good: #45d19a;
  --warn: #f0b357;
  --bad: #fb7185;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: -.01em; }
.brand svg { width: 27px; height: 27px; flex: none; fill: var(--accent); color: var(--accent); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 650; }
.tagline {
  font-size: 11px; font-weight: 500; color: var(--muted);
  letter-spacing: .015em; white-space: nowrap;
}
.search { flex: 1; display: flex; gap: 8px; max-width: 620px; }
.search input {
  flex: 1; min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2); color: var(--text); font-size: 15px;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; background: var(--surface); }
.search button {
  padding: 10px 20px; border: 0; border-radius: 999px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 15px; cursor: pointer;
}
.search button:hover { filter: brightness(1.07); }
.topbar-actions { display: flex; gap: 6px; margin-left: auto; }
.icon-btn {
  display: grid; place-items: center; line-height: 1;
  width: 36px; height: 36px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 16px;
}
.icon-btn:hover { background: var(--accent-soft); }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(360px, 460px) 1fr;
  height: calc(100dvh - 57px);
}
.panel { overflow-y: auto; padding: 20px; border-right: 1px solid var(--border); }
.map-wrap { position: relative; }
#map { width: 100%; height: 100%; background: var(--surface-2); }

/* ---------- empty state ---------- */
.empty h1 { font-size: 24px; margin: 8px 0 8px; letter-spacing: -.02em; }
.empty p { color: var(--muted); margin: 0 0 16px; }
code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer;
}
.chip:hover { background: var(--accent-soft); border-color: var(--accent); }

/* ---------- result ---------- */
.hero-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hero h2 { font-size: 26px; margin: 0; letter-spacing: -.02em; }
.share-btn {
  display: inline-flex; align-items: center; gap: 6px; margin-left: auto;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 6px 13px; font: inherit; font-size: 12.5px; font-weight: 600;
  cursor: pointer; line-height: 1;
}
.share-btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.share-btn:active { transform: scale(.97); }
.share-btn[hidden] { display: none; }
@media (max-width: 359px) { .share-btn span { display: none; } .share-btn { padding: 7px 10px; } }

.airline { margin: 2px 0 18px; color: var(--muted); font-size: 14px; }
.status {
  font-size: 12px; font-weight: 650; letter-spacing: .03em; text-transform: uppercase;
  padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border);
}
.status.live { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); border-color: transparent; }
.status.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); border-color: transparent; }
.status.bad  { background: color-mix(in srgb, var(--bad) 15%, transparent);  color: var(--bad);  border-color: transparent; }

.eta {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  margin: 0 0 16px; padding: 12px 16px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow);
  border-left: 3px solid var(--muted);
}
.eta[hidden] { display: none; }
.eta.ontime { border-left-color: var(--good); }
.eta.warn { border-left-color: var(--warn); }
.eta.late { border-left-color: var(--bad); }
.eta-time { font-size: 19px; font-weight: 700; letter-spacing: -.02em; }
.eta-note { font-size: 13px; color: var(--muted); }
.eta.late .eta-note { color: var(--bad); font-weight: 600; }
.eta.warn .eta-note { color: var(--warn); font-weight: 600; }
.eta.ontime .eta-note { color: var(--good); font-weight: 600; }

.route {
  display: grid; grid-template-columns: 1fr minmax(90px, 1.2fr) 1fr; gap: 12px; align-items: start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 16px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.endpoint .iata { font-size: 30px; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
.endpoint .city { font-size: 13px; font-weight: 600; }
.endpoint .airport { font-size: 12px; color: var(--muted); }
.endpoint.right { text-align: right; }
.progress-wrap { padding-top: 14px; }
.progress { position: relative; height: 4px; border-radius: 4px; background: var(--surface-2); }
.progress-bar { height: 100%; border-radius: 4px; background: var(--accent); width: 0%; transition: width .6s ease; }
.plane-dot {
  position: absolute; top: 50%; left: 0; transform: translate(-50%, -50%);
  font-size: 15px; color: var(--accent); transition: left .6s ease;
}
.progress-meta { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  font-size: 11px; color: var(--muted); margin-top: 8px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px; align-items: start; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.card h3 {
  margin: 0 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650;
}
dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; align-items: baseline; }
dt { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
dd { margin: 0; text-align: right; font-size: 13.5px; font-weight: 550; font-variant-numeric: tabular-nums; }
dd.big { font-size: 17px; font-weight: 700; }
dd .sub { display: block; font-size: 11px; font-weight: 400; color: var(--muted); line-height: 1.35; margin-top: 1px; }
dd .late { color: var(--bad); }
dd .early { color: var(--good); }
.site-footer { margin: 22px 0 0; padding-top: 16px; border-top: 1px solid var(--border); }
.build { font-size: 11px; color: var(--muted); margin: 0 0 10px; opacity: .8; }
.footer-line { font-size: 11.5px; line-height: 1.55; color: var(--muted); margin: 0 0 12px; }
.terms summary {
  font-size: 12px; font-weight: 600; color: var(--muted); cursor: pointer;
  padding: 7px 0; list-style: none; display: flex; align-items: center; gap: 6px;
}
.terms summary::-webkit-details-marker { display: none; }
.terms summary::before { content: '▸'; font-size: 10px; transition: transform .15s; }
.terms[open] summary::before { transform: rotate(90deg); }
.terms summary:hover { color: var(--accent); }
.terms-body {
  max-height: 340px; overflow-y: auto; padding: 4px 14px 10px 0;
  font-size: 11.5px; line-height: 1.6; color: var(--muted);
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.terms-body h4 { font-size: 11.5px; color: var(--text); margin: 14px 0 4px; }
.terms-body p { margin: 0 0 7px; }
.terms-body b { color: var(--text); }
.terms-meta { padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.terms-body a, .copyright a { color: var(--accent); }
.copyright { font-size: 11px; color: var(--muted); opacity: .75; margin: 12px 0 0; }
.icon-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.card.alerts { border-left: 3px solid var(--accent); margin-bottom: 12px; }
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.events li { display: grid; gap: 1px; padding-left: 12px; border-left: 2px solid var(--border); }
.events li.critical { border-left-color: var(--bad); }
.events li b { font-size: 13.5px; }
.events li span { font-size: 12.5px; color: var(--muted); }
.events li time { font-size: 11px; color: var(--muted); opacity: .75; }

.sources { font-size: 11.5px; color: var(--muted); margin: 16px 0 4px; }
.sources a { color: inherit; }

/* ---------- map extras ---------- */
.map-badge[hidden] { display: none; }
.map-badge {
  position: absolute; top: 12px; right: 12px; z-index: 500;
  display: flex; align-items: center; gap: 7px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 13px; font-size: 12px; font-weight: 600; box-shadow: var(--shadow);
}
.map-badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); animation: pulse 2s infinite; }
.map-badge.stale { color: var(--muted); font-weight: 500; }
.map-badge.stale .dot { background: var(--muted); animation: none; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .25 } }
.map-fallback { display: grid; place-items: center; height: 100%; padding: 24px;
  text-align: center; color: var(--muted); font-size: 13px; }
/* OSM has no keyless dark basemap, so invert the standard tiles for the dark theme. */
.tiles-dark { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9); }
/* The aircraft pings: a slow radar ripple, two rings offset so it reads as a repeating pulse. */
.recenter {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 500;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 7px 16px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; box-shadow: var(--shadow);
}
.recenter:hover { background: var(--accent-soft); border-color: var(--accent); }
.recenter[hidden] { display: none; }
.map-badge .ago { color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }
.map-badge .refresh {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  font-size: 15px; line-height: 1; padding: 0 0 0 2px;
}
.map-badge .refresh:hover { color: var(--accent); }
.map-badge .refresh.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.plane-icon { position: relative; }
.plane-icon svg { display: block; filter: drop-shadow(0 2px 4px rgba(0,0,0,.35)); position: relative; z-index: 2; }
.plane-icon .ping {
  position: absolute; left: 50%; top: 50%; width: 34px; height: 34px; margin: -17px 0 0 -17px;
  border-radius: 50%; border: 2px solid var(--accent); opacity: 0; pointer-events: none;
  animation: ping 3s cubic-bezier(0, 0, .2, 1) infinite;
}
.plane-icon .ping-2 { animation-delay: 1.5s; }
.plane-icon.estimated .ping { border-color: #9dbcf7; }
@keyframes ping {
  0%   { transform: scale(.45); opacity: .6; }
  70%  { opacity: 0; }
  100% { transform: scale(2.6); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .plane-icon .ping { animation: none; } }
.plane-icon.estimated svg { filter: drop-shadow(0 1px 3px rgba(0,0,0,.25)); }
.leaflet-container { font: inherit; background: var(--surface-2); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); }
#diag-details { grid-template-columns: 1fr auto; gap: 10px 12px; }
#diag-details dt { white-space: normal; color: var(--text); font-size: 13px; font-weight: 550; }
#diag-details dt .sub { display: block; font-size: 11.5px; font-weight: 400; color: var(--muted); margin-top: 2px; }
#diag-details dd { font-size: 15px; }
#diag-details dd.pending { color: var(--muted); letter-spacing: 1px; }

.apt-label {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 1px 6px; font-size: 11px; font-weight: 700; box-shadow: var(--shadow); white-space: nowrap;
}

.quota-bar-row { grid-column: 1 / -1; }
.quota-bar { display: block; height: 4px; border-radius: 4px; background: var(--surface-2);
  overflow: hidden; margin-top: 2px; }
.quota-bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.quota-bar i.low { background: var(--bad); }

/* Pull to refresh: an installed PWA gets no browser-provided one. */
.ptr {
  position: fixed; top: -46px; left: 50%; z-index: 1500;
  width: 38px; height: 38px; margin-left: -19px;
  display: grid; place-items: center; border-radius: 50%;
  background: var(--surface); color: var(--accent);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transform: translateX(-50%);
}
.ptr.on { opacity: 1; }
.ptr.ready { color: #fff; background: var(--accent); border-color: var(--accent); }
.ptr.spinning svg { animation: spin .8s linear infinite; }
.ptr:not(.on) { transition: transform .25s ease, opacity .25s ease; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 2000;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 13.5px; box-shadow: var(--shadow); max-width: 90vw;
}

/* ---------- responsive: mobile-first PWA layout ---------- */
@media (max-width: 900px) {
  /* Standalone PWA has no browser chrome, so respect the notch and home indicator. */
  .topbar {
    flex-wrap: wrap; gap: 10px 12px;
    padding: calc(10px + env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px
             max(14px, env(safe-area-inset-left));
  }
  .layout { grid-template-columns: 1fr; grid-template-rows: 46dvh auto; height: auto; }
  .map-wrap { order: -1; height: 46dvh; min-height: 240px; position: sticky; top: 0; z-index: 1; }
  .panel {
    border-right: 0; height: auto; overflow: visible;
    padding: 16px max(16px, env(safe-area-inset-left)) calc(28px + env(safe-area-inset-bottom))
             max(16px, env(safe-area-inset-right));
    background: var(--bg); border-radius: 18px 18px 0 0; margin-top: -18px;
    position: relative; z-index: 2; box-shadow: 0 -8px 24px rgba(0,0,0,.08);
  }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  /* Comfortable thumb targets. */
  .search input, .search button { padding: 12px 18px; font-size: 16px; }  /* 16px avoids iOS zoom-on-focus */
  .icon-btn { width: 42px; height: 42px; }
  .chip { padding: 9px 16px; font-size: 14px; }
  .recenter { bottom: 14px; padding: 9px 18px; }
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { padding: 13px 14px; }
  .hero h2 { font-size: 23px; }
  .eta { padding: 11px 14px; }
  .eta-time { font-size: 18px; }
  .endpoint .iata { font-size: 26px; }
  .route { padding: 15px 14px; gap: 8px; }
  .map-badge { top: 10px; right: 10px; left: 10px; justify-content: center; font-size: 11.5px; }
}

@media (max-width: 460px) {
  .cards { grid-template-columns: 1fr; }
  .brand-name { font-size: 15px; }
  .tagline { font-size: 10.5px; }
  .route { grid-template-columns: 1fr auto 1fr; }
  .endpoint .iata { font-size: 24px; }
}

/* Standalone (installed) mode: the page is the whole app, so lose the page-level scroll chrome. */
@media (display-mode: standalone) {
  body { overscroll-behavior-y: none; }
  .topbar { position: sticky; top: 0; }
}
