const STEPS = [
  ['01', 'Operational Audit', 'Map bottlenecks, existing APIs, CRM schemas, and manual workflows before writing a line of code.', ['Workflow map', 'System inventory', 'Data access review']],
  ['02', 'System Architecture', 'Design data flow, human-in-the-loop checkpoints, fallback rules, and interface prototypes.', ['Architecture diagram', 'Approval checkpoints', 'Clickable prototype']],
  ['03', 'Iterative Build & Guardrails', 'Ship tested modules in weekly milestones with real telemetry, error handling, and role permissions.', ['Weekly demos', 'Error budgets & alerts', 'Role permissions']],
  ['04', 'Deployment & Ownership', 'Hand over clean documentation, maintainable repositories, and operational dashboards your team controls.', ['Your repositories', 'Runbooks & docs', 'Ops dashboards']],
];

function ProcessBand() {
  const ref = React.useRef(null);
  const [p, setP] = React.useState(0);
  const wide = useMedia('(min-width: 900px)');
  React.useEffect(() => {
    const f = () => {
      if (!ref.current) return;
      const r = ref.current.getBoundingClientRect();
      const vh = window.innerHeight;
      setP(Math.max(0, Math.min(1, (vh * 0.6 - r.top) / (r.height))));
    };
    f(); window.addEventListener('scroll', f, { passive: true }); window.addEventListener('resize', f);
    return () => { window.removeEventListener('scroll', f); window.removeEventListener('resize', f); };
  }, []);
  const { SectionHeader, Badge } = DS;
  return (
    <section id="process" style={{ position: 'relative', background: 'linear-gradient(180deg, rgba(30,27,75,.94), rgba(30,27,75,.9))', backdropFilter: 'var(--glass-blur)', WebkitBackdropFilter: 'var(--glass-blur)', padding: `${wide ? 112 : 72}px 0`, overflow: 'hidden' }}>
      <div aria-hidden style={{ position: 'absolute', inset: 0, backgroundImage: 'linear-gradient(rgba(233,231,255,.08) 1px, transparent 1px), linear-gradient(90deg, rgba(233,231,255,.08) 1px, transparent 1px)', backgroundSize: '64px 64px' }} />
      <div aria-hidden style={{ position: 'absolute', width: 620, height: 620, right: '-10%', top: '-20%', borderRadius: '50%', background: 'radial-gradient(circle, rgba(124,58,237,.35), transparent 65%)' }} />
      <div aria-hidden style={{ position: 'absolute', width: 520, height: 520, left: '-8%', bottom: '-20%', borderRadius: '50%', background: 'radial-gradient(circle, rgba(6,182,212,.22), transparent 65%)' }} />
      <Container style={{ position: 'relative' }}>
        <Reveal><SectionHeader dark eyebrow="How Yantrrk builds" title="Audit first. Ship weekly. Hand over everything." lead="A four-stage engineering process with written deliverables at each stage, so you always know what exists, who owns it, and what runs next." /></Reveal>
        <div ref={ref} style={{ position: 'relative', marginTop: 56, display: 'grid', gap: wide ? 0 : 8, paddingLeft: wide ? 0 : 36 }}>
          <div aria-hidden style={{ position: 'absolute', left: wide ? 'calc(25% - 1px)' : 11, top: 8, bottom: 8, width: 2, background: 'rgba(233,231,255,.12)', borderRadius: 2 }}>
            <div style={{ width: '100%', height: `${p * 100}%`, background: 'linear-gradient(180deg, #7C3AED, #2563EB, #06B6D4)', borderRadius: 2, transition: 'height .1s linear' }} />
          </div>
          {STEPS.map(([n, t, d, out], i) => {
            const on = p >= (i + 0.25) / STEPS.length;
            return (
              <Reveal key={n} delay={i * 0.07} style={{ position: 'relative', display: 'grid', gridTemplateColumns: wide ? '25% minmax(0,1fr) minmax(0,.8fr)' : 'minmax(0,1fr)', gap: wide ? 0 : 12, padding: wide ? '28px 0' : '18px 16px', margin: wide ? '0 0 12px' : '0 0 10px', borderRadius: 18, background: on ? 'rgba(255,255,255,.07)' : 'rgba(255,255,255,.03)', border: '1px solid ' + (on ? 'rgba(233,231,255,.18)' : 'rgba(233,231,255,.08)'), backdropFilter: 'blur(14px)', WebkitBackdropFilter: 'blur(14px)', boxShadow: on ? '0 1px 0 rgba(255,255,255,.08) inset, 0 20px 40px -20px rgba(0,0,0,.5)' : 'none', transition: 'background .4s, border-color .4s, box-shadow .4s' }}>
                <span aria-hidden style={{ position: 'absolute', left: wide ? 'calc(25% - 7px)' : -31, top: wide ? 38 : 26, width: 14, height: 14, borderRadius: '50%', background: on ? 'var(--yk-sky)' : 'var(--yk-indigo)', border: `2px solid ${on ? 'var(--yk-sky)' : 'rgba(233,231,255,.3)'}`, boxShadow: on ? '0 0 0 4px rgba(6,182,212,.18)' : 'none', transition: 'all .3s' }} />
                <div style={{ font: '500 13px var(--font-mono)', color: on ? 'var(--yk-sky)' : 'rgba(233,231,255,.5)', paddingTop: 4, transition: 'color .3s' }}>{n} /</div>
                <div style={{ paddingLeft: wide ? 40 : 0, paddingRight: wide ? 32 : 0 }}>
                  <h3 style={{ font: '600 22px/1.3 var(--font-display)', color: '#fff', letterSpacing: '-.01em' }}>{t}</h3>
                  <p style={{ font: '400 16px/1.6 var(--font-body)', color: 'var(--text-on-dark-muted)', marginTop: 8, maxWidth: 520 }}>{d}</p>
                </div>
                <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap', alignContent: 'flex-start', paddingTop: wide ? 6 : 0 }}>{out.map((o) => <Badge key={o} tone="dark" size="sm">{o}</Badge>)}</div>
              </Reveal>
            );
          })}
        </div>
      </Container>
    </section>
  );
}

Object.assign(window, { ProcessBand });
