/* ============================================================
   Brand & Store — Affiliate · Creator Performance  ·  route #bs-affiliate (FE-036)
   Page-scoped styles (.bs-aff-*) + the BsDrillTable component styles (the page
   ships the real CSS for the shared drill table). Tokens with fallbacks.
   Plan palette: Open → --color-action-hover / Target → --color-action-active
   (canonical action tokens, theme-invariant). Accent purple/teal + the rank-fill
   gradient are page-local --vars here pending a global mint in FE-031.
   ============================================================ */

.bs-aff-page {
  display: flex; flex-direction: column; gap: var(--space-5, 20px); min-width: 0;
  /* Plan palette — theme-invariant action tokens (leave as-is). */
  --bs-aff-plan-open: var(--color-action-hover, #3B82F6);
  --bs-aff-plan-target: var(--color-action-active, #1D4ED8);
  /* Data-viz accents — DARK is the DEFAULT theme (:root), so the base values
     here must read on the dark surfaces (--bg-inset #080A0F / --bg-surface
     #151820); the [data-theme="light"] block below restores the deeper hues.
     Never a light-only private hex — it silently breaks dark theme
     (page-conventions §1). */
  --bs-aff-rank-fill-from: #5B7FD0;
  --bs-aff-rank-fill-to: #7E9BE0;
  --bs-aff-accent-purple: #C4B5FD;   /* violet-300 — reads on #080A0F + #151820 */
  --bs-aff-accent-teal: #5EEAD4;     /* teal-300  — reads on both dark bgs */
}
[data-theme="light"] .bs-aff-page {
  --bs-aff-rank-fill-from: #6B89C9;
  --bs-aff-rank-fill-to: #8DA4D6;
  --bs-aff-accent-purple: #5B21B6;   /* deeper violet for the light surface */
  --bs-aff-accent-teal: #0F766E;
}
/* Flex children grow to wide content (drill tables) → page overflow; min-width:0
   lets them shrink so the table's own overflow-x scroll engages instead. */
.bs-aff-page > * { min-width: 0; }

/* ---- KPI overview --------------------------------------------------- */
.bs-aff-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-4, 16px);
}
.bs-aff-kpi-grid--more {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: var(--space-4, 16px);
}
@media (max-width: 900px) {
  .bs-aff-kpi-grid, .bs-aff-kpi-grid--more { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .bs-aff-kpi-grid, .bs-aff-kpi-grid--more { grid-template-columns: minmax(0, 1fr); }
}

.bs-aff-more-btn {
  appearance: none;
  background: transparent;
  border: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.25));
  border-radius: var(--radius-2, 8px);
  color: var(--text-secondary, #64748b);
  font: inherit; font-size: 0.8125rem;
  padding: 4px 12px; cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.bs-aff-more-btn:hover { color: var(--color-action, #2563eb); border-color: var(--color-action, #2563eb); }

.bs-aff-approx-note {
  display: flex; align-items: flex-start; gap: var(--space-2, 8px);
  margin: var(--space-4, 16px) 0 0; padding-top: var(--space-3, 12px);
  border-top: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.18));
  color: var(--text-tertiary, #94a3b8); font-size: 0.75rem; line-height: 1.45;
}
.bs-aff-approx-note svg { flex: 0 0 auto; margin-top: 2px; opacity: 0.8; }

/* ---- error / empty state ------------------------------------------- */
.bs-aff-state { padding: var(--space-6, 24px); color: var(--text-tertiary, #94a3b8); text-align: center; }
.bs-aff-state--error { color: var(--color-danger, #dc2626); }
.bs-aff-state .btn { margin-top: var(--space-3, 12px); }

/* ---- footnotes ----------------------------------------------------- */
.bs-aff-foot {
  margin: var(--space-3, 12px) 0 0;
  color: var(--text-tertiary, #94a3b8); font-size: 0.72rem; line-height: 1.4;
}

/* ---- §1 Creator Performance: ranking (left) + drill table (right) --- */
.bs-aff-cperf-grid { display: grid; grid-template-columns: minmax(220px, 2fr) 8fr; gap: var(--space-5, 20px); min-width: 0; }
.bs-aff-cperf-grid > * { min-width: 0; }
@media (max-width: 1024px) { .bs-aff-cperf-grid { grid-template-columns: minmax(0, 1fr); } }

.bs-aff-rank__title { font-size: 0.8125rem; font-weight: 700; color: var(--text-secondary, #475569); margin-bottom: var(--space-3, 12px); }
.bs-aff-rank__hint { font-weight: 500; color: var(--text-tertiary, #94a3b8); font-size: 0.6875rem; margin-left: 6px; }
/* Ranking-mode toggle (Top Creators / IM PIC) — narrow card → own centered line
   below the title (page-conventions §2). Pill styling from global .pnl-compare-toggle. */
.bs-aff-rank-toggle { display: flex; justify-content: center; margin: 2px 0 var(--space-3, 12px); }
.bs-aff-rank-row {
  display: grid; grid-template-columns: 96px 1fr auto auto; align-items: center;
  gap: 8px; height: 26px;
}
.bs-aff-rank-name { font-size: 11px; color: var(--text-secondary, #475569); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bs-aff-rank-track { position: relative; height: 14px; border-radius: 3px; background: var(--bg-inset, rgba(148,163,184,0.16)); overflow: hidden; }
.bs-aff-rank-fill { position: absolute; left: 0; top: 0; height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--bs-aff-rank-fill-from, #6B89C9), var(--bs-aff-rank-fill-to, #8DA4D6)); }
.bs-aff-rank-val { font-size: 11px; font-variant-numeric: tabular-nums; color: var(--text-primary, #1a1a1a); white-space: nowrap; }
.bs-aff-rank-cnt { font-size: 10px; font-variant-numeric: tabular-nums; color: var(--text-tertiary, #94a3b8); white-space: nowrap; min-width: 28px; text-align: right; }

/* ---- §3 Campaign Contribution: donut (left) + grouped bar (right) --- */
.bs-aff-contrib-grid { display: grid; grid-template-columns: minmax(240px, 2fr) 8fr; gap: var(--space-5, 20px); min-width: 0; align-items: center; }
.bs-aff-contrib-grid > * { min-width: 0; }
@media (max-width: 1024px) { .bs-aff-contrib-grid { grid-template-columns: minmax(0, 1fr); } }

.bs-aff-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 16px; margin-bottom: var(--space-3, 12px); }
.bs-aff-legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary, #475569); }
.bs-aff-legend-dot { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }
.bs-aff-donut { display: block; width: 100%; max-width: 300px; height: auto; margin: 0 auto; }
.bs-aff-donut-c1 { font-size: 11px; font-weight: 700; fill: var(--text-secondary, #475569); }
.bs-aff-donut-c2 { font-size: 10px; fill: var(--text-tertiary, #94a3b8); }
/* On-slice % labels: white fill + fixed dark outline (paint-order:stroke) so the
   text reads on the theme-invariant blue slice in BOTH themes — copies the
   canonical SoR-donut idiom (bs-overall-sor-donut.js). Fixed rgba stroke (not a
   theme token) keeps the outline dark in dark mode. Scoped to .bs-aff-donut-pill
   only — the center NMV/split labels (.bs-aff-donut-c1/c2) keep their muted fills. */
.bs-aff-donut-pill text {
  font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
  fill: #fff; stroke: rgba(15, 18, 25, 0.45); stroke-width: 2px; paint-order: stroke; stroke-linejoin: round;
}
/* Donut slice fills — the CSS `fill` property resolves var() (the SVG :fill
   attribute would not), keeping the plan palette token-driven + theme-correct. */
.bs-aff-donut-slice--target { fill: var(--bs-aff-plan-target, #1D4ED8); }
.bs-aff-donut-slice--open   { fill: var(--bs-aff-plan-open, #3B82F6); }

/* Locked Content-Type affordance — canonical [data-tooltip] dark pill replacing
   the native title= (mirrors bs-media.css / bs-customer-service.css). */
.bs-aff-locked-filter[data-tooltip] { position: relative; }
.bs-aff-locked-filter[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute; left: 50%; bottom: calc(100% + 6px); transform: translateX(-50%);
  white-space: nowrap; background: var(--text-primary, #0F172A); color: var(--bg-surface, #fff);
  font-size: 11px; font-weight: 600; padding: 4px 8px; border-radius: var(--radius-sm, 4px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.18); pointer-events: none; z-index: 40;
}
.bs-aff-subhead { font-size: 0.8125rem; font-weight: 600; color: var(--text-secondary, #475569); margin-bottom: var(--space-2, 8px); text-align: center; }

/* ---- §4 Campaign Trendline: pivot table --------------------------- */
/* Export now uses the global .pnl-export-menu / .table-export-btn dropdown (S8,
   CSV + XLSX) wrapped in the page-unique .bs-aff-export-menu (outside-click
   scope); the former plain .bs-aff-export-csv button rule was retired. */
/* Self-contained scroll (2026-05-31): own both axes + cap height so the per-cell
   sticky header pins (was overflow-x only). Frozen hier column (sticky-left) kept. */
.bs-aff-pivot-scroll { max-height: calc(100vh - 240px); overflow: auto; -webkit-overflow-scrolling: touch; min-width: 0; border: 1px solid var(--border-default); border-radius: var(--radius-md, 10px); }
.bs-aff-pivot { width: 100%; border-collapse: collapse; font-size: 12px; }
.bs-aff-pivot thead th {
  position: sticky; top: 0; z-index: 2; background: var(--bg-inset, #eaebee);
  border-bottom: 2px solid var(--border-default, #e5e7eb);
  padding: 8px 10px; font-size: var(--font-xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-secondary, #5f6775); text-align: center; white-space: nowrap;
}
.bs-aff-pivot thead th.bs-aff-pivot-hier { text-align: left; left: 0; z-index: 3; min-width: 200px; background: var(--bg-inset, #eaebee); }
.bs-aff-pivot thead th.bs-aff-pivot-total { border-left: 2px solid var(--border-strong, #d1d5db); }
.bs-aff-pivot tbody td {
  padding: 6px 10px; text-align: right; white-space: nowrap;
  font-variant-numeric: tabular-nums; font-family: var(--font-mono); font-size: 12px;
  border-bottom: 1px solid var(--border-subtle, #f0f0ee);
}
.bs-aff-pivot tbody td.bs-aff-pivot-hier {
  position: sticky; left: 0; z-index: 1; text-align: left; background: var(--bg-surface, #fff);
  font-family: var(--font-body, system-ui, sans-serif); padding-left: var(--space-6, 24px);
}
.bs-aff-pivot tbody td.bs-aff-pivot-total { border-left: 2px solid var(--border-strong, #d1d5db); background: var(--bg-inset, #fafaf9); font-weight: 700; }
.bs-aff-pivot-grouphdr td {
  background: var(--bg-inset, #f4f5f7); font-family: var(--font-body, system-ui, sans-serif);
  font-weight: 700; text-align: left; padding: 8px 10px; position: sticky; left: 0;
}
.bs-aff-gh-target td:first-child { border-left: 3px solid var(--bs-aff-plan-target, #1D4ED8); }
.bs-aff-gh-open   td:first-child { border-left: 3px solid var(--bs-aff-plan-open, #3B82F6); }
.bs-aff-gh-all    td:first-child { border-left: 3px solid var(--text-secondary, #475569); }
.bs-aff-pivot-row--grand td { background: var(--color-action-ghost, rgba(37,99,235,0.06)); font-weight: 700; }

/* ============================================================
   BsDrillTable component styles (.bs-aff-drill-*) + accent columns.
   Sticky header + first-col mirror the matrix-table idiom.
   ============================================================ */
.bs-aff-drill-wrap { position: relative; min-width: 0; }
.bs-aff-drill-scroll { max-height: calc(100vh - 240px); overflow: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border-default); border-radius: var(--radius-md, 10px); }  /* self-contained scroll → sticky header pins (2026-05-31); rounded bordered container = portfolio standard */

/* Drill toolbar: buttons on the RIGHT; export dropdown stays right of buttons.
   Level badge + separator hidden (condensed layout per Tinh feedback).
   True 3-button consolidation (Drill Down / Drill Up / Expand → one combo) needs
   controller (shared BsDrillTable). */
.bs-aff-drill-toolbar { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 0 0 8px; flex-wrap: wrap; }
.bs-aff-drill-toolbar__left { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* In-table search (opt-in :searchable) — sits at the left of the drill toolbar.
   Theme-adaptive app tokens so it reads in both themes (page-conventions §1). */
.bs-aff-drill-search-wrap { position: relative; display: inline-flex; align-items: center; }
.bs-aff-drill-search-ico { position: absolute; left: 8px; color: var(--text-tertiary, #94a3b8); pointer-events: none; }
.bs-aff-drill-search {
  appearance: none; height: 28px; padding: 0 10px 0 27px;
  border: 1px solid var(--border-subtle, rgba(148, 163, 184, 0.25)); border-radius: 6px;
  background: var(--bg-surface, #fff); color: var(--text-primary, #1a1a1a);
  font: inherit; font-size: 0.78rem; min-width: 180px; max-width: 260px;
}
.bs-aff-drill-search::placeholder { color: var(--text-tertiary, #94a3b8); }
.bs-aff-drill-search:focus { outline: none; border-color: var(--color-action, #2563eb); }

/* Hide Level badge and | separator — reduces visual noise until controller decides final 3 */
.bs-aff-drill-toolbar .bs-aff-drill-level-badge,
.bs-aff-drill-toolbar .bs-aff-drill-sep { display: none; }
.bs-aff-drill-btn {
  appearance: none; background: var(--bg-surface, #fff);
  border: 1px solid var(--border-subtle, rgba(148,163,184,0.25)); border-radius: 6px;
  color: var(--text-secondary, #64748b); font: inherit; font-size: 0.75rem;
  padding: 3px 9px; cursor: pointer; transition: color 0.12s, border-color 0.12s;
}
.bs-aff-drill-btn:hover { color: var(--color-action, #2563eb); border-color: var(--color-action, #2563eb); }
.bs-aff-drill-sep { color: var(--border-strong, #d1d5db); }
.bs-aff-drill-level-badge {
  font-size: 0.6875rem; font-variant-numeric: tabular-nums;
  background: var(--bg-inset, rgba(148,163,184,0.16)); color: var(--text-secondary, #64748b);
  border-radius: 9999px; padding: 2px 10px;
}
.bs-aff-drill-export-menu { position: relative; display: inline-block; }

.bs-aff-drill-table { width: 100%; border-collapse: collapse; font-size: 12px; color: var(--text-primary, #1a1a1a); }
.bs-aff-drill-table thead th {
  position: sticky; top: 0; z-index: 2; background: var(--bg-inset, #eaebee);
  border-bottom: 2px solid var(--border-default, #e5e7eb);
  padding: 8px 10px; font-size: var(--font-xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-secondary, #5f6775); white-space: nowrap; text-align: center;
}
.bs-aff-drill-table thead th.bs-aff-drill-hier-th {
  text-align: left; left: 0; z-index: 3; background: var(--bg-inset, #eaebee); min-width: 200px;
}
.bs-aff-drill-table tbody tr { border-bottom: 1px solid var(--border-subtle, #f0f0ee); transition: background 0.12s; }
.bs-aff-drill-table tbody tr:hover { background: var(--bg-hover, #f8f8f6); }
.bs-aff-drill-val-td {
  padding: 6px 10px; text-align: right; white-space: nowrap;
  font-variant-numeric: tabular-nums; font-family: var(--font-mono); font-size: 12px;
}
.bs-aff-drill-hier-td {
  position: sticky; left: 0; z-index: 1; text-align: left; background: var(--bg-surface, #fff);
  padding: 6px 10px; min-width: 200px; max-width: 320px;
  font-family: var(--font-body, system-ui, sans-serif);
}
.bs-aff-drill-node-label { display: flex; align-items: center; gap: 6px; line-height: 1.3; }
.bs-aff-xbtn {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 16px; height: 16px; border: 1px solid var(--border-strong, #d1d5db); border-radius: 3px;
  background: transparent; color: var(--color-action, #2563eb); font-size: 10px; font-weight: 700;
  line-height: 1; cursor: pointer; user-select: none; transition: background 0.1s;
}
.bs-aff-xbtn:hover { background: var(--color-action-ghost, rgba(37,99,235,0.08)); }
.bs-aff-drill-leaf-indent { display: inline-block; width: 16px; flex-shrink: 0; }
.bs-aff-drill-row-text { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.bs-aff-drill-depth-0 .bs-aff-drill-row-text { font-weight: 700; }
.bs-aff-drill-depth-1 .bs-aff-drill-row-text { font-weight: 600; }
.bs-aff-drill-depth-2 .bs-aff-drill-row-text { font-weight: 400; color: var(--text-secondary, #4a4a4a); }
.bs-aff-drill-table tr.bs-aff-drill-depth-0 td { background: var(--bg-inset); }
.bs-aff-drill-table tr.bs-aff-drill-depth-0:hover td { background: var(--bg-hover, #f4f4f2); }

.bs-aff-drill-loading-cell { padding: 6px 10px; color: var(--text-tertiary, #94a3b8); font-size: 11px; font-style: italic; }
.bs-aff-drill-empty { padding: 20px; text-align: center; color: var(--text-tertiary, #6b6b6b); font-size: 13px; }
.bs-aff-drill-total td, .bs-aff-drill-total .bs-aff-drill-val-td, .bs-aff-drill-total .bs-aff-drill-hier-td {
  background: var(--bg-active, #e4e5e9); font-weight: 700; border-top: 2px solid var(--border-strong, #d1d5db);
}
.bs-aff-drill-approx-note { margin: var(--space-3, 12px) 0 0; color: var(--text-tertiary, #94a3b8); font-size: 0.72rem; line-height: 1.4; }

/* accent columns (spec §C4): purple = cancel/AOV, teal = live/video */
.bs-aff-col-purple { border-left: 1px solid color-mix(in srgb, var(--bs-aff-accent-purple) 45%, transparent); }
.bs-aff-drill-table tbody td.bs-aff-col-purple { color: var(--bs-aff-accent-purple, #5B21B6); }
.bs-aff-col-teal { border-left: 1px solid color-mix(in srgb, var(--bs-aff-accent-teal) 45%, transparent); }
.bs-aff-drill-table tbody td.bs-aff-col-teal { color: var(--bs-aff-accent-teal, #0F766E); }

/* ── Affiliate · Livestream — bespoke page (KPI strip + charts + pending states) ── */
.bs-aff-page .bs-aff-kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: var(--space-4,16px); margin-top: var(--space-3,12px); }
.bs-aff-page .bs-aff-kpi-grid + .bs-aff-kpi-grid { margin-top: var(--space-3,12px); }
.bs-aff-page .bs-aff-kpi-grid--ls2 { margin-top: var(--space-3,12px); }
.bs-aff-page .bs-aff-kpi-card { display:flex; flex-direction:column; gap:4px; padding: var(--space-4,16px); background: var(--bg-surface); border:1px solid var(--border-subtle); border-radius: var(--radius-md,10px); min-width:0; }
.bs-aff-page .bs-aff-kpi-label { font-size:11px; font-weight:700; color: var(--text-tertiary); text-transform:uppercase; letter-spacing:0.08em; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.bs-aff-page .bs-aff-kpi-value { font-size:20px; font-weight:700; font-family: var(--font-mono,'Geist Mono',monospace); font-variant-numeric: tabular-nums; color: var(--text-primary); text-align: right; } /* feedback 2026-06-09 #1 — right-align numerics */
.bs-aff-page .bs-aff-chart-card { margin-top: var(--space-4,16px); }
.bs-aff-page .bs-aff-pending { display:flex; align-items:center; justify-content:center; min-height:150px; padding: var(--space-6,24px); border:1px dashed var(--border-default); border-radius: var(--radius-md,10px); color: var(--text-tertiary); font-size:13px; text-align:center; background: color-mix(in srgb, var(--bg-inset) 40%, transparent); }
.bs-aff-page .bs-aff-ls-foot { font-size:11px; color: var(--text-tertiary); margin-top:6px; }
@media (max-width: 900px){ .bs-aff-page .bs-aff-kpi-grid { grid-template-columns: repeat(2,minmax(0,1fr)); } }

/* ── Affiliate content-type segment toggle (merged Overview/Live/Video/Other) ── */
.bs-aff-page .bs-aff-ct-bar { display:flex; align-items:center; gap: var(--space-3,12px); flex-wrap:wrap; margin: var(--space-4,16px) 0 var(--space-2,8px); }
.bs-aff-page .bs-aff-ct-btn { display:inline-flex; align-items:center; gap:6px; }
.bs-aff-page .bs-aff-ct-ico { display:inline-flex; align-items:center; }
.bs-aff-page .bs-aff-ct-ico svg { display:block; }
/* Per-type colour indicator on the icon (matches the affiliate accent tokens). */
.bs-aff-page .bs-aff-ct-btn--live  .bs-aff-ct-ico { color: var(--bs-aff-accent-teal); }
.bs-aff-page .bs-aff-ct-btn--video .bs-aff-ct-ico { color: var(--bs-aff-accent-purple); }
/* Active pill: icon follows the active text colour so it never clashes with the fill. */
.bs-aff-page .bs-aff-ct-btn.pnl-compare-btn--active .bs-aff-ct-ico { color: currentColor; }
.bs-aff-page .bs-aff-ct-note { font-size: var(--font-xs,11px); color: var(--text-tertiary); }
