/* 2K Platform — shared design system (training portal + CRMs).
   Brand colors are injected per site as --brand / --brand-ink / --accent / --accent-ink.
   Fonts are self-hosted (SIL Open Font License, see fonts/). */
@font-face { font-family: 'Barlow'; font-style: normal; font-weight: 400; font-display: swap; src: url('fonts/barlow-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow'; font-style: italic; font-weight: 400; font-display: swap; src: url('fonts/barlow-latin-400-italic.woff2') format('woff2'); }
@font-face { font-family: 'Barlow'; font-style: normal; font-weight: 500; font-display: swap; src: url('fonts/barlow-latin-500-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow'; font-style: normal; font-weight: 600; font-display: swap; src: url('fonts/barlow-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow'; font-style: normal; font-weight: 700; font-display: swap; src: url('fonts/barlow-latin-700-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-style: normal; font-weight: 600; font-display: swap; src: url('fonts/barlow-condensed-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-style: normal; font-weight: 700; font-display: swap; src: url('fonts/barlow-condensed-latin-700-normal.woff2') format('woff2'); }
@font-face { font-family: 'Barlow Condensed'; font-style: normal; font-weight: 800; font-display: swap; src: url('fonts/barlow-condensed-latin-800-normal.woff2') format('woff2'); }
@font-face { font-family: 'IBM Plex Mono'; font-style: normal; font-weight: 400; font-display: swap; src: url('fonts/ibm-plex-mono-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'IBM Plex Mono'; font-style: normal; font-weight: 600; font-display: swap; src: url('fonts/ibm-plex-mono-latin-600-normal.woff2') format('woff2'); }
:root {
  --brand: #13436b;
  --brand-ink: #ffffff;
  --accent: #e3a72f;
  --accent-ink: #1b1405;
  --brand-soft: color-mix(in srgb, var(--brand) 9%, #ffffff);
  --brand-line: color-mix(in srgb, var(--brand) 28%, #ffffff);
  --brand-deep: color-mix(in srgb, var(--brand) 78%, #000000);
  --accent-soft: color-mix(in srgb, var(--accent) 18%, #ffffff);

  --ink: #172231;
  --ink-2: #3f4c5e;
  --ink-3: #657286;
  --ink-4: #8e99aa;
  --line: #d6dde6;
  --line-soft: #e7ecf2;
  --bg: #edf1f5;
  --panel: #ffffff;
  --sunk: #f6f8fb;
  --paper: #fffefb;

  --ok: #157a52;
  --ok-bg: #e1f3ea;
  --warn: #93570a;
  --warn-bg: #fbefd8;
  --bad: #b42318;
  --bad-bg: #fce7e5;
  --info: #1d5fa8;
  --info-bg: #e3edf9;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 18px;
  --font: 'Barlow', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Barlow Condensed', 'Barlow', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --shadow-pop: 0 16px 40px rgba(23, 34, 49, 0.18), 0 2px 6px rgba(23, 34, 49, 0.08);
  --focus: 0 0 0 3px color-mix(in srgb, var(--brand) 38%, transparent);
  --sidebar-w: 252px;
}

*,
*::before,
*::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
img, svg { max-width: 100%; }
a { color: var(--brand); text-underline-offset: 2px; }
a:hover { color: var(--brand-deep); }
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: 0.005em;
  margin: 0 0 0.4em;
  color: var(--ink);
}
h1 { font-size: clamp(2rem, 1.4rem + 2.2vw, 3rem); }
h2 { font-size: clamp(1.55rem, 1.2rem + 1.2vw, 2.1rem); }
h3 { font-size: 1.3rem; }
h4 { font-size: 1.08rem; }
p { margin: 0 0 0.9em; }
small, .small { font-size: 0.875rem; }
.muted { color: var(--ink-3); }
.ink-2 { color: var(--ink-2); }
.display { font-family: var(--font-display); }
.num { font-variant-numeric: tabular-nums; }
hr { border: 0; border-top: 1px solid var(--line-soft); margin: 1.25rem 0; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- layout helpers ---------- */
.row { display: flex; align-items: center; gap: 0.75rem; }
.row.wrap { flex-wrap: wrap; }
.row.top { align-items: flex-start; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.stack.tight { gap: 0.4rem; }
.stack.loose { gap: 1.25rem; }
.grow { flex: 1 1 auto; min-width: 0; }
.right { margin-left: auto; }
.center { text-align: center; }
.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) {
  .grid.three, .grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
  .grid.two, .grid.three, .grid.four { grid-template-columns: minmax(0, 1fr); }
  .hide-sm { display: none !important; }
}
@media (min-width: 621px) { .only-sm { display: none !important; } }

/* ---------- buttons ---------- */
.btn {
  --b-bg: var(--panel);
  --b-ink: var(--ink);
  --b-line: var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 40px;
  padding: 0.5rem 1rem;
  border: 1px solid var(--b-line);
  border-radius: var(--r-sm);
  background: var(--b-bg);
  color: var(--b-ink);
  font: 600 0.95rem/1 var(--font);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { --b-line: var(--ink-4); color: var(--b-ink); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.is-busy { opacity: 0.55; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-primary { --b-bg: var(--brand); --b-ink: var(--brand-ink); --b-line: var(--brand); }
.btn-primary:hover { --b-bg: var(--brand-deep); --b-line: var(--brand-deep); }
.btn-accent { --b-bg: var(--accent); --b-ink: var(--accent-ink); --b-line: var(--accent); }
.btn-accent:hover { --b-bg: color-mix(in srgb, var(--accent) 85%, #000); --b-line: color-mix(in srgb, var(--accent) 85%, #000); }
.btn-ghost { --b-bg: transparent; --b-line: transparent; color: var(--ink-2); }
.btn-ghost:hover { --b-bg: var(--sunk); --b-line: transparent; }
.btn-danger { --b-bg: var(--panel); --b-ink: var(--bad); --b-line: color-mix(in srgb, var(--bad) 40%, #fff); }
.btn-danger:hover { --b-bg: var(--bad-bg); --b-line: var(--bad); }
.btn-sm { min-height: 32px; padding: 0.35rem 0.7rem; font-size: 0.86rem; }
.btn-lg { min-height: 50px; padding: 0.8rem 1.4rem; font-size: 1.05rem; }
.btn-icon { padding: 0; width: 40px; }
.btn-icon.btn-sm { width: 32px; }
.btn-block { width: 100%; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field > label, .label { font-weight: 600; font-size: 0.9rem; color: var(--ink-2); }
.field .hint { font-size: 0.82rem; color: var(--ink-3); }
input[type='text'], input[type='email'], input[type='password'], input[type='tel'], input[type='number'],
input[type='date'], input[type='datetime-local'], input[type='url'], input[type='search'], select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--panel);
  color: var(--ink);
  font: 400 1rem/1.35 var(--font);
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
input[aria-invalid='true'], select[aria-invalid='true'] { border-color: var(--bad); }
.check { display: flex; gap: 0.6rem; align-items: flex-start; font-size: 0.95rem; }
.check input { margin-top: 0.25rem; width: 18px; height: 18px; accent-color: var(--brand); }
.form-error {
  background: var(--bad-bg);
  color: var(--bad);
  border-radius: var(--r-sm);
  padding: 0.6rem 0.8rem;
  font-size: 0.92rem;
}

/* ---------- surfaces ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: 1.25rem;
}
.panel.flush { padding: 0; overflow: hidden; }
.panel-head { display: flex; align-items: center; gap: 0.75rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line-soft); }
.panel-head h3 { margin: 0; font-size: 1.15rem; }
.panel-body { padding: 1rem 1.25rem; }
.sunk { background: var(--sunk); border-radius: var(--r-md); padding: 1rem; }

/* ---------- pills / badges ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--sunk);
  color: var(--ink-2);
  white-space: nowrap;
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill.brand { background: var(--brand-soft); color: var(--brand); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
table.data th {
  text-align: left;
  font-weight: 600;
  color: var(--ink-3);
  font-size: 0.82rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--line);
  background: var(--sunk);
  white-space: nowrap;
}
table.data td { padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr.click { cursor: pointer; }
table.data tr.click:hover td { background: var(--brand-soft); }
table.data td.num, table.data th.num { text-align: right; }

/* ---------- progress ---------- */
.bar { height: 8px; background: var(--line-soft); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: inherit; transition: width 0.4s ease; }
.bar.ok > span { background: var(--ok); }
.bar.thin { height: 5px; }

/* ---------- app shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1.1rem 0.85rem;
  background: var(--panel);
  border-right: 1px solid var(--line-soft);
  overflow-y: auto;
}
.sidebar .brand-logo { display: flex; align-items: center; min-height: 48px; padding: 0 0.5rem 0.9rem; }
.sidebar .brand-logo img { height: 44px; width: auto; max-width: 200px; object-fit: contain; }
.nav-group { margin-top: 0.75rem; padding: 0 0.6rem 0.3rem; font-size: 0.78rem; font-weight: 600; color: var(--ink-4); }
.nav-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.65rem;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-weight: 500;
  text-decoration: none;
}
.nav-link svg { width: 19px; height: 19px; flex: none; color: var(--ink-3); }
.nav-link:hover { background: var(--sunk); color: var(--ink); }
.nav-link.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-link.active svg { color: var(--brand); }
.nav-link .count { margin-left: auto; font-size: 0.78rem; color: var(--ink-3); }
.sidebar .foot { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--line-soft); }
.main { min-width: 0; padding: 1.75rem clamp(1rem, 3vw, 2.5rem) 5rem; }
.main-inner { max-width: 1180px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-head h1, .page-head h2 { margin: 0; }
.page-head .sub { color: var(--ink-3); margin: 0.35rem 0 0; }
.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 30;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line-soft);
}
.topbar img { height: 34px; width: auto; max-width: 160px; object-fit: contain; display: block; }
.tabbar {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: var(--panel);
  border-top: 1px solid var(--line-soft);
  padding: 0.35rem 0.25rem calc(0.35rem + env(safe-area-inset-bottom));
}
.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0.3rem 0;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-3);
  text-decoration: none;
}
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a.active { color: var(--brand); }
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .topbar { display: flex; }
  .tabbar { display: flex; }
  .main { padding-top: 1.1rem; padding-bottom: 6.5rem; }
}

/* ---------- overlays ---------- */
.toast-stack { position: fixed; z-index: 90; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: 0.5rem; max-width: min(380px, calc(100vw - 2rem)); }
@media (max-width: 860px) { .toast-stack { bottom: 5.5rem; left: 1rem; right: 1rem; } }
.toast {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  padding: 0.75rem 0.9rem;
  border-radius: var(--r-md);
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow-pop);
  font-size: 0.93rem;
  animation: toast-in 0.2s ease-out;
}
.toast.ok { background: #0f5c3e; }
.toast.bad { background: #8f1c13; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(15, 23, 34, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal {
  width: min(560px, 100%);
  max-height: calc(100vh - 2rem);
  overflow: auto;
  background: var(--panel);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
}
.modal.wide { width: min(860px, 100%); }
.modal-head { display: flex; align-items: center; gap: 0.75rem; padding: 1.1rem 1.25rem 0.5rem; }
.modal-head h3 { margin: 0; }
.modal-body { padding: 0.5rem 1.25rem 1.25rem; }
.modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.6rem; padding: 0.9rem 1.25rem; border-top: 1px solid var(--line-soft); background: var(--sunk); }
.drawer-backdrop { position: fixed; inset: 0; z-index: 70; background: rgba(15, 23, 34, 0.3); }
.drawer {
  position: fixed;
  z-index: 71;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(520px, 100vw);
  background: var(--panel);
  box-shadow: var(--shadow-pop);
  display: flex;
  flex-direction: column;
  animation: drawer-in 0.22s ease-out;
}
@keyframes drawer-in { from { transform: translateX(24px); opacity: 0.4; } }
.drawer-head { display: flex; align-items: center; gap: 0.75rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line-soft); }
.drawer-head h3 { margin: 0; }
.drawer-body { flex: 1; overflow-y: auto; padding: 1.1rem 1.25rem; }
.drawer-foot { padding: 0.9rem 1.25rem; border-top: 1px solid var(--line-soft); display: flex; gap: 0.6rem; justify-content: flex-end; }

/* ---------- misc ---------- */
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--ink-3); }
.empty h3 { color: var(--ink-2); }
.stat .value { font-family: var(--font-display); font-weight: 700; font-size: 2.1rem; line-height: 1; }
.stat .label { color: var(--ink-3); font-size: 0.88rem; margin-top: 0.35rem; }
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--line); margin-bottom: 1.25rem; overflow-x: auto; }
.tabs button, .tabs a {
  border: 0;
  background: none;
  padding: 0.65rem 0.9rem;
  font: 600 0.95rem var(--font);
  color: var(--ink-3);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  text-decoration: none;
  white-space: nowrap;
}
.tabs .active { color: var(--brand); border-bottom-color: var(--brand); }
.chip-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font: 500 0.88rem var(--font);
  color: var(--ink-2);
  cursor: pointer;
}
.chip:hover { border-color: var(--brand-line); color: var(--brand); }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-page { display: grid; place-items: center; min-height: 60vh; }
.preview-switch {
  position: fixed;
  left: 1rem;
  bottom: 1rem;
  z-index: 60;
  display: flex;
  gap: 0.4rem;
  align-items: center;
  font-size: 0.8rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem 0.35rem 0.25rem 0.75rem;
  box-shadow: var(--shadow-pop);
}
.preview-switch select { min-height: 30px; padding: 0.15rem 0.5rem; font-size: 0.8rem; width: auto; border-radius: 999px; }
@media (max-width: 860px) { .preview-switch { bottom: 5.25rem; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
@media print {
  .sidebar, .topbar, .tabbar, .no-print, .toast-stack, .preview-switch { display: none !important; }
  body { background: #fff; }
  .shell { display: block; }
  .main { padding: 0; }
}
