
const { useState, useEffect, useRef } = React;
const sb = window.sb;

const IMG = {
  hero:    "uploads/chateau-hero.jpg",
  chateau: "uploads/histoire/13-chateau-restaure.jpg",
  cellar:  "uploads/histoire/14-salon-chesterfield.jpg",
  stairs:  "uploads/histoire/13-chateau-restaure.jpg",
  tasting: "https://lh3.googleusercontent.com/aida-public/AB6AXuAHJwQV32amumA2VNPkcxyK0mqqck94whlqiTvZYoe5v33SdH5mrSXdsGJZaARIMwKFnATDKC-wAxjqNuk4Chltwe0yhlYfSPloXG2pTLZRGIFUjwz9knongTB74vP_vLh1ApITo0TZV8P9QYwYOrzoqandKW53t0n8lVMYnxRiK-6NWmi8HHQgpOP4JT3MyCWYZe_UJC1HrSyn951uhlKMLx0jrWibIxlUgXv1k3L58fKCxvdyGAWnbgpdHaXvH9_XxnVP5XX5mFE"
};

const NAV  = ["Accueil","L'histoire","Boutique","Contact"];
const IDS  = ["accueil","histoire","boutique","contact"];
const serif    = { fontFamily:"'Malbonte', 'Noto Serif', serif" };
const mono     = { fontFamily:"'Manrope', sans-serif" };
const GOLD     = "#e9c176";
const goldGrad = "linear-gradient(135deg,#e9c176 0%,#c5a059 100%)";

// ─── PRIMITIVES ──────────────────────────────────────────────────────────
function Label({ children, style={} }) {
  return <span style={{ ...mono, fontSize:10, textTransform:"uppercase", letterSpacing:"0.2em", color:GOLD, opacity:0.85, ...style }}>{children}</span>;
}
function GoldLine({ w=48, center=false }) {
  return <div style={{ width:w, height:1, background:`linear-gradient(90deg,${GOLD},transparent)`, ...(center?{margin:"0 auto"}:{}) }} />;
}

// ─── REVEAL ──────────────────────────────────────────────────────────────
function Reveal({ children, delay="0s", style={}, ...rest }) {
  const [vis, setVis] = useState(false);
  const ref = useRef(null);
  useEffect(() => {
    const el = ref.current; if (!el) return;
    const check = () => { const r = el.getBoundingClientRect(); return r.top < window.innerHeight + 120 && r.bottom > 0; };
    if (check()) { setTimeout(() => setVis(true), 50); return; }
    const obs = new IntersectionObserver(([e]) => { if (e.isIntersecting) { setVis(true); obs.disconnect(); } }, { threshold:0.05, rootMargin:"0px 0px -30px 0px" });
    obs.observe(el); return () => obs.disconnect();
  }, []);
  return (
    <div ref={ref} style={{ opacity:vis?1:0, transform:vis?"none":"translateY(32px)", transition:`opacity 0.85s cubic-bezier(0.16,1,0.3,1) ${delay}, transform 0.85s cubic-bezier(0.16,1,0.3,1) ${delay}`, ...style }} {...rest}>
      {children}
    </div>
  );
}

// ─── ROUTING ─────────────────────────────────────────────────────────────
function getRoute() {
  const h = (window.location.hash || "").replace(/^#\/?/, "").toLowerCase();
  return IDS.includes(h) ? h : "accueil";
}
function navigateTo(id) {
  if (window.location.hash.replace(/^#\/?/, "").toLowerCase() === id) {
    window.scrollTo({ top: 0, behavior: "smooth" });
  } else {
    window.location.hash = "#" + id;
  }
}
function useRoute() {
  const [route, setRoute] = useState(getRoute);
  useEffect(() => {
    const h = () => { setRoute(getRoute()); window.scrollTo({ top: 0, behavior: "auto" }); };
    window.addEventListener("hashchange", h);
    return () => window.removeEventListener("hashchange", h);
  }, []);
  return route;
}

// ─── NAV ─────────────────────────────────────────────────────────────────
function Nav({ gold, onContact, route }) {
  const [scrolled, setScrolled] = useState(false);
  const [menuOpen, setMenuOpen] = useState(false);
  const active = Math.max(0, IDS.indexOf(route));
  useEffect(() => {
    const h = () => setScrolled(window.scrollY > 60);
    window.addEventListener("scroll", h, { passive:true });
    return () => window.removeEventListener("scroll", h);
  }, []);
  useEffect(() => { document.body.style.overflow = menuOpen ? "hidden" : ""; return () => { document.body.style.overflow = ""; }; }, [menuOpen]);
  const go = (id) => { setMenuOpen(false); navigateTo(id); };
  return (
    <>
      <nav className="cl-nav" style={{ position:"fixed", top:0, left:0, right:0, zIndex:200, background:"rgba(13,13,13,0.92)", backdropFilter:"blur(24px)", WebkitBackdropFilter:"blur(24px)", borderBottom:"1px solid rgba(78,70,57,0.22)", padding:scrolled?"12px 0":"20px 0", transition:"padding 0.4s ease" }}>
        <div className="cl-nav-inner" style={{ maxWidth:1400, margin:"0 auto", padding:"0 24px", display:"flex", justifyContent:"space-between", alignItems:"center", gap:16 }}>
          <img src="uploads/logo.png" alt="Château Lazaar" onClick={() => window.scrollTo({top:0,behavior:"smooth"})} style={{ height:scrolled?48:60, width:"auto", cursor:"pointer", objectFit:"contain", flexShrink:0, transition:"height 0.4s ease" }} />
          <div className="cl-nav-links" style={{ display:"flex", gap:36, alignItems:"center" }}>
            {NAV.map((item,i) => (
              <button key={item} onClick={() => go(IDS[i])} style={{
                background:"none", border:"none", cursor:"pointer", ...mono,
                fontSize:10, textTransform:"uppercase", letterSpacing:"0.18em", fontWeight:600,
                color:active===i?gold:"#6b6258",
                borderBottom:active===i?`1px solid rgba(233,193,118,0.45)`:"1px solid transparent",
                paddingBottom:3, transition:"color 0.35s,border-color 0.35s"
              }}>{item}</button>
            ))}
          </div>
          <button className="cl-nav-cta" onClick={onContact} style={{ background:goldGrad, border:"none", cursor:"pointer", color:"#412d00", ...mono, fontSize:10, textTransform:"uppercase", letterSpacing:"0.2em", fontWeight:700, padding:"11px 28px", transition:"opacity 0.25s" }}
            onMouseEnter={e => e.currentTarget.style.opacity="0.82"}
            onMouseLeave={e => e.currentTarget.style.opacity="1"}
          >Contact</button>
        </div>
      </nav>

      {/* Burger menu: fixed top-right, hidden on desktop via CSS */}
      <button className="cl-burger" aria-label="Menu" aria-expanded={menuOpen} onClick={() => setMenuOpen(o => !o)} style={{ position:"fixed", top:12, right:16, zIndex:210, background:"rgba(13,13,13,0.55)", border:"1px solid rgba(233,193,118,0.45)", borderRadius:8, cursor:"pointer", padding:0, width:46, height:46, flexDirection:"column", justifyContent:"center", alignItems:"center", gap:5, backdropFilter:"blur(8px)", WebkitBackdropFilter:"blur(8px)" }}>
        <span style={{ display:"block", width:22, height:2, background:gold, transition:"transform 0.35s ease, opacity 0.25s ease", transform: menuOpen?"translateY(7px) rotate(45deg)":"none" }} />
        <span style={{ display:"block", width:22, height:2, background:gold, transition:"opacity 0.2s ease", opacity: menuOpen?0:1 }} />
        <span style={{ display:"block", width:22, height:2, background:gold, transition:"transform 0.35s ease", transform: menuOpen?"translateY(-7px) rotate(-45deg)":"none" }} />
      </button>

      {/* Mobile side panel */}
      <div onClick={() => setMenuOpen(false)} style={{ position:"fixed", inset:0, zIndex:150, background:"rgba(8,8,8,0.55)", backdropFilter:"blur(6px)", WebkitBackdropFilter:"blur(6px)", opacity:menuOpen?1:0, pointerEvents:menuOpen?"all":"none", transition:"opacity 0.4s ease" }} />
      <aside style={{ position:"fixed", top:0, right:0, bottom:0, width:"min(82vw, 360px)", zIndex:160, background:"#131313", borderLeft:"1px solid rgba(78,70,57,0.2)", boxShadow:"-20px 0 60px rgba(0,0,0,0.5)", transform:menuOpen?"translateX(0)":"translateX(100%)", transition:"transform 0.45s cubic-bezier(0.16,1,0.3,1)", display:"flex", flexDirection:"column", padding:"96px 32px 32px" }}>
        <div style={{ ...serif, fontSize:13, color:GOLD, fontStyle:"italic", letterSpacing:"0.04em", marginBottom:28 }}>Menu</div>
        <div style={{ display:"flex", flexDirection:"column", gap:4 }}>
          {NAV.map((item,i) => (
            <button key={item} onClick={() => go(IDS[i])} style={{
              background:"none", border:"none", cursor:"pointer", textAlign:"left",
              ...serif, fontSize:26, fontWeight:400, lineHeight:1.4,
              color: active===i ? gold : "#e5e2e1",
              padding:"10px 0", transition:"color 0.25s, transform 0.25s",
            }}
              onMouseEnter={e => e.currentTarget.style.color = gold}
              onMouseLeave={e => e.currentTarget.style.color = active===i ? gold : "#e5e2e1"}
            >{item}</button>
          ))}
        </div>
        <div style={{ marginTop:"auto", display:"flex", flexDirection:"column", gap:18 }}>
          <div style={{ height:1, background:"rgba(78,70,57,0.25)" }} />
          <button onClick={() => { setMenuOpen(false); onContact(); }} style={{ background:goldGrad, border:"none", cursor:"pointer", color:"#412d00", ...mono, fontSize:11, textTransform:"uppercase", letterSpacing:"0.22em", fontWeight:700, padding:"14px 22px" }}>Contact</button>
          <a href="mailto:contact@chateau-lazaar.com" style={{ ...mono, fontSize:11, color:"#6b6258", textDecoration:"none", letterSpacing:"0.05em" }}>contact@chateau-lazaar.com</a>
          <p style={{ ...mono, fontSize:10, color:"#4a4540", letterSpacing:"0.12em", textTransform:"uppercase", lineHeight:1.7, margin:0 }}>95 rue Emile Morlot<br/>02310 Charly-sur-Marne</p>
        </div>
      </aside>
    </>
  );
}

// ─── HERO ────────────────────────────────────────────────────────────────
function Hero({ gold }) {
  return (
    <header id="accueil" className="cl-hero" style={{ position:"relative", height:"100vh", minHeight:560, overflow:"hidden", display:"flex", alignItems:"center", justifyContent:"center", backgroundImage:`url('${IMG.hero}')`, backgroundSize:"cover", backgroundPosition:"center 30%" }}>
      <div style={{ position:"absolute", inset:0, zIndex:0, overflow:"hidden", pointerEvents:"none" }}>
        <video
          src="https://trepggvmepbblsvlqhrx.supabase.co/storage/v1/object/public/media/hero.mp4"
          autoPlay
          muted
          loop
          playsInline
          preload="auto"
          poster={IMG.hero}
          style={{ position:"absolute", top:"50%", left:"50%", transform:"translate(-50%,-50%)", minWidth:"100%", minHeight:"100%", width:"auto", height:"auto", objectFit:"cover", pointerEvents:"none" }}
        />
      </div>
      <div style={{ position:"absolute", inset:0, background:"linear-gradient(180deg,rgba(13,13,13,0.2) 0%,rgba(13,13,13,0.5) 50%,rgba(13,13,13,0.92) 100%)", zIndex:1 }} />
      <div style={{ position:"relative", zIndex:2, textAlign:"center", padding:"0 24px", maxWidth:960, margin:"0 auto" }}>
        <Reveal delay="0s" style={{ marginBottom:24 }}><Label style={{ color:"#ffffff", opacity:0.95 }}>Charly-sur-Marne · Depuis 1760</Label></Reveal>
        <Reveal delay="0.12s">
          <h1 className="cl-hero-title" style={{ ...serif, fontSize:"clamp(30px,5.53vw,75px)", color:"#ffffff", letterSpacing:"-0.025em", lineHeight:1.05, margin:"0 0 32px", fontWeight:400, textShadow:"0 4px 48px rgba(0,0,0,0.5)" }}>
            L'Excellence à la Française
          </h1>
        </Reveal>
        <Reveal delay="0.24s" style={{ width:100, height:1, background:`linear-gradient(90deg,transparent,${gold},transparent)`, margin:"0 auto 32px" }} />
        <Reveal delay="0.36s">
          <p style={{ ...mono, color:"#ffffff", fontSize:17, fontWeight:300, lineHeight:1.75, maxWidth:520, margin:"0 auto" }}>
            Un lieu légendaire niché au cœur de la vallée de la Marne, où l'histoire carolingienne se mêle au raffinement contemporain.
          </p>
        </Reveal>
      </div>
      <div style={{ position:"absolute", bottom:40, left:"50%", transform:"translateX(-50%)", zIndex:2, display:"flex", flexDirection:"column", alignItems:"center", gap:10, opacity:0.7 }}>
        <Label>Découvrir</Label>
        <div style={{ width:1, height:52, background:`linear-gradient(180deg,${GOLD},transparent)`, animation:"scrollPulse 2.2s ease infinite" }} />
      </div>
    </header>
  );
}

// ─── HISTOIRE ─────────────────────────────────────────────────────────────
function Histoire({ onModal }) {
  return (
    <section id="histoire" style={{ background:"#131313" }}>
      {/* ── Intro ── */}
      <div style={{ padding:"140px 0 80px", position:"relative", overflow:"hidden" }}>
        <div style={{ ...serif, position:"absolute", right:-30, top:"50%", transform:"translateY(-50%)", fontSize:"clamp(90px,14vw,220px)", color:"rgba(78,70,57,0.09)", fontStyle:"italic", pointerEvents:"none", userSelect:"none", lineHeight:1 }}>1760</div>
        <div style={{ maxWidth:1400, margin:"0 auto", padding:"0 48px", display:"grid", gridTemplateColumns:"1fr 1fr", gap:80, alignItems:"center" }}>
          <Reveal style={{ position:"relative" }}>
            <div style={{ position:"absolute", top:-28, left:-28, width:160, height:160, background:"#131313", zIndex:0 }} />
            <div style={{ position:"relative", zIndex:1, overflow:"hidden" }} className="zoom-wrap">
              <img src={IMG.chateau} alt="Façade du Château Lazaar" className="zoom-img" style={{ width:"100%", height:580, objectFit:"cover", display:"block", transition:"transform 1.2s cubic-bezier(0.16,1,0.3,1)" }} />
            </div>
            <div style={{ position:"absolute", bottom:-18, right:-18, width:72, height:72, background:goldGrad, zIndex:2, display:"flex", alignItems:"center", justifyContent:"center" }}>
              <span style={{ ...serif, fontSize:22, color:"#412d00", fontStyle:"italic", fontWeight:300 }}>1760</span>
            </div>
          </Reveal>
          <Reveal delay="0.18s">
            <Label style={{ display:"block", marginBottom:20 }}>Un Lieu Chargé d'Histoire</Label>
            <h2 style={{ ...serif, fontSize:"clamp(32px,3.8vw,54px)", color:"#e5e2e1", letterSpacing:"-0.02em", lineHeight:1.12, marginBottom:32, fontWeight:400 }}>
              Une Métamorphose<br/>Au Fil Des Siècles
            </h2>
            <p style={{ ...mono, color:"#d1c5b4", fontSize:16, fontWeight:300, lineHeight:1.82, marginBottom:24 }}>
              Niché au cœur de la vallée de la Marne, le Château Lazaar vous invite à un voyage à travers le temps, où l'histoire se mêle au raffinement. Autrefois connu sous le nom de « Caroli Villa », domaine de Charles Martel, ce lieu légendaire est chargé d'une riche histoire intimement liée à la dynastie carolingienne.
            </p>
            <p style={{ ...mono, color:"#d1c5b4", fontSize:16, fontWeight:300, lineHeight:1.82, marginBottom:48 }}>
              En 2020, le Château Lazaar fut racheté et méticuleusement restauré par Monsieur Lazaar, lui insufflant une nouvelle vie tout en préservant son âme historique.
            </p>
            <div style={{ display:"flex", alignItems:"center", gap:20 }}>
              <GoldLine />
              <button onClick={onModal} style={{ background:"none", border:"none", cursor:"pointer", ...mono, fontSize:10, textTransform:"uppercase", letterSpacing:"0.18em", color:GOLD, transition:"opacity 0.25s" }}
                onMouseEnter={e => e.currentTarget.style.opacity="0.6"}
                onMouseLeave={e => e.currentTarget.style.opacity="1"}
              >Découvrir l'héritage</button>
            </div>
          </Reveal>
        </div>
      </div>

      {/* ── Héritage carolingien ── */}
      <div style={{ padding:"80px 0", background:"#131313" }}>
        <div style={{ maxWidth:1400, margin:"0 auto", padding:"0 48px" }}>
          <div style={{ display:"grid", gridTemplateColumns:"1fr 1fr", gap:80, alignItems:"center" }}>
            <Reveal>
              <Label style={{ display:"block", marginBottom:20 }}>L'Héritage</Label>
              <h2 style={{ ...serif, fontSize:"clamp(28px,3.2vw,46px)", color:"#e5e2e1", letterSpacing:"-0.02em", lineHeight:1.15, marginBottom:28, fontWeight:400 }}>
                Un Héritage<br/>Carolingien
              </h2>
              <p style={{ ...mono, color:"#d1c5b4", fontSize:16, fontWeight:300, lineHeight:1.82 }}>
                Le nom de la commune, Charly-sur-Marne, trouve ses racines dans « Caroli Villa », signifiant « Domaine de Charles ». Ce nom rend hommage à Charles Martel, illustre maire du palais et ancêtre de Pépin III dit le Bref, fondateur de la dynastie carolingienne.
              </p>
              <p style={{ ...mono, color:"#d1c5b4", fontSize:16, fontWeight:300, lineHeight:1.82, marginTop:20 }}>
                L'histoire du Château Lazaar est indissociable de cette figure historique majeure, dont la victoire face aux troupes arabes en 732 marqua un tournant crucial pour l'Europe.
              </p>
            </Reveal>
            <Reveal delay="0.18s">
              <div style={{ display:"grid", gridTemplateColumns:"1fr 1fr", gap:4 }}>
                {[
                  { label:"Caroli Villa", sub:"Domaine de Charles Martel" },
                  { label:"732 ap. J.-C.", sub:"Bataille de Poitiers" },
                  { label:"Un style intemporel", sub:"Château entièrement restauré" },
                  { label:"Région viticole", sub:"Au cœur de la vallée de la Marne" }
                ].map(({ label, sub }) => (
                  <div key={label} style={{ background:"#131313", padding:"36px 28px" }}>
                    <div style={{ ...serif, fontSize:18, color:GOLD, marginBottom:8, fontWeight:400, lineHeight:1.2 }}>{label}</div>
                    <div style={{ ...mono, fontSize:10, textTransform:"uppercase", letterSpacing:"0.15em", color:"#6b6258", lineHeight:1.5 }}>{sub}</div>
                  </div>
                ))}
              </div>
            </Reveal>
          </div>
        </div>
      </div>

      {/* ── Frise chronologique ── */}
      <div style={{ padding:"80px 0 120px", background:"#131313" }}>
        <div style={{ maxWidth:1400, margin:"0 auto", padding:"0 48px" }}>
          <Reveal style={{ textAlign:"center", marginBottom:72 }}>
            <Label style={{ display:"block", marginBottom:16 }}>Chronologie</Label>
            <h2 style={{ ...serif, fontSize:"clamp(28px,3vw,44px)", color:"#e5e2e1", letterSpacing:"-0.02em", fontWeight:400 }}>
              Cinq Siècles d'Histoire
            </h2>
          </Reveal>
          <Reveal delay="0.1s" style={{ display:"grid", gridTemplateColumns:"repeat(4,1fr)", gap:2 }}>
            {[
              { year:"~732", title:"Caroli Villa", text:"Domaine de Charles Martel, ancêtre de la dynastie carolingienne." },
              { year:"1760", title:"Famille Vignon", text:"Acquis par la famille Vignon après avoir été « Hôtel Dieu » du Diocèse de Soissons." },
              { year:"2006", title:"Charly-sur-Marne", text:"La commune adopte son nom en hommage à son illustre passé carolingien." },
              { year:"2020", title:"Restauration", text:"Monsieur Lazaar rachète et restaure méticuleusement le château, préservant son âme historique." }
            ].map(({ year, title, text }) => (
              <div key={year} style={{ background:"#131313", padding:"48px 36px", position:"relative" }}>
                <div style={{ ...serif, fontSize:32, color:GOLD, fontStyle:"italic", marginBottom:16, opacity:0.7, fontWeight:400 }}>{year}</div>
                <div style={{ ...serif, fontSize:18, color:"#e5e2e1", marginBottom:14, fontWeight:400 }}>{title}</div>
                <p style={{ ...mono, color:"#d1c5b4", fontWeight:300, fontSize:14, lineHeight:1.75 }}>{text}</p>
                <div style={{ position:"absolute", bottom:0, left:0, right:0, height:2, background:goldGrad, opacity:0.3 }} />
              </div>
            ))}
          </Reveal>
        </div>
      </div>
    </section>
  );
}

// ─── STATS ────────────────────────────────────────────────────────────────
function Stats() {
  const items = [
    { value:"5 000", label:"Mètres carrés", sub:"de parc" },
    { value:"3 000", label:"Mètres carrés", sub:"habitables" },
    { value:"30",    label:"Pièces",         sub:"au total" }
  ];
  return (
    <section style={{ padding:"100px 0", background:"#131313" }}>
      <div style={{ maxWidth:1400, margin:"0 auto", padding:"0 48px" }}>
        <Reveal style={{ textAlign:"center", marginBottom:72 }}>
          <Label style={{ display:"block", marginBottom:16 }}>Un Château Unique</Label>
          <h2 style={{ ...serif, fontSize:"clamp(28px,3vw,44px)", color:"#e5e2e1", letterSpacing:"-0.02em", fontWeight:400 }}>
            Construit en 1760 · Restauré en 2020
          </h2>
        </Reveal>
        <Reveal delay="0.1s" style={{ display:"grid", gridTemplateColumns:"repeat(3,1fr)", gap:2 }}>
          {items.map(({ value, label, sub }) => (
            <div key={value} style={{ background:"#131313", padding:"60px 48px", textAlign:"center", position:"relative", overflow:"hidden" }}>
              <div style={{ ...serif, fontSize:"clamp(48px,6vw,88px)", color:GOLD, lineHeight:1, marginBottom:16, fontWeight:400 }}>{value}</div>
              <div style={{ ...mono, fontSize:11, textTransform:"uppercase", letterSpacing:"0.18em", color:"#d1c5b4", marginBottom:6 }}>{label}</div>
              <div style={{ ...mono, fontSize:10, textTransform:"uppercase", letterSpacing:"0.15em", color:"#6b6258" }}>{sub}</div>
            </div>
          ))}
        </Reveal>
      </div>
    </section>
  );
}

// ─── PRODUITS ─────────────────────────────────────────────────────────────
function Produits() {
  const [hov, setHov] = useState(null);
  const [imgs, setImgs] = useState({});
  const prods = [
    { id:"miel", icon:"🍯", title:"Miel", sub:"Biologique", desc:"Un miel d'exception récolté dans le parc du château, aux saveurs florales et authentiques de la vallée de la Marne." },
    { id:"epicerie", icon:"🫙", title:"Épicerie Fine", sub:"Produits originaux", desc:"Une sélection de produits artisanaux soigneusement choisis pour leur qualité et leur caractère authentique." },
    { id:"parfum", icon:"🌸", title:"Parfum", sub:"Fragrances intemporelles", desc:"Des fragrances inspirées du château et de ses jardins, capturant l'essence de l'excellence à la française." }
  ];

  useEffect(() => {
    (async () => {
      if (!sb) return;
      const { data } = await sb
        .from("products")
        .select("category,image_url,sort_order")
        .eq("is_published", true)
        .not("image_url", "is", null)
        .order("sort_order", { ascending: true });
      if (!data) return;
      const byCat = {};
      for (const p of data) {
        if (!byCat[p.category] && p.image_url) byCat[p.category] = p.image_url;
      }
      setImgs(byCat);
    })();
  }, []);
  return (
    <section id="boutique" style={{ padding:"140px 0", background:"#131313" }}>
      <div style={{ maxWidth:1400, margin:"0 auto", padding:"0 48px" }}>
        <Reveal style={{ marginBottom:80 }}>
          <Label style={{ display:"block", marginBottom:16 }}>La Boutique</Label>
          <h2 style={{ ...serif, fontSize:"clamp(36px,4vw,60px)", color:"#e5e2e1", letterSpacing:"-0.02em", lineHeight:1.1, fontWeight:400, maxWidth:540 }}>
            Des Produits<br/>Authentiques
          </h2>
        </Reveal>
        <div style={{ display:"grid", gridTemplateColumns:"repeat(3,1fr)", gap:6 }}>
          {prods.map(({ id, icon, title, sub, desc }, i) => {
            const img = imgs[id];
            return (
            <Reveal key={id} delay={`${i*0.12}s`}>
              <div
                onMouseEnter={() => setHov(id)}
                onMouseLeave={() => setHov(null)}
                style={{
                  background: "#131313",
                  padding:"56px 48px 64px",
                  cursor:"pointer", height:"100%",
                  transition:"background 0.4s ease",
                  position:"relative", overflow:"hidden"
                }}
              >
                <div style={{ position:"absolute", inset:0, background:`linear-gradient(135deg,rgba(233,193,118,0.05),transparent)`, opacity:hov===id?1:0, transition:"opacity 0.4s" }} />
                <div style={{ width:"100%", aspectRatio:"4/3", border:`1px solid rgba(233,193,118,0.2)`, marginBottom:32, overflow:"hidden", background:"#0f0f0f", display:"flex", alignItems:"center", justifyContent:"center" }}>
                  {img ? (
                    <img src={img} alt={title}
                      style={{ width:"100%", height:"100%", objectFit:"cover", transform:hov===id?"scale(1.06)":"scale(1)", transition:"transform 0.8s cubic-bezier(0.16,1,0.3,1)" }} />
                  ) : (
                    <span style={{ fontSize:54, transform:hov===id?"scale(1.1)":"scale(1)", transition:"transform 0.4s ease" }}>{icon}</span>
                  )}
                </div>
                <Label style={{ display:"block", marginBottom:12 }}>{sub}</Label>
                <h3 style={{ ...serif, fontSize:28, color:"#e5e2e1", fontWeight:400, marginBottom:20 }}>{title}</h3>
                <p style={{ ...mono, color:"#d1c5b4", fontWeight:300, lineHeight:1.78, fontSize:15 }}>{desc}</p>
                <div style={{ marginTop:36, display:"flex", alignItems:"center", gap:16, opacity:hov===id?1:0, transform:hov===id?"translateY(0)":"translateY(6px)", transition:"opacity 0.35s,transform 0.35s" }}>
                  <GoldLine />
                  <span style={{ ...mono, fontSize:10, textTransform:"uppercase", letterSpacing:"0.18em", color:GOLD }}>Découvrir</span>
                </div>
              </div>
            </Reveal>
            );
          })}
        </div>
      </div>
    </section>
  );
}

// ─── SAVOIR-FAIRE ─────────────────────────────────────────────────────────
function SavoirFaire() {
  const [cellarHov, setCellarHov] = useState(false);
  return (
    <section style={{ padding:"140px 0", background:"#131313", overflow:"hidden" }}>
      <div style={{ maxWidth:1400, margin:"0 auto", padding:"0 48px" }}>
        <Reveal style={{ display:"flex", justifyContent:"space-between", alignItems:"flex-end", marginBottom:96 }}>
          <div style={{ maxWidth:520 }}>
            <Label style={{ display:"block", marginBottom:16 }}>Le Domaine</Label>
            <h2 style={{ ...serif, fontSize:"clamp(36px,4.5vw,64px)", color:"#e5e2e1", letterSpacing:"-0.02em", lineHeight:1.1, marginBottom:20, fontWeight:400 }}>
              Un Savoir-faire<br/>d'Exception
            </h2>
            <p style={{ ...mono, color:"#d1c5b4", fontWeight:300, lineHeight:1.78, fontSize:16 }}>
              Niché au cœur de la vallée de la Marne, le Château Lazaar perpétue un art de vivre à la française, alliant patrimoine historique et excellence contemporaine.
            </p>
          </div>
          <div style={{ ...serif, fontSize:"clamp(64px,9vw,150px)", color:"rgba(78,70,57,0.1)", fontStyle:"italic", lineHeight:1, userSelect:"none" }}>1760</div>
        </Reveal>
        <div style={{ display:"grid", gridTemplateColumns:"5fr 7fr", gap:32, alignItems:"start" }}>
          <Reveal delay="0.1s" style={{ paddingTop:72 }}>
            <div style={{ overflow:"hidden", cursor:"pointer" }} onMouseEnter={() => setCellarHov(true)} onMouseLeave={() => setCellarHov(false)}>
              <img src={IMG.cellar} alt="Salon du château" style={{ width:"100%", aspectRatio:"3/4", objectFit:"cover", display:"block", filter:cellarHov?"grayscale(0%) brightness(1.05)":"grayscale(40%)", transform:cellarHov?"scale(1.04)":"scale(1)", transition:"filter 1s ease,transform 1.2s cubic-bezier(0.16,1,0.3,1)" }} />
            </div>
            <div style={{ marginTop:28 }}>
              <h3 style={{ ...serif, fontSize:22, color:GOLD, marginBottom:10, fontWeight:400 }}>Un Intérieur d'Exception</h3>
              <p style={{ ...mono, fontSize:10, textTransform:"uppercase", letterSpacing:"0.18em", color:"#d1c5b4" }}>Moulures dorées · Parquet d'origine</p>
            </div>
          </Reveal>
          <Reveal delay="0.22s">
            <div style={{ overflow:"hidden" }} className="zoom-wrap">
              <img src={IMG.stairs} alt="Façade du château" className="zoom-img" style={{ width:"100%", aspectRatio:"16/10", objectFit:"cover", display:"block", transition:"transform 1.2s cubic-bezier(0.16,1,0.3,1)" }} />
            </div>
            <div style={{ marginTop:28, maxWidth:360, marginLeft:"auto", textAlign:"right" }}>
              <h3 style={{ ...serif, fontSize:22, color:GOLD, marginBottom:10, fontWeight:400 }}>Une Bâtisse Mythique</h3>
              <p style={{ ...mono, fontSize:10, textTransform:"uppercase", letterSpacing:"0.18em", color:"#d1c5b4" }}>Construite en 1760 · Style classique français</p>
            </div>
          </Reveal>
        </div>
      </div>
    </section>
  );
}

// ─── CTA BOUTIQUE ─────────────────────────────────────────────────────────
function BoutiqueCTA() {
  const [btnHov, setBtnHov] = useState(false);
  return (
    <section style={{ padding:"140px 0", background:"#131313", position:"relative", overflow:"hidden" }}>
      <div style={{ ...serif, position:"absolute", left:"50%", top:"50%", transform:"translate(-50%,-50%)", fontSize:"clamp(80px,18vw,280px)", color:"rgba(78,70,57,0.06)", fontStyle:"italic", whiteSpace:"nowrap", pointerEvents:"none", userSelect:"none", lineHeight:1 }}>Lazaar</div>
      <div style={{ maxWidth:800, margin:"0 auto", padding:"0 48px", textAlign:"center", position:"relative", zIndex:1 }}>
        <Reveal>
          <Label style={{ display:"block", marginBottom:20 }}>Notre Boutique en Ligne</Label>
          <h2 style={{ ...serif, fontSize:"clamp(36px,5vw,72px)", color:"#e5e2e1", letterSpacing:"-0.02em", lineHeight:1.1, marginBottom:24, fontWeight:400 }}>
            Découvrez<br/>Notre Boutique<br/>en Ligne
          </h2>
          <div style={{ width:80, height:1, background:`linear-gradient(90deg,transparent,${GOLD},transparent)`, margin:"0 auto 32px" }} />
          <p style={{ ...mono, color:"#d1c5b4", fontWeight:300, lineHeight:1.78, fontSize:17, marginBottom:48, maxWidth:480, margin:"0 auto 48px" }}>
            Nous vous proposons toute une gamme de produits authentiques issus du domaine — miel biologique, épicerie fine et fragrances intemporelles.
          </p>
          <button
            onClick={() => navigateTo("boutique")}
            onMouseEnter={() => setBtnHov(true)}
            onMouseLeave={() => setBtnHov(false)}
            style={{ background:btnHov?goldGrad:"none", border:`1px solid rgba(233,193,118,${btnHov?0:0.4})`, cursor:"pointer", color:btnHov?"#412d00":GOLD, ...mono, fontSize:11, textTransform:"uppercase", letterSpacing:"0.25em", padding:"18px 48px", transition:"all 0.45s ease", fontWeight:600 }}
          >Découvrir !</button>
        </Reveal>
      </div>
    </section>
  );
}

// ─── MODAL HISTOIRE ───────────────────────────────────────────────────────
function HistoireModal({ open, onClose }) {
  useEffect(() => { document.body.style.overflow = open?"hidden":""; return () => { document.body.style.overflow=""; }; }, [open]);
  return (
    <div style={{ position:"fixed", inset:0, zIndex:500, background:"rgba(10,10,10,0.97)", backdropFilter:"blur(20px)", display:"flex", alignItems:"center", justifyContent:"center", opacity:open?1:0, pointerEvents:open?"all":"none", transition:"opacity 0.5s ease" }}>
      <button onClick={onClose} style={{ position:"absolute", top:32, right:40, background:"none", border:"none", cursor:"pointer", ...mono, fontSize:10, textTransform:"uppercase", letterSpacing:"0.2em", color:"#6b6258", display:"flex", alignItems:"center", gap:12, transition:"color 0.25s" }}
        onMouseEnter={e => e.currentTarget.style.color=GOLD}
        onMouseLeave={e => e.currentTarget.style.color="#6b6258"}
      ><span style={{ fontSize:20 }}>✕</span> Fermer</button>
      <div style={{ maxWidth:1100, width:"100%", padding:"0 48px", display:"grid", gridTemplateColumns:"1fr 1fr", gap:80, alignItems:"center" }}>
        <div>
          <Label style={{ display:"block", marginBottom:24 }}>Héritage · De Caroli Villa à Château Lazaar</Label>
          <h2 style={{ ...serif, fontSize:"clamp(36px,4vw,56px)", color:"#e5e2e1", letterSpacing:"-0.02em", lineHeight:1.1, marginBottom:36, fontWeight:400 }}>
            Un Lieu Chargé<br/>d'Histoire
          </h2>
          {[
            ["Caroli Villa","Autrefois connu sous le nom de « Caroli Villa », domaine de Charles Martel, ce lieu légendaire est intimement lié à la dynastie carolingienne. La victoire de Charles Martel face aux troupes arabes en 732 marqua un tournant crucial pour l'Europe."],
            ["1760","Acquis par la famille Vignon en 1760, le château connut de nombreuses transformations. Légué au Diocèse de Soissons, il fut transformé en « Hôtel Dieu » avant d'être rendu à sa vocation résidentielle."],
            ["2006","La commune adopta le nom de Charly-sur-Marne, en référence à son illustre passé carolingien — « Caroli Villa » signifiant « Domaine de Charles »."],
            ["2020","Monsieur Lazaar rachète et restaure méticuleusement le château, lui insufflant une nouvelle vie tout en préservant son âme historique et son style classique français."]
          ].map(([year, text]) => (
            <div key={year} style={{ display:"flex", gap:28, marginBottom:28 }}>
              <div style={{ flexShrink:0 }}>
                <span style={{ ...serif, fontSize:13, color:GOLD, fontStyle:"italic" }}>{year}</span>
                <div style={{ width:1, height:36, background:`linear-gradient(180deg,${GOLD},transparent)`, margin:"8px 0 0 18px" }} />
              </div>
              <p style={{ ...mono, color:"#d1c5b4", fontWeight:300, lineHeight:1.78, fontSize:15, paddingTop:2 }}>{text}</p>
            </div>
          ))}
        </div>
        <div style={{ position:"relative" }}>
          <img src={IMG.chateau} alt="" style={{ width:"100%", height:600, objectFit:"cover", display:"block" }} />
          <div style={{ position:"absolute", inset:0, background:"linear-gradient(180deg,transparent 50%,rgba(10,10,10,0.6) 100%)" }} />
          <div style={{ position:"absolute", bottom:32, left:32, right:32 }}>
            <GoldLine w={32} />
            <p style={{ ...mono, fontSize:10, textTransform:"uppercase", letterSpacing:"0.18em", color:"#d1c5b4", marginTop:16 }}>Charly-sur-Marne · Vallée de la Marne · Hauts-de-France</p>
          </div>
        </div>
      </div>
    </div>
  );
}

// ─── MODAL CONTACT ────────────────────────────────────────────────────────
function ContactModal({ open, onClose }) {
  const [sent, setSent] = useState(false);
  const [busy, setBusy] = useState(false);
  const [err, setErr] = useState("");
  const [form, setForm] = useState({ name:"", email:"", message:"" });
  useEffect(() => { document.body.style.overflow = open?"hidden":""; return () => { document.body.style.overflow=""; }; }, [open]);
  const submit = async (e) => {
    e.preventDefault();
    if (busy) return;
    setBusy(true); setErr("");
    const { error } = await sb.from("contact_messages").insert({
      name: form.name.trim(),
      email: form.email.trim(),
      message: form.message.trim(),
      source: "modal"
    });
    setBusy(false);
    if (error) { setErr("Une erreur est survenue. Merci de réessayer."); return; }
    setSent(true);
  };
  return (
    <div style={{ position:"fixed", inset:0, zIndex:500, background:"rgba(10,10,10,0.96)", backdropFilter:"blur(20px)", display:"flex", alignItems:"center", justifyContent:"center", opacity:open?1:0, pointerEvents:open?"all":"none", transition:"opacity 0.5s ease" }}>
      <button onClick={onClose} style={{ position:"absolute", top:32, right:40, background:"none", border:"none", cursor:"pointer", ...mono, fontSize:10, textTransform:"uppercase", letterSpacing:"0.2em", color:"#6b6258", display:"flex", alignItems:"center", gap:12, transition:"color 0.25s" }}
        onMouseEnter={e => e.currentTarget.style.color=GOLD}
        onMouseLeave={e => e.currentTarget.style.color="#6b6258"}
      ><span style={{ fontSize:20 }}>✕</span> Fermer</button>
      <div style={{ maxWidth:520, width:"100%", padding:"0 48px" }}>
        {!sent ? (
          <>
            <Label style={{ display:"block", marginBottom:20 }}>Prise de Contact</Label>
            <h2 style={{ ...serif, fontSize:"clamp(28px,3vw,44px)", color:"#e5e2e1", letterSpacing:"-0.02em", lineHeight:1.1, marginBottom:48, fontWeight:400 }}>Écrivez-nous</h2>
            <form onSubmit={submit} style={{ display:"flex", flexDirection:"column", gap:32 }}>
              {[["name","Votre nom","text"],["email","Adresse e-mail","email"],["message","Votre message","textarea"]].map(([key,label,type]) => (
                <div key={key}>
                  <label style={{ ...mono, fontSize:10, textTransform:"uppercase", letterSpacing:"0.18em", color:"#4a4540", display:"block", marginBottom:10 }}>{label}</label>
                  {type==="textarea"
                    ? <textarea rows={3} value={form[key]} onChange={e => setForm(f=>({...f,[key]:e.target.value}))} required style={{ width:"100%", background:"none", border:"none", borderBottom:"1px solid rgba(78,70,57,0.4)", color:"#e5e2e1", ...mono, fontSize:15, fontWeight:300, padding:"8px 0", outline:"none", resize:"none", transition:"border-color 0.3s" }} onFocus={e=>e.target.style.borderBottomColor=GOLD} onBlur={e=>e.target.style.borderBottomColor="rgba(78,70,57,0.4)"} />
                    : <input type={type} value={form[key]} onChange={e => setForm(f=>({...f,[key]:e.target.value}))} required style={{ width:"100%", background:"none", border:"none", borderBottom:"1px solid rgba(78,70,57,0.4)", color:"#e5e2e1", ...mono, fontSize:15, fontWeight:300, padding:"8px 0", outline:"none", transition:"border-color 0.3s" }} onFocus={e=>e.target.style.borderBottomColor=GOLD} onBlur={e=>e.target.style.borderBottomColor="rgba(78,70,57,0.4)"} />
                  }
                </div>
              ))}
              {err && <div style={{ ...mono, fontSize:11, color:"#e08c8c", letterSpacing:"0.06em" }}>{err}</div>}
              <button type="submit" disabled={busy} style={{ background:goldGrad, border:"none", cursor:busy?"wait":"pointer", color:"#412d00", ...mono, fontSize:10, textTransform:"uppercase", letterSpacing:"0.2em", fontWeight:700, padding:"16px", marginTop:8, transition:"opacity 0.25s", opacity:busy?0.6:1 }}
                onMouseEnter={e=>e.currentTarget.style.opacity=busy?"0.6":"0.82"} onMouseLeave={e=>e.currentTarget.style.opacity=busy?"0.6":"1"}
              >{busy ? "Envoi…" : "Envoyer"}</button>
            </form>
          </>
        ) : (
          <div style={{ textAlign:"center" }}>
            <GoldLine w={48} center />
            <h2 style={{ ...serif, fontSize:40, color:"#e5e2e1", letterSpacing:"-0.02em", margin:"32px 0 16px", fontWeight:400 }}>Merci</h2>
            <p style={{ ...mono, color:"#d1c5b4", fontWeight:300, lineHeight:1.8, fontSize:16 }}>Votre message a bien été reçu. Nous vous répondrons dans les plus brefs délais.</p>
          </div>
        )}
      </div>
    </div>
  );
}

// ─── FOOTER ──────────────────────────────────────────────────────────────
function NewsletterSignup({ gold }) {
  const [email, setEmail] = useState("");
  const [state, setState] = useState({ busy:false, ok:false, err:"" });
  const submit = async (e) => {
    e.preventDefault();
    if (state.busy) return;
    setState({ busy:true, ok:false, err:"" });
    const { error } = await sb.from("newsletter_subscribers").insert({ email: email.trim(), source:"footer" });
    if (error) {
      if (error.code === "23505") { setState({ busy:false, ok:true, err:"" }); setEmail(""); return; }
      setState({ busy:false, ok:false, err:"Erreur, veuillez réessayer." });
      return;
    }
    setState({ busy:false, ok:true, err:"" });
    setEmail("");
  };
  return (
    <form onSubmit={submit} style={{ marginTop:24, display:"flex", flexDirection:"column", gap:10, maxWidth:280 }}>
      <label style={{ ...mono, fontSize:10, textTransform:"uppercase", letterSpacing:"0.2em", color:gold }}>Newsletter</label>
      <div style={{ display:"flex", borderBottom:"1px solid rgba(78,70,57,0.4)" }}>
        <input type="email" required value={email} onChange={e=>setEmail(e.target.value)} placeholder="votre@email.com"
          style={{ flex:1, background:"none", border:"none", color:"#e5e2e1", ...mono, fontSize:13, fontWeight:300, padding:"8px 0", outline:"none" }} />
        <button type="submit" disabled={state.busy} style={{ background:"none", border:"none", cursor:state.busy?"wait":"pointer", color:gold, ...mono, fontSize:10, textTransform:"uppercase", letterSpacing:"0.2em", padding:"8px 0 8px 12px", fontWeight:700, opacity:state.busy?0.6:1 }}>
          {state.busy ? "…" : "OK →"}
        </button>
      </div>
      {state.ok && <div style={{ ...mono, fontSize:10, color:gold, letterSpacing:"0.08em" }}>Merci pour votre inscription.</div>}
      {state.err && <div style={{ ...mono, fontSize:10, color:"#e08c8c", letterSpacing:"0.08em" }}>{state.err}</div>}
    </form>
  );
}

function Footer({ gold }) {
  return (
    <footer style={{ background:"#131313", paddingTop:96, paddingBottom:48 }}>
      <div style={{ maxWidth:1400, margin:"0 auto", padding:"0 48px" }}>
        <div style={{ display:"grid", gridTemplateColumns:"1fr 1fr 1fr", gap:48, marginBottom:80 }}>
          <div>
            <img src="uploads/logo.png" alt="Château Lazaar" style={{ height:80, width:"auto", objectFit:"contain", marginBottom:20 }} />
            <p style={{ ...mono, color:"#4a4540", fontSize:12, lineHeight:1.85, maxWidth:260 }}>L'excellence à la Française. 95 rue Emile Morlot, 02310 Charly-sur-Marne.</p>
            <div style={{ marginTop:28 }}>
              <a href="mailto:contact@chateau-lazaar.com" style={{ ...mono, fontSize:11, color:"#6b6258", textDecoration:"none", transition:"color 0.3s", display:"block" }}
                onMouseEnter={e=>e.currentTarget.style.color=GOLD}
                onMouseLeave={e=>e.currentTarget.style.color="#6b6258"}
              >contact@chateau-lazaar.com</a>
            </div>
            <NewsletterSignup gold={gold} />
          </div>
          <div>
            <div style={{ ...serif, color:gold, fontSize:13, marginBottom:28, fontStyle:"italic" }}>Navigation</div>
            <div style={{ display:"flex", flexDirection:"column", gap:16 }}>
              {NAV.map((item,i) => (
                <button key={item} onClick={() => navigateTo(IDS[i])} style={{ background:"none", border:"none", cursor:"pointer", ...mono, fontSize:11, textTransform:"uppercase", letterSpacing:"0.16em", color:"#3a3530", transition:"color 0.3s", textAlign:"left" }}
                  onMouseEnter={e=>e.currentTarget.style.color=GOLD} onMouseLeave={e=>e.currentTarget.style.color="#3a3530"}
                >{item}</button>
              ))}
            </div>
          </div>
          <div>
            <div style={{ ...serif, color:gold, fontSize:13, marginBottom:28, fontStyle:"italic" }}>Légal</div>
            <div style={{ display:"flex", flexDirection:"column", gap:16 }}>
              {["Mentions légales","Politique de confidentialité","CGV"].map(item => (
                <button key={item} style={{ background:"none", border:"none", cursor:"pointer", ...mono, fontSize:11, textTransform:"uppercase", letterSpacing:"0.16em", color:"#3a3530", transition:"color 0.3s", textAlign:"left" }}
                  onMouseEnter={e=>e.currentTarget.style.color=GOLD} onMouseLeave={e=>e.currentTarget.style.color="#3a3530"}
                >{item}</button>
              ))}
            </div>
          </div>
        </div>
        <div style={{ borderTop:"1px solid rgba(78,70,57,0.12)", paddingTop:32, textAlign:"center" }}>
          <p style={{ ...mono, color:"#2e2a26", fontSize:10, textTransform:"uppercase", letterSpacing:"0.2em" }}>© Château Lazaar · Tous Droits Réservés 2024 · Charly-sur-Marne</p>
        </div>
      </div>
    </footer>
  );
}

// ─── PAGE HERO BANNER ────────────────────────────────────────────────────
function PageBanner({ eyebrow, title, subtitle, image }) {
  return (
    <header style={{ position:"relative", minHeight:"58vh", display:"flex", alignItems:"center", justifyContent:"center", overflow:"hidden", background:"#131313", marginTop:0 }}>
      <img src={image} alt="" style={{ position:"absolute", inset:0, width:"100%", height:"100%", objectFit:"cover", opacity:0.45 }} />
      <div style={{ position:"absolute", inset:0, background:"linear-gradient(180deg,rgba(13,13,13,0.55) 0%,rgba(13,13,13,0.55) 50%,rgba(13,13,13,0.95) 100%)" }} />
      <div style={{ position:"relative", textAlign:"center", padding:"180px 24px 80px", maxWidth:920 }}>
        <Reveal style={{ marginBottom:20 }}><Label style={{ color:"#ffffff", opacity:0.92 }}>{eyebrow}</Label></Reveal>
        <Reveal delay="0.1s">
          <h1 className="cl-hero-title" style={{ ...serif, fontSize:"clamp(34px,5.5vw,72px)", color:"#ffffff", letterSpacing:"-0.025em", lineHeight:1.05, margin:"0 0 24px", fontWeight:400, textShadow:"0 4px 48px rgba(0,0,0,0.5)" }}>{title}</h1>
        </Reveal>
        <Reveal delay="0.2s" style={{ width:80, height:1, background:`linear-gradient(90deg,transparent,${GOLD},transparent)`, margin:"0 auto 28px" }} />
        {subtitle && <Reveal delay="0.3s"><p style={{ ...mono, color:"#ffffff", fontSize:16, fontWeight:300, lineHeight:1.75, maxWidth:560, margin:"0 auto" }}>{subtitle}</p></Reveal>}
      </div>
    </header>
  );
}

// ─── HISTOIRE PAGE ───────────────────────────────────────────────────────
const HISTOIRE_GALLERY = [
  { src:"uploads/histoire/11-facade-chantier.jpg", label:"Façade sous échafaudage", text:"La grande façade classique en plein chantier de restauration : pierre, fronton et tourelles repris à l'identique." },
  { src:"uploads/histoire/12-salon-or.jpg",        label:"Le Grand Salon",          text:"Boiseries dorées, miroirs d'époque et cheminée monumentale — l'art de recevoir à la française retrouvé." },
  { src:"uploads/histoire/05-pierre.jpg",          label:"Restauration de la pierre", text:"Nettoyage et consolidation des élévations du XVIIIᵉ siècle." },
  { src:"uploads/histoire/06-paves-pose.jpg",      label:"Pose des pavés", text:"Recréation à l'identique des allées en pavés anciens, posées à la main." },
  { src:"uploads/histoire/07-paves-final.jpg",     label:"Allée d'honneur", text:"Le cheminement principal vers l'entrée, achevé et bordé de buis taillés." },
  { src:"uploads/histoire/09-jardin.jpg",          label:"Jardins à la française", text:"Dessin des parterres, plantation des buis et reprise des massifs." },
  { src:"uploads/histoire/10-final.jpg",           label:"La façade restaurée", text:"Le château retrouve son blanc d'origine, encadré de ses deux tourelles." }
];

function HistoirePage() {
  return (
    <>
      <PageBanner
        eyebrow="Charly-sur-Marne · Vallée de la Marne"
        title="Une Histoire contée sur des siècles"
        subtitle="De Caroli Villa, domaine de Charles Martel, au Château Lazaar restauré en 2020 — un lieu où chaque pierre raconte un fragment de l'histoire de France."
        image="uploads/histoire/01-facade.jpg"
      />

      {/* Intro éditorial */}
      <section style={{ background:"#131313", padding:"100px 0" }}>
        <div style={{ maxWidth:1200, margin:"0 auto", padding:"0 48px", display:"grid", gridTemplateColumns:"1fr 1fr", gap:80, alignItems:"start" }}>
          <Reveal>
            <Label style={{ display:"block", marginBottom:18 }}>Le Lieu</Label>
            <h2 style={{ ...serif, fontSize:"clamp(30px,3.4vw,48px)", color:"#e5e2e1", letterSpacing:"-0.02em", lineHeight:1.15, fontWeight:400, marginBottom:0 }}>
              Au cœur de la vallée<br/>de la Marne
            </h2>
          </Reveal>
          <Reveal delay="0.15s">
            <p style={{ ...mono, color:"#d1c5b4", fontWeight:300, lineHeight:1.85, fontSize:16, marginBottom:22 }}>
              Le Château Lazaar veille sur Charly-sur-Marne depuis 1760. Construit dans le style classique français, il occupe un site dont la mémoire remonte au VIIIᵉ siècle, lorsque la commune portait encore le nom latin de <em style={{ color:GOLD, fontStyle:"italic" }}>Caroli Villa</em>, « Domaine de Charles ».
            </p>
            <p style={{ ...mono, color:"#d1c5b4", fontWeight:300, lineHeight:1.85, fontSize:16 }}>
              Sa silhouette, ses deux tourelles d'ardoise, son fronton sculpté et ses jardins à la française composent un ensemble rare, témoignage vivant de l'art de bâtir français.
            </p>
          </Reveal>
        </div>
      </section>

      {/* Héritage carolingien */}
      <section style={{ background:"#131313", padding:"100px 0" }}>
        <div style={{ maxWidth:1400, margin:"0 auto", padding:"0 48px" }}>
          <div style={{ display:"grid", gridTemplateColumns:"5fr 7fr", gap:64, alignItems:"center" }}>
            <Reveal>
              <Label style={{ display:"block", marginBottom:18 }}>L'héritage carolingien</Label>
              <h2 style={{ ...serif, fontSize:"clamp(28px,3.2vw,46px)", color:"#e5e2e1", letterSpacing:"-0.02em", lineHeight:1.15, marginBottom:24, fontWeight:400 }}>
                De Caroli Villa<br/>à Charly-sur-Marne
              </h2>
              <p style={{ ...mono, color:"#d1c5b4", fontWeight:300, lineHeight:1.85, fontSize:16, marginBottom:20 }}>
                Le nom <em style={{ color:GOLD }}>Caroli Villa</em> rend hommage à Charles Martel, maire du palais et ancêtre de Pépin le Bref, fondateur de la dynastie carolingienne. Sa victoire face aux troupes arabes à Poitiers, en 732, marque un tournant pour l'Europe naissante.
              </p>
              <p style={{ ...mono, color:"#d1c5b4", fontWeight:300, lineHeight:1.85, fontSize:16 }}>
                C'est en 2006 que la commune adopte officiellement le nom de Charly-sur-Marne, en référence directe à ce passé carolingien dont le château est aujourd'hui l'un des plus beaux gardiens.
              </p>
            </Reveal>
            <Reveal delay="0.18s">
              <div style={{ display:"grid", gridTemplateColumns:"1fr 1fr", gap:4 }}>
                {[
                  { v:"732", l:"Bataille de Poitiers", s:"Charles Martel arrête l'avancée arabe." },
                  { v:"1760", l:"Construction du château", s:"Style classique français." },
                  { v:"XIXᵉ", l:"Hôtel-Dieu de Soissons", s:"Le domaine devient lieu d'accueil." },
                  { v:"2020", l:"Restauration Lazaar", s:"Renaissance fidèle du domaine." }
                ].map(({ v, l, s }) => (
                  <div key={v} style={{ background:"#131313", padding:"32px 26px" }}>
                    <div style={{ ...serif, fontSize:26, color:GOLD, fontStyle:"italic", marginBottom:10, fontWeight:400 }}>{v}</div>
                    <div style={{ ...mono, fontSize:11, textTransform:"uppercase", letterSpacing:"0.15em", color:"#e5e2e1", marginBottom:8, fontWeight:600 }}>{l}</div>
                    <div style={{ ...mono, fontSize:11, color:"#d1c5b4", lineHeight:1.65, fontWeight:300 }}>{s}</div>
                  </div>
                ))}
              </div>
            </Reveal>
          </div>
        </div>
      </section>

      {/* Galerie restauration */}
      <section style={{ background:"#131313", padding:"110px 0" }}>
        <div style={{ maxWidth:1400, margin:"0 auto", padding:"0 48px" }}>
          <Reveal style={{ textAlign:"center", marginBottom:72, maxWidth:720, marginInline:"auto" }}>
            <Label style={{ display:"block", marginBottom:18 }}>La Restauration · 2020 → 2024</Label>
            <h2 style={{ ...serif, fontSize:"clamp(32px,3.6vw,52px)", color:"#e5e2e1", letterSpacing:"-0.02em", lineHeight:1.12, fontWeight:400, marginBottom:22 }}>
              Une renaissance pierre à pierre
            </h2>
            <p style={{ ...mono, color:"#d1c5b4", fontWeight:300, lineHeight:1.85, fontSize:15 }}>
              Sous l'impulsion de Monsieur Lazaar, le domaine a fait l'objet d'une restauration complète : reprise des façades, des charpentes, des tourelles, recréation des allées pavées et redessin des jardins à la française. Un chantier de plusieurs années, mené par des compagnons et artisans d'art.
            </p>
          </Reveal>

          <div style={{ display:"grid", gridTemplateColumns:"repeat(12, 1fr)", gap:8 }}>
            {HISTOIRE_GALLERY.map((item, i) => {
              const layouts = [
                { gc:"span 7", h:520 },
                { gc:"span 5", h:520 },
                { gc:"span 5", h:420 },
                { gc:"span 7", h:420 },
                { gc:"span 4", h:420 },
                { gc:"span 4", h:420 },
                { gc:"span 4", h:420 }
              ];
              const L = layouts[i] || { gc:"span 6", h:420 };
              return (
                <Reveal key={item.src} delay={`${(i % 3) * 0.08}s`} style={{ gridColumn:L.gc }} className="cl-gal-cell">
                  <div className="zoom-wrap" style={{ position:"relative", overflow:"hidden", background:"#131313", height:L.h }}>
                    <img src={item.src} alt={item.label} className="zoom-img" style={{ width:"100%", height:"100%", objectFit:"cover", display:"block", transition:"transform 1.2s cubic-bezier(0.16,1,0.3,1), filter 0.6s" }} />
                    <div style={{ position:"absolute", inset:0, background:"linear-gradient(180deg,transparent 55%,rgba(8,8,8,0.85) 100%)", pointerEvents:"none" }} />
                    <div style={{ position:"absolute", left:24, right:24, bottom:22, color:"#fff" }}>
                      <div style={{ ...serif, fontSize:18, color:GOLD, marginBottom:6, fontWeight:400 }}>{item.label}</div>
                      <div style={{ ...mono, fontSize:11, color:"#d1c5b4", fontWeight:300, lineHeight:1.55, maxWidth:420 }}>{item.text}</div>
                    </div>
                  </div>
                </Reveal>
              );
            })}
          </div>
        </div>
      </section>

      {/* Détails architecturaux */}
      <section style={{ background:"#131313", padding:"110px 0" }}>
        <div style={{ maxWidth:1200, margin:"0 auto", padding:"0 48px" }}>
          <Reveal style={{ textAlign:"center", marginBottom:64 }}>
            <Label style={{ display:"block", marginBottom:16 }}>L'Architecture</Label>
            <h2 style={{ ...serif, fontSize:"clamp(28px,3vw,44px)", color:"#e5e2e1", letterSpacing:"-0.02em", fontWeight:400 }}>
              Un style classique français
            </h2>
          </Reveal>
          <div style={{ display:"grid", gridTemplateColumns:"repeat(3,1fr)", gap:2 }}>
            {[
              { t:"Tourelles d'ardoise", d:"Deux flèches en ardoise coiffent les pavillons latéraux, signature visuelle du domaine." },
              { t:"Fronton sculpté", d:"Le tympan central porte un décor doré, dévoilant la signature de la maison." },
              { t:"Statuaire romaine", d:"Niches et socles accueillent une collection de statues de style romain." },
              { t:"Jardin à la française", d:"Parterres géométriques de buis, allées pavées, fontaine centrale." },
              { t:"Pierre de taille", d:"Façades en pierre claire, moulures et chaînages d'angle restaurés à l'identique." },
              { t:"Ferronnerie d'art", d:"Garde-corps, grilles et portails travaillés selon les techniques d'origine." }
            ].map(({ t, d }) => (
              <Reveal key={t}>
                <div style={{ background:"#131313", padding:"40px 32px", height:"100%" }}>
                  <div style={{ ...serif, fontSize:20, color:GOLD, marginBottom:14, fontWeight:400 }}>{t}</div>
                  <p style={{ ...mono, fontSize:13, color:"#d1c5b4", fontWeight:300, lineHeight:1.78, margin:0 }}>{d}</p>
                </div>
              </Reveal>
            ))}
          </div>
        </div>
      </section>
    </>
  );
}

// ─── BOUTIQUE PAGE ───────────────────────────────────────────────────────
function BoutiquePage() {
  return (
    <>
      <PageBanner
        eyebrow="La Boutique du Château"
        title="Des Produits Authentiques"
        subtitle="Une sélection issue du domaine et de partenaires artisans, dans l'esprit d'une épicerie fine à la française."
        image="uploads/histoire/09-jardin.jpg"
      />
      <Produits />
      <BoutiqueCTA />
    </>
  );
}

// ─── CONTACT PAGE ────────────────────────────────────────────────────────
function ContactPage() {
  const [form, setForm] = useState({ name:"", email:"", subject:"Visite privée", message:"" });
  const [sent, setSent] = useState(false);
  const [busy, setBusy] = useState(false);
  const [err, setErr] = useState("");
  const submit = async (e) => {
    e.preventDefault();
    if (busy) return;
    setBusy(true); setErr("");
    // Save the contact message + if subject suggests a visit, also create a reservation request.
    const trimmed = {
      name: form.name.trim(),
      email: form.email.trim(),
      subject: form.subject.trim(),
      message: form.message.trim()
    };
    const { error } = await sb.from("contact_messages").insert({
      ...trimmed,
      source: "contact_page"
    });
    if (!error && /visite|réservation|reservation/i.test(trimmed.subject)) {
      await sb.from("reservations").insert({
        name: trimmed.name,
        email: trimmed.email,
        message: `[${trimmed.subject}] ${trimmed.message}`
      });
    }
    setBusy(false);
    if (error) { setErr("Une erreur est survenue. Merci de réessayer."); return; }
    setSent(true);
  };
  return (
    <>
      <PageBanner
        eyebrow="Prise de Contact"
        title="Écrivez-nous"
        subtitle="Pour toute demande de visite, événement privé ou information sur la boutique, notre équipe vous répond avec attention."
        image="uploads/histoire/10-final.jpg"
      />
      <section style={{ background:"#131313", padding:"100px 0" }}>
        <div style={{ maxWidth:1200, margin:"0 auto", padding:"0 48px", display:"grid", gridTemplateColumns:"5fr 7fr", gap:80, alignItems:"start" }}>
          <Reveal>
            <Label style={{ display:"block", marginBottom:18 }}>Coordonnées</Label>
            <h2 style={{ ...serif, fontSize:"clamp(28px,3vw,42px)", color:"#e5e2e1", letterSpacing:"-0.02em", lineHeight:1.15, fontWeight:400, marginBottom:32 }}>
              Château Lazaar
            </h2>
            <div style={{ display:"flex", flexDirection:"column", gap:24, marginBottom:40 }}>
              {[
                { k:"Adresse", v:"95 rue Emile Morlot\n02310 Charly-sur-Marne" },
                { k:"E-mail", v:"contact@chateau-lazaar.com" },
                { k:"Visites", v:"Sur rendez-vous uniquement" }
              ].map(({ k, v }) => (
                <div key={k}>
                  <div style={{ ...mono, fontSize:10, textTransform:"uppercase", letterSpacing:"0.2em", color:GOLD, marginBottom:8 }}>{k}</div>
                  <div style={{ ...mono, color:"#d1c5b4", fontSize:15, fontWeight:300, lineHeight:1.7, whiteSpace:"pre-line" }}>{v}</div>
                </div>
              ))}
            </div>
            <a href="https://www.google.com/maps?q=95+rue+Emile+Morlot+02310+Charly-sur-Marne" target="_blank" rel="noreferrer" style={{ ...mono, fontSize:11, textTransform:"uppercase", letterSpacing:"0.22em", color:GOLD, textDecoration:"none", borderBottom:`1px solid ${GOLD}`, paddingBottom:4 }}>Ouvrir dans Maps</a>
          </Reveal>
          <Reveal delay="0.12s">
            <div style={{ background:"#131313", padding:"48px 44px" }}>
              {!sent ? (
                <>
                  <h3 style={{ ...serif, fontSize:24, color:"#e5e2e1", marginBottom:32, fontWeight:400 }}>Formulaire</h3>
                  <form onSubmit={submit} style={{ display:"grid", gridTemplateColumns:"1fr 1fr", gap:28 }}>
                    {[
                      ["name","Votre nom","text", "1 / 2"],
                      ["email","Adresse e-mail","email", "2 / 3"],
                      ["subject","Objet","text", "1 / 3"],
                      ["message","Votre message","textarea", "1 / 3"]
                    ].map(([k, l, type, col]) => (
                      <div key={k} style={{ gridColumn: col }}>
                        <label style={{ ...mono, fontSize:10, textTransform:"uppercase", letterSpacing:"0.2em", color:"#6b6258", display:"block", marginBottom:10 }}>{l}</label>
                        {type === "textarea"
                          ? <textarea rows={4} value={form[k]} onChange={e=>setForm(f=>({...f,[k]:e.target.value}))} required style={{ width:"100%", background:"none", border:"none", borderBottom:"1px solid rgba(78,70,57,0.4)", color:"#e5e2e1", ...mono, fontSize:15, fontWeight:300, padding:"8px 0", outline:"none", resize:"none", transition:"border-color 0.3s" }} onFocus={e=>e.target.style.borderBottomColor=GOLD} onBlur={e=>e.target.style.borderBottomColor="rgba(78,70,57,0.4)"} />
                          : <input type={type} value={form[k]} onChange={e=>setForm(f=>({...f,[k]:e.target.value}))} required style={{ width:"100%", background:"none", border:"none", borderBottom:"1px solid rgba(78,70,57,0.4)", color:"#e5e2e1", ...mono, fontSize:15, fontWeight:300, padding:"8px 0", outline:"none", transition:"border-color 0.3s" }} onFocus={e=>e.target.style.borderBottomColor=GOLD} onBlur={e=>e.target.style.borderBottomColor="rgba(78,70,57,0.4)"} />
                        }
                      </div>
                    ))}
                    {err && <div style={{ gridColumn:"1 / 3", ...mono, fontSize:11, color:"#e08c8c", letterSpacing:"0.06em" }}>{err}</div>}
                    <button type="submit" disabled={busy} style={{ gridColumn:"1 / 3", background:goldGrad, border:"none", cursor:busy?"wait":"pointer", color:"#412d00", ...mono, fontSize:11, textTransform:"uppercase", letterSpacing:"0.22em", fontWeight:700, padding:"16px", marginTop:12, opacity:busy?0.6:1 }}
                      onMouseEnter={e=>e.currentTarget.style.opacity=busy?"0.6":"0.85"} onMouseLeave={e=>e.currentTarget.style.opacity=busy?"0.6":"1"}
                    >{busy ? "Envoi…" : "Envoyer le message"}</button>
                  </form>
                </>
              ) : (
                <div style={{ textAlign:"center", padding:"60px 20px" }}>
                  <GoldLine w={48} center />
                  <h3 style={{ ...serif, fontSize:36, color:"#e5e2e1", letterSpacing:"-0.02em", margin:"28px 0 14px", fontWeight:400 }}>Merci</h3>
                  <p style={{ ...mono, color:"#d1c5b4", fontWeight:300, lineHeight:1.8, fontSize:15 }}>Votre message a bien été reçu.<br/>Nous vous répondrons dans les plus brefs délais.</p>
                </div>
              )}
            </div>
          </Reveal>
        </div>
      </section>
    </>
  );
}

// ─── HOME PAGE ───────────────────────────────────────────────────────────
function HomePage({ gold, onModal }) {
  return (
    <>
      <Hero gold={gold} />
      <Histoire onModal={onModal} />
      <Stats />
      <Produits />
      <SavoirFaire />
      <BoutiqueCTA />
    </>
  );
}

// ─── APP ─────────────────────────────────────────────────────────────────
function App() {
  const route = useRoute();
  const [histoireOpen, setHistoireOpen] = useState(false);
  const [contactOpen,  setContactOpen]  = useState(false);
  const [t, setTweak] = useTweaks(/*EDITMODE-BEGIN*/{
    "gold": "#e9c176",
    "grain": true
  }/*EDITMODE-END*/);
  return (
    <div className={t.grain?"grain-on":""}>
      <Nav gold={t.gold} onContact={() => navigateTo("contact")} route={route} />
      {route === "accueil"  && <HomePage gold={t.gold} onModal={() => navigateTo("histoire")} />}
      {route === "histoire" && <HistoirePage />}
      {route === "boutique" && <BoutiquePage />}
      {route === "contact"  && <ContactPage />}
      <Footer gold={t.gold} />
      <HistoireModal open={histoireOpen} onClose={() => setHistoireOpen(false)} />
      <ContactModal  open={contactOpen}  onClose={() => setContactOpen(false)} />
      <TweaksPanel>
        <TweakSection label="Marque" />
        <TweakColor label="Or Signature" value={t.gold} options={["#e9c176","#d4af7a","#b8966a","#c9b78a"]} onChange={v => setTweak("gold", v)} />
        <TweakSection label="Effets" />
        <TweakToggle label="Texture Grain" value={t.grain} onChange={v => setTweak("grain", v)} />
      </TweaksPanel>
    </div>
  );
}

ReactDOM.createRoot(document.getElementById("root")).render(<App />);
