:root {
  --bg: #0b1220;
  --panel: #131c2e;
  --ink: #e6edf7;
  --muted: #8fa3bf;
  --accent: #3fa9f5;
  --card-paper: #fdfdf8;
  --card-ink: #17223b;
  --card-line: #b9c2d4;
  --danger: #e05656;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

/* ── Top bar ─────────────────────────────────────────────── */
#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px max(14px, env(safe-area-inset-left)) 10px max(14px, env(safe-area-inset-right));
  background: var(--panel);
  border-bottom: 1px solid #1f2c45;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-size: 17px; letter-spacing: .3px; white-space: nowrap; }
.brand b { color: var(--accent); }

#tabs { display: flex; gap: 6px; flex: 1; min-width: 120px; }
#tabs .tab {
  border: 1px solid #2a3a5c;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 14px;
  cursor: pointer;
}
#tabs .tab.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.actions { display: flex; gap: 6px; flex-wrap: wrap; }
button {
  font: inherit;
  font-size: 14px;
  border: 1px solid #2a3a5c;
  background: #182540;
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
}
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { color: var(--danger); border-color: #4b2530; background: transparent; }

/* ── Layout ──────────────────────────────────────────────── */
#main { display: grid; place-items: start center; padding: 22px 12px 60px; }
.empty { max-width: 520px; text-align: center; margin-top: 10vh; color: var(--muted); }
.empty h1 { color: var(--ink); font-weight: 600; }
.empty .hint { font-size: 14px; }
body.dragover #main { outline: 3px dashed var(--accent); outline-offset: -14px; border-radius: 20px; }

#card-wrap { width: 100%; max-width: 480px; display: grid; gap: 16px; }

/* ── The card (mirrors the handwritten sheet) ────────────── */
.card {
  background: var(--card-paper);
  color: var(--card-ink);
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0,0,0,.45);
  padding: 20px 22px 18px;
  font-family: "Menlo", "SF Mono", ui-monospace, monospace;
}
.card .datebox {
  display: inline-block;
  border: 2px solid var(--card-ink);
  padding: 2px 10px;
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 10px;
}
.card .flightline {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: .5px;
  margin-bottom: 12px;
}
.card .flightline .altn { color: #64748b; }

.card .times {
  border-collapse: collapse;
  margin: 0 0 14px 2px;
  font-size: 17px;
}
.card .times th {
  font-size: 10px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  padding: 0 10px 2px;
  font-family: inherit;
}
.card .times th.rowlab { padding: 0 6px 0 0; text-align: right; }
.card .times td {
  border: 1.5px solid var(--card-ink);
  padding: 4px 14px;
  font-weight: 700;
  text-align: center;
  min-width: 76px;
}

.card .ladder { margin: 0; }
.card .row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 3.5px 0;
  border-bottom: 1px dotted var(--card-line);
  font-size: 17px;
}
.card .row:last-child { border-bottom: none; }
.card .row .lab { width: 58px; font-weight: 700; flex: none; }
.card .row .val { font-weight: 700; min-width: 90px; }
.card .row .unit { color: #64748b; font-size: 12px; }
.card .row .aux {
  margin-left: auto;
  color: #64748b;
  font-size: 12px;
  font-family: -apple-system, sans-serif;
  text-align: right;
}
.card .row .aux input {
  width: 52px;
  font: inherit;
  border: 1px solid var(--card-line);
  border-radius: 4px;
  padding: 1px 4px;
  text-align: right;
  background: #fff;
  color: var(--card-ink);
}
.card [contenteditable] { outline: none; border-radius: 3px; padding: 0 3px; }
.card [contenteditable]:focus { background: #fff3bf; }
.card [contenteditable].edited { color: #b45309; }

.card .notes {
  margin-top: 14px;
  border-top: 1.5px solid var(--card-ink);
  padding-top: 8px;
  min-height: 46px;
  font-size: 15px;
  white-space: pre-wrap;
}
.card .notes:empty::before { content: "Notes…"; color: #9aa7bd; }

/* ── Details panel ───────────────────────────────────────── */
#details {
  background: var(--panel);
  border: 1px solid #1f2c45;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
}
#details summary { cursor: pointer; color: var(--muted); }
#details-body { padding-top: 10px; display: grid; gap: 6px; }
#details-body .kv { display: flex; gap: 8px; }
#details-body .kv b { color: var(--muted); font-weight: 600; min-width: 108px; }
#details-body .route { font-family: ui-monospace, monospace; font-size: 12.5px; line-height: 1.5; color: var(--ink); }
#details-body table { border-collapse: collapse; margin-top: 2px; }
#details-body td, #details-body th { border: 1px solid #2a3a5c; padding: 3px 10px; font-size: 13px; }
#details-body th { color: var(--muted); font-weight: 600; }

/* ── Display (flight-deck) mode ─────────────────────────── */
body.display #topbar .brand, body.display #tabs { opacity: .35; }
body.display #main { padding-top: 8px; }
body.display #card-wrap { max-width: 690px; }
body.display .card { font-size: 22px; }
body.display .card .flightline { font-size: 26px; }
body.display .card .row { font-size: 24px; padding: 6px 0; }
body.display .card .row .lab { width: 84px; }
body.display .card .times { font-size: 24px; }
body.display #details { display: none; }

/* ── Toast ───────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1c2a47;
  border: 1px solid var(--accent);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  z-index: 50;
  box-shadow: 0 8px 22px rgba(0,0,0,.5);
}

/* ── 4-up fold sheet ─────────────────────────────────────── */
.print4 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  width: 8.2in;
  height: 10.4in;
  margin: 0 auto;
  background: #fff;
}
.print4 .cell { padding: .28in; overflow: hidden; border: .5px dashed #bbb; }
.print4 .cell.flip { transform: rotate(180deg); }
.print4 .card { box-shadow: none; border-radius: 0; padding: 8px 10px; font-size: 11px; }
.print4 .card .flightline { font-size: 13px; margin-bottom: 6px; }
.print4 .card .datebox { font-size: 11px; padding: 1px 6px; margin-bottom: 6px; }
.print4 .card .times { font-size: 11px; margin-bottom: 7px; }
.print4 .card .times td { padding: 2px 8px; min-width: 48px; }
.print4 .card .row { font-size: 11.5px; padding: 1.5px 0; gap: 6px; }
.print4 .card .row .lab { width: 38px; }
.print4 .card .row .aux { display: none; }
.print4 .card .notes { min-height: 24px; font-size: 10px; margin-top: 7px; }

/* ── Print ───────────────────────────────────────────────── */
@media print {
  body { background: #fff; }
  #topbar, #details, #toast { display: none !important; }
  #main { padding: 0; }
  body.print-single .card {
    box-shadow: none;
    width: 4.4in;
    margin: .4in auto;
    border: 1px solid #999;
  }
  body.print-single .print4 { display: none; }
  body.print-4up #main { display: none; }
  body.print-4up .print4[hidden] { display: grid !important; }
  .card [contenteditable]:focus { background: none; }
  .card [contenteditable].edited { color: inherit; }
}
