// ProcessNew — 5 steps (colleague's copy), remapped dioramas, 2+2+1 layout
// Original Process.jsx untouched above this on the page
const { useEffect: usePNEffect, useRef: usePNRef, useState: usePNState } = React;

const dioramaShellPN = {
  position: 'relative',
  height: '220px',
  background: 'rgba(10, 10, 12, 0.6)',
  border: '1px solid var(--border-subtle)',
  borderRadius: '10px',
  overflow: 'hidden',
};

// Step 1: Poznáme vaši značku — reused Audit diorama logic
function DioramaPN1({ inView = true }) {
  const metrics = [
    { label: 'CTR',   numeric: 5.8,  suffix: '%',    decimals: 1, fill: 0.85 },
    { label: 'ROAS',  numeric: 4.2,  suffix: 'x',    decimals: 1, fill: 0.92 },
    { label: 'SPEND', numeric: 24,   suffix: 'K Kč', decimals: 0, fill: 0.45 },
    { label: 'FREQ',  numeric: 1.6,  suffix: '',     decimals: 1, fill: 0.36 },
  ];
  return (
    <div style={dioramaShellPN}>
      <div style={{
        position: 'absolute', top: '14px', left: '16px', right: '16px',
        display: 'flex', alignItems: 'center', gap: '8px',
        fontFamily: 'var(--font-mono)', fontSize: '10px',
        color: 'var(--text-tertiary)', letterSpacing: '0.15em',
      }}>
        <span style={{
          width: '7px', height: '7px', borderRadius: '999px',
          background: 'var(--accent)',
          animation: 'recBlink 1.4s ease-in-out infinite', flexShrink: 0,
        }} />
        AUDIT · HISTORICKÁ KREATIVA
      </div>
      <div style={{
        position: 'absolute', top: '40px', bottom: '14px', left: '16px', right: '16px',
        display: 'grid', gridTemplateColumns: '92px 1fr', gap: '14px', alignItems: 'stretch',
      }}>
        <div style={{
          background: 'linear-gradient(160deg, rgba(247,19,63,0.18), rgba(0,0,0,0.5))',
          border: '1px solid var(--accent)', borderRadius: '6px',
          position: 'relative', overflow: 'hidden',
          boxShadow: '0 0 24px rgba(247,19,63,0.18)', padding: '8px',
          animation: 'winnerBreath 4s ease-in-out infinite',
        }}>
          <div style={{
            position: 'absolute', inset: 0,
            backgroundImage: 'repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,0.18) 2px, rgba(0,0,0,0.18) 3px)',
            opacity: 0.5, pointerEvents: 'none', animation: 'scanlineDrift 8s linear infinite',
          }} />
          <span style={{
            position: 'absolute', top: '8px', left: '8px',
            fontFamily: 'var(--font-mono)', fontSize: '8px',
            color: 'var(--accent)', letterSpacing: '0.18em', fontWeight: 700, zIndex: 1,
            animation: inView ? 'stampImpact 700ms cubic-bezier(0.34, 1.56, 0.64, 1) both' : 'none',
          }}>● BEST</span>
          <div style={{
            position: 'absolute', top: '50%', left: '50%',
            transform: 'translate(-50%, -50%)',
            display: 'flex', flexDirection: 'column', gap: '4px', alignItems: 'center',
            zIndex: 1, animation: 'playPulse 3s ease-in-out infinite',
          }}>
            <div style={{
              width: 0, height: 0,
              borderLeft: '11px solid rgba(255,255,255,0.65)',
              borderTop: '7px solid transparent', borderBottom: '7px solid transparent',
              marginLeft: '3px', filter: 'drop-shadow(0 0 6px rgba(247,19,63,0.5))',
            }} />
            <span style={{ fontFamily: 'var(--font-mono)', fontSize: '8px', color: 'var(--text-tertiary)', letterSpacing: '0.1em' }}>9:16</span>
          </div>
        </div>
        <div style={{ display: 'flex', flexDirection: 'column', justifyContent: 'space-between' }}>
          <div style={{ display: 'flex', flexDirection: 'column', gap: '10px' }}>
            {metrics.map((m, i) => (
              <div key={i} style={{ display: 'flex', alignItems: 'center', gap: '10px' }}>
                <span style={{ fontFamily: 'var(--font-mono)', fontSize: '9px', color: 'var(--text-tertiary)', letterSpacing: '0.14em', minWidth: '44px', fontWeight: 600 }}>{m.label}</span>
                <div style={{ flex: 1, height: '6px', background: 'rgba(255,255,255,0.06)', borderRadius: '999px', overflow: 'hidden' }}>
                  <div style={{
                    height: '100%',
                    background: 'linear-gradient(to right, var(--accent), #FF8A4F)',
                    borderRadius: '999px',
                    width: inView ? `${m.fill * 100}%` : '0%',
                    transition: `width 900ms cubic-bezier(0.65, 0, 0.35, 1) ${200 + i * 130}ms`,
                  }} />
                </div>
                <span style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: '14px', color: 'var(--text-primary)', letterSpacing: '-0.02em', minWidth: '52px', textAlign: 'right' }}>
                  <CountUp to={m.numeric} duration={900} suffix={m.suffix} decimals={m.decimals} />
                </span>
              </div>
            ))}
          </div>
          <span style={{ fontFamily: 'var(--font-mono)', fontSize: '10px', color: 'var(--accent)', letterSpacing: '0.04em', marginTop: '8px', fontWeight: 600 }}>⌇ Začínáme od dat.</span>
        </div>
      </div>
    </div>
  );
}

// Step 2: Vezmeme produkt a podklady — file/asset upload diorama
function DioramaPN2({ inView = true }) {
  const assets = [
    { name: 'produkt_foto_01.jpg', type: 'IMG', size: '3.2 MB', done: true },
    { name: 'brand_manual.pdf',    type: 'PDF', size: '8.1 MB', done: true },
    { name: 'produkt_white_bg.png', type: 'PNG', size: '4.2 MB', done: false, pct: 67 },
    { name: 'logo_pack.zip',       type: 'ZIP', size: '1.4 MB', done: false, pct: 31 },
  ];
  return (
    <div style={dioramaShellPN}>
      <div style={{
        position: 'absolute', top: '14px', left: '16px', right: '16px',
        display: 'flex', justifyContent: 'space-between',
        fontFamily: 'var(--font-mono)', fontSize: '10px',
        color: 'var(--text-tertiary)', letterSpacing: '0.15em',
      }}>
        <span style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
          <span style={{ width: '7px', height: '7px', borderRadius: '999px', background: 'var(--accent)', animation: 'dotPulseStrong 1.2s ease-in-out infinite' }} />
          PŘÍJEM PODKLADŮ
        </span>
        <span style={{ color: 'var(--accent)', fontWeight: 600 }}>
          <CountUp to={2} duration={800} /> / 4 HOTOVO
        </span>
      </div>
      <div style={{
        position: 'absolute', top: '46px', left: '16px', right: '16px', bottom: '14px',
        display: 'flex', flexDirection: 'column', gap: '14px', justifyContent: 'center',
      }}>
        {assets.map((a, i) => (
          <div key={i} style={{ display: 'flex', flexDirection: 'column', gap: '5px' }}>
            <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
              <span style={{
                fontFamily: 'var(--font-mono)', fontSize: '10px',
                color: 'var(--text-secondary)', letterSpacing: '0.04em',
                display: 'flex', alignItems: 'center', gap: '6px',
              }}>
                <span style={{ color: a.done ? '#7AE3A8' : 'var(--accent)', fontSize: '9px' }}>{a.type}</span>
                {a.name}
              </span>
              <span style={{ fontFamily: 'var(--font-mono)', fontSize: '9px', color: a.done ? '#7AE3A8' : 'var(--accent)', fontWeight: 600 }}>
                {a.done ? '✓' : `${a.pct}%`}
              </span>
            </div>
            {!a.done && (
              <div style={{ height: '4px', background: 'rgba(255,255,255,0.06)', borderRadius: '999px', overflow: 'hidden' }}>
                <div style={{
                  height: '100%',
                  background: 'linear-gradient(to right, var(--accent), #FF8A4F)',
                  borderRadius: '999px',
                  width: inView ? `${a.pct}%` : '0%',
                  transition: `width 900ms cubic-bezier(0.65, 0, 0.35, 1) ${300 + i * 150}ms`,
                }} />
              </div>
            )}
          </div>
        ))}
      </div>
    </div>
  );
}

// Step 3: Navrhneme kreativní směry — 3 direction cards, middle selected
function DioramaPN3({ inView = true }) {
  const directions = [
    {
      label: 'SMĚR A',
      name: 'Srovnávací',
      lines: ['Před / po', 'kontrast', 'výsledek'],
      selected: false,
    },
    {
      label: 'SMĚR B',
      name: 'Lifestyle',
      lines: ['Produkt', 'v situaci', 'CTA →'],
      selected: true,
    },
    {
      label: 'SMĚR C',
      name: 'Výkonový',
      lines: ['Přímý offer', 'sleva / akce', 'urgence'],
      selected: false,
    },
  ];

  return (
    <div style={dioramaShellPN}>
      <div style={{
        position: 'absolute', top: '14px', left: '16px',
        fontFamily: 'var(--font-mono)', fontSize: '10px',
        color: 'var(--text-tertiary)', letterSpacing: '0.15em',
      }}>● KREATIVNÍ SMĚRY · 3 KONCEPTY</div>

      <div style={{
        position: 'absolute', top: '40px', bottom: '14px', left: '16px', right: '16px',
        display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: '8px', alignItems: 'stretch',
      }}>
        {directions.map((d, i) => (
          <div key={i} style={{
            background: d.selected
              ? 'linear-gradient(135deg, rgba(247,19,63,0.18), rgba(0,0,0,0.4))'
              : 'linear-gradient(135deg, rgba(80,80,90,0.12), rgba(0,0,0,0.4))',
            border: `1px solid ${d.selected ? 'var(--accent)' : 'var(--border)'}`,
            borderRadius: '6px', padding: '10px',
            display: 'flex', flexDirection: 'column', justifyContent: 'space-between',
            boxShadow: d.selected ? '0 0 24px rgba(247,19,63,0.15)' : 'none',
            animation: d.selected && inView
              ? 'afterGlowPulse 4s ease-in-out 1500ms infinite, afterLift 4s ease-in-out 1500ms infinite'
              : (!d.selected && inView ? 'beforeFade 1200ms ease-out 1400ms both' : 'none'),
            opacity: inView ? 1 : 0,
            transition: 'opacity 400ms',
          }}>
            <span style={{
              fontFamily: 'var(--font-mono)', fontSize: '8px', letterSpacing: '0.18em', fontWeight: 700,
              color: d.selected ? 'var(--accent)' : 'var(--text-tertiary)',
            }}>{d.label}</span>
            <div style={{ display: 'flex', flexDirection: 'column', gap: '5px' }}>
              <div style={{
                fontFamily: 'var(--font-display)', fontSize: '12px', fontWeight: 700,
                color: d.selected ? 'var(--text-primary)' : 'var(--text-secondary)',
                letterSpacing: '-0.01em',
                animation: d.selected && inView ? 'diffFlash 800ms ease-out 1700ms both' : 'none',
                border: '1px solid transparent', padding: '1px 3px', borderRadius: '3px',
              }}>{d.name}</div>
              {d.lines.map((line, j) => (
                <div key={j} style={{
                  fontFamily: j === d.lines.length - 1 && d.selected ? 'var(--font-mono)' : 'var(--font-body)',
                  fontSize: j === d.lines.length - 1 && d.selected ? '8px' : '11px',
                  color: j === d.lines.length - 1 && d.selected ? 'var(--accent)' : 'var(--text-tertiary)',
                  fontWeight: j === d.lines.length - 1 && d.selected ? 600 : 400,
                  letterSpacing: j === d.lines.length - 1 && d.selected ? '0.08em' : 0,
                  animation: d.selected && inView ? `diffFlash 800ms ease-out ${1900 + j * 200}ms both` : 'none',
                  border: '1px solid transparent', padding: '1px 3px', borderRadius: '3px',
                }}>{line}</div>
              ))}
            </div>
          </div>
        ))}
      </div>
    </div>
  );
}

// Step 4: Vytvoříme sadu kreativ — reused Production diorama
function DioramaPN4({ inView = true }) {
  const variants = [
    { label: 'Produktový banner · 1:1', pct: 100, state: 'DONE' },
    { label: 'Lifestyle banner · 9:16', pct: 71, state: 'RUN' },
    { label: 'Výkonový banner · 1:1',   pct: 38, state: 'RUN' },
  ];
  return (
    <div style={dioramaShellPN}>
      <div style={{
        position: 'absolute', top: '14px', left: '16px', right: '16px',
        display: 'flex', justifyContent: 'space-between', alignItems: 'center',
        fontFamily: 'var(--font-mono)', fontSize: '10px',
        color: 'var(--text-tertiary)', letterSpacing: '0.15em',
      }}>
        <span style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
          <span style={{ width: '7px', height: '7px', borderRadius: '999px', background: 'var(--accent)', animation: 'dotPulseStrong 1.2s ease-in-out infinite' }} />
          6 KREATIV PARALELNĚ
        </span>
        <span style={{ color: 'var(--accent)', animation: 'etaLoop 4s ease-in-out infinite' }}>
          <CountUp to={3} duration={1100} /> / 6 HOTOVO
        </span>
      </div>
      <div style={{
        position: 'absolute', top: '46px', left: '16px', right: '16px', bottom: '16px',
        display: 'flex', flexDirection: 'column', gap: '20px', justifyContent: 'center',
      }}>
        {variants.map((v, i) => (
          <div key={i} style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
            <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline' }}>
              <span style={{
                fontFamily: 'var(--font-mono)', fontSize: '11px',
                color: 'var(--text-secondary)', letterSpacing: '0.04em',
                animation: inView ? `glitchSettle 600ms steps(8) ${300 + i * 150}ms both` : 'none',
                display: 'inline-block',
              }}>{v.label}</span>
              <span style={{ fontFamily: 'var(--font-mono)', fontSize: '10px', color: v.state === 'DONE' ? '#7AE3A8' : 'var(--accent)', letterSpacing: '0.1em', fontWeight: 600, animation: v.state === 'DONE' ? 'doneGlow 2.5s ease-in-out infinite' : 'none' }}>{v.pct}%</span>
            </div>
            <div style={{ height: '5px', background: 'rgba(255,255,255,0.08)', borderRadius: '999px', overflow: 'hidden', position: 'relative' }}>
              <div style={{
                position: 'absolute', inset: 0,
                width: inView ? `${v.pct}%` : '0%',
                background: v.state === 'DONE' ? 'linear-gradient(to right, #7AE3A8, #5AC78F)' : 'linear-gradient(to right, var(--accent), #FF8A4F)',
                borderRadius: '999px',
                transition: `width 1100ms cubic-bezier(0.65, 0, 0.35, 1) ${200 + i * 200}ms`,
              }} />
              {v.state === 'RUN' && (
                <div style={{ position: 'absolute', top: 0, bottom: 0, left: `${v.pct - 6}%`, width: '6%', background: 'linear-gradient(to right, transparent, rgba(255,255,255,0.6), transparent)', animation: 'shimmer 1.6s ease-in-out infinite' }} />
              )}
            </div>
          </div>
        ))}
      </div>
    </div>
  );
}

// Step 5: Dodáme výstupy do reklam — reused Handover diorama
function DioramaPN5() {
  const files = [
    { name: 'meta-ads-export/', folder: true, depth: 0 },
    { name: 'produktove/', folder: true, depth: 1 },
    { name: 'banner_1x1.jpg', depth: 2, size: '0.8 MB' },
    { name: 'banner_9x16.jpg', depth: 2, size: '1.1 MB' },
    { name: 'lifestyle/', folder: true, depth: 1 },
    { name: 'banner_1x1.jpg', depth: 2, size: '0.9 MB' },
    { name: 'banner_9x16.jpg', depth: 2, size: '1.2 MB' },
    { name: 'vykonove/', folder: true, depth: 1 },
    { name: 'banner_1x1.jpg', depth: 2, size: '0.7 MB' },
    { name: 'banner_9x16.jpg', depth: 2, size: '1.0 MB' },
  ];
  return (
    <div style={dioramaShellPN}>
      <div style={{ position: 'absolute', top: '14px', left: '16px', fontFamily: 'var(--font-mono)', fontSize: '10px', color: 'var(--text-tertiary)', letterSpacing: '0.15em', zIndex: 2 }}>● META ADS · EXPORT</div>
      <div style={{ position: 'absolute', top: '14px', right: '16px', fontFamily: 'var(--font-mono)', fontSize: '10px', color: 'var(--accent)', letterSpacing: '0.12em', fontWeight: 600, zIndex: 2 }}>Připraveno ke spuštění.</div>
      <div style={{
        position: 'absolute', top: '40px', left: '16px', right: '16px', bottom: '14px',
        overflow: 'hidden',
        maskImage: 'linear-gradient(to bottom, transparent, black 14%, black 86%, transparent)',
        WebkitMaskImage: 'linear-gradient(to bottom, transparent, black 14%, black 86%, transparent)',
      }}>
        <div style={{ display: 'flex', flexDirection: 'column', gap: '5px', animation: 'handoverScroll 14s linear infinite' }}>
          {[...files, ...files].map((f, i) => (
            <div key={i} style={{ display: 'flex', alignItems: 'center', gap: '8px', paddingLeft: `${f.depth * 14}px`, fontFamily: 'var(--font-mono)', fontSize: '11px', flexShrink: 0 }}>
              <span style={{ color: f.folder ? 'var(--accent)' : 'var(--text-tertiary)', fontSize: '10px', minWidth: '8px' }}>{f.folder ? '▾' : '·'}</span>
              <span style={{ color: f.folder ? 'var(--text-primary)' : 'var(--text-secondary)', fontWeight: f.folder ? 600 : 400, flex: 1 }}>{f.name}</span>
              {f.size && <span style={{ color: 'var(--text-tertiary)', fontSize: '9px', letterSpacing: '0.05em' }}>{f.size}</span>}
            </div>
          ))}
        </div>
      </div>
    </div>
  );
}

// ============ STEP CARD ============
function StepCardPN({ num, title, desc, Diorama, delay }) {
  const [hover, setHover] = usePNState(false);
  const [inView, setInView] = usePNState(false);
  const cardRef = usePNRef(null);

  usePNEffect(() => {
    const el = cardRef.current; if (!el) return;
    const reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
    if (reduced) { setInView(true); return; }
    const r = el.getBoundingClientRect();
    const vh = window.innerHeight || document.documentElement.clientHeight;
    if (r.top < vh * 0.85 && r.bottom > 0) {
      const t = setTimeout(() => setInView(true), delay + 200);
      return () => clearTimeout(t);
    }
    const io = new IntersectionObserver(entries => {
      entries.forEach(e => { if (e.isIntersecting) { setInView(true); io.unobserve(el); } });
    }, { threshold: 0.25 });
    io.observe(el);
    return () => io.disconnect();
  }, [delay]);

  return (
    <Reveal delay={delay} y={28} style={{ height: '100%' }}>
      <div
        ref={cardRef}
        onMouseEnter={() => setHover(true)}
        onMouseLeave={() => setHover(false)}
        style={{
          background: hover ? 'var(--surface-hover)' : 'var(--surface)',
          border: '1px solid ' + (hover ? 'var(--border-strong)' : 'var(--border)'),
          borderRadius: '14px', padding: '32px',
          display: 'flex', flexDirection: 'column', gap: '24px',
          height: '100%', boxSizing: 'border-box',
          transform: hover ? 'translateY(-4px)' : 'translateY(0)',
          boxShadow: hover ? '0 20px 40px -20px rgba(0,0,0,0.8)' : 'none',
          transition: 'background 400ms cubic-bezier(0.65, 0, 0.35, 1), border-color 400ms, transform 500ms cubic-bezier(0.22, 1, 0.36, 1), box-shadow 500ms cubic-bezier(0.22, 1, 0.36, 1)',
          position: 'relative', overflow: 'hidden',
        }}
      >
        <span aria-hidden="true" style={{
          position: 'absolute', top: '-18px', right: '-8px',
          fontFamily: 'var(--font-display)', fontWeight: 800,
          fontSize: '180px', lineHeight: 1,
          color: hover ? 'rgba(247,19,63,0.08)' : 'rgba(247,19,63,0.05)',
          letterSpacing: '-0.05em', pointerEvents: 'none', userSelect: 'none',
          transition: 'color 500ms cubic-bezier(0.65, 0, 0.35, 1)',
        }}>{String(num).padStart(2, '0')}</span>

        <span style={{
          alignSelf: 'flex-start', fontFamily: 'var(--font-mono)', fontSize: '11px',
          padding: '5px 12px', borderRadius: '6px',
          background: 'rgba(255,255,255,0.06)', border: '1px solid var(--border-subtle)',
          color: 'var(--text-secondary)', letterSpacing: '0.1em', textTransform: 'uppercase',
          position: 'relative', zIndex: 1,
        }}>Krok {num}</span>

        <div style={{ position: 'relative', zIndex: 1, flex: 1 }}>
          <h3 style={{
            fontFamily: 'var(--font-display)', fontWeight: 600,
            fontSize: '32px', letterSpacing: '-0.02em',
            color: 'var(--text-primary)', margin: '0 0 12px',
          }}>{title}</h3>
          <p style={{
            fontFamily: 'var(--font-body)', fontSize: '15px',
            color: 'var(--text-secondary)', lineHeight: 1.55,
            margin: 0, maxWidth: '38ch',
          }}>{desc}</p>
        </div>

        <div style={{ position: 'relative', zIndex: 1, marginTop: 'auto' }}>
          <Diorama inView={inView} />
        </div>
      </div>
    </Reveal>
  );
}

function ProcessNew() {
  const steps = [
    {
      num: 1,
      title: 'Poznáme vaši značku',
      desc: 'Projdeme si, co prodáváte, komu, jaké kreativy vám fungovaly a co už jste zkoušeli. Bez toho netvoříme naslepo.',
      D: DioramaPN1,
    },
    {
      num: 2,
      title: 'Vezmeme produkt a podklady',
      desc: 'Pracujeme s vaším produktem, fotkami, videi, brand manuálem nebo existujícími reklamami. Když podklady nejsou perfektní, nevadí — pomůžeme si vlastním workflow.',
      D: DioramaPN2,
    },
    {
      num: 3,
      title: 'Navrhneme kreativní směry',
      desc: 'Připravíme kreativní koncepty, které budou respektovat vaše zadání.',
      D: DioramaPN3,
    },
    {
      num: 4,
      title: 'Vytvoříme sadu kreativ',
      desc: 'Kombinujeme AI, reálné podklady a práci grafiků. Hlídáme detaily, uvěřitelnost i to, aby produkt nepůsobil falešně.',
      D: DioramaPN4,
    },
    {
      num: 5,
      title: 'Dodáme výstupy do reklam',
      desc: 'Dle domluveného balíčku připravíme několik setů reklamní grafiky do Meta Ads.',
      D: DioramaPN5,
    },
  ];

  return (
    <section data-screen-label="04b Proces nový" style={{
      maxWidth: '1280px', margin: '0 auto',
      padding: '32px 32px 65px',
    }}>

      <NumberedHeader
        num="04"
        title="Jak z produktu vzniknou kreativy do reklam."
        sub="Pět kroků. Od poznání vaší značky po hotové bannery připravené do Meta Ads."
      />

      {/* 2+2 grid */}
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)', gap: '14px', marginBottom: '14px' }}>
        {steps.slice(0, 4).map((s, i) => (
          <StepCardPN key={s.num} num={s.num} title={s.title} desc={s.desc} Diorama={s.D} delay={i * 120} />
        ))}
      </div>

      {/* 5th step — full width */}
      <StepCardPN num={steps[4].num} title={steps[4].title} desc={steps[4].desc} Diorama={steps[4].D} delay={480} />
    </section>
  );
}

window.ProcessNew = ProcessNew;
