/* ═══════════════════════════════════════════════════════════════════════
   UnifiedSales OS — design system
   A revenue-operations console: layered slate surfaces, one indigo→violet
   brand gradient reserved for the spine (logo / active nav / primary
   action), disciplined status colors, mono-typeset data.
   Legacy token names (--bg, --panel, --card, --border, --blue, …) are kept
   so per-page inline styles continue to work.
   ═══════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* surfaces */
  --bg0: #0a0c12; --bg1: #10131c; --bg2: #161b27; --bg3: #1d2432;
  --line: #242b3d; --line-strong: #333d57;
  /* ink */
  --ink: #e7ebf4; --ink2: #96a0b5; --ink3: #5b6579;
  /* brand (spine only) */
  --brand-a: #6366f1; --brand-b: #8b5cf6; --link: #8b97ff;
  --brand-grad: linear-gradient(135deg, var(--brand-a), var(--brand-b));
  /* status system */
  --ok: #34d399; --warn: #fbbf24; --danger: #f87171; --info: #22d3ee;
  /* legacy aliases (page inline styles depend on these names) */
  --bg: var(--bg0); --panel: var(--bg1); --card: var(--bg2); --border: var(--line);
  --text: var(--ink); --text2: var(--ink2); --text3: var(--ink3);
  --blue: var(--brand-a); --purple: var(--brand-b);
  --green: var(--ok); --orange: var(--warn); --red: var(--danger); --cyan: var(--info);
  /* shape + type */
  --radius: 10px; --radius-lg: 14px;
  --font: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', monospace;
  /* shell */
  --sidebar-w: 232px; --topbar-h: 60px;
  --shadow-1: 0 1px 2px rgba(0,0,0,.35);
  --shadow-2: 0 8px 28px rgba(0,0,0,.45);
}

html { height: 100%; }
body {
  min-height: 100%; background: var(--bg0); color: var(--ink);
  font-family: var(--font); font-size: 13px; line-height: 1.55;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
::selection { background: rgba(99,102,241,.35); }

:focus-visible {
  outline: 2px solid var(--brand-a); outline-offset: 2px; border-radius: 4px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* subtle themed scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 6px;
  border: 2px solid var(--bg0); }
*::-webkit-scrollbar-track { background: transparent; }

/* ─── App shell: injected sidebar + topbar, no per-page markup needed ─── */
body.with-shell {
  display: grid; height: 100vh; overflow: hidden;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
}
body.with-shell > .page,
body.with-shell > main { grid-column: 2; min-height: 0; }
body.with-shell > .page { overflow-y: auto; padding: 26px clamp(20px, 3.5vw, 44px) 64px; }
.page > * { max-width: 1160px; margin-left: auto; margin-right: auto; }

/* ─── Sidebar — the spine ─── */
.sidebar {
  grid-row: 1 / -1; grid-column: 1; display: flex; flex-direction: column;
  background: var(--bg1); border-right: 1px solid var(--line);
  padding: 14px 10px; overflow-y: auto;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px;
  font-weight: 700; font-size: 15px; letter-spacing: -0.02em; white-space: nowrap;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  background: var(--brand-grad); display: grid; place-items: center;
  color: #fff; font-size: 13px; font-weight: 700;
  box-shadow: 0 0 18px rgba(99,102,241,.35);
}
.brand .grad {
  background: var(--brand-grad);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.sidebar .nav-label {
  font-size: 10px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink3); padding: 12px 12px 6px;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  position: relative; display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 8px; color: var(--ink2);
  font-size: 13px; font-weight: 500; white-space: nowrap;
  transition: background .12s ease, color .12s ease;
}
.sidebar nav a:hover { background: var(--bg3); color: var(--ink); text-decoration: none; }
.sidebar nav a.active { background: var(--bg3); color: var(--ink); }
.sidebar nav a.active::before {
  content: ""; position: absolute; left: 0; top: 7px; bottom: 7px; width: 3px;
  border-radius: 3px; background: var(--brand-grad);
}
.sidebar nav a svg { width: 17px; height: 17px; flex: none; opacity: .85; }
.sidebar nav a.active svg { opacity: 1; }
/* the decision pulse — pending approvals notch */
.nav-pulse {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px;
  display: grid; place-items: center; border-radius: 10px;
  background: rgba(251,191,36,.15); color: var(--warn);
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  animation: pulse-glow 2.4s ease-in-out infinite;
}
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(251,191,36,.28); }
  50% { box-shadow: 0 0 0 5px rgba(251,191,36,0); }
}
.sidebar .foot {
  margin-top: auto; padding: 12px 12px 4px; font-size: 11px; color: var(--ink3);
  border-top: 1px solid var(--line);
}

/* ─── Topbar ─── */
header.topbar {
  grid-column: 2; display: flex; align-items: center; gap: 12px;
  padding: 0 clamp(20px, 3.5vw, 44px); background: var(--bg1);
  border-bottom: 1px solid var(--line);
}
.topbar .crumb { font-size: 13px; font-weight: 600; color: var(--ink); }
.spacer { flex: 1; }
.user-chip {
  display: flex; align-items: center; gap: 8px; padding: 5px 10px 5px 5px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--bg2);
  font-size: 12px; color: var(--ink2); max-width: 240px;
}
.user-chip .avatar {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
  background: var(--brand-grad); color: #fff; display: grid; place-items: center;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
}
.user-chip span.mail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── Controls ─── */
select, input, textarea {
  background: var(--bg2); color: var(--ink); border: 1px solid var(--line);
  padding: 7px 11px; border-radius: 8px; font-family: var(--font); font-size: 13px;
  transition: border-color .12s ease, background .12s ease;
}
select:hover, input:hover, textarea:hover { border-color: var(--line-strong); }
select:focus, input:focus, textarea:focus {
  outline: none; border-color: var(--brand-a);
  box-shadow: 0 0 0 3px rgba(99,102,241,.18);
}
input::placeholder, textarea::placeholder { color: var(--ink3); }
label { color: var(--ink2); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--bg2); color: var(--ink); font-family: var(--font);
  font-size: 12.5px; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
}
.btn:hover { background: var(--bg3); border-color: var(--line-strong); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--brand-grad); border: none; color: #fff; font-weight: 600;
  box-shadow: 0 2px 12px rgba(99,102,241,.35);
}
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { border-color: rgba(248,113,113,.4); color: var(--danger); background: transparent; }
.btn.danger:hover { background: rgba(248,113,113,.1); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

/* ─── Badges: status is a system, not decoration ─── */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px;
  border-radius: 999px; font-size: 11px; font-weight: 500; line-height: 1.7;
  background: var(--bg3); border: 1px solid var(--line); color: var(--ink2);
  white-space: nowrap;
}
.badge::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--ink3); flex: none;
}
.badge.green  { color: var(--ok);     border-color: rgba(52,211,153,.35);  background: rgba(52,211,153,.08); }
.badge.green::before  { background: var(--ok); }
.badge.red    { color: var(--danger); border-color: rgba(248,113,113,.35); background: rgba(248,113,113,.08); }
.badge.red::before    { background: var(--danger); }
.badge.orange { color: var(--warn);   border-color: rgba(251,191,36,.35);  background: rgba(251,191,36,.08); }
.badge.orange::before { background: var(--warn); }
.badge.blue   { color: var(--link);   border-color: rgba(99,102,241,.4);   background: rgba(99,102,241,.1); }
.badge.blue::before   { background: var(--brand-a); }
.badge.cyan   { color: var(--info);   border-color: rgba(34,211,238,.35);  background: rgba(34,211,238,.08); }
.badge.cyan::before   { background: var(--info); }
.badge .dot { display: none; }

/* ─── Page anatomy ─── */
.page h1 { font-size: 21px; font-weight: 650; letter-spacing: -0.02em; }
.page h2 { letter-spacing: -0.01em; }
.page-sub { color: var(--ink2); font-size: 12.5px; }

.card {
  background: var(--bg1); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 18px; box-shadow: var(--shadow-1);
}
.grid { display: grid; gap: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--ink2); }
.small { font-size: 12px; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }

/* ─── Tables: the console's workhorse ─── */
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; font-size: 10.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .08em; color: var(--ink3); padding: 10px 14px;
  border-bottom: 1px solid var(--line); background: var(--bg1);
  position: sticky; top: 0; z-index: 1;
}
table.data td {
  padding: 11px 14px; border-bottom: 1px solid var(--line); font-size: 13px;
  vertical-align: middle;
}
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: rgba(99,102,241,.045); }
table.data tr.clickable { cursor: pointer; }
table.data td .mono, table.data td.mono { font-size: 12px; color: var(--ink); }

/* numbers wear mono — data is the product's material */
.num, .val, .value, td.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.scorebar { height: 7px; background: var(--bg3); border-radius: 4px; overflow: hidden; }
.scorebar > div {
  height: 100%; border-radius: 4px; background: var(--brand-grad);
  transition: width .4s ease;
}

pre.json {
  background: var(--bg0); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; font-family: var(--mono); font-size: 11px; overflow-x: auto;
  white-space: pre-wrap; word-break: break-word; color: var(--ink2);
}

/* ─── Empty states: an invitation to act ─── */
.empty-state, .card .muted.small:only-child {
  color: var(--ink2);
}
.empty-state {
  text-align: center; padding: 40px 20px; border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg); background: transparent;
}
.empty-state .glyph { font-size: 26px; margin-bottom: 8px; opacity: .5; }
.empty-state strong { display: block; color: var(--ink); font-size: 14px; margin-bottom: 4px; }

/* ─── Loading skeleton ─── */
.skeleton {
  border-radius: 8px; background: linear-gradient(90deg, var(--bg2) 25%, var(--bg3) 50%, var(--bg2) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite; min-height: 14px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ─── Modal (replaces browser prompt/confirm) ─── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center;
  background: rgba(5,7,12,.65); backdrop-filter: blur(3px);
  animation: fade-in .14s ease;
}
.modal {
  width: min(440px, calc(100vw - 40px)); background: var(--bg1);
  border: 1px solid var(--line-strong); border-radius: var(--radius-lg);
  padding: 20px; box-shadow: var(--shadow-2); animation: modal-in .16s ease;
}
.modal h3 { font-size: 15px; font-weight: 600; margin-bottom: 6px; letter-spacing: -0.01em; }
.modal p { color: var(--ink2); font-size: 13px; margin-bottom: 14px; }
.modal input, .modal textarea { width: 100%; margin-bottom: 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(6px) scale(.98); } }

/* ─── Impersonation banner (spec §8) ─── */
#impersonation-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 400;
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 7px 16px; font-size: 12.5px; font-weight: 500; color: #1a1205;
  background: linear-gradient(90deg, var(--warn), #f59e0b);
}
#impersonation-banner .btn {
  padding: 3px 10px; font-size: 11.5px; background: rgba(0,0,0,.15);
  border-color: rgba(0,0,0,.2); color: #1a1205;
}
body.with-shell:has(#impersonation-banner) { padding-top: 32px; }

/* ─── Toasts ─── */
#toast-stack {
  position: fixed; bottom: 20px; right: 20px; z-index: 300;
  display: flex; flex-direction: column; gap: 8px; max-width: 380px;
}
.toast {
  background: var(--bg2); color: var(--ink); border: 1px solid var(--line-strong);
  border-left: 3px solid var(--brand-a); padding: 11px 14px; border-radius: 10px;
  font-size: 12.5px; box-shadow: var(--shadow-2); animation: toast-in .18s ease;
}
.toast.error { border-left-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateX(12px); } }

/* ─── Stat tiles (dashboard + reuse) ─── */
.tile .value { font-size: 26px; font-weight: 650; font-family: var(--mono); }

/* ─── Responsive: icon rail under 1000px ─── */
@media (max-width: 1000px) {
  body.with-shell { grid-template-columns: 64px minmax(0, 1fr); }
  .sidebar { padding: 14px 8px; }
  .sidebar .brand span, .sidebar nav a .label, .sidebar .nav-label,
  .sidebar .foot, .nav-pulse { display: none; }
  .sidebar nav a { justify-content: center; padding: 10px; }
  .sidebar nav a.has-pulse::after {
    content: ""; position: absolute; top: 6px; right: 6px; width: 7px; height: 7px;
    border-radius: 50%; background: var(--warn);
  }
  .user-chip .mail { display: none; }
}
@media (max-width: 640px) {
  body.with-shell > .page { padding: 16px 14px 48px; }
  header.topbar { padding: 0 14px; }
}
