/* ============================================================
   Sacred Command v2 — tokens.css
   ALL custom props + reset + typography + shared primitives.
   The only other stylesheet is app.css (shell). Views inject
   scoped CSS via ensureStyles(). No overrides archaeology.
   ============================================================ */

:root {
  /* Surfaces */
  --bg0: #0a0b10;
  --bg1: #101117;
  --bg2: #14151a;
  --bg3: #1a1c24;
  --line: #23262f;
  --line-hi: #2e3340;

  /* Text */
  --text: #f4f5f7;
  --text2: #8b93a3;
  --text3: #5b6371;
  --cream: #ede7da;

  /* Accents */
  --red: #ff3b4e;            /* internal hot-red: actions, live dots */
  --red-dim: rgba(255, 59, 78, 0.14);
  --crimson: #C41230;        /* brand crimson: client-facing, ambient glow */
  --crimson-dim: rgba(196, 18, 48, 0.16);
  --good: #22c55e;
  --good-dim: rgba(34, 197, 94, 0.14);
  --warn: #eab308;
  --warn-dim: rgba(234, 179, 8, 0.14);
  --gold: #C8A158;           /* sparingly: milestones, "won" */
  --gold-dim: rgba(200, 161, 88, 0.15);

  /* Type */
  --font-display: 'Montserrat', system-ui, -apple-system, sans-serif;
  --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;

  /* Shape & motion */
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 7px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.3);
  --speed: 150ms;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  background: var(--bg0);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
img, video { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
ul, ol { list-style: none; }
::selection { background: var(--crimson); color: #fff; }

/* Scrollbars (webkit) — quiet, cockpit-dark */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 8px; border: 2px solid var(--bg0); }
::-webkit-scrollbar-thumb:hover { background: var(--line-hi); }

/* ---------- Typography ---------- */
h1, h2, h3, .display {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--text);
}
h1 { font-size: 24px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; font-weight: 700; }
.muted { color: var(--text2); }
.faint { color: var(--text3); }
.cream { color: var(--cream); }
.section-label {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text3);
}

/* Every numeric element: mono + tabular */
.num, .kpi-num, .mono, td.num, .thermo-num, .money {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ---------- Focus ---------- */
:focus-visible { outline: 2px solid var(--crimson); outline-offset: 2px; border-radius: 4px; }

/* ============================================================
   Shared primitives
   ============================================================ */

/* Card */
.card {
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  transition: border-color var(--speed) ease, transform var(--speed) ease, box-shadow var(--speed) ease;
}
.card:hover { border-color: var(--line-hi); }
.card.lift:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg3);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  transition: background var(--speed) ease, border-color var(--speed) ease, transform 80ms ease;
}
.btn:hover { background: #20232d; border-color: var(--line-hi); }
.btn:active { transform: scale(0.97); }
.btn-red {
  background: var(--red);
  border-color: transparent;
  color: #fff;
}
.btn-red:hover { background: #e5303f; border-color: transparent; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text2); }
.btn-ghost:hover { background: var(--bg2); color: var(--text); border-color: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: var(--radius-xs); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--text2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.chip-good  { color: var(--good);  background: var(--good-dim);  border-color: transparent; }
.chip-warn  { color: var(--warn);  background: var(--warn-dim);  border-color: transparent; }
.chip-red   { color: var(--red);   background: var(--red-dim);   border-color: transparent; }
.chip-gold  { color: var(--gold);  background: var(--gold-dim);  border-color: transparent; }
.chip-crimson { color: #ff8296; background: var(--crimson-dim); border-color: transparent; }
.chip-dim   { color: var(--text3); }

/* KPI block */
.kpi { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.kpi-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text3);
}
.kpi-num {
  font-size: 26px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.1;
}
.kpi-sub { font-size: 12px; color: var(--text2); }

/* Health / status dots */
.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text3);
  flex: 0 0 auto;
}
.dot-healthy { background: var(--good); }
.dot-watch   { background: var(--warn); }
.dot-risk    { background: var(--red); }

/* Live dot — pulsing */
.live-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--good);
  flex: 0 0 auto;
  animation: livePulse 1.8s ease-out infinite;
}
.live-dot.red { background: var(--red); animation-name: livePulseRed; }
@keyframes livePulse {
  0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5); }
  70%  { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}
@keyframes livePulseRed {
  0%   { box-shadow: 0 0 0 0 rgba(255, 59, 78, 0.5); }
  70%  { box-shadow: 0 0 0 8px rgba(255, 59, 78, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 59, 78, 0); }
}

/* Count badge */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
}
.badge[hidden] { display: none; }

/* Table */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text3);
  border-bottom: 1px solid var(--line);
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr { transition: background var(--speed) ease; }
.table tbody tr:hover { background: var(--bg2); }
.table tbody tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

/* Drawer (right sheet) */
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 400px;
  max-width: 100vw;
  background: var(--bg1);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateX(105%);
  transition: transform 220ms cubic-bezier(0.32, 0.72, 0.28, 1);
  z-index: 60;
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.drawer-head h2 { flex: 1; font-size: 15px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 14px 16px; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }

/* Scrim */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(6, 7, 10, 0.6);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
  z-index: 55;
}
.scrim.show { opacity: 1; pointer-events: auto; }

/* Modal */
.modal-scrim {
  position: fixed;
  inset: 0;
  background: rgba(6, 7, 10, 0.65);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 70;
  animation: fadeIn 150ms ease;
}
.modal {
  width: 480px;
  max-width: 100%;
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: modalIn 180ms cubic-bezier(0.32, 0.72, 0.28, 1);
}
.modal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { flex: 1; font-size: 15px; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
}
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(0.98); } }
@keyframes fadeIn { from { opacity: 0; } }

/* Toast */
#toasts {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 90;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 340px;
  padding: 10px 14px;
  background: var(--bg3);
  border: 1px solid var(--line-hi);
  border-left: 3px solid var(--good);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  font-size: 13px;
  font-weight: 500;
  animation: toastIn 200ms cubic-bezier(0.32, 0.72, 0.28, 1);
}
.toast-warn { border-left-color: var(--warn); }
.toast-err  { border-left-color: var(--red); }
.toast.out  { opacity: 0; transform: translateY(6px); transition: opacity 250ms ease, transform 250ms ease; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }

/* Inputs */
.input, .textarea, .select {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  transition: border-color var(--speed) ease;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--crimson); outline: none; }
.input::placeholder, .textarea::placeholder { color: var(--text3); }
.textarea { resize: vertical; min-height: 80px; line-height: 1.5; }

/* Utility */
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.right { margin-left: auto; }
.hidden { display: none !important; }
