/* coeff-viz.css — co/efficient dashboard component library styles.
 *
 * Injected into every agent-authored custom-dashboard page (see viz_assets.go).
 * It reads the managed --t-* palette that the host injects per dashboard (see
 * models.CustomDashboardPaletteRoles), and defines a legacy --primary-*/--secondary-*
 * scale on top of it so the charts ported from the YMCA viz library theme
 * themselves with no per-chart edits. Setting the dashboard palette recolors
 * every chart for free, the same way it recolors hand-built markup.
 *
 * Everything is namespaced cv-* so it never collides with a page's own CSS.
 */

:root {
  /* The two anchor colors, mapped from the house roles: the brand blue
     (--t-accent-2) is the default data color; the orange (--t-accent) is the
     highlight/contrast color. */
  --cv-primary:   var(--t-accent-2, #245ea4);
  --cv-secondary: var(--t-accent,   #e27124);

  /* Numbered primary scale, derived from --cv-primary. */
  --primary-900: color-mix(in srgb, var(--cv-primary) 65%, #000);
  --primary-800: color-mix(in srgb, var(--cv-primary) 82%, #000);
  --primary-700: var(--cv-primary); /* base */
  --primary-600: color-mix(in srgb, var(--cv-primary) 85%, #fff);
  --primary-500: color-mix(in srgb, var(--cv-primary) 68%, #fff);
  --primary-400: color-mix(in srgb, var(--cv-primary) 56%, #fff);
  --primary-300: color-mix(in srgb, var(--cv-primary) 42%, #fff);
  --primary-200: color-mix(in srgb, var(--cv-primary) 30%, #fff);
  --primary-100: color-mix(in srgb, var(--cv-primary) 20%, #fff);
  --primary-50:  color-mix(in srgb, var(--cv-primary) 12%, #fff);

  /* Numbered secondary scale, derived from --cv-secondary. */
  --secondary-900: color-mix(in srgb, var(--cv-secondary) 70%, #000);
  --secondary-700: var(--cv-secondary); /* base */
  --secondary-500: color-mix(in srgb, var(--cv-secondary) 70%, #fff);
  --secondary-300: color-mix(in srgb, var(--cv-secondary) 45%, #fff);
}

/* ---- Shared tooltip (every chart) ---- */
.cv-tooltip {
  position: absolute;
  background: var(--t-surface, #fff);
  color: var(--t-text, #111827);
  padding: 12px 16px;
  border: 1px solid var(--t-border, #dbe3ec);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .18);
  max-width: 300px;
  z-index: 1000;
}
.cv-tooltip.visible { opacity: 1; }
.cv-tooltip-label { font-weight: 700; margin-bottom: 4px; }
.cv-tooltip-desc  { font-weight: 500; color: var(--t-text-2, #374151); }

/* ---- Shared legend ---- */
.cv-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; justify-content: center; }
.cv-legend-item { display: flex; align-items: center; gap: 6px; }
.cv-legend-swatch { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.cv-legend-label { font-size: 12px; color: var(--t-text-2, #475569); }

/* ---- Donut ---- */
.cv-donut { display: flex; justify-content: center; }
.cv-donut svg text { font-family: inherit; }
.cv-donut-arc { stroke: var(--t-surface, #fff); stroke-width: 3; cursor: pointer; }
.cv-donut-slice-val   { font-weight: 800; font-size: 18px; fill: var(--t-surface, #fff); text-shadow: 1px 1px 3px rgba(0, 0, 0, .4); }
.cv-donut-slice-lab   { font-weight: 600; font-size: 11px; fill: var(--t-surface, #fff); text-shadow: 1px 1px 2px rgba(0, 0, 0, .4); }
.cv-donut-center      { font-weight: 800; font-size: 40px; fill: var(--t-accent-2); }
.cv-donut-center-lab  { font-weight: 600; font-size: 14px; fill: var(--t-muted); }
.cv-badge             { font-weight: 600; font-size: 14px; }
@media (max-width: 600px) {
  .cv-donut-center    { font-size: 32px; }
  .cv-donut-slice-val { font-size: 14px; }
}

/* ---- Bars (horizontal) ---- */
.cv-bars { display: flex; flex-direction: column; gap: 10px; }
.cv-bar-row { display: grid; grid-template-columns: minmax(125px, 30%) 1fr; gap: 8px; align-items: center; }
.cv-bar-row.has-rank { grid-template-columns: 22px minmax(110px, 30%) 1fr; }
.cv-bar-rank { font: 600 .75rem/1 ui-monospace, monospace; color: var(--t-muted, #64748b); text-align: right; }
.cv-bar-row.muted { opacity: .6; }
.cv-bar-row.muted .cv-bar-label { font-style: italic; }
.cv-bar-row.client .cv-bar-label { font-weight: 700; }
.cv-bar-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--t-text, #0a1628); font-size: .9rem; }
.cv-bar-track { width: 100%; display: flex; align-items: center; gap: 6px; }
.cv-bar-fill {
  height: var(--cv-bar-h, 26px); border-radius: 6px; display: flex; align-items: center;
  transition: width .4s ease; box-shadow: 0 3px 8px rgba(15, 23, 42, .12);
}
.cv-bar-value { font-weight: 700; font-size: 13px; color: var(--t-text, #000); white-space: nowrap; flex-shrink: 0; }
.cv-bar-group { margin-bottom: 12px; }
.cv-bar-group .cv-bar-row { margin-bottom: 2px; }

/* ---- Funnel ---- */
.cv-funnel-item { margin: 0 auto 6px; transition: width .4s ease; }
.cv-funnel-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-radius: 8px; color: #fff; cursor: pointer;
  box-shadow: 0 3px 8px rgba(15, 23, 42, .12);
}
.cv-funnel-label { font-weight: 600; font-size: 13px; }
.cv-funnel-value { font-weight: 800; font-size: 14px; }

/* ---- Gauge ---- */
.cv-gauge { display: flex; flex-direction: column; align-items: center; }
.cv-gauge-bg { fill: var(--t-border, #e5e7eb); }
.cv-gauge-text { font-weight: 800; font-size: 36px; fill: var(--t-text, #0a1628); }

/* ---- Heatmap ---- */
.cv-heatmap { border-collapse: collapse; width: 100%; font-size: 13px; }
.cv-heatmap th, .cv-heatmap td { padding: 7px 10px; text-align: center; border: 1px solid var(--t-border, #dbe3ec); }
.cv-heatmap thead th { background: var(--t-surface-alt, #f8fafc); color: var(--t-text-2, #475569); font-weight: 600; }
.cv-heatmap tbody th { text-align: left; color: var(--t-text, #0a1628); font-weight: 500; }
.cv-heatmap-group th { background: var(--t-surface-alt, #f8fafc); text-align: left; font-weight: 700; color: var(--t-text, #0a1628); }

/* ---- Bubbles ---- */
.cv-bubbles { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; justify-content: center; }
.cv-bubble {
  border-radius: 50%; display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; color: #fff; cursor: pointer;
}
.cv-bubble-value { font-weight: 800; line-height: 1; }
.cv-bubble-label { font-weight: 600; margin-top: 2px; opacity: .95; }

/* ---- Treemap ---- */
.cv-treemap-cell { cursor: pointer; }
.cv-treemap-pct { fill: #fff; font-weight: 800; text-anchor: middle; text-shadow: 1px 1px 3px rgba(0,0,0,.35); }
.cv-treemap-title { fill: #fff; font-weight: 600; font-size: 13px; text-anchor: middle; }
.cv-treemap-title-small { fill: #fff; font-weight: 600; font-size: 11px; text-anchor: middle; }
.cv-treemap-title-tiny  { fill: #fff; font-weight: 600; font-size: 9px;  text-anchor: middle; }

/* ---- Quadrant / scatter ---- */
.cv-quadrant-label { font-size: 12px; font-weight: 600; fill: var(--t-muted, #64748b); }
.cv-axis-label { font-size: 13px; font-weight: 700; fill: var(--t-accent, #e27124); }
.cv-axis-sub { font-size: 10px; fill: var(--t-muted, #6b7280); }
.cv-point-label { font-size: 11px; font-weight: 600; fill: var(--t-text, #0a1628); text-anchor: middle; }
.cv-axis-line { stroke: var(--t-text, #000); stroke-width: 1; }
.cv-divider { stroke: var(--t-border, #d0d4da); stroke-width: 2; }
.cv-chain { stroke: var(--t-text, #000); stroke-width: 1.25; }
.cv-arrowhead { fill: var(--t-text, #000); }
.cv-pt { stroke: var(--t-surface, #fff); stroke-width: 2; cursor: pointer; }

/* ---- Pillar (grouped vertical bars) ---- */
.cv-pillar text { font-family: inherit; }
.cv-pillar .cv-axis-x text { fill: var(--t-text-2, #4b5563); font-size: 12px; font-weight: 600; }
.cv-pillar .cv-axis-y text { fill: var(--t-muted, #6b7280); font-size: 11px; }
.cv-legend-svg { font-size: 11px; font-weight: 600; fill: var(--t-text-2, #4b5563); }

/* ---- Maps (choropleth, dots, region circles) ---- */
.cv-geo { width: 100%; }
.cv-geo-svg { display: block; width: 100%; height: auto; }
.cv-geo-unit { stroke: var(--t-surface, #fff); stroke-width: 0.6; cursor: default; transition: opacity .12s; }
.cv-geo-unit:hover { opacity: 0.82; }
.cv-geo-outline { fill: none; stroke: var(--t-text-2, #475569); stroke-width: 1; stroke-linejoin: round; pointer-events: none; opacity: 0.7; }
.cv-geo-label { font-size: 10px; font-weight: 600; fill: var(--t-text, #0a1628); text-anchor: middle; dominant-baseline: middle; pointer-events: none; paint-order: stroke; stroke: var(--t-surface, #fff); stroke-width: 2.5px; stroke-linejoin: round; }
.cv-geo-dot { fill-opacity: 0.78; stroke: var(--t-surface, #fff); stroke-width: 1.2; cursor: pointer; }
.cv-geo-dot:hover { fill-opacity: 1; }
.cv-geo-dot-label { font-size: 11px; font-weight: 600; fill: var(--t-text, #0a1628); pointer-events: none; paint-order: stroke; stroke: var(--t-surface, #fff); stroke-width: 2.5px; }
.cv-geo-legend { margin-bottom: 12px; }
.cv-geo-ramp { display: inline-block; width: 140px; height: 12px; border-radius: 3px; border: 1px solid var(--t-border, #dbe3ec); }
.cv-geo-ramp-lab, .cv-geo-ramp-mid { font-size: 12px; color: var(--t-text-2, #475569); font-variant-numeric: tabular-nums; }
.cv-geo-ramp-mid { margin: 0 -2px; }
.cv-geo-swatch-empty { background: var(--t-surface-alt, #f1f5f9); border: 1px solid var(--t-border, #dbe3ec); }
.cv-geo-swatch-hatch { background: repeating-linear-gradient(45deg, var(--t-surface-alt, #f1f5f9) 0 3px, var(--t-muted, #94a3b8) 3px 4px); border: 1px solid var(--t-border, #dbe3ec); }
.cv-map-state { stroke: var(--t-surface, #fff); stroke-width: 0.8; opacity: 0.9; }
.cv-map-region { fill-opacity: 0.78; stroke: var(--t-surface, #fff); stroke-width: 1.5; cursor: pointer; }
.cv-map-label { font-size: 11px; font-weight: 700; fill: #fff; pointer-events: none; }

/* ---- KPI stat cards ---- */
.cv-stats { display: flex; flex-wrap: wrap; gap: 16px; }
.cv-stat-card {
  background: var(--t-surface, #fff); border: 1px solid var(--t-border, #dbe3ec);
  border-radius: 10px; padding: 18px 22px; min-width: 150px; flex: 1;
}
.cv-stat-number { font-weight: 800; font-size: 2rem; color: var(--t-text, #0a1628); line-height: 1; font-variant-numeric: tabular-nums; }
.cv-stat-number-small { font-weight: 700; font-size: 1.2rem; color: var(--t-text, #0a1628); line-height: 1.2; }
.cv-stat-label { font-size: .85rem; color: var(--t-text-2, #475569); margin-top: 6px; }
.cv-stat-extra { font-size: .75rem; color: var(--t-muted, #64748b); }
.cv-stat-trend { display: inline-flex; align-items: center; gap: 4px; margin-top: 8px; font-size: .78rem; font-weight: 600; padding: 2px 8px; border-radius: 6px; }
.cv-stat-trend-up   { color: var(--t-positive, #065f46); background: color-mix(in srgb, var(--t-positive) 15%, var(--t-surface)); }
.cv-stat-trend-down { color: var(--t-negative, #991b1b); background: color-mix(in srgb, var(--t-negative) 15%, var(--t-surface)); }
.cv-stat-trend-flat { color: var(--t-muted, #6b7280); background: var(--t-surface-alt, #f3f4f6); }

/* ---- Table ---- */
.cv-table-wrap { overflow-x: auto; }
.cv-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.cv-table th, .cv-table td { padding: 8px 12px; border-bottom: 1px solid var(--t-border, #dbe3ec); text-align: left; }
.cv-table thead th { background: var(--t-surface-alt, #f8fafc); color: var(--t-text-2, #475569); font-weight: 600; }
.cv-table td { color: var(--t-text, #0a1628); font-variant-numeric: tabular-nums; }
.cv-net-pos { color: var(--t-positive, #15803d); font-weight: 700; }
.cv-net-neg { color: var(--t-negative, #dc2626); font-weight: 700; }

/* ---- Stacked intensity bar + net ---- */
.cv-stk-row { display: grid; grid-template-columns: minmax(110px, 180px) 1fr 56px; align-items: center; gap: 12px; margin-bottom: 8px; }
.cv-stk-lab { color: var(--t-text, #0a1628); font-size: .85rem; }
.cv-stk { display: flex; height: 22px; border-radius: 4px; overflow: hidden; background: var(--t-surface-alt, #f8fafc); }
.cv-stk span { display: flex; align-items: center; justify-content: center; font-size: .7rem; font-weight: 700; color: var(--t-surface, #fff); white-space: nowrap; overflow: hidden; }
.cv-stk-net { font-weight: 700; text-align: right; }
.cv-stk-net.pos { color: var(--t-positive, #15803d); }
.cv-stk-net.neg { color: var(--t-negative, #dc2626); }

/* ---- Diverging bar (D left, R right) ---- */
.cv-div-row { display: grid; grid-template-columns: minmax(110px, 180px) 1fr 64px; align-items: center; gap: 12px; margin-bottom: 6px; }
.cv-div-lab { color: var(--t-text, #0a1628); font-size: .85rem; }
.cv-div-track { position: relative; height: 16px; border-radius: 3px; background: linear-gradient(to right, var(--party-d-soft, #dbe5f7) 50%, var(--party-r-soft, #fde2e2) 50%); }
.cv-div-track::after { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1.5px; background: var(--t-text, #0a1628); }
.cv-div-fill { position: absolute; top: 0; bottom: 0; }
.cv-div-val { font-weight: 700; text-align: right; }

/* ---- Electorate bar ---- */
.cv-elec { display: flex; height: 34px; border-radius: 5px; overflow: hidden; gap: 2px; }
.cv-elec-seg { position: relative; display: flex; background: color-mix(in srgb, var(--c) 22%, var(--t-surface, #fff)); }
.cv-elec-take { background: var(--c); }
.cv-elec-und  { background: repeating-linear-gradient(135deg, var(--c) 0 3px, transparent 3px 7px); }

/* ---- Line chart (over time) ---- */
.cv-lc { width: 100%; height: auto; overflow: visible; }
.cv-lc-line { fill: none; stroke-width: 2.5; stroke-linejoin: round; }
.cv-lc-pt { cursor: pointer; }
.cv-lc-grid  { stroke: var(--t-border, #dbe3ec); stroke-width: 1; }
.cv-lc-ytick { font-size: 10px; text-anchor: end; fill: var(--t-muted, #64748b); }
.cv-lc-xtick { font-size: 10px; text-anchor: middle; fill: var(--t-muted, #64748b); }
.cv-lc-lab   { font-size: 10px; font-weight: 700; text-anchor: middle; paint-order: stroke; stroke: var(--t-surface, #fff); stroke-width: 4px; }

/* ---- Wave-over-wave rows ---- */
.cv-wave-row { display: grid; grid-template-columns: minmax(120px, 200px) 1fr auto 48px; align-items: center; gap: 10px; margin-bottom: 8px; }
.cv-wave-lab { color: var(--t-text, #0a1628); font-size: .85rem; }
.cv-wave-bars { display: grid; gap: 3px; }
.cv-wave-bars span { height: 8px; border-radius: 4px; }
.cv-wave-was { background: color-mix(in srgb, var(--t-muted, #64748b) 40%, transparent); }
.cv-wave-vals i { font-style: normal; font-size: .78rem; color: var(--t-muted, #64748b); }
.cv-wave-d { font-weight: 700; text-align: right; }
.cv-wave-d.up { color: var(--t-positive, #15803d); }
.cv-wave-d.dn { color: var(--t-negative, #dc2626); }
.cv-wave-d.flat { color: var(--t-muted, #64748b); }

/* ---- Slope (before -> after) ---- */
.cv-slope-row { display: grid; grid-template-columns: minmax(110px, 180px) 44px 1fr 44px 70px; align-items: center; gap: 10px; margin-bottom: 6px; }
.cv-slope { width: 100%; height: 36px; }
.cv-slope line { stroke: var(--t-accent, #e27124); stroke-width: 2; vector-effect: non-scaling-stroke; }
.cv-slope-a { color: var(--t-muted, #64748b); text-align: right; }
.cv-slope-b { font-weight: 700; color: var(--t-accent, #e27124); }
.cv-slope-d { font-size: .8rem; font-weight: 700; color: var(--t-text, #0a1628); }
