:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --text: #13202e;
  --muted: #5f6d7c;
  --line: #d9e0e8;
  --line-strong: #b5c1ce;
  --brand: #0f2a4a;
  --accent: #1d5fd1;
  --accent-text: #ffffff;
  --gold: #c99a1c;
  --good: #1a7f45;
  --good-bg: #e3f4ea;
  --warn: #9a5b00;
  --warn-bg: #fff2d9;
  --bad: #b3261e;
  --bad-bg: #fde7e5;
  --radius: 10px;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d141c;
    --surface: #152130;
    --surface-2: #1a2838;
    --text: #e6edf4;
    --muted: #96a5b5;
    --line: #273648;
    --line-strong: #3a4d63;
    --brand: #0a1b30;
    --accent: #5b95f5;
    --accent-text: #0b1420;
    --gold: #e2b947;
    --good: #5cc98a;
    --good-bg: #133222;
    --warn: #f0b44c;
    --warn-bg: #3a2a0b;
    --bad: #ff8a80;
    --bad-bg: #3d1513;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
p { margin: .4rem 0; }
code, .mono { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.ok, .good { color: var(--good); }
.bad { color: var(--bad); }
.boot { padding: 2rem; color: var(--muted); }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1.5rem;
  padding: .6rem max(16px, env(safe-area-inset-left));
  background: var(--brand); color: #fff;
}
.brand { display: flex; align-items: center; gap: .55rem; color: #fff; font-weight: 650; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.mainnav { display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; }
.mainnav a { color: #c9d6e6; padding: .4rem .7rem; border-radius: 8px; white-space: nowrap; }
.mainnav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.mainnav a.active { background: rgba(255,255,255,.14); color: #fff; }
.content { max-width: 1280px; margin: 0 auto; padding: 1.25rem 16px 4rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin: .25rem 0 1rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
@media (max-width: 720px) {
  .topbar { flex-direction: column; align-items: stretch; gap: .35rem; padding-bottom: .4rem; }
  .content { padding-top: 1rem; }
}

/* ---------- cards, buttons ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.card.error { border-color: var(--bad); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.warnbox { background: var(--warn-bg); border-color: transparent; color: var(--warn); }
.warnbox ul { margin: 0; padding-left: 1.2rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 1rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: 38px; padding: .45rem .9rem;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.big { min-height: 46px; padding: .6rem 1.3rem; font-size: 1rem; }
.btn.tiny { min-height: 30px; padding: .2rem .5rem; font-size: .8rem; }
.btn.busy { opacity: .6; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }

.chip { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.chip.good { background: var(--good-bg); color: var(--good); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }

/* ---------- dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; }
.stat { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: .6rem .75rem; }
.stat-label { color: var(--muted); font-size: .8rem; }
.stat-value { font-family: var(--mono); font-size: 1.35rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); font-size: .78rem; }
.review { margin: 0; padding-left: 1.1rem; }
.review li { margin: .25rem 0; }
.flights { list-style: none; margin: 0; padding: 0; }
.flights li a { display: grid; grid-template-columns: 6.5rem 1fr 1fr 4rem; gap: .5rem; padding: .5rem .25rem; border-top: 1px solid var(--line); color: var(--text); }
.flights li a:hover { background: var(--surface-2); text-decoration: none; }
.f-time { text-align: right; }
@media (max-width: 560px) { .flights li a { grid-template-columns: 5.5rem 1fr 3.5rem; } .f-ac { display: none; } }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: .75rem; }
table { border-collapse: collapse; width: 100%; }
.plain th, .plain td { padding: .5rem .7rem; border-bottom: 1px solid var(--line); text-align: left; }
.plain thead th { font-size: .8rem; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.plain tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }

.logbook { font-size: .82rem; }
.logbook th, .logbook td { border: 1px solid var(--line); padding: .3rem .4rem; white-space: nowrap; }
.logbook thead th { background: var(--surface-2); font-size: .74rem; font-weight: 600; text-align: center; vertical-align: bottom; }
.logbook thead th.grp { border-bottom-color: var(--line-strong); }
.logbook td.wide, .logbook th.wide { white-space: normal; min-width: 14rem; text-align: left; }
.logbook td.strong { font-weight: 700; }
.logbook tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.logbook tbody tr:hover td { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.logbook tbody td:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; }
.logbook tr.needs-review td { background: var(--warn-bg) !important; }
.logbook tfoot th, .logbook tfoot td { background: var(--surface-2); font-weight: 600; }
.logbook tfoot .tot-label { text-align: right; position: sticky; left: 0; }
.logbook tfoot tr.tot-all td, .logbook tfoot tr.tot-all th { border-top: 2px solid var(--line-strong); font-weight: 750; }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: .9rem; overflow-x: auto; }
.tabs a { padding: .5rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.pager { display: flex; gap: .35rem; align-items: center; margin-bottom: .75rem; flex-wrap: wrap; }
.pager select { min-height: 38px; }

/* ---------- entry ---------- */
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .15rem 1.25rem; margin: 0; }
.fields dt { color: var(--muted); font-size: .78rem; margin-top: .5rem; }
.fields dd { margin: 0; overflow-wrap: anywhere; }
h1.voided { text-decoration: line-through; color: var(--muted); }
.history { list-style: none; margin: 0; padding: 0; }
.history > li { border-left: 3px solid var(--line-strong); padding: .3rem 0 .6rem .8rem; margin-left: .2rem; }
.history > li + li { margin-top: .3rem; }
.changes { margin: .25rem 0; padding-left: 1.1rem; }
del { color: var(--bad); }
ins { color: var(--good); text-decoration: none; font-weight: 600; }
.void-form { max-width: 560px; }

/* ---------- forms ---------- */
label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 8px;
  padding: .5rem .6rem; min-height: 40px; width: 100%;
}
textarea { resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; }
.entry-form { max-width: 980px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin: 0 0 1rem; padding: .8rem 1rem 1rem; }
legend { font-weight: 650; padding: 0 .35rem; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; }
@media (max-width: 760px) { .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid4 > span:empty { display: none; } }
.stack { display: flex; flex-direction: column; gap: .65rem; }
.field-label { font-size: .85rem; color: var(--muted); }
.with-btn { display: flex; gap: .35rem; align-items: center; }
.check-label { flex-direction: row; align-items: center; gap: .45rem; color: var(--text); margin-top: .5rem; }
.segmented { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line-strong); border-radius: 9px; overflow: hidden; width: fit-content; max-width: 100%; }
.segmented label { flex-direction: row; color: var(--text); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { padding: .5rem .9rem; cursor: pointer; border-right: 1px solid var(--line); }
.segmented label:last-child span { border-right: 0; }
.segmented input:checked + span { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.segmented input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: -3px; }
.derived { margin: 0; }
.checks-card h2 { margin-bottom: .4rem; }
.check { padding: .15rem 0; }
.check.warn { color: var(--warn); }
.form-error { color: var(--bad); min-height: 1em; }
.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.reason { border-color: var(--gold); }
.inline-form { display: flex; gap: .5rem; margin-top: .75rem; flex-wrap: wrap; }
.inline-form input { max-width: 260px; }

/* ---------- sign-in ---------- */
.signin-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--brand), var(--bg) 70%); }
.signin { width: 100%; max-width: 400px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: .5rem; padding: 2rem 1.5rem; }
.signin form { width: 100%; text-align: left; }
.token-login { border-top: 1px solid var(--line); padding-top: .8rem; margin-top: .5rem; }

/* ---------- print ---------- */
.print-doc { padding: 16px; }
.print-toolbar { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.print-page { background: #fff; color: #000; padding: 10mm; margin-bottom: 1rem; border: 1px solid var(--line); overflow-x: auto; }
.print-page .logbook th, .print-page .logbook td { border-color: #999; background: #fff !important; color: #000; }
.print-head { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: 4mm; font-size: 11pt; }
.print-foot { display: flex; gap: 2rem; align-items: flex-end; margin-top: 6mm; font-size: 9pt; flex-wrap: wrap; }
.sigline { border-top: 1px solid #000; min-width: 60mm; padding-top: 1mm; margin-top: 10mm; }
.sigline.short { min-width: 30mm; }
@media print {
  @page { size: A4 landscape; margin: 8mm; }
  body { background: #fff; }
  .no-print { display: none !important; }
  .print-doc { padding: 0; }
  .print-page { border: 0; padding: 0; margin: 0; page-break-after: always; overflow: visible; }
  .print-page .logbook { font-size: 6.6pt; width: 100%; }
  .print-page .logbook td.wide { min-width: 0; max-width: 55mm; }
  .print-page .logbook th, .print-page .logbook td { padding: 1px 2px; }
  .print-page .logbook tbody td:first-child, .print-page .logbook tfoot .tot-label { position: static; }
}

/* ---------- entry type, signature, photos ---------- */
.type-picker { max-width: 360px; margin-bottom: 1rem; }
.type-picker select { font-weight: 600; color: var(--text); }
.span2 { grid-column: span 2; }
.sig-wrap { position: relative; margin-top: .75rem; }
.sig-canvas { display: block; width: 100%; height: 190px; background: #fff; border: 1px solid var(--line-strong); border-radius: 8px; touch-action: none; cursor: crosshair; }
.sig-line { position: absolute; left: 14px; right: 14px; bottom: 36px; border-bottom: 1px dashed #9aa6b2; color: #9aa6b2; font-size: .8rem; line-height: 1; pointer-events: none; }
.sig-actions { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-top: .4rem; }
.photo-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; margin-bottom: .6rem; }
.photo { display: flex; flex-direction: column; gap: .3rem; }
.photo img, .photo-grid img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: var(--surface-2); }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .75rem; margin-top: .75rem; }
.photo-grid figure, .sig-card { margin: 0; }
.photo-grid figcaption, .sig-card figcaption { font-size: .85rem; display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-top: .3rem; }
.sig-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .75rem; }
.sig-card img { width: 100%; height: 110px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
.warn { color: var(--warn); }
.sig-thumb { height: 18px; vertical-align: middle; margin-left: .35rem; background: #fff; border-radius: 2px; }
.photo-mark { color: var(--muted); }
@media (max-width: 760px) { .span2 { grid-column: span 2; } }
@media print { .sig-thumb { height: 14px; } .photo-mark { display: none; } }
