/* Funnel tab — scoped under #funnel-view. Tokens-only (extends the styles.css
   token layer; no hardcoded hex outside this categorical-palette token block,
   no raw px outside the spacing scale). The Sankey needs a categorical palette
   to tell the acquisition sources apart — a deliberate, documented exception to
   the "one accent" rule (the user asked to match the multi-colored reference).
   The hues are muted/desaturated to stay calm; red/amber/green stay reserved
   for status (Outcome: sold=green, lost=red; Pipeline: quoted=accent). */

:root {
  /* Categorical source palette (muted). Degree-1 ribbons + legend dots. */
  --fnl-src-tivly: #5b8cff;
  --fnl-src-bold_penguin: #e08a4c;
  --fnl-src-benepath: #d06a86;
  --fnl-src-partnerships: #8a7fe0;
  --fnl-src-google_ads: #4ca6a0;
  --fnl-src-meta_ads: #5f8fd8;
  --fnl-src-chatgpt_ads: #3fa06d;
  --fnl-src-chatgpt_organic: #6fae7f;
  --fnl-src-organic_direct: #a9b0c2;
  --fnl-src-other: #6b7486;
  /* Intake + pipeline tints — color the later-degree nodes AND the ribbons that
     leave them, so hue carries through every tier (not just Degree 1). Muted;
     status red/amber/green stay reserved for the Outcome column + Quoted. */
  --fnl-live_transfer: var(--accent);
  --fnl-missed_abandoned: #c08552;
  --fnl-not_yet_contacted: #767e90;
  --fnl-quoted: var(--accent);
  --fnl-submitted: #c7a14b;
  --fnl-nothing: #5f6678;
  --fnl-ribbon-op: 0.26;
  --fnl-ribbon-op-hover: 0.52;
  --fnl-node-fill: var(--line-strong);
}

/* ---------- toolbars reuse the shared .toolbar / .segmented styles ---------- */
#funnel-view .funnel-custom { display: inline-flex; gap: var(--sp-2); align-items: center; }
#funnel-view .funnel-mode { margin-left: auto; }

/* ---------- KPI strip (per-source spend + CPL) ---------- */
#funnel-view .funnel-kpi { cursor: pointer; transition: border-color 120ms ease, box-shadow 120ms ease; }
#funnel-view .funnel-kpi:hover,
#funnel-view .funnel-kpi:focus-visible { border-color: var(--line-strong); box-shadow: var(--shadow-md); outline: none; }
#funnel-view .funnel-kpi .kpi__label { display: inline-flex; align-items: center; gap: var(--sp-2); }
#funnel-view .funnel-kpi__blank { color: var(--muted); }

.fnl-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 3px;
  background: var(--faint); flex: none;
}
/* Source dots/ribbons by key. */
.fnl-src-tivly { --fnl-c: var(--fnl-src-tivly); }
.fnl-src-bold_penguin { --fnl-c: var(--fnl-src-bold_penguin); }
.fnl-src-benepath { --fnl-c: var(--fnl-src-benepath); }
.fnl-src-partnerships { --fnl-c: var(--fnl-src-partnerships); }
.fnl-src-google_ads { --fnl-c: var(--fnl-src-google_ads); }
.fnl-src-meta_ads { --fnl-c: var(--fnl-src-meta_ads); }
.fnl-src-chatgpt_ads { --fnl-c: var(--fnl-src-chatgpt_ads); }
.fnl-src-chatgpt_organic { --fnl-c: var(--fnl-src-chatgpt_organic); }
.fnl-src-organic_direct { --fnl-c: var(--fnl-src-organic_direct); }
.fnl-src-other { --fnl-c: var(--fnl-src-other); }
/* Intake + pipeline keys feed --fnl-c too, so a ribbon leaving one of those
   nodes (Degree 2/3) inherits that node's hue. */
.funnel-ribbon.fnl-live_transfer { --fnl-c: var(--fnl-live_transfer); }
.funnel-ribbon.fnl-missed_abandoned { --fnl-c: var(--fnl-missed_abandoned); }
.funnel-ribbon.fnl-not_yet_contacted { --fnl-c: var(--fnl-not_yet_contacted); }
.funnel-ribbon.fnl-quoted { --fnl-c: var(--fnl-quoted); }
.funnel-ribbon.fnl-submitted { --fnl-c: var(--fnl-submitted); }
.funnel-ribbon.fnl-nothing { --fnl-c: var(--fnl-nothing); }
.fnl-dot.fnl-src-tivly, .fnl-dot.fnl-src-bold_penguin, .fnl-dot.fnl-src-benepath,
.fnl-dot.fnl-src-partnerships, .fnl-dot.fnl-src-google_ads, .fnl-dot.fnl-src-meta_ads,
.fnl-dot.fnl-src-chatgpt_ads, .fnl-dot.fnl-src-chatgpt_organic,
.fnl-dot.fnl-src-organic_direct, .fnl-dot.fnl-src-other { background: var(--fnl-c); }
/* Status dots for the later degrees (allocation destination + legend). */
.fnl-dot.fnl-sold, .fnl-dot.fnl-quoted { background: var(--green); }
.fnl-dot.fnl-lost { background: var(--red); }
.fnl-dot.fnl-live_transfer { background: var(--accent); }
.fnl-dot.fnl-submitted { background: var(--amber); }
.fnl-dot.fnl-missed_abandoned, .fnl-dot.fnl-not_yet_contacted,
.fnl-dot.fnl-nothing, .fnl-dot.fnl-open { background: var(--faint); }

/* ---------- Sankey card ---------- */
.funnel-sankey-wrap {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-card); padding: var(--sp-5); margin-bottom: var(--sp-5);
}
.funnel-sankey__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-4); }
.funnel-sankey__eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; }
.funnel-sankey__title { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; margin: var(--sp-1) 0 0; color: var(--fg-strong); }
.funnel-sankey__total { text-align: right; font-size: 26px; font-weight: 800; letter-spacing: -0.02em; color: var(--fg-strong); font-variant-numeric: tabular-nums; }
.funnel-sankey__total small { display: block; font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 0; }

.funnel-sankey { width: 100%; overflow: visible; }
.funnel-svg { display: block; width: 100%; height: auto; }

.funnel-node { fill: var(--fnl-node-fill); stroke: none; cursor: pointer; transition: opacity 120ms ease; }
.funnel-node:hover, .funnel-node:focus-visible { opacity: 0.85; outline: none; }
.funnel-node:focus-visible { stroke: var(--accent); stroke-width: 2; }
/* Degree-1 source nodes take their source hue; later degrees stay graphite,
   with status tints only where meaningful. */
.funnel-node.fnl-src-tivly, .funnel-node.fnl-src-bold_penguin, .funnel-node.fnl-src-benepath,
.funnel-node.fnl-src-partnerships, .funnel-node.fnl-src-google_ads, .funnel-node.fnl-src-meta_ads,
.funnel-node.fnl-src-chatgpt_ads, .funnel-node.fnl-src-chatgpt_organic,
.funnel-node.fnl-src-organic_direct, .funnel-node.fnl-src-other { fill: var(--fnl-c); }
.funnel-node.fnl-sold { fill: var(--green); }
.funnel-node.fnl-lost { fill: var(--red); }
.funnel-node.fnl-quoted { fill: var(--accent); }
.funnel-node.fnl-live_transfer { fill: var(--fnl-live_transfer); }
.funnel-node.fnl-missed_abandoned { fill: var(--fnl-missed_abandoned); }
.funnel-node.fnl-not_yet_contacted { fill: var(--fnl-not_yet_contacted); }
.funnel-node.fnl-submitted { fill: var(--fnl-submitted); }
.funnel-node.fnl-nothing { fill: var(--fnl-nothing); }

.funnel-ribbon {
  fill: var(--fnl-c, var(--line-strong)); opacity: var(--fnl-ribbon-op);
  transition: opacity 120ms ease; cursor: pointer;
}
.funnel-ribbon:hover { opacity: var(--fnl-ribbon-op-hover); }
.funnel-ribbon:focus-visible { opacity: var(--fnl-ribbon-op-hover); outline: none; stroke: var(--accent); stroke-width: 1.5; }

.funnel-node-label { pointer-events: none; }
.funnel-node-name { fill: var(--fg-strong); font-size: 12px; font-weight: 700; }
.funnel-node-val { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.funnel-node-money { fill: var(--green); font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }

.funnel-legend { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); margin-top: var(--sp-4); padding-top: var(--sp-4); border-top: 1px solid var(--hairline); }
.funnel-legend__item { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: 12px; color: var(--muted); }

.funnel-empty { padding: var(--sp-8) var(--sp-4); text-align: center; color: var(--muted); }

/* ---------- allocation breakdown ---------- */
.funnel-alloc-wrap {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-card); padding: var(--sp-5);
}
.funnel-alloc__title { font-size: 16px; font-weight: 800; letter-spacing: -0.01em; margin: 0; color: var(--fg-strong); }
.funnel-alloc__note { font-size: 12px; color: var(--muted); margin: var(--sp-1) 0 var(--sp-4); }
.funnel-alloc__block { padding: var(--sp-3) 0; border-top: 1px solid var(--hairline); }
.funnel-alloc__block:first-of-type { border-top: none; }
.funnel-alloc__head { display: flex; align-items: center; gap: var(--sp-2); font-size: 13px; }
.funnel-alloc__head b { color: var(--fg-strong); }
.funnel-alloc__total { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.funnel-alloc__chip { width: 10px; height: 10px; border-radius: 3px; background: var(--line-strong); flex: none; }

.funnel-bar { display: flex; height: 8px; border-radius: 999px; overflow: hidden; background: var(--bar-track); margin: var(--sp-2) 0 var(--sp-3); }
.funnel-bar__seg { height: 100%; }
.funnel-bar__seg--good { background: var(--green); }
.funnel-bar__seg--bad { background: var(--red); }
.funnel-bar__seg--accent { background: var(--accent); }
.funnel-bar__seg--neutral { background: var(--line-strong); }

.funnel-alloc__table { width: 100%; border-collapse: collapse; font-size: 13px; }
.funnel-alloc__table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 700; padding: var(--sp-1) var(--sp-2); }
.funnel-alloc__table td { padding: var(--sp-2); border-top: 1px solid var(--hairline); }
.funnel-alloc__row { cursor: pointer; }
.funnel-alloc__row:hover, .funnel-alloc__row:focus-visible { background: var(--surface-2); outline: none; }
.funnel-alloc__dest { display: flex; align-items: center; gap: var(--sp-2); color: var(--fg); }
.funnel-alloc__num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.funnel-alloc__strong { color: var(--fg-strong); font-weight: 700; }
.funnel-alloc__faint { color: var(--muted); }

/* ---------- drill modal ---------- */
.funnel-drill { position: fixed; inset: 0; z-index: 80; }
.funnel-drill[hidden] { display: none; }
.funnel-drill__backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45); }
.funnel-drill__panel {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(720px, 92vw); max-height: 82vh; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop); overflow: hidden;
}
.funnel-drill__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-4); border-bottom: 1px solid var(--hairline); }
.funnel-drill__head h3 { margin: 0; font-size: 15px; color: var(--fg-strong); }
.funnel-drill__actions { display: inline-flex; gap: var(--sp-2); }
.funnel-drill__scroll { overflow: auto; }
.funnel-drill__table { width: 100%; border-collapse: collapse; font-size: 13px; }
.funnel-drill__table th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: var(--sp-2) var(--sp-3); }
.funnel-drill__table td { padding: var(--sp-2) var(--sp-3); border-top: 1px solid var(--hairline); font-variant-numeric: tabular-nums; }
.funnel-drill__company { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font: inherit; text-align: left; }
.funnel-drill__company:hover { text-decoration: underline; }

/* Wide variant: the per-line coverage matrix needs more room + a horizontal
   scroll. Company name/ID stick to the left so the glyph grid stays readable. */
.funnel-drill__panel--wide { width: min(1180px, 96vw); }
.funnel-drill__legend { margin: 0 var(--sp-4) var(--sp-2); }
.funnel-drill__table--cov { white-space: nowrap; }
.funnel-drill__table--cov th.funnel-drill__cov,
.funnel-drill__table--cov td.funnel-drill__cov {
  text-align: center; padding-left: var(--sp-2); padding-right: var(--sp-2);
}
.funnel-drill__table--cov td.funnel-drill__name,
.funnel-drill__table--cov th:first-child {
  position: sticky; left: 0; z-index: 1; background: var(--surface);
}
.funnel-drill__table--cov th:first-child { background: var(--surface-2); z-index: 2; }
.funnel-drill__cov-filter { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: 12px; color: var(--muted); }
.funnel-drill__cov-filter select { font: inherit; }
.funnel-drill__empty { text-align: center; color: var(--muted); padding: var(--sp-5); }

/* Language flag — a calm dimension pill (NOT a red/amber/green status color).
   Inline ES badge next to a company; the toolbar chip is also click-to-filter. */
.funnel-flag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px;
  font-weight: 700; line-height: 1; white-space: nowrap; padding: 2px var(--sp-2);
  border-radius: 999px; border: 1px solid var(--line-strong); color: var(--muted); }
.funnel-flag--es { color: var(--fg-strong); }
.funnel-flag[hidden] { display: none; }
span.funnel-flag--es { cursor: pointer; }
span.funnel-flag--es:hover { border-color: var(--accent); }
span.funnel-flag--es.is-active { border-color: var(--accent); color: var(--accent); }

/* ---------- phone-responsive (no horizontal overflow at 390/320) ---------- */
@media (max-width: 640px) {
  .funnel-sankey-wrap, .funnel-alloc-wrap { padding: var(--sp-4); }
  .funnel-sankey__head { flex-direction: column; gap: var(--sp-2); }
  .funnel-sankey__total { text-align: left; }
  #funnel-view .funnel-mode { margin-left: 0; width: 100%; }
  .funnel-node-name { font-size: 11px; }
  .funnel-node-val, .funnel-node-money { font-size: 10px; }
}
@media (max-width: 380px) {
  .funnel-sankey-wrap, .funnel-alloc-wrap { padding: var(--sp-3); }
}
