:root {
  --bg: #0f172a;
  --bg-2: #111c34;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #1e3a8a;
  --brand-2: #2563eb;
  --accent: #db2777;
  --heavy: #fbcfe8;
  --heavy-line: #db2777;
  --light: #dbeafe;
  --light-line: #2563eb;
  --warn: #fde68a;
  --warn-line: #d97706;
  --ok: #16a34a;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(2, 8, 23, 0.10);
  --train: #ede9fe;
  --sim: #fce7f3;
  --meet: #dcfce7;
  --break: #f1f5f9;
  --meal: #fff7ed;
  --custom: #ecfeff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: "Heebo", system-ui, "Segoe UI", Arial, sans-serif;
  background: #eef2f7;
  color: var(--ink);
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
  background: linear-gradient(120deg, var(--bg), var(--bg-2));
  color: #fff;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  font-size: 26px;
  background: rgba(255, 255, 255, .12);
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 12px;
}
.brand h1 { font-size: 18px; margin: 0; }
.brand .sub { margin: 0; font-size: 12px; color: #c7d2fe; }

.tabs { display: flex; gap: 6px; margin-inline-start: auto; }
.tab {
  background: rgba(255, 255, 255, .08);
  color: #e5edff;
  border: 0;
  padding: 9px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  transition: .15s;
}
.tab:hover { background: rgba(255, 255, 255, .18); }
.tab.active { background: #fff; color: var(--brand); }

.actions .day-label { font-size: 13px; color: #c7d2fe; display: flex; gap: 6px; align-items: center; }
.actions input[type="date"] {
  border: 0; border-radius: 8px; padding: 6px 8px; font-family: inherit;
}

/* ---------- Panels ---------- */
main { max-width: 1280px; margin: 0 auto; padding: 22px 18px 60px; }
.panel { display: none; animation: fade .2s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.panel-head { margin-bottom: 14px; }
.panel-head h2 { margin: 0 0 4px; font-size: 22px; color: var(--brand); }
.hint { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.6; }

.card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
}

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.span2 { grid-column: span 2; }
.field.span4 { grid-column: span 4; }
.field label { font-size: 13px; font-weight: 600; color: #374151; }
.field input[type="text"],
.field input[type="time"],
.field input[type="search"],
input[type="search"] {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  font-family: inherit;
  font-size: 14px;
}
.inline { display: flex; align-items: center; gap: 8px; }
.inline input { flex: 1; }

.certs { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.certs legend { font-size: 13px; font-weight: 700; color: var(--brand); padding: 0 6px; }
.cert-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.cert-field { display: flex; flex-direction: column; gap: 4px; }
.cert-field label { font-size: 12.5px; font-weight: 600; color: #374151; }
.cert-field select, #reqForm select, .modal-section select, #reqForm input[type="text"] {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 9px;
  font-family: inherit; font-size: 13.5px; background: #fff;
}
.cert-tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; margin: 2px; white-space: nowrap; background: #f8fafc; border: 1px solid var(--line); border-radius: 7px; padding: 2px 7px; }
.certs-cell { max-width: 520px; }
.lvl { font-size: 11px; font-weight: 800; border-radius: 5px; padding: 1px 6px; }
.lvl.instr { background: #fce7f3; color: var(--accent); }
.lvl.qual { background: #dcfce7; color: #15803d; }
.lvl.trainee { background: #fef3c7; color: #b45309; }
.field.span1 { grid-column: span 1; }

/* date nav */
.nav-day { background: rgba(255,255,255,.12); color: #fff; border: 0; width: 32px; height: 32px; border-radius: 8px; font-size: 20px; cursor: pointer; line-height: 1; }
.nav-day:hover { background: rgba(255,255,255,.25); }
#weekdayLabel { font-weight: 700; color: #fff; margin-inline-end: 4px; }

/* events banner */
.events-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 16px; }
.eb-title { font-weight: 800; color: var(--brand); }
.eb-chip { background: #eef2ff; color: var(--brand); border: 1px solid #c7d2fe; border-radius: 999px; padding: 4px 12px; font-size: 13px; font-weight: 600; }
.check { display: flex; align-items: center; gap: 7px; font-weight: 500; font-size: 13.5px; cursor: pointer; }
.role .check { background: #f8fafc; padding: 10px; border-radius: 8px; border: 1px solid var(--line); }

.actions-row { flex-direction: row; gap: 10px; align-items: center; }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 9px 16px;
  border-radius: 9px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  transition: .15s;
}
.btn:hover { background: #f3f4f6; }
.btn.primary { background: var(--brand-2); color: #fff; border-color: var(--brand-2); }
.btn.primary:hover { background: #1d4ed8; }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.danger:hover { background: #b91c1c; }

/* ---------- Tables ---------- */
.table-head-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 12px; flex-wrap: wrap; }
.table-head-row h3 { margin: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: right; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: none; }
tbody tr:hover { background: #f9fafb; }
.pill { display: inline-block; background: #eef2ff; color: var(--brand); border-radius: 999px; padding: 2px 9px; font-size: 12px; margin: 2px; font-weight: 600; }
.pill.role { background: #fce7f3; color: var(--accent); }
.pill.trainee { background: #fef3c7; color: #b45309; }
.row-actions { display: flex; gap: 6px; }
.icon-btn { border: 0; background: transparent; cursor: pointer; font-size: 16px; padding: 4px; border-radius: 6px; }
.icon-btn:hover { background: #eef2ff; }

/* ---------- Flights grid ---------- */
.flights-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.flight-cell { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; text-align: center; }
.flight-cell .slot { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.flight-cell input { width: 100%; text-align: center; border: 1px solid var(--line); border-radius: 7px; padding: 6px; font-family: inherit; font-size: 16px; font-weight: 700; }
.flight-cell.heavy { background: var(--heavy); border-color: var(--heavy-line); }
.flight-cell.light { background: var(--light); border-color: var(--light-line); }
.flight-cell.night { grid-column: 1 / -1; background: #1e293b; color: #fff; }
.flight-cell.night .slot { color: #cbd5e1; }

.staffing-summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.staff-block { border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.staff-block h4 { margin: 0 0 8px; font-size: 15px; }
.staff-block.heavy { border-inline-start: 5px solid var(--heavy-line); }
.staff-block.light { border-inline-start: 5px solid var(--light-line); }
.staff-block .max-f { font-size: 12px; color: var(--muted); }
.staff-block ul { margin: 8px 0 0; padding-inline-start: 18px; }

/* ---------- Schedule grid ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.legend { font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 12px; }
.legend .dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; margin-inline-end: 4px; vertical-align: -1px; }
.dot.heavy { background: var(--heavy); border: 1px solid var(--heavy-line); }
.dot.light { background: var(--light); border: 1px solid var(--light-line); }
.dot.warn { background: var(--warn); border: 1px solid var(--warn-line); }

.schedule-wrap { overflow-x: auto; padding: 12px; }
.schedule-grid { display: grid; gap: 4px; min-width: 900px; }
.sg-cell { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 8px; min-height: 56px; font-size: 13px; }
.sg-corner { background: var(--brand); color: #fff; font-weight: 700; display: grid; place-items: center; }
.sg-colhead { background: #1e293b; color: #fff; font-weight: 700; text-align: center; display: grid; place-items: center; padding: 8px 4px; }
.sg-rowhead { background: #eef2ff; color: var(--brand); font-weight: 700; display: grid; place-items: center; text-align: center; }
.sg-rowhead small { display: block; font-weight: 500; color: var(--muted); font-size: 11px; }

.sg-cell.assignable { cursor: pointer; transition: .12s; }
.sg-cell.assignable:hover { background: #eef2ff; border-color: var(--brand-2); }
.sg-cell.empty-req { background: var(--warn); border-color: var(--warn-line); }
.sg-cell.conflict { background: #fee2e2; border-color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger); }
.act-item.conflict { outline: 1.5px solid var(--danger); }
.tag.conflict-tag { background: var(--danger); color: #fff; }
.sg-cell.not-required { background: #f1f5f9; opacity: .55; }

.assignee { font-weight: 700; }
.tag { display: inline-block; border-radius: 6px; padding: 1px 6px; font-size: 11px; font-weight: 700; margin-top: 4px; }
.tag.train { background: var(--train); color: #6d28d9; }
.tag.sim { background: var(--sim); color: var(--accent); }
.tag.meet { background: var(--meet); color: #15803d; }
.tag.break { background: var(--break); color: var(--muted); }
.cell-note { color: var(--muted); font-size: 11.5px; margin-top: 3px; }

.activities-cell { text-align: start; display: flex; flex-direction: column; gap: 4px; }
.act-item { display: flex; align-items: center; gap: 7px; padding: 5px 8px; border-radius: 7px; font-size: 12.5px; border: 1px solid rgba(0,0,0,.05); }
.act-item .act-time { font-variant-numeric: tabular-nums; font-weight: 700; color: #334155; white-space: nowrap; font-size: 11.5px; }
.act-item .act-body { flex: 1; line-height: 1.35; }
.act-item .act-tools { display: flex; gap: 6px; opacity: .55; }
.act-item:hover .act-tools { opacity: 1; }
.act-item .edit, .act-item .del { cursor: pointer; font-weight: 700; }
.act-item .edit { color: var(--brand-2); }
.act-item .del { color: var(--danger); }
.act-item.train { background: var(--train); }
.act-item.sim { background: var(--sim); }
.act-item.meet { background: var(--meet); }
.act-item.meal { background: var(--meal); }
.act-item.custom { background: var(--custom); }
.act-item.break { background: var(--break); }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-backdrop[hidden] { display: none; }
.modal { background: #fff; border-radius: 14px; width: min(560px, 100%); max-height: 88vh; overflow: auto; box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; }
.modal-head h3 { margin: 0; color: var(--brand); }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 16px; }
.modal-section { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.modal-section h4 { margin: 0 0 10px; font-size: 14px; }
.modal-section select, .modal-section input[type="text"] { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-family: inherit; font-size: 14px; margin-bottom: 8px; }
.modal-section .row { display: flex; gap: 8px; }
.modal-section .row > * { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 11px 18px; border-radius: 10px;
  font-size: 14px; z-index: 80; box-shadow: var(--shadow);
}

/* ---------- Responsive / print ---------- */
@media (max-width: 760px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .field.span2, .field.span4 { grid-column: span 2; }
  .cert-grid { grid-template-columns: 1fr 1fr; }
  .tabs { width: 100%; order: 3; }
}

@media print {
  .topbar, .toolbar, .panel-head, #data, #controllers, #flights { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; padding: 0; }
  #schedule.panel { display: block !important; }
  .schedule-grid { min-width: 0; }
  .sg-cell { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
