:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --text: #14181d;
  --text-2: #4d5661;
  --muted: #6b7480;
  --line: #dde3ea;
  --accent: #0e5aa7;
  --accent-ink: #ffffff;
  --accent-soft: #e2edf9;
  --danger: #c0352b;
  --warn-soft: #fff4d6;
  --warn-ink: #7a5300;
  --ok-soft: #e3f4e9;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e6e9ee;
  --radius: 10px;
  --tabbar-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111315;
    --surface: #1a1d20;
    --surface-2: #23272b;
    --text: #eceef0;
    --text-2: #c0c6cc;
    --muted: #8d959e;
    --line: #2e3338;
    --accent: #4a9be8;
    --accent-ink: #08121c;
    --accent-soft: #1b2c3e;
    --danger: #ef6b61;
    --warn-soft: #3a2f12;
    --warn-ink: #f2cf7a;
    --ok-soft: #173024;
    --series-1: #3987e5;
    --series-2: #d95926;
    --grid: #2a2e33;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111315; --surface: #1a1d20; --surface-2: #23272b; --text: #eceef0; --text-2: #c0c6cc;
  --muted: #8d959e; --line: #2e3338; --accent: #4a9be8; --accent-ink: #08121c; --accent-soft: #1b2c3e;
  --danger: #ef6b61; --warn-soft: #3a2f12; --warn-ink: #f2cf7a; --ok-soft: #173024;
  --series-1: #3987e5; --series-2: #d95926; --grid: #2a2e33;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
code { font-size: .85em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- layout ---------- */
header.top {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.topnav { display: none; margin-left: auto; align-items: center; gap: 4px; }
.topnav a:not(.btn) { color: var(--text-2); padding: 6px 10px; border-radius: 8px; }
.topnav a.on { color: var(--accent); background: var(--accent-soft); }
.topnav a:hover { text-decoration: none; background: var(--surface-2); }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
main.wide { max-width: 1400px; }
.pagehead { margin: 4px 0 14px; }
.pagehead p { margin: 4px 0 0; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: .72rem; color: var(--muted); padding: 6px 0; }
.tabbar a span { font-size: 1.25rem; line-height: 1.2; }
.tabbar a.on { color: var(--accent); }
.tabbar a:hover { text-decoration: none; }
.tabbar a.add span {
  display: grid; place-items: center; width: 50px; height: 50px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 1.7rem; margin-top: -18px;
  box-shadow: 0 3px 10px rgb(0 0 0 / .25);
}

@media (min-width: 900px) {
  .topnav { display: flex; }
  .tabbar { display: none; }
  body { padding-bottom: 32px; }
}

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; min-width: 0; }
.card.empty { text-align: center; padding: 32px 16px; }
.flash { background: var(--ok-soft); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; }
.flash.error { background: var(--warn-soft); color: var(--warn-ink); }
.flash ul { margin: 0; padding-left: 18px; }
.badge { display: inline-block; font-size: .7rem; padding: 1px 6px; border-radius: 99px; background: var(--warn-soft); color: var(--warn-ink); vertical-align: middle; white-space: nowrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 8px 16px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.topnav .btn { min-height: 36px; margin-left: 8px; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.topnav button.link { color: var(--text-2); padding: 6px 10px; }
form.inline { display: inline; }

input, select, textarea {
  font: inherit; font-size: 16px; /* 16px avoids iOS zoom on focus */
  width: 100%; padding: 10px 12px; min-height: 44px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--text);
}
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type="checkbox"] { width: 20px; min-height: 20px; height: 20px; accent-color: var(--accent); }
input[type="file"] { padding: 8px; }

.form label, .form .field { display: block; margin-bottom: 14px; font-weight: 600; font-size: .9rem; color: var(--text-2); }
.form label input, .form label textarea, .form label select { margin-top: 5px; font-weight: 400; }
.form .lbl { display: block; margin-bottom: 6px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.row { display: flex; gap: 12px; align-items: flex-end; }
.row .grow { flex: 1; min-width: 0; }
.row .narrow { width: 110px; flex: none; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }
.actions.sticky { position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px); background: var(--bg); padding: 10px 0; }
@media (min-width: 900px) { .actions.sticky { bottom: 0; } }
.danger-zone { margin: 8px 0 24px; }
#flightform { max-width: 640px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: -4px 0 14px; }
.chip {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  border-radius: 99px; padding: 7px 12px; font: inherit; font-size: .88rem; cursor: pointer; min-height: 36px;
}
.chip:hover { text-decoration: none; border-color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.yearnav { margin: 0 0 16px; }

/* filters */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; align-items: center; }
.filters input[type="search"] { grid-column: 1 / -1; }
.filters .reset { justify-self: start; }
@media (min-width: 900px) {
  .filters { grid-template-columns: 2fr 1fr 1fr 1fr auto auto; }
  .filters input[type="search"] { grid-column: auto; }
}
.tablefilter { max-width: 360px; margin-bottom: 12px; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; border-collapse: separate; border-spacing: 0; }
.card table.data { border: 0; }
.card table.data th:first-child, .card table.data td:first-child { padding-left: 0; }
tr[data-href] { cursor: pointer; }
tr[data-href]:hover td { background: var(--surface-2); }
table.mapping tr.isnew td:first-child { box-shadow: inset 3px 0 var(--series-1); padding-left: 10px; }
table.mapping tr.fuzzy td { background: var(--warn-soft); }
table.mapping select, table.mapping input { min-width: 180px; }
.card { overflow-x: auto; }

table.flights { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); border-collapse: separate; border-spacing: 0; overflow: hidden; }
table.flights td.nb { color: var(--muted); font-variant-numeric: tabular-nums; width: 3em; }
table.flights td.date { white-space: nowrap; }
table.flights td.notes { color: var(--text-2); font-size: .88rem; max-width: 360px; }
table.flights tr:target td, table.flights tr.hl td { background: var(--accent-soft); }
table.flights tbody tr:last-child td { border-bottom: 0; }

/* flight table -> cards on phones */
@media (max-width: 700px) {
  table.flights, table.flights tbody { display: block; border: 0; background: none; }
  table.flights thead { display: none; }
  table.flights tr {
    display: grid; grid-template-columns: auto 1fr auto; gap: 2px 10px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 10px 12px; margin-bottom: 8px;
  }
  table.flights td { border: 0; padding: 0; }
  table.flights td.nb { grid-row: 1; grid-column: 1; font-size: .85rem; width: auto; }
  table.flights td.nb:empty::before { content: "·"; }
  table.flights td.date { grid-row: 1; grid-column: 2; font-size: .85rem; color: var(--muted); }
  table.flights td.dur { grid-row: 1; grid-column: 3; font-weight: 600; }
  table.flights td.route { grid-column: 1 / -1; font-weight: 600; }
  table.flights td.wing { grid-column: 1 / -1; font-size: .82rem; color: var(--muted); }
  table.flights td.notes { grid-column: 1 / -1; max-width: none; }
  table.flights td.notes:empty, table.flights td.wing:empty { display: none; }
  table.data { font-size: .9rem; }
  table.data th, table.data td { padding: 8px 6px; }
}

/* kpis & charts */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(5, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; color: var(--text); min-width: 0; }
a.kpi:hover { text-decoration: none; border-color: var(--accent); }
.kpi .v { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi .v small { font-size: .9rem; color: var(--muted); font-weight: 600; }
.kpi .l { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.charts { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
@media (min-width: 900px) { .charts { grid-template-columns: 1fr 1fr; } .span2 { grid-column: 1 / -1; } }
.chart { position: relative; height: 240px; }
.chart.tall { height: 380px; }

/* map */
.map { height: calc(100vh - 230px); min-height: 360px; border-radius: var(--radius); border: 1px solid var(--line); margin-bottom: 16px; z-index: 0; }
.map.small { height: 300px; min-height: 0; margin-bottom: 6px; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: .85rem; color: var(--text-2); }
.legend .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-left: 6px; }
.legend .dot.takeoff { background: var(--series-1); }
.legend .dot.landing { background: var(--series-2); }
.legend .line { display: inline-block; width: 22px; border-top: 2px dashed var(--muted); margin-left: 6px; }
.leaflet-popup-content { font: 14px/1.4 system-ui, sans-serif; }
.inline-list { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 0; list-style: none; margin: 0; }

.aliases { list-style: none; padding: 0; margin: 0; }
.aliases li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }

.menu { padding: 0; }
.menu a { display: flex; flex-direction: column; padding: 14px 16px; border-bottom: 1px solid var(--line); color: var(--text); font-weight: 600; }
.menu a:last-child { border-bottom: 0; }
.menu a span { font-weight: 400; font-size: .85rem; }

.login { max-width: 360px; margin: 10vh auto; }
.login h1 { margin-bottom: 16px; }
.login label { display: block; margin-bottom: 12px; }
.login .btn { width: 100%; }
