:root {
  --bg: #f4f7fc; --surface: #ffffff; --surface-2: #eef3fb; --text: #0f1b33; --muted: #5a6b88; --border: #d9e2f1;
  --primary: #1d4ed8; --primary-hover: #1e40af; --primary-text: #ffffff; --focus: #93b4ff;
  --on_time: #166534; --slightly_late: #854d0e; --very_late: #9a3412; --canceled: #991b1b; --unknown: #5a6b88;
  --pastel-on_time: #cfeedd; --pastel-slightly_late: #fbebb0; --pastel-very_late: #fcd9bd; --pastel-canceled: #fbcfcf; --pastel-unknown: #e3e9f4;
  --tint-on_time: #eaf8ee; --tint-slightly_late: #fdf6dc; --tint-very_late: #fdeee2; --tint-canceled: #fdeaea; --tint-unknown: #eef1f6;
  --shadow: 0 1px 2px rgba(15,27,51,.06), 0 4px 14px rgba(15,27,51,.05);
}
:root[data-theme="dark"] {
  --bg: #0a1224; --surface: #111d36; --surface-2: #17274a; --text: #e8eefc; --muted: #93a5c8; --border: #243558;
  --primary: #4b83ff; --primary-hover: #6b97ff; --primary-text: #07122b; --focus: #3b62c9;
  --on_time: #9be7b4; --slightly_late: #f6df8a; --very_late: #f8c18c; --canceled: #f7a8a8; --unknown: #93a5c8;
  --pastel-on_time: #1d4a31; --pastel-slightly_late: #4a3f12; --pastel-very_late: #54321a; --pastel-canceled: #5a2323; --pastel-unknown: #223356;
  --tint-on_time: #11301f; --tint-slightly_late: #342d0c; --tint-very_late: #38210f; --tint-canceled: #3a1616; --tint-unknown: #1a2540;
  --shadow: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1224; --surface: #111d36; --surface-2: #17274a; --text: #e8eefc; --muted: #93a5c8; --border: #243558;
    --primary: #4b83ff; --primary-hover: #6b97ff; --primary-text: #07122b; --focus: #3b62c9;
    --on_time: #9be7b4; --slightly_late: #f6df8a; --very_late: #f8c18c; --canceled: #f7a8a8; --unknown: #93a5c8;
  --pastel-on_time: #1d4a31; --pastel-slightly_late: #4a3f12; --pastel-very_late: #54321a; --pastel-canceled: #5a2323; --pastel-unknown: #223356;
    --tint-on_time: #11301f; --tint-slightly_late: #342d0c; --tint-very_late: #38210f; --tint-canceled: #3a1616; --tint-unknown: #1a2540;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; padding-bottom: env(safe-area-inset-bottom); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; } h2 { font-size: 1.1rem; margin: 0 0 .5rem; } h3 { font-size: 1rem; margin: 0 0 .25rem; }
a { color: var(--primary); }
.muted { color: var(--muted); } .small { font-size: .85rem; } .hidden { display: none !important; }

/* top bar + nav */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--primary); color: var(--primary-text); padding: calc(env(safe-area-inset-top) + .6rem) max(16px, env(safe-area-inset-right)) .6rem max(16px, env(safe-area-inset-left)); display: flex; align-items: center; gap: .75rem; }
:root[data-theme="dark"] .topbar { background: #12254d; color: #e8eefc; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .topbar { background: #12254d; color: #e8eefc; } }
.brand { font-weight: 800; letter-spacing: .2px; font-size: 1.15rem; display: flex; align-items: center; gap: .5rem; color: inherit; text-decoration: none; }
.brand img { width: 26px; height: 26px; border-radius: 6px; }
.topnav { display: flex; gap: .25rem; margin-left: auto; align-items: center; }
.topnav a, .topnav button { color: inherit; background: transparent; border: 0; padding: .45rem .7rem; border-radius: 8px; font: inherit; text-decoration: none; cursor: pointer; position: relative; }
.topnav a.active { background: rgba(255,255,255,.18); }
.topnav a:hover, .topnav button:hover { background: rgba(255,255,255,.12); }
.badge { background: #ef4444; color: #fff; border-radius: 999px; font-size: .72rem; padding: 0 .4rem; margin-left: .25rem; min-width: 1.2rem; display: inline-block; text-align: center; }
.badge.amber { background: #d97706; }
@media (max-width: 700px) {
  .topnav { position: fixed; bottom: 0; left: 0; right: 0; margin: 0; background: var(--surface); border-top: 1px solid var(--border); justify-content: space-around; padding: .3rem .4rem calc(env(safe-area-inset-bottom) + .3rem); z-index: 30; }
  .topnav a, .topnav button { color: var(--muted); padding: .4rem .5rem; font-size: .82rem; text-align: center; }
  .topnav a.active { background: var(--surface-2); color: var(--primary); }
  main { padding-bottom: 5rem !important; }
}
main { max-width: 1100px; margin: 0 auto; padding: 1rem max(16px, env(safe-area-inset-right)) 2rem max(16px, env(safe-area-inset-left)); }

/* cards, forms, buttons */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.row.space { justify-content: space-between; }
.grid { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .2rem; }
input, select { width: 100%; padding: .65rem .7rem; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; min-height: 44px; }
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
button.btn, a.btn { background: var(--primary); color: var(--primary-text); border: 0; border-radius: 10px; padding: .65rem 1rem; font: inherit; font-weight: 600; cursor: pointer; min-height: 44px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
button.btn:hover, a.btn:hover { background: var(--primary-hover); }
button.btn.secondary, a.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
button.btn.danger { background: transparent; color: var(--canceled); border: 1px solid var(--border); }
button.btn.small, a.btn.small { min-height: 36px; padding: .35rem .7rem; font-size: .85rem; }
button:disabled { opacity: .55; cursor: not-allowed; }
.error { color: var(--canceled); } .notice { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: .6rem .8rem; }
.auth { max-width: 420px; margin: 8vh auto; padding: 0 16px; }
.auth .card { padding: 1.4rem; }
.stack > * + * { margin-top: .7rem; }

/* event list */
.event-card { display: block; text-decoration: none; color: inherit; }
.event-card:hover { border-color: var(--primary); }
.pill { display: inline-block; font-size: .75rem; padding: .05rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

/* status chips (filters) */
.chips { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .25rem; -webkit-overflow-scrolling: touch; }
.chip { flex: 0 0 auto; border: 2px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: .4rem .85rem; font: inherit; font-weight: 600; cursor: pointer; min-height: 40px; }
.chip .n { margin-left: .35rem; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { background: var(--surface-2); }
.chip.on_time { color: var(--on_time); } .chip.slightly_late { color: var(--slightly_late); } .chip.very_late { color: var(--very_late); } .chip.canceled { color: var(--canceled); } .chip.unknown { color: var(--unknown); }
.chip.on_time[aria-pressed="true"] { border-color: var(--on_time); } .chip.slightly_late[aria-pressed="true"] { border-color: var(--slightly_late); }
.chip.very_late[aria-pressed="true"] { border-color: var(--very_late); } .chip.canceled[aria-pressed="true"] { border-color: var(--canceled); } .chip.unknown[aria-pressed="true"] { border-color: var(--unknown); }
.chip.all[aria-pressed="true"] { border-color: var(--primary); }

/* flight list: filtered => the rows turn a very light tint of the chosen status */
.flights { border: 1px solid var(--border); border-radius: 14px; overflow: hidden; background: var(--surface); }
.flight { display: grid; grid-template-columns: 1.4fr 1fr 1fr auto; gap: .5rem 1rem; padding: .8rem 1rem; border-top: 1px solid var(--border); align-items: center; background: var(--surface); }
.flight:first-child { border-top: 0; }
.flights.tint-on_time .flight { background: var(--tint-on_time); } .flights.tint-slightly_late .flight { background: var(--tint-slightly_late); }
.flights.tint-very_late .flight { background: var(--tint-very_late); } .flights.tint-canceled .flight { background: var(--tint-canceled); } .flights.tint-unknown .flight { background: var(--tint-unknown); }
.flights.tint-on_time, .flights.tint-slightly_late, .flights.tint-very_late, .flights.tint-canceled, .flights.tint-unknown { border-color: var(--text); }
.who { font-weight: 650; } .num { font-weight: 700; font-variant-numeric: tabular-nums; }
.status { font-weight: 800; }
.flight .status, .event-card .status { display: inline-block; padding: .12rem .6rem; border-radius: 999px; font-weight: 700; }
.flight .status.on_time, .event-card .status.on_time { background: var(--pastel-on_time); } .flight .status.slightly_late { background: var(--pastel-slightly_late); }
.flight .status.very_late, .event-card .status.very_late { background: var(--pastel-very_late); } .flight .status.canceled, .event-card .status.canceled { background: var(--pastel-canceled); }
.flight .status.unknown { background: var(--pastel-unknown); }
.flight.untracked .who, .flight.untracked .num { opacity: .85; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; margin: .25rem 0 .6rem; background: var(--surface); max-width: 100%; }
.seg-btn { border: 0; background: transparent; color: var(--text); font: inherit; font-weight: 600; padding: .55rem 1rem; min-height: 44px; cursor: pointer; }
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn[aria-pressed="true"] { background: var(--primary); color: var(--primary-text); }
.check { display: flex; align-items: center; gap: .5rem; color: var(--text); font-size: 1rem; margin: 0; }
input[type="checkbox"] { width: 1.2rem; height: 1.2rem; min-height: 0; accent-color: var(--primary); }
.status.on_time { color: var(--on_time); } .status.slightly_late { color: var(--slightly_late); } .status.very_late { color: var(--very_late); } .status.canceled { color: var(--canceled); } .status.unknown { color: var(--unknown); }
.filterbanner { margin: .5rem 0; padding: .5rem .8rem; border-radius: 10px; font-weight: 600; border: 1px dashed var(--text); }
@media (max-width: 700px) { .flight { grid-template-columns: 1fr auto; } .flight .c2, .flight .c3 { grid-column: 1 / -1; } }
@media (min-width: 701px) and (max-width: 1100px) { .flight { grid-template-columns: 1.3fr 1fr 1fr auto; } }

.table { width: 100%; border-collapse: collapse; } .table th, .table td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--muted); font-size: .8rem; font-weight: 600; }
.scroll-x { overflow-x: auto; }
.alert { display: flex; gap: .8rem; padding: .8rem 1rem; border-bottom: 1px solid var(--border); align-items: center; }
.alert.unread { background: var(--surface-2); font-weight: 600; }
.alert .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 10px; }
.dot.very_late, .dot.diverted { background: var(--very_late); } .dot.canceled { background: var(--canceled); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 5.5rem; background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; z-index: 50; max-width: 90vw; }
