// CTox EAD — recreations of the real CTox screens, in Synvia green.
// Each screen is a pure component; BeatScreen animates cursor + annotations.
// Conferido contra a plataforma real (ctox.io) em 06/08/2026 — ver telas-reais-ctox/.

// ── Wizard stepper (Laboratório → Amostra) — igual ao real com treinamento OK (7 etapas).
// Obs.: conta SEM treinamento de aptidão concluído vê um wizard reduzido de 5 etapas.
const WIZ = ['Laboratório', 'Coletor', 'Finalidade', 'Doador', 'Pagamento', 'Testemunha', 'Amostra'];

function WizardStepper({ active = 3 }) {
  return (
    <div style={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'center', padding: '46px 0 20px' }}>
      {WIZ.map((label, i) => {
        const n = i + 1;
        const done = n < active, cur = n === active;
        return (
          <React.Fragment key={label}>
            <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', width: 176 }}>
              <div style={{
                width: 56, height: 56, borderRadius: '50%',
                display: 'flex', alignItems: 'center', justifyContent: 'center',
                background: done ? '#7FBFA4' : (cur ? CTX_BLUE : '#123028'),
                color: '#fff', fontSize: 24, fontWeight: 800,
                boxShadow: cur ? `0 0 0 6px rgba(28,65,55,0.14)` : 'none',
              }}>
                {done ? (
                  <svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="#fff" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round">
                    <path d="M4 13l5 5L20 6"/>
                  </svg>
                ) : <span data-tnum>{n}</span>}
              </div>
              <div style={{
                marginTop: 12, fontSize: 20,
                color: cur ? CTX_BLUE : (done ? '#7FBFA4' : '#9BB3AA'),
                fontWeight: cur ? 700 : 500,
              }}>{label}</div>
            </div>
            {i < WIZ.length - 1 && (
              <div style={{ height: 2, background: '#C9D8D2', flex: '0 0 44px', marginTop: 27 }} />
            )}
          </React.Fragment>
        );
      })}
    </div>
  );
}

// ── Circular option button (Finalidade / Pagamento) ───────────────────────
function CircleOption({ icon, label, selected, pulse }) {
  return (
    <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 14 }}>
      <div style={{
        width: 92, height: 92, borderRadius: '50%',
        background: selected ? CTX_BLUE : '#2E7C63',
        color: '#fff', display: 'flex', alignItems: 'center', justifyContent: 'center',
        transform: selected ? 'scale(1.08)' : 'scale(1)',
        boxShadow: selected ? `0 0 0 7px rgba(178,232,71,0.45)` : '0 3px 10px rgba(0,0,0,0.10)',
        transition: 'all 180ms ease-out',
        animation: pulse ? 'chatPulse 1.5s ease-out infinite' : 'none',
      }}>
        <span style={{ transform: 'scale(1.9)', display: 'flex' }}>{icon}</span>
      </div>
      <div style={{ fontSize: 23, color: CTX_INK, fontWeight: selected ? 700 : 500 }}>{label}</div>
    </div>
  );
}

const SCR_I = {
  car: (
    <svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinejoin="round" strokeLinecap="round">
      <path d="M3 14l2-5a3 3 0 0 1 2.8-2h8.4A3 3 0 0 1 19 9l2 5v4h-3v-2H6v2H3z"/>
      <circle cx="7.5" cy="16.5" r="1.1"/><circle cx="16.5" cy="16.5" r="1.1"/>
    </svg>
  ),
  case: (
    <svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinejoin="round">
      <rect x="3" y="7" width="18" height="13" rx="2"/><path d="M9 7V5h6v2"/>
    </svg>
  ),
  dots: (
    <svg viewBox="0 0 24 24" width="24" height="24" fill="currentColor">
      <circle cx="6" cy="12" r="1.8"/><circle cx="12" cy="12" r="1.8"/><circle cx="18" cy="12" r="1.8"/>
    </svg>
  ),
  doc: (
    <svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinejoin="round">
      <path d="M7 3h8l4 4v14H7z"/><path d="M15 3v4h4"/>
    </svg>
  ),
  card: (
    <svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinejoin="round">
      <rect x="2.5" y="6" width="19" height="12" rx="2"/><path d="M2.5 10h19"/>
    </svg>
  ),
  barcode: (
    <svg viewBox="0 0 24 24" width="24" height="24" fill="currentColor">
      <rect x="4" y="5" width="1.6" height="14"/><rect x="7" y="5" width="1" height="14"/>
      <rect x="9.5" y="5" width="2" height="14"/><rect x="13" y="5" width="1" height="14"/>
      <rect x="15.5" y="5" width="1.6" height="14"/><rect x="18.5" y="5" width="1" height="14"/>
    </svg>
  ),
  cash: (
    <svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinejoin="round">
      <rect x="2.5" y="6" width="19" height="12" rx="2"/><circle cx="12" cy="12" r="3"/>
    </svg>
  ),
  pix: (
    <svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" strokeWidth="1.9" strokeLinejoin="round">
      <path d="M12 3l4.5 4.5L12 12 7.5 7.5z"/><path d="M12 12l4.5 4.5L12 21l-4.5-4.5z"/>
    </svg>
  ),
  dots3v: (
    <svg viewBox="0 0 24 24" width="20" height="20" fill="currentColor">
      <circle cx="12" cy="5" r="1.7"/><circle cx="12" cy="12" r="1.7"/><circle cx="12" cy="19" r="1.7"/>
    </svg>
  ),
};

// ── Status chip ────────────────────────────────────────────────────────────
const STATUS_COLORS = {
  'Aguardando Envio':        { bg: '#FFF1CC', fg: '#7A5A05' },
  'Aguardando Recebimento':  { bg: '#E4EEF7', fg: '#1D4E76' },
  'Em Triagem':              { bg: '#E7F1EC', fg: '#1C4137' },
  'Amostra Recebida':        { bg: '#EDE9F7', fg: '#40307A' },
  'Aguardando Confirmatório':{ bg: '#FFE6D4', fg: '#8A4212' },
  'Em Confirmatório':        { bg: '#FFDCC2', fg: '#7A3A0C' },
  'Finalizado':              { bg: '#DFF3E4', fg: '#14672F' },
  'Recoleta':                { bg: '#FBDDDD', fg: '#8C1D1D' },
  'Aguardando envio':        { bg: '#FFF1CC', fg: '#7A5A05' },
  'Enviado':                 { bg: '#E1EBFA', fg: '#1D4E76' },
  'Recebido':                { bg: '#D9F2DE', fg: '#1F7A38' },
};
function StatusChip({ s }) {
  const c = STATUS_COLORS[s] || { bg: '#EEE', fg: '#444' };
  return (
    <span style={{ background: c.bg, color: c.fg, padding: '7px 15px', borderRadius: 6,
      fontSize: 17, fontWeight: 700, whiteSpace: 'nowrap' }}>{s}</span>
  );
}

// ════════════════════════════════════════════════════════════════════════════
// SCREEN: Lista de Coletas
// ════════════════════════════════════════════════════════════════════════════
// Formato real: código numérico de 8 dígitos, sem prefixo (ex.: 76536298).
// Colunas reais: Código, Situação, Laboratório, Coletor, Doador, Data da coleta, Recebido Em, Ações.
const COLETAS_ROWS = [
  ['76536291', 'Finalizado',               'LAB EXEMPLO - COTIA', 'Marcos R. Lima', 'Ana Paula Ferreira', '29/04/2026 - 15:43', '30/04/2026 - 09:12'],
  ['76536292', 'Em Confirmatório',         'LAB EXEMPLO - COTIA', 'Marcos R. Lima', 'Bruno Carvalho',     '29/04/2026 - 15:43', '30/04/2026 - 09:12'],
  ['76536293', 'Aguardando Confirmatório', 'LAB EXEMPLO - COTIA', 'Juliana Prado',  'Carla Menezes',      '29/04/2026 - 14:10', '30/04/2026 - 09:12'],
  ['76536294', 'Em Triagem',               'LAB EXEMPLO - COTIA', 'Juliana Prado',  'Diego Nascimento',   '29/04/2026 - 11:22', '30/04/2026 - 09:12'],
  ['76536295', 'Aguardando Recebimento',   'LAB EXEMPLO - COTIA', 'Marcos R. Lima', 'Eduardo Batista',    '28/04/2026 - 17:05', '-'],
  ['76536296', 'Aguardando Envio',         'LAB EXEMPLO - COTIA', 'Juliana Prado',  'Fernanda Rocha',     '28/04/2026 - 16:48', '-'],
];

function ScreenColetas({ tab = 'Coletas', revealRows = 6, highlightRow = -1 }) {
  return (
    <AppShell activeSidebar="scissors" title="Coletas"
      headerRight={
        <div style={{ display: 'flex', alignItems: 'center', gap: 20 }}>
          <PillButton icon={I.docplus} label="INSTRUÇÕES" />
          <PillButton icon={I.plus} label="NOVA COLETA" />
          <div style={{ color: '#fff', opacity: 0.92 }}>{I.bell}</div>
        </div>
      }>
      {/* Tabs */}
      <div style={{ display: 'flex', justifyContent: 'center', padding: '22px 0 4px', background: '#F1F3F2' }}>
        <div style={{ display: 'flex', border: `1px solid ${CTX_BLUE}`, borderRadius: 6, overflow: 'hidden' }}>
          {['Coletas', 'Recoletas'].map((tb) => (
            <div key={tb} style={{ padding: '14px 78px', fontSize: 21, fontWeight: 600,
              background: tab === tb ? CTX_BLUE : '#fff', color: tab === tb ? '#fff' : CTX_BLUE }}>{tb}</div>
          ))}
        </div>
      </div>

      <div style={{ margin: '26px 56px', background: '#fff', borderRadius: 10, padding: '34px 40px',
        boxShadow: '0 2px 10px rgba(0,0,0,0.05)' }}>
        <div style={{ fontSize: 38, fontWeight: 500, color: CTX_INK, marginBottom: 26 }}>Lista de Coletas</div>
        {/* Filters */}
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr 1fr', gap: 34, marginBottom: 34 }}>
          {[['Filtro', 'Código Amostra'], ['', 'Código da amostra'], ['Coletor', 'Todos'], ['Finalidade', 'Todas']].map((f, i) => (
            <div key={i}>
              {f[0] && <div style={{ fontSize: 15, color: CTX_MUTED, marginBottom: 5 }}>{f[0]}</div>}
              <div style={{ borderBottom: `1px solid #CBD5D0`, paddingBottom: 9, fontSize: 21,
                color: i === 1 ? CTX_MUTED : CTX_INK, display: 'flex', alignItems: 'center', gap: 10,
                marginTop: f[0] ? 0 : 22 }}>
                {i === 1 && <span style={{ color: CTX_MUTED, display: 'flex' }}>{I.search}</span>}
                {f[1]}
              </div>
            </div>
          ))}
        </div>
        {/* Table — na tela real a Situação aparece como texto simples, sem chip colorido */}
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1.35fr 1.35fr 1.15fr 1.35fr 1.15fr 1.05fr 0.45fr', columnGap: 18 }}>
          {['Código da amostra', 'Situação da Análise', 'Laboratório', 'Coletor', 'Doador', 'Data da coleta', 'Recebido Em', 'Ações'].map((h) => (
            <div key={h} style={{ fontSize: 17, color: CTX_MUTED, fontWeight: 600, paddingBottom: 16,
              borderBottom: `1px solid ${CTX_DIVIDER}` }}>{h}</div>
          ))}
          {COLETAS_ROWS.slice(0, revealRows).map((r, ri) => (
            <React.Fragment key={r[0]}>
              {[
                <span data-tnum style={{ fontWeight: 700, color: CTX_INK }}>{r[0]}</span>,
                r[1], r[2], r[3], r[4],
                <span data-tnum>{r[5]}</span>,
                <span data-tnum>{r[6]}</span>,
                <span style={{ color: CTX_BLUE, display: 'flex' }}>{SCR_I.dots3v}</span>,
              ].map((cell, ci) => (
                <div key={ci} style={{ padding: '19px 0', borderBottom: `1px solid ${CTX_DIVIDER}`,
                  fontSize: 19, color: 'rgba(44,57,66,0.9)', display: 'flex', alignItems: 'center',
                  background: ri === highlightRow ? 'rgba(178,232,71,0.20)' : 'transparent' }}>{cell}</div>
              ))}
            </React.Fragment>
          ))}
        </div>
      </div>
    </AppShell>
  );
}

// ════════════════════════════════════════════════════════════════════════════
// SCREEN: Nova Coleta — Finalidade (etapa 3 do wizard real)
// ════════════════════════════════════════════════════════════════════════════
function ScreenFinalidade({ selected = null, resp = '', typing = false, voucher = 'Não' }) {
  const opts = [
    { id: 'CNH', icon: SCR_I.car }, { id: 'CLT', icon: SCR_I.case },
    { id: 'CLT + CNH', icon: SCR_I.car }, { id: 'Outro', icon: SCR_I.dots },
    { id: 'Concurso', icon: SCR_I.doc },
  ];
  return (
    <AppShell activeSidebar="scissors" title="COLETA" headerBack showChat={false}>
      <div style={{ background: '#fff', height: '100%' }}>
        <WizardStepper active={3} />
        <div style={{ padding: '34px 120px' }}>
          <div style={{ fontSize: 42, fontWeight: 500, color: CTX_INK, marginBottom: 44 }}>Finalidade</div>
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 90, marginBottom: 54 }}>
            <div>
              <div style={{ fontSize: 18, color: CTX_MUTED, marginBottom: 8 }}>Data e Hora do atendimento *</div>
              <div data-tnum style={{ borderBottom: '1px solid #CBD5D0', paddingBottom: 10, fontSize: 26, color: CTX_INK }}>
                29/04/2026 15:56
              </div>
            </div>
            <div>
              <div style={{ fontSize: 18, color: CTX_BLUE, marginBottom: 8 }}>Profissional responsável pelo atendimento</div>
              <div style={{ borderBottom: `2px solid ${CTX_BLUE}`, paddingBottom: 10, fontSize: 26, color: CTX_INK,
                display: 'flex', alignItems: 'center' }}>
                {resp}
                {typing && <span style={{ display: 'inline-block', width: 2, height: 28, background: CTX_BLUE,
                  marginLeft: 2, animation: 'caretBlink 1s steps(2) infinite' }} />}
              </div>
            </div>
          </div>
          <div style={{ fontSize: 26, color: CTX_INK, marginBottom: 18 }}>O condutor possui vale-exame?</div>
          <div style={{ display: 'flex', gap: 44, marginBottom: 52 }}>
            {['Sim', 'Não'].map((o) => (
              <div key={o} style={{ display: 'flex', alignItems: 'center', gap: 12, fontSize: 26, color: CTX_INK }}>
                <span style={{ width: 26, height: 26, borderRadius: '50%',
                  border: `2px solid ${voucher === o ? CTX_BLUE : '#A9B8B2'}`,
                  display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
                  {voucher === o && <span style={{ width: 13, height: 13, borderRadius: '50%', background: CTX_BLUE }} />}
                </span>{o}
              </div>
            ))}
          </div>
          <div style={{ display: 'flex', gap: 82 }}>
            {opts.map((o) => <CircleOption key={o.id} icon={o.icon} label={o.id} selected={selected === o.id} />)}
          </div>
        </div>
      </div>
    </AppShell>
  );
}

// ════════════════════════════════════════════════════════════════════════════
// SCREEN: Nova Coleta — Pagamento (etapa 5 do wizard real)
// ════════════════════════════════════════════════════════════════════════════
function ScreenPagamento({ selected = null }) {
  const opts = [
    { id: 'Cartão', icon: SCR_I.card }, { id: 'Boleto', icon: SCR_I.barcode },
    { id: 'Dinheiro', icon: SCR_I.cash }, { id: 'Pix', icon: SCR_I.pix },
  ];
  return (
    <AppShell activeSidebar="scissors" title="COLETA" headerBack showChat={false}>
      <div style={{ background: '#fff', height: '100%', position: 'relative' }}>
        <WizardStepper active={5} />
        <div style={{ padding: '30px 120px' }}>
          <div style={{ fontSize: 42, fontWeight: 500, color: CTX_INK, marginBottom: 38 }}>Pagamento</div>
          <div style={{ fontSize: 27, color: CTX_INK, marginBottom: 6 }}>Valor Total**</div>
          <div data-tnum style={{ fontSize: 40, fontWeight: 700, color: CTX_BLUE, marginBottom: 8 }}>R$ 249,90</div>
          <div style={{ fontSize: 19, color: CTX_MUTED, marginBottom: 46 }}>**Valor máximo: R$350,00</div>
          <div style={{ fontSize: 30, color: CTX_INK, marginBottom: 34 }}>Forma de Pagamento</div>
          <div style={{ display: 'flex', gap: 88 }}>
            {opts.map((o) => <CircleOption key={o.id} icon={o.icon} label={o.id} selected={selected === o.id} />)}
          </div>
        </div>
        <div style={{ position: 'absolute', bottom: 40, left: 0, right: 0, display: 'flex',
          justifyContent: 'center', gap: 24, borderTop: `1px solid ${CTX_DIVIDER}`, paddingTop: 34 }}>
          {['VOLTAR', 'PRÓXIMO'].map((b, i) => (
            <div key={b} style={{ padding: '17px 62px', borderRadius: 999, fontSize: 20, fontWeight: 700,
              letterSpacing: '0.06em', background: i ? CTX_BLUE : '#5E8C7C', color: '#fff' }}>{b}</div>
          ))}
        </div>
      </div>
    </AppShell>
  );
}

// ════════════════════════════════════════════════════════════════════════════
// SCREEN: Dashboard / Acompanhamento de Coletas
// ════════════════════════════════════════════════════════════════════════════
function ScreenDashboard({ range = 'MÊS', grow = 1 }) {
  // Tela real: gráfico de LINHA/ÁREA com pontos e valores (não barras); anos de 2018 a 2026.
  const vals = [38, 52, 47, 61, 74, 58, 66, 82, 71, 90, 78, 64];
  const months = ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'];
  const W = 1240, H = 300, PADX = 34, TOP = 34, BASE = H - 40;
  const maxV = 90;
  const pts = vals.map((v, i) => ({
    x: PADX + (i * (W - 2 * PADX)) / (vals.length - 1),
    y: BASE - (v / maxV) * (BASE - TOP) * grow,
  }));
  const line = pts.map((p, i) => `${i ? 'L' : 'M'}${p.x},${p.y}`).join(' ');
  const area = `${line} L${pts[pts.length - 1].x},${BASE} L${pts[0].x},${BASE} Z`;
  return (
    <AppShell activeSidebar="bars" title="Acompanhamento de Coletas"
      headerRight={<div style={{ color: '#fff', opacity: 0.92 }}>{I.bell}</div>}>
      <div style={{ margin: '30px 56px', background: '#fff', borderRadius: 10, padding: '32px 44px',
        boxShadow: '0 2px 10px rgba(0,0,0,0.05)' }}>
        <div style={{ fontSize: 38, fontWeight: 500, color: CTX_INK, marginBottom: 26 }}>Resumo</div>
        <div style={{ display: 'flex', gap: 40, borderBottom: `1px solid ${CTX_DIVIDER}`, paddingBottom: 14, marginBottom: 28 }}>
          {['2018','2019','2020','2021','2022','2023','2024','2025','2026'].map((y, i, arr) => (
            <div key={y} data-tnum style={{ fontSize: 21, fontWeight: i === arr.length - 1 ? 700 : 500,
              color: i === arr.length - 1 ? CTX_BLUE : CTX_MUTED,
              borderBottom: i === arr.length - 1 ? `3px solid ${CTX_BLUE}` : 'none', paddingBottom: 11 }}>{y}</div>
          ))}
        </div>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 22, marginBottom: 30 }}>
          {[['Total','781'],['Máximo','90'],['Mínimo','38'],['Média','65']].map(([l, v]) => (
            <div key={l} style={{ border: `1px solid ${CTX_DIVIDER}`, borderRadius: 8, padding: '20px 26px' }}>
              <div style={{ fontSize: 19, color: CTX_MUTED, fontWeight: 600 }}>{l}</div>
              <div data-tnum style={{ fontSize: 40, fontWeight: 800, color: CTX_BLUE, marginTop: 4 }}>{v}</div>
            </div>
          ))}
        </div>
        <div style={{ display: 'flex', gap: 0, marginBottom: 20 }}>
          {['ANO','MÊS','SEMANA','DIA'].map((r) => (
            <div key={r} style={{ flex: 1, textAlign: 'center', fontSize: 19, fontWeight: 700, paddingBottom: 12,
              color: range === r ? CTX_BLUE : CTX_MUTED,
              borderBottom: `3px solid ${range === r ? CTX_BLUE : CTX_DIVIDER}` }}>{r}</div>
          ))}
        </div>
        <svg viewBox={`0 0 ${W} ${H}`} style={{ width: '100%', display: 'block' }}>
          {[0.25, 0.5, 0.75, 1].map((f) => (
            <line key={f} x1={PADX} x2={W - PADX}
              y1={BASE - f * (BASE - TOP)} y2={BASE - f * (BASE - TOP)}
              stroke={CTX_DIVIDER} strokeWidth="1" strokeDasharray="3 5" />
          ))}
          <line x1={PADX} x2={W - PADX} y1={BASE} y2={BASE} stroke={CTX_DIVIDER} strokeWidth="1.5" />
          <path d={area} fill="rgba(28,65,55,0.10)" />
          <path d={line} fill="none" stroke={CTX_BLUE} strokeWidth="2.5"
            strokeLinejoin="round" strokeLinecap="round" />
          {pts.map((p, i) => (
            <circle key={i} cx={p.x} cy={p.y} r={i === 9 ? 6 : 4.5}
              fill={i === 9 ? CTX_GREEN_LIME : CTX_BLUE}
              stroke="#fff" strokeWidth="1.5" />
          ))}
          {grow > 0.85 && pts.map((p, i) => (
            <text key={i} x={p.x} y={p.y - 14} textAnchor="middle"
              fontSize="15" fontWeight="700" fill={CTX_MUTED}
              style={{ fontVariantNumeric: 'tabular-nums' }}>{vals[i]}</text>
          ))}
          {pts.map((p, i) => (
            <text key={i} x={p.x} y={H - 12} textAnchor="middle" fontSize="16" fill={CTX_MUTED}>{months[i]}</text>
          ))}
        </svg>
      </div>
    </AppShell>
  );
}

// ════════════════════════════════════════════════════════════════════════════
// SCREEN: Pacotes Enviados (logística)
// ════════════════════════════════════════════════════════════════════════════
// Formato real: código alfanumérico (BAG física, ex.: LP35FBZJ) ou numérico ("sem BAG").
// Colunas reais: Pacote, Status, Enviado em, Recebido em, Amostras Verificadas, Enviado Por, Sem pacote, Ações.
const PACOTES = [
  ['LP35FBZJ', 'Aguardando envio', '-',                  '-',                  '3 amostras', 'Juliana Prado',  'NÃO'],
  ['28R4D6BF', 'Aguardando envio', '-',                  '-',                  '4 amostras', 'Juliana Prado',  'NÃO'],
  ['47174673', 'Enviado',          '29/04/2026 - 16:33', '-',                  '1 amostras', 'Marcos R. Lima', 'SIM'],
  ['UGHCI5LI', 'Recebido',         '29/04/2026 - 10:38', '29/04/2026 - 10:38', '3 amostras', 'Marcos R. Lima', 'NÃO'],
  ['J2SELR27', 'Recebido',         '28/04/2026 - 13:58', '28/04/2026 - 13:59', '5 amostras', 'Juliana Prado',  'NÃO'],
];

function ScreenPacotes({ highlightRow = -1 }) {
  return (
    <AppShell activeSidebar="send" title="Novo pacote (bag)"
      headerRight={<PillButton icon={I.plus} label="NOVO PACOTE (BAG)" />}>
      <div style={{ margin: '30px 56px', background: '#fff', borderRadius: 10, padding: '32px 44px',
        boxShadow: '0 2px 10px rgba(0,0,0,0.05)' }}>
        <div style={{ fontSize: 38, fontWeight: 500, color: CTX_INK, marginBottom: 28 }}>Pacotes Enviados</div>
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 46, marginBottom: 34 }}>
          {['Pesquisar por Pacote ou número de amostra', 'Situação do Pacote'].map((p) => (
            <div key={p} style={{ borderBottom: '1px solid #CBD5D0', paddingBottom: 10, fontSize: 21, color: CTX_MUTED }}>{p}</div>
          ))}
        </div>
        <div style={{ display: 'grid', gridTemplateColumns: '0.9fr 1.1fr 1.25fr 1.25fr 1fr 1.1fr 0.7fr 0.45fr', columnGap: 18 }}>
          {['Pacote', 'Status', 'Enviado em', 'Recebido em', 'Amostras Verificadas', 'Enviado Por', 'Sem pacote', 'Ações'].map((h) => (
            <div key={h} style={{ fontSize: 17, color: CTX_MUTED, fontWeight: 600, paddingBottom: 16,
              borderBottom: `1px solid ${CTX_DIVIDER}` }}>{h}</div>
          ))}
          {PACOTES.map((r, ri) => (
            <React.Fragment key={r[0]}>
              {[
                <span data-tnum style={{ fontWeight: 700, color: CTX_INK }}>{r[0]}</span>,
                <StatusChip s={r[1]} />,
                <span data-tnum>{r[2]}</span>,
                <span data-tnum>{r[3]}</span>, r[4], r[5],
                <span style={{ color: r[6] === 'SIM' ? '#1F8A3E' : CTX_BLUE, fontWeight: 700 }}>{r[6]}</span>,
                <span style={{ color: CTX_BLUE, display: 'flex' }}>{SCR_I.dots3v}</span>,
              ].map((cell, ci) => (
                <div key={ci} style={{ padding: '19px 0', borderBottom: `1px solid ${CTX_DIVIDER}`,
                  fontSize: 19, color: 'rgba(44,57,66,0.9)', display: 'flex', alignItems: 'center',
                  background: ri === highlightRow ? 'rgba(178,232,71,0.22)' : 'transparent' }}>{cell}</div>
              ))}
            </React.Fragment>
          ))}
        </div>
      </div>
    </AppShell>
  );
}

// ════════════════════════════════════════════════════════════════════════════
// BEAT: screen walkthrough (screen + cursor + caption)
// ════════════════════════════════════════════════════════════════════════════
const SCREENS = {
  coletas: ScreenColetas,
  finalidade: ScreenFinalidade,
  pagamento: ScreenPagamento,
  dashboard: ScreenDashboard,
  pacotes: ScreenPacotes,
};

function BeatScreen({ beat }) {
  const { localTime, duration } = useSprite();
  const { opacity } = kitFade(localTime, duration, 0.35, 0.4);
  const Screen = SCREENS[beat.screen];
  const props = typeof beat.props === 'function' ? beat.props(localTime) : (beat.props || {});
  const cur = kitCursor(localTime, beat.cursor);
  return (
    <div style={{ position: 'absolute', inset: 0, background: CTX_BG, opacity, overflow: 'hidden' }}>
      <Screen {...props} />
      {beat.caption && (
        <SubSprite start={beat.captionAt || 1.0} end={duration - 0.3}>
          <Caption text={beat.caption} x={beat.captionX || 130} y={beat.captionY || 900}
            width={beat.captionW || 1100} accent={CTX_GREEN_LIME} />
        </SubSprite>
      )}
      {cur && <Cursor x={cur.x} y={cur.y} clicking={cur.clicking} />}
    </div>
  );
}

Object.assign(window, {
  WizardStepper, CircleOption, SCR_I, StatusChip, SCREENS, BeatScreen,
  ScreenColetas, ScreenFinalidade, ScreenPagamento, ScreenDashboard, ScreenPacotes,
});
