// mnm-components.jsx — Data + UI building blocks
const { useState, useRef, useEffect, useCallback } = React;

/* ─── DATA ─────────────────────────────────────────────────────────────────── */

const PERIOD_DATA = {
  'Diciembre 2024': {
    kpis: [
      { id:'utilidad', label:'Utilidad Neta', value:'$4,200', status:'green', change:'+12%', changeSuffix:'vs nov.', tooltip:'Lo que te queda después de restar todos los costos e impuestos a tus ingresos totales del período.' },
      { id:'margen', label:'Margen Bruto', value:'38.5%', status:'yellow', change:'−4 pts', changeSuffix:'vs nov.', tooltip:'Qué porcentaje de cada peso vendido te queda después de restar los costos directos de producción.' },
      { id:'flujo', label:'Flujo de Caja', value:'$2,800', status:'green', change:'+8%', changeSuffix:'vs nov.', tooltip:'El dinero real que entró y salió de tu negocio este período. Diferente a la utilidad contable.' },
      { id:'equilibrio', label:'Pto. de Equilibrio', value:'$18,500', status:'green', change:'día 14', changeSuffix:'alcanzado', tooltip:'Las ventas mínimas para cubrir todos tus costos fijos y variables. Si vendes más, estás en utilidad.' },
      { id:'ebitda', label:'EBITDA', value:'$5,100', status:'green', change:'14.2%', changeSuffix:'margen', tooltip:'Utilidad antes de intereses, impuestos y depreciación. Mide la rentabilidad operativa pura del negocio.' },
    ],
    hallazgos: [
      { id:1, severity:'critico', title:'Margen bruto cayó 4 puntos vs. noviembre', detail:'De 42.5% a 38.5% — variación de −9.4%, supera el umbral del 15%.', category:'Costos variables / Insumos', context:'Los costos de insumos aumentaron $1,200 sin un ajuste correspondiente en los precios de venta. El proveedor principal subió precios en diciembre sin previo aviso.' },
      { id:2, severity:'advertencia', title:'Flujo de caja 33% menor a la utilidad neta', detail:'Posible acumulación de cuentas por cobrar no registradas.', category:'Liquidez', context:'Brecha de $1,400 entre utilidad neta y flujo real. Se detectan al menos 3 facturas de catering sin cobrar del período actual.' },
      { id:3, severity:'info', title:'Punto de equilibrio alcanzado el día 14', detail:'Mejor que noviembre (día 18) y el benchmark de la industria (día 16).', category:'Rendimiento', context:'Tendencia positiva sostenida: Oct. día 17 → Nov. día 18 → Dic. día 14. El ritmo de ventas mejora consistentemente.' },
    ],
  },
  'Noviembre 2024': {
    kpis: [
      { id:'utilidad', label:'Utilidad Neta', value:'$3,750', status:'yellow', change:'+3%', changeSuffix:'vs oct.', tooltip:'Lo que te queda después de restar todos los costos e impuestos.' },
      { id:'margen', label:'Margen Bruto', value:'42.5%', status:'green', change:'+1 pt', changeSuffix:'vs oct.', tooltip:'Qué porcentaje de cada peso vendido te queda después de restar costos directos.' },
      { id:'flujo', label:'Flujo de Caja', value:'$2,600', status:'yellow', change:'−2%', changeSuffix:'vs oct.', tooltip:'El dinero real que entró y salió de tu negocio.' },
      { id:'equilibrio', label:'Pto. de Equilibrio', value:'$18,500', status:'yellow', change:'día 18', changeSuffix:'alcanzado', tooltip:'Las ventas mínimas para cubrir todos tus costos.' },
      { id:'ebitda', label:'EBITDA', value:'$4,800', status:'green', change:'13.1%', changeSuffix:'margen', tooltip:'Utilidad antes de intereses, impuestos y depreciación.' },
    ],
    hallazgos: [
      { id:1, severity:'advertencia', title:'Flujo de caja por debajo de la utilidad neta', detail:'Brecha de $1,150 — cuentas por cobrar acumulándose.', category:'Liquidez', context:'Tres clientes corporativos con pagos pendientes mayores a 30 días.' },
      { id:2, severity:'info', title:'Margen bruto mejoró 1 punto vs. octubre', detail:'De 41.5% a 42.5% — tendencia positiva en control de costos.', category:'Eficiencia', context:'Reducción de desperdicio de insumos en cocina implementada exitosamente.' },
    ],
  },
  'Octubre 2024': {
    kpis: [
      { id:'utilidad', label:'Utilidad Neta', value:'$3,640', status:'yellow', change:'−5%', changeSuffix:'vs sep.', tooltip:'Lo que te queda después de restar todos los costos e impuestos.' },
      { id:'margen', label:'Margen Bruto', value:'41.5%', status:'green', change:'0 pts', changeSuffix:'vs sep.', tooltip:'Qué porcentaje de cada peso vendido te queda después de restar costos directos.' },
      { id:'flujo', label:'Flujo de Caja', value:'$2,650', status:'yellow', change:'−8%', changeSuffix:'vs sep.', tooltip:'El dinero real que entró y salió de tu negocio.' },
      { id:'equilibrio', label:'Pto. de Equilibrio', value:'$18,500', status:'red', change:'día 17', changeSuffix:'alcanzado', tooltip:'Las ventas mínimas para cubrir todos tus costos.' },
      { id:'ebitda', label:'EBITDA', value:'$4,600', status:'yellow', change:'12.8%', changeSuffix:'margen', tooltip:'Utilidad antes de intereses, impuestos y depreciación.' },
    ],
    hallazgos: [
      { id:1, severity:'critico', title:'Utilidad neta cayó 5% vs. septiembre', detail:'Descenso de $192 — patrón de erosión de margen en curso.', category:'Rentabilidad', context:'Aumento de costos de servicios públicos en temporada combinado con baja de ventas en primera semana.' },
      { id:2, severity:'advertencia', title:'Punto de equilibrio alcanzado tarde (día 17)', detail:'Por encima del benchmark de la industria (día 16).', category:'Rendimiento', context:'Flujo de clientes irregular en las primeras dos semanas del mes.' },
    ],
  },
};

const BASE_ACCIONES = [
  { id:1, p:1, accion:'Revisar precio de insumos con proveedor principal', hallazgoId:1, status:'pendiente',    fecha:'31 Ene 2025', notas:'' },
  { id:2, p:2, accion:'Implementar control de inventario semanal',          hallazgoId:1, status:'en-progreso', fecha:'15 Feb 2025', notas:'Hablé con el equipo esta semana.' },
  { id:3, p:3, accion:'Registrar y gestionar cuentas por cobrar pendientes',hallazgoId:2, status:'pendiente',   fecha:'10 Ene 2025', notas:'' },
  { id:4, p:4, accion:'Activar cobro automático para clientes corporativos', hallazgoId:2, status:'pendiente',   fecha:'28 Feb 2025', notas:'' },
  { id:5, p:5, accion:'Mantener ritmo: punto de equilibrio antes del día 14',hallazgoId:3, status:'completado',  fecha:'14 Ene 2025', notas:'Meta lograda ✓' },
];

const CHAT_QUESTIONS = [
  { ai:'¡Hola! Vamos a registrar los datos de **Diciembre 2024**. Empecemos: ¿cuánto fue tu facturación total del mes?', label:'Facturación total', suggestions:['$34,400','$30,000 aprox.','Tengo varios canales'] },
  { ai:'Anotado. Ahora los **costos de insumos** — materias primas y todo lo que gastaste directamente para producir lo que vendiste.', label:'Costos de insumos', suggestions:['$13,440','$12,000 aprox.','No lo sé exacto'] },
  { ai:'Perfecto. ¿Cuánto fueron los **costos fijos** del mes? — renta, servicios (luz, agua, gas), nómina del equipo.', label:'Costos fijos', suggestions:['$11,100','$11,500 aprox.','Te desgloso por categoría'] },
  { ai:'Casi listo. ¿Hay **otros gastos** importantes? — comisiones, deudas, pagos extraordinarios.', label:'Otros gastos', suggestions:['Comisiones delivery $840','No, eso es todo','Tengo deudas también'] },
];

const VOICE_EXTRACTED = {
  ingresos: [{l:'Ventas mostrador',v:'$28,400'},{l:'Delivery / domicilios',v:'$4,200'},{l:'Catering eventos',v:'$1,800'}],
  costos_v: [{l:'Insumos y materia prima',v:'$12,600'},{l:'Comisiones delivery',v:'$840'}],
  costos_f: [{l:'Alquiler local',v:'$3,200'},{l:'Servicios (luz, agua, gas)',v:'$1,100'},{l:'Nómina',v:'$6,800'}],
  missing:  ['Deudas / obligaciones mensuales'],
};

const APP_DATA = {
  business: 'Cafetería El Roble',
  periods: Object.keys(PERIOD_DATA),
  getPeriod: p => PERIOD_DATA[p] || PERIOD_DATA['Diciembre 2024'],
};

/* ─── ICONS ─────────────────────────────────────────────────────────────────── */

const Ic = {
  Dashboard: ()=><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><rect x="1.5" y="1.5" width="5.5" height="5.5" rx="1.5" stroke="currentColor" strokeWidth="1.4"/><rect x="9" y="1.5" width="5.5" height="5.5" rx="1.5" stroke="currentColor" strokeWidth="1.4"/><rect x="1.5" y="9" width="5.5" height="5.5" rx="1.5" stroke="currentColor" strokeWidth="1.4"/><rect x="9" y="9" width="5.5" height="5.5" rx="1.5" stroke="currentColor" strokeWidth="1.4"/></svg>,
  Upload:    ()=><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M8 2.5L11.5 6H9.5V11H6.5V6H4.5L8 2.5Z" stroke="currentColor" strokeWidth="1.4" strokeLinejoin="round"/><path d="M3 13H13" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round"/></svg>,
  Alert:     ()=><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M8 2.5L14 13H2L8 2.5Z" stroke="currentColor" strokeWidth="1.4" strokeLinejoin="round"/><path d="M8 7V9.5" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round"/><circle cx="8" cy="11.5" r="0.7" fill="currentColor"/></svg>,
  List:      ()=><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M2 4.5H14M2 8H11M2 11.5H8" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round"/></svg>,
  Calendar:  ()=><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><rect x="2" y="3" width="12" height="11" rx="2" stroke="currentColor" strokeWidth="1.4"/><path d="M5 1.5V4M11 1.5V4" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round"/><path d="M2 6.5H14" stroke="currentColor" strokeWidth="1.3"/></svg>,
  Info:      ()=><svg width="13" height="13" viewBox="0 0 13 13" fill="none"><circle cx="6.5" cy="6.5" r="5.5" stroke="currentColor" strokeWidth="1.2"/><path d="M6.5 6V9.5" stroke="currentColor" strokeWidth="1.2" strokeLinecap="round"/><circle cx="6.5" cy="4" r="0.65" fill="currentColor"/></svg>,
  Chevron:   ()=><svg width="13" height="13" viewBox="0 0 13 13" fill="none"><path d="M3 5L6.5 8.5L10 5" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round"/></svg>,
  ChevronR:  ()=><svg width="13" height="13" viewBox="0 0 13 13" fill="none"><path d="M5 3L8.5 6.5L5 10" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round"/></svg>,
  ChevronL:  ()=><svg width="13" height="13" viewBox="0 0 13 13" fill="none"><path d="M8 3L4.5 6.5L8 10" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round"/></svg>,
  Mic:       ()=><svg width="22" height="22" viewBox="0 0 22 22" fill="none"><rect x="7" y="2" width="8" height="11" rx="4" stroke="currentColor" strokeWidth="1.5"/><path d="M4 11.5C4 15.09 7.13 18 11 18C14.87 18 18 15.09 18 11.5" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round"/><path d="M11 18V21" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round"/></svg>,
  Chat:      ()=><svg width="22" height="22" viewBox="0 0 22 22" fill="none"><path d="M19 11.5C19 15.09 15.87 18 12 18H10.5L7 20V18H5C3.34 18 2 16.66 2 15V8C2 6.34 3.34 5 5 5H17C18.66 5 20 6.34 20 8V11.5H19Z" stroke="currentColor" strokeWidth="1.5" strokeLinejoin="round"/></svg>,
  Form:      ()=><svg width="22" height="22" viewBox="0 0 22 22" fill="none"><rect x="3" y="3" width="16" height="16" rx="3" stroke="currentColor" strokeWidth="1.5"/><path d="M7 8.5H15M7 11.5H12.5M7 14.5H10" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round"/></svg>,
  Check:     ()=><svg width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M2.5 7L5.5 10L11.5 4" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round"/></svg>,
  Star:      ()=><svg width="11" height="11" viewBox="0 0 11 11" fill="currentColor"><path d="M5.5 1L6.7 4H10L7.4 5.9L8.4 9L5.5 7L2.6 9L3.6 5.9L1 4H4.3L5.5 1Z"/></svg>,
  Export:    ()=><svg width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M7 2V8.5M4.5 6L7 8.5L9.5 6" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round"/><path d="M2 10.5V12.5H12V10.5" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round"/></svg>,
  Refresh:   ()=><svg width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M12 7A5 5 0 012 7M2 4.5V7H4.5" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round"/></svg>,
  Warning:   ()=><svg width="14" height="14" viewBox="0 0 14 14" fill="none"><path d="M7 2L13 12H1L7 2Z" stroke="currentColor" strokeWidth="1.3" strokeLinejoin="round"/><path d="M7 6V8.5" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round"/><circle cx="7" cy="10" r="0.6" fill="currentColor"/></svg>,
  X:         ()=><svg width="13" height="13" viewBox="0 0 13 13" fill="none"><path d="M2.5 2.5L10.5 10.5M10.5 2.5L2.5 10.5" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round"/></svg>,
};

/* ─── SPARKLINE ─────────────────────────────────────────────────────────────── */
function Sparkline({ status, width, height }) {
  width  = width  || 80;
  height = height || 20;
  var datasets = {
    green:  [38,42,40,48,52,50,58,62],
    yellow: [62,60,55,58,52,54,50,50],
    red:    [68,64,60,55,58,50,46,42],
    info:   [46,50,47,52,50,54,52,56],
  };
  var pts = datasets[status] || datasets.info;
  var mn = Math.min.apply(null,pts);
  var mx = Math.max.apply(null,pts);
  var range = mx - mn || 1;
  var sw = width / (pts.length - 1);
  var points = pts.map(function(v,i){return (i*sw)+','+(height-((v-mn)/range)*(height-2)+1);}).join(' ');
  var colors = {green:'#16A34A',yellow:'#D97706',red:'#DC2626',info:'#9C8D7C'};
  var color = colors[status] || colors.info;
  return (
    <svg width={width} height={height} viewBox={'0 0 '+width+' '+height} style={{display:'block'}}>
      <polyline points={points} fill="none" stroke={color} strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" opacity="0.75"/>
    </svg>
  );
}

/* ─── TOOLTIP ────────────────────────────────────────────────────────────────── */

function Tooltip({ text, children }) {
  const [show, setShow] = useState(false);
  return (
    <span style={{position:'relative',display:'inline-flex',alignItems:'center'}}
      onMouseEnter={()=>setShow(true)} onMouseLeave={()=>setShow(false)}>
      {children}
      {show && (
        <span style={{
          position:'absolute',bottom:'calc(100% + 8px)',left:'50%',transform:'translateX(-50%)',
          width:'210px',background:'var(--surf-3)',border:'1px solid var(--border-2)',
          borderRadius:'8px',padding:'8px 10px',fontSize:'12px',color:'var(--t2)',
          lineHeight:1.55,zIndex:300,pointerEvents:'none',whiteSpace:'normal',textAlign:'left',
          boxShadow:'0 8px 28px rgba(0,0,0,0.3)',
        }}>{text}</span>
      )}
    </span>
  );
}

/* ─── KPI CARD ───────────────────────────────────────────────────────────────── */

const SC = {
  green:  ['var(--s-green)',  'var(--s-green-bg)'],
  yellow: ['var(--s-yellow)', 'var(--s-yellow-bg)'],
  red:    ['var(--s-red)',    'var(--s-red-bg)'],
};
const getSC = s => SC[s] || ['var(--t3)', 'var(--surf-3)'];

function KPICard({ kpi }) {
  var DOT_COLOR = {green:'#16A34A',yellow:'#D97706',red:'#DC2626',info:'#797776'};
  var dotColor = DOT_COLOR[kpi.status] || DOT_COLOR.info;
  var isUp = kpi.change && kpi.change[0] === '+';
  var isDown = kpi.change && (kpi.change[0] === '-' || kpi.change[0] === '\u2212');
  var changeColor = isUp ? '#16A34A' : isDown ? '#DC2626' : '#D97706';
  var [hov,setHov] = useState(false);
  return (
    <div className="kpi-card" onMouseEnter={function(){setHov(true);}} onMouseLeave={function(){setHov(false);}}
      style={{
        background:'rgba(255,255,255,0.70)',
        backdropFilter:'var(--glass-blur)',
        WebkitBackdropFilter:'var(--glass-blur)',
        border:'0.5px solid var(--glass-border)',
        boxShadow: hov
          ? '0 0 0 0.5px rgba(255,255,255,0.65) inset,0 12px 36px rgba(0,0,0,0.10)'
          : 'var(--glass-shadow)',
        borderRadius:'var(--radius-card)',
        padding:'18px 20px 14px',
        flex:'1 1 160px',
        transform: hov ? 'translateY(-3px)' : 'none',
        transition:'transform 0.18s,box-shadow 0.18s',
        cursor:'default',
        display:'flex',flexDirection:'column',gap:'8px',
      }}>
      <div style={{display:'flex',justifyContent:'space-between',alignItems:'center'}}>
        <span style={{fontSize:'10px',fontWeight:500,letterSpacing:'0.08em',textTransform:'uppercase',color:'var(--t3)',fontFamily:'var(--font)'}}>{kpi.label}</span>
        <Tooltip text={kpi.tooltip}>
          <span style={{width:'8px',height:'8px',borderRadius:'50%',background:dotColor,display:'inline-block',cursor:'help',flexShrink:0,boxShadow:'0 0 6px '+dotColor+'66'}}/>
        </Tooltip>
      </div>
      <div style={{fontSize:'28px',fontWeight:500,color:'var(--orange,#F97316)',letterSpacing:'-0.025em',lineHeight:1,fontFamily:'var(--font-mono)',fontVariantNumeric:'tabular-nums'}}>
        {kpi.value}
      </div>
      <div style={{display:'flex',alignItems:'flex-end',justifyContent:'space-between'}}>
        <div style={{fontSize:'11px',fontWeight:500,color:changeColor}}>
          {kpi.change} <span style={{color:'var(--t3)',fontWeight:400,fontSize:'10.5px'}}>{kpi.changeSuffix}</span>
        </div>
        <Sparkline status={kpi.status} width={72} height={18}/>
      </div>
    </div>
  );
}

/* ─── FINDING CARD ───────────────────────────────────────────────────────────── */

const SEV = {
  critico:     {label:'CRÍTICO',    c:'var(--s-red)',   bg:'var(--s-red-bg)',   border:'var(--s-red)'},
  advertencia: {label:'ADVERTENCIA',c:'var(--s-yellow)',bg:'var(--s-yellow-bg)',border:'var(--s-yellow)'},
  info:        {label:'INFORMATIVO',c:'var(--t2)',       bg:'var(--surf-3)',     border:'var(--border-2)'},
};

function FindingCard({ h, expanded, onToggle, onPlan }) {
  const s = SEV[h.severity];
  return (
    <div style={{background:'var(--glass-bg)',backdropFilter:'var(--glass-blur)',WebkitBackdropFilter:'var(--glass-blur)',border:'0.5px solid var(--glass-border)',boxShadow:'var(--glass-shadow)',borderLeft:'3px solid '+s.border,borderRadius:'var(--radius-card)',overflow:'hidden',transition:'box-shadow 0.15s'}}>
      <div onClick={onToggle} style={{padding:'14px 18px',display:'flex',alignItems:'flex-start',gap:'12px',cursor:'pointer'}}>
        <div style={{flex:1}}>
          <div style={{display:'flex',alignItems:'center',gap:'8px',marginBottom:'6px',flexWrap:'wrap'}}>
            <span style={{fontSize:'10px',fontWeight:700,letterSpacing:'0.06em',padding:'2px 7px',borderRadius:'3px',background:s.bg,color:s.c}}>{s.label}</span>
            <span style={{fontSize:'11px',color:'var(--t3)'}}>{h.category}</span>
          </div>
          <p style={{fontSize:'13.5px',fontWeight:600,color:'var(--t1)',margin:'0 0 4px'}}>{h.title}</p>
          <p style={{fontSize:'12px',color:'var(--t2)',margin:0,lineHeight:1.5}}>{h.detail}</p>
        </div>
        <span style={{color:'var(--t3)',marginTop:'3px',transition:'transform 0.2s',transform:expanded?'rotate(180deg)':'',lineHeight:0,flexShrink:0}}><Ic.Chevron/></span>
      </div>
      {expanded && (
        <div style={{padding:'0 18px 14px',borderTop:'1px solid var(--border)'}}>
          <p style={{fontSize:'12.5px',color:'var(--t2)',lineHeight:1.65,margin:'12px 0 12px'}}>{h.context}</p>
          {onPlan && <button onClick={onPlan} style={{background:'var(--accent-bg)',border:'1px solid var(--accent-border)',color:'var(--accent)',borderRadius:'6px',padding:'6px 14px',fontSize:'12px',fontWeight:600,cursor:'pointer'}}>Ver en Plan de Acción →</button>}
        </div>
      )}
    </div>
  );
}

/* ─── ACTION ROW ─────────────────────────────────────────────────────────────── */

const SCYCLE = {pendiente:'en-progreso','en-progreso':'completado',completado:'pendiente'};
const SCFG = {
  pendiente:    {label:'Pendiente',   c:'var(--t3)',       bg:'var(--surf-2)'},
  'en-progreso':{label:'En progreso', c:'var(--s-yellow)', bg:'var(--s-yellow-bg)'},
  completado:   {label:'Completado',  c:'var(--s-green)',  bg:'var(--s-green-bg)'},
};

function ActionRow({ action, hallazgos, onChange }) {
  const [showNote, setShowNote] = useState(false);
  const [note, setNote] = useState(action.notas);
  const sc = SCFG[action.status];
  const h = hallazgos.find(x=>x.id===action.hallazgoId);
  const sevDot = h ? (h.severity==='critico'?'var(--s-red)':h.severity==='advertencia'?'var(--s-yellow)':'var(--s-green)') : 'var(--t3)';
  return (
    <div style={{background:'var(--glass-bg)',backdropFilter:'var(--glass-blur)',WebkitBackdropFilter:'var(--glass-blur)',border:'0.5px solid var(--glass-border)',boxShadow:'var(--glass-shadow)',borderRadius:'var(--radius-card)',padding:'14px 16px',opacity:action.status==='completado'?0.6:1,transition:'opacity 0.2s',animation:'fadeInUp 0.2s ease both'}}>
      <div style={{display:'flex',gap:'12px',alignItems:'flex-start'}}>
        <div style={{width:'24px',height:'24px',borderRadius:'50%',flexShrink:0,background:'var(--surf-3)',display:'flex',alignItems:'center',justifyContent:'center',fontSize:'11px',fontWeight:700,color:'var(--t3)',marginTop:'1px'}}>{action.p}</div>
        <div style={{flex:1,minWidth:0}}>
          <p style={{fontSize:'13px',fontWeight:500,color:'var(--t1)',margin:'0 0 6px',textDecoration:action.status==='completado'?'line-through':'none',lineHeight:1.4}}>{action.accion}</p>
          <div style={{display:'flex',flexWrap:'wrap',gap:'6px',alignItems:'center'}}>
            {h && (
              <span style={{fontSize:'11px',color:'var(--t3)',background:'var(--surf-2)',borderRadius:'4px',padding:'2px 8px',display:'inline-flex',alignItems:'center',gap:'4px'}}>
                <span style={{width:'5px',height:'5px',borderRadius:'50%',background:sevDot,flexShrink:0}}></span>
                Hallazgo #{h.id}
              </span>
            )}
            <span style={{fontSize:'11px',color:'var(--t3)'}}>· {action.fecha}</span>
            <button onClick={()=>setShowNote(!showNote)} style={{fontSize:'11px',color:note?'var(--accent)':'var(--t3)',background:'none',border:'none',cursor:'pointer',padding:0}}>{note?'✎ nota':'+ nota'}</button>
          </div>
          {showNote && <textarea value={note} onChange={e=>setNote(e.target.value)} placeholder="Nota de seguimiento..." style={{marginTop:'8px',width:'100%',background:'var(--surf-2)',border:'1px solid var(--border)',borderRadius:'6px',padding:'8px 10px',fontSize:'12px',color:'var(--t1)',resize:'none',minHeight:'52px',fontFamily:'var(--font)'}}/>}
        </div>
        <button onClick={()=>onChange(action.id,SCYCLE[action.status])} style={{flexShrink:0,padding:'5px 10px',borderRadius:'6px',background:sc.bg,color:sc.c,border:'none',fontSize:'11px',fontWeight:600,whiteSpace:'nowrap',cursor:'pointer'}}>{sc.label}</button>
      </div>
    </div>
  );
}

/* ─── EXPORTS ────────────────────────────────────────────────────────────────── */

Object.assign(window, {
  PERIOD_DATA, BASE_ACCIONES, CHAT_QUESTIONS, VOICE_EXTRACTED, APP_DATA,
  Ic, Tooltip, KPICard, FindingCard, ActionRow, SEV, SCFG, SCYCLE, getSC,
});
