/* ============================================================
   AlgoPartner — Master Operator Console
   Design tokens + theme + components
   ============================================================ */

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

/* ---------- Tokens: shared ---------- */
:root {
  --font-ui: 'Hanken Grotesk', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;

  --r-xs: 5px;
  --r-sm: 7px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-full: 999px;

  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-7: 32px; --sp-8: 40px; --sp-10: 56px;

  --sidebar-w: 248px;
  --sidebar-w-collapsed: 64px;
  --topbar-h: 60px;

  --ease: cubic-bezier(.4, 0, .2, 1);
  --speed: .18s;

  /* semantic hues — shared chroma/lightness, vary hue */
  --accent-h: 256;
}

/* ---------- Dark theme (default) ---------- */
:root, [data-theme="dark"] {
  --bg:            oklch(0.165 0.006 264);
  --bg-grad:       oklch(0.185 0.008 264);
  --surface:       oklch(0.205 0.007 264);
  --surface-2:     oklch(0.228 0.008 264);
  --surface-3:     oklch(0.255 0.010 264);
  --surface-hover: oklch(0.275 0.011 264);

  --border:        oklch(0.30 0.010 264);
  --border-soft:   oklch(0.26 0.009 264);
  --border-strong: oklch(0.40 0.014 264);

  --text:          oklch(0.97 0.003 264);
  --text-muted:    oklch(0.72 0.008 264);
  --text-faint:    oklch(0.56 0.010 264);

  --accent:        oklch(0.66 0.155 var(--accent-h));
  --accent-strong: oklch(0.72 0.165 var(--accent-h));
  --accent-soft:   oklch(0.66 0.155 var(--accent-h) / 0.14);
  --accent-line:   oklch(0.66 0.155 var(--accent-h) / 0.40);
  --on-accent:     oklch(0.99 0 0);

  --success:       oklch(0.74 0.15 158);
  --success-soft:  oklch(0.74 0.15 158 / 0.15);
  --warning:       oklch(0.80 0.13 78);
  --warning-soft:  oklch(0.80 0.13 78 / 0.15);
  --danger:        oklch(0.68 0.17 22);
  --danger-soft:   oklch(0.68 0.17 22 / 0.15);
  --info:          oklch(0.72 0.10 230);
  --info-soft:     oklch(0.72 0.10 230 / 0.15);
  --neutral-soft:  oklch(0.50 0.01 264 / 0.22);

  --shadow-sm: 0 1px 2px oklch(0 0 0 / .35);
  --shadow-md: 0 6px 20px -6px oklch(0 0 0 / .55);
  --shadow-lg: 0 24px 60px -12px oklch(0 0 0 / .65);
  --overlay: oklch(0.10 0.006 264 / 0.62);

  color-scheme: dark;
}

/* ---------- Light theme ---------- */
[data-theme="light"] {
  --bg:            oklch(0.975 0.003 264);
  --bg-grad:       oklch(0.955 0.005 264);
  --surface:       oklch(1 0 0);
  --surface-2:     oklch(1 0 0);
  --surface-3:     oklch(0.975 0.004 264);
  --surface-hover: oklch(0.965 0.005 264);

  --border:        oklch(0.91 0.005 264);
  --border-soft:   oklch(0.94 0.004 264);
  --border-strong: oklch(0.85 0.007 264);

  --text:          oklch(0.24 0.012 264);
  --text-muted:    oklch(0.48 0.012 264);
  --text-faint:    oklch(0.62 0.012 264);

  --accent:        oklch(0.55 0.18 var(--accent-h));
  --accent-strong: oklch(0.50 0.19 var(--accent-h));
  --accent-soft:   oklch(0.55 0.18 var(--accent-h) / 0.10);
  --accent-line:   oklch(0.55 0.18 var(--accent-h) / 0.30);
  --on-accent:     oklch(0.99 0 0);

  --success:       oklch(0.55 0.14 158);
  --success-soft:  oklch(0.55 0.14 158 / 0.12);
  --warning:       oklch(0.62 0.13 70);
  --warning-soft:  oklch(0.70 0.14 78 / 0.16);
  --danger:        oklch(0.56 0.19 22);
  --danger-soft:   oklch(0.56 0.19 22 / 0.10);
  --info:          oklch(0.55 0.12 230);
  --info-soft:     oklch(0.55 0.12 230 / 0.10);
  --neutral-soft:  oklch(0.60 0.01 264 / 0.14);

  --shadow-sm: 0 1px 2px oklch(0.5 0.02 264 / .10);
  --shadow-md: 0 8px 24px -8px oklch(0.4 0.03 264 / .18);
  --shadow-lg: 0 28px 64px -16px oklch(0.4 0.03 264 / .26);
  --overlay: oklch(0.42 0.02 264 / 0.34);

  color-scheme: light;
}

/* ---------- Reset / base ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  letter-spacing: -0.005em;
}
#root { height: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: inherit; text-decoration: none; }
::selection { background: var(--accent-soft); }
.mono { font-family: var(--font-mono); font-feature-settings: "tnum" 1; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* scrollbars */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   APP SHELL
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  transition: grid-template-columns var(--speed) var(--ease);
}
.app.collapsed { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  height: 100dvh; /* dynamic viewport — mobile chrome doesn't clip the drawer's bottom groups */
  position: relative;
  z-index: 40;
}
.sb-brandhead {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.logo-mark {
  width: 30px; height: 30px; flex-shrink: 0;
  border-radius: 8px;
  background: linear-gradient(140deg, var(--accent-strong), var(--accent));
  display: grid; place-items: center;
  box-shadow: 0 2px 10px var(--accent-soft);
}
.logo-mark svg { display: block; }
.logo-word { font-weight: 800; font-size: 15.5px; letter-spacing: -0.02em; white-space: nowrap; }
.logo-word b { color: var(--accent); }
.collapsed .logo-word, .collapsed .sb-pick-meta, .collapsed .nav-label,
.collapsed .nav-group-label, .collapsed .sb-foot-text { display: none; }

/* brand picker */
.sb-picker-wrap { padding: var(--sp-3) var(--sp-3) var(--sp-2); flex-shrink: 0; }
.sb-picker {
  width: 100%;
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  transition: border-color var(--speed), background var(--speed);
  text-align: left;
}
.sb-picker:hover { border-color: var(--border-strong); background: var(--surface-3); }
.sb-picker.open { border-color: var(--accent-line); }
.brand-avatar {
  width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0;
  display: grid; place-items: center;
  font-weight: 700; font-size: 12px; color: var(--on-accent);
}
.sb-pick-meta { flex: 1; min-width: 0; }
.sb-pick-meta .nm { display: block; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-pick-meta .sub { display: block; font-size: 11px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.collapsed .sb-picker { justify-content: center; padding: var(--sp-2); }
.collapsed .sb-picker .chev { display: none; }

.brand-menu {
  position: absolute; left: var(--sp-3); right: var(--sp-3);
  top: calc(var(--topbar-h) + 50px);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-1);
  z-index: 60;
  animation: pop .14s var(--ease);
}
.brand-menu-item {
  width: 100%; display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-2);
  border-radius: var(--r-sm); text-align: left;
}
.brand-menu-item:hover { background: var(--surface-hover); }
.brand-menu-item.active { background: var(--accent-soft); }
.brand-menu-item .nm { font-size: 13px; font-weight: 600; flex: 1; }
.brand-menu-item .ck { color: var(--accent); }
.brand-menu-sep { height: 1px; background: var(--border-soft); margin: var(--sp-1) var(--sp-2); }

/* nav */
.nav { flex: 1; overflow-y: auto; padding: var(--sp-2) var(--sp-3) var(--sp-4); }
.nav-group { margin-top: var(--sp-4); }
.nav-group:first-child { margin-top: var(--sp-1); }
.nav-group-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--text-faint); padding: var(--sp-2) var(--sp-3) var(--sp-1);
}
.nav-item {
  width: 100%;
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 8px var(--sp-3);
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-size: 13.5px; font-weight: 500;
  position: relative;
  transition: background var(--speed), color var(--speed);
  margin-bottom: 1px;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.nav-item.active::before {
  content: ""; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 18px; border-radius: 3px; background: var(--accent);
}
.nav-item .nav-ic { flex-shrink: 0; display: grid; place-items: center; width: 18px; }
.nav-label { flex: 1; white-space: nowrap; }
.nav-badge {
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 600;
  background: var(--surface-3); color: var(--text-muted);
  border-radius: var(--r-full); padding: 1px 7px; min-width: 20px; text-align: center;
}
.nav-item.active .nav-badge { background: var(--accent); color: var(--on-accent); }
.nav-item.master::after {
  content: "M"; font-family: var(--font-mono); font-size: 9px; font-weight: 700;
  color: var(--warning); background: var(--warning-soft);
  border-radius: 4px; padding: 1px 4px; line-height: 1.2;
}
.collapsed .nav-item { justify-content: center; padding: 9px; }
.collapsed .nav-badge, .collapsed .nav-item.master::after { display: none; }
.collapsed .nav-item.active::before { left: 0; }

.sb-foot { border-top: 1px solid var(--border-soft); padding: var(--sp-3); flex-shrink: 0; }
.sb-collapse-btn {
  width: 100%; display: flex; align-items: center; gap: var(--sp-3);
  padding: 7px var(--sp-3); border-radius: var(--r-sm); color: var(--text-faint); font-size: 12.5px;
}
.sb-collapse-btn:hover { background: var(--surface-hover); color: var(--text); }
.collapsed .sb-collapse-btn { justify-content: center; }

/* ---------- Main column ---------- */
.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; height: 100dvh; overflow: hidden; background: var(--bg); }

/* topbar */
.topbar {
  height: var(--topbar-h); flex-shrink: 0;
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-6);
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklch, var(--surface) 70%, transparent);
  backdrop-filter: blur(8px);
}
.tb-mobile-btn { display: none; }
.tb-context { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.tb-brandname { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; white-space: nowrap; }
.tb-spacer { flex: 1; }
.tb-actions { display: flex; align-items: center; gap: var(--sp-2); }

.env-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  padding: 4px 10px; border-radius: var(--r-full);
  background: var(--success-soft); color: var(--success);
  border: 1px solid color-mix(in oklch, var(--success) 30%, transparent);
}
.env-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; box-shadow: 0 0 8px currentColor; }
.env-chip.staging { background: var(--warning-soft); color: var(--warning); border-color: color-mix(in oklch, var(--warning) 30%, transparent); }

.icon-btn {
  width: 36px; height: 36px; border-radius: var(--r-sm);
  display: grid; place-items: center; color: var(--text-muted);
  transition: background var(--speed), color var(--speed);
  position: relative;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn .ping { position: absolute; top: 7px; right: 8px; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); border: 2px solid var(--surface); }

.admin-chip {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 4px 6px 4px 4px; border-radius: var(--r-full);
  border: 1px solid var(--border); background: var(--surface-2);
  transition: border-color var(--speed);
}
.admin-chip:hover { border-color: var(--border-strong); }
.admin-av { width: 28px; height: 28px; border-radius: 50%; background: linear-gradient(140deg, var(--accent-strong), var(--accent)); color: var(--on-accent); display: grid; place-items: center; font-weight: 700; font-size: 11px; }
.admin-chip .who { font-size: 12.5px; font-weight: 600; padding-right: 2px; white-space: nowrap; }

/* dropdown menu (shared) */
.menu {
  position: absolute; top: calc(100% + 6px); right: 0;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  padding: var(--sp-1); min-width: 180px; z-index: 70; animation: pop .14s var(--ease);
}
.menu-item { width: 100%; display: flex; align-items: center; gap: var(--sp-3); padding: 8px 10px; border-radius: var(--r-sm); font-size: 13px; text-align: left; color: var(--text); }
.menu-item:hover { background: var(--surface-hover); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-soft); }
.menu-sep { height: 1px; background: var(--border-soft); margin: var(--sp-1) var(--sp-2); }
.menu-head { padding: 8px 10px 6px; font-size: 11px; color: var(--text-faint); font-weight: 600; }

/* page scroll area */
.page-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; }
.page { padding: var(--sp-6) var(--sp-7) var(--sp-8); max-width: 1480px; margin: 0 auto; }

/* page header */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-6); flex-wrap: wrap; }
.page-head .ph-titles { min-width: 0; }
.page-eyebrow { font-size: 12px; font-weight: 600; color: var(--text-faint); display: flex; align-items: center; gap: 7px; margin-bottom: 4px; white-space: nowrap; flex-wrap: wrap; }
.page-eyebrow .sep { color: var(--border-strong); }
.page-title { font-size: 24px; font-weight: 800; letter-spacing: -0.025em; }
.page-sub { color: var(--text-muted); font-size: 13.5px; margin-top: 3px; }
.page-head-actions { display: flex; align-items: center; gap: var(--sp-2); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: var(--r-sm);
  font-size: 13px; font-weight: 600; white-space: nowrap;
  border: 1px solid transparent;
  transition: background var(--speed), border-color var(--speed), color var(--speed), transform .06s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.btn-ghost { color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in oklch, var(--danger) 28%, transparent); }
.btn-danger:hover { background: var(--danger); color: var(--on-accent); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; border-radius: var(--r-xs); }
.btn-icon-only { padding: 0; width: 36px; }
.btn-block { width: 100%; }

/* ============================================================
   CARDS / PANELS
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.card-pad { padding: var(--sp-5); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border-soft); }
.panel-head > div:first-child { flex: 1; min-width: 0; }
.panel-head h3 { font-size: 14.5px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-head .sub { font-size: 12px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-head .seg, .panel-head .btn { flex-shrink: 0; }

/* ---------- KPI / stat cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-4); }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: var(--sp-5) var(--sp-5) 34px; position: relative; overflow: hidden; min-height: 138px;
  transition: border-color var(--speed), transform var(--speed);
}
.kpi:hover { border-color: var(--border-strong); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-3); }
.kpi-label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.kpi-ic { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.kpi-ic.green { background: var(--success-soft); color: var(--success); }
.kpi-ic.amber { background: var(--warning-soft); color: var(--warning); }
.kpi-ic.red { background: var(--danger-soft); color: var(--danger); }
.kpi-value { font-family: var(--font-mono); font-size: 27px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.kpi-foot { display: flex; align-items: center; gap: var(--sp-2); margin-top: var(--sp-3); font-size: 12px; white-space: nowrap; position: relative; z-index: 1; }
.kpi-foot .ctx { white-space: nowrap; }
.kpi-delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 700; font-family: var(--font-mono); font-size: 11.5px; padding: 2px 6px; border-radius: var(--r-xs); }
.kpi-delta.up { color: var(--success); background: var(--success-soft); }
.kpi-delta.down { color: var(--danger); background: var(--danger-soft); }
.kpi-delta.flat { color: var(--text-muted); background: var(--neutral-soft); }
.kpi-foot .ctx { color: var(--text-faint); }
.kpi-spark { position: absolute; right: 0; bottom: 0; left: 0; opacity: .5; pointer-events: none; display: flex; justify-content: flex-end; }

/* dashboard layout */
.dash-cols { display: grid; grid-template-columns: 1.6fr 1fr; gap: var(--sp-4); margin-top: var(--sp-4); }
.section-gap { margin-top: var(--sp-4); }

/* brand summary list */
.brand-row { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-5); border-bottom: 1px solid var(--border-soft); transition: background var(--speed); }
.brand-row:last-child { border-bottom: none; }
.brand-row:hover { background: var(--surface-hover); }
.brand-row .bmeta { flex: 1; min-width: 0; }
.brand-row .bmeta .nm { font-weight: 600; font-size: 13.5px; }
.brand-row .bmeta .sub { font-size: 11.5px; color: var(--text-faint); }
.brand-row .bstat { text-align: right; }
.brand-row .bstat .v { font-family: var(--font-mono); font-weight: 600; font-size: 13.5px; }
.brand-row .bstat .l { font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .04em; }

/* activity feed */
.feed { padding: var(--sp-2) 0; }
.feed-item { display: flex; gap: var(--sp-3); padding: var(--sp-3) var(--sp-5); position: relative; }
.feed-item:hover { background: var(--surface-hover); }
.feed-ic { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; flex-shrink: 0; background: var(--surface-3); color: var(--text-muted); }
.feed-ic.green { background: var(--success-soft); color: var(--success); }
.feed-ic.amber { background: var(--warning-soft); color: var(--warning); }
.feed-ic.red { background: var(--danger-soft); color: var(--danger); }
.feed-ic.accent { background: var(--accent-soft); color: var(--accent); }
.feed-body { flex: 1; min-width: 0; }
.feed-body .txt { font-size: 13px; line-height: 1.4; }
.feed-body .txt b { font-weight: 600; }
.feed-body .meta { font-size: 11px; color: var(--text-faint); margin-top: 2px; display: flex; gap: 8px; }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; line-height: 1;
  padding: 4px 9px; border-radius: var(--r-full);
  white-space: nowrap;
}
.badge .bdot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.green { color: var(--success); background: var(--success-soft); }
.badge.amber { color: var(--warning); background: var(--warning-soft); }
.badge.red { color: var(--danger); background: var(--danger-soft); }
.badge.blue { color: var(--info); background: var(--info-soft); }
.badge.accent { color: var(--accent); background: var(--accent-soft); }
.badge.neutral { color: var(--text-muted); background: var(--neutral-soft); }

/* ============================================================
   DATA TABLE
   ============================================================ */
.toolbar { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border-soft); flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
.search {
  display: flex; align-items: center; gap: var(--sp-2);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 0 10px; height: 34px; min-width: 220px; color: var(--text-faint);
  transition: border-color var(--speed);
}
.search:focus-within { border-color: var(--accent-line); }
.search input { background: none; border: none; outline: none; flex: 1; font-size: 13px; color: var(--text); }
.search input::placeholder { color: var(--text-faint); }

.filter-pill {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 12px;
  border-radius: var(--r-sm); border: 1px solid var(--border); background: var(--surface-2);
  font-size: 12.5px; font-weight: 500; color: var(--text-muted); transition: all var(--speed);
}
.filter-pill:hover { border-color: var(--border-strong); color: var(--text); }
.filter-pill.active { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-strong); }
.filter-pill .ct { font-family: var(--font-mono); font-size: 11px; opacity: .7; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 2px; gap: 2px; }
.seg button { padding: 4px 11px; border-radius: var(--r-xs); font-size: 12.5px; font-weight: 600; color: var(--text-muted); height: 28px; }
.seg button.active { background: var(--surface-3); color: var(--text); box-shadow: var(--shadow-sm); }

.table-scroll { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl thead th {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface-3);
  text-align: left; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-faint); padding: 10px var(--sp-4); white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.tbl thead th.sortable { cursor: pointer; user-select: none; }
.tbl thead th.sortable:hover { color: var(--text); }
.tbl thead th .th-in { display: inline-flex; align-items: center; gap: 5px; }
.tbl thead th.right { text-align: right; }
.tbl thead th.right .th-in { flex-direction: row-reverse; }
.tbl tbody td { padding: 11px var(--sp-4); border-bottom: 1px solid var(--border-soft); white-space: nowrap; }
.tbl tbody tr { transition: background var(--speed); cursor: pointer; }
.tbl tbody tr:hover { background: var(--surface-hover); }
.tbl tbody tr.sel { background: var(--accent-soft); }
.tbl td.right { text-align: right; }
.td-strong { font-weight: 600; }
.td-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.td-muted { color: var(--text-muted); }
.td-faint { color: var(--text-faint); font-size: 12px; }
.cell-user { display: flex; align-items: center; gap: var(--sp-3); }
.cell-user .av { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 11px; color: var(--on-accent); flex-shrink: 0; }
.cell-user .cu-meta { min-width: 0; }
.cell-user .cu-meta .nm { font-weight: 600; }
.cell-user .cu-meta .sub { font-size: 11.5px; color: var(--text-faint); }

.row-actions { display: flex; align-items: center; gap: 4px; justify-content: flex-end; }
.row-act-btn { width: 30px; height: 30px; border-radius: var(--r-xs); display: grid; place-items: center; color: var(--text-faint); transition: all var(--speed); }
.row-act-btn:hover { background: var(--surface-3); color: var(--text); }
tr:hover .row-act-btn { color: var(--text-muted); }

/* table footer / pagination */
.tbl-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border-soft); flex-wrap: wrap; }
.tbl-foot .info { font-size: 12.5px; color: var(--text-faint); }
.tbl-foot .info b { color: var(--text); font-family: var(--font-mono); }
.pager { display: flex; align-items: center; gap: 3px; }
.pager button { min-width: 30px; height: 30px; padding: 0 7px; border-radius: var(--r-xs); font-size: 12.5px; font-weight: 600; color: var(--text-muted); font-family: var(--font-mono); }
.pager button:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }
.pager button.active { background: var(--accent); color: var(--on-accent); }
.pager button:disabled { opacity: .4; cursor: not-allowed; }

/* ============================================================
   STATES: empty / loading / error
   ============================================================ */
.state { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: var(--sp-10) var(--sp-6); gap: var(--sp-3); }
.state-ic { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-faint); margin-bottom: 2px; }
.state-ic.error { background: var(--danger-soft); color: var(--danger); }
.state h4 { font-size: 16px; font-weight: 700; }
.state p { font-size: 13px; color: var(--text-muted); max-width: 380px; }
.state-actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-2); }

.skel { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-hover) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: var(--r-xs); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.skel-row { display: flex; align-items: center; gap: var(--sp-3); padding: 11px var(--sp-4); border-bottom: 1px solid var(--border-soft); }

/* ============================================================
   MODAL + DRAWER
   ============================================================ */
.overlay {
  position: fixed; inset: 0; background: var(--overlay); z-index: 100;
  display: flex; backdrop-filter: blur(2px); animation: fade .16s var(--ease);
}
.overlay.center { align-items: center; justify-content: center; padding: var(--sp-6); }
.overlay.right { justify-content: flex-end; }

.modal {
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-xl); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 580px; max-height: 90vh; display: flex; flex-direction: column;
  animation: modalIn .2s var(--ease);
}
.modal.lg { max-width: 720px; }
.drawer {
  background: var(--surface); border-left: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 480px; height: 100vh;
  display: flex; flex-direction: column; animation: drawerIn .22s var(--ease);
}
.drawer.wide { max-width: 620px; }

.modal-head { display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-5) var(--sp-5) var(--sp-4); border-bottom: 1px solid var(--border-soft); }
.modal-head .mh-titles { flex: 1; min-width: 0; }
.modal-head h3 { font-size: 17px; font-weight: 700; letter-spacing: -0.015em; }
.modal-head .sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.modal-body { padding: var(--sp-5); overflow-y: auto; flex: 1; }
.modal-foot { display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border-soft); }
.modal-foot .grow { flex: 1; }

/* sensitive banner */
.sensitive-banner { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); background: var(--warning-soft); border: 1px solid color-mix(in oklch, var(--warning) 28%, transparent); color: var(--warning); font-size: 12.5px; font-weight: 500; margin-bottom: var(--sp-4); }
.sensitive-banner b { font-weight: 700; }

/* ============================================================
   FORMS
   ============================================================ */
.field { margin-bottom: var(--sp-4); }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; }
.field .hint { font-size: 11.5px; color: var(--text-faint); margin-top: 5px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }
.input, .textarea, .select {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 9px 11px; font-size: 13.5px; color: var(--text); transition: border-color var(--speed), box-shadow var(--speed); outline: none;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder { color: var(--text-faint); }
.input.mono { font-family: var(--font-mono); }
.textarea { resize: vertical; min-height: 84px; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.6; }
.select { appearance: none; cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
.input-prefix { position: relative; }
.input-prefix .pfx { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-faint); font-family: var(--font-mono); font-size: 13px; pointer-events: none; }
.input-prefix .input { padding-left: 30px; }

/* toggle */
.toggle { width: 38px; height: 22px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border); position: relative; transition: background var(--speed), border-color var(--speed); flex-shrink: 0; }
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--text-faint); transition: transform var(--speed), background var(--speed); }
.toggle.on { background: var(--accent); border-color: var(--accent); }
.toggle.on::after { transform: translateX(16px); background: var(--on-accent); }

/* multi-select chips (Pines) */
.chips-field { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); min-height: 44px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 4px 6px 4px 10px; border-radius: var(--r-full); background: var(--accent-soft); color: var(--accent-strong); }
.chip button { display: grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; color: currentColor; opacity: .7; }
.chip button:hover { opacity: 1; background: color-mix(in oklch, var(--accent) 20%, transparent); }
.chip-opt { display: flex; align-items: center; gap: var(--sp-3); padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer; }
.chip-opt:hover { background: var(--surface-hover); }
.chk { width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid var(--border-strong); display: grid; place-items: center; flex-shrink: 0; transition: all var(--speed); }
.chk.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* segmented type/labels in forms */
.radio-cards { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
.radio-card { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r-sm); cursor: pointer; transition: all var(--speed); }
.radio-card:hover { border-color: var(--border-strong); }
.radio-card.on { border-color: var(--accent); background: var(--accent-soft); }
.radio-card .rc-t { font-size: 13px; font-weight: 600; }
.radio-card .rc-s { font-size: 11.5px; color: var(--text-faint); margin-top: 1px; }

/* drawer detail rows */
.detail-hero { display: flex; align-items: center; gap: var(--sp-4); padding: var(--sp-5); border-bottom: 1px solid var(--border-soft); }
.detail-hero .av-lg { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; font-weight: 700; font-size: 18px; color: var(--on-accent); flex-shrink: 0; }
.detail-hero .dh-meta h3 { font-size: 17px; font-weight: 700; }
.detail-hero .dh-meta .sub { font-size: 12.5px; color: var(--text-muted); font-family: var(--font-mono); }
.detail-list { padding: var(--sp-2) 0; }
.detail-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); padding: 10px var(--sp-5); }
.detail-row .k { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.detail-row .v { font-size: 13px; font-weight: 600; text-align: right; min-width: 0; }
.detail-section-label .dsl-t { white-space: nowrap; }
.detail-section-label { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-faint); padding: var(--sp-4) var(--sp-5) 6px; }

/* code / payload block */
.code-block { background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--sp-4); font-family: var(--font-mono); font-size: 12px; line-height: 1.65; overflow-x: auto; white-space: pre; color: var(--text-muted); }
.code-block .k { color: var(--accent); }
.code-block .s { color: var(--success); }
.code-block .n { color: var(--warning); }

/* masked secret value */
.secret-val { display: inline-flex; align-items: center; gap: var(--sp-2); font-family: var(--font-mono); font-size: 12.5px; }
.secret-val .masked { letter-spacing: 2px; color: var(--text-faint); }

/* toast */
.toast-wrap { position: fixed; bottom: var(--sp-6); left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: var(--sp-2); align-items: center; }
.toast { display: flex; align-items: center; gap: var(--sp-3); background: var(--surface-3); border: 1px solid var(--border-strong); border-radius: var(--r-md); padding: 11px 16px; box-shadow: var(--shadow-lg); font-size: 13px; font-weight: 500; animation: toastIn .22s var(--ease); min-width: 260px; }
.toast .ti { display: grid; place-items: center; flex-shrink: 0; }
.toast.success .ti { color: var(--success); }
.toast.error .ti { color: var(--danger); }
.toast.info .ti { color: var(--accent); }

/* tiny meta tag */
.kbd { font-family: var(--font-mono); font-size: 10.5px; padding: 1px 5px; border-radius: 4px; background: var(--surface-3); border: 1px solid var(--border); color: var(--text-faint); }

/* product grid */
.prod-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-4); }
.prod-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-5); transition: border-color var(--speed), transform var(--speed); position: relative; }
.prod-card:hover { border-color: var(--border-strong); }
.prod-card .pc-top { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: var(--sp-4); }
.prod-icon { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.prod-card h4 { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.prod-card .pc-desc { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; line-height: 1.5; min-height: 38px; }
.prod-price { font-family: var(--font-mono); font-size: 18px; font-weight: 600; margin-top: var(--sp-3); }
.prod-price span { font-size: 12px; color: var(--text-faint); font-weight: 400; }
.prod-pines { display: flex; flex-wrap: wrap; gap: 5px; margin-top: var(--sp-4); padding-top: var(--sp-4); border-top: 1px solid var(--border-soft); }
.pine-tag { font-family: var(--font-mono); font-size: 10.5px; font-weight: 500; padding: 3px 7px; border-radius: var(--r-xs); background: var(--surface-3); color: var(--text-muted); }
.prod-card .pc-foot { display: flex; align-items: center; justify-content: space-between; margin-top: var(--sp-4); }

/* sparkline svg helpers */
.spark-area { display: block; }

/* placeholder image */
.img-ph { background-image: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 8px, var(--surface-3) 8px, var(--surface-3) 16px); border: 1px dashed var(--border-strong); border-radius: var(--r-md); display: grid; place-items: center; color: var(--text-faint); font-family: var(--font-mono); font-size: 11px; }

/* divider */
.vsep { width: 1px; height: 22px; background: var(--border); }

/* mobile backdrop */
.sb-backdrop { display: none; }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(-6px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes drawerIn { from { transform: translateX(30px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1180px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-cols { grid-template-columns: 1fr; }
  .prod-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 920px) {
  .app { grid-template-columns: 1fr !important; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w);
    transform: translateX(-100%); transition: transform var(--speed) var(--ease);
  }
  .app.mobile-open .sidebar { transform: none; }
  .app.mobile-open .sb-backdrop { display: block; position: fixed; inset: 0; background: var(--overlay); z-index: 35; }
  .tb-mobile-btn { display: grid; }
  .page { padding: var(--sp-5) var(--sp-4) var(--sp-7); }
  .topbar { padding: 0 var(--sp-4); }
  .tb-brandname { font-size: 14px; }
}
@media (max-width: 560px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .prod-grid { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
  .page-title { font-size: 20px; }
  .admin-chip .who { display: none; }
}

/* ============================================================
   MASTER-CONSOLE ADDITIONS (vanilla reskin — not in prototype)
   ============================================================ */

/* full-screen boot overlay (auth + first data load) */
.boot {
  position: fixed; inset: 0; z-index: 500;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-4); background: var(--bg); color: var(--text-muted);
}
.boot .spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
.boot h4 { font-size: 14px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
.boot .boot-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: var(--sp-7); max-width: 420px; text-align: center; box-shadow: var(--shadow-md);
}
.boot .boot-card h3 { font-size: 17px; font-weight: 700; margin-bottom: var(--sp-2); }
.boot .boot-card p { font-size: 13px; color: var(--text-muted); margin-bottom: var(--sp-4); }
.boot details { margin-top: var(--sp-4); text-align: left; }
.boot details summary { font-size: 12px; color: var(--text-faint); cursor: pointer; }
.boot details pre { margin-top: var(--sp-2); font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); white-space: pre-wrap; word-break: break-word; }
@keyframes spin { to { transform: rotate(360deg); } }

/* dashboard: top-affiliate rows reuse .brand-row; rank chip */
.rank-chip {
  width: 26px; height: 26px; border-radius: 7px; flex-shrink: 0;
  display: grid; place-items: center; font-family: var(--font-mono); font-weight: 600; font-size: 12px;
  background: var(--surface-3); color: var(--text-muted);
}
.rank-chip.gold { background: var(--warning-soft); color: var(--warning); }

/* scalev integration mini-grid */
.kv-grid { display: grid; grid-template-columns: 130px 1fr; gap: 6px var(--sp-3); padding: var(--sp-4) var(--sp-5); font-size: 12.5px; }
.kv-grid .k { color: var(--text-faint); }
.kv-grid .v { font-family: var(--font-mono); word-break: break-all; }
