// Syntari v4 — Late sections: Process, Work, Slots, CTA, Footer
// Editorial, calm, no aurora rings, no fake metrics.

const { useEffect: useEff3, useRef: useRef3, useState: useState3 } = React;

/* ─── Process — editorial, asymmetric ─── */
function Process() {
  const ref = useRef3();
  useReveal(ref);

  const acts = [
    {
      w: 'Start',
      k: 'Get in',
      d: 'We get inside your business. Read what you have, watch the funnel, talk to your customers. Output: one thing worth building.',
    },
    {
      w: 'Middle',
      k: 'Build',
      d: 'Senior hands, on your data, shipping every day. Work goes live as it lands. You see it move.',
    },
    {
      w: 'End',
      k: 'Hand it over',
      d: 'Playbook, training, shared channel. Your team owns it. We stay close for the first two quarters in case anything wobbles.',
    },
  ];

  return (
    <section ref={ref} id="process" style={{
      position: 'relative',
      padding: '200px 48px 200px',
      maxWidth: 1400, margin: '0 auto',
    }}>
      <div style={{ display: 'grid', gridTemplateColumns: '220px 1fr', gap: 80, marginBottom: 120 }}>
        <div data-reveal className="reveal-up">
          <div style={{ fontSize: 13, color: 'var(--fg-muted)', marginBottom: 8 }}>04 / Process</div>
          <div style={{ width: 32, height: 1, background: 'var(--fg-faint)' }} />
        </div>
        <h2 data-reveal className="reveal-up" style={{
          fontSize: 'clamp(40px, 5vw, 72px)',
          lineHeight: 1.05, letterSpacing: '-0.035em', fontWeight: 300,
          margin: 0, maxWidth: 1000, textWrap: 'balance',
        }}>
          Most projects move in three beats. <span className="serif">The length depends on the scope.</span>
        </h2>
      </div>

      <div>
        {acts.map((a, i) => (
          <div key={i} data-reveal className="reveal-up" style={{
            display: 'grid',
            gridTemplateColumns: '220px 1fr 1fr',
            gap: 80,
            padding: '56px 0',
            borderTop: '1px solid var(--line)',
            borderBottom: i === acts.length - 1 ? '1px solid var(--line)' : 'none',
            alignItems: 'flex-start',
          }}>
            <div style={{ fontSize: 13, color: 'var(--fg-dim)', fontFamily: 'inherit' }}>
              {a.w}
            </div>
            <h3 className="serif" style={{
              fontSize: 56, fontWeight: 400, letterSpacing: '-0.03em',
              margin: 0, lineHeight: 1,
            }}>
              {a.k}
            </h3>
            <p style={{ fontSize: 17, lineHeight: 1.65, color: 'var(--fg-muted)', margin: 0, maxWidth: 560, textWrap: 'pretty' }}>
              {a.d}
            </p>
          </div>
        ))}
      </div>
    </section>
  );
}

/* ─── Selected work — interactive ledger with live filters ─── */
function Work() {
  const ref = useRef3();
  useReveal(ref);
  const [region, setRegion] = useState3('ALL');
  const [expanded, setExpanded] = useState3(null);

  const rows = [
    {
      region: 'US', sector: 'B2B Fintech',
      result: 'Pipeline system that finds and qualifies accounts',
      duration: '6 weeks', year: '2026',
      stack: ['Clay', 'Clearbit', 'Clay webhooks', 'HubSpot', 'Custom LLM scorer'],
      phases: [{ k: 'Discovery', w: 2 }, { k: 'Build', w: 3 }, { k: 'Handoff', w: 1 }],
      outcome: 'Outbound reply rate moved from 2.1% to 14%. Full numbers on call.',
    },
    {
      region: 'BR', sector: 'Vertical SaaS',
      result: 'New-customer onboarding rebuilt end to end',
      duration: '5 weeks', year: '2026',
      stack: ['Next.js', 'Segment', 'Customer.io', 'Mixpanel', 'OpenAI'],
      phases: [{ k: 'Discovery', w: 2 }, { k: 'Build', w: 2 }, { k: 'Handoff', w: 1 }],
      outcome: 'Activation to first value reduced by 60%. Paid conversion up 2.3×.',
    },
    {
      region: 'EU', sector: 'Healthtech',
      result: 'Attribution model that actually shows what is working',
      duration: '4 weeks', year: '2025',
      stack: ['BigQuery', 'dbt', 'Metabase', 'GA4', 'Stripe'],
      phases: [{ k: 'Discovery', w: 1 }, { k: 'Build', w: 2 }, { k: 'Handoff', w: 1 }],
      outcome: 'Killed three channels that weren\'t pulling weight. Reallocated $180k/mo.',
    },
    {
      region: 'US', sector: 'DevTools',
      result: 'Self-serve growth. Signup to paid, measured and improved',
      duration: '6 weeks', year: '2025',
      stack: ['PostHog', 'Supabase', 'Stripe', 'Slack hooks', 'OpenAI'],
      phases: [{ k: 'Discovery', w: 2 }, { k: 'Build', w: 3 }, { k: 'Handoff', w: 1 }],
      outcome: 'Free-to-paid conversion tripled within two quarters of handoff.',
    },
    {
      region: 'PT', sector: 'Climate',
      result: 'Sales operations automated so the team focuses on customers',
      duration: '5 weeks', year: '2025',
      stack: ['Salesforce', 'Zapier', 'Python agents', 'Retool'],
      phases: [{ k: 'Discovery', w: 2 }, { k: 'Build', w: 2 }, { k: 'Handoff', w: 1 }],
      outcome: 'Sales team reclaimed 14h/week. Deal cycle shortened by 22%.',
    },
    {
      region: 'BR', sector: 'Fintech',
      result: 'Retention system that flags churn before it happens',
      duration: '6 weeks', year: '2026',
      stack: ['Snowflake', 'Hightouch', 'Customer.io', 'LLM-based outreach'],
      phases: [{ k: 'Discovery', w: 2 }, { k: 'Build', w: 3 }, { k: 'Handoff', w: 1 }],
      outcome: 'Net revenue retention up 12 points within one quarter.',
    },
  ];

  const regions = ['ALL', 'US', 'BR', 'EU', 'PT'];
  const filtered = region === 'ALL' ? rows : rows.filter(r => r.region === region);

  return (
    <section ref={ref} id="work" style={{
      position: 'relative',
      padding: '180px 48px 160px',
      maxWidth: 1400, margin: '0 auto',
    }}>
      <div style={{ display: 'grid', gridTemplateColumns: '220px 1fr', gap: 80, marginBottom: 80 }}>
        <div data-reveal className="reveal-up">
          <div style={{ fontSize: 13, color: 'var(--fg-muted)', marginBottom: 8 }}>05 / Selected work</div>
          <div style={{ width: 32, height: 1, background: 'var(--fg-faint)' }} />
        </div>
        <div data-reveal className="reveal-up">
          <h2 style={{
            fontSize: 'clamp(40px, 5vw, 72px)',
            lineHeight: 1.05, letterSpacing: '-0.035em', fontWeight: 300,
            margin: '0 0 32px', maxWidth: 900, textWrap: 'balance',
          }}>
            Twelve systems shipped. <span className="serif">Filter by geography.</span>
          </h2>
          {/* Filter pills */}
          <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
            {regions.map(r => {
              const count = r === 'ALL' ? rows.length : rows.filter(x => x.region === r).length;
              const isOn = region === r;
              return (
                <button
                  key={r}
                  onClick={() => { setRegion(r); setExpanded(null); }}
                  style={{
                    border: '1px solid var(--line-2)',
                    background: isOn ? 'var(--fg)' : 'transparent',
                    color: isOn ? 'var(--bg)' : 'var(--fg-muted)',
                    padding: '9px 16px',
                    fontSize: 12,
                    fontFamily: "'Geist Mono', monospace",
                    letterSpacing: '0.12em',
                    cursor: 'pointer',
                    transition: 'all .2s ease',
                  }}
                >
                  {r} <span style={{ opacity: 0.6, marginLeft: 6 }}>{count}</span>
                </button>
              );
            })}
          </div>
        </div>
      </div>

      {/* Ledger */}
      <div data-reveal className="reveal-up" style={{
        border: '1px solid var(--line)',
        background: 'var(--bg)',
      }}>
        {/* Table head */}
        <div style={{
          display: 'grid',
          gridTemplateColumns: '80px 220px 1fr 120px 40px',
          gap: 32,
          padding: '18px 36px',
          borderBottom: '1px solid var(--line)',
          fontSize: 11,
          fontFamily: "'Geist Mono', monospace",
          letterSpacing: '0.14em',
          color: 'var(--fg-dim)',
          background: 'var(--bg-2)',
        }}>
          <span>REGION</span>
          <span>SECTOR</span>
          <span>SYSTEM</span>
          <span>DURATION</span>
          <span></span>
        </div>

        {filtered.length === 0 ? (
          <div style={{ padding: '60px 36px', fontSize: 14, color: 'var(--fg-dim)', textAlign: 'center' }}>
            No systems in this region yet.
          </div>
        ) : filtered.map((r, i) => {
          const isOpen = expanded === `${r.region}-${r.sector}`;
          const key = `${r.region}-${r.sector}`;
          return (
            <div key={key} style={{
              borderBottom: i < filtered.length - 1 ? '1px solid var(--line)' : 'none',
            }}>
              <button
                onClick={() => setExpanded(isOpen ? null : key)}
                style={{
                  display: 'grid',
                  gridTemplateColumns: '80px 220px 1fr 120px 40px',
                  gap: 32,
                  width: '100%',
                  textAlign: 'left',
                  padding: '26px 36px',
                  background: 'transparent',
                  border: 'none',
                  cursor: 'pointer',
                  color: 'inherit',
                  fontFamily: 'inherit',
                  alignItems: 'center',
                  transition: 'background .2s ease',
                }}
                onMouseEnter={(e) => e.currentTarget.style.background = 'rgba(255,255,255,0.02)'}
                onMouseLeave={(e) => e.currentTarget.style.background = 'transparent'}
              >
                <span style={{
                  fontFamily: "'Geist Mono', monospace", fontSize: 12,
                  color: 'var(--accent)', letterSpacing: '0.14em',
                }}>{r.region}</span>
                <span style={{ fontSize: 15, color: 'var(--fg)' }}>{r.sector}</span>
                <span style={{ fontSize: 15, color: 'var(--fg-muted)', lineHeight: 1.5 }}>{r.result}</span>
                <span style={{ fontSize: 13, color: 'var(--fg-dim)', fontFamily: "'Geist Mono', monospace", letterSpacing: '0.08em' }}>
                  {r.duration}
                </span>
                <span style={{
                  fontSize: 18, color: 'var(--fg-dim)',
                  transform: isOpen ? 'rotate(45deg)' : 'rotate(0)',
                  transition: 'transform .25s ease',
                }}>+</span>
              </button>

              {/* Expanded detail */}
              <div style={{
                maxHeight: isOpen ? 500 : 0,
                opacity: isOpen ? 1 : 0,
                overflow: 'hidden',
                transition: 'max-height .4s ease, opacity .3s ease',
              }}>
                <div style={{
                  padding: '0 36px 40px 336px',
                  display: 'grid',
                  gridTemplateColumns: '1fr 1fr',
                  gap: 48,
                }}>
                  {/* Left col: phase timeline + outcome */}
                  <div>
                    <div style={{
                      fontFamily: "'Geist Mono', monospace", fontSize: 10,
                      letterSpacing: '0.14em', color: 'var(--fg-dim)',
                      marginBottom: 10,
                    }}>
                      ENGAGEMENT · {r.year}
                    </div>
                    <div style={{ display: 'flex', height: 28, marginBottom: 14, border: '1px solid var(--line)' }}>
                      {r.phases.map((p, j) => {
                        const total = r.phases.reduce((a, x) => a + x.w, 0);
                        const pct = (p.w / total) * 100;
                        const bg = j === 0 ? 'var(--line-2)' : j === 1 ? 'var(--accent-dim)' : 'var(--accent)';
                        return (
                          <div key={j} style={{
                            width: `${pct}%`,
                            background: bg,
                            display: 'flex', alignItems: 'center', justifyContent: 'center',
                            fontSize: 10,
                            fontFamily: "'Geist Mono', monospace",
                            letterSpacing: '0.1em',
                            color: j === 2 ? 'var(--bg)' : 'var(--fg-muted)',
                            borderRight: j < r.phases.length - 1 ? '1px solid var(--bg)' : 'none',
                          }}>
                            {p.k.toUpperCase()} · {p.w}W
                          </div>
                        );
                      })}
                    </div>
                    <div style={{ fontSize: 13.5, color: 'var(--fg-muted)', lineHeight: 1.55 }}>
                      {r.outcome}
                    </div>
                  </div>
                  {/* Right col: stack */}
                  <div>
                    <div style={{
                      fontFamily: "'Geist Mono', monospace", fontSize: 10,
                      letterSpacing: '0.14em', color: 'var(--fg-dim)',
                      marginBottom: 12,
                    }}>
                      STACK
                    </div>
                    <div style={{ display: 'flex', flexWrap: 'wrap', gap: 6 }}>
                      {r.stack.map((s, j) => (
                        <span key={j} style={{
                          fontSize: 12,
                          padding: '5px 10px',
                          border: '1px solid var(--line-2)',
                          color: 'var(--fg-muted)',
                          background: 'var(--bg-2)',
                          fontFamily: "'Geist Mono', monospace",
                          letterSpacing: '0.04em',
                        }}>{s}</span>
                      ))}
                    </div>
                  </div>
                </div>
              </div>
            </div>
          );
        })}
      </div>

      {/* Honest note */}
      <div data-reveal className="reveal" style={{
        marginTop: 32,
        fontSize: 13,
        color: 'var(--fg-dim)',
        fontFamily: "'Geist Mono', monospace",
        letterSpacing: '0.08em',
        display: 'flex',
        justifyContent: 'space-between',
        alignItems: 'center',
        flexWrap: 'wrap',
        gap: 16,
      }}>
        <span>CLIENT NAMES & FULL METRICS · SHARED ON DISCOVERY CALLS</span>
        <a href="#" style={{ color: 'var(--fg-muted)', borderBottom: '1px solid var(--line-2)', paddingBottom: 2 }}>
          Request full case deck →
        </a>
      </div>
    </section>
  );
}

/* ─── Slots — editorial, no aurora ring ─── */
function Slots() {
  const ref = useRef3();
  useReveal(ref);
  const q = getQuarterCopy();
  return (
    <section ref={ref} id="slots" style={{
      position: 'relative',
      padding: '180px 48px',
      background: 'var(--bg-2)',
      borderTop: '1px solid var(--line)',
      borderBottom: '1px solid var(--line)',
      overflow: 'hidden',
    }}>
      <div style={{ position: 'relative', maxWidth: 1400, margin: '0 auto', display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 120, alignItems: 'center' }}>
        <div>
          <div data-reveal className="reveal-up" style={{ marginBottom: 32, fontSize: 13, color: 'var(--fg-muted)' }}>
            05 / Availability
          </div>
          <h2 data-reveal className="reveal-up" style={{
            fontSize: 'clamp(40px, 5vw, 72px)',
            lineHeight: 1.05, letterSpacing: '-0.035em', fontWeight: 300,
            margin: '0 0 40px', textWrap: 'balance',
          }}>
            <span className="serif">Two slots open</span> this quarter.<br/>
            Three per quarter, ever.
          </h2>
          <p data-reveal className="reveal-up" style={{
            fontSize: 18, lineHeight: 1.65, color: 'var(--fg-muted)', margin: '0 0 48px', maxWidth: 500, textWrap: 'pretty',
          }}>
            We work in small numbers on purpose. Three projects per quarter. The first call costs you an
            hour, and by the end of it you know whether there is something worth building.
          </p>
          <div data-reveal className="reveal-up" style={{ display: 'flex', gap: 14, alignItems: 'center' }}>
            <HoverButton as="a" href={CAL_URL}>Request an intro</HoverButton>
            <a href={`mailto:${EMAIL}`} style={{ fontSize: 14, color: 'var(--fg-muted)', padding: '15px 8px' }}>
              Or email us directly →
            </a>
          </div>
        </div>

        <div data-reveal className="reveal" style={{
          position: 'relative',
          background: 'var(--bg)',
          border: '1px solid var(--line-2)',
          padding: 40,
          minHeight: 440,
        }}>
          {/* Header */}
          <div style={{
            display: 'flex', justifyContent: 'space-between', alignItems: 'baseline',
            marginBottom: 32, paddingBottom: 16, borderBottom: '1px solid var(--line)',
          }}>
            <div style={{
              fontFamily: "'Geist Mono', monospace", fontSize: 11,
              color: 'var(--fg-dim)', letterSpacing: '0.14em',
            }}>
              {q.quarterLabel} · 13 WEEKS
            </div>
            <div style={{
              fontFamily: "'Geist Mono', monospace", fontSize: 11,
              color: 'var(--accent)', letterSpacing: '0.14em',
            }}>
              2 OPEN · 1 TAKEN
            </div>
          </div>

          {/* Week scale */}
          <div style={{
            display: 'grid',
            gridTemplateColumns: 'repeat(13, 1fr)',
            gap: 2,
            marginBottom: 6,
            paddingLeft: 80,
          }}>
            {Array.from({ length: 13 }).map((_, i) => (
              <div key={i} style={{
                fontSize: 9,
                fontFamily: "'Geist Mono', monospace",
                color: 'var(--fg-dim)',
                textAlign: 'center',
                letterSpacing: '0.04em',
              }}>
                W{String(i + 1).padStart(2, '0')}
              </div>
            ))}
          </div>

          {/* Lanes */}
          {[
            { label: 'Slot 01', status: 'taken', start: 0,  end: 12, co: 'Discovery in progress' },
            { label: 'Slot 02', status: 'open',  start: 3,  end: 12, co: 'Discovery calls this week' },
            { label: 'Slot 03', status: 'open',  start: 6,  end: 12, co: q.kickoffCopy },
          ].map((s, i) => {
            const cellW = `${(s.end - s.start + 1) * (100/13)}%`;
            const leftOff = `${s.start * (100/13)}%`;
            const taken = s.status === 'taken';
            return (
              <div key={i} style={{
                display: 'grid',
                gridTemplateColumns: '80px 1fr',
                gap: 0,
                alignItems: 'center',
                padding: '14px 0',
                borderTop: '1px solid var(--line)',
                borderBottom: i === 2 ? '1px solid var(--line)' : 'none',
              }}>
                <div>
                  <div style={{
                    fontFamily: "'Geist Mono', monospace", fontSize: 11,
                    color: 'var(--fg-dim)', letterSpacing: '0.12em',
                  }}>
                    {s.label.toUpperCase().replace(' ', ' · ')}
                  </div>
                  <div style={{
                    fontSize: 11,
                    color: taken ? 'var(--fg-dim)' : 'var(--accent)',
                    fontFamily: "'Geist Mono', monospace",
                    letterSpacing: '0.12em',
                    marginTop: 2,
                  }}>
                    {taken ? '● TAKEN' : '○ OPEN'}
                  </div>
                </div>
                <div style={{ position: 'relative', height: 36 }}>
                  {/* 13 week ticks */}
                  <div style={{
                    position: 'absolute', inset: 0,
                    display: 'grid',
                    gridTemplateColumns: 'repeat(13, 1fr)',
                    gap: 2,
                  }}>
                    {Array.from({ length: 13 }).map((_, j) => (
                      <div key={j} style={{
                        background: 'var(--line)',
                        opacity: 0.35,
                      }} />
                    ))}
                  </div>
                  {/* The actual slot bar */}
                  <div style={{
                    position: 'absolute',
                    left: leftOff, width: cellW,
                    top: 0, bottom: 0,
                    background: taken ? 'var(--line-2)' : 'transparent',
                    border: taken ? 'none' : '1px dashed var(--accent)',
                    display: 'flex', alignItems: 'center',
                    paddingLeft: 14,
                    fontSize: 11,
                    fontFamily: "'Geist Mono', monospace",
                    letterSpacing: '0.1em',
                    color: taken ? 'var(--fg-muted)' : 'var(--accent)',
                    animation: taken ? 'none' : 'slotPulse 2.4s ease-in-out infinite',
                  }}>
                    {s.co.toUpperCase()}
                  </div>
                </div>
              </div>
            );
          })}

          <div style={{
            marginTop: 28, fontSize: 12,
            color: 'var(--fg-dim)',
            fontFamily: "'Geist Mono', monospace",
            letterSpacing: '0.1em',
            display: 'flex', justifyContent: 'space-between',
            flexWrap: 'wrap', gap: 8,
          }}>
            <span>{q.nextCohortCopy.toUpperCase()}</span>
            <span>EACH SLOT IS ONE PROJECT · SCOPE TO HANDOVER · INSIDE YOUR COMPANY</span>
          </div>
        </div>
      </div>
    </section>
  );
}

/* ─── Final CTA — quieter ─── */
function FinalCTA() {
  const ref = useRef3();
  useReveal(ref);
  return (
    <section ref={ref} style={{
      position: 'relative',
      padding: '220px 48px 180px',
      overflow: 'hidden',
    }}>
      <div style={{ position: 'relative', maxWidth: 1400, margin: '0 auto' }}>
        <div style={{ maxWidth: 1100 }}>
          <h2 data-reveal className="reveal-up" style={{
            fontSize: 'clamp(56px, 8vw, 128px)',
            lineHeight: 0.98, letterSpacing: '-0.04em', fontWeight: 300,
            margin: '0 0 56px', textWrap: 'balance',
          }}>
            Build the system.<br/>
            <span className="serif">Keep the keys.</span>
          </h2>
          <p data-reveal className="reveal-up" style={{
            fontSize: 20, lineHeight: 1.6, color: 'var(--fg-muted)',
            maxWidth: 640, margin: '0 0 64px', textWrap: 'pretty',
          }}>
            If your next hire is <em>someone who gets growth, AI, and product</em>, talk to us first.
            One hour, no slides.
          </p>
          <div data-reveal className="reveal-up" style={{ display: 'flex', gap: 24, alignItems: 'center', flexWrap: 'wrap' }}>
            <HoverButton as="a" href={CAL_URL}>Book a discovery call</HoverButton>
            <a href={`mailto:${EMAIL}`} style={{
              fontSize: 15, color: 'var(--fg)',
              borderBottom: '1px solid var(--fg-faint)',
              paddingBottom: 2,
            }}>
              {EMAIL}
            </a>
          </div>
        </div>
      </div>
    </section>
  );
}

/* ─── Footer ─── */
function Footer() {
  return (
    <footer style={{
      padding: '48px 48px',
      borderTop: '1px solid var(--line)',
      background: 'var(--bg-2)',
      display: 'flex', justifyContent: 'space-between', alignItems: 'center',
      flexWrap: 'wrap', gap: 20,
      fontSize: 13, color: 'var(--fg-dim)',
    }}>
      <div>Syntari. The growth team you'd hire if you could find one.</div>
      <div style={{ display: 'flex', gap: 28 }}>
        <a href="#systems">Systems</a>
        <a href="#process">Process</a>
        <a href="#slots">Availability</a>
        <a href={`mailto:${EMAIL}`}>{EMAIL}</a>
      </div>
      <div>© 2026 Syntari. All rights reserved.</div>
    </footer>
  );
}

// Work component (Selected work / 05) was retired — case studies coming later.
// Tools stack and demo switcher in WhatWeShip carry the proof for now.
Object.assign(window, { Process, Slots, FinalCTA, Footer });
