/* Bellatrix shared design tokens + platform shell.
   Single source of truth for look & feel across every Bellatrix app. */
:root {
  --bg: #F7F8FA;
  --panel: #FFFFFF;
  --ink: #1A1B1E;
  --ink-soft: #374151;
  --ink-faint: #9CA3AF;
  --line: #E5E7EB;
  --line-soft: #F1F2F4;
  --accent: var(--brand-primary, #3868C0);
  --accent-dark: var(--brand-primary-700, #2A4E96);
  --accent-soft: #E8EEF9;
  --accent-ink: #FFFFFF;
  --ok: #067647;
  --ok-soft: #D1FAE5;
  --warn: #92400E;
  --warn-soft: #FEF3C7;
  --err: #B42318;
  --err-soft: #FEF2F2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.10);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
body.bx { margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 14px; line-height: 1.45; }

/* ---------- auth card pages ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center;
  justify-content: center; flex-direction: column; gap: 18px; padding: 24px; }
.auth-card { background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow); width: 380px; max-width: 94vw;
  padding: 30px 32px; }
.auth-logo { display: block; margin: 0 auto 6px; height: 40px; }
.auth-card h1 { font-size: 19px; margin: 8px 0 2px; text-align: center; }
.auth-card .sub { color: var(--ink-soft); text-align: center; margin: 0 0 18px;
  font-size: 13px; }
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 12.5px; font-weight: 600;
  color: var(--ink-soft); margin-bottom: 5px; }
.field input, .field select { width: 100%; padding: 9px 11px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
  color: var(--ink); font-family: var(--font); }
.field input:focus { outline: 2px solid var(--accent-soft);
  border-color: var(--accent); }
.btn { display: inline-flex; align-items: center; justify-content: center;
  gap: 7px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font-size: 13.5px; font-weight: 600;
  cursor: pointer; text-decoration: none; font-family: var(--font); }
.btn:hover { background: var(--line-soft); }
.btn-primary { background: var(--accent); border-color: var(--accent);
  color: var(--accent-ink); width: 100%; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { color: var(--err); border-color: #f3c6c0; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.auth-links { display: flex; justify-content: space-between; margin-top: 14px;
  font-size: 12.5px; }
.auth-links a, a.tlink { color: var(--accent); text-decoration: none; }
.auth-links a:hover, a.tlink:hover { text-decoration: underline; }
.auth-error { background: var(--err-soft); color: var(--err);
  border: 1px solid #f3c6c0; border-radius: 8px; padding: 9px 12px;
  font-size: 13px; margin-bottom: 14px; }
.auth-ok { background: var(--ok-soft); color: var(--ok);
  border: 1px solid #bce5d1; border-radius: 8px; padding: 9px 12px;
  font-size: 13px; margin-bottom: 14px; }
.auth-foot { color: var(--ink-faint); font-size: 12px; }
.auth-foot a { color: var(--ink-faint); }

/* ---------- notification banner ---------- */
.bx-banner { position: sticky; top: 0; z-index: 3000; display: flex;
  align-items: center; gap: 12px; padding: 9px 16px; font-size: 13.5px;
  font-weight: 600; }
.bx-banner a { color: inherit; text-decoration: underline; }
.bx-banner .bx { margin-left: auto; cursor: pointer; opacity: .75;
  background: none; border: none; color: inherit; font-size: 15px; }
.bx-banner .bx:hover { opacity: 1; }
.bx-banner .marquee { overflow: hidden; white-space: nowrap; flex: 1; }
.bx-banner .marquee span { display: inline-block; padding-left: 100%;
  animation: bx-scroll 18s linear infinite; }
@keyframes bx-scroll { 0% {transform: translateX(0);} 100% {transform: translateX(-100%);} }

/* ---------- profile menu (shared shell component) ---------- */
.bx-profile { position: relative; }
.bx-profile .avatar { width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); display: flex;
  align-items: center; justify-content: center; font-weight: 700;
  font-size: 13px; cursor: pointer; border: none; }
.bx-profile .menu { position: absolute; right: 0; top: 40px; width: 230px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(16,24,40,.14); padding: 6px; display: none;
  z-index: 4000; }
.bx-profile .menu.open { display: block; }
.bx-profile .menu .who { padding: 9px 11px; border-bottom: 1px solid var(--line-soft);
  margin-bottom: 5px; }
.bx-profile .menu .who .nm { font-weight: 700; font-size: 13.5px; }
.bx-profile .menu .who .em { color: var(--ink-faint); font-size: 12px; }
.bx-profile .menu a, .bx-profile .menu button.mi { display: block; width: 100%;
  text-align: left; padding: 8px 11px; border-radius: 7px; font-size: 13px;
  color: var(--ink-soft); text-decoration: none; background: none; border: none;
  cursor: pointer; font-family: var(--font); }
.bx-profile .menu a:hover, .bx-profile .menu button.mi:hover {
  background: var(--line-soft); color: var(--ink); }

/* ---------- admin studio shell (Supabase-Studio-style) ---------- */
.studio { display: flex; min-height: 100vh; }
.studio-rail { width: 220px; background: var(--panel);
  border-right: 1px solid var(--line); padding: 0 10px 14px; flex-shrink: 0;
  display: flex; flex-direction: column; position: sticky; top: 0;
  height: 100vh; overflow-y: auto; }
/* Brand box matched to the same canonical header height as the topbar so
   their bottom borders align pixel-exactly (logo + name side by side). */
.studio-rail .brand { display: flex; align-items: center; gap: 10px;
  box-sizing: border-box; margin: 0 -10px 8px; padding: 0 14px;
  height: var(--bx-header-h); min-height: var(--bx-header-h);
  border-bottom: 1px solid var(--line); }
.studio-rail .brand img { height: 40px; width: auto; max-width: 96px;
  object-fit: contain; flex: 0 0 auto; }
.studio-rail .brand > div { min-width: 0; }
.studio-rail .brand .t { font-weight: 800; font-size: 13px; line-height: 1.12;
  text-transform: uppercase; letter-spacing: .04em; }
.studio-rail .brand .s { font-size: 11px; color: var(--ink-faint);
  line-height: 1.15; }
.studio-rail .grp { font-size: 10.5px; font-weight: 700; letter-spacing: .07em;
  color: var(--ink-faint); text-transform: uppercase; padding: 12px 8px 4px; }
.studio-rail a.nav { display: flex; align-items: center; gap: 9px;
  padding: 7px 9px; border-radius: 7px; color: var(--ink-soft);
  text-decoration: none; font-size: 13.2px; border-left: 2px solid transparent; }
.studio-rail a.nav:hover { background: var(--line-soft); color: var(--ink); }
.studio-rail a.nav.on { background: var(--accent-soft); color: var(--accent-dark);
  font-weight: 600; border-left-color: var(--accent); }
.studio-main { flex: 1; min-width: 0; }
.studio-top { display: flex; align-items: center; gap: 12px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 10px 22px; position: sticky; top: 0; z-index: 100; }
.studio-top h2 { font-size: 15.5px; margin: 0; }
.studio-top .crumb { color: var(--ink-faint); font-size: 12.5px; }
.studio-top .grow { margin-left: auto; display: flex; gap: 10px;
  align-items: center; }
.studio-body { padding: 22px; max-width: 1180px; }

.card { background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px; }
.card .hd { display: flex; align-items: center; gap: 10px;
  padding: 13px 18px; border-bottom: 1px solid var(--line-soft); }
.card .hd h3 { margin: 0; font-size: 14px; }
.card .hd .grow { margin-left: auto; display: flex; gap: 8px; }
.card .bd { padding: 16px 18px; }
.card .bd.p0 { padding: 0; }

table.grid { width: 100%; border-collapse: collapse; font-size: 13.2px; }
table.grid th { text-align: left; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .05em; color: var(--ink-faint); font-weight: 700;
  padding: 9px 14px; border-bottom: 1px solid var(--line);
  background: var(--bg); }
table.grid td { padding: 9px 14px; border-bottom: 1px solid var(--line-soft);
  vertical-align: middle; }
table.grid tr:hover td { background: #fafbfc; }

.chip { display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.err { background: var(--err-soft); color: var(--err); }
.chip.mut { background: var(--line-soft); color: var(--ink-soft); }
.chip.acc { background: var(--accent-soft); color: var(--accent-dark); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px,1fr));
  gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .v { font-size: 22px; font-weight: 800; }
.kpi .l { font-size: 12px; color: var(--ink-faint); margin-top: 2px; }
.kpi .d { font-size: 11.5px; margin-top: 4px; }

.mono { font-family: var(--mono); font-size: 12px; }
pre.log { background: #101418; color: #d7e0e8; border-radius: 8px;
  padding: 13px 15px; font-family: var(--mono); font-size: 12px;
  overflow: auto; max-height: 420px; white-space: pre-wrap; }

.modal-back { position: fixed; inset: 0; background: rgba(16,24,40,.45);
  display: none; align-items: flex-start; justify-content: center;
  z-index: 5000; padding: 60px 16px; }
.modal-back.open { display: flex; }
.modal { background: var(--panel); border-radius: 14px; width: 480px;
  max-width: 96vw; max-height: 84vh; overflow: auto; padding: 22px 24px;
  box-shadow: 0 16px 48px rgba(16,24,40,.25); }
.modal h3 { margin: 0 0 14px; font-size: 15.5px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 9px;
  margin-top: 18px; }

.toast { position: fixed; bottom: 22px; right: 22px; background: var(--ink);
  color: #fff; padding: 10px 16px; border-radius: 9px; font-size: 13px;
  box-shadow: var(--shadow); z-index: 6000; opacity: 0;
  transition: opacity .25s; pointer-events: none; }
.toast.show { opacity: 1; }
.empty { color: var(--ink-faint); text-align: center; padding: 26px;
  font-size: 13px; }
.muted { color: var(--ink-faint); }
.spin { display: inline-block; width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--accent-soft); border-top-color: var(--accent);
  animation: bx-spin .8s linear infinite; }
@keyframes bx-spin { to { transform: rotate(360deg); } }

/* ================================================================
   Unified app sidebar — THE Bellatrix standard for every customer app.
   Same logo (the Wizard's), same app-name lockup, same nav font,
   size and colors, same collapsible drawer. When collapsed the
   wordmark disappears and only the favicon remains (no squashing).
   ================================================================ */
.bx-sidenav { font-family: var(--font) !important; }

/* ---- ONE canonical header height for every app ----
   --bx-header-h is the shared height of the logo box AND the topbar
   ("ribbon") to its right, so their bottom borders line up pixel-exactly.
   It NEVER changes on collapse. --bx-mark is the collapsed favicon size.
   Change these two numbers to re-scale the whole header, everywhere. */
:root { --bx-header-h: 92px; --bx-mark: 24px; }

/* Logo box: fixed to the canonical height, logo + app-name side by side. */
.bx-brand {
  position: relative; box-sizing: border-box;
  height: var(--bx-header-h) !important;
  min-height: var(--bx-header-h) !important;
  max-height: var(--bx-header-h) !important;
  padding: 0 16px;
  display: flex !important; align-items: center; gap: 11px;
  border-bottom: 1px solid var(--line); }
.bx-brand-link { display: flex; align-items: center; gap: 11px;
  text-decoration: none; color: var(--ink);
  flex: 1 1 auto; min-width: 0; line-height: 1; }
.bx-brand-logo { height: 60px !important; width: auto !important;
  max-width: 120px; object-fit: contain; display: block;
  flex: 0 0 auto; margin: 0 !important; }
/* App name ALWAYS to the RIGHT of the logo. Up to two rows, ~2px line
   spacing, block centred on the logo's horizontal centre line. */
.bx-brand-app { display: block; flex: 1 1 auto; min-width: 0;
  font-family: var(--font); font-size: 12px; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase; color: var(--ink);
  line-height: 1.12; margin: 0; padding: 0; align-self: center; }
/* Collapsed favicon: one consistent square size across every app. Square
   (equal height & width), object-fit:contain so the mark is never distorted. */
.bx-brand-mark { display: none !important;
  width: var(--bx-mark) !important; height: var(--bx-mark) !important;
  object-fit: contain; }
/* Collapse chevron: pinned to the very BOTTOM-RIGHT corner of the logo box.
   No background on hover/click/focus so it never casts a shadow over the
   favicon when the panel is collapsed. */
.bx-nav-toggle { position: absolute; right: 3px; bottom: 3px; width: 18px;
  height: 18px; border: none; background: none !important; border-radius: 4px;
  color: var(--ink-faint); cursor: pointer; display: flex;
  align-items: center; justify-content: center; padding: 0; z-index: 2;
  box-shadow: none !important; outline: none !important;
  -webkit-tap-highlight-color: transparent; }
.bx-nav-toggle:hover { color: var(--ink); }
.bx-nav-toggle:focus, .bx-nav-toggle:active { background: none !important;
  box-shadow: none !important; outline: none !important; }
.bx-nav-toggle svg { width: 14px; height: 14px; transition: transform .2s; }

/* The topbar ("ribbon") to the right of the logo box: matched height and a
   matching bottom border so the two align pixel-exactly, in every app. */
.topbar, .page-header, .studio-top {
  box-sizing: border-box;
  height: var(--bx-header-h) !important;
  min-height: var(--bx-header-h) !important;
  border-bottom: 1px solid var(--line); }

/* nav items — identical across apps, overrides app-local styles */
.bx-sidenav .sidebar-nav a,
.bx-sidenav a.nav-item {
  font-family: var(--font) !important; font-size: 13.2px !important;
  font-weight: 500 !important; line-height: 1.35 !important;
  color: var(--ink-soft) !important; display: flex !important;
  align-items: center; gap: 9px; padding: 7px 14px !important;
  margin: 1px 6px 1px 0 !important; border-left: 2px solid transparent !important;
  border-radius: 0 7px 7px 0 !important; text-decoration: none !important; }
.bx-sidenav .sidebar-nav a:hover,
.bx-sidenav a.nav-item:hover {
  background: var(--line-soft) !important; color: var(--ink) !important; }
.bx-sidenav .sidebar-nav a.active,
.bx-sidenav a.nav-item.active {
  background: var(--accent-soft) !important; color: var(--accent-dark) !important;
  font-weight: 600 !important; border-left-color: var(--accent) !important; }
.bx-sidenav .sidebar-nav a svg,
.bx-sidenav a.nav-item svg { width: 16px; height: 16px; flex: 0 0 16px; }
.bx-sidenav .sidebar-section-label,
.bx-sidenav .nav-section {
  font-family: var(--font) !important; font-size: 10.5px !important;
  font-weight: 700 !important; letter-spacing: .07em !important;
  text-transform: uppercase !important; color: var(--ink-faint) !important;
  padding: 12px 14px 4px !important; margin: 0 !important; }

/* collapsed drawer: 64px rail, favicon only, icon-only nav */
aside.bx-sidenav { transition: width .18s ease; }
.app-shell.bx-nav-collapsed { grid-template-columns: 64px 1fr !important; }
aside.bx-sidenav.bx-collapsed { width: 64px !important;
  min-width: 64px !important; overflow: hidden; }
/* Collapsed: the logo box keeps its EXACT height (no jump); only its width
   shrinks. Favicon centred, name + wordmark hidden, chevron bottom-right. */
.bx-collapsed .bx-brand { padding: 0 6px; justify-content: center; }
.bx-collapsed .bx-brand-link { flex: 0 0 auto; justify-content: center;
  gap: 0; }
.bx-collapsed .bx-brand-logo,
.bx-collapsed .bx-brand-app { display: none !important; }
.bx-collapsed .bx-brand-mark { display: block !important; margin: 0 auto; }
.bx-collapsed .bx-nav-toggle svg { transform: rotate(180deg); }
.bx-collapsed .nav-label,
.bx-collapsed .bx-navtext,
.bx-collapsed .sidebar-section-label,
.bx-collapsed .nav-section,
.bx-collapsed .sidebar-bottom,
.bx-collapsed .sidebar-disclaimer,
.bx-collapsed .acting-as-label,
.bx-collapsed .acting-as-card,
.bx-collapsed .attention-badge { display: none !important; }
.bx-collapsed .sidebar-nav a,
.bx-collapsed a.nav-item { justify-content: center;
  padding: 9px 0 !important; margin: 1px 4px !important;
  border-left-width: 0 !important; border-radius: 7px !important; }
