:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1d232b;
  --muted: #5f6b7a;
  --border: #dde2e8;
  --accent: #1565c0;
  --best-bg: #fff7d1;
  --selected: #e3effd;
  --igc: #c2185b;
  --puretrack: #1565c0;
  --ogn: #2e7d32;
  --garmin: #ef6c00;
  --live: #1e8e3e;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181d;
    --surface: #1d2329;
    --text: #e6e9ed;
    --muted: #9aa5b1;
    --border: #333c46;
    --accent: #64a8f0;
    --best-bg: #3b3415;
    --selected: #1f3550;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.top { position: relative; display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 1100; }
.brand { font-weight: 700; font-size: 18px; text-decoration: none; color: var(--text); }
.top nav { display: flex; gap: 16px; align-items: center; }
.top form { margin: 0; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
h1 { font-size: 24px; margin: 4px 0 12px; }
h2 { font-size: 18px; margin: 28px 0 8px; }
h2 small { font-weight: 400; color: var(--muted); font-size: 14px; }
small { color: var(--muted); }
.back { margin: 0; }
.zone { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.empty { color: var(--muted); }

.map { width: 100%; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.map-overview { height: 380px; margin-bottom: 16px; }
.map-flight { height: 70vh; min-height: 380px; }
.leaflet-container { font: inherit; }

table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th { font-size: 13px; color: var(--muted); font-weight: 600; }
tbody tr:last-child > * { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.flights tbody tr { cursor: pointer; }
.flights tbody tr:hover, .routes tbody tr:hover { background: var(--selected); }
.routes tbody tr { cursor: pointer; }
.routes tr.best { background: var(--best-bg); font-weight: 600; }
.routes tr.selected td:first-child { box-shadow: inset 4px 0 0 var(--accent); }
.times td, .emails td { font-variant-numeric: tabular-nums; }
.emails tr.other { color: var(--muted); }
.delta { color: var(--muted); font-size: 13px; white-space: nowrap; }
.table-wrap { overflow-x: auto; }

.summary { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 0 0 6px; }
.summary div { min-width: 90px; }
.summary dt { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.summary dd { margin: 0; font-size: 18px; font-weight: 600; }

.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 10px; background: var(--border); color: var(--text); vertical-align: 1px; }
.badge.igc { background: var(--igc); color: #fff; }
.badge.wp { background: #21759b; color: #fff; }
.badge.live { background: var(--live); color: #fff; }
.badge.best { background: #f9a825; color: #000; }

.controls { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 0 0 10px; }
.group { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.group-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-right: 2px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); cursor: pointer; font: inherit; font-size: 14px; user-select: none; }
.chip input { margin: 0; }
.chip.igc { border-color: var(--igc); }
.chip.combined { border-color: #263238; }
.chip.puretrack { border-color: var(--puretrack); }
.chip.ogn { border-color: var(--ogn); }
.chip.garmin { border-color: var(--garmin); }
.chip.disabled { opacity: .45; cursor: default; }
.chip .count { color: var(--muted); font-size: 12px; }

.login { max-width: 340px; margin: 60px auto; background: var(--surface); padding: 24px; border: 1px solid var(--border); border-radius: 8px; display: grid; gap: 12px; }
.login h1 { margin: 0; }
.login label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.login input { font: inherit; padding: 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }
.login button { font: inherit; padding: 9px; border: 0; border-radius: 6px; background: var(--accent); color: #fff; cursor: pointer; }
.error { color: #d32f2f; margin: 0; }

@media (max-width: 700px) {
  main { padding: 12px 16px; }
  th, td { padding: 6px; font-size: 14px; }
  .map-flight { height: 60vh; }
}

.post-link { margin: -6px 0 12px; }
.post-title { color: var(--muted); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 12px; }
.filters input, .filters select { font: inherit; font-size: 14px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
.filters input[type=search] { flex: 1 1 180px; min-width: 0; }
.filters .min { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; color: var(--muted); }
.filters .min input { width: 70px; }
.filters .count { margin-left: auto; font-size: 13px; color: var(--muted); }

.intro { color: var(--muted); max-width: 70ch; }
.notice { padding: 10px 12px; border-radius: 6px; background: var(--selected); }
.notice.error { background: #fdecea; color: #b71c1c; }
.settings fieldset { border: 1px solid var(--border); border-radius: 8px; background: var(--surface); margin: 0 0 16px; padding: 4px 16px 8px; }
.settings legend { font-weight: 700; padding: 0 6px; }
.field { display: grid; grid-template-columns: minmax(180px, 280px) 1fr; gap: 4px 16px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.field:last-child { border-bottom: 0; }
.field > label { font-weight: 600; font-size: 14px; padding-top: 6px; }
.field.changed > label::after { content: " •"; color: var(--accent); }
.field input[type=text], .field input[type=password], .field textarea { font: inherit; font-size: 14px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); width: 100%; max-width: 420px; }
.field input.number { width: 120px; }
.field textarea { font-family: ui-monospace, monospace; }
.field input[type=checkbox] { margin-top: 9px; }
.field .unit { color: var(--muted); font-size: 14px; margin-left: 6px; }
.field .inline { font-size: 14px; color: var(--muted); margin-left: 10px; }
.help { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.field-error { margin: 4px 0 0; font-size: 13px; color: #d32f2f; font-weight: 600; }
.has-error input, .has-error textarea { border-color: #d32f2f; }
.badge.monitor { background: #6a1b9a; color: #fff; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 0 0 24px; }
.actions button, .monitor-restart button { font: inherit; padding: 9px 16px; border: 0; border-radius: 6px; background: var(--accent); color: #fff; cursor: pointer; }
button.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.monitor-restart { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 4px 16px 16px; }
@media (max-width: 700px) { .field { grid-template-columns: 1fr; } .field > label { padding-top: 0; } }
@media (prefers-color-scheme: dark) { .notice.error { background: #4a1c1c; color: #ffb4ab; } }

.top nav a { text-decoration: none; }
.top nav a[aria-current="page"] { color: var(--text); font-weight: 600; }

/* Menu button: only on narrow screens, where the menu folds away */
.menu-toggle { display: none; align-items: center; gap: 8px; font: inherit; font-size: 15px; padding: 6px 12px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); cursor: pointer; }
.menu-icon, .menu-icon::before, .menu-icon::after { display: block; width: 16px; height: 2px; background: currentColor;
  border-radius: 1px; position: relative; transition: transform .15s, background .15s; }
.menu-icon::before, .menu-icon::after { content: ""; position: absolute; left: 0; }
.menu-icon::before { top: -5px; }
.menu-icon::after { top: 5px; }
.top.open .menu-icon { background: transparent; }
.top.open .menu-icon::before { transform: translateY(5px) rotate(45deg); }
.top.open .menu-icon::after { transform: translateY(-5px) rotate(-45deg); }
@media (max-width: 760px) {
  .js .menu-toggle { display: inline-flex; }
  .js .top nav { display: none; }
  .js .top.open nav { display: flex; }
  .top nav { position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; align-items: stretch; gap: 0;
    background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: 0 8px 16px rgba(0, 0, 0, .12); padding: 4px 0; }
  .top nav a, .top nav button.link { display: block; width: 100%; text-align: left; padding: 12px 16px; font-size: 16px; }
  .top nav a[aria-current="page"] { box-shadow: inset 3px 0 0 var(--accent); }
  .no-js .top { flex-wrap: wrap; }
  .no-js .top nav { position: static; box-shadow: none; border: 0; }
}
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--live); border-radius: 8px; padding: 12px 16px; }
.card.bad { border-left-color: #d32f2f; }
.card-head { display: flex; align-items: center; gap: 8px; }
.card-head h3 { margin: 0; font-size: 17px; }
.card-head .state { margin-left: auto; font-size: 13px; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--live); flex: none; }
.card.bad .dot, .dot.bad { background: #d32f2f; }
.dot.ok { background: var(--live); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 8px 0; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.warn-text { color: #c62828; }
.facts-table th { width: 220px; font-weight: 600; }
code.wrap { white-space: pre-wrap; word-break: break-word; font-size: 13px; }
.tabs { display: flex; gap: 4px; margin: 0 0 12px; border-bottom: 1px solid var(--border); }
.tab { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.filters input[type=checkbox] { padding: 0; margin: 0; }
.log { max-height: 75vh; overflow-y: auto; background: #0f1419; color: #d6dde5; border-radius: 8px; padding: 8px 0; font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-x: auto; }
.log-line { display: flex; gap: 12px; padding: 1px 12px; white-space: pre-wrap; word-break: break-word; }
.log-line:hover { background: #1c2430; }
.log-time { color: #7d8a99; flex: none; }
.log-line.level-warning .log-msg { color: #ffcc66; }
.log-line.level-error .log-msg, .log-line.level-critical .log-msg { color: #ff8a80; }
.log .empty { padding: 8px 12px; margin: 0; color: #7d8a99; }
@media (max-width: 700px) { .log-line { flex-direction: column; gap: 0; } }
.map-button a { display: flex !important; align-items: center; justify-content: center; color: #333; }

/* Safari shows hairline gaps between tiles, which Leaflet's mix-blend-mode
   fix doesn't cure there: overlap each tile by 1px instead, as the blog does
   (its theme's style.css). The blend mode has to go too, or the overlaps
   would add up to bright lines. */
.leaflet-container img.leaflet-tile {
    width: 257px !important;
    height: 257px !important;
    mix-blend-mode: normal !important;
}

.timeline td { font-variant-numeric: tabular-nums; }
.timeline td:first-child { white-space: nowrap; }
.timeline tr.this-flight { background: var(--best-bg); }
.timeline tr.event-data td, .timeline tr.event-gap td { color: var(--muted); }
.timeline tr.event-gap td:nth-child(2) { color: #c62828; }

/* Day page */
.day-layout { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 24px; align-items: start; }
.day-side { position: sticky; top: 16px; }
.day-head { display: flex; align-items: center; gap: 10px; }
.day-head h1 { margin: 4px 0; }
.day-step { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); text-decoration: none; font-size: 22px; line-height: 1; color: var(--text); flex: none; }
.live { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--live); border-radius: 8px; padding: 4px 16px 10px; margin: 0 0 16px; }
.live h2 { margin: 6px 0; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.month { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.month-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.month-head a { text-decoration: none; font-size: 20px; padding: 0 8px; }
.calendar { border: 0; width: 100%; table-layout: fixed; }
.calendar th { text-align: center; font-size: 11px; padding: 4px 0; border: 0; }
.calendar td { padding: 2px; border: 0; text-align: center; }
.calendar td a { display: block; position: relative; padding: 6px 0; border-radius: 6px; text-decoration: none; color: var(--text); font-variant-numeric: tabular-nums; font-size: 14px; }
.calendar td a:hover { background: var(--selected); }
.calendar td.out a { color: var(--muted); opacity: .5; }
.calendar td.has-data a { background: var(--selected); }
.calendar td.has-flight a { font-weight: 700; }
.calendar td.has-flight a::after, .legend .key.has-flight { content: ""; position: absolute; left: 50%; bottom: 2px; width: 5px; height: 5px; margin-left: -2.5px; border-radius: 50%; background: var(--igc); }
.calendar td.today a { box-shadow: inset 0 0 0 1px var(--accent); }
.calendar td.selected a { background: var(--accent); color: #fff; }
.legend { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; margin: 8px 0; }
.legend .key { display: inline-block; width: 12px; height: 12px; border-radius: 3px; position: relative; }
.legend .key.has-data { background: var(--selected); border: 1px solid var(--border); }
.legend .key.has-flight { position: static; width: 8px; height: 8px; margin: 0 0 0 8px; border-radius: 50%; }
.date-jump label { font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.date-jump input { font: inherit; font-size: 14px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }
@media (max-width: 900px) {
  .day-layout { grid-template-columns: 1fr; }
  .day-side { position: static; order: -1; }
  .month { max-width: 360px; }
}
.day-link { font-size: 14px; font-weight: 400; margin-left: 8px; white-space: nowrap; }
