/* ==========================================================================
   Sales OS — Portal design system (Lane B1). Binding tokens per
   docs/BUILD-CONTRACT-v0.4.md §4. Dark workspace, plain-English, no
   gradients/emoji/purple/decorative icons/lorem. One stylesheet, shared by
   agency screens (B1) and company/wizard/studio screens (B2).
   ========================================================================== */

:root {
  --bg: #0B1220;
  --surface: #111A2B;
  --raised: #16223A;
  --line: rgba(255,255,255,.08);
  --ink: #E7ECF4;
  --muted: #98A4B8;
  --accent: #3FB68B;
  --accent-ink: #06231A;
  --warn: #E0A63A;
  --danger: #E15B5B;
  --radius: 6px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-6: 24px; --sp-8: 32px;
  --sidenav-w: 236px;
  --topbar-h: 56px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/20px Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, p { margin: 0; }
button { font: inherit; }
table { font-variant-numeric: tabular-nums; }
::selection { background: rgba(63,182,139,.35); }

/* ---------------------------------------------------------------- layout */
.app-shell { min-height: 100%; }
.app-main { display: flex; min-height: 100vh; padding-top: var(--topbar-h); }
.app-content { flex: 1; min-width: 0; padding: var(--sp-6); }
@media (max-width: 900px) { .app-content { padding: var(--sp-4); } }

/* ----------------------------------------------------------------- topbar */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h); z-index: 40;
  display: flex; align-items: center; gap: var(--sp-4);
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 0 var(--sp-4);
}
.topbar-brand { font-weight: 600; font-size: 15px; white-space: nowrap; }
.topbar-brand span { color: var(--muted); font-weight: 400; }
.switcher { position: relative; }
.switcher-btn {
  display: flex; align-items: center; gap: var(--sp-2);
  background: var(--raised); border: 1px solid var(--line); color: var(--ink);
  border-radius: var(--radius); padding: 6px 10px; cursor: pointer; max-width: 320px;
}
.switcher-btn .cur { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.switcher-btn .tag { color: var(--muted); font-size: 12px; }
.switcher-menu {
  position: absolute; top: calc(100% + 6px); left: 0; min-width: 280px; max-height: 360px;
  overflow: auto; background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0,0,0,.4); padding: var(--sp-2); z-index: 50;
}
.switcher-menu input {
  width: 100%; margin-bottom: var(--sp-2);
}
.switcher-item {
  display: flex; justify-content: space-between; gap: var(--sp-2); padding: 8px 10px; border-radius: 4px; cursor: pointer;
}
.switcher-item:hover { background: rgba(255,255,255,.06); }
.switcher-item .name { color: var(--ink); }
.switcher-item .meta { color: var(--muted); font-size: 12px; }
.topbar-spacer { flex: 1; }
.topbar-search input { width: 220px; }
.user-menu { position: relative; }
.user-menu-btn {
  display: flex; align-items: center; gap: 8px; background: transparent; border: none; color: var(--ink); cursor: pointer;
  padding: 6px 8px; border-radius: var(--radius);
}
.user-menu-btn:hover { background: rgba(255,255,255,.06); }
.user-avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 12px;
}
.user-menu-dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); background: var(--raised); border: 1px solid var(--line);
  border-radius: var(--radius); min-width: 200px; box-shadow: 0 12px 32px rgba(0,0,0,.4); z-index: 50; padding: var(--sp-2);
}
.user-menu-dropdown .meta { padding: 6px 10px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.user-menu-dropdown button { width: 100%; text-align: left; background: transparent; border: none; color: var(--ink); padding: 8px 10px; border-radius: 4px; cursor: pointer; }
.user-menu-dropdown button:hover { background: rgba(255,255,255,.06); }

/* ---------------------------------------------------------------- sidenav */
.sidenav {
  position: fixed; top: var(--topbar-h); left: 0; bottom: 0; width: var(--sidenav-w);
  overflow-y: auto; background: var(--surface); border-right: 1px solid var(--line); padding: var(--sp-4) var(--sp-2);
  z-index: 30;
}
.app-content { margin-left: var(--sidenav-w); }
.sidenav-group { margin-bottom: var(--sp-6); }
.sidenav-group-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; padding: 0 10px; margin-bottom: 6px; }
.sidenav-link {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius); color: var(--ink);
  cursor: pointer; font-size: 13.5px;
}
.sidenav-link:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.sidenav-link.active { background: rgba(63,182,139,.14); color: var(--accent); }
.sidenav-link .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.sidenav-link.active .dot { background: var(--accent); }
.sidenav-toggle { display: none; }
@media (max-width: 900px) {
  .sidenav { transform: translateX(-100%); transition: transform .18s ease; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .sidenav.open { transform: translateX(0); }
  .app-content { margin-left: 0; }
  .sidenav-toggle { display: inline-flex; }
}

/* ------------------------------------------------------------- acting-as */
.banner-actas {
  background: rgba(224,166,58,.12); border: 1px solid rgba(224,166,58,.35); color: var(--warn);
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: var(--sp-4);
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap;
}
.banner-actas b { color: var(--ink); }
.banner-actas button { flex-shrink: 0; }

/* ------------------------------------------------------------- page head */
.page-header { margin-bottom: var(--sp-6); display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; }
.page-header h1 { font-size: 22px; line-height: 28px; font-weight: 600; }
.page-header .explainer { color: var(--muted); margin-top: 4px; max-width: 62ch; }
.page-header .actions { display: flex; gap: var(--sp-2); flex-shrink: 0; }
.page-tabs-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-4); }

/* -------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--raised); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px 14px; font-size: 13.5px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: rgba(255,255,255,.09); }
.btn:disabled { opacity: .5; cursor: default; }
.btn--sm { padding: 5px 10px; font-size: 12.5px; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn--primary:hover { background: #37a67e; }
.btn--ghost { background: transparent; }
.btn--danger { background: transparent; border-color: rgba(225,91,91,.4); color: var(--danger); }
.btn--danger:hover { background: rgba(225,91,91,.1); }
.btn-icon { width: 32px; height: 32px; padding: 0; }

/* ---------------------------------------------------------------- cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--sp-4); }
.card + .card { margin-top: var(--sp-4); }
.card h2 { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.card .sub { color: var(--muted); font-size: 12.5px; margin-bottom: var(--sp-3); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--sp-4); }

/* --------------------------------------------------------------- stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--sp-4); margin-bottom: var(--sp-4); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--sp-4); }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 26px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .delta { font-size: 12px; margin-top: 4px; color: var(--muted); }
.stat .delta.up { color: var(--accent); }
.stat .delta.down { color: var(--danger); }

/* --------------------------------------------------------------- tables */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
table.data-table { width: 100%; border-collapse: collapse; min-width: 560px; }
.data-table thead th {
  position: sticky; top: 0; background: var(--raised); text-align: left; color: var(--muted);
  font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 10px 14px; border-bottom: 1px solid var(--line);
  cursor: default; white-space: nowrap; z-index: 1;
}
.data-table thead th.sortable { cursor: pointer; user-select: none; }
.data-table thead th.sortable:hover { color: var(--ink); }
.data-table thead th .arrow { margin-left: 4px; color: var(--accent); }
.data-table tbody td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table tbody tr.clickable:hover { background: rgba(255,255,255,.04); }
.row-link { color: var(--ink); text-decoration: none; }
.data-table tbody tr.clickable:hover .row-link { color: var(--accent); }
.data-table .empty-row td { padding: 40px 14px; text-align: center; color: var(--muted); }
.data-table .empty-row .hint { display: block; margin-top: 6px; font-size: 12.5px; }

.empty-state { padding: 48px 24px; text-align: center; color: var(--muted); }
.empty-state .title { color: var(--ink); font-weight: 600; margin-bottom: 6px; }
.empty-state .hint { font-size: 12.5px; }

/* ---------------------------------------------------------------- badge */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: rgba(255,255,255,.08); color: var(--muted); }
.badge.ok, .badge.active, .badge.live { background: rgba(63,182,139,.16); color: var(--accent); }
.badge.warn, .badge.pending { background: rgba(224,166,58,.16); color: var(--warn); }
.badge.danger, .badge.suspended, .badge.failed { background: rgba(225,91,91,.16); color: var(--danger); }
.badge-count { background: var(--danger); color: #fff; border-radius: 999px; font-size: 10.5px; padding: 1px 6px; margin-left: 6px; }

/* ---------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs .tab { padding: 9px 4px; margin-right: var(--sp-4); background: transparent; border: none; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; font-size: 13.5px; }
.tabs .tab:hover { color: var(--ink); }
.tabs .tab.active { color: var(--ink); border-bottom-color: var(--accent); }

/* --------------------------------------------------------------- forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); }
.field label { font-size: 12.5px; color: var(--muted); }
.field .hint { font-size: 12px; color: var(--muted); }
.field .err { font-size: 12px; color: var(--danger); }
.field.has-err input, .field.has-err select, .field.has-err textarea { border-color: var(--danger); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=search], input[type=tel], select, textarea {
  background: var(--raised); border: 1px solid var(--line); color: var(--ink); border-radius: var(--radius);
  padding: 8px 10px; font: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(63,182,139,.5); outline-offset: 0; border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 var(--sp-4); }
.form-actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-2); }

/* -------------------------------------------------------------- drawer */
.drawer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 60; display: flex; justify-content: flex-end; }
.drawer { width: 420px; max-width: 100vw; background: var(--surface); border-left: 1px solid var(--line); height: 100%; overflow-y: auto; padding: var(--sp-6); }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: var(--sp-4); }
.drawer-head h2 { font-size: 18px; }
.drawer-close { background: transparent; border: none; color: var(--muted); font-size: 20px; cursor: pointer; line-height: 1; }
.drawer-close:hover { color: var(--ink); }

/* ---------------------------------------------------------------- toast */
.toast-stack { position: fixed; bottom: var(--sp-4); right: var(--sp-4); z-index: 90; display: flex; flex-direction: column; gap: 8px; max-width: 340px; }
.toast { background: var(--raised); border: 1px solid var(--line); border-left: 3px solid var(--accent); color: var(--ink); border-radius: var(--radius); padding: 10px 14px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }

/* ------------------------------------------------------------- skeleton */
.skeleton { background: linear-gradient(90deg, var(--raised) 25%, rgba(255,255,255,.09) 37%, var(--raised) 63%); background-size: 400% 100%; animation: sk 1.4s ease infinite; border-radius: 4px; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.skeleton-line { height: 14px; margin-bottom: 8px; }
.skeleton-block { height: 80px; }

/* ------------------------------------------------------------- confirm */
.confirm-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 100; display: flex; align-items: center; justify-content: center; }
.confirm-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--sp-6); width: 380px; max-width: calc(100vw - 32px); }
.confirm-box h3 { margin-bottom: 8px; }
.confirm-box p { color: var(--muted); margin-bottom: var(--sp-4); }
.confirm-box .form-actions { justify-content: flex-end; }

/* ---------------------------------------------------------------- misc */
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.hidden { display: none !important; }
.pill-row { display: flex; gap: 8px; flex-wrap: wrap; }
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 380px; max-width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--sp-8) var(--sp-6); }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card .sub { color: var(--muted); margin-bottom: var(--sp-6); font-size: 13px; }
.login-card .divider { text-align: center; color: var(--muted); font-size: 12px; margin: var(--sp-4) 0; }
.chooser-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; cursor: pointer; }
.chooser-item:hover { border-color: var(--accent); }

/* -------------------------------------------------------------- charts */
.chart-wrap { width: 100%; overflow: hidden; }
.chart-wrap svg { display: block; width: 100%; height: auto; }
.chart-legend { display: flex; gap: var(--sp-4); margin-top: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.chart-legend .swatch { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.chart-axis-label { fill: var(--muted); font-size: 10px; }
.chart-gridline { stroke: var(--line); stroke-width: 1; }

@media (max-width: 390px) {
  .page-header h1 { font-size: 19px; }
  .stat .value { font-size: 21px; }
  .drawer { width: 100vw; padding: var(--sp-4); }
}

/* ---------------------------------------------------------- Nox parity: journey drawer + ask card */
.journey-summary { margin-bottom: var(--sp-4); padding-bottom: var(--sp-4); border-bottom: 1px solid var(--line); }
.journey-identity { font-size: 15px; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.journey-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 12.5px; color: var(--muted); }
.journey-timeline { display: flex; flex-direction: column; gap: 0; }
.journey-row { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.journey-row:last-child { border-bottom: none; }
.journey-row--event .jt-body { color: var(--muted); font-size: 13px; }
.jt-time { width: 92px; flex-shrink: 0; color: var(--muted); font-size: 11.5px; padding-top: 1px; }
.jt-body { flex: 1; min-width: 0; }
.jt-body .mono { word-break: break-all; }
.journey-factors { display: flex; flex-wrap: wrap; gap: 6px; }

.ask-card { display: flex; flex-direction: column; gap: 10px; }
.ask-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.ask-chip { background: var(--raised); border: 1px solid var(--line); color: var(--ink); border-radius: 999px; padding: 6px 12px; font-size: 12.5px; cursor: pointer; }
.ask-chip:hover { border-color: var(--accent); color: var(--accent); }
.ask-thread { display: flex; flex-direction: column; gap: 10px; max-height: 320px; overflow-y: auto; }
.ask-bubble { max-width: 88%; padding: 8px 12px; border-radius: 8px; font-size: 13.5px; }
.ask-bubble.q { background: var(--raised); margin-right: auto; }
.ask-bubble.a { background: rgba(63,182,139,.14); margin-left: auto; }
.ask-input-row { display: flex; gap: 8px; }
.ask-input-row input { flex: 1; }
