/* ═══════════════════════════════════════════════════════════════
   Grupo Cerrado — cenas animadas (motion graphics em SVG).

   Cada divisão conta a própria história em movimento, no lugar das
   fotos de placeholder:

     CenaRota        Express       — a van sai do CD, faz a rota e entrega
     CenaEmpresa     Empresas      — loja → Cerrado → cliente, com NF-e
     CenaRastreio    Consumidor    — o celular acompanhando a entrega ao vivo
     CenaEntregador  Entregadores  — o parceiro rodando, ganhos subindo
     CenaGestao      Consultoria   — do achismo (pontos soltos) ao indicador
     CenaPainel      dashboards    — KPIs vivos (consultoria, ERP, express)
     CenaErp         ERP           — o sistema rodando, NF-e autorizada
     CenaLex         Lex           — contrato se escreve, assina e é carimbado
     CenaEcossistema Grupo         — as 5 empresas orbitando o mesmo centro

   E peças de apoio: RedeFundo (rede de rotas atrás dos títulos),
   EstradaCTA (veículo cruzando o pé dos CTAs) e Digitando (código de
   rastreio sendo digitado).

   Animação: CSS (motion.css) para os loops ambientes e SMIL para o que
   precisa andar sincronizado num caminho. motion.js pausa tudo fora
   da tela. Depende de site-primitives.jsx (CE, Icon).
   ═══════════════════════════════════════════════════════════════ */

// Os PNGs da frota ficam 7 dias no cache do navegador (firebase.json). Ao trocar
// o conteúdo de um deles mantendo o nome, suba este número.
var CE_VERSAO_VEICULOS = 2;
function ceAsset(p) {
  var base = (typeof window !== 'undefined' && window.ASSET_BASE != null) ? window.ASSET_BASE : '../../';
  if (p.indexOf('assets/veiculos/') === 0) p += '?v=' + CE_VERSAO_VEICULOS;
  return base + p;
}

/* moldura comum: div responsiva + svg 460×360 */
function Cena({ rotulo, fluida, altura, children, defs }) {
  var estilo = altura ? { aspectRatio: 'auto', height: altura } : undefined;
  return (
    <div className={'ce-cena' + (fluida ? ' ce-cena-fluida' : '')} role="img" aria-label={rotulo} style={estilo}>
      <svg viewBox="0 0 460 360" preserveAspectRatio="xMidYMid slice">
        <defs>
          <filter id="ce-sombra" x="-20%" y="-20%" width="140%" height="160%">
            <feDropShadow dx="0" dy="6" stdDeviation="8" floodColor="#0F1C3E" floodOpacity=".28" />
          </filter>
          {defs}
        </defs>
        {children}
      </svg>
    </div>
  );
}

/* ícone do kit dentro de um svg */
function Ico({ name, x, y, size, color, sw }) {
  var s = size || 18;
  return (
    <g transform={'translate(' + (x - s / 2) + ' ' + (y - s / 2) + ')'}>
      <Icon name={name} size={s} color={color || '#fff'} strokeWidth={sw || 2} />
    </g>
  );
}

/* um “toast” branco com ícone redondo, título e linha de apoio */
function Toast({ x, y, w, titulo, sub, cor, icone, className, d, ciclo }) {
  return (
    <g transform={'translate(' + x + ' ' + y + ')'}>
      <g className={className || 'ce-toast'} style={{ '--ce-d': (d || 0) + 's', '--ce-ciclo': (ciclo || 7) + 's' }}>
        <rect width={w} height="50" rx="12" fill="#fff" filter="url(#ce-sombra)" />
        <circle cx="25" cy="25" r="14" fill={cor || CE.success} />
        <Ico name={icone || 'check'} x={25} y={25} size={15} sw={3} />
        <text x="48" y="22" fontSize="13" fontWeight="800" fill={CE.n900} letterSpacing=".04em">{titulo}</text>
        <text x="48" y="37" className="ce-t-body" fontSize="10.5" fill={CE.n500}>{sub}</text>
      </g>
    </g>
  );
}

/* ═══════════════ EXPRESS · a rota ═══════════════ */
var ROTA_D = 'M70 290 H172 Q190 290 190 272 V198 Q190 180 208 180 H292 Q310 180 310 162 V113 Q310 95 328 95 H380';

function CenaRota({ fluida }) {
  var xs = [0, 70, 190, 310, 410, 460], ys = [0, 95, 180, 290, 360];
  var quadras = [];
  for (var i = 0; i < xs.length - 1; i++) for (var j = 0; j < ys.length - 1; j++) {
    var x0 = xs[i] + 15, x1 = xs[i + 1] - 15, y0 = ys[j] + 15, y1 = ys[j + 1] - 15;
    if (x1 - x0 > 8 && y1 - y0 > 8) quadras.push([x0, y0, x1 - x0, y1 - y0, (i + j) % 3]);
  }
  var T = '7s';
  return (
    <Cena fluida={fluida} rotulo="Animação: a van da Cerrado Express sai do centro de distribuição, percorre a rota e entrega ao cliente"
      defs={<linearGradient id="ce-rota-bg" x1="0" y1="0" x2="1" y2="1">
        <stop offset="0" stopColor={CE.blue900} /><stop offset="1" stopColor={CE.blue} />
      </linearGradient>}>
      <rect width="460" height="360" fill="url(#ce-rota-bg)" />

      {/* quarteirões */}
      {quadras.map(function(q, k) {
        return <rect key={k} x={q[0]} y={q[1]} width={q[2]} height={q[3]} rx="7"
          fill={q[4] === 0 ? 'rgba(255,255,255,.07)' : 'rgba(255,255,255,.035)'} />;
      })}
      {/* ruas */}
      <g stroke="rgba(255,255,255,.16)" strokeWidth="1" strokeDasharray="6 9">
        {ys.slice(1, -1).map(function(y) { return <line key={'h' + y} x1="0" x2="460" y1={y} y2={y} />; })}
        {xs.slice(1, -1).map(function(x) { return <line key={'v' + x} y1="0" y2="360" x1={x} x2={x} />; })}
      </g>

      {/* tráfego ambiente */}
      {[['M460 180 H0', 11], ['M410 360 V0', 9], ['M0 95 H460', 13]].map(function(t, k) {
        return (
          <circle key={k} r="2.6" fill="#fff" opacity=".45">
            <animateMotion dur={t[1] + 's'} repeatCount="indefinite" path={t[0]} begin={(-k * 1.7) + 's'} />
          </circle>
        );
      })}

      {/* rota: tracejado de fundo + traço que se desenha */}
      <path d={ROTA_D} fill="none" stroke={CE.sun} strokeOpacity=".28" strokeWidth="4" strokeLinecap="round" strokeDasharray="1 9" />
      <path id="ce-rota" d={ROTA_D} pathLength="100" fill="none" stroke={CE.sun} strokeWidth="4.5"
        strokeLinecap="round" strokeLinejoin="round" strokeDasharray="100" strokeDashoffset="100">
        <animate attributeName="stroke-dashoffset" values="100;0;0;0" keyTimes="0;.68;.93;1" dur={T} repeatCount="indefinite" />
        <animate attributeName="stroke-opacity" values="1;1;0;0" keyTimes="0;.9;.97;1" dur={T} repeatCount="indefinite" />
      </path>

      {/* CD de origem */}
      <g>
        <circle cx="70" cy="290" r="21" fill={CE.blue700} stroke="rgba(255,255,255,.3)" strokeWidth="1.5" />
        <Ico name="package" x={70} y={290} size={18} />
        <rect x="42" y="318" width="56" height="18" rx="9" fill="rgba(255,255,255,.12)" />
        <text x="70" y="331" textAnchor="middle" fontSize="10" fontWeight="700" fill="#fff" letterSpacing=".12em">CD GYN</text>
      </g>

      {/* destino: onda de chegada + pin */}
      <circle cx="380" cy="95" r="4" fill="none" stroke={CE.sun} strokeWidth="2">
        <animate attributeName="r" values="4;4;30;30" keyTimes="0;.68;.86;1" dur={T} repeatCount="indefinite" />
        <animate attributeName="opacity" values="0;.9;0;0" keyTimes="0;.68;.86;1" dur={T} repeatCount="indefinite" />
      </circle>
      <g transform="translate(380 95)">
        <path d="M0 0 C-9 -11 -14 -17 -14 -25 a14 14 0 1 1 28 0 c0 8 -5 14 -14 25z" fill="#fff" />
        <circle cy="-25" r="6" fill={CE.rust} />
      </g>

      {/* a van (vista de cima), percorrendo a rota */}
      <g>
        <animateMotion dur={T} repeatCount="indefinite" rotate="auto" keyPoints="0;1;1" keyTimes="0;.68;1" calcMode="linear">
          <mpath href="#ce-rota" />
        </animateMotion>
        <circle r="22" fill={CE.sun} opacity=".2" />
        <image href={ceAsset('assets/veiculos/van-top.png')} x="-26" y="-26" width="52" height="52" />
      </g>

      {/* status embaixo: em rota → entregue */}
      <g transform="translate(286 306)">
        <rect width="150" height="34" rx="17" fill="rgba(15,28,62,.55)" stroke="rgba(255,255,255,.22)" />
        <circle className="ce-pisca" cx="20" cy="17" r="4.5" fill={CE.sun} />
        <text x="33" y="21.5" fontSize="12" fontWeight="700" fill="#fff" letterSpacing=".08em">
          EM ROTA · 12 MIN
          <animate attributeName="opacity" values="1;1;0;0;1" keyTimes="0;.67;.69;.98;1" dur={T} repeatCount="indefinite" />
        </text>
        <text x="33" y="21.5" fontSize="12" fontWeight="700" fill={CE.sun} letterSpacing=".08em" opacity="0">
          ENTREGUE ✓
          <animate attributeName="opacity" values="0;0;1;1;0" keyTimes="0;.68;.7;.97;1" dur={T} repeatCount="indefinite" />
        </text>
      </g>

      {/* toast de entrega */}
      <g opacity="0">
        <animate attributeName="opacity" values="0;0;1;1;0" keyTimes="0;.7;.74;.94;1" dur={T} repeatCount="indefinite" />
        <animateTransform attributeName="transform" type="translate" values="22 34;22 34;22 22;22 22;22 16"
          keyTimes="0;.7;.75;.94;1" dur={T} repeatCount="indefinite" />
        <rect width="190" height="50" rx="12" fill="#fff" filter="url(#ce-sombra)" />
        <circle cx="25" cy="25" r="14" fill={CE.success} />
        <Ico name="check" x={25} y={25} size={15} sw={3} />
        <text x="48" y="22" fontSize="13" fontWeight="800" fill={CE.n900} letterSpacing=".04em">PEDIDO ENTREGUE</text>
        <text x="48" y="37" className="ce-t-body" fontSize="10.5" fill={CE.n500}>#4821 · no prazo · 14:32</text>
      </g>
    </Cena>
  );
}

/* ═══════════════ EMPRESAS · loja → Cerrado → cliente ═══════════════ */
var FLUXO_D = 'M70 112 C130 52 170 52 230 112 S330 172 390 112';

function CenaEmpresa() {
  var barras = [18, 26, 22, 31, 28, 36, 30, 40, 34, 44, 39, 48, 42, 52];
  return (
    <Cena rotulo="Animação: pedidos saem da loja, passam pela Cerrado com nota fiscal e chegam ao cliente; painel com indicadores ao vivo"
      defs={<linearGradient id="ce-emp-bg" x1="0" y1="0" x2="0" y2="1">
        <stop offset="0" stopColor={CE.blue900} /><stop offset="1" stopColor={CE.blue800} />
      </linearGradient>}>
      <rect width="460" height="360" fill="url(#ce-emp-bg)" />

      {/* trilho do fluxo */}
      <path d={FLUXO_D} fill="none" stroke="rgba(255,255,255,.12)" strokeWidth="10" strokeLinecap="round" />
      <path id="ce-fluxo" d={FLUXO_D} fill="none" stroke={CE.sun} strokeOpacity=".7" strokeWidth="2"
        strokeDasharray="6 10" className="ce-tracejado-anda" />

      {/* caixas viajando */}
      {[0, 1.5, 3].map(function(b) {
        return (
          <g key={b}>
            <animateMotion dur="4.5s" begin={(-b) + 's'} repeatCount="indefinite" calcMode="spline"
              keyPoints="0;1" keyTimes="0;1" keySplines=".45 0 .55 1"><mpath href="#ce-fluxo" /></animateMotion>
            <rect x="-8" y="-8" width="16" height="16" rx="3" fill={CE.sun} stroke="#fff" strokeWidth="1.5" />
            <line x1="-8" x2="8" y1="0" y2="0" stroke={CE.rust} strokeWidth="2" />
          </g>
        );
      })}

      {/* estações */}
      {[[70, 'SUA LOJA', 'building'], [390, 'SEU CLIENTE', 'heart']].map(function(e) {
        return (
          <g key={e[1]}>
            <circle cx={e[0]} cy="112" r="28" fill={CE.blue700} stroke="rgba(255,255,255,.28)" strokeWidth="1.5" />
            <Ico name={e[2]} x={e[0]} y={112} size={22} />
            <text x={e[0]} y="160" textAnchor="middle" fontSize="10.5" fontWeight="700" fill="rgba(255,255,255,.75)" letterSpacing=".14em">{e[1]}</text>
          </g>
        );
      })}
      <g>
        <circle className="ce-gira ce-fb" cx="230" cy="112" r="38" fill="none" stroke={CE.sun} strokeOpacity=".55" strokeWidth="1.5" strokeDasharray="4 7" />
        <circle cx="230" cy="112" r="30" fill={CE.sun} />
        <image href={ceAsset('assets/symbol-white.png')} x="214" y="96" width="32" height="32" />
        <text x="230" y="168" textAnchor="middle" fontSize="10.5" fontWeight="800" fill={CE.sun} letterSpacing=".14em">CERRADO</text>
      </g>
      {/* NF-e emitida a cada caixa que passa pelo centro */}
      <g transform="translate(230 40)" opacity="0">
        <animate attributeName="opacity" values="0;1;1;0" keyTimes="0;.12;.7;1" dur="1.5s" begin="2.1s" repeatCount="indefinite" />
        <rect x="-38" y="-13" width="76" height="26" rx="13" fill="#fff" />
        <text x="0" y="4.5" textAnchor="middle" fontSize="11.5" fontWeight="800" fill={CE.success} letterSpacing=".06em">NF-e ✓</text>
      </g>

      {/* painel */}
      <g transform="translate(24 192)">
        <rect width="412" height="146" rx="16" fill="#fff" />
        <text x="20" y="28" fontSize="11.5" fontWeight="800" fill={CE.n500} letterSpacing=".14em">PAINEL DA SUA OPERAÇÃO</text>
        <circle className="ce-pisca" cx="344" cy="24" r="4" fill={CE.success} />
        <text x="354" y="28" fontSize="10.5" fontWeight="800" fill={CE.success} letterSpacing=".1em">AO VIVO</text>
        {[['142', 'entregues hoje', CE.blue], ['98,4%', 'no prazo', CE.success], ['6', 'em rota agora', CE.rust]].map(function(k, i) {
          return (
            <g key={k[1]} transform={'translate(' + (20 + i * 74) + ' 52)'}>
              <text y="16" fontSize="24" fontWeight="800" fontStyle="italic" fill={k[2]}>{k[0]}</text>
              <text y="32" className="ce-t-body" fontSize="9.5" fill={CE.n500}>{k[1]}</text>
            </g>
          );
        })}
        <line x1="20" x2="210" y1="104" y2="104" stroke={CE.n100} />
        <text x="20" y="126" className="ce-t-body" fontSize="10" fill={CE.n600}>Nota fiscal em 100% das entregas</text>
        {barras.map(function(h, i) {
          return <rect key={i} className="ce-barra" x={236 + i * 12} y={128 - h} width="8" height={h} rx="2.5"
            fill={i === barras.length - 1 ? CE.sun : CE.blue}
            style={{ '--ce-d': (0.6 + i * 0.06).toFixed(2) + 's', '--ce-v': (0.7 + (i % 4) * 0.08).toFixed(2) }} />;
        })}
      </g>
    </Cena>
  );
}

/* ═══════════════ CONSUMIDOR · o celular rastreando ═══════════════ */
var RAST_D = 'M178 214 V176 Q178 164 190 164 H238 Q250 164 250 152 V88 Q250 76 262 76 H284';

function CenaRastreio({ modo }) {
  var T = '8s';
  var corrida = modo === 'corrida';
  var tx = corrida
    ? { status: 'MOTORISTA A CAMINHO', eta: 'Chega em 3 min · embarque na portaria', quem: 'Ana · Carro', info: '4,9 ★ · HB20 prata · final 42',
        notif: 'Cerrado', notifTxt: 'Sua motorista chegou!', icone: 'pin', chipA: 'CORRIDA', chipB: 'PIX', chipBIco: 'wallet' }
    : { status: 'SAIU PARA ENTREGA', eta: 'Chega em ~12 min · 3 paradas', quem: 'Carlos · Moto', info: '4,9 ★ · placa final 42',
        notif: 'Cerrado Express', notifTxt: 'Seu pedido está chegando!', icone: 'truck', chipA: 'AO VIVO', chipB: 'SEGURO', chipBIco: 'shield' };
  return (
    <Cena rotulo="Animação: celular mostrando a encomenda se movendo no mapa até a casa do cliente, com notificação"
      defs={<>
        <radialGradient id="ce-ras-glow" cx=".7" cy=".2" r=".8">
          <stop offset="0" stopColor={CE.sun} stopOpacity=".55" /><stop offset=".6" stopColor={CE.sun} stopOpacity="0" />
        </radialGradient>
        <clipPath id="ce-ras-tela"><rect x="153" y="26" width="154" height="308" rx="20" /></clipPath>
      </>}>
      <rect width="460" height="360" fill={CE.n950} />
      <rect width="460" height="360" fill="url(#ce-ras-glow)" />
      <circle className="ce-gira ce-fb" cx="230" cy="180" r="150" fill="none" stroke="rgba(255,255,255,.07)" strokeDasharray="3 10" />

      {/* celular */}
      <g className="ce-flutua">
        <rect x="145" y="18" width="170" height="324" rx="28" fill={CE.n800} stroke="rgba(255,255,255,.18)" strokeWidth="2" />
        <g clipPath="url(#ce-ras-tela)">
          <rect x="153" y="26" width="154" height="308" fill={CE.blue50} />
          {/* mapa */}
          <g stroke="#fff" strokeWidth="11">
            <line x1="153" x2="307" y1="164" y2="164" /><line x1="153" x2="307" y1="76" y2="76" />
            <line x1="178" x2="178" y1="26" y2="240" /><line x1="250" x2="250" y1="26" y2="240" />
          </g>
          {[[186, 86, 52, 66], [258, 86, 46, 66], [186, 174, 52, 40], [258, 174, 46, 40], [153, 26, 18, 42]].map(function(q, k) {
            return <rect key={k} x={q[0]} y={q[1]} width={q[2]} height={q[3]} rx="5" fill={k % 2 ? CE.blue100 : '#DDE5F7'} />;
          })}
          <path d={RAST_D} fill="none" stroke={CE.blue} strokeOpacity=".25" strokeWidth="5" strokeLinecap="round" />
          <path id="ce-rast" d={RAST_D} pathLength="100" fill="none" stroke={CE.blue} strokeWidth="5" strokeLinecap="round"
            strokeDasharray="100" strokeDashoffset="100">
            <animate attributeName="stroke-dashoffset" values="100;0;0" keyTimes="0;.85;1" dur={T} repeatCount="indefinite" />
          </path>
          <g transform="translate(284 76)">
            <path d="M0 0 C-7 -9 -11 -13 -11 -19 a11 11 0 1 1 22 0 c0 6 -4 10 -11 19z" fill={CE.rust} />
            <circle cy="-19" r="4.5" fill="#fff" />
          </g>
          <g>
            <animateMotion dur={T} repeatCount="indefinite" rotate="auto" keyPoints="0;1;1" keyTimes="0;.85;1" calcMode="linear"><mpath href="#ce-rast" /></animateMotion>
            <circle r="13" fill={CE.sun} opacity=".25" />
            <image href={ceAsset('assets/veiculos/' + (corrida ? 'car-top.png' : 'moto-bag-top.png'))} x="-17" y="-17" width="34" height="34" />
          </g>
          {/* folha inferior */}
          <rect x="153" y="234" width="154" height="110" rx="16" fill="#fff" />
          <rect x="216" y="241" width="28" height="4" rx="2" fill={CE.n200} />
          <text x="166" y="266" fontSize="11" fontWeight="800" fill={CE.rust} letterSpacing=".03em">{tx.status}</text>
          <text x="166" y="281" className="ce-t-body" fontSize="9.5" fill={CE.n600}>{tx.eta}</text>
          <rect x="166" y="292" width="128" height="6" rx="3" fill={CE.n100} />
          <rect x="166" y="292" width="40" height="6" rx="3" fill={CE.blue}>
            <animate attributeName="width" values="40;128;128" keyTimes="0;.85;1" dur={T} repeatCount="indefinite" />
          </rect>
          <circle cx="178" cy="316" r="10" fill={CE.blue50} />
          <Ico name={tx.icone} x={178} y={316} size={12} color={CE.blue} />
          <text x="194" y="314" className="ce-t-body" fontSize="9" fontWeight="600" fill={CE.n800}>{tx.quem}</text>
          <text x="194" y="325" className="ce-t-body" fontSize="8.5" fill={CE.n500}>{tx.info}</text>
          {/* notificação que desce */}
          <g className="ce-notif" style={{ '--ce-ciclo': '8s', '--ce-d': '1.2s' }}>
            <rect x="158" y="40" width="144" height="40" rx="11" fill="#fff" filter="url(#ce-sombra)" />
            <rect x="168" y="49" width="22" height="22" rx="6" fill={CE.sun} />
            <image href={ceAsset('assets/symbol-white.png')} x="171" y="52" width="16" height="16" />
            <text x="196" y="58" className="ce-t-body" fontSize="8.5" fontWeight="700" fill={CE.n900}>{tx.notif}</text>
            <text x="196" y="70" className="ce-t-body" fontSize="8" fill={CE.n600}>{tx.notifTxt}</text>
          </g>
        </g>
        <rect x="205" y="30" width="50" height="7" rx="3.5" fill={CE.n800} />
      </g>

      {/* chips flutuantes */}
      <g className="ce-flutua-2">
        <rect x="26" y="88" width="98" height="32" rx="16" fill="rgba(255,255,255,.1)" stroke="rgba(255,255,255,.22)" />
        <circle className="ce-pisca" cx="44" cy="104" r="4.5" fill={CE.success} />
        <text x="56" y="108.5" fontSize="12" fontWeight="700" fill="#fff" letterSpacing=".1em">{tx.chipA}</text>
      </g>
      <g className="ce-flutua">
        <rect x="330" y="236" width="108" height="32" rx="16" fill="rgba(255,255,255,.1)" stroke="rgba(255,255,255,.22)" />
        <g className="ce-sino"><Ico name="bell" x={349} y={252} size={15} color={CE.sun} /></g>
        <text x="362" y="256.5" fontSize="12" fontWeight="700" fill="#fff" letterSpacing=".1em">AVISOS</text>
      </g>
      <g className="ce-flutua-2">
        <rect x="336" y="70" width="98" height="32" rx="16" fill="rgba(255,255,255,.1)" stroke="rgba(255,255,255,.22)" />
        <Ico name={tx.chipBIco} x={354} y={86} size={15} color={CE.sun} />
        <text x="367" y="90.5" fontSize="12" fontWeight="700" fill="#fff" letterSpacing=".1em">{tx.chipB}</text>
      </g>
    </Cena>
  );
}

/* ═══════════════ ENTREGADORES · o parceiro rodando ═══════════════ */
function predios(seed, alt, larg) {
  var out = [], x = 0, k = seed;
  while (x < 460) {
    k = (k * 9301 + 49297) % 233280;
    var w = larg[0] + (k % (larg[1] - larg[0]));
    var h = alt[0] + ((k >> 3) % (alt[1] - alt[0]));
    out.push([x, w, h]);
    x += w + 4;
  }
  return out;
}
var CE_PREDIOS_LONGE = predios(7, [40, 110], [26, 52]);
var CE_PREDIOS_PERTO = predios(3, [30, 80], [34, 62]);

function Skyline({ lista, base, cor, janelas, classe }) {
  var faixa = function(dx) {
    return lista.map(function(p, i) {
      var x = p[0] + dx, h = p[2];
      return (
        <g key={dx + '-' + i}>
          <rect x={x} y={base - h} width={p[1]} height={h} fill={cor} />
          {janelas && [0, 1, 2].map(function(r) {
            return (i + r) % 3 === 0 && h > 40 + r * 14
              ? <rect key={r} x={x + 7} y={base - h + 10 + r * 14} width="6" height="6" rx="1" fill={CE.sun} opacity=".8" /> : null;
          })}
        </g>
      );
    });
  };
  return <g className={classe}>{faixa(0)}{faixa(460)}</g>;
}

function CenaEntregador({ fluida, carro }) {
  var tracos = [];
  for (var i = 0; i < 20; i++) tracos.push(i * 46);
  return (
    <Cena fluida={fluida} rotulo="Animação: entregador parceiro rodando de moto pela cidade, com ganhos e novas corridas aparecendo"
      defs={<linearGradient id="ce-ent-ceu" x1="0" y1="0" x2="0" y2="1">
        <stop offset="0" stopColor={CE.blue900} /><stop offset=".55" stopColor={CE.blue} /><stop offset="1" stopColor={CE.rust} />
      </linearGradient>}>
      <rect width="460" height="360" fill="url(#ce-ent-ceu)" />
      <circle className="ce-sol" cx="330" cy="190" r="74" fill={CE.sun} />
      <circle cx="330" cy="190" r="104" fill={CE.sun} opacity=".18" />
      <Skyline lista={CE_PREDIOS_LONGE} base={252} cor={CE.blue800} classe="ce-desliza-3" />
      <Skyline lista={CE_PREDIOS_PERTO} base={252} cor={CE.blue900} janelas classe="ce-desliza-2" />

      {/* pista */}
      <rect y="250" width="460" height="110" fill={CE.n900} />
      <rect y="250" width="460" height="4" fill={CE.sun} />
      <g className="ce-desliza-r">
        {tracos.map(function(x) { return <rect key={x} x={x} y="318" width="24" height="5" rx="2.5" fill="rgba(255,255,255,.35)" />; })}
      </g>

      {/* linhas de velocidade */}
      <g stroke="#fff" strokeLinecap="round" opacity=".5">
        {[[96, 236, 40], [70, 262, 56], [104, 284, 30]].map(function(l, k) {
          return <line key={k} x1={l[0]} x2={l[0] + l[2]} y1={l[1]} y2={l[1]} strokeWidth="2" strokeDasharray={l[2] + ' 200'}>
            <animate attributeName="stroke-dashoffset" values={l[2] + ';-' + (l[2] + 20)} dur={(0.8 + k * 0.2) + 's'} repeatCount="indefinite" />
          </line>;
        })}
      </g>

      {/* a moto oficial da Cerrado (render do app), balançando na pista */}
      <g transform="translate(232 292)">
        <ellipse cx="0" cy="18" rx="86" ry="7" fill="#000" opacity=".35" />
        <polygon points="70,-40 170,-62 170,-6" fill="#FFF5D6" opacity=".12" />
        <g className="ce-sacode">
          <image href={ceAsset('assets/veiculos/' + (carro ? 'car.png' : 'moto-bag.png'))}
            x={carro ? -120 : -88} y={carro ? -86 : -128} width={carro ? 240 : 176} height={carro ? 108 : 146} />
        </g>
      </g>

      {/* ganhos subindo */}
      {[[300, 122, 0], [356, 150, 1.2], [262, 92, 2.4]].map(function(g, k) {
        return (
          <g key={k} transform={'translate(' + g[0] + ' ' + g[1] + ')'}>
            <g className="ce-sobe" style={{ '--ce-d': g[2] + 's' }}>
              <rect x="-44" y="-15" width="88" height="30" rx="15" fill={CE.success} />
              <text x="0" y="5" textAnchor="middle" fontSize="14" fontWeight="800" fill="#fff">+ R$ {['12,50', '9,80', '15,20'][k]}</text>
            </g>
          </g>
        );
      })}

      <Toast x={22} y={22} w={200} titulo="NOVA CORRIDA" sub="2,4 km · Setor Bueno" cor={CE.sun} icone="bolt" d={0.8} ciclo={6} />
    </Cena>
  );
}

/* ═══════════════ CONSULTORIA · do achismo ao número ═══════════════ */
function CenaGestao() {
  var TEAL = '#0F5F6B', TEAL_D = '#0A4049';
  var hs = [52, 78, 70, 104, 122, 146, 172];
  var soltos = [[-30, -150], [90, -40], [-60, 20], [40, -110], [-130, -30], [-70, -60], [-160, 40]];
  var topos = hs.map(function(h, i) { return [74 + i * 50 + 13, 286 - h]; });
  var linha = 'M' + topos.map(function(p) { return p[0] + ' ' + p[1]; }).join(' L');
  return (
    <Cena rotulo="Animação: pontos soltos (achismo) se organizam em um gráfico de indicadores com tendência de alta"
      defs={<linearGradient id="ce-ges-bg" x1="0" y1="0" x2="1" y2="1">
        <stop offset="0" stopColor={TEAL_D} /><stop offset="1" stopColor={TEAL} />
      </linearGradient>}>
      <rect width="460" height="360" fill="url(#ce-ges-bg)" />

      {/* rótulos de fase */}
      <g transform="translate(30 52)">
        <g className="ce-fase-a">
          <text fontSize="26" fontWeight="800" fill={CE.sun} letterSpacing=".02em">ACHISMO</text>
          <text y="20" className="ce-t-body" fontSize="11.5" fill="rgba(255,255,255,.7)">cada um com sua planilha</text>
        </g>
        <g className="ce-fase-b">
          <text fontSize="26" fontWeight="800" fill="#fff" letterSpacing=".02em">INDICADORES</text>
          <text y="20" className="ce-t-body" fontSize="11.5" fill="rgba(255,255,255,.7)">decisão com número</text>
        </g>
      </g>
      <g className="ce-fase-b" transform="translate(316 30)">
        <rect width="118" height="40" rx="12" fill={CE.sun} />
        <Ico name="trending" x={22} y={20} size={17} color="#3D1303" sw={2.5} />
        <text x="38" y="25" fontSize="15" fontWeight="800" fill="#3D1303">+23% margem</text>
      </g>

      {/* área do gráfico */}
      <rect x="30" y="92" width="400" height="234" rx="16" fill="rgba(255,255,255,.06)" stroke="rgba(255,255,255,.12)" />
      {[140, 190, 240].map(function(y) { return <line key={y} x1="50" x2="410" y1={y} y2={y} stroke="rgba(255,255,255,.08)" strokeDasharray="4 6" />; })}
      <line x1="50" x2="410" y1="286" y2="286" stroke="rgba(255,255,255,.3)" />

      {/* interrogações do caos */}
      <g className="ce-fase-a" fill="rgba(255,255,255,.28)" fontWeight="800">
        <text x="120" y="160" fontSize="30">?</text><text x="300" y="200" fontSize="22">?</text>
        <text x="220" y="130" fontSize="18">?</text><text x="370" y="150" fontSize="26">?</text>
      </g>

      {hs.map(function(h, i) {
        return <rect key={i} className="ce-cresce" x={74 + i * 50} y={286 - h} width="26" height={h} rx="5"
          fill={i === hs.length - 1 ? CE.sun : 'rgba(255,255,255,.85)'} style={{ animationDelay: (i * 0.06) + 's' }} />;
      })}
      <path d={linha} pathLength="1" className="ce-linha-ciclo" fill="none" stroke={CE.sun} strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" />
      {topos.map(function(p, i) {
        return <circle key={i} className="ce-ponto" cx={p[0]} cy={p[1]} r="6.5" fill={CE.sun} stroke={TEAL_D} strokeWidth="2"
          style={{ '--sx': soltos[i][0] + 'px', '--sy': soltos[i][1] * -0.6 + 'px', animationDelay: (i * 0.04) + 's' }} />;
      })}
    </Cena>
  );
}

/* ═══════════════ Painel de KPIs (reutilizável) ═══════════════ */
function CenaPainel({ cor, titulo, fluida, rotulo, kpis }) {
  var c = cor || CE.blue;
  var k = kpis || [['87%', 'no prazo', 13], ['R$ 4,20', 'custo/entrega', 38], ['-18%', 'desperdício', 55]];
  var pts = [[40, 300], [70, 286], [100, 292], [130, 268], [160, 274], [190, 248], [220, 252], [250, 226], [280, 214]];
  var linha = 'M' + pts.map(function(p) { return p[0] + ' ' + p[1]; }).join(' L');
  var area = linha + ' L280 318 L40 318 Z';
  var horiz = [['Goiânia', 0.92], ['Anápolis', 0.74], ['Rio Verde', 0.6], ['Jataí', 0.44]];
  return (
    <Cena fluida={fluida} rotulo={rotulo || 'Animação: painel de indicadores com gráficos atualizando ao vivo'}
      defs={<linearGradient id={'ce-pnl-area-' + c.slice(1)} x1="0" y1="0" x2="0" y2="1">
        <stop offset="0" stopColor={c} stopOpacity=".55" /><stop offset="1" stopColor={c} stopOpacity="0" />
      </linearGradient>}>
      <rect width="460" height="360" fill={CE.n900} />
      <circle className="ce-sol" cx="440" cy="-10" r="130" fill={c} opacity=".25" />
      <text x="24" y="38" fontSize="13" fontWeight="800" fill="#fff" letterSpacing=".14em">{titulo || 'PAINEL DE INDICADORES'}</text>
      <circle className="ce-pisca" cx="392" cy="33" r="4" fill={CE.success} />
      <text x="402" y="37.5" fontSize="10.5" fontWeight="800" fill={CE.success} letterSpacing=".1em">AO VIVO</text>

      {k.map(function(kp, i) {
        var x = 24 + i * 142;
        return (
          <g key={kp[1]} transform={'translate(' + x + ' 56)'}>
            <rect width="130" height="84" rx="12" fill="rgba(255,255,255,.06)" stroke="rgba(255,255,255,.1)" />
            <circle cx="36" cy="42" r="21" fill="none" stroke="rgba(255,255,255,.1)" strokeWidth="6" />
            <circle cx="36" cy="42" r="21" fill="none" stroke={i === 0 ? CE.sun : c === CE.n800 ? CE.sun : c} strokeWidth="6"
              strokeLinecap="round" pathLength="100" className="ce-anel-prog" transform="rotate(-90 36 42)"
              style={{ '--ce-alvo': kp[2], '--ce-d': (0.4 + i * 0.2) + 's' }} />
            <text x="68" y="42" fontSize="17" fontWeight="800" fontStyle="italic" fill="#fff">{kp[0]}</text>
            <text x="68" y="57" className="ce-t-body" fontSize="9.5" fill={CE.n400}>{kp[1]}</text>
          </g>
        );
      })}

      {/* gráfico de linha */}
      <g>
        <rect x="24" y="156" width="272" height="180" rx="12" fill="rgba(255,255,255,.04)" stroke="rgba(255,255,255,.08)" />
        <text x="40" y="180" fontSize="10.5" fontWeight="700" fill={CE.n400} letterSpacing=".12em">EVOLUÇÃO · 9 SEMANAS</text>
        {[220, 260, 300].map(function(y) { return <line key={y} x1="40" x2="280" y1={y} y2={y} stroke="rgba(255,255,255,.06)" />; })}
        <path d={area} fill={'url(#ce-pnl-area-' + c.slice(1) + ')'} opacity=".9" />
        <path id={'ce-pnl-linha-' + c.slice(1)} d={linha} pathLength="1" className="ce-desenha" fill="none"
          stroke={c === CE.n800 ? CE.sun : c} strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" style={{ '--ce-d': '.6s', filter: 'brightness(1.5)' }} />
        <g>
          <animateMotion dur="5s" begin="0s" repeatCount="indefinite" keyPoints="0;1;1" keyTimes="0;.8;1" calcMode="linear">
            <mpath href={'#ce-pnl-linha-' + c.slice(1)} />
          </animateMotion>
          <circle r="9" fill={CE.sun} opacity=".25" />
          <circle r="4.5" fill={CE.sun} stroke="#fff" strokeWidth="2" />
        </g>
      </g>

      {/* ranking horizontal */}
      <g transform="translate(308 156)">
        <rect width="128" height="180" rx="12" fill="rgba(255,255,255,.04)" stroke="rgba(255,255,255,.08)" />
        <text x="14" y="24" fontSize="10.5" fontWeight="700" fill={CE.n400} letterSpacing=".12em">POR UNIDADE</text>
        {horiz.map(function(h, i) {
          return (
            <g key={h[0]} transform={'translate(14 ' + (46 + i * 34) + ')'}>
              <text className="ce-t-body" fontSize="9.5" fill={CE.n300}>{h[0]}</text>
              <rect y="7" width="100" height="7" rx="3.5" fill="rgba(255,255,255,.08)" />
              <rect className="ce-barra-h" y="7" width={100 * h[1]} height="7" rx="3.5" fill={i === 0 ? CE.sun : c === CE.n800 ? CE.n300 : c}
                style={{ '--ce-d': (0.8 + i * 0.15) + 's', filter: 'brightness(1.4)' }} />
            </g>
          );
        })}
      </g>
    </Cena>
  );
}

/* ═══════════════ ERP · o sistema rodando ═══════════════ */
function CenaErp() {
  var vendas = [34, 42, 38, 52, 48, 60, 56, 68, 64, 78, 74, 92];
  return (
    <Cena rotulo="Animação: tela do Cerrado ERP com faturamento, estoque, gráfico de vendas crescendo e NF-e autorizada"
      defs={<linearGradient id="ce-erp-bg" x1="0" y1="0" x2="1" y2="1">
        <stop offset="0" stopColor={CE.rust700} /><stop offset="1" stopColor={CE.rust} />
      </linearGradient>}>
      <rect width="460" height="360" fill="url(#ce-erp-bg)" />

      <g filter="url(#ce-sombra)">
        <rect x="18" y="22" width="424" height="318" rx="14" fill="#fff" />
      </g>
      {/* barra de título */}
      <path d="M18 36 a14 14 0 0 1 14 -14 h396 a14 14 0 0 1 14 14 v12 h-424 z" fill={CE.n100} />
      {[34, 48, 62].map(function(x, i) { return <circle key={x} cx={x} cy="35" r="4" fill={[CE.rust, CE.sun, CE.n300][i]} />; })}
      <text x="230" y="39" textAnchor="middle" fontSize="11" fontWeight="800" fill={CE.n600} letterSpacing=".12em">CERRADO ERP</text>

      {/* menu lateral com indicador que passeia */}
      <path d="M18 48 h56 v292 h-42 a14 14 0 0 1 -14 -14 z" fill={CE.n900} />
      <rect x="18" y="66" width="4" height="32" rx="2" fill={CE.sun}>
        <animateTransform attributeName="transform" type="translate" dur="10s" repeatCount="indefinite"
          values="0 0;0 0;0 44;0 44;0 88;0 88;0 132;0 132;0 0" keyTimes="0;.2;.25;.45;.5;.7;.75;.95;1" calcMode="spline"
          keySplines="0 0 1 1;.6 0 .2 1;0 0 1 1;.6 0 .2 1;0 0 1 1;.6 0 .2 1;0 0 1 1;.6 0 .2 1" />
      </rect>
      {['chart', 'package', 'building', 'truck', 'trending'].map(function(n, i) {
        return <Ico key={n} name={n} x={46} y={82 + i * 44} size={17} color={i === 0 ? '#fff' : CE.n400} />;
      })}

      {/* KPIs */}
      {[['FATURAMENTO', 'R$ 84,3 mil', '+12%'], ['ESTOQUE', '1.284 itens', 'ok'], ['NF-e HOJE', '312 notas', '+48']].map(function(k, i) {
        return (
          <g key={k[0]} transform={'translate(' + (88 + i * 116) + ' 62)'}>
            <rect width="106" height="62" rx="10" fill={CE.n50} stroke={CE.n200} />
            <text x="12" y="20" fontSize="9" fontWeight="800" fill={CE.n500} letterSpacing=".12em">{k[0]}</text>
            <text x="12" y="41" fontSize="15.5" fontWeight="800" fontStyle="italic" fill={CE.n900}>{k[1]}</text>
            <text x="12" y="54" className="ce-t-body" fontSize="8.5" fontWeight="700" fill={CE.success}>▲ {k[2]}</text>
          </g>
        );
      })}

      {/* gráfico de vendas */}
      <rect x="88" y="136" width="338" height="190" rx="10" fill={CE.n50} stroke={CE.n200} />
      <text x="102" y="158" fontSize="10" fontWeight="800" fill={CE.n500} letterSpacing=".12em">VENDAS · ÚLTIMOS 12 MESES</text>
      {[200, 240, 280].map(function(y) { return <line key={y} x1="102" x2="412" y1={y} y2={y} stroke={CE.n200} strokeDasharray="3 5" />; })}
      {vendas.map(function(v, i) {
        return <rect key={i} className="ce-barra" x={106 + i * 25.5} y={310 - v * 1.3} width="16" height={v * 1.3} rx="3"
          fill={i === vendas.length - 1 ? CE.sun : CE.rust}
          style={{ '--ce-d': (0.5 + i * 0.07).toFixed(2) + 's', '--ce-v': (0.82 + (i % 3) * 0.05).toFixed(2) }} />;
      })}
      <path d={'M' + vendas.map(function(v, i) { return (114 + i * 25.5) + ' ' + (300 - v * 1.3); }).join(' L')}
        pathLength="1" className="ce-desenha" fill="none" stroke={CE.blue} strokeWidth="2.5" strokeLinecap="round"
        strokeLinejoin="round" style={{ '--ce-d': '1.4s' }} />

      <Toast x={238} y={170} w={184} titulo="NF-e AUTORIZADA" sub="SEFAZ-GO · em 0,8 segundo" className="ce-toast-dir" d={2.4} ciclo={6} />
    </Cena>
  );
}

/* ═══════════════ LEX · contrato, assinatura, carimbo ═══════════════ */
function CenaLex() {
  var T = '7s';
  var linhas = [150, 128, 156, 140, 96, 150, 120, 146, 84];
  return (
    <Cena rotulo="Animação: contrato sendo escrito, assinado e carimbado, com alerta de prazo e selo de segurança"
      defs={<radialGradient id="ce-lex-glow" cx=".8" cy=".15" r=".9">
        <stop offset="0" stopColor={CE.blue} stopOpacity=".9" /><stop offset=".7" stopColor={CE.blue} stopOpacity="0" />
      </radialGradient>}>
      <rect width="460" height="360" fill={CE.n950} />
      <rect width="460" height="360" fill="url(#ce-lex-glow)" />

      {/* documento */}
      <g transform="rotate(-3 230 180)">
        <rect x="128" y="26" width="206" height="306" rx="10" fill="#fff" filter="url(#ce-sombra)" />
        <rect x="128" y="26" width="206" height="8" rx="4" fill={CE.blue} />
        <text x="146" y="60" fontSize="10.5" fontWeight="800" fill={CE.n900} letterSpacing=".06em">CONTRATO DE PRESTAÇÃO</text>
        <text x="146" y="73" fontSize="10.5" fontWeight="800" fill={CE.n900} letterSpacing=".06em">DE SERVIÇOS · Nº 0427</text>
        {/* cláusula destacada */}
        <rect x="142" y="134" width="176" height="24" rx="4" fill={CE.sun} opacity="0">
          <animate attributeName="opacity" values="0;0;.28;.28;0" keyTimes="0;.3;.34;.92;1" dur={T} repeatCount="indefinite" />
        </rect>
        {linhas.map(function(w, i) {
          var s = (0.03 + i * 0.03).toFixed(2), e = (0.07 + i * 0.03).toFixed(2);
          return (
            <rect key={i} x="146" y={90 + i * 16} width="0" height="5.5" rx="2.75" fill={i === 3 || i === 4 ? CE.n400 : CE.n200}>
              <animate attributeName="width" values={'0;0;' + w + ';' + w + ';' + w} keyTimes={'0;' + s + ';' + e + ';.94;1'} dur={T} repeatCount="indefinite" />
              <animate attributeName="opacity" values="1;1;0" keyTimes="0;.94;1" dur={T} repeatCount="indefinite" />
            </rect>
          );
        })}
        <line x1="146" x2="270" y1="304" y2="304" stroke={CE.n300} />
        <text x="146" y="318" className="ce-t-body" fontSize="8.5" fill={CE.n500}>Papel timbrado do escritório</text>
        <path d="M150 296 c8 -18 16 -22 18 -9 s-6 16 2 9 s12 -24 20 -16 s-4 20 6 12 s14 -18 22 -9 s8 7 24 -5 s10 -4 18 2"
          pathLength="1" fill="none" stroke={CE.blue900} strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round"
          strokeDasharray="1" strokeDashoffset="1">
          <animate attributeName="stroke-dashoffset" values="1;1;0;0;0" keyTimes="0;.38;.56;.94;1" dur={T} repeatCount="indefinite" />
          <animate attributeName="opacity" values="1;1;0" keyTimes="0;.94;1" dur={T} repeatCount="indefinite" />
        </path>
        {/* carimbo */}
        <g transform="translate(286 246)">
          <g opacity="0">
            <animate attributeName="opacity" values="0;0;1;1;0" keyTimes="0;.6;.64;.94;1" dur={T} repeatCount="indefinite" />
            <animateTransform attributeName="transform" type="scale" values="1.9;1.9;.94;1;1;1" keyTimes="0;.6;.64;.67;.94;1" dur={T} repeatCount="indefinite" />
            <g transform="rotate(-12)">
              <circle r="34" fill="rgba(31,138,91,.08)" stroke={CE.success} strokeWidth="3" />
              <circle r="27" fill="none" stroke={CE.success} strokeWidth="1" strokeDasharray="3 3" />
              <Ico name="check" x={0} y={-8} size={18} color={CE.success} sw={3} />
              <text y="13" textAnchor="middle" fontSize="10" fontWeight="800" fill={CE.success} letterSpacing=".1em">ASSINADO</text>
            </g>
          </g>
        </g>
      </g>

      {/* prazo */}
      <g className="ce-flutua">
        <rect x="22" y="58" width="96" height="92" rx="14" fill="#fff" filter="url(#ce-sombra)" />
        <rect x="22" y="58" width="96" height="26" rx="13" fill={CE.rust} />
        <rect x="22" y="72" width="96" height="12" fill={CE.rust} />
        <text x="70" y="76" textAnchor="middle" fontSize="10.5" fontWeight="800" fill="#fff" letterSpacing=".14em">PRAZO</text>
        <text x="70" y="118" textAnchor="middle" fontSize="30" fontWeight="800" fontStyle="italic" fill={CE.n900}>12</text>
        <text x="70" y="137" textAnchor="middle" fontSize="10" fontWeight="700" fill={CE.n500} letterSpacing=".14em">OUTUBRO</text>
        <g className="ce-sino">
          <circle cx="112" cy="62" r="13" fill={CE.sun} stroke={CE.n950} strokeWidth="2" />
          <Ico name="bell" x={112} y={62} size={13} color="#3D1303" sw={2.4} />
        </g>
      </g>

      {/* segurança */}
      <g className="ce-flutua-2">
        <rect x="344" y="204" width="98" height="96" rx="14" fill="rgba(255,255,255,.08)" stroke="rgba(255,255,255,.18)" />
        <circle className="ce-gira ce-fb" cx="393" cy="240" r="22" fill="none" stroke={CE.sun} strokeWidth="1.5" strokeDasharray="3 6" />
        <Ico name="shield" x={393} y={240} size={22} color={CE.sun} />
        <text x="393" y="279" textAnchor="middle" fontSize="11" fontWeight="800" fill="#fff" letterSpacing=".06em">100% EM DIA</text>
        <text x="393" y="292" textAnchor="middle" className="ce-t-body" fontSize="8.5" fill={CE.n400}>prazos</text>
      </g>
    </Cena>
  );
}

/* ═══════════════ GRUPO · o ecossistema ═══════════════ */
function CenaEcossistema({ fluida }) {
  var divs = window.CE_DIVISIONS || [];
  var C = { x: 230, y: 184 }, R = 128;
  var nos = divs.map(function(d, i) {
    var a = (-90 + i * (360 / divs.length)) * Math.PI / 180;
    return { d: d, x: C.x + Math.cos(a) * R, y: C.y + Math.sin(a) * R * 0.86 };
  });
  return (
    <Cena fluida={fluida} rotulo="Animação: as cinco empresas do Grupo Cerrado conectadas ao mesmo centro, trocando informação"
      defs={<linearGradient id="ce-eco-bg" x1="0" y1="0" x2="1" y2="1">
        <stop offset="0" stopColor={CE.blue900} /><stop offset="1" stopColor={CE.blue} />
      </linearGradient>}>
      <rect width="460" height="360" fill="url(#ce-eco-bg)" />
      <circle className="ce-sol" cx="230" cy="184" r="150" fill={CE.sun} opacity=".1" />
      <ellipse className="ce-gira ce-fb" cx={C.x} cy={C.y} rx={R} ry={R * 0.86} fill="none" stroke="rgba(255,255,255,.18)" strokeDasharray="2 8" />
      <circle className="ce-gira-rev ce-fb" cx={C.x} cy={C.y} r="72" fill="none" stroke={CE.sun} strokeOpacity=".35" strokeDasharray="10 14" />

      {nos.map(function(n, i) {
        var d = 'M' + C.x + ' ' + C.y + ' L' + n.x.toFixed(1) + ' ' + n.y.toFixed(1);
        return (
          <g key={'l' + n.d.key}>
            <path id={'ce-eco-' + i} d={d} stroke="rgba(255,255,255,.2)" strokeWidth="1.5" />
            {[0, 1].map(function(k) {
              return (
                <circle key={k} r="3" fill={k ? '#fff' : CE.sun}>
                  <animateMotion dur="2.4s" begin={(-(i * 0.35 + k * 1.2)) + 's'} repeatCount="indefinite"
                    keyPoints={k ? '1;0' : '0;1'} keyTimes="0;1" calcMode="linear"><mpath href={'#ce-eco-' + i} /></animateMotion>
                </circle>
              );
            })}
          </g>
        );
      })}

      {/* centro */}
      <circle className="ce-onda ce-fb" cx={C.x} cy={C.y} r="40" fill="none" stroke={CE.sun} strokeWidth="2" />
      <circle cx={C.x} cy={C.y} r="40" fill={CE.sun} />
      <image href={ceAsset('assets/symbol-white.png')} x={C.x - 24} y={C.y - 24} width="48" height="48" />

      {nos.map(function(n, i) {
        return (
          <g key={n.d.key} className={i % 2 ? 'ce-flutua' : 'ce-flutua-2'} style={{ animationDelay: (i * 0.4) + 's' }}>
            <circle cx={n.x} cy={n.y} r="25" fill={n.d.cor} stroke="rgba(255,255,255,.55)" strokeWidth="2" />
            <Ico name={n.d.icon} x={n.x} y={n.y} size={20} />
            <rect x={n.x - 42} y={n.y + 30} width="84" height="19" rx="9.5" fill="rgba(12,14,18,.55)" />
            <text x={n.x} y={n.y + 43.5} textAnchor="middle" fontSize="10.5" fontWeight="800" fill="#fff" letterSpacing=".1em">
              {n.d.display.toUpperCase()}
            </text>
          </g>
        );
      })}
    </Cena>
  );
}

/* ═══════════════ Rede de rotas ao fundo ═══════════════ */
function RedeFundo({ cor, opacidade }) {
  var c = cor || '#fff';
  var curvas = [
    'M-20 420 C 200 300, 360 360, 560 220 S 900 120, 1220 160',
    'M-20 120 C 180 200, 420 80, 640 180 S 980 380, 1220 300',
    'M100 620 C 260 420, 520 520, 700 380 S 1000 260, 1220 420',
    'M300 -20 C 380 160, 560 200, 760 120 S 1060 40, 1220 90',
  ];
  return (
    <svg className="ce-rede" viewBox="0 0 1200 600" preserveAspectRatio="xMidYMid slice" aria-hidden="true"
      style={{ opacity: opacidade == null ? 0.5 : opacidade }}>
      {curvas.map(function(d, i) {
        return (
          <g key={i}>
            <path id={'ce-rede-' + i} d={d} fill="none" stroke={c} strokeOpacity=".16" strokeWidth="1.5" strokeDasharray="4 12"
              className="ce-tracejado-anda" />
            <circle r="3.5" fill={CE.sun}>
              <animateMotion dur={(9 + i * 2.5) + 's'} begin={(-i * 1.3) + 's'} repeatCount="indefinite"><mpath href={'#ce-rede-' + i} /></animateMotion>
            </circle>
          </g>
        );
      })}
      {[[560, 220], [640, 180], [760, 120], [700, 380]].map(function(p, i) {
        return (
          <g key={i}>
            <circle className="ce-onda ce-fb" cx={p[0]} cy={p[1]} r="6" fill="none" stroke={CE.sun} strokeWidth="1.5" style={{ animationDelay: (i * 0.6) + 's' }} />
            <circle cx={p[0]} cy={p[1]} r="3" fill={c} fillOpacity=".6" />
          </g>
        );
      })}
    </svg>
  );
}

/* ═══════════════ Veículo cruzando o pé do CTA ═══════════════ */
function EstradaCTA({ veiculo }) {
  var moto = veiculo === 'moto';
  return (
    <div className="ce-estrada" aria-hidden="true">
      <div style={{ position: 'absolute', left: 0, right: 0, bottom: 8, borderTop: '2px dashed rgba(255,255,255,.14)' }} />
      <div className="ce-estrada-veiculo">
        <img src={ceAsset('assets/veiculos/' + (moto ? 'moto-bag.png' : 'car.png'))} alt=""
          style={{ height: moto ? 58 : 44, display: 'block', filter: 'drop-shadow(0 6px 8px rgba(0,0,0,.35))' }} />
      </div>
    </div>
  );
}

/* ═══════════════ Código de rastreio sendo digitado ═══════════════ */
function Digitando({ textos, cor }) {
  var lista = textos || ['CE-2506-0042-BR'];
  var st = React.useState({ i: 0, n: 0, apagando: false }), s = st[0], set = st[1];
  var parado = React.useMemo(function() {
    try { return window.matchMedia('(prefers-reduced-motion: reduce)').matches; } catch (e) { return false; }
  }, []);
  React.useEffect(function() {
    if (parado) return;
    var alvo = lista[s.i];
    var espera = s.apagando ? 35 : 95;
    if (!s.apagando && s.n === alvo.length) espera = 2200;
    if (s.apagando && s.n === 0) espera = 400;
    var t = setTimeout(function() {
      if (!s.apagando && s.n === alvo.length) set({ i: s.i, n: s.n, apagando: true });
      else if (s.apagando && s.n === 0) set({ i: (s.i + 1) % lista.length, n: 0, apagando: false });
      else set({ i: s.i, n: s.n + (s.apagando ? -1 : 1), apagando: s.apagando });
    }, espera);
    return function() { clearTimeout(t); };
  }, [s, parado]);
  var txt = parado ? lista[0] : lista[s.i].slice(0, s.n);
  return <span style={{ color: cor }}>{txt}<span className="ce-caret" aria-hidden="true" /></span>;
}

/* ═══════════════ ABERTURA · a entrada do Grupo Cerrado ═══════════════
   Inspirada na abertura do Dropbox Brand: linhas de grade cruzam a tela e
   fecham um quadro no centro; dentro dele o sol do Cerrado se desenha em
   traço e ganha cor sobre o horizonte; a marca sobe; por fim o quadro
   “voa” até o logo do cabeçalho enquanto a cortina some (técnica FLIP).
   Só na primeira visita da sessão — o <head> da home marca
   html.ce-com-abertura antes do React. Clique pula. */
function AberturaGrupo() {
  var ativa = typeof document !== 'undefined' && document.documentElement.classList.contains('ce-com-abertura');
  var st = React.useState(ativa ? 'ini' : 'fim'), fase = st[0], setFase = st[1];
  var quadro = React.useRef(null), sol = React.useRef(null);
  var S = Math.round(Math.min(window.innerWidth * 0.62, window.innerHeight * 0.5, 380));

  React.useEffect(function() {
    if (fase === 'fim') return;
    var r1 = requestAnimationFrame(function() { r1 = requestAnimationFrame(function() { setFase('on'); }); });
    var t1 = setTimeout(function() { voar(); setFase('sai'); }, 2400);
    var t2 = setTimeout(function() { setFase('fim'); }, 3500);
    return function() { cancelAnimationFrame(r1); clearTimeout(t1); clearTimeout(t2); };
  }, []);

  function voar() {
    var q = quadro.current, s = sol.current, logo = document.querySelector('header img');
    if (!q || !s || !logo) return;
    var rq = q.getBoundingClientRect(), rs = s.getBoundingClientRect(), rl = logo.getBoundingClientRect();
    var esc = rl.height / rs.height;
    // o centro do sol pousa no centro do símbolo do logo
    var dx = (rl.left + rl.width / 2) - (rq.left + (rs.left - rq.left + rs.width / 2) * esc);
    var dy = (rl.top + rl.height / 2) - (rq.top + (rs.top - rq.top + rs.height / 2) * esc);
    q.style.transform = 'translate(' + dx.toFixed(1) + 'px,' + dy.toFixed(1) + 'px) scale(' + esc.toFixed(4) + ')';
  }

  if (fase === 'fim') return null;
  var meio = 'calc(50% - ' + (S / 2) + 'px)', fim = 'calc(50% + ' + (S / 2) + 'px)';
  var raios = [-80, -55, -30, 0, 30, 55, 80];
  return (
    <div className={'ce-ab2' + (fase !== 'ini' ? ' ce-ab2-on' : '') + (fase === 'sai' ? ' ce-ab2-sai' : '')}
      aria-hidden="true" onClick={function() { setFase('fim'); }}>
      <i className="ln v a" style={{ left: meio }} /><i className="ln v b" style={{ left: fim }} />
      <i className="ln h a" style={{ top: meio }} /><i className="ln h b" style={{ top: fim }} />
      <div ref={quadro} className="ce-ab2-quadro" style={{ left: meio, top: meio, width: S, height: S }}>
        <svg ref={sol} className="ce-ab2-sol" viewBox="0 0 200 120" width={S * 0.62} height={S * 0.62 * 0.6} style={{ overflow: 'visible' }}>
          <defs><clipPath id="ce-ab2-ceu"><rect x="-60" y="-80" width="320" height="180" /></clipPath></defs>
          <g clipPath="url(#ce-ab2-ceu)">
            {raios.map(function(a, i) {
              var rad = (a - 90) * Math.PI / 180;
              return <line key={a} className="ce-ab2-raio" x1={100 + Math.cos(rad) * 60} y1={100 + Math.sin(rad) * 60}
                x2={100 + Math.cos(rad) * 78} y2={100 + Math.sin(rad) * 78} style={{ animationDelay: (1.5 + i * 0.05) + 's' }} />;
            })}
            <circle className="ce-ab2-traco" cx="100" cy="100" r="48" pathLength="1" transform="rotate(180 100 100)" />
          </g>
          <line className="ce-ab2-horiz" x1="0" x2="200" y1="100" y2="100" pathLength="1" />
        </svg>
        <div className="ce-ab2-nome">
          <span><b style={{ animationDelay: '1.25s' }}>Grupo</b></span>
          <span><b style={{ animationDelay: '1.38s' }}>Cerrado</b></span>
        </div>
      </div>
    </div>
  );
}

/* a frota passando no horizonte do herói */
function CaravanaHorizonte() {
  // só veículos de perfil: o caminhão é renderizado de 3/4 e destoa andando de lado
  var v = [['moto-bag.png', 46, 19, 0], ['car.png', 40, 26, -11], ['moto-carretinha.png', 44, 30, -4]];
  return (
    <div className="ce-caravana" aria-hidden="true">
      {v.map(function(x, i) {
        return <img key={i} src={ceAsset('assets/veiculos/' + x[0])} alt=""
          style={{ height: x[1], animationDuration: x[2] + 's', animationDelay: x[3] + 's' }} />;
      })}
    </div>
  );
}

/* sol nascendo no horizonte do herói da home */
function HorizonteSol() {
  return (
    <div className="ce-horizonte" aria-hidden="true">
      <div className="ce-horizonte-raios" />
      <div className="ce-horizonte-sol" />
      <div className="ce-horizonte-linha" />
    </div>
  );
}

/* ═══════════════ PARCEIRO COMERCIAL · a rede que gera comissão ═══════════════ */
function CenaParceiro() {
  var V = { x: 230, y: 140 };
  var esq = [[62, 64], [62, 140], [62, 216]], dir = [[398, 64], [398, 140], [398, 216]];
  var pares = esq.map(function(e, i) {
    var d = dir[(i + 1) % 3];
    return 'M' + e[0] + ' ' + e[1] + ' Q' + ((e[0] + V.x) / 2) + ' ' + e[1] + ' ' + V.x + ' ' + V.y +
      ' Q' + ((d[0] + V.x) / 2) + ' ' + d[1] + ' ' + d[0] + ' ' + d[1];
  });
  var barras = [22, 28, 26, 34, 38, 44, 52];
  return (
    <Cena rotulo="Animação: o parceiro comercial conecta empresas e entregadores e recebe comissão a cada entrega"
      defs={<linearGradient id="ce-par-bg" x1="0" y1="0" x2="1" y2="1">
        <stop offset="0" stopColor={CE.blue900} /><stop offset="1" stopColor={CE.blue} />
      </linearGradient>}>
      <rect width="460" height="360" fill="url(#ce-par-bg)" />
      <text x="62" y="28" textAnchor="middle" fontSize="10" fontWeight="800" fill="rgba(255,255,255,.6)" letterSpacing=".14em">EMPRESAS</text>
      <text x="398" y="28" textAnchor="middle" fontSize="10" fontWeight="800" fill="rgba(255,255,255,.6)" letterSpacing=".14em">ENTREGADORES</text>

      {pares.map(function(d, i) {
        return (
          <g key={i}>
            <path id={'ce-par-' + i} d={d} fill="none" stroke="rgba(255,255,255,.18)" strokeWidth="1.5" strokeDasharray="4 6" className="ce-tracejado-anda" />
            <g>
              <animateMotion dur="3.6s" begin={(-i * 1.2) + 's'} repeatCount="indefinite"><mpath href={'#ce-par-' + i} /></animateMotion>
              <rect x="-6" y="-6" width="12" height="12" rx="2.5" fill={CE.sun} stroke="#fff" strokeWidth="1.2" />
            </g>
          </g>
        );
      })}

      {esq.map(function(p, i) {
        return (
          <g key={'e' + i} className={i % 2 ? 'ce-flutua' : 'ce-flutua-2'}>
            <circle cx={p[0]} cy={p[1]} r="22" fill={CE.blue700} stroke="rgba(255,255,255,.3)" strokeWidth="1.5" />
            <Ico name="building" x={p[0]} y={p[1]} size={18} />
          </g>
        );
      })}
      {dir.map(function(p, i) {
        return (
          <g key={'d' + i} className={i % 2 ? 'ce-flutua-2' : 'ce-flutua'}>
            <circle cx={p[0]} cy={p[1]} r="22" fill={CE.blue700} stroke="rgba(255,255,255,.3)" strokeWidth="1.5" />
            <Ico name={i === 1 ? 'pin' : 'truck'} x={p[0]} y={p[1]} size={18} />
          </g>
        );
      })}

      {/* você no centro */}
      <circle className="ce-onda ce-fb" cx={V.x} cy={V.y} r="30" fill="none" stroke={CE.sun} strokeWidth="2" />
      <circle cx={V.x} cy={V.y} r="32" fill={CE.sun} />
      <Ico name="userplus" x={V.x} y={V.y - 2} size={22} color="#3D1303" sw={2.4} />
      <rect x={V.x - 30} y={V.y + 40} width="60" height="20" rx="10" fill="#fff" />
      <text x={V.x} y={V.y + 54} textAnchor="middle" fontSize="11" fontWeight="800" fill={CE.blue900} letterSpacing=".12em">VOCÊ</text>

      {[[-46, 0], [40, 1.2], [-6, 2.4]].map(function(c, k) {
        return (
          <g key={k} transform={'translate(' + (V.x + c[0]) + ' ' + (V.y - 46) + ')'}>
            <g className="ce-sobe" style={{ '--ce-d': c[1] + 's' }}>
              <rect x="-34" y="-12" width="68" height="24" rx="12" fill={CE.success} />
              <text x="0" y="4.5" textAnchor="middle" fontSize="12" fontWeight="800" fill="#fff">+ R$ {['1,20', '0,90', '1,50'][k]}</text>
            </g>
          </g>
        );
      })}

      {/* comissão do mês */}
      <g transform="translate(110 252)">
        <rect width="240" height="86" rx="14" fill="#fff" filter="url(#ce-sombra)" />
        <text x="16" y="24" fontSize="10" fontWeight="800" fill={CE.n500} letterSpacing=".14em">SUA COMISSÃO NO MÊS</text>
        <text x="16" y="56" fontSize="26" fontWeight="800" fontStyle="italic" fill={CE.success}>R$ 3.480</text>
        <text x="16" y="74" className="ce-t-body" fontSize="9.5" fill={CE.n500}>12 empresas · 2.900 entregas</text>
        {barras.map(function(h, i) {
          return <rect key={i} className="ce-barra" x={152 + i * 11} y={72 - h} width="7" height={h} rx="2"
            fill={i === barras.length - 1 ? CE.sun : CE.blue}
            style={{ '--ce-d': (0.5 + i * 0.08).toFixed(2) + 's', '--ce-v': (0.75 + (i % 3) * 0.08).toFixed(2) }} />;
        })}
      </g>
    </Cena>
  );
}

/* ═══════════════ ENERGIAS · sol → painel → casa ═══════════════ */
function CenaEnergia() {
  var VERDE = '#16A34A', VERDE_D = '#0E6B30';
  var CABO = 'M300 196 C 300 236, 252 246, 214 262 S 150 288, 120 300';
  return (
    <Cena rotulo="Animação: o sol gera energia nos painéis do telhado, a energia corre até o medidor e a conta de luz cai"
      defs={<>
        <linearGradient id="ce-ene-ceu" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0" stopColor="#0B3B22" /><stop offset=".7" stopColor={VERDE_D} /><stop offset="1" stopColor={VERDE} />
        </linearGradient>
        <linearGradient id="ce-ene-brilho" x1="0" y1="0" x2="1" y2="0">
          <stop offset="0" stopColor="#fff" stopOpacity="0" /><stop offset=".5" stopColor="#fff" stopOpacity=".55" /><stop offset="1" stopColor="#fff" stopOpacity="0" />
        </linearGradient>
        <clipPath id="ce-ene-painel"><polygon points="232,150 352,150 372,192 252,192" /></clipPath>
      </>}>
      <rect width="460" height="360" fill="url(#ce-ene-ceu)" />
      {/* sol com raios */}
      <g className="ce-gira ce-fb">
        {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map(function(i) {
          return <rect key={i} x="98" y="2" width="5" height="26" rx="2.5" fill={CE.sun} opacity=".55" transform={'rotate(' + (i * 30) + ' 100 78)'} />;
        })}
      </g>
      <circle className="ce-pulsa" cx="100" cy="78" r="40" fill={CE.sun} />
      {/* raios de luz até o painel */}
      {[0, 1, 2].map(function(i) {
        return <line key={i} x1={128 + i * 6} y1={104 + i * 4} x2={262 + i * 34} y2={160 + i * 6} stroke={CE.sun100}
          strokeWidth="2" strokeDasharray="6 10" opacity=".7" className="ce-tracejado-anda" style={{ animationDelay: (i * 0.2) + 's' }} />;
      })}

      {/* chão e casa */}
      <rect y="300" width="460" height="60" fill="#0B3B22" />
      <g>
        <rect x="236" y="196" width="140" height="104" fill="#F6F7F9" />
        <polygon points="222,198 302,132 390,198" fill={CE.n700} />
        <rect x="292" y="236" width="34" height="64" rx="3" fill={CE.n600} />
        <rect x="252" y="218" width="28" height="26" rx="3" fill={CE.sun100} />
        <rect x="340" y="218" width="26" height="26" rx="3" fill={CE.sun100} />
        {/* painéis */}
        <polygon points="232,150 352,150 372,192 252,192" fill="#1B3A6B" stroke="#fff" strokeWidth="1.5" />
        <g stroke="rgba(255,255,255,.45)" strokeWidth="1">
          {[1, 2, 3, 4].map(function(i) { return <line key={i} x1={232 + i * 24} y1="150" x2={252 + i * 24} y2="192" />; })}
          <line x1="242" y1="171" x2="362" y2="171" />
        </g>
        <g clipPath="url(#ce-ene-painel)">
          <rect className="ce-ene-reflexo" x="160" y="140" width="50" height="60" fill="url(#ce-ene-brilho)" />
        </g>
      </g>

      {/* cabo com energia correndo até o medidor */}
      <path id="ce-ene-cabo" d={CABO} fill="none" stroke="rgba(255,255,255,.25)" strokeWidth="3" />
      {[0, 1, 2, 3].map(function(i) {
        return (
          <circle key={i} r="4" fill="#FDE047">
            <animateMotion dur="2.4s" begin={(-i * 0.6) + 's'} repeatCount="indefinite"><mpath href="#ce-ene-cabo" /></animateMotion>
          </circle>
        );
      })}
      <g transform="translate(96 284)">
        <rect width="48" height="40" rx="8" fill="#fff" stroke={VERDE} strokeWidth="2" />
        <Ico name="zap" x={24} y={20} size={18} color={VERDE} sw={2.4} />
      </g>

      {/* economia */}
      <g transform="translate(24 150)"><g className="ce-flutua-2">
        <rect width="190" height="96" rx="14" fill="#fff" filter="url(#ce-sombra)" />
        <text x="16" y="24" fontSize="10" fontWeight="800" fill={CE.n500} letterSpacing=".14em">CONTA DE LUZ</text>
        <text x="16" y="56" fontSize="28" fontWeight="800" fontStyle="italic" fill={VERDE}>−92%</text>
        <text x="16" y="76" className="ce-t-body" fontSize="9.5" fill={CE.n500}>38,4 kWh hoje</text>
        {[30, 24, 18, 12, 7, 4].map(function(h, i) {
          return <rect key={i} className="ce-barra" x={124 + i * 10} y={80 - h} width="6" height={h} rx="2"
            fill={i === 5 ? VERDE : CE.n300} style={{ '--ce-d': (0.4 + i * 0.08).toFixed(2) + 's', '--ce-v': '.9' }} />;
        })}
      </g></g>
      <Toast x={256} y={26} w={180} titulo="PAINEL ON-LINE" sub="monitoramento 24h" cor={VERDE} icone="check" d={1} ciclo={7} />
    </Cena>
  );
}

Object.assign(window, { Cena, CenaRota, CenaEmpresa, CenaRastreio, CenaEntregador, CenaGestao, CenaPainel,
  CenaErp, CenaLex, CenaEcossistema, RedeFundo, EstradaCTA, Digitando,
  AberturaGrupo, HorizonteSol, CenaParceiro, CenaEnergia, CaravanaHorizonte });

/* ═══════════════════════════════════════════════════════════
   Seções-padrão das páginas internas. Herói, grade de cards,
   passos e CTA com a mesma cara em todas as páginas.
   ═══════════════════════════════════════════════════════════ */
function SecaoHeroi({ fundo, sol, eyebrow, eyebrowCor, titulo, texto, textoCor, botoes, visual, faixa }) {
  return (
    <section style={{ position: 'relative', background: fundo || CE.blue, overflow: 'hidden' }}>
      {sol !== false && (
        <div style={{ position: 'absolute', right: '-6%', top: '-30%', width: 640, height: 640, borderRadius: '50%',
          background: 'radial-gradient(circle, ' + CE.sun + ' 0%, transparent 62%)', opacity: sol || .45 }} />
      )}
      <div style={{ position: 'relative', maxWidth: 1180, margin: '0 auto', padding: '84px 40px 96px',
        display: 'grid', gridTemplateColumns: '1.1fr .9fr', gap: 48, alignItems: 'center' }}>
        <div>
          <div style={{ fontFamily: CE.disp, fontWeight: 700, fontStyle: 'italic', textTransform: 'uppercase',
            letterSpacing: '.1em', fontSize: 14, color: eyebrowCor || CE.sun, marginBottom: 16 }}>{eyebrow}</div>
          <h1 data-ce-split="0.15" style={{ fontFamily: CE.disp, fontWeight: 800, textTransform: 'uppercase', color: '#fff',
            fontSize: 62, lineHeight: .95, letterSpacing: '-.01em', margin: '0 0 22px' }}>{titulo}</h1>
          <p style={{ fontFamily: CE.body, fontSize: 18, lineHeight: 1.6, color: textoCor || 'rgba(255,255,255,.85)',
            maxWidth: 470, margin: '0 0 32px' }}>{texto}</p>
          <div style={{ display: 'flex', gap: 14, flexWrap: 'wrap' }}>{botoes}</div>
        </div>
        <div style={{ display: 'flex', justifyContent: 'center' }}>
          <div style={{ borderRadius: 22, overflow: 'hidden', border: '6px solid rgba(255,255,255,.16)',
            boxShadow: '0 30px 60px rgba(15,28,62,.4)' }}>{visual}</div>
        </div>
      </div>
      <div style={{ position: 'absolute', bottom: 0, left: 0, right: 0, height: 6, display: 'flex' }}>
        {(faixa || [CE.rust, CE.sun, CE.blue700]).map(function(c, i) {
          return <div key={i} style={{ flex: [2, 1, 4][i], background: c }} />;
        })}
      </div>
    </section>
  );
}

function SecaoCards({ id, fundo, escuro, eyebrow, titulo, texto, itens, cols, cor }) {
  var n = cols || 3;
  return (
    <section id={id} style={{ background: fundo || '#fff' }}>
      <div style={{ maxWidth: 1180, margin: '0 auto', padding: '92px 40px' }}>
        <div style={{ textAlign: 'center', marginBottom: 52 }}>
          <Eyebrow light={escuro}>{eyebrow}</Eyebrow>
          <h2 style={{ fontFamily: CE.disp, fontWeight: 800, textTransform: 'uppercase', fontSize: 46,
            color: escuro ? '#fff' : CE.n900, margin: '12px 0 ' + (texto ? 14 : 0) + 'px', letterSpacing: '-.01em' }}>{titulo}</h2>
          {texto && <p style={{ fontFamily: CE.body, fontSize: 17, lineHeight: 1.65, color: escuro ? CE.n300 : CE.n600,
            maxWidth: 600, margin: '0 auto' }}>{texto}</p>}
        </div>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(' + n + ',1fr)', gap: 22 }}>
          {itens.map(function(s) {
            return (
              <div key={s.t} style={{ background: escuro ? CE.n900 : CE.n50, border: '1px solid ' + (escuro ? CE.n800 : CE.n200),
                borderRadius: 18, padding: 28 }}>
                <div style={{ width: 54, height: 54, borderRadius: 14, background: escuro ? CE.n800 : '#fff',
                  border: '1px solid ' + (escuro ? CE.n700 : CE.n200),
                  display: 'flex', alignItems: 'center', justifyContent: 'center', marginBottom: 18 }}>
                  <Icon name={s.i} size={26} color={escuro ? CE.sun : (cor || CE.rust)} />
                </div>
                <h3 style={{ fontFamily: CE.disp, fontWeight: 700, textTransform: 'uppercase', fontSize: 20,
                  color: escuro ? '#fff' : CE.n900, margin: '0 0 8px' }}>{s.t}</h3>
                <p style={{ fontFamily: CE.body, fontSize: 14.5, lineHeight: 1.6, color: escuro ? CE.n400 : CE.n600, margin: 0 }}>{s.d}</p>
              </div>
            );
          })}
        </div>
      </div>
    </section>
  );
}

function SecaoPassos({ id, fundo, eyebrow, titulo, passos, cor }) {
  return (
    <section id={id} style={{ background: fundo || CE.n50 }}>
      <div style={{ maxWidth: 1180, margin: '0 auto', padding: '92px 40px' }}>
        <div style={{ textAlign: 'center', marginBottom: 52 }}>
          <Eyebrow>{eyebrow}</Eyebrow>
          <h2 style={{ fontFamily: CE.disp, fontWeight: 800, textTransform: 'uppercase', fontSize: 46,
            color: CE.n900, margin: '12px 0 0', letterSpacing: '-.01em' }}>{titulo}</h2>
        </div>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(' + passos.length + ',1fr)', gap: 22 }}>
          {passos.map(function(s, i) {
            return (
              <div key={s.t} style={{ background: '#fff', border: '1px solid ' + CE.n200, borderRadius: 18, padding: 30 }}>
                <div style={{ fontFamily: CE.disp, fontWeight: 800, fontStyle: 'italic', fontSize: 52, color: CE.n200,
                  lineHeight: .8, marginBottom: 10 }}>{'0' + (i + 1)}</div>
                <div style={{ width: 50, height: 50, borderRadius: 999, background: cor || CE.blue,
                  display: 'flex', alignItems: 'center', justifyContent: 'center', marginBottom: 16 }}>
                  <Icon name={s.i} size={24} color="#fff" />
                </div>
                <h3 style={{ fontFamily: CE.disp, fontWeight: 700, textTransform: 'uppercase', fontSize: 22,
                  color: CE.n900, margin: '0 0 8px' }}>{s.t}</h3>
                <p style={{ fontFamily: CE.body, fontSize: 14.5, lineHeight: 1.6, color: CE.n600, margin: 0 }}>{s.d}</p>
              </div>
            );
          })}
        </div>
      </div>
    </section>
  );
}

function SecaoCTA({ id, fundo, titulo, texto, botoes, veiculo }) {
  return (
    <section id={id || 'contato'} data-ce-luz style={{ position: 'relative', background: fundo || CE.n950, overflow: 'hidden' }}>
      {veiculo ? <EstradaCTA veiculo={veiculo === 'moto' ? 'moto' : undefined} /> : <RedeFundo opacidade={.6} />}
      <div style={{ position: 'relative', maxWidth: 1180, margin: '0 auto', padding: '88px 40px',
        display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 40, flexWrap: 'wrap' }}>
        <div>
          <h2 style={{ fontFamily: CE.disp, fontWeight: 800, textTransform: 'uppercase', fontSize: 50,
            color: '#fff', lineHeight: 1, margin: '0 0 12px', letterSpacing: '-.01em' }}>{titulo}</h2>
          <p style={{ fontFamily: CE.body, fontSize: 18, color: 'rgba(255,255,255,.8)', margin: 0, maxWidth: 440 }}>{texto}</p>
        </div>
        <div style={{ display: 'flex', gap: 14, flexWrap: 'wrap' }}>{botoes}</div>
      </div>
    </section>
  );
}


/* ═══════════════ FROTA FLUTUANTE · os veículos reais em órbita ═══════════════
   Resposta da marca ao castelo 3D da EPIC: a frota oficial da Cerrado
   (renders do app) gira em órbita sobre um piso em grade, em 3D de CSS.
   O mouse inclina a câmera; a rolagem (--o no ancestral .ce-mf) faz a
   frota subir e acelera a órbita. Os de trás viram para a esquerda,
   como se estivessem mesmo dando a volta. */
var CE_FROTA = [
  { img: 'moto-bag.png', w: 150 }, { img: 'car.png', w: 190 }, { img: 'moto-carretinha.png', w: 175 },
  { img: 'moto-bag.png', w: 150 }, { img: 'car.png', w: 190 },
];
function FrotaFlutuante() {
  var palco = React.useRef(null), itens = React.useRef([]);
  React.useEffect(function() {
    var parado = false;
    try { parado = window.matchMedia('(prefers-reduced-motion: reduce)').matches; } catch (e) {}
    var mx = 0, my = 0, ax = 0, ay = 0, t0 = performance.now(), vivo = true, visivel = true;
    function mouse(e) { mx = e.clientX / window.innerWidth - 0.5; my = e.clientY / window.innerHeight - 0.5; }
    window.addEventListener('mousemove', mouse, { passive: true });
    var io = new IntersectionObserver(function(en) { visivel = en[0].isIntersecting; }, { threshold: 0 });
    if (palco.current) io.observe(palco.current.parentElement); // o palco começa fora da tela; observa o contêiner
    var sec = palco.current && palco.current.closest('.ce-mf');
    (function quadro() {
      if (!vivo) return;
      requestAnimationFrame(quadro);
      if (!visivel || !palco.current) return;
      if (!parado) { ax += (mx - ax) * 0.05; ay += (my - ay) * 0.05; }
      // com movimento reduzido a frota fica parada, já no lugar (não depende da rolagem)
      var o = parado ? 1 : (sec ? parseFloat(getComputedStyle(sec).getPropertyValue('--o')) || 0 : 1);
      var t = parado ? 0 : (performance.now() - t0) / 1000;
      var giro = t * 0.22 + o * 1.6 + ax * 0.9;
      palco.current.style.transform = 'translateY(' + ((1 - o) * 55).toFixed(1) + 'vh) rotateX(' + (64 - ay * 12).toFixed(2) + 'deg) rotateZ(' + (ax * 10).toFixed(2) + 'deg)';
      palco.current.style.opacity = Math.min(1, o * 1.6).toFixed(3);
      palco.current.style.scale = Math.max(0.42, Math.min(1, window.innerWidth / 1150)).toFixed(3); // cabe no celular
      itens.current.forEach(function(el, i) {
        if (!el) return;
        var a = giro + (i / CE_FROTA.length) * Math.PI * 2;
        var x = Math.cos(a) * 340, y = Math.sin(a) * 210;
        var tras = Math.sin(a) < 0; // metade de trás anda para a esquerda
        var pulo = Math.sin(t * 2.2 + i) * 6;
        el.style.transform = 'translate3d(' + x.toFixed(1) + 'px,' + y.toFixed(1) + 'px,0) rotateX(-64deg) translateY(' + pulo.toFixed(1) + 'px) scaleX(' + (tras ? -1 : 1) + ')';
        el.style.zIndex = Math.round(y + 300);
      });
    })();
    return function() { vivo = false; window.removeEventListener('mousemove', mouse); io.disconnect(); };
  }, []);
  return (
    <div className="ce-frota" aria-hidden="true">
      <div ref={palco} className="ce-frota-palco">
        <div className="ce-frota-piso" />
        <div className="ce-frota-orbita" />
        <div className="ce-frota-centro">
          <img src={ceAsset('assets/symbol-color.png')} alt="" />
        </div>
        {CE_FROTA.map(function(v, i) {
          return (
            <div key={i} ref={function(el) { itens.current[i] = el; }} className="ce-frota-item">
              <img src={ceAsset('assets/veiculos/' + v.img)} alt="" style={{ width: v.w }} />
              <span className="ce-frota-sombra" />
            </div>
          );
        })}
      </div>
    </div>
  );
}


/* Seção "o app de verdade": celular com uma demo de telas-app.jsx + texto.
   O celular gira levemente na direção do cursor (data-ce-orbita). */
function SecaoApp({ id, fundo, escuro, eyebrow, titulo, texto, itens, demo, invertido }) {
  var Demo = window[demo];
  if (!window.CelularMockup || !Demo) return null;
  var Cel = window.CelularMockup;
  var celular = (
    <div style={{ display: 'flex', justifyContent: 'center' }}>
      <div data-ce-orbita style={{ filter: 'drop-shadow(0 40px 60px rgba(15,28,62,.35))' }}>
        <Cel largura={270}><Demo /></Cel>
      </div>
    </div>
  );
  var textoCol = (
    <div>
      <Eyebrow light={escuro}>{eyebrow}</Eyebrow>
      <h2 data-ce-split style={{ fontFamily: CE.disp, fontWeight: 800, textTransform: 'uppercase', fontSize: 48,
        color: escuro ? '#fff' : CE.n900, lineHeight: .98, margin: '12px 0 18px', letterSpacing: '-.01em' }}>{titulo}</h2>
      <p style={{ fontFamily: CE.body, fontSize: 17, lineHeight: 1.65, color: escuro ? CE.n300 : CE.n600, margin: '0 0 26px', maxWidth: 470 }}>{texto}</p>
      <ul style={{ listStyle: 'none', padding: 0, margin: 0, display: 'flex', flexDirection: 'column', gap: 14 }}>
        {itens.map(function(item) {
          return (
            <li key={item} style={{ display: 'flex', alignItems: 'flex-start', gap: 12 }}>
              <Icon name="check" size={20} color={CE.sun} style={{ flexShrink: 0, marginTop: 2 }} />
              <span style={{ fontFamily: CE.body, fontSize: 15.5, color: escuro ? CE.n200 : CE.n800 }}>{item}</span>
            </li>
          );
        })}
      </ul>
    </div>
  );
  return (
    <section id={id} data-ce-luz={escuro ? '' : undefined} style={{ position: 'relative', overflow: 'hidden', background: fundo || '#fff' }}>
      <div style={{ position: 'relative', maxWidth: 1180, margin: '0 auto', padding: '92px 40px',
        display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 56, alignItems: 'center' }}>
        {invertido ? celular : textoCol}
        {invertido ? textoCol : celular}
      </div>
    </section>
  );
}

/* linhas de grade que se desenham ao fundo (Dropbox Brand) */
function GradeLinhas({ colunas, linhas }) {
  var cs = colunas || [16.66, 33.33, 50, 66.66, 83.33], ls = linhas || [];
  return (
    <div className="ce-grade" aria-hidden="true">
      {cs.map(function(x, i) { return <i key={'v' + i} className="v" style={{ left: x + '%', '--ce-gd': (i * 0.08) + 's' }} />; })}
      {ls.map(function(y, i) { return <i key={'h' + i} className="h" style={{ top: y + '%', '--ce-gd': (0.2 + i * 0.1) + 's' }} />; })}
    </div>
  );
}

/* faixa de palavras correndo (bdsn) */
function FaixaPalavras({ palavras, fundo, cor }) {
  var lista = palavras || ['Entrega', 'Mobilidade', 'ERP', 'Lex', 'Energia', 'Gestão 4.0'];
  var item = function(k) {
    return lista.map(function(p, i) {
      return (
        <span key={k + i} style={{ display: 'inline-flex', alignItems: 'center', gap: '0.5em', paddingRight: '0.5em' }}>
          <span>{p}</span><span style={{ color: CE.sun, fontSize: '.55em' }}>✦</span>
        </span>
      );
    });
  };
  return (
    <div className="ce-marquee" aria-label={lista.join(', ')}
      style={{ background: fundo || CE.n950, color: cor || '#fff', padding: '26px 0', borderTop: '1px solid ' + CE.n800, borderBottom: '1px solid ' + CE.n800 }}>
      <div className="ce-marquee-trilho" aria-hidden="true" style={{ fontFamily: CE.disp, fontWeight: 800, fontStyle: 'italic',
        textTransform: 'uppercase', fontSize: 'clamp(40px, 7vw, 96px)', lineHeight: 1, letterSpacing: '-.01em' }}>
        {item('a')}{item('b')}
      </div>
    </div>
  );
}

Object.assign(window, { SecaoHeroi, SecaoCards, SecaoPassos, SecaoCTA, GradeLinhas, FaixaPalavras, FrotaFlutuante, CE_FROTA, SecaoApp });
