/* CTMS — Crew Training Management System */
:root {
  --bg: #f2f4f8;
  --panel: #ffffff;
  --line: #dde3ec;
  --ink: #1a2436;
  --muted: #64748b;
  --brand: #12335f;
  --brand-2: #1c4f8f;
  --accent: #2f6fed;
  --ok: #1a9e6c;
  --warn: #d97706;
  --bad: #dc2626;
  --sidebar: #0e1f38;
  --sidebar-ink: #c6d4ea;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 30, 54, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Tahoma, sans-serif;
  background: var(--bg); color: var(--ink);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- shell ---- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 228px; flex: 0 0 228px; background: var(--sidebar); color: var(--sidebar-ink);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-mark { font-size: 22px; background: var(--accent); color: #fff; width: 38px; height: 38px; border-radius: 9px; display: flex; align-items: center; justify-content: center; }
.brand-name { font-weight: 700; color: #fff; letter-spacing: .5px; }
.brand-sub { font-size: 11px; opacity: .7; }
.sidebar nav { padding: 10px 8px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px; color: var(--sidebar-ink);
  padding: 8px 12px; border-radius: 8px; margin: 1px 0; font-size: 13.5px;
}
.nav-item:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 600; }
.nav-icon { width: 20px; text-align: center; }
.sidebar-foot { padding: 10px 8px 16px; border-top: 1px solid rgba(255,255,255,.08); }
.user-chip { padding: 6px 12px 10px; }
.user-name { color: #fff; font-weight: 600; font-size: 13.5px; }
.user-role { font-size: 11.5px; opacity: .7; }
.main { flex: 1; padding: 26px 30px 10px; max-width: 1500px; }
.foot { color: var(--muted); font-size: 12px; padding: 26px 0 18px; }

/* ---- headers ---- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
h1 { font-size: 21px; margin: 0; color: var(--brand); }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
h2 { font-size: 15px; margin: 26px 0 10px; color: var(--brand); text-transform: uppercase; letter-spacing: .6px; }

/* ---- cards & stats ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .num { font-size: 26px; font-weight: 700; color: var(--brand); line-height: 1.1; }
.stat .lbl { font-size: 12px; color: var(--muted); margin-top: 3px; }
.stat.alert .num { color: var(--bad); }
.stat.warn .num { color: var(--warn); }
.stat.good .num { color: var(--ok); }
a.stat { display: block; } a.stat:hover { text-decoration: none; border-color: var(--accent); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.panel h2:first-child { margin-top: 0; }

/* ---- tables ---- */
.tbl-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); background: #f7f9fc; border-bottom: 1px solid var(--line);
  padding: 9px 10px; white-space: nowrap; position: sticky; top: 0;
}
td { padding: 7px 10px; border-bottom: 1px solid #eef1f6; white-space: nowrap; }
tr:hover td { background: #f6f9ff; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl-note { font-size: 12px; color: var(--muted); padding: 8px 4px; }

/* ---- badges ---- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px;
  font-weight: 700; letter-spacing: .3px; white-space: nowrap;
}
.st-expired  { background: #fde8e8; color: #b91c1c; }
.st-due30    { background: #fdeddd; color: #c2570b; }
.st-due90    { background: #fdf6dd; color: #a16207; }
.st-due180   { background: #eef4dd; color: #4d7c0f; }
.st-due365   { background: #e2f3ec; color: #15803d; }
.st-ok       { background: #e2f3ec; color: #0f766e; }
.st-inactive { background: #e5e7eb; color: #6b7280; }
.b-booked    { background: #dbeafe; color: #1d4ed8; }
.b-planned   { background: #e5e7eb; color: #475569; }
.b-conducted { background: #dcfce7; color: #15803d; }
.b-cancelled { background: #fde8e8; color: #b91c1c; }
.b-role      { background: #e7edf7; color: #12335f; }

/* ---- forms ---- */
label { display: block; font-size: 12px; color: var(--muted); margin: 0 0 3px; font-weight: 600; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--ink); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfd4f7; border-color: var(--accent); }
input[disabled], input[readonly] { background: #f1f4f8; color: var(--muted); }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .g3, .g4 { grid-template-columns: repeat(2, 1fr); } }

.btn {
  display: inline-block; background: var(--accent); border: 0; color: #fff; padding: 9px 18px;
  border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { background: var(--brand-2); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn-ghost:hover { background: #eef4ff; color: var(--accent); }
.btn-sm { padding: 5px 12px; font-size: 12.5px; }
.btn-danger { background: var(--bad); }
.btn-danger:hover { background: #a61b1b; }

.filterbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.filterbar > div { min-width: 130px; }
.filterbar .grow { flex: 1; min-width: 200px; }

/* ---- flash ---- */
.flash { padding: 11px 16px; border-radius: 8px; margin-bottom: 14px; font-weight: 500; }
.flash-success { background: #dcfce7; color: #14532d; }
.flash-error { background: #fde8e8; color: #7f1d1d; }
.flash-info { background: #dbeafe; color: #1e3a8a; }

/* ---- login ---- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: linear-gradient(160deg, #0e1f38 0%, #12335f 60%, #1c4f8f 100%); }
.login-card { background: #fff; border-radius: 14px; padding: 36px; width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.login-card h1 { display: flex; gap: 10px; align-items: center; font-size: 19px; }
.login-card .brand-mark { font-size: 20px; width: 36px; height: 36px; }
.login-card p { color: var(--muted); font-size: 13px; }
.login-card label { margin-top: 14px; }
.login-card .btn { width: 100%; margin-top: 20px; }

/* ---- misc ---- */
.pill-row { display: flex; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.right { text-align: right; }
.mt { margin-top: 16px; }
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 1100px) { .kpi-grid { grid-template-columns: 1fr; } }
.rtl { direction: rtl; text-align: right; font-family: "Segoe UI", Tahoma, sans-serif; }
.progress { background: #eef1f6; height: 8px; border-radius: 6px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--ok); }
.chart-box { max-height: 320px; }
@media print { .sidebar, .filterbar, .btn, .foot { display: none !important; } .main { padding: 0; } }

/* ---- v2: builder, QMS, branding ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tab { padding: 9px 16px; border-radius: 8px 8px 0 0; color: var(--muted); font-weight: 600; font-size: 13.5px; border: 1px solid transparent; border-bottom: 0; }
.tab:hover { background: #fff; text-decoration: none; }
.tab.active { background: var(--panel); color: var(--brand); border-color: var(--line); margin-bottom: -1px; }

.lead { color: var(--muted); max-width: 78ch; margin: 0 0 16px; line-height: 1.6; }
.small { font-size: 11.5px; }
.nowrap { white-space: nowrap; }
code { background: #eef1f6; padding: 1px 6px; border-radius: 5px; font-size: 12px; color: #334; }

.lnk { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: 13px; padding: 0 4px; }
.lnk:hover { text-decoration: underline; }
.lnk.danger { color: var(--bad); }

.chk { display: inline-flex; gap: 6px; align-items: center; font-weight: 400; color: var(--ink);
       background: #f5f7fb; border: 1px solid var(--line); border-radius: 7px; padding: 6px 11px; cursor: pointer; font-size: 13px; margin: 0; }
.chk input { width: auto; }
.chk:hover { border-color: var(--accent); }
.fhelp { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

.nav-sep { font-size: 10.5px; text-transform: uppercase; letter-spacing: .9px; opacity: .5; padding: 14px 12px 5px; }
.brand-logo { width: 38px; height: 38px; object-fit: contain; border-radius: 8px; background: rgba(255,255,255,.08); }

.colorpick { height: 42px; padding: 3px; cursor: pointer; }
.logo-preview { width: 84px; height: 84px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.logo-preview img { max-width: 68px; max-height: 68px; object-fit: contain; }
.theme-chip { display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--line);
              border-radius: 9px; padding: 7px 12px; cursor: pointer; font: inherit; font-size: 13px; color: var(--ink); margin: 0; }
.theme-chip:hover { border-color: var(--accent); }
.theme-chip .sw { width: 13px; height: 13px; border-radius: 3px; display: inline-block; }

input[type=file] { padding: 8px; background: #f5f7fb; }
label > div { padding-top: 4px; font-size: 13.5px; color: var(--ink); font-weight: 400; }
.grid > div > div:not(.fhelp) { color: var(--ink); }

/* keep wide content inside the viewport instead of pushing the page sideways */
.main { min-width: 0; max-width: 100%; }
.shell > .main { flex: 1 1 auto; }
.panel, .tbl-wrap, .cards, .kpi-grid { max-width: 100%; }
.grid { min-width: 0; }
.grid > div { min-width: 0; }
@media (max-width: 1500px) { .g4 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 1150px) { .g4, .g3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 760px)  { .g4, .g3, .g2 { grid-template-columns: 1fr; } .sidebar { width: 64px; flex-basis: 64px; }
  .sidebar .brand-name, .sidebar .brand-sub, .sidebar .nav-item span:not(.nav-icon), .nav-sep, .user-chip { display: none; }
  .nav-item { justify-content: center; } .main { padding: 18px 14px; } }
