/* ============================================================
   AlgoPartner Affiliate — console reskin bridge
   Loaded AFTER console.css on every affiliate page.

   1. Brand-driven accent: maps the per-brand --brand-primary (set at
      runtime by theme.js from /api/brand/me) onto the console
      --accent / --accent-strong / --accent-soft / --accent-line tokens,
      so TRXC (purple) and ETC (cyan) each keep their own colour while
      every component stays on the console design system.
   2. Affiliate-only components (hero, quick-actions, funnel, donut,
      ref-band, team rows, sidebar user footer, mobile bottom-nav)
      re-expressed in console tokens — these have no admin equivalent.
   ============================================================ */

/* ---------- 1. Brand → accent ramp ----------------------------------
   Hue + chroma come from the brand primary; lightness is normalised into
   the console band so contrast stays consistent across brands. The L/C
   envelope matches console's own accent (dark 0.66 / 0.72, light 0.55 / 0.49). */
:root { --brand-primary: #6B5FD4; } /* default; theme.js overrides at runtime */

:root, [data-theme="dark"] {
  --accent:        oklch(from var(--brand-primary) 0.66 clamp(0.07, c, 0.16) h);
  --accent-strong: oklch(from var(--brand-primary) 0.72 clamp(0.07, c, 0.17) h);
  --accent-soft:   oklch(from var(--brand-primary) 0.66 clamp(0.07, c, 0.16) h / 0.15);
  --accent-line:   oklch(from var(--brand-primary) 0.66 clamp(0.07, c, 0.16) h / 0.42);
  --on-accent:     oklch(0.99 0 0);
}
[data-theme="light"] {
  --accent:        oklch(from var(--brand-primary) 0.55 clamp(0.07, c, 0.19) h);
  --accent-strong: oklch(from var(--brand-primary) 0.49 clamp(0.07, c, 0.20) h);
  --accent-soft:   oklch(from var(--brand-primary) 0.55 clamp(0.07, c, 0.19) h / 0.12);
  --accent-line:   oklch(from var(--brand-primary) 0.55 clamp(0.07, c, 0.19) h / 0.30);
}
/* Fallback for engines without relative-colour syntax: flat brand primary. */
@supports not (color: oklch(from #000 l c h)) {
  :root, [data-theme="dark"], [data-theme="light"] {
    --accent: var(--brand-primary);
    --accent-strong: var(--brand-primary);
    --accent-soft: color-mix(in oklch, var(--brand-primary) 15%, transparent);
    --accent-line: color-mix(in oklch, var(--brand-primary) 42%, transparent);
  }
}

/* ---------- 2a. Sidebar user footer (affiliate keeps the user in the
   sidebar foot; admin keeps it in the topbar). Console-styled. -------- */
.sb-user {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-2);
  border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--border);
}
.sb-user .av {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-weight: 700; font-size: 11px;
  color: var(--on-accent); background: linear-gradient(140deg, var(--accent-strong), var(--accent));
}
.sb-user .su-meta { min-width: 0; }
.sb-user .su-meta .nm { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user .su-meta .rf { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.collapsed .sb-user { justify-content: center; padding: var(--sp-2); }
.collapsed .sb-user .su-meta { display: none; }
.sb-logout {
  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-logout:hover { background: var(--danger-soft); color: var(--danger); }
.collapsed .sb-logout { justify-content: center; }
.collapsed .sb-logout .sb-foot-text { display: none; }

/* ---------- 2b. Mobile bottom nav ---------------------------------- */
.aff-bottom-nav { display: none; }
@media (max-width: 920px) {
  .aff-bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 80;
    height: 62px; background: color-mix(in oklch, var(--surface) 88%, transparent);
    border-top: 1px solid var(--border); backdrop-filter: blur(14px);
  }
  .aff-bottom-nav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; font-size: 9.5px; font-weight: 600; letter-spacing: .02em;
    color: var(--text-faint); padding: 6px 2px;
  }
  .aff-bottom-nav-item svg { width: 19px; height: 19px; }
  .aff-bottom-nav-item.active { color: var(--accent-strong); }
  /* keep page content clear of the bar */
  .page { padding-bottom: 88px; }
}

/* ============================================================
   OVERVIEW PAGE COMPONENTS
   ============================================================ */

/* hero — all-time commission + status tiles */
.ov-hero { position: relative; overflow: hidden; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-6) var(--sp-7); }
.ov-hero-spark { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .38; pointer-events: none; }
.ov-hero-grid { position: relative; display: grid; grid-template-columns: 1.8fr 1fr 1fr 1fr; gap: var(--sp-6); align-items: end; }
.ov-hl { font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); margin-bottom: 8px; }
.ov-hv { font-family: var(--font-mono); font-size: 34px; font-weight: 600; letter-spacing: -.02em; line-height: 1; }
.ov-hm { font-family: var(--font-mono); font-size: 22px; font-weight: 600; letter-spacing: -.01em; line-height: 1; }
.ov-hn { font-size: 12px; color: var(--text-faint); margin-top: 6px; }
.ov-hn.ok { color: var(--success); }
.ov-hn.warn { color: var(--warning); }
.ov-hero-meta { display: flex; gap: var(--sp-2) var(--sp-3); align-items: center; flex-wrap: wrap; margin-top: var(--sp-3); font-size: 12.5px; color: var(--text-muted); }
.ov-hero-meta > span { white-space: nowrap; }
.ov-hero-meta strong { color: var(--text); font-family: var(--font-mono); }

/* quick-action cards */
.qa-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-4); }
.qa-card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-5); display: flex; gap: var(--sp-4); overflow: hidden; transition: border-color var(--speed); }
.qa-card:hover { border-color: var(--border-strong); }
.qa-ic { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; background: var(--accent-soft); color: var(--accent); }
.qa-ic.green { background: var(--success-soft); color: var(--success); }
.qa-ic.amber { background: var(--warning-soft); color: var(--warning); }
.qa-h { font-size: 14px; font-weight: 700; letter-spacing: -.01em; margin-bottom: 4px; }
.qa-card p { font-size: 12.5px; color: var(--text-muted); line-height: 1.5; margin-bottom: 10px; }
.qa-cta { font-size: 12.5px; font-weight: 600; color: var(--accent); cursor: pointer; }
.qa-cta:hover { color: var(--accent-strong); }
.qa-badge { position: absolute; top: 14px; right: 16px; font-family: var(--font-mono); font-size: 9.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; padding: 3px 8px; border-radius: var(--r-full); background: var(--accent-soft); color: var(--accent); }
.qa-badge.green { background: var(--success-soft); color: var(--success); }
.qa-badge.amber { background: var(--warning-soft); color: var(--warning); }

/* funnel */
.funnel { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-3); }
.fstep { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--sp-4) var(--sp-4) calc(var(--sp-4) + 2px); }
.fstep .l { font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-faint); margin-bottom: 8px; }
.fstep .v { font-family: var(--font-mono); font-size: 26px; font-weight: 600; line-height: 1; letter-spacing: -.01em; }
.fstep .v.accent { color: var(--accent); }
.fstep .v.cy { color: var(--accent); }
.fstep .v.amber { color: var(--warning); }
.fstep .v.green { color: var(--success); }
.fstep .vu { font-size: 11px; color: var(--text-faint); margin-top: 6px; }
.fstep .conv { position: absolute; top: 50%; right: -9px; transform: translateY(-50%); z-index: 2; font-family: var(--font-mono); font-size: 10px; color: var(--text-muted); background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-full); padding: 2px 7px; white-space: nowrap; }
@media (max-width: 760px) { .fstep .conv { display: none; } }

/* chart legend + 2-col layout */
.legend { display: flex; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: 10px; font-size: 11.5px; color: var(--text-muted); font-family: var(--font-mono); }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.ov-2col { display: grid; grid-template-columns: 1.6fr 1fr; gap: var(--sp-4); }

/* commission-status donut */
.donut-wrap { display: flex; gap: var(--sp-5); align-items: center; flex-wrap: wrap; padding: var(--sp-5); }
.donut-legend { flex: 1; min-width: 150px; display: flex; flex-direction: column; gap: 10px; }
.donut-legend .row { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 12.5px; }
.donut-legend .lab { display: flex; align-items: center; gap: 8px; color: var(--text-muted); white-space: nowrap; }
.donut-legend .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.donut-legend .v { font-family: var(--font-mono); font-size: 12.5px; color: var(--text); white-space: nowrap; }

/* top-performance team rows */
.tt-row { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-5); border-bottom: 1px solid var(--border-soft); }
.tt-row:last-child { border-bottom: none; }
.tt-rank { 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); }
.tt-rank.gold { background: var(--warning-soft); color: var(--warning); }
.tt-av { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex-shrink: 0; }
.tt-meta { flex: 1; min-width: 0; }
.tt-nm { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tt-rf { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); }
.tt-val { text-align: right; font-family: var(--font-mono); font-size: 13px; font-weight: 600; color: var(--success); white-space: nowrap; }
.tt-val .n { display: block; color: var(--text-faint); font-size: 10.5px; font-weight: 400; }

/* referral band */
.ref-band { display: flex; gap: var(--sp-5); align-items: center; flex-wrap: wrap; background: var(--accent-soft); border: 1px solid var(--accent-line); border-radius: var(--r-lg); padding: var(--sp-5) var(--sp-6); }
.ref-band .lbl { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); }
.ref-band .code { font-family: var(--font-mono); font-size: 26px; font-weight: 600; letter-spacing: .12em; color: var(--accent-strong); margin-top: 4px; }
.ref-band .urls { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 280px; }
.ref-band .url { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); background: var(--bg); border: 1px solid var(--border); padding: 8px 12px; border-radius: var(--r-sm); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.ref-band .url span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ref-band .url .copy { color: var(--text-faint); font-family: inherit; font-size: 11px; font-weight: 600; flex-shrink: 0; }
.ref-band .url .copy:hover { color: var(--accent-strong); }

/* shared empty / loading cell used by inline page scripts */
.empty { text-align: center; padding: var(--sp-8) var(--sp-5); color: var(--text-muted); font-size: 13px; }

/* ============================================================
   LEGACY COMPATIBILITY LAYER
   Maps operator-twin variable names + a few component classes still
   emitted by preserved inline page scripts onto console tokens, so the
   re-skinned pages render correctly WITHOUT rewriting the inline JS.
   (operator-twin.css is NOT loaded on converted pages.)
   ============================================================ */
:root {
  --bg2: var(--bg-grad);
  --card: var(--surface);
  --card2: var(--surface-2);
  --card3: var(--surface-3);
  --border2: var(--border-strong);
  --cyan: var(--accent);
  --cyan2: var(--accent-strong);
  --cyan3: var(--accent);
  --emerald: var(--success);
  --amber: var(--warning);
  --gold: var(--warning);
  --green: var(--success);
  --red: var(--danger);
  --white: var(--text);
  --muted: var(--text-faint);
  --muted2: var(--text-muted);
}

/* legacy badge colours (format.js is dual-class: "badge b-green green") */
.badge.b-cyan   { color: var(--accent);  background: var(--accent-soft); }
.badge.b-green  { color: var(--success); background: var(--success-soft); }
.badge.b-amber, .badge.b-gold { color: var(--warning); background: var(--warning-soft); }
.badge.b-red    { color: var(--danger);  background: var(--danger-soft); }
.badge.b-violet { color: var(--info);    background: var(--info-soft); }
.badge.b-muted  { color: var(--text-muted); background: var(--neutral-soft); }

/* inline-script alerts (settings/recruit/withdraw feedback) */
.alert { border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4); margin-bottom: var(--sp-4); font-size: 13px; line-height: 1.5; border: 1px solid transparent; }
.alert-error   { background: var(--danger-soft);  border-color: color-mix(in oklch, var(--danger) 28%, transparent);  color: var(--danger); }
.alert-success { background: var(--success-soft); border-color: color-mix(in oklch, var(--success) 28%, transparent); color: var(--success); }
.alert-info    { background: var(--accent-soft);  border-color: var(--accent-line); color: var(--accent-strong); }
.alert-warn    { background: var(--warning-soft); border-color: color-mix(in oklch, var(--warning) 28%, transparent); color: var(--warning); }

/* legacy form group + hero stat classes (operator-twin) re-expressed on console */
.form-group { margin-bottom: var(--sp-4); }
.form-group:last-child { margin-bottom: 0; }
.form-group > label, label.form-label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.hint { font-size: 11.5px; color: var(--text-faint); margin-top: 5px; }
.hl { font-family: var(--font-mono); font-size: 10px; letter-spacing: .06em; color: var(--text-faint); text-transform: uppercase; margin-bottom: 8px; }
.hv { font-family: var(--font-mono); font-size: 40px; font-weight: 600; letter-spacing: -.02em; line-height: 1; color: var(--text); }
.hm { font-family: var(--font-mono); font-size: 26px; font-weight: 600; letter-spacing: -.01em; line-height: 1; color: var(--text); }
.hn { font-size: 11.5px; color: var(--text-faint); margin-top: 6px; }
.hn.ok { color: var(--success); }
.hn.warn { color: var(--warning); }

/* inline-script table blocks that emit .table-wrap > table (settings banks,
   teams modal, withdraw history). Console-styled without needing .tbl. */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table-wrap thead th { text-align: left; padding: 10px var(--sp-4); background: var(--surface-3); font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table-wrap tbody td { padding: 11px var(--sp-4); border-bottom: 1px solid var(--border-soft); }
.table-wrap tbody tr:last-child td { border-bottom: none; }
.table-wrap tbody tr:hover { background: var(--surface-hover); }
.mono { font-family: var(--font-mono); }

/* legacy spinner used by some inline scripts */
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* legacy layout grids (operator-twin) re-expressed on console spacing */
.row-1-1 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }
.row-2-1 { display: grid; grid-template-columns: 1.7fr 1fr; gap: var(--sp-4); }
.row-3   { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-4); }
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-4); }
.kpi-row.kpi-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1180px) {
  .row-2-1, .row-3, .kpi-row, .kpi-row.kpi-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .row-1-1, .row-2-1, .row-3, .kpi-row, .kpi-row.kpi-3 { grid-template-columns: 1fr; }
}

/* compact affiliate KPI tile (.akpi > .l/.v/.n) — console-styled, lighter than
   the dashboard .kpi. Used on teams/withdraw and the teams-detail modal. */
.akpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-4) var(--sp-5); }
.akpi .l { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); margin-bottom: 7px; }
.akpi .v { font-family: var(--font-mono); font-size: 26px; font-weight: 600; letter-spacing: -.01em; line-height: 1.1; }
.akpi .v.cy { color: var(--accent); }
.akpi .v.green { color: var(--success); }
.akpi .v.gold { color: var(--warning); }
.akpi .v.red { color: var(--danger); }
.akpi .n { font-size: 11.5px; color: var(--text-faint); margin-top: 7px; }

.btn-sm { /* console already defines */ }
/* legacy extra-small button used by inline templates (recruit/promo/withdraw) */
.btn-xs { height: 26px; padding: 0 9px; font-size: 11px; border-radius: var(--r-xs); }
.btn-green { background: var(--success); color: oklch(0.18 0.03 158); border-color: var(--success); }
.btn-green:hover { filter: brightness(1.06); }

/* static modal-overlay pattern (teams/promo/withdraw toggle .open) — console-styled */
.modal-overlay { position: fixed; inset: 0; background: var(--overlay); display: none; align-items: center; justify-content: center; z-index: 100; backdrop-filter: blur(2px); padding: var(--sp-6); }
.modal-overlay.open { display: flex; animation: fade .16s var(--ease); }
.modal-overlay .modal { background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-xl); box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; padding: var(--sp-5) var(--sp-6) var(--sp-6); animation: modalIn .2s var(--ease); }
.modal-overlay .modal.wide { max-width: 760px; }
.modal-overlay .modal h3 { font-size: 18px; font-weight: 700; letter-spacing: -.015em; }
.modal-overlay .modal p { font-size: 12.5px; color: var(--text-muted); }
.modal-footer { display: flex; gap: var(--sp-2); justify-content: flex-end; margin-top: var(--sp-5); }

/* legacy downline rows (operator-twin .dl-row) used by teams + recruit */
.dl-row { display: grid; grid-template-columns: auto 1fr auto auto auto; gap: var(--sp-4); align-items: center; padding: var(--sp-3) var(--sp-5); border-bottom: 1px solid var(--border-soft); font-size: 13px; }
.dl-row:last-child { border-bottom: none; }
.dl-av { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.dl-mt { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); }
.dl-stat { font-family: var(--font-mono); font-size: 12px; }
.dl-stat .l { color: var(--text-faint); font-size: 10px; display: block; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 2px; }
.dl-sub { margin-left: 44px; padding-left: 16px; border-left: 1px dashed var(--border); margin-top: 4px; padding-bottom: 6px; }

/* responsive */
@media (max-width: 1180px) {
  .qa-grid { grid-template-columns: 1fr; }
  .ov-2col { grid-template-columns: 1fr; }
  .ov-hero-grid { grid-template-columns: 1fr 1fr; gap: var(--sp-5); }
}
@media (max-width: 760px) {
  .funnel { grid-template-columns: 1fr 1fr; }
  .ov-hero-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   AUTH / PRE-LOGIN PAGES (no app shell) — centered console card
   ============================================================ */
.hidden { display: none !important; }
.auth-wrap { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: var(--sp-6); }
.auth-card { width: 100%; max-width: 420px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-5); }
.auth-logo { width: 46px; height: 46px; border-radius: 12px; background: linear-gradient(140deg, var(--accent-strong), var(--accent)); display: grid; place-items: center; box-shadow: 0 3px 16px var(--accent-soft); }
.auth-title { font-size: 18px; font-weight: 700; letter-spacing: -.01em; text-align: center; }
.auth-sub { font-size: 13px; color: var(--text-muted); text-align: center; margin-top: 3px; }
.auth-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-6); }
.auth-divider { display: flex; align-items: center; gap: var(--sp-3); margin: var(--sp-4) 0; color: var(--text-faint); font-size: 11px; letter-spacing: .04em; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.auth-foot { text-align: center; font-size: 13px; color: var(--text-muted); margin-top: var(--sp-5); }
.auth-foot a, .auth-link { color: var(--accent-strong); font-weight: 600; }
.auth-foot a:hover, .auth-link:hover { color: var(--accent); }
.auth-panel .field label { color: var(--text-muted); }
