const cxBrl=n=>n>=1e6?'R$ '+(n/1e6).toFixed(1).replace('.',',')+' mi':'R$ '+Math.round((n||0)/1e3)+' mil';
const cxPct=(a,b)=>b?(a/b*100).toFixed(1).replace('.',',')+'%':'—';
const cxScoreTone=v=>v>=80?'success':v>=60?'info':'neutral';
const cxGrid=(min,gap=20)=>({display:'grid',gridTemplateColumns:'repeat(auto-fit,minmax(min('+min+'px,100%),1fr))',gap});
const cxMono={fontFamily:'var(--font-mono)'};const cxRow=k=>({borderTop:k?'1px solid var(--border-subtle)':'none'});
function ScoreChip({v,size}){const c=VX_TONE[cxScoreTone(v)],lg=size==='lg';return <span style={{fontFamily:'var(--font-mono)',fontSize:lg?22:13,fontWeight:600,color:c,background:vxMix(c,14),border:'1px solid '+vxMix(c,38),borderRadius:lg?12:8,padding:lg?'6px 14px':'2px 8px',display:'inline-block',lineHeight:1.3}}>{v}</span>}
function StageBadge({stage}){const{Badge}=window.VRticeDesignSystem_d763eb;const s=window.VXCommercial.STG[stage]||{label:stage,tone:'neutral'};return <Badge tone={s.tone}>{s.label}</Badge>}
function Person({name,size=28}){const{Avatar}=window.VRticeDesignSystem_d763eb;return name?<span style={{display:'inline-flex',alignItems:'center',gap:8,minWidth:0}}><Avatar name={name} size={size}/><span style={{fontSize:13,color:'var(--text-strong)',whiteSpace:'nowrap',overflow:'hidden',textOverflow:'ellipsis'}}>{name}</span></span>:<span style={{fontSize:13,color:'var(--status-warning)',display:'inline-flex',alignItems:'center',gap:6}}><i className='ph ph-user-circle-dashed' style={{fontSize:18}}/>Sem responsável</span>}
const CxDash=()=> <span style={{color:'var(--text-subtle)'}}>—</span>;
function useProspects(){const R=window.VxSalesIntelligence;const [tick,setTick]=React.useState(0);React.useEffect(()=>R.subscribe(()=>setTick(x=>x+1)),[]);React.useEffect(()=>{R.load()},[]);return React.useMemo(()=>R.rows,[tick])}
// Erro de leitura da base comercial: aparece como erro, nunca como lista vazia (DAT-05).
function CxLoadError(){const{Alert}=window.VRticeDesignSystem_d763eb;useProspects();const m=window.VxSalesIntelligence.loadError;return m?<Alert tone="danger" title="Falha ao carregar dados">{m}</Alert>:null}
Object.assign(window,{cxBrl,cxPct,cxScoreTone,cxGrid,cxMono,cxRow,ScoreChip,StageBadge,Person,CxDash,useProspects,CxLoadError});