// Atelier Vitrine — landing page React component
// Parametrized by `accent` ({hex, name, ink}). Two instances live side-by-side
// on the design canvas (bleu profond vs terracotta).

// ─── CONFIG ENVOI DE FORMULAIRE (Formspree) ────────────────────
// Endpoint connecté au compte d'Allan (destinataire : allan.faquin@gmail.com).
// Accusé de réception au prospect : à activer via "Autoresponse" dans les
// réglages du formulaire sur le dashboard Formspree.
const FORMSPREE_ENDPOINT = 'https://formspree.io/f/mzdqzlez';

const PALETTES = {
  bleu: {
    name: 'Bleu profond',
    accent: '#1E3A5F', // deep navy-blue
    accentDeep: '#16263F',
    accentSoft: '#E8EDF3',
    onAccent: '#F8F5F0'
  },
  terracotta: {
    name: 'Terracotta',
    accent: '#B5552E', // sober terracotta
    accentDeep: '#8C3F1E',
    accentSoft: '#F1E5DC',
    onAccent: '#F8F5F0'
  }
};

const CREAM = '#F8F5F0';
const CREAM_DEEP = '#EFE9DF';
const INK = '#1F2937';
const INK_SOFT = '#4B5563';
const HAIR = '#D9D2C5';

// ── Tiny SVG icon set (line, hand-drawn-ish) ───────────────────
const Icon = {
  Phone: (p) =>
  <svg viewBox="0 0 24 24" width={p.s || 18} height={p.s || 18} fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
      <path d="M5 4h4l2 5-2.5 1.5a11 11 0 0 0 5 5L15 13l5 2v4a2 2 0 0 1-2 2A15 15 0 0 1 3 6a2 2 0 0 1 2-2z" />
    </svg>,

  Arrow: (p) =>
  <svg viewBox="0 0 24 24" width={p.s || 16} height={p.s || 16} fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
      <path d="M5 12h14M13 6l6 6-6 6" />
    </svg>,

  Check: (p) =>
  <svg viewBox="0 0 24 24" width={p.s || 18} height={p.s || 18} fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="M4 12l5 5L20 6" />
    </svg>,

  Pin: (p) =>
  <svg viewBox="0 0 24 24" width={p.s || 22} height={p.s || 22} fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
      <path d="M12 21s7-7 7-12a7 7 0 1 0-14 0c0 5 7 12 7 12z" /><circle cx="12" cy="9" r="2.5" />
    </svg>,

  Tag: (p) =>
  <svg viewBox="0 0 24 24" width={p.s || 22} height={p.s || 22} fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
      <path d="M3 12V4h8l10 10-8 8-10-10z" /><circle cx="7.5" cy="7.5" r="1.2" />
    </svg>,

  Clock: (p) =>
  <svg viewBox="0 0 24 24" width={p.s || 22} height={p.s || 22} fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="12" cy="12" r="9" /><path d="M12 7v5l3 2" />
    </svg>,

  Chat: (p) =>
  <svg viewBox="0 0 24 24" width={p.s || 26} height={p.s || 26} fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
      <path d="M4 5h16v11H9l-5 4z" />
    </svg>,

  Hammer: (p) =>
  <svg viewBox="0 0 24 24" width={p.s || 26} height={p.s || 26} fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
      <path d="M14 4l6 6-3 3-6-6 3-3z" /><path d="M11 7l-7 7 3 3 7-7" /><path d="M5 17l-2 2 2 2 2-2" />
    </svg>,

  Tools: (p) =>
  <svg viewBox="0 0 24 24" width={p.s || 26} height={p.s || 26} fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round">
      <path d="M14.7 6.3a4 4 0 0 1 5 5l-1.4-1.4-2.1.6-.6 2.1 1.4 1.4a4 4 0 0 1-5-5" />
      <path d="M13.3 12.7l-7.6 7.6a1.5 1.5 0 0 1-2.1-2.1l7.6-7.6" />
    </svg>,

  Send: (p) =>
  <svg viewBox="0 0 24 24" width={p.s || 22} height={p.s || 22} fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
      <path d="M21 3L3 11l7 3 3 7z" /><path d="M21 3l-11 11" />
    </svg>,

  Close: (p) =>
  <svg viewBox="0 0 24 24" width={p.s || 20} height={p.s || 20} fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round">
      <path d="M6 6l12 12M18 6L6 18" />
    </svg>

};

// ── Hand-drawn rule (top of every section) ─────────────────────
function Rule({ accent }) {
  return (
    <div style={{ display: 'flex', alignItems: 'center', gap: 14, color: accent, fontSize: 12, letterSpacing: '.18em', textTransform: 'uppercase', fontWeight: 600 }}>
      <span style={{ width: 36, height: 1, background: accent, opacity: .5 }} />
    </div>);

}

// ── Photo placeholder — labeled, sober ─────────────────────────
function Photo({ label, h = '100%', tone = 'warm', children, style }) {
  // soft warm gradients to evoke 'chantier / atelier' lighting without faking it
  const grads = {
    warm: 'linear-gradient(135deg,#C9B89A 0%,#8A7657 60%,#5C4A33 100%)',
    cool: 'linear-gradient(135deg,#A8B0B8 0%,#6F7884 60%,#3F4753 100%)',
    wood: 'linear-gradient(135deg,#B7926A 0%,#7E5A38 60%,#4A331C 100%)',
    stone: 'linear-gradient(135deg,#BDB8AE 0%,#857F73 60%,#4F4A40 100%)'
  };
  return (
    <div style={{
      position: 'relative', width: '100%', height: h, overflow: 'hidden',
      background: grads[tone] || grads.warm,
      ...style
    }}>
      {/* film grain */}
      <div style={{ position: 'absolute', inset: 0, opacity: .18, mixBlendMode: 'overlay',
        backgroundImage: 'radial-gradient(circle at 20% 30%, #fff 0, transparent 40%), radial-gradient(circle at 80% 70%, #000 0, transparent 50%)' }} />
      <div style={{ position: 'absolute', left: 14, bottom: 12,
        fontSize: 11, letterSpacing: '.16em', textTransform: 'uppercase',
        color: 'rgba(255,255,255,.85)', fontFamily: 'var(--av-sans)', fontWeight: 500,
        display: 'flex', alignItems: 'center', gap: 8 }}>
        <span style={{ width: 6, height: 6, background: 'rgba(255,255,255,.85)', borderRadius: '50%' }} />
        {label}
      </div>
      {children}
    </div>);

}

// ── Mini browser mockup (used in portfolio cards) ──────────────
function BrowserMock({ accent, accentSoft, metier, tone = 'warm' }) {
  return (
    <div style={{
      background: '#fff', borderRadius: 6, overflow: 'hidden',
      boxShadow: '0 1px 0 rgba(0,0,0,.04), 0 8px 24px -8px rgba(31,41,55,.18)',
      border: `1px solid ${HAIR}`
    }}>
      <div style={{ display: 'flex', alignItems: 'center', gap: 5, padding: '8px 10px', background: '#F4EFE6', borderBottom: `1px solid ${HAIR}` }}>
        <span style={{ width: 9, height: 9, borderRadius: '50%', background: '#D9D2C5' }} />
        <span style={{ width: 9, height: 9, borderRadius: '50%', background: '#D9D2C5' }} />
        <span style={{ width: 9, height: 9, borderRadius: '50%', background: '#D9D2C5' }} />
        <span style={{ flex: 1, marginLeft: 8, height: 14, borderRadius: 3, background: '#fff', fontSize: 9, color: INK_SOFT, padding: '1px 8px', display: 'flex', alignItems: 'center', fontFamily: 'var(--av-sans)' }}>{metier.toLowerCase().replace(/[^a-z]/g, '')}.fr</span>
      </div>
      <div style={{ aspectRatio: '16/10', position: 'relative' }}>
        <Photo tone={tone} label={metier} h="100%" />
        <div style={{ position: 'absolute', inset: 0, padding: '14px 16px', display: 'flex', flexDirection: 'column', justifyContent: 'space-between' }}>
          <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
            <div style={{ fontFamily: 'var(--av-serif)', color: '#fff', fontSize: 13, fontWeight: 500, letterSpacing: '.02em' }}>{metier.split('—')[0].trim()}</div>
            <div style={{ display: 'flex', gap: 10, fontSize: 8, color: 'rgba(255,255,255,.85)', letterSpacing: '.1em', textTransform: 'uppercase', fontFamily: 'var(--av-sans)' }}>
              <span>Accueil</span><span>Réalisations</span><span>Contact</span>
            </div>
          </div>
          <div>
            <div style={{ fontFamily: 'var(--av-serif)', color: '#fff', fontSize: 18, lineHeight: 1.15, maxWidth: '70%', fontWeight: 500 }}>
              Du travail soigné,<br />fait pour durer.
            </div>
            <div style={{ marginTop: 10, display: 'inline-block', background: accent, color: '#fff', fontSize: 8.5, letterSpacing: '.12em', textTransform: 'uppercase', padding: '6px 10px', fontFamily: 'var(--av-sans)', fontWeight: 600 }}>
              Devis gratuit
            </div>
          </div>
        </div>
      </div>
    </div>);

}

// ── Mini phone mockup (sits next to browser) ───────────────────
function PhoneMock({ accent, metier, tone = 'warm' }) {
  return (
    <div style={{
      width: 64, background: '#1F2937', borderRadius: 9, padding: 3,
      boxShadow: '0 8px 18px -6px rgba(0,0,0,.35)',
      flexShrink: 0
    }}>
      <div style={{ borderRadius: 7, overflow: 'hidden', position: 'relative', aspectRatio: '9/19' }}>
        <Photo tone={tone} label="" h="100%" />
        <div style={{ position: 'absolute', inset: 0, padding: '8px 6px', display: 'flex', flexDirection: 'column', justifyContent: 'space-between' }}>
          <div style={{ height: 3, width: 18, background: 'rgba(255,255,255,.5)', borderRadius: 2, margin: '0 auto' }} />
          <div>
            <div style={{ fontFamily: 'var(--av-serif)', color: '#fff', fontSize: 8, lineHeight: 1.1, fontWeight: 500 }}>Travail<br />soigné.</div>
            <div style={{ marginTop: 6, background: accent, color: '#fff', fontSize: 5, letterSpacing: '.08em', textTransform: 'uppercase', padding: '3px 4px', textAlign: 'center', fontFamily: 'var(--av-sans)', fontWeight: 600 }}>
              Devis
            </div>
          </div>
        </div>
      </div>
    </div>);

}

// ── Process step number (engraved-feel) ────────────────────────
function StepNumber({ n, accent }) {
  return (
    <div style={{
      width: 54, height: 54, borderRadius: '50%',
      border: `1.5px solid ${accent}`, color: accent,
      display: 'flex', alignItems: 'center', justifyContent: 'center',
      fontFamily: 'var(--av-serif)', fontSize: 24, fontWeight: 500,
      flexShrink: 0
    }}>{n}</div>);

}

// ── PORTFOLIO DATA ─────────────────────────────────────────────
const PROJECTS = [
{ metier: 'Charpentier — Limoux', result: '+12 demandes de devis le premier mois.', tone: 'wood' },
{ metier: 'Maçon — Carcassonne', result: '3 chantiers signés en 6 semaines.', tone: 'stone' },
{ metier: 'Menuisier — Quillan', result: 'Plus visible que ses 2 concurrents locaux.', tone: 'wood' },
{ metier: 'Électricien — Castelnaudary', result: '+8 appels par semaine, en moyenne.', tone: 'cool' },
{ metier: 'Couvreur — Limoux', result: 'Un site clair, aussi pro que son travail.', tone: 'warm' },
{ metier: 'Paysagiste — Trèbes', result: 'Devis signés dès la 2e semaine en ligne.', tone: 'warm' }];


// ─── HEADER ────────────────────────────────────────────────────
function Header({ accent, onCta }) {
  return (
    <header style={{
      position: 'absolute', top: 0, left: 0, right: 0, zIndex: 5,
      padding: '22px 40px', display: 'flex', alignItems: 'center', justifyContent: 'space-between',
      color: '#F8F5F0'
    }}>
      <div style={{ fontFamily: 'var(--av-serif)', fontSize: 22, fontWeight: 500, letterSpacing: '.01em' }}>
        Atelier Vitrine
      </div>
      <nav style={{ display: 'flex', alignItems: 'center', gap: 30, fontFamily: 'var(--av-sans)', fontSize: 13, fontWeight: 500 }}>
        <a href="#realisations" style={{ color: '#F8F5F0', textDecoration: 'none', opacity: .85 }}>Réalisations</a>
        <a href="#process" style={{ color: '#F8F5F0', textDecoration: 'none', opacity: .85 }}>Comment ça se passe</a>
        <a href="#pourquoi" style={{ color: '#F8F5F0', textDecoration: 'none', opacity: .85 }}>Pourquoi moi</a>
        <button onClick={onCta} style={{
          background: 'transparent', border: `1px solid rgba(248,245,240,.6)`, color: '#F8F5F0',
          padding: '9px 16px', fontSize: 12, letterSpacing: '.08em', textTransform: 'uppercase', fontWeight: 600,
          cursor: 'pointer', fontFamily: 'var(--av-sans)'
        }}>Demander un devis</button>
      </nav>
    </header>);

}

// ─── HERO ──────────────────────────────────────────────────────
function Hero({ palette, onCta, onPortfolio, tweaks }) {
  const M = MOODS[tweaks.mood], V = VOICES[tweaks.voice], L = LAYOUTS[tweaks.layout];
  const overlay = M.overlay.replace('%ACCENT%', palette.accentDeep);
  return (
    <section style={{ position: 'relative', minHeight: 760, color: CREAM }}>
      {/* Background photo */}
      <Photo label="Photo · Charpente en cours, atelier Limoux" h="100%" tone={M.tone} style={{ position: 'absolute', inset: 0 }} />
      {/* Tint overlay for legibility */}
      <div style={{ position: 'absolute', inset: 0, background: overlay }} />

      <Header accent={palette.accent} onCta={onCta} />

      <div style={{ position: 'relative', padding: '180px 40px 110px', maxWidth: 1200, margin: '0 auto' }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 14, marginBottom: 28, fontSize: 12, letterSpacing: '.2em', textTransform: 'uppercase', fontWeight: 600, opacity: .92, fontFamily: 'var(--av-sans)' }}>
          <span style={{ width: 32, height: 1, background: '#F8F5F0', opacity: .7 }} />
          {V.eyebrow}
        </div>

        <h1 style={{
          fontFamily: 'var(--av-serif)', fontSize: L.heroSize, lineHeight: 1.04,
          fontWeight: 400, margin: 0, maxWidth: 920, letterSpacing: '-.015em',
          textWrap: 'balance'
        }}>
          {V.h1a} <em style={{ fontStyle: 'italic', fontWeight: 400, color: CREAM }}>{V.h1b}</em>
        </h1>

        <p style={{
          fontFamily: 'var(--av-sans)', fontSize: L.leadSize, lineHeight: 1.55,
          maxWidth: 580, marginTop: 28, color: 'rgba(248,245,240,.9)', fontWeight: 400
        }}>
          {V.sub}
        </p>

        <div style={{ marginTop: 44, display: 'flex', alignItems: 'center', gap: 18, flexWrap: 'wrap' }}>
          <button onClick={onCta} style={{
            background: palette.accent, color: '#F8F5F0', border: 'none',
            padding: '18px 28px', fontSize: 14, letterSpacing: '.08em',
            textTransform: 'uppercase', fontWeight: 700, cursor: 'pointer',
            fontFamily: 'var(--av-sans)', display: 'inline-flex', alignItems: 'center', gap: 12,
            boxShadow: '0 4px 0 rgba(0,0,0,.18)'
          }}>
            {V.cta} <Icon.Arrow s={16} />
          </button>
          <button onClick={onPortfolio} style={{
            background: 'transparent', color: '#F8F5F0', border: '1px solid rgba(248,245,240,.5)',
            padding: '17px 24px', fontSize: 14, letterSpacing: '.08em',
            textTransform: 'uppercase', fontWeight: 600, cursor: 'pointer',
            fontFamily: 'var(--av-sans)'
          }}>
            {V.secondary}
          </button>
        </div>

        {/* Trust strip */}
        <div style={{
          marginTop: 80, display: 'flex', alignItems: 'center', gap: 32, flexWrap: 'wrap',
          paddingTop: 30, borderTop: '1px solid rgba(248,245,240,.2)',
          fontFamily: 'var(--av-sans)', fontSize: 13, color: 'rgba(248,245,240,.85)'
        }}>
          <span style={{ display: 'flex', alignItems: 'center', gap: 10 }}><Icon.Pin s={18} /> Aude</span>
          <span style={{ opacity: .4 }}>·</span>
          <span style={{ display: 'flex', alignItems: 'center', gap: 10 }}><Icon.Clock s={18} /> Livré en moins de 10 jours</span>
          <span style={{ opacity: .4 }}>·</span>
          <span style={{ display: 'flex', alignItems: 'center', gap: 10 }}><Icon.Tag s={18} /> Tarif fixe, annoncé d'avance</span>
        </div>
      </div>
    </section>);

}

// ─── PORTFOLIO ─────────────────────────────────────────────────
function Portfolio({ palette, onOpen, tweaks }) {
  const V = VOICES[tweaks.voice], L = LAYOUTS[tweaks.layout], M = MOODS[tweaks.mood];
  const portfolioTones = M.portfolio.split('-');
  const projects = PROJECTS.map((p, i) => ({ ...p, tone: portfolioTones[i % portfolioTones.length] || p.tone }));
  return (
    <section id="realisations" style={{ background: CREAM, padding: `${L.sectionPad}px 40px` }}>
      <div style={{ maxWidth: 1200, margin: '0 auto' }}>
        <Rule accent={palette.accent} />
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', gap: 40, marginTop: 14, flexWrap: 'wrap' }}>
          <h2 style={{
            fontFamily: 'var(--av-serif)', fontSize: L.sectionSize, lineHeight: 1.05, fontWeight: 400,
            color: INK, margin: 0, maxWidth: 680, letterSpacing: '-.01em'
          }}>
            {V.portfolioH} <em style={{ fontStyle: 'italic' }}>{V.portfolioHi}</em>
          </h2>
          <p style={{ fontFamily: 'var(--av-sans)', fontSize: L.sublead, color: INK_SOFT, maxWidth: 340, margin: 0, lineHeight: 1.55 }}>
            {V.portfolioP}
          </p>
        </div>

        <div style={{
          display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: L.gridGap, marginTop: 56
        }}>
          {projects.map((p, i) =>
          <button key={i} onClick={() => onOpen(p)} style={{
            background: 'transparent', border: 'none', padding: 0, cursor: 'pointer', textAlign: 'left',
            display: 'flex', flexDirection: 'column', gap: 18
          }}>
              <div style={{ display: 'flex', gap: 14, alignItems: 'flex-end' }}>
                <div style={{ flex: 1 }}>
                  <BrowserMock accent={palette.accent} accentSoft={palette.accentSoft} metier={p.metier} tone={p.tone} />
                </div>
                <PhoneMock accent={palette.accent} metier={p.metier} tone={p.tone} />
              </div>
              <div>
                <div style={{
                fontFamily: 'var(--av-sans)', fontSize: 11, letterSpacing: '.18em',
                textTransform: 'uppercase', fontWeight: 600, color: palette.accent, marginBottom: 8
              }}>
                  Réalisation · {String(i + 1).padStart(2, '0')}
                </div>
                <div style={{ fontFamily: 'var(--av-serif)', fontSize: 22, color: INK, lineHeight: 1.2, fontWeight: 500, marginBottom: 8, letterSpacing: '-.005em' }}>
                  {p.metier}
                </div>
                <div style={{ fontFamily: 'var(--av-sans)', fontSize: 14, color: INK_SOFT, lineHeight: 1.5 }}>
                  {p.result}
                </div>
              </div>
            </button>
          )}
        </div>
      </div>
    </section>);

}

// ─── PROCESS ───────────────────────────────────────────────────
const STEPS = [
{ t: 'On discute', d: '30 minutes, gratuit, sans engagement. Vous me racontez votre métier.', icon: Icon.Chat },
{ t: 'Je construis', d: '4 à 7 jours. Vous voyez l\'avancée chaque jour, par lien privé.', icon: Icon.Hammer },
{ t: 'On ajuste ensemble', d: 'Autant d\'allers-retours qu\'il faut. Le site doit vous ressembler.', icon: Icon.Tools },
{ t: 'Mise en ligne', d: 'Site en ligne, et je reste joignable pour les retouches après.', icon: Icon.Send }];


function Process({ palette, tweaks }) {
  const V = VOICES[tweaks.voice], L = LAYOUTS[tweaks.layout];
  return (
    <section id="process" style={{ background: CREAM_DEEP, padding: `${L.sectionPad}px 40px` }}>
      <div style={{ maxWidth: 1200, margin: '0 auto' }}>
        <Rule accent={palette.accent} />
        <h2 style={{
          fontFamily: 'var(--av-serif)', fontSize: L.sectionSize, fontWeight: 400, color: INK,
          margin: '14px 0 0', letterSpacing: '-.01em'
        }}>
          {V.processH} <em style={{ fontStyle: 'italic' }}>{V.processHi}</em>
        </h2>
        <p style={{ fontFamily: 'var(--av-sans)', fontSize: L.sublead, color: INK_SOFT, maxWidth: 520, marginTop: 14, lineHeight: 1.55 }}>
          {V.processP}
        </p>

        <div style={{
          display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 0, marginTop: 64,
          borderTop: `1px solid ${HAIR}`
        }}>
          {STEPS.map((s, i) => {
            const I = s.icon;
            return (
              <div key={i} style={{
                padding: '40px 28px 32px', borderRight: i < 3 ? `1px solid ${HAIR}` : 'none',
                position: 'relative'
              }}>
                <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 28 }}>
                  <StepNumber n={String(i + 1).padStart(2, '0')} accent={palette.accent} />
                  <div style={{ color: palette.accent, opacity: .6 }}><I s={28} /></div>
                </div>
                <div style={{ fontFamily: 'var(--av-serif)', fontSize: 24, color: INK, fontWeight: 500, marginBottom: 10, lineHeight: 1.15, letterSpacing: '-.005em' }}>{s.t}</div>
                <div style={{ fontFamily: 'var(--av-sans)', fontSize: 14, color: INK_SOFT, lineHeight: 1.55 }}>{s.d}</div>
              </div>);

          })}
        </div>
      </div>
    </section>);

}

// ─── POURQUOI MOI ──────────────────────────────────────────────
const REASONS = [
{ kicker: 'Local', title: 'Basé dans l\'Aude.', body: 'On peut se voir autour d\'un café à Carcassonne ou Limoux. Pas un prestataire à 800 km.', icon: Icon.Pin },
{ kicker: 'Tarif', title: 'Pas de mauvaise surprise.', body: 'Le prix est fixé avant qu\'on commence, et il ne bouge pas. Devis clair, sur une page.', icon: Icon.Tag },
{ kicker: 'Délai', title: 'Site livré en 10 jours.', body: 'Une fois nos échanges faits, vous avez votre site en ligne en moins de deux semaines.', icon: Icon.Clock }];


function Pourquoi({ palette, tweaks }) {
  const V = VOICES[tweaks.voice], L = LAYOUTS[tweaks.layout];
  return (
    <section id="pourquoi" style={{ background: CREAM, padding: `${L.sectionPad}px 40px` }}>
      <div style={{ maxWidth: 1200, margin: '0 auto' }}>
        <Rule accent={palette.accent} />
        <h2 style={{
          fontFamily: 'var(--av-serif)', fontSize: L.sectionSize, fontWeight: 400, color: INK,
          margin: '14px 0 64px', letterSpacing: '-.01em', maxWidth: 760
        }}>
          {V.pourquoiH} <em style={{ fontStyle: 'italic' }}>{V.pourquoiHi}</em>
        </h2>

        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 48 }}>
          {REASONS.map((r, i) => {
            const I = r.icon;
            return (
              <div key={i} style={{ display: 'flex', flexDirection: 'column', gap: 18 }}>
                <div style={{ color: palette.accent }}><I s={32} /></div>
                <div style={{ fontFamily: 'var(--av-sans)', fontSize: 11, letterSpacing: '.2em', textTransform: 'uppercase', color: palette.accent, fontWeight: 700 }}>
                  {r.kicker}
                </div>
                <div style={{ fontFamily: 'var(--av-serif)', fontSize: 30, color: INK, fontWeight: 500, lineHeight: 1.15, letterSpacing: '-.005em' }}>
                  {r.title}
                </div>
                <div style={{ fontFamily: 'var(--av-sans)', fontSize: 15, color: INK_SOFT, lineHeight: 1.6 }}>
                  {r.body}
                </div>
              </div>);

          })}
        </div>
      </div>
    </section>);

}

// ─── CTA FINAL + FORMULAIRE ────────────────────────────────────
function CtaForm({ palette, formRef, status, onSubmit, form, setForm, tweaks }) {
  const V = VOICES[tweaks.voice], L = LAYOUTS[tweaks.layout];
  const onChange = (k) => (e) => setForm({ ...form, [k]: e.target.value });
  const emailOk = /^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(form.email.trim());
  const isValid = form.nom.trim() && form.tel.trim() && form.metier.trim() && emailOk;
  const sending = status === 'sending';
  const sent = status === 'ok';

  return (
    <section ref={formRef} id="contact" style={{ background: palette.accent, color: palette.onAccent, padding: `${L.sectionPad}px 40px`, position: 'relative', overflow: 'hidden' }}>
      {/* Subtle texture */}
      <div style={{ position: 'absolute', inset: 0, opacity: .05,
        backgroundImage: 'repeating-linear-gradient(45deg, #fff 0 1px, transparent 1px 8px)',
        pointerEvents: 'none' }} />

      <div style={{ maxWidth: 1100, margin: '0 auto', position: 'relative', display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 80, alignItems: 'center' }}>
        <div>
          <div style={{ fontSize: 12, letterSpacing: '.22em', textTransform: 'uppercase', fontWeight: 600, opacity: .75, fontFamily: 'var(--av-sans)', marginBottom: 24 }}>
            Devis gratuit · Réponse sous 24h
          </div>
          <h2 style={{
            fontFamily: 'var(--av-serif)', fontSize: Math.max(L.sectionSize + 10, 48), fontWeight: 400, lineHeight: 1.05,
            margin: 0, letterSpacing: '-.015em'
          }}>
            {V.finalH} <em style={{ fontStyle: 'italic' }}>{V.finalHi}</em>
          </h2>
          <p style={{ fontFamily: 'var(--av-sans)', fontSize: L.leadSize - 1, lineHeight: 1.55, marginTop: 24, opacity: .92, maxWidth: 440 }}>
            {V.finalP}
          </p>
          <div style={{ marginTop: 48, paddingTop: 32, borderTop: '1px solid rgba(248,245,240,.25)' }}>
            <div style={{ fontSize: 11, letterSpacing: '.2em', textTransform: 'uppercase', opacity: .7, fontFamily: 'var(--av-sans)', fontWeight: 600, marginBottom: 12 }}>
              Comment ça marche
            </div>
            <div style={{ fontFamily: 'var(--av-sans)', fontSize: 15, lineHeight: 1.6, opacity: .92, maxWidth: 420 }}>
              Remplissez le formulaire ci-contre : je reviens vers vous dans la
              journée avec un devis clair. C'est gratuit et sans engagement.
            </div>
          </div>
        </div>

        {/* Form card */}
        <div style={{
          background: CREAM, color: INK, padding: '40px 36px',
          boxShadow: '0 30px 60px -20px rgba(0,0,0,.35)',
          position: 'relative', minHeight: 380
        }}>
          {!sent ?
          <form onSubmit={onSubmit}>
              <div style={{ fontFamily: 'var(--av-serif)', fontSize: 22, fontWeight: 500, marginBottom: 24, letterSpacing: '-.005em' }}>
                Demander un devis
              </div>
              <Field label="Votre nom" value={form.nom} onChange={onChange('nom')} accent={palette.accent} placeholder="Jean Dupont" />
              <Field label="Votre email" value={form.email} onChange={onChange('email')} accent={palette.accent} placeholder="jean@exemple.fr" type="email" />
              <Field label="Téléphone" value={form.tel} onChange={onChange('tel')} accent={palette.accent} placeholder="06 ..." type="tel" />
              <Field label="Votre métier" value={form.metier} onChange={onChange('metier')} accent={palette.accent} placeholder="Charpentier, maçon, ..." />
              <Field label="Message (optionnel)" value={form.msg} onChange={onChange('msg')} accent={palette.accent} placeholder="Quelques mots sur votre projet" textarea />
              <button type="submit" disabled={!isValid || sending} style={{
              marginTop: 8, width: '100%',
              background: (isValid && !sending) ? palette.accent : '#C9C2B5', color: '#F8F5F0', border: 'none',
              padding: '18px', fontSize: 13, letterSpacing: '.1em',
              textTransform: 'uppercase', fontWeight: 700, cursor: (isValid && !sending) ? 'pointer' : 'not-allowed',
              fontFamily: 'var(--av-sans)', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: 12,
              boxShadow: (isValid && !sending) ? '0 4px 0 rgba(0,0,0,.15)' : 'none',
              transition: 'all .15s'
            }}>
                {sending ? 'Envoi en cours…' : 'Demander mon devis gratuit'} {!sending && <Icon.Arrow s={16} />}
              </button>
              {status === 'error' &&
              <div style={{ marginTop: 14, fontFamily: 'var(--av-sans)', fontSize: 13, color: '#B5552E', lineHeight: 1.5 }}>
                L'envoi a échoué. Réessayez dans un instant, ou renvoyez le formulaire.
              </div>}
              <div style={{ marginTop: 18, fontFamily: 'var(--av-sans)', fontSize: 12, color: INK_SOFT, lineHeight: 1.5 }}>
                Vos infos restent entre nous. Pas de newsletter, pas de revente.
              </div>
            </form> :

          <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start', gap: 18, paddingTop: 20 }}>
              <div style={{
              width: 54, height: 54, borderRadius: '50%', background: palette.accentSoft, color: palette.accent,
              display: 'flex', alignItems: 'center', justifyContent: 'center'
            }}>
                <Icon.Check s={28} />
              </div>
              <div style={{ fontFamily: 'var(--av-serif)', fontSize: 32, fontWeight: 500, letterSpacing: '-.01em', lineHeight: 1.1 }}>
                Message bien reçu, {form.nom.split(' ')[0] || 'à vous'}.
              </div>
              <div style={{ fontFamily: 'var(--av-sans)', fontSize: 15, color: INK_SOFT, lineHeight: 1.6 }}>
                Je reviens vers vous dans la journée à l'adresse <strong style={{ color: INK }}>{form.email}</strong>.
                Un accusé de réception vient d'y être envoyé.
              </div>
            </div>
          }
        </div>
      </div>
    </section>);

}

function Field({ label, value, onChange, accent, placeholder, type = 'text', textarea }) {
  const [focus, setFocus] = React.useState(false);
  const Tag = textarea ? 'textarea' : 'input';
  return (
    <label style={{ display: 'block', marginBottom: 18, fontFamily: 'var(--av-sans)' }}>
      <div style={{ fontSize: 11, letterSpacing: '.18em', textTransform: 'uppercase', color: INK_SOFT, fontWeight: 600, marginBottom: 8 }}>
        {label}
      </div>
      <Tag
        type={type}
        value={value}
        onChange={onChange}
        onFocus={() => setFocus(true)}
        onBlur={() => setFocus(false)}
        placeholder={placeholder}
        rows={textarea ? 3 : undefined}
        style={{
          width: '100%', boxSizing: 'border-box',
          border: 'none', borderBottom: `1.5px solid ${focus ? accent : HAIR}`,
          background: 'transparent', padding: '10px 0',
          fontSize: 16, color: INK, fontFamily: 'var(--av-sans)',
          outline: 'none', resize: textarea ? 'vertical' : 'none',
          transition: 'border-color .15s'
        }} />
      
    </label>);

}

// ─── FOOTER ────────────────────────────────────────────────────
function Footer({ palette }) {
  return (
    <footer style={{ background: '#1A1F2A', color: 'rgba(248,245,240,.8)', padding: '56px 40px 36px' }}>
      <div style={{ maxWidth: 1200, margin: '0 auto', display: 'grid', gridTemplateColumns: '2fr 1fr 1fr', gap: 40, alignItems: 'flex-start' }}>
        <div>
          <div style={{ fontFamily: 'var(--av-serif)', fontSize: 24, color: CREAM, fontWeight: 500, letterSpacing: '.01em' }}>Atelier Vitrine</div>
          <div style={{ fontFamily: 'var(--av-sans)', fontSize: 13, marginTop: 10, opacity: .7, maxWidth: 340, lineHeight: 1.6 }}>Sites vitrines pour artisans et pros du BTP. Basé dans l'Aude, j'interviens aussi en dehors du département.


          </div>
        </div>
        <FootCol title="Navigation">
          <a href="#realisations" style={fLink}>Réalisations</a>
          <a href="#process" style={fLink}>Comment ça se passe</a>
          <a href="#pourquoi" style={fLink}>Pourquoi moi</a>
        </FootCol>
        <FootCol title="Légal">
          <a href="#" style={fLink}>Mentions légales</a>
          <a href="#" style={fLink}>Confidentialité</a>
        </FootCol>
      </div>
      <div style={{ maxWidth: 1200, margin: '48px auto 0', paddingTop: 24, borderTop: '1px solid rgba(248,245,240,.12)', display: 'flex', justifyContent: 'space-between', fontFamily: 'var(--av-sans)', fontSize: 12, opacity: .6 }}>
        <span>© 2026 Atelier Vitrine</span>
        <span>Basé dans l'Aude.</span>
      </div>
    </footer>);

}
const fLink = {
  display: 'block', color: 'rgba(248,245,240,.8)', textDecoration: 'none',
  fontFamily: 'var(--av-sans)', fontSize: 13, marginBottom: 8, lineHeight: 1.5
};
function FootCol({ title, children }) {
  return (
    <div>
      <div style={{ fontFamily: 'var(--av-sans)', fontSize: 11, letterSpacing: '.2em', textTransform: 'uppercase', color: CREAM, fontWeight: 600, marginBottom: 14, opacity: .9 }}>{title}</div>
      {children}
    </div>);

}

// ─── PROJECT MODAL ─────────────────────────────────────────────
function ProjectModal({ project, palette, onClose }) {
  if (!project) return null;
  return (
    <div onClick={onClose} style={{
      position: 'fixed', inset: 0, background: 'rgba(20,15,10,.7)', zIndex: 100,
      display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 40,
      animation: 'avFade .2s ease-out'
    }}>
      <div onClick={(e) => e.stopPropagation()} style={{
        background: CREAM, maxWidth: 880, width: '100%', maxHeight: '90vh', overflow: 'auto',
        position: 'relative'
      }}>
        <button onClick={onClose} style={{
          position: 'absolute', top: 16, right: 16, zIndex: 2, background: 'rgba(248,245,240,.9)', border: 'none',
          width: 36, height: 36, borderRadius: '50%', cursor: 'pointer', color: INK,
          display: 'flex', alignItems: 'center', justifyContent: 'center'
        }}>
          <Icon.Close s={18} />
        </button>
        <div style={{ aspectRatio: '16/9' }}>
          <Photo tone={project.tone} label={project.metier} h="100%" />
        </div>
        <div style={{ padding: '40px 48px 48px' }}>
          <div style={{ fontFamily: 'var(--av-sans)', fontSize: 11, letterSpacing: '.2em', textTransform: 'uppercase', color: palette.accent, fontWeight: 700, marginBottom: 14 }}>
            Réalisation
          </div>
          <h3 style={{ fontFamily: 'var(--av-serif)', fontSize: 40, fontWeight: 500, color: INK, margin: 0, letterSpacing: '-.01em', lineHeight: 1.1 }}>
            {project.metier}
          </h3>
          <p style={{ fontFamily: 'var(--av-sans)', fontSize: 18, color: INK_SOFT, marginTop: 18, lineHeight: 1.6 }}>
            {project.result}
          </p>
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 24, marginTop: 32, paddingTop: 32, borderTop: `1px solid ${HAIR}` }}>
            <Stat label="Délai de livraison" value="4 jours" />
            <Stat label="Pages" value="5" />
            <Stat label="Premier mois" value="+12 leads" />
          </div>
        </div>
      </div>
    </div>);

}
function Stat({ label, value }) {
  return (
    <div>
      <div style={{ fontFamily: 'var(--av-sans)', fontSize: 11, letterSpacing: '.18em', textTransform: 'uppercase', color: INK_SOFT, fontWeight: 600, marginBottom: 8 }}>
        {label}
      </div>
      <div style={{ fontFamily: 'var(--av-serif)', fontSize: 28, color: INK, fontWeight: 500, letterSpacing: '-.005em' }}>
        {value}
      </div>
    </div>);

}

// ─── MAIN PAGE ─────────────────────────────────────────────────
function LandingPage({ paletteKey, tweaks = { mood: 'atelier', voice: 'chaleureux', layout: 'classique' } }) {
  const palette = PALETTES[paletteKey];
  const formRef = React.useRef(null);
  const portfolioRef = React.useRef(null);
  const [project, setProject] = React.useState(null);
  const [status, setStatus] = React.useState('idle'); // idle | sending | ok | error
  const [form, setForm] = React.useState({ nom: '', email: '', tel: '', metier: '', msg: '' });

  const scrollToForm = () => formRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' });
  const scrollToPortfolio = () => {
    document.getElementById('realisations')?.scrollIntoView({ behavior: 'smooth', block: 'start' });
  };
  const onSubmit = async (e) => {
    e.preventDefault();
    if (status === 'sending') return;
    setStatus('sending');
    try {
      const res = await fetch(FORMSPREE_ENDPOINT, {
        method: 'POST',
        headers: { 'Accept': 'application/json' },
        body: JSON.stringify({
          nom: form.nom,
          email: form.email,
          telephone: form.tel,
          metier: form.metier,
          message: form.msg,
          _replyto: form.email,
          _subject: `Demande de devis \u2014 ${form.nom} (${form.metier})`
        })
      });
      if (res.ok) setStatus('ok');
      else setStatus('error');
    } catch (err) {
      setStatus('error');
    }
  };

  return (
    <div style={{ background: CREAM, color: INK, fontFamily: 'var(--av-sans)' }}>
      <Hero palette={palette} onCta={scrollToForm} onPortfolio={scrollToPortfolio} tweaks={tweaks} />
      <Portfolio palette={palette} onOpen={setProject} tweaks={tweaks} />
      <Process palette={palette} tweaks={tweaks} />
      <Pourquoi palette={palette} tweaks={tweaks} />
      <CtaForm palette={palette} formRef={formRef} status={status} onSubmit={onSubmit} form={form} setForm={setForm} tweaks={tweaks} />
      <Footer palette={palette} />
      <ProjectModal project={project} palette={palette} onClose={() => setProject(null)} />
    </div>);

}

window.LandingPage = LandingPage;
window.PALETTES = PALETTES;

// ── TWEAKS LAYER ───────────────────────────────────────────────
// Three expressive controls. Each one shifts MULTIPLE properties at once
// to actually reshape the feel — not single-property pixel pushing.
//
//   mood    : atelier  | chantier | charpente   (photo tones, hero overlay, accent)
//   voice   : chaleureux | direct | sobre        (rewrites copy throughout)
//   layout  : classique | editorial | compact    (type scale, density, rhythm)

const MOODS = {
  atelier:   { tone:'wood',  overlay:'linear-gradient(180deg, rgba(20,15,10,.55) 0%, rgba(20,15,10,.35) 50%, %ACCENT%E6 100%)', accentMul:1,    portfolio:'wood-stone-warm' },
  chantier:  { tone:'stone', overlay:'linear-gradient(180deg, rgba(30,40,50,.55) 0%, rgba(30,40,50,.4) 50%, %ACCENT%F0 100%)',  accentMul:1.05, portfolio:'stone-cool-stone' },
  charpente: { tone:'wood',  overlay:'linear-gradient(180deg, rgba(15,12,8,.78) 0%, rgba(15,12,8,.65) 60%, rgba(10,8,5,.92) 100%)', accentMul:1.1, portfolio:'wood-wood-warm' },
};

const VOICES = {
  chaleureux: {
    eyebrow: 'Sites vitrines pour artisans · BTP',
    h1a: 'Le site internet qui vous ramène',
    h1b: 'des chantiers.',
    sub: "Sites vitrines pour artisans et pros du BTP. Basé dans l'Aude, j'interviens partout en France. Livré en moins de 10 jours, tarif clair.",
    cta: 'Demander un devis gratuit',
    secondary: 'Voir des réalisations',
    portfolioH: 'Des sites pensés',
    portfolioHi: 'pour le terrain.',
    portfolioP: 'Chaque site est conçu pour une chose : faire sonner votre téléphone. Voici ce que ça donne, en vrai, chez des artisans du coin.',
    processH: 'Comment ça',
    processHi: 'se passe.',
    processP: 'Quatre étapes, deux semaines maximum. Pas de jargon, pas de prestataire qui disparaît.',
    pourquoiH: 'Pourquoi travailler',
    pourquoiHi: 'avec moi.',
    finalH: 'On en',
    finalHi: 'parle ?',
    finalP: 'Dites-moi qui vous êtes et ce que vous faites. Je reviens vers vous dans la journée avec un devis clair.',
  },
  direct: {
    eyebrow: 'Sites pour artisans · pas de blabla',
    h1a: 'Un vrai site.',
    h1b: 'Pas une carte de visite en ligne.',
    sub: "Vous bossez. Moi aussi. Je fais des sites qui ramènent des chantiers, livrés en moins de 10 jours, à prix fixe. Pas de jargon, pas de surprises.",
    cta: 'Devis gratuit',
    secondary: 'Voir le travail',
    portfolioH: 'Des sites',
    portfolioHi: 'qui bossent.',
    portfolioP: "Pas de design qui en jette pour rien. Chaque page sert à une seule chose : faire sonner votre téléphone.",
    processH: 'On fait',
    processHi: 'comme ça.',
    processP: "Quatre étapes. Deux semaines max. Pas de réunions inutiles, pas de relances pour vous tirer les vers du nez.",
    pourquoiH: 'Trois raisons,',
    pourquoiHi: 'c\'est tout.',
    finalH: 'On',
    finalHi: 'y va ?',
    finalP: "Dites-moi qui vous êtes et ce que vous faites. Je vous rappelle dans la journée. Pas de mail à rallonge.",
  },
  sobre: {
    eyebrow: 'Atelier Vitrine · Aude',
    h1a: 'Sites vitrines',
    h1b: 'pour artisans et BTP.',
    sub: "Conception de sites internet professionnels. Délai annoncé : moins de 10 jours. Tarif fixe, communiqué avant signature.",
    cta: 'Demander un devis',
    secondary: 'Réalisations',
    portfolioH: 'Réalisations',
    portfolioHi: 'récentes.',
    portfolioP: "Une sélection de sites livrés à des artisans du département de l'Aude.",
    processH: 'Méthode',
    processHi: 'en quatre étapes.',
    processP: "Du premier échange à la mise en ligne, comptez deux semaines.",
    pourquoiH: 'Trois',
    pourquoiHi: 'engagements.',
    finalH: 'Prendre',
    finalHi: 'contact.',
    finalP: "Renseignez ce formulaire pour recevoir un devis détaillé sous 24h.",
  },
};

const LAYOUTS = {
  classique:  { heroSize:72, sectionSize:54, sectionPad:120, gridGap:32, processCols:4, leadSize:19, sublead:15 },
  editorial:  { heroSize:104, sectionSize:78, sectionPad:160, gridGap:48, processCols:4, leadSize:22, sublead:17 },
  compact:    { heroSize:54, sectionSize:38, sectionPad:80,  gridGap:24, processCols:4, leadSize:16, sublead:14 },
};

window.MOODS = MOODS;
window.VOICES = VOICES;
window.LAYOUTS = LAYOUTS;
