:root {
  --bg: #000;
  --header: #8c8c8c;
  --header-text: #fff;
  --line: #000;
  --text: #f2f2f2;
  --muted: #9aa0a6;
  --box: #1b1b1b;
  --box-border: #555;
  --grp-border: #777;
  --accent: #3b82f6;
  --warn: #f59e0b;
  --danger: #ef4444;
  --bar-h: 56px;        /* height of the "press here" trigger bar */
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;            /* the sheet scrolls internally; drawer slides off-screen */
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  /* bottom inset is handled by the fixed trigger bar / drawer, not here */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

/* ===== Sheet ===== */
/* pad the bottom so the last rows / chart clear the fixed trigger bar */
.sheet-wrap { flex: 1; overflow: auto; min-height: 0; padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom) + 10px); }

.sheet {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto; /* columns size to content: wide values show fully, narrow ones shrink */
  font-variant-numeric: tabular-nums;
}

.sheet thead th {
  position: sticky;
  z-index: 2;                 /* keep the fixed header above the scrolling rows */
  background: var(--header);
  color: var(--header-text);
  border: 2px solid var(--line);
  padding: 6px 3px;
  font-size: 0.95rem;
  text-align: center;
}
/* grp-row height MUST equal the sub-row's `top`, otherwise the few-px gap between
   the two sticky rows lets scrolling data show through behind the header */
.sheet thead .grp-row th { top: 0; height: 38px; font-weight: 700; font-size: 1.05rem; }
.sheet thead .sub-row th { top: 37px; font-weight: 600; font-size: 0.85rem; }

.sheet tbody td {
  border: 1px solid #262626;
  padding: 9px 2px;
  text-align: center;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sheet tbody tr:nth-child(even) td { background: #0c0c0c; }
.sheet tbody tr.editing td { background: rgba(59, 130, 246, 0.18); }
.sheet td.c-time { font-weight: 700; }
.sheet td.sum.drop, .sheet td.oob { color: var(--warn); font-weight: 700; }

/* fixed-ish widths for the narrow columns so the sheet stays tidy */
.c-time { width: 76px; }
.c-ap { width: 38px; }
.c-act { width: 66px; }
.col-irs { width: 40px; }

.row-actions { display: inline-flex; gap: 2px; }
.icon-btn {
  background: transparent; border: none; cursor: pointer;
  font-size: 1.1rem; line-height: 1; padding: 4px 6px; color: var(--muted);
}
.icon-btn.del:active { color: var(--danger); }

th.c-act { padding: 5px 5px; }
.copy-th {
  display: block; width: 100%;
  background: #2b2b2b; color: #fff; border: 1px solid #000;
  border-radius: 6px; padding: 6px 6px; font-weight: 700; font-size: 0.8rem; cursor: pointer;
}
.copy-th + .copy-th { margin-top: 5px; }
.copy-th:active { background: var(--accent); }
.clearall-th { background: #5a2222; }
.clearall-th:active { background: var(--danger); }

.empty-hint { color: var(--muted); text-align: center; padding: 28px 16px; font-size: 0.95rem; }

/* ===== Fuel-used vs time chart (vanilla SVG, below the data lines) ===== */
.chart-wrap { padding: 6px 12px 20px; }
.chart-wrap[hidden] { display: none; }
.chart-title { color: #cfd6df; font-size: 0.9rem; font-weight: 600; letter-spacing: 0.02em; text-align: center; margin: 4px 2px 8px; }
.chart {
  background: linear-gradient(180deg, #0b0f16 0%, #0c0c0c 100%);
  border: 1px solid #20262e; border-radius: 10px; padding: 6px 8px;
}
.cg-svg { width: 100%; height: auto; display: block; }
.cg-grid { stroke: rgba(255, 255, 255, 0.07); stroke-width: 1; }
.cg-axis { stroke: rgba(255, 255, 255, 0.25); stroke-width: 1; }
.cg-line { stroke: #6db3ff; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.cg-dot { fill: #6db3ff; }
.cg-avg { stroke: #c9d2dd; stroke-width: 2; stroke-dasharray: 7 5; opacity: 0.85; fill: none; }
.cg-leg { fill: #c9d2dd; font-size: 12px; }
.cg-yl { fill: var(--muted); font-size: 13px; text-anchor: end; font-variant-numeric: tabular-nums; }
.cg-xl { fill: var(--muted); font-size: 13px; text-anchor: middle; font-variant-numeric: tabular-nums; }
.cg-axtitle { fill: #7e8794; font-size: 12px; }

/* ===== Entry panel (slide-up bottom sheet) ===== */
.entry {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  max-height: 88dvh;
  overflow-y: auto;
  border-top: 2px solid #2b3440;
  border-radius: 16px 16px 0 0;
  padding: 8px 14px 14px;
  padding-left: calc(14px + env(safe-area-inset-left));
  padding-right: calc(14px + env(safe-area-inset-right));
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  background: #5c6c86; /* Airbus FCU slate-blue panel */
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.5);
  transform: translateY(100%);   /* hidden below the screen by default */
  transition: transform 0.38s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}
body.entry-open .entry { transform: translateY(0); }

/* little grab handle at the top of the sheet */
.entry-grip {
  width: 44px; height: 5px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.45);
  margin: 0 auto 8px;
}

/* full-width bar that opens the entry sheet */
.entry-trigger {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  border: 0; border-top: 2px solid #2b3440; cursor: pointer;
  padding: 17px 12px;
  padding-bottom: calc(17px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #6d7e9a 0%, #5c6c86 100%);
  color: #fff; font-weight: 700; font-size: 0.95rem; letter-spacing: 0.08em;
  white-space: nowrap;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.45);
  transition: opacity 0.25s ease;
}
.entry-trigger:active { background: linear-gradient(180deg, #5c6c86 0%, #4f5d75 100%); }
.entry-trigger .et-chevron {
  font-size: 0.8rem; line-height: 1;
  animation: etbob 1.8s ease-in-out infinite;
}
@keyframes etbob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
body.entry-open .entry-trigger { opacity: 0; pointer-events: none; }

.entry-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px 10px;
}
.linkbtn {
  background: none; border: none; color: var(--text);
  font-size: 1rem; cursor: pointer; padding: 4px 2px;
}
.linkbtn:active { color: var(--accent); }
.mode-info { flex: 1; text-align: center; line-height: 1.25; padding: 0 8px; }
#modeLine1 { display: block; font-weight: 600; font-size: 0.95rem; color: var(--text); }
#modeLine2 { display: block; font-size: 0.8rem; color: #d6dbe2; }
.app-ver { display: block; font-size: 0.68rem; color: var(--muted); margin-top: 3px; letter-spacing: 0.02em; }
.checkbtn {
  width: 54px; height: 54px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.9rem; line-height: 1;
  color: #6b7280;                       /* gray checkmark: not all fields complete */
  background: linear-gradient(#1c222b, #0e1218);
  border: 1px solid #000;
  border-radius: 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: color 0.15s ease;
}
.checkbtn:active { box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.7); }
.checkbtn.complete { color: #2fd441; text-shadow: 0 0 9px rgba(47, 212, 65, 0.65); }  /* all fields complete */

.bar-right { display: flex; align-items: center; gap: 12px; }
.clearbtn {
  height: 54px; padding: 0 18px;
  display: inline-flex; align-items: center; justify-content: center;
  color: #e8eaed; font-size: 0.95rem; font-weight: 600;
  background: linear-gradient(#1c222b, #0e1218);
  border: 1px solid #000;
  border-radius: 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  cursor: pointer;
}
.clearbtn:active { box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.7); }

.error { color: var(--danger); font-size: 0.9rem; margin: 0 0 8px; padding: 0 2px; }

.groups { display: flex; flex-wrap: wrap; gap: 12px; }

.grp {
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 10px;
  margin: 0;
  padding: 10px 12px 12px;
  min-width: 0;
}
.grp legend {
  padding: 0 8px;
  color: #fff;
  font-size: 0.9rem;
}
.grp .info { color: #cfd6df; cursor: help; }

/* group widths so they flow into ~2 rows on iPad landscape */
.grp-ap    { flex: 1 1 230px; }
.grp-alt   { flex: 3 1 440px; }
.grp-fuel  { flex: 2 1 340px; }
.grp-pitch { flex: 1 1 220px; }
.grp-oil   { flex: 1 1 200px; }
.grp-o2    { flex: 1.2 1 240px; }
.grp-irs   { flex: 1.5 1 300px; }

.cols { display: flex; gap: 10px; }
.cols .in { flex: 1; }

.in { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.in > span { font-size: 0.72rem; color: #e2e6ec; }

.grp input {
  width: 100%;
  background: #050505;                       /* black LCD-style window */
  border: 2px solid;
  border-color: #2c3645 #7e90aa #8a9bb5 #2c3645;  /* chamfer: dark top/left, light bottom/right */
  border-radius: 6px;
  color: #6db3ff;
  padding: 11px 10px;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  box-shadow:
    inset 0 3px 7px rgba(0, 0, 0, 0.95),     /* deep recess */
    inset 0 -1px 2px rgba(255, 255, 255, 0.05),
    0 1px 1px rgba(255, 255, 255, 0.10);     /* outer lip catching light */
}
/* erroneous parameter: amber, mirrors the .oob/.drop cells in the table */
.grp input.oob {
  color: var(--warn);
  border-color: #2c3645 var(--warn) var(--warn) #2c3645;
  box-shadow: inset 0 3px 7px rgba(0, 0, 0, 0.95), 0 0 0 2px rgba(245, 158, 11, 0.45);
}
.grp input:focus {
  outline: none;
  border-color: #2c3645 var(--accent) var(--accent) #2c3645;
  box-shadow: inset 0 3px 7px rgba(0, 0, 0, 0.95), 0 0 0 2px rgba(59, 130, 246, 0.4);
}
.grp input[readonly] { background: #050505; color: #49c14b; }
.grp input[readonly].oob { color: var(--warn); }   /* SUM amber overrides its green */

/* ===== Seven-segment altimeter displays (same look as EBT_APP timers/chronos) ===== */
/* The real <input> is laid transparently over an SVG seven-segment readout that is
   redrawn live as the pilot types — so editing/auto-advance is unchanged but the
   value reads out like the avionics LCD timers in EBT_APP. */
.seg-field { position: relative; display: block; }

.seg-display {
  display: flex;
  align-items: center;
  justify-content: center;   /* digit block centered in the window */
  gap: 0;
  min-height: 46px;
  padding: 8px 7px;
  border-radius: 6px;
  border: 2px solid;
  border-color: #0f172a #475569 #475569 #0f172a;   /* recessed bezel: dark top/left, light bottom/right */
  background: linear-gradient(180deg, #0b0f16 0%, #111827 100%);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.75), inset 0 -1px 0 rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.seg-display .seg-svg { display: block; filter: drop-shadow(0 0 2px rgba(148, 163, 184, 0.28)); }

/* transparent editable layer on top of the readout (override the blue .grp input look) */
.grp input.seg-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: transparent;
  caret-color: transparent;       /* the lit segments are the cursor */
  font-size: 16px;                /* keep ≥16px so iOS doesn't zoom on focus */
  box-shadow: none;
  z-index: 1;
}
.grp input.seg-input:focus,
.grp input.seg-input.oob {
  border: 0;
  box-shadow: none;
  color: transparent;
}

/* focus / out-of-bounds rings live on the bezel, mirroring the blue/amber input states */
.seg-field:focus-within .seg-display {
  border-color: #0f172a var(--accent) var(--accent) #0f172a;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.75), 0 0 0 2px rgba(59, 130, 246, 0.4);
}
.seg-input.oob + .seg-display {
  border-color: #0f172a var(--warn) var(--warn) #0f172a;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.75), 0 0 0 2px rgba(245, 158, 11, 0.45);
}

.pair { display: flex; align-items: flex-end; gap: 8px; }
.pair .in { flex: 1; }
.pair > input { flex: 1; }

.fuel-row { display: flex; align-items: flex-end; gap: 8px; }
.fuel-row .in { flex: 1; }
.op { color: #e2e6ec; font-size: 1.2rem; padding-bottom: 10px; }

/* Autopilot toggles */
/* Autopilot pushbuttons (mimic the real FCU AP1/AP2 buttons) */
.ap-toggles { display: flex; gap: 18px; flex-wrap: nowrap; justify-content: center; }
.ap-toggle {
  flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  width: 78px; padding: 8px 8px 9px;
  background: #0b0b0b;
  border: 2px solid #c2b48c;          /* tan bezel like the FCU */
  border-radius: 7px;
  box-shadow: 0 3px 5px rgba(0, 0, 0, 0.55);
  cursor: pointer;
}
.ap-toggle:active { background: #050505; }

/* green legend block divided into three segments */
.ap-light {
  width: 38px; height: 26px;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
  padding: 3px 5px;
  background: #060906; border: 1px solid #000; border-radius: 2px;
  box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.9);
}
.ap-light i {
  display: block; width: 100%; height: 6px; border-radius: 1px;
  background: #283028;                 /* off: dim */
  transition: background 0.12s ease, box-shadow 0.12s ease;
}
.ap-toggle.on .ap-light i {
  background: linear-gradient(#62ff44, #21cc05);   /* on: bright green */
  box-shadow: 0 0 7px rgba(70, 255, 45, 0.9);
}

.ap-label {
  color: #fff;
  font-weight: 700; font-size: 0.95rem; letter-spacing: 0.5px;
}

/* ===== Modals ===== */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; background: rgba(0, 0, 0, 0.65);
}
.modal[hidden] { display: none; }

.caution-card {
  background: #0a0a0a;
  border: 3px solid #f5a623;
  border-radius: 4px;
  padding: 22px 26px;
  width: 100%;
  max-width: 760px;
  max-height: 86vh;
  overflow: auto;
}
.caution-title { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; font-size: 1.5rem; font-weight: 700; }
.warn-ico { color: #f5a623; font-size: 1.6rem; }
.caution-rule { border: none; border-top: 1px solid #3a3a3a; margin: 12px 0; }
.caution-head { font-size: 1.2rem; margin: 6px 0 16px; }
.caution-body { color: #cfcfcf; font-size: 0.95rem; line-height: 1.5; }
.caution-body p { margin: 10px 0; }
.caution-list { margin: 10px 0; padding-left: 22px; }
.caution-list li { margin: 5px 0; font-variant-numeric: tabular-nums; }
.caution-actions { display: flex; justify-content: flex-end; margin-top: 6px; }
.okbtn {
  background: transparent; color: #fff;
  border: 1px solid #888; border-radius: 4px;
  padding: 10px 26px; font-size: 1rem; cursor: pointer; text-decoration: underline;
}
.okbtn:active { background: #222; }
.okbtn.primary { border-color: var(--accent); background: rgba(59, 130, 246, 0.18); text-decoration: none; }

/* Initial FOB chip in the entry bar */
.bar-left { display: flex; align-items: center; gap: 14px; }
.init-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #1b1b1b; border: 1px solid #555; border-radius: 999px;
  color: #fff; padding: 6px 12px; font-size: 0.85rem; cursor: pointer; white-space: nowrap;
}
.init-chip .muted { color: var(--muted); }
.init-chip strong { color: #6db3ff; font-variant-numeric: tabular-nums; }
.init-chip .chip-edit { color: var(--accent); }
.init-chip.unset { box-shadow: inset 0 0 0 1px var(--accent); }

/* Initial FOB modal */
.init-card {
  background: #111; border: 1px solid #555; border-radius: 10px;
  padding: 22px; width: 100%; max-width: 420px;
}
.init-card h2 { margin: 0 0 4px; font-size: 1.15rem; }
.init-sub { color: var(--muted); margin: 0 0 14px; font-size: 0.9rem; }
.init-card input {
  width: 100%; background: linear-gradient(180deg, #121212, #1d1d1d); border: 1px solid #000;
  border-radius: 6px; color: #6db3ff; padding: 12px; font-size: 1.3rem;
  font-variant-numeric: tabular-nums;
  box-shadow: inset 2px 2px 5px rgba(0, 0, 0, 0.85), inset -1px -1px 2px rgba(255, 255, 255, 0.05);
}
.init-card input:focus { outline: none; border-color: var(--accent); }
.init-actions { display: flex; gap: 12px; margin-top: 16px; }
.init-actions .okbtn { flex: 1; }

/* delete confirmation modal */
.confirm-card {
  background: #111; border: 1px solid #555; border-radius: 10px;
  padding: 22px; width: 100%; max-width: 380px;
}
.confirm-card h2 { margin: 0 0 8px; font-size: 1.15rem; }
.confirm-card p { color: var(--muted); margin: 0 0 18px; }
.confirm-actions { display: flex; gap: 12px; }
.confirm-actions .okbtn { flex: 1; text-decoration: none; }
.okbtn.danger { border-color: var(--danger); color: #fff; background: rgba(239, 68, 68, 0.18); }
