:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #d9dee6;
  --text: #18202b;
  --muted: #5d6877;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --ok: #1d7a45;
  --ok-bg: #e3f4ea;
  --warn: #9a6400;
  --warn-bg: #fdf1d8;
  --bad: #b3261e;
  --bad-bg: #fbe5e3;
  --radius: 8px;
  --series-1: #2a78d6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b;
    --surface: #1a2029;
    --surface-2: #232a35;
    --border: #323b48;
    --text: #e4e8ee;
    --muted: #97a2b1;
    --accent: #5b9cf5;
    --accent-text: #0b1220;
    --ok: #6fd39a;
    --ok-bg: #173226;
    --warn: #f0bf5c;
    --warn-bg: #3a2e12;
    --bad: #f28b82;
    --bad-bg: #3b1d1b;
    --series-1: #3987e5;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
h1, h2 { margin: 0; }
h1 { font-size: 18px; }
h2 { font-size: 16px; }
h2 small { color: var(--muted); font-weight: normal; font-size: 13px; margin-left: 6px; }

.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
nav { display: flex; gap: 4px; flex-wrap: wrap; min-width: 0; }
.tab { background: none; border: 0; padding: 8px 12px; border-radius: 6px; color: var(--muted); font-weight: 600; cursor: pointer; }
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--accent); color: var(--accent-text); }

main { padding: 20px; max-width: 1500px; margin: 0 auto; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 24px 0 10px; }
.panel > .section-head:first-child { margin-top: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.form-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); font-weight: 600; }
label.block { margin-top: 12px; }
label.check { flex-direction: row; align-items: center; gap: 6px; font-size: 14px; color: var(--text); font-weight: normal; align-self: end; padding-bottom: 8px; }
label.check small { color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px; padding: 7px 8px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=number] { width: 100%; text-align: right; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
textarea { resize: vertical; width: 100%; }
.ident { text-transform: uppercase; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.row > label { min-width: 110px; }
.row > label.grow { flex: 1; min-width: 160px; }
.total-row { margin-top: 12px; }
.total input { font-weight: 700; width: 120px; }
.quickfill { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; padding-bottom: 4px; }
.quickfill span { color: var(--muted); font-size: 12px; margin-right: 4px; }
.quickfill button { padding: 4px 8px; font-size: 12px; }
.grid-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px 12px; margin-top: 14px; }

button, .button {
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-block;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 7px 12px; border-radius: 6px; white-space: nowrap;
}
button:hover, .button:hover { border-color: var(--accent); }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.ghost, .button.ghost { background: transparent; }
button.danger { color: var(--bad); }
button.small { padding: 2px 8px; font-size: 12px; }
.actions { display: flex; justify-content: flex-end; margin-top: 12px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input[type=search] { width: 240px; }
.file-btn { flex-direction: row; font-size: 14px; color: var(--text); }

.warnings:empty { display: none; }
.warnings { margin-top: 12px; padding: 8px 12px; border-radius: 6px; background: var(--warn-bg); color: var(--warn); font-size: 13px; }
.warnings div::before { content: "⚠ "; }

.toast { position: fixed; bottom: 20px; right: 20px; padding: 10px 16px; border-radius: 6px; z-index: 20;
  background: var(--text); color: var(--bg); box-shadow: 0 4px 16px rgba(0,0,0,.25); max-width: 420px; }
.toast.error { background: var(--bad); color: #fff; }

/* tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.data th { background: var(--surface-2); font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); position: sticky; top: 0; }
table.data td.num, table.data th.num { text-align: right; }
table.data td.zero { color: var(--border); }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tfoot td { font-weight: 700; background: var(--surface-2); border-bottom: 0; }
table.data td.remarks { white-space: normal; min-width: 180px; max-width: 320px; color: var(--muted); }
table.data td.empty { text-align: center; color: var(--muted); padding: 24px; white-space: normal; }
table.log td.ac small { color: var(--muted); }
tr.editing { outline: 2px solid var(--accent); outline-offset: -2px; }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); margin-right: 4px; }

/* stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(140px, 100%), 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.stat .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.headline { border-color: var(--accent); }

.currency-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); gap: 10px; }
.cur { border-radius: var(--radius); padding: 12px 14px; border: 1px solid var(--border); background: var(--surface); }
.cur .title { font-weight: 700; display: flex; justify-content: space-between; gap: 8px; }
.cur .rule { font-size: 12px; color: var(--muted); }
.cur .detail { margin-top: 6px; font-size: 13px; }
.badge { white-space: nowrap; align-self: flex-start; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 10px; text-transform: uppercase; }
.cur.ok .badge { background: var(--ok-bg); color: var(--ok); }
.cur.soon .badge { background: var(--warn-bg); color: var(--warn); }
.cur.lapsed .badge { background: var(--bad-bg); color: var(--bad); }
.cur.ok { border-left: 4px solid var(--ok); }
.cur.soon { border-left: 4px solid var(--warn); }
.cur.lapsed { border-left: 4px solid var(--bad); }
.period { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

@media (max-width: 640px) {
  main { padding: 12px 16px; }
  .topbar { padding: 10px 16px; gap: 8px; }
  .tab { padding: 6px 8px; }
  .filters input[type=search] { width: 100%; }
}

[hidden] { display: none !important; }
:root { color-scheme: light dark; }
button:disabled { opacity: .35; cursor: not-allowed; }
button:disabled:hover { border-color: var(--border); }

/* ---------- home ---------- */
.hero-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: 12px; }
.cur.hero { padding: 14px 16px; }
.cur.hero .title { font-size: 15px; }
.cur.hero .title small { color: var(--muted); font-weight: 600; margin-left: 4px; margin-right: auto; }
.hero-label { margin-top: 10px; font-size: 12px; color: var(--muted); font-weight: 600; }
.hero-date { font-size: 24px; font-weight: 700; margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.cur.lapsed .hero-date { color: var(--bad); }

.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }

.chart-card { padding: 12px 16px; }
.chart-summary { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.chart { position: relative; height: 260px; outline: none; border-radius: 4px; }
.chart:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.chart svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--border); stroke-width: 1; opacity: .6; }
.chart .grid.base { opacity: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--series-1); transition: opacity .1s; }
.chart .bar.dim { opacity: .35; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; }
.chart .area { fill: var(--series-1); opacity: .12; }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; }
.chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart-tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 10px; box-shadow: 0 4px 14px rgba(0,0,0,.18); white-space: nowrap; font-size: 13px; z-index: 2; }
.chart-tip strong { font-size: 15px; font-variant-numeric: tabular-nums; }
.chart-tip span { color: var(--muted); }
.chart-tip .when { color: var(--muted); font-size: 12px; }
.chart-data { margin-top: 8px; }
.chart-data summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.chart-data .table-wrap { margin-top: 8px; max-height: 280px; overflow-y: auto; }

/* ---------- entry readiness / settings ---------- */
.actions { align-items: center; gap: 12px; }
.missing { color: var(--muted); font-size: 13px; }
button.primary:disabled { background: var(--surface-2); border-color: var(--border); color: var(--muted); opacity: 1; }
.tag.default { color: var(--accent); border-color: var(--accent); background: transparent; }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

/* ---------- delete / confirmation ---------- */
#flight-delete { margin-right: auto; }
table.log th:last-child, table.log td:last-child { position: sticky; right: 0; background: var(--surface);
  box-shadow: -1px 0 0 var(--border); }
table.log th:last-child { background: var(--surface-2); }
table.log tbody tr:hover td:last-child, table.log tfoot td:last-child { background: var(--surface-2); }
button.danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
button.danger-solid:hover { filter: brightness(1.1); border-color: var(--bad); }
.dialog { border: 1px solid var(--border); border-radius: 10px; padding: 20px; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 16px 48px rgba(0,0,0,.35); }
.dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog h3 { margin: 0 0 8px; font-size: 17px; }
.confirm-body p { margin: 0 0 12px; color: var(--muted); }
.confirm-body dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0;
  padding: 10px 12px; background: var(--surface-2); border-radius: 6px; }
.confirm-body dt { color: var(--muted); font-size: 12px; font-weight: 600; padding-top: 1px; }
.confirm-body dd { margin: 0; overflow-wrap: anywhere; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- simulator filter ---------- */
.sim-filter { max-width: 200px; }

/* ---------- add & duplicate ---------- */
button.secondary-small { font-size: 12px; padding: 5px 10px; background: transparent; color: var(--accent); border-color: var(--border); }
button.secondary-small:hover:not(:disabled) { border-color: var(--accent); }
button.secondary-small:disabled { color: var(--muted); }

/* ---------- aircraft combobox ---------- */
.combo-wrap { position: relative; display: flex; flex-direction: column; gap: 3px; min-width: 200px; }
.combo-wrap > label { display: block; }
.combo-input { width: 100%; text-transform: uppercase; }
.combo-input.invalid { border-color: var(--bad); outline-color: var(--bad); }
.combo-list { position: absolute; top: 100%; left: 0; right: 0; z-index: 10; margin: 4px 0 0; padding: 4px;
  list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); max-height: 260px; overflow-y: auto; }
.combo-list li { display: flex; align-items: baseline; gap: 6px; padding: 6px 8px; border-radius: 4px; cursor: pointer; }
.combo-list li small { margin-left: auto; color: var(--muted); font-size: 11px; }
.combo-list li.active { background: var(--accent); color: var(--accent-text); }
.combo-list li.active small { color: inherit; opacity: .8; }
.combo-list li.empty { color: var(--muted); cursor: default; }
.row > .combo-wrap.grow { flex: 1; min-width: 200px; }

/* validation marks on saved entries */
.issue-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0 0 10px; padding: 8px 12px; border-radius: 6px; background: var(--warn-bg); color: var(--warn); font-size: 13px; }
.issue-banner span::before { content: "⚠ "; }
.issue-banner[hidden] { display: none !important; }
tr.invalid td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.issue { color: var(--warn); cursor: help; }
td.flag { background: var(--warn-bg); color: var(--warn); }

/* signed-in user + sign-in page */
.user-box { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.user-box[hidden] { display: none !important; }
body.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { max-width: 440px; width: 100%; text-align: center; }
.login-card h1 { margin: 0 0 16px; }
.login-card ul, .login-card p { text-align: left; font-size: 14px; }
.login-card .button { display: inline-block; text-decoration: none; }
.login-error { color: var(--bad); background: var(--bad-bg); padding: 8px 12px; border-radius: 6px; }
