// SitePages.jsx — page sections (Home / Services / Portfolio / About / Journal / Contact)
// All sections use shared atoms from SiteShared.jsx and pull copy from window.i18nContent[lang]

const Section = ({ id, label, children, bleed, dark }) => (
  <section id={id} data-screen-label={label} style={{
    padding: bleed ? 0 : 'clamp(80px, 9vw, 140px) clamp(24px, 5vw, 80px)',
    position: 'relative',
    background: dark ? 'rgba(0,0,0,0.35)' : 'transparent',
  }}>
    <div style={{ maxWidth: 1280, margin: '0 auto', position: 'relative' }}>{children}</div>
  </section>
);

const Eyebrow = ({ children }) => (
  <div style={{
    display: 'inline-flex', alignItems: 'center', gap: 10,
    fontFamily: 'var(--ssl-font-mono)', fontSize: 12, fontWeight: 500,
    letterSpacing: '0.16em', textTransform: 'uppercase',
    color: 'var(--ssl-accent)', marginBottom: 24,
  }}>
    <span style={{ width: 28, height: 1, background: 'currentColor' }}/>
    {children}
  </div>
);

// ─── HOME ─────────────────────────────────────────────────────────────────────
const HomeHero = ({ t, accent, motion, theme, navigate }) => {
  const [mouse, setMouse] = React.useState({ x: 0.5, y: 0.5 });
  React.useEffect(() => {
    if (motion === 'off') return;
    const h = (e) => setMouse({ x: e.clientX / window.innerWidth, y: e.clientY / window.innerHeight });
    window.addEventListener('mousemove', h); return () => window.removeEventListener('mousemove', h);
  }, [motion]);
  const txtColor = theme === 'light' ? '#0A0A0F' : 'white';
  return (
    <section data-screen-label="01 Home Hero" style={{
      position: 'relative',
      minHeight: '100vh',
      display: 'flex', flexDirection: 'column', justifyContent: 'center',
      padding: 'clamp(120px, 14vw, 180px) clamp(24px, 5vw, 80px) clamp(80px, 10vw, 120px)',
      overflow: 'hidden',
    }}>
      {/* photo backdrop */}
      <div style={{
        position: 'absolute', inset: 0, pointerEvents: 'none',
        backgroundImage: 'url(assets/portfolio/img_3610.jpg)',
        backgroundSize: 'cover', backgroundPosition: 'center',
        opacity: theme === 'light' ? 0.16 : 0.42,
      }}/>
      {/* legibility scrim over photo */}
      <div style={{
        position: 'absolute', inset: 0, pointerEvents: 'none',
        background: theme === 'light'
          ? 'linear-gradient(180deg, rgba(255,255,255,0.55) 0%, rgba(255,255,255,0.82) 55%, var(--ssl-bg) 100%)'
          : 'linear-gradient(180deg, rgba(10,10,15,0.55) 0%, rgba(10,10,15,0.72) 50%, var(--ssl-bg) 100%)',
      }}/>
      {/* spotlight bg */}
      <div style={{
        position: 'absolute', inset: 0, pointerEvents: 'none',
        background: theme === 'light'
          ? `radial-gradient(circle at ${mouse.x*100}% ${mouse.y*100}%, rgba(224,36,123,0.10), transparent 50%), radial-gradient(circle at 80% 20%, rgba(60,129,189,0.08), transparent 55%)`
          : `radial-gradient(circle at ${mouse.x*100}% ${mouse.y*100}%, rgba(224,36,123,0.18), transparent 45%), radial-gradient(circle at 80% 20%, rgba(60,129,189,0.16), transparent 55%), radial-gradient(circle at 20% 80%, rgba(110,46,165,0.20), transparent 50%)`,
        transition: motion === 'off' ? 'none' : 'background 600ms var(--ssl-ease-out)',
      }}/>
      {/* grid texture */}
      <div style={{ position: 'absolute', inset: 0, pointerEvents: 'none', opacity: theme === 'light' ? 0.4 : 0.5,
        backgroundImage: 'linear-gradient(' + (theme==='light'?'rgba(0,0,0,0.04)':'rgba(255,255,255,0.04)') + ' 1px, transparent 1px), linear-gradient(90deg, ' + (theme==='light'?'rgba(0,0,0,0.04)':'rgba(255,255,255,0.04)') + ' 1px, transparent 1px)',
        backgroundSize: '64px 64px',
        maskImage: 'radial-gradient(ellipse at center, black, transparent 75%)',
      }}/>
      <div style={{ maxWidth: 1280, margin: '0 auto', width: '100%', position: 'relative' }}>
        <Eyebrow>{t.hero.eyebrow}</Eyebrow>
        <h1 style={{
          fontFamily: 'var(--ssl-font-display)', fontWeight: 700,
          fontSize: 'clamp(48px, 8vw, 128px)',
          lineHeight: 0.94, letterSpacing: '-0.03em', margin: 0, color: txtColor,
          maxWidth: 1100,
        }}>
          {t.hero.title1}<br/>
          <span style={{ background: 'var(--ssl-gradient-stage)', WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent', backgroundClip: 'text', fontStyle: 'italic' }}>{t.hero.title2}</span>
        </h1>
        <p style={{
          fontFamily: 'var(--ssl-font-body)', fontSize: 'clamp(17px, 1.6vw, 22px)',
          lineHeight: 1.5, color: theme === 'light' ? 'rgba(10,10,15,0.72)' : 'rgba(255,255,255,0.72)',
          maxWidth: 640, marginTop: 36, fontWeight: 400,
        }}>{t.hero.lead}</p>
        <div style={{ display: 'flex', flexWrap: 'wrap', gap: 14, marginTop: 44 }}>
          <PrimaryBtn onClick={() => navigate('contact')}>{t.hero.cta1} <Icon name="arrow-right" size={16}/></PrimaryBtn>
          <SecondaryBtn theme={theme} onClick={() => navigate('portfolio')}>{t.hero.cta2}</SecondaryBtn>
        </div>
        <div style={{ display: 'flex', flexWrap: 'wrap', gap: 8, marginTop: 56 }}>
          {t.hero.pills.map((p, i) => (
            <span key={p} style={{
              fontFamily: 'var(--ssl-font-mono)', fontSize: 11, fontWeight: 500,
              letterSpacing: '0.1em', textTransform: 'uppercase',
              padding: '8px 14px', borderRadius: 999,
              border: '1px solid ' + (theme === 'light' ? 'rgba(0,0,0,0.12)' : 'rgba(255,255,255,0.12)'),
              color: theme === 'light' ? 'rgba(10,10,15,0.7)' : 'rgba(255,255,255,0.7)',
              background: theme === 'light' ? 'rgba(255,255,255,0.5)' : 'rgba(255,255,255,0.02)',
              backdropFilter: 'blur(4px)',
            }}>{p}</span>
          ))}
        </div>
      </div>
    </section>
  );
};

const StatsStrip = ({ t, theme }) => (
  <Section id="stats" label="02 Stats" dark={theme!=='light'}>
    <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(180px, 1fr))', gap: 0, borderTop: '1px solid var(--ssl-stroke-1)', borderBottom: '1px solid var(--ssl-stroke-1)' }}>
      {t.stats.map((s, i) => (
        <div key={i} style={{ padding: '40px 28px', borderLeft: i ? '1px solid var(--ssl-stroke-1)' : 0 }}>
          <div style={{ fontFamily: 'var(--ssl-font-display)', fontSize: 'clamp(40px, 5vw, 64px)', fontWeight: 700, lineHeight: 1, letterSpacing: '-0.02em', background: 'var(--ssl-gradient-stage)', WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent' }}>{s.num}</div>
          <div style={{ fontFamily: 'var(--ssl-font-body)', fontSize: 14, fontWeight: 600, marginTop: 14, color: theme==='light'?'#0A0A0F':'white' }}>{s.label}</div>
          <div style={{ fontFamily: 'var(--ssl-font-mono)', fontSize: 11, marginTop: 4, color: theme==='light'?'rgba(10,10,15,0.55)':'rgba(255,255,255,0.55)', letterSpacing: '0.04em' }}>{s.sub}</div>
        </div>
      ))}
    </div>
  </Section>
);

const Capabilities = ({ t, theme }) => (
  <Section id="capabilities" label="03 Why us">
    <div style={{ display: 'grid', gridTemplateColumns: 'minmax(0, 1fr) minmax(0, 1.2fr)', gap: 'clamp(40px, 6vw, 96px)' }}>
      <div>
        <Eyebrow>{t.capabilities.eyebrow}</Eyebrow>
        <h2 style={{ fontFamily: 'var(--ssl-font-display)', fontSize: 'clamp(32px, 4vw, 56px)', fontWeight: 700, lineHeight: 1.05, letterSpacing: '-0.02em', margin: 0, color: theme==='light'?'#0A0A0F':'white' }}>{t.capabilities.title}</h2>
        <p style={{ fontFamily: 'var(--ssl-font-body)', fontSize: 18, lineHeight: 1.55, color: theme==='light'?'rgba(10,10,15,0.65)':'rgba(255,255,255,0.65)', marginTop: 24 }}>{t.capabilities.sub}</p>
      </div>
      <ul style={{ listStyle: 'none', padding: 0, margin: 0, display: 'flex', flexDirection: 'column', gap: 0 }}>
        {t.capabilities.items.map((row, i) => (
          <li key={i} style={{ display: 'flex', gap: 18, padding: '24px 0', borderTop: '1px solid var(--ssl-stroke-1)', borderBottom: i === t.capabilities.items.length - 1 ? '1px solid var(--ssl-stroke-1)' : 0 }}>
            <span style={{ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', width: 32, height: 32, borderRadius: 8, background: 'var(--ssl-gradient-stage)', color: 'white', flexShrink: 0 }}><Icon name="check" size={16} stroke={2.5}/></span>
            <span style={{ fontFamily: 'var(--ssl-font-body)', fontSize: 18, lineHeight: 1.45, color: theme==='light'?'#0A0A0F':'white' }}>
              <strong style={{ fontWeight: 600 }}>{row[0]}</strong>
              <span style={{ color: theme==='light'?'rgba(10,10,15,0.65)':'rgba(255,255,255,0.65)', fontWeight: 400 }}>{row[1]}</span>
            </span>
          </li>
        ))}
      </ul>
    </div>
  </Section>
);

// ─── SERVICES ─────────────────────────────────────────────────────────────────
const Services = ({ t, theme }) => (
  <Section id="services" label="04 Services">
    <Eyebrow>{t.services.eyebrow}</Eyebrow>
    <h2 style={{ fontFamily: 'var(--ssl-font-display)', fontSize: 'clamp(36px, 5vw, 72px)', fontWeight: 700, lineHeight: 1.02, letterSpacing: '-0.025em', margin: 0, color: theme==='light'?'#0A0A0F':'white', maxWidth: 980 }}>
      {t.services.title1} <span style={{ fontStyle: 'italic', background: 'var(--ssl-gradient-stage)', WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent' }}>{t.services.title2}</span>
    </h2>
    <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(320px, 1fr))', gap: 1, marginTop: 64, background: 'var(--ssl-stroke-1)', border: '1px solid var(--ssl-stroke-1)', borderRadius: 14, overflow: 'hidden' }}>
      {t.services.list.map((s, i) => (
        <div key={s.name} style={{ padding: '36px 32px 32px', background: theme==='light'?'#fff':'var(--ssl-surface-1)', position: 'relative', overflow: 'hidden' }}>
          {s.featured && <div style={{ position: 'absolute', inset: 0, background: 'radial-gradient(circle at 100% 0%, rgba(224,36,123,0.10), transparent 60%)', pointerEvents: 'none' }}/>}
          <div style={{ position: 'relative' }}>
            <span style={{ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', width: 44, height: 44, borderRadius: 10, background: 'var(--ssl-gradient-stage)', color: 'white' }}><Icon name={s.name} size={22}/></span>
            <h3 style={{ fontFamily: 'var(--ssl-font-display)', fontSize: 24, fontWeight: 600, marginTop: 24, color: theme==='light'?'#0A0A0F':'white', letterSpacing: '-0.01em' }}>{s.title}</h3>
            <p style={{ fontFamily: 'var(--ssl-font-body)', fontSize: 15, lineHeight: 1.55, color: theme==='light'?'rgba(10,10,15,0.65)':'rgba(255,255,255,0.65)', marginTop: 12, marginBottom: 20 }}>{s.desc}</p>
            <div style={{ fontFamily: 'var(--ssl-font-mono)', fontSize: 11, color: 'var(--ssl-accent)', letterSpacing: '0.04em', paddingTop: 16, borderTop: '1px dashed var(--ssl-stroke-1)' }}>{s.specs}</div>
          </div>
        </div>
      ))}
    </div>
  </Section>
);

// ─── PORTFOLIO ────────────────────────────────────────────────────────────────
const Portfolio = ({ t, theme, treatment }) => {
  const [filter, setFilter] = React.useState(t.portfolio.filters[0]);
  const cases = t.portfolio.cases.filter(c => filter === t.portfolio.filters[0] || c.tag === filter);
  return (
    <Section id="portfolio" label="05 Portfolio">
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', flexWrap: 'wrap', gap: 24, marginBottom: 48 }}>
        <div>
          <Eyebrow>{t.portfolio.eyebrow}</Eyebrow>
          <h2 style={{ fontFamily: 'var(--ssl-font-display)', fontSize: 'clamp(36px, 4.5vw, 64px)', fontWeight: 700, lineHeight: 1.02, letterSpacing: '-0.025em', margin: 0, color: theme==='light'?'#0A0A0F':'white' }}>{t.portfolio.title}</h2>
        </div>
        <div style={{ display: 'flex', flexWrap: 'wrap', gap: 6 }}>
          {t.portfolio.filters.map(f => (
            <button key={f} onClick={() => setFilter(f)} style={{
              fontFamily: 'var(--ssl-font-mono)', fontSize: 11, letterSpacing: '0.1em', textTransform: 'uppercase',
              padding: '9px 14px', borderRadius: 999, cursor: 'pointer',
              border: '1px solid ' + (f === filter ? 'transparent' : 'var(--ssl-stroke-2)'),
              background: f === filter ? 'var(--ssl-gradient-stage)' : 'transparent',
              color: f === filter ? 'white' : (theme==='light'?'rgba(10,10,15,0.7)':'rgba(255,255,255,0.7)'),
              transition: 'all 240ms var(--ssl-ease-out)',
            }}>{f}</button>
          ))}
        </div>
      </div>
      {treatment === 'grid' && <PortfolioGrid cases={cases} theme={theme}/>}
      {treatment === 'mosaic' && <PortfolioMosaic cases={cases} theme={theme}/>}
      {treatment === 'scroll' && <PortfolioScroll cases={cases} theme={theme}/>}
      {treatment === 'fullbleed' && <PortfolioFullbleed cases={cases} theme={theme}/>}
    </Section>
  );
};

const CaseCard = ({ c, idx, theme, height = 280 }) => (
  <a href="#portfolio" style={{ textDecoration: 'none', display: 'block', cursor: 'pointer' }}
     onMouseEnter={e => { const ph = e.currentTarget.querySelector('.ph'); if (ph) ph.style.transform = 'scale(1.04)'; }}
     onMouseLeave={e => { const ph = e.currentTarget.querySelector('.ph'); if (ph) ph.style.transform = 'none'; }}>
    <div style={{ overflow: 'hidden', borderRadius: 16 }}>
      <div className="ph" style={{ transition: 'transform 600ms var(--ssl-ease-out)' }}>
        <Placeholder pin={c.pin} label={c.city} idx={idx} height={height} img={c.img}/>
      </div>
    </div>
    <div style={{ paddingTop: 18, display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', gap: 16 }}>
      <div style={{ minWidth: 0 }}>
        <h3 style={{ fontFamily: 'var(--ssl-font-display)', fontSize: 20, fontWeight: 600, color: theme==='light'?'#0A0A0F':'white', margin: 0, letterSpacing: '-0.01em' }}>{c.title}</h3>
        <div style={{ fontFamily: 'var(--ssl-font-mono)', fontSize: 11, marginTop: 6, color: theme==='light'?'rgba(10,10,15,0.55)':'rgba(255,255,255,0.55)', letterSpacing: '0.04em' }}>{c.meta} · {c.role}</div>
      </div>
    </div>
  </a>
);

const PortfolioGrid = ({ cases, theme }) => (
  <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(320px, 1fr))', gap: 32 }}>
    {cases.map((c, i) => <CaseCard key={i} c={c} idx={i} theme={theme}/>)}
  </div>
);

const PortfolioMosaic = ({ cases, theme }) => (
  <div style={{ display: 'grid', gridTemplateColumns: 'repeat(12, 1fr)', gap: 24 }}>
    {cases.map((c, i) => {
      // varying span pattern
      const span = [[7,360],[5,360],[5,300],[7,300],[6,320],[6,320],[8,340],[4,340]][i % 8];
      return <div key={i} style={{ gridColumn: 'span ' + span[0] }}><CaseCard c={c} idx={i} theme={theme} height={span[1]}/></div>;
    })}
  </div>
);

const PortfolioScroll = ({ cases, theme }) => (
  <div style={{ display: 'flex', gap: 24, overflowX: 'auto', paddingBottom: 24, scrollSnapType: 'x mandatory', margin: '0 calc(-1 * clamp(24px, 5vw, 80px))', padding: '0 clamp(24px, 5vw, 80px) 24px' }}>
    {cases.map((c, i) => (
      <div key={i} style={{ flex: '0 0 auto', width: 380, scrollSnapAlign: 'start' }}>
        <CaseCard c={c} idx={i} theme={theme} height={420}/>
      </div>
    ))}
  </div>
);

const PortfolioFullbleed = ({ cases, theme }) => (
  <div style={{ display: 'flex', flexDirection: 'column', gap: 80 }}>
    {cases.map((c, i) => (
      <div key={i} style={{ display: 'grid', gridTemplateColumns: i % 2 ? 'minmax(0, 1fr) minmax(0, 1.3fr)' : 'minmax(0, 1.3fr) minmax(0, 1fr)', gap: 40, alignItems: 'center' }}>
        <div style={{ order: i % 2 ? 2 : 1 }}>
          <Placeholder pin={c.pin} label={c.city} idx={i} height={460} img={c.img}/>
        </div>
        <div style={{ order: i % 2 ? 1 : 2 }}>
          <div style={{ fontFamily: 'var(--ssl-font-mono)', fontSize: 11, letterSpacing: '0.16em', textTransform: 'uppercase', color: 'var(--ssl-accent)' }}>{c.tag} · {c.meta}</div>
          <h3 style={{ fontFamily: 'var(--ssl-font-display)', fontSize: 'clamp(28px, 3vw, 44px)', fontWeight: 600, color: theme==='light'?'#0A0A0F':'white', margin: '12px 0 16px', letterSpacing: '-0.02em', lineHeight: 1.08 }}>{c.title}</h3>
          <div style={{ fontFamily: 'var(--ssl-font-body)', fontSize: 15, color: theme==='light'?'rgba(10,10,15,0.65)':'rgba(255,255,255,0.65)' }}>{c.role}</div>
        </div>
      </div>
    ))}
  </div>
);

// ─── ABOUT ────────────────────────────────────────────────────────────────────
const About = ({ t, theme }) => (
  <Section id="about" label="06 About" dark={theme!=='light'}>
    <Eyebrow>{t.about.eyebrow}</Eyebrow>
    <div style={{ display: 'grid', gridTemplateColumns: 'minmax(0, 1.2fr) minmax(0, 1fr)', gap: 'clamp(40px, 6vw, 96px)', alignItems: 'start' }}>
      <div>
        <h2 style={{ fontFamily: 'var(--ssl-font-display)', fontSize: 'clamp(36px, 4.5vw, 64px)', fontWeight: 700, lineHeight: 1.02, letterSpacing: '-0.025em', margin: 0, color: theme==='light'?'#0A0A0F':'white' }}>
          {t.about.title1} <span style={{ fontStyle: 'italic', background: 'var(--ssl-gradient-stage)', WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent' }}>{t.about.title2}</span>
        </h2>
        <p style={{ fontFamily: 'var(--ssl-font-body)', fontSize: 18, lineHeight: 1.6, color: theme==='light'?'rgba(10,10,15,0.7)':'rgba(255,255,255,0.7)', marginTop: 32, maxWidth: 640 }}>{t.about.body}</p>
      </div>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 0, border: '1px solid var(--ssl-stroke-1)', borderRadius: 14, overflow: 'hidden' }}>
        {t.about.principles.map((p, i) => (
          <div key={i} style={{ padding: '24px 24px', borderTop: i ? '1px solid var(--ssl-stroke-1)' : 0 }}>
            <div style={{ fontFamily: 'var(--ssl-font-display)', fontSize: 18, fontWeight: 600, color: theme==='light'?'#0A0A0F':'white', marginBottom: 8 }}>{p.t}</div>
            <div style={{ fontFamily: 'var(--ssl-font-body)', fontSize: 14, lineHeight: 1.55, color: theme==='light'?'rgba(10,10,15,0.65)':'rgba(255,255,255,0.65)' }}>{p.d}</div>
          </div>
        ))}
      </div>
    </div>
    <div style={{ marginTop: 80, display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(220px, 1fr))', gap: 24 }}>
      {t.about.team.map((m, i) => (
        <div key={i}>
          <div style={{ aspectRatio: '4/5', borderRadius: 14, overflow: 'hidden' }}>
            <Placeholder idx={(i+1)*2} height="100%"/>
          </div>
          <div style={{ marginTop: 16, fontFamily: 'var(--ssl-font-display)', fontSize: 18, fontWeight: 600, color: theme==='light'?'#0A0A0F':'white' }}>{m.name}</div>
          <div style={{ fontFamily: 'var(--ssl-font-mono)', fontSize: 11, marginTop: 4, color: theme==='light'?'rgba(10,10,15,0.55)':'rgba(255,255,255,0.55)', letterSpacing: '0.04em' }}>{m.role}</div>
        </div>
      ))}
    </div>
  </Section>
);

// ─── JOURNAL ──────────────────────────────────────────────────────────────────
const Journal = ({ t, theme }) => (
  <Section id="journal" label="07 Journal">
    <Eyebrow>{t.journal.eyebrow}</Eyebrow>
    <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', flexWrap: 'wrap', gap: 24 }}>
      <h2 style={{ fontFamily: 'var(--ssl-font-display)', fontSize: 'clamp(36px, 4.5vw, 64px)', fontWeight: 700, lineHeight: 1.02, letterSpacing: '-0.025em', margin: 0, color: theme==='light'?'#0A0A0F':'white' }}>{t.journal.title}</h2>
      <p style={{ fontFamily: 'var(--ssl-font-body)', fontSize: 16, color: theme==='light'?'rgba(10,10,15,0.65)':'rgba(255,255,255,0.65)', maxWidth: 360, margin: 0 }}>{t.journal.sub}</p>
    </div>
    <div style={{ marginTop: 56, borderTop: '1px solid var(--ssl-stroke-1)' }}>
      {t.journal.posts.map((p, i) => (
        <a key={i} href="#journal" style={{ display: 'grid', gridTemplateColumns: '120px minmax(0, 1fr) 140px 32px', alignItems: 'center', gap: 24, padding: '28px 0', borderBottom: '1px solid var(--ssl-stroke-1)', textDecoration: 'none', transition: 'background 240ms var(--ssl-ease-out)' }}
            onMouseEnter={e => { e.currentTarget.style.background = theme==='light' ? 'rgba(0,0,0,0.02)' : 'rgba(255,255,255,0.02)'; const a = e.currentTarget.querySelector('.arrow'); if(a){a.style.transform='translateX(6px)'; a.style.color='var(--ssl-accent)';} }}
            onMouseLeave={e => { e.currentTarget.style.background = 'transparent'; const a = e.currentTarget.querySelector('.arrow'); if(a){a.style.transform='none'; a.style.color = theme==='light'?'rgba(10,10,15,0.4)':'rgba(255,255,255,0.4)';} }}>
          <div style={{ fontFamily: 'var(--ssl-font-mono)', fontSize: 11, color: 'var(--ssl-accent)', letterSpacing: '0.1em', textTransform: 'uppercase' }}>{p.tag}</div>
          <h3 style={{ fontFamily: 'var(--ssl-font-display)', fontSize: 22, fontWeight: 500, color: theme==='light'?'#0A0A0F':'white', margin: 0, letterSpacing: '-0.01em', lineHeight: 1.25 }}>{p.title}</h3>
          <div style={{ fontFamily: 'var(--ssl-font-mono)', fontSize: 11, color: theme==='light'?'rgba(10,10,15,0.55)':'rgba(255,255,255,0.55)', letterSpacing: '0.04em' }}>{p.date} · {p.read}</div>
          <span className="arrow" style={{ color: theme==='light'?'rgba(10,10,15,0.4)':'rgba(255,255,255,0.4)', transition: 'all 240ms var(--ssl-ease-out)' }}><Icon name="arrow-right" size={20}/></span>
        </a>
      ))}
    </div>
  </Section>
);

// ─── CONTACT ──────────────────────────────────────────────────────────────────
const LEAD_INTAKE_URL = 'https://leadintake-ose4knk64a-uc.a.run.app';

const Contact = ({ t, theme, locale }) => {
  const [status, setStatus] = React.useState('idle'); // 'idle' | 'sending' | 'sent' | 'error'
  const [errorMsg, setErrorMsg] = React.useState('');

  const handleSubmit = async (e) => {
    e.preventDefault();
    if (status === 'sending') return;
    setStatus('sending');
    setErrorMsg('');

    const fd = new FormData(e.currentTarget);
    const payload = {
      name: fd.get('name') || '',
      email: fd.get('email') || '',
      phone: fd.get('phone') || '',
      event: fd.get('event') || '',
      date: fd.get('date') || '',
      kind: fd.get('kind') || '',
      notes: fd.get('notes') || '',
      website: fd.get('website') || '', // honeypot
      locale: locale || 'en',
    };

    try {
      const resp = await fetch(LEAD_INTAKE_URL, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(payload),
      });
      const data = await resp.json().catch(() => ({}));
      if (resp.ok && data.ok) {
        setStatus('sent');
        if (window.gtag) {
          window.gtag('event', 'generate_lead', { value: 1, currency: 'USD' });
        }
      } else {
        setStatus('error');
        setErrorMsg(data.error || (t.contact.errorBody || 'Something went wrong'));
      }
    } catch (err) {
      setStatus('error');
      setErrorMsg(t.contact.errorBody || 'Network error. Please try again.');
    }
  };

  return (
    <Section id="contact" label="08 Contact" dark={theme!=='light'}>
      <Eyebrow>{t.contact.eyebrow}</Eyebrow>
      <div style={{ display: 'grid', gridTemplateColumns: 'minmax(0, 1fr) minmax(0, 1fr)', gap: 'clamp(40px, 6vw, 96px)', alignItems: 'start' }}>
        <div>
          <h2 style={{ fontFamily: 'var(--ssl-font-display)', fontSize: 'clamp(36px, 4.5vw, 64px)', fontWeight: 700, lineHeight: 1.02, letterSpacing: '-0.025em', margin: 0, color: theme==='light'?'#0A0A0F':'white' }}>
            {t.contact.title1} <span style={{ fontStyle: 'italic', background: 'var(--ssl-gradient-stage)', WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent' }}>{t.contact.title2}</span>
          </h2>
          <p style={{ fontFamily: 'var(--ssl-font-body)', fontSize: 18, lineHeight: 1.55, color: theme==='light'?'rgba(10,10,15,0.7)':'rgba(255,255,255,0.7)', marginTop: 24, maxWidth: 480 }}>{t.contact.lead}</p>
          <div style={{ marginTop: 48, display: 'flex', flexDirection: 'column', gap: 0, borderTop: '1px solid var(--ssl-stroke-1)' }}>
            {t.contact.direct.map((d, i) => (
              <div key={i} style={{ display: 'flex', alignItems: 'center', gap: 16, padding: '18px 0', borderBottom: '1px solid var(--ssl-stroke-1)' }}>
                <span style={{ color: 'var(--ssl-accent)' }}><Icon name={d.icon} size={18}/></span>
                <span style={{ fontFamily: 'var(--ssl-font-mono)', fontSize: 11, color: theme==='light'?'rgba(10,10,15,0.55)':'rgba(255,255,255,0.55)', letterSpacing: '0.1em', textTransform: 'uppercase', minWidth: 110 }}>{d.lbl}</span>
                <span style={{ fontFamily: 'var(--ssl-font-body)', fontSize: 16, color: theme==='light'?'#0A0A0F':'white' }}>{d.val}</span>
              </div>
            ))}
          </div>
        </div>
        <div style={{ background: theme==='light' ? '#fff' : 'var(--ssl-surface-1)', border: '1px solid var(--ssl-stroke-1)', borderRadius: 16, padding: 'clamp(28px, 3vw, 40px)' }}>
          {status !== 'sent' ? (
            <form onSubmit={handleSubmit} style={{ display: 'flex', flexDirection: 'column', gap: 20 }}>
              <FormField name="name" required label={t.contact.labels.name} placeholder={t.contact.placeholders.name} theme={theme}/>
              <div style={{ display: 'grid', gridTemplateColumns: 'minmax(0, 1fr) minmax(0, 1fr)', gap: 16 }}>
                <FormField name="email" required label={t.contact.labels.email} placeholder={t.contact.placeholders.email} type="email" theme={theme}/>
                <FormField name="phone" label={t.contact.labels.phone} placeholder={t.contact.placeholders.phone} type="tel" theme={theme}/>
              </div>
              <div style={{ display: 'grid', gridTemplateColumns: 'minmax(0, 1fr) minmax(0, 1fr)', gap: 16 }}>
                <FormField name="event" required label={t.contact.labels.event} placeholder={t.contact.placeholders.event} theme={theme}/>
                <FormField name="date" label={t.contact.labels.date} placeholder={t.contact.placeholders.date} theme={theme}/>
              </div>
              <FormSelect name="kind" label={t.contact.labels.kind} options={t.contact.kinds} theme={theme}/>
              <FormField name="notes" label={t.contact.labels.notes} placeholder={t.contact.placeholders.notes} multiline theme={theme}/>
              {/* Honeypot — hidden from humans, bots tend to fill all fields */}
              <input
                type="text"
                name="website"
                tabIndex="-1"
                autoComplete="off"
                style={{ position: 'absolute', left: '-9999px', width: 1, height: 1, opacity: 0 }}
                aria-hidden="true"
              />
              {status === 'error' && (
                <div style={{
                  padding: '12px 14px', borderRadius: 10, fontSize: 14,
                  background: 'rgba(224,36,123,0.08)', border: '1px solid rgba(224,36,123,0.3)',
                  color: theme==='light'?'#0A0A0F':'#fff'
                }}>
                  {errorMsg}
                </div>
              )}
              <div style={{ marginTop: 8 }}>
                <PrimaryBtn type="submit" disabled={status === 'sending'}>
                  {status === 'sending'
                    ? (t.contact.labels.sending || 'Sending…')
                    : t.contact.labels.send} <Icon name="arrow-right" size={16}/>
                </PrimaryBtn>
              </div>
            </form>
          ) : (
            <div style={{ padding: '32px 8px', textAlign: 'center' }}>
              <div style={{ width: 56, height: 56, borderRadius: 14, background: 'var(--ssl-gradient-stage)', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', color: 'white', marginBottom: 20 }}><Icon name="check" size={26} stroke={2.5}/></div>
              <h3 style={{ fontFamily: 'var(--ssl-font-display)', fontSize: 26, fontWeight: 600, margin: 0, color: theme==='light'?'#0A0A0F':'white', letterSpacing: '-0.01em' }}>{t.contact.sent.title}</h3>
              <p style={{ fontFamily: 'var(--ssl-font-body)', fontSize: 16, marginTop: 12, color: theme==='light'?'rgba(10,10,15,0.65)':'rgba(255,255,255,0.65)' }}>{t.contact.sent.body}</p>
              <button onClick={() => setStatus('idle')} style={{ marginTop: 24, fontFamily: 'var(--ssl-font-body)', fontSize: 14, fontWeight: 500, padding: '10px 18px', borderRadius: 8, border: '1px solid var(--ssl-stroke-2)', background: 'transparent', color: theme==='light'?'#0A0A0F':'white', cursor: 'pointer' }}>{t.contact.sent.again}</button>
            </div>
          )}
        </div>
      </div>
    </Section>
  );
};

const FormField = ({ name, label, placeholder, type = 'text', multiline, required, theme }) => (
  <label style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
    <span style={{ fontFamily: 'var(--ssl-font-mono)', fontSize: 11, fontWeight: 500, letterSpacing: '0.1em', textTransform: 'uppercase', color: theme==='light'?'rgba(10,10,15,0.55)':'rgba(255,255,255,0.55)' }}>{label}{required ? ' *' : ''}</span>
    {multiline ? (
      <textarea name={name} required={required} placeholder={placeholder} rows={4} style={inputStyle(theme)}/>
    ) : (
      <input name={name} required={required} type={type} placeholder={placeholder} style={inputStyle(theme)}/>
    )}
  </label>
);

const FormSelect = ({ name, label, options, theme }) => (
  <label style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
    <span style={{ fontFamily: 'var(--ssl-font-mono)', fontSize: 11, fontWeight: 500, letterSpacing: '0.1em', textTransform: 'uppercase', color: theme==='light'?'rgba(10,10,15,0.55)':'rgba(255,255,255,0.55)' }}>{label}</span>
    <select name={name} style={{ ...inputStyle(theme), appearance: 'none', backgroundImage: `url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='${theme==='light'?'%230A0A0F':'%23ffffff'}' stroke-width='2'><polyline points='6 9 12 15 18 9'/></svg>")`, backgroundRepeat: 'no-repeat', backgroundPosition: 'right 14px center', paddingRight: 38 }}>
      {options.map(o => <option key={o}>{o}</option>)}
    </select>
  </label>
);

const inputStyle = (theme) => ({
  fontFamily: 'var(--ssl-font-body)', fontSize: 15,
  padding: '12px 14px', borderRadius: 10,
  border: '1px solid var(--ssl-stroke-2)',
  background: theme==='light' ? 'rgba(0,0,0,0.02)' : 'rgba(255,255,255,0.04)',
  color: theme==='light' ? '#0A0A0F' : 'white',
  outline: 'none', transition: 'border 200ms var(--ssl-ease-out)',
  resize: 'vertical',
});

window.HomeHero = HomeHero;
window.StatsStrip = StatsStrip;
window.Capabilities = Capabilities;
window.Services = Services;
window.Portfolio = Portfolio;
window.About = About;
window.Journal = Journal;
window.Contact = Contact;
window.Eyebrow = Eyebrow;
window.Section = Section;
