:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --border: #475569;
  --accent: #f59e0b;
  --green: #16a34a;
  --red: #dc2626;
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #e2e8f0;
  --text: #0f172a;
  --muted: #475569;
  --border: #cbd5e1;
  --accent: #d97706;
  --green: #15803d;
  --red: #b91c1c;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Top-Left Vertical Rail */
.left-rail {
  width: 68px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.rail-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 4px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}
.rail-btn:disabled { opacity: 0.4; }
.home-btn {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  font-weight: 800;
}

.main-content {
  flex: 1;
  padding: 14px;
  max-width: 780px;
  margin: 0 auto;
  width: 100%;
}

.page { display: none; }
.page.active { display: block; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
}
h1 { margin: 0; font-size: 22px; }
.sub-text { font-size: 12px; color: var(--muted); }

.cert-pill, .station-pill {
  display: inline-block;
  margin-top: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-2);
}
.cert-pill.warn { background: var(--accent); color: #000; }
.cert-pill.expired { background: var(--red); color: #fff; }

/* Flight & Fleet Grid (Overview) */
.flight-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.span-2 { grid-column: span 2; }

.field-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 54px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  text-align: left;
}
.field-box label {
  display: block;
  width: 100%;
  font-size: 10px;
  font-weight: 800;
  color: var(--muted);
  margin-bottom: 3px;
  text-align: left;
}
.field-box input, .field-box select {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  outline: none;
  text-align: left;
  text-align-last: left;
}

.label-with-flag {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 3px;
}
.label-with-flag label {
  width: auto;
  margin-bottom: 0;
}

.etops-flag {
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 900;
  font-size: 9px;
  letter-spacing: 0.4px;
  line-height: 1.2;
}
.etops-flag.is-etops { background: #2563eb; color: #fff; }
.etops-flag.non-etops { background: var(--surface-2); color: var(--muted); }

.tail-row {
  display: flex;
  gap: 6px;
  align-items: center;
  width: 100%;
}

.primary-sm {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 8px;
  padding: 7px 12px;
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
}

/* Action Grid */
.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.action-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.action-btn strong { font-size: 14px; }
.action-btn.loto-red { background: var(--red); border-color: var(--red); color: #fff; }
.action-btn.loto-green { background: var(--green); border-color: var(--green); color: #fff; }

.full-voice-btn {
  width: 100%;
  margin-bottom: 12px;
  padding: 16px;
}

/* Scratchpad & Close Out */
.scratchpad-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 12px;
}
.scratchpad-box label {
  display: block;
  font-size: 10px;
  font-weight: 800;
  color: var(--muted);
  margin-bottom: 6px;
}
.scratchpad-box textarea {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  resize: vertical;
  outline: none;
  font-family: inherit;
}

.closeout-btn, .verify-all-btn {
  width: 100%;
  padding: 15px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #000;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}

/* Cowl & Routine Grids */
.cowl-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.cowl-btn, .routine-btn {
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 20px 10px;
  text-align: center;
  cursor: pointer;
}
.cowl-btn:active, .routine-btn:active { border-color: var(--accent); }
.cowl-btn strong, .routine-btn strong { display: block; font-size: 16px; margin-top: 4px; }
.tag { font-size: 10px; font-weight: 800; color: var(--accent); text-transform: uppercase; }

.copy-stack { display: flex; flex-direction: column; gap: 10px; }
.copy-bar {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  text-align: left;
  cursor: pointer;
}
.copy-bar:disabled { opacity: 0.45; cursor: default; }
.copy-val { font-size: 15px; font-weight: 700; margin-top: 4px; }

/* LOTO Checklist */
.group-title {
  font-size: 13px;
  text-transform: uppercase;
  color: var(--muted);
  margin: 14px 0 6px;
}
.checklist { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 6px; }
.check-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  cursor: pointer;
}
.radio-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--red);
  flex-shrink: 0;
}
.check-item.done { opacity: 0.6; text-decoration: line-through; }
.check-item.done .radio-dot { background: var(--green); border-color: var(--green); }

/* Settings & History */
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.setting-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.setting-row label { font-size: 14px; font-weight: 700; }
.setting-row input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 8px;
  font-weight: 700;
}

.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-size: 13px;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: #000;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 99;
}
.toast.show { opacity: 1; }