/* sections.jsx — all homepage sections, RTL Hebrew.
   Every string, image and link below is read from window.CONTENT (content.js)
   so it can be edited at /admin. Layout and styling stay in code. */

const { useState, useEffect, useRef } = React;

const whatsappLink = (message) =>
  `https://wa.me/${CONTACT.whatsapp}?text=${encodeURIComponent(message || CONTACT.defaultWaMessage || "")}`;

/* shop category buttons, as [key, label] pairs */
const productFilters = () => (CONTENT.filters || []).map((f) => [f.key, f.label]);

/* ─────────── Announcement bar ─────────── */
function AnnouncementBar({ palette }){
  const items = (COPY.announce && COPY.announce.length) ? COPY.announce.filter(Boolean) : [];
  if (!items.length) return null;
  return (
    <div style={{ background: palette.ink, color: palette.bg, fontSize: 11, overflow: "hidden", position:"relative", letterSpacing:".06em" }}>
      <div className="ticker-track" style={{ display:"flex", whiteSpace:"nowrap", padding:"8px 0" }}>
        {[0,1].map(k => (
          <div key={k} style={{ display:"flex", gap:48, paddingInlineEnd:48 }}>
            {items.map((t,i)=>(
              <span key={i} style={{ display:"inline-flex", alignItems:"center", gap:10 }}>
                <span style={{ width:3, height:3, borderRadius:999, background: palette.gold, display:"inline-block" }}/>
                {t}
              </span>
            ))}
          </div>
        ))}
      </div>
    </div>
  );
}

/* ─────────── Nav ─────────── */
function Nav({ palette }){
  const [open, setOpen] = useState(false);
  const current = normalizePathname(window.location.pathname);
  const links = NAV.links || [];
  return (
    <header data-screen-label="01 Nav" style={{ position:"sticky", top:0, zIndex:50, background: `${palette.bg}F0`, backdropFilter:"saturate(140%) blur(16px)", borderBottom:`1px solid ${palette.line}` }}>
      <div className="container" style={{ display:"flex", alignItems:"center", justifyContent:"space-between", padding:"18px 24px", gap:16 }}>
        <a href="/" style={{ display:"flex", alignItems:"center", gap:10 }}>
          <Logo palette={palette}/>
        </a>
        <nav className="nav-desktop" style={{ display:"flex", gap:30, fontSize:13, alignItems:"center" }}>
          {links.map((l,i)=>{
            const active = l.href === "/" ? current === "/" : current === l.href || current.startsWith(`${l.href}/`);
            return (
            <a key={i} href={l.href} style={{ color: palette.ink, opacity: active ? 1 : .72, fontWeight: active ? 500 : 400, padding:"4px 0", position:"relative", transition:"opacity .25s ease" }}
               onMouseEnter={e=>e.currentTarget.style.opacity="1"}
               onMouseLeave={e=>e.currentTarget.style.opacity = active ? "1" : ".72"}
            >
              {l.label}
              {active && <span aria-hidden="true" style={{ position:"absolute", insetInlineStart:"50%", bottom:-4, width:4, height:4, borderRadius:999, background: palette.accent, transform:"translateX(50%)" }}/>}
            </a>
          )})}
        </nav>
        <div style={{ display:"flex", alignItems:"center", gap:4 }}>
          <a href="/products" aria-label="חיפוש מוצרים" style={iconBtn(palette)}><IconSearch size={18}/></a>
          <a href={whatsappLink(NAV.waMessage)} aria-label="הזמנה בוואטסאפ" style={{...iconBtn(palette), position:"relative"}}>
            <IconBag size={18}/>
          </a>
          <button aria-label="תפריט" onClick={()=>setOpen(o=>!o)} style={{...iconBtn(palette), display:"none"}} className="nav-burger">
            {open ? <IconClose size={18}/> : <IconMenu size={18}/>}
          </button>
        </div>
      </div>
      {open && (
        <nav className="nav-mobile" style={{ borderTop:`1px solid ${palette.line}`, background: palette.bg, padding:"10px 24px 18px" }}>
          {links.map((l)=>(
            <a key={l.href} href={l.href} onClick={()=>setOpen(false)}
              style={{ display:"block", padding:"13px 0", borderBottom:`1px solid ${palette.line}`, color: palette.ink, fontSize:15, fontWeight:600 }}>
              {l.label}
            </a>
          ))}
          <a href={whatsappLink(NAV.waMessage)} style={{ display:"inline-flex", alignItems:"center", gap:8, marginTop:14, background: palette.accent, color: palette.bg, padding:"12px 18px", borderRadius:999, fontSize:14, fontWeight:700 }}>
            <IconWa size={16}/> {NAV.mobileCta}
          </a>
        </nav>
      )}
      <style>{`
        @media (max-width: 920px){
          .nav-desktop{ display:none !important; }
          .nav-burger{ display:grid !important; }
        }
        @media (min-width: 921px){
          .nav-mobile{ display:none !important; }
        }
      `}</style>
    </header>
  );
}
const iconBtn = (palette) => ({
  width:38, height:38, display:"grid", placeItems:"center",
  borderRadius:999, border:"0", background:"transparent", color: palette.ink,
});

function Logo({ palette, compact = false }){
  const size = compact ? 22 : 28;
  return (
    <div style={{ display:"flex", alignItems:"baseline", gap:6, lineHeight:1, direction:"ltr" }}>
      <span style={{ fontFamily:'"Cormorant Garamond", Georgia, serif', fontStyle:"italic", fontWeight:500, fontSize: size, letterSpacing:".01em" }}>{SITE.logoFirst}</span>
      <span style={{ fontFamily:'"Cormorant Garamond", Georgia, serif', fontStyle:"italic", fontWeight:500, fontSize: size, letterSpacing:".01em", color: palette.accent }}>{SITE.logoSecond}</span>
    </div>
  );
}

/* ─────────── Hero ─────────── */
function Hero({ palette, variant="editorial" }){
  return <HeroEditorial palette={palette}/>;
}

function HeroEditorial({ palette }){
  const stats = COPY.heroStats || [];
  return (
    <section data-screen-label="02 Hero" className="pad-y" style={{ position:"relative", overflow:"hidden" }}>
      <div className="container" style={{ position:"relative" }}>
        <div className="hero-grid" style={{ display:"grid", gridTemplateColumns:"1.05fr .95fr", gap:64, alignItems:"center" }}>
          <div>
            <div className="eyebrow" style={{ color: palette.accent, display:"inline-flex", alignItems:"center", gap:14, marginBottom:28 }}>
              <span style={{ width:36, height:1, background: palette.accent, opacity:.5 }}/>
              <span style={{ width:3, height:3, borderRadius:999, background: palette.accent }}/>
              <span>{COPY.heroEyebrow}</span>
            </div>
            <h1 className="display" style={{ fontSize:"clamp(48px, 7.2vw, 104px)", margin:"0 0 26px", color: palette.ink, fontWeight:600, letterSpacing:"-.02em" }}>
              {COPY.heroTitleTop}
              <br/>
              <span style={{ color: palette.accent, fontStyle:"italic", fontWeight:400 }}>{COPY.heroTitleAccent}</span>
            </h1>
            <div style={{ display:"flex", alignItems:"center", gap:14, marginBottom:26 }}>
              <span style={{ width:32, height:1, background: palette.gold }}/>
              <span style={{ fontSize:13, color: palette.ink2, letterSpacing:".08em" }}>
                <span className="latin" style={{ fontStyle:"italic", color: palette.ink, fontWeight:500 }}>{COPY.heroByline}</span>
              </span>
            </div>
            <p style={{ fontSize:"clamp(16px, 1.35vw, 18.5px)", lineHeight:1.7, maxWidth:"44ch", color: palette.ink2, marginTop:0, fontWeight:400 }}>
              {COPY.heroLede}
            </p>
            <div style={{ display:"flex", flexWrap:"wrap", gap:14, marginTop:38, alignItems:"center" }}>
              <PrimaryBtn palette={palette} size="lg" href={whatsappLink(COPY.heroWaMessage)}>{COPY.heroPriceCta}</PrimaryBtn>
              <GhostBtn palette={palette} size="lg" href={COPY.heroSampleHref || "/sample"}>{COPY.heroSampleCta}</GhostBtn>
            </div>
            <div style={{ display:"flex", gap:36, marginTop:48, flexWrap:"wrap", alignItems:"flex-start" }}>
              {stats.map((s,i)=>(
                <div key={i}>
                  <div className="display" style={{ fontSize:30, color: palette.accent, fontWeight:600, lineHeight:1, letterSpacing:"-.02em" }}>{s.n}</div>
                  <div style={{ fontSize:11, color: palette.ink2, marginTop:6, letterSpacing:".14em", textTransform:"uppercase" }}>{s.l}</div>
                </div>
              ))}
            </div>
          </div>
          <div style={{ position:"relative", display:"grid", placeItems:"center", padding:"20px 0" }}>
            <div aria-hidden="true" style={{ position:"absolute", inset:"-30px 10%", background: palette.rose, borderRadius:"50% 38% 60% 42% / 50% 50% 60% 50%", opacity:.45, filter:"blur(3px)" }}/>
            <div style={{ position:"relative" }}>
              <BookCover width={340} palette={palette} rotate={-3}/>
            </div>
          </div>
        </div>
      </div>
      <style>{`
        @media (max-width: 900px){
          .hero-grid{ grid-template-columns: 1fr !important; gap: 36px !important; }
          .hero-grid > div:nth-child(2){ order: -1; }
        }
      `}</style>
    </section>
  );
}

/* ─────────── Trust / press strip ─────────── */
function TrustStrip({ palette }){
  const c = HOME.trust || {};
  return (
    <section style={{ borderTop:`1px solid ${palette.line}`, borderBottom:`1px solid ${palette.line}`, background: palette.surface }}>
      <div className="container" style={{ display:"flex", flexWrap:"wrap", alignItems:"center", justifyContent:"space-between", gap:20, padding:"22px 24px", color: palette.ink2 }}>
        <div style={{ display:"flex", alignItems:"center", gap:14 }}>
          <AdlerSeal palette={palette}/>
          <div style={{ fontSize:13.5 }}>
            <div style={{ fontWeight:600, color: palette.ink }}>{c.sealTitle}</div>
            <div style={{ opacity:.7, marginTop:2 }}>{c.sealSub}</div>
          </div>
        </div>
        <div className="press-row" style={{ display:"flex", alignItems:"center", gap:28, opacity:.75, flexWrap:"wrap" }}>
          {(c.keywords || []).map((p,i)=>(
            <span key={i} style={{ fontSize:13, letterSpacing:".06em", fontWeight:600 }}>{p}</span>
          ))}
        </div>
      </div>
    </section>
  );
}

function AdlerSeal({ palette, size = 56 }){
  const src = productImageSrc(C("home.trust.sealImage", "/assets/adler-seal.png"));
  if (!src) return null;
  return (
    <img
      src={src}
      alt={C("home.trust.sealTitle", "")}
      width={size}
      height={size}
      style={{ width: size, height: size, objectFit: "contain", display: "block" }}
    />
  );
}

/* ─────────── Value Props ─────────── */
function ValueProps({ palette }){
  const c = HOME.valueProps || {};
  const items = c.items || [];
  return (
    <section data-screen-label="04 Value Props" className="pad-y" style={{ background: palette.bg }}>
      <div className="container">
        <div style={{ display:"flex", alignItems:"end", justifyContent:"space-between", flexWrap:"wrap", gap:24, marginBottom:48 }}>
          <div style={{ maxWidth:560 }}>
            <Eyebrow palette={palette}>{c.eyebrow}</Eyebrow>
            <h2 className="display" style={{ fontSize:"clamp(34px, 4.5vw, 56px)", margin:"14px 0 0" }}>{c.title}</h2>
          </div>
          <p style={{ maxWidth:380, color: palette.ink2, fontSize:15.5, lineHeight:1.6, margin:0 }}>
            {c.intro}
          </p>
        </div>
        <div className="vp-grid" style={{ display:"grid", gridTemplateColumns:`repeat(${Math.max(items.length,1)}, 1fr)`, gap:0, border:`1px solid ${palette.line}`, borderRadius:6, overflow:"hidden", background: palette.surface }}>
          {items.map((it,i)=>{
            const ItIcon = iconByName(it.icon);
            return (
            <div key={i} style={{
              padding:"32px 28px",
              borderInlineEnd: i<items.length-1 ? `1px solid ${palette.line}` : "none",
              position:"relative",
            }}>
              <div className="latin" style={{ fontSize:12, color: palette.accent, letterSpacing:".24em" }}>{it.n}</div>
              <div style={{ marginTop:18, width:52, height:52, borderRadius:999, background: palette.accent, color: palette.bg, display:"grid", placeItems:"center", boxShadow:`0 8px 18px -8px ${palette.accent}` }}>
                <ItIcon size={24} stroke={palette.bg} strokeWidth={1.9}/>
              </div>
              <h3 className="display" style={{ fontSize:24, margin:"18px 0 10px", fontWeight:600 }}>{it.t}</h3>
              <p style={{ fontSize:14.5, lineHeight:1.6, color: palette.ink2, margin:0 }}>{it.d}</p>
            </div>
          )})}
        </div>
      </div>
      <style>{`
        @media (max-width: 920px){
          .vp-grid{ grid-template-columns: 1fr 1fr !important; }
          .vp-grid > div:nth-child(2n){ border-inline-end:none !important; }
          .vp-grid > div:nth-child(-n+2){ border-bottom: 1px solid ${palette.line}; }
        }
        @media (max-width: 560px){
          .vp-grid{ grid-template-columns: 1fr !important; }
          .vp-grid > div{ border-inline-end:none !important; border-bottom: 1px solid ${palette.line}; }
          .vp-grid > div:last-child{ border-bottom:none; }
        }
      `}</style>
    </section>
  );
}

/* ─────────── About the book / editorial spread ─────────── */
function AboutBook({ palette }){
  const c = HOME.aboutBook || {};
  const img = productImageSrc(c.image);
  return (
    <section id="book" data-screen-label="05 About Book" className="pad-y" style={{ background: palette.surface, position:"relative" }}>
      <div className="container">
        <div className="about-grid" style={{ display:"grid", gridTemplateColumns:"1fr 1.15fr", gap:64, alignItems:"center" }}>
          <div style={{ position:"relative" }}>
            {img
              ? <img src={img} alt={c.imageAlt || ""} style={{ width:"100%", aspectRatio:"4/5", objectFit:"cover", objectPosition:"center", borderRadius:4, display:"block" }}/>
              : <PhotoPlaceholder label={c.imageAlt || "תמונה"} palette={palette} tone="rose"/>}
            <div style={{ position:"absolute", insetInlineStart:-30, bottom:-30, background: palette.bg, padding:18, border:`1px solid ${palette.line}`, borderRadius:6, maxWidth:240, boxShadow:"0 20px 40px -20px rgba(0,0,0,.18)" }}>
              <IconChat size={26} stroke={palette.accent}/>
              <p className="display" style={{ fontSize:17, lineHeight:1.45, margin:"10px 0 8px", fontWeight:500 }}>
                {c.cardTitle}
              </p>
              <div style={{ fontSize:12, color: palette.ink2 }}>{c.cardSub}</div>
            </div>
          </div>
          <div>
            <Eyebrow palette={palette}>{c.eyebrow}</Eyebrow>
            <h2 className="display" style={{ fontSize:"clamp(32px, 4vw, 50px)", margin:"14px 0 22px", lineHeight:1.1 }}>
              {c.title} <span style={{ color: palette.accent, fontStyle:"italic", fontWeight:500 }}>{c.titleAccent}</span>
            </h2>
            <p style={{ fontSize:16.5, lineHeight:1.7, color: palette.ink2, marginTop:0 }}>
              {c.p1}
            </p>
            <p style={{ fontSize:16.5, lineHeight:1.7, color: palette.ink2 }}>
              {c.p2}
            </p>
            <div style={{ display:"grid", gridTemplateColumns:"repeat(2, 1fr)", gap:18, marginTop:30 }}>
              {(c.stats || []).map((s,i)=>(
                <div key={i} style={{ borderTop:`1px solid ${palette.line}`, paddingTop:14 }}>
                  <div className="display" style={{ fontSize:32, color: palette.accent, fontWeight:700 }}>{s.n}</div>
                  <div style={{ fontSize:13, color: palette.ink2, marginTop:2 }}>{s.l}</div>
                </div>
              ))}
            </div>
            <div style={{ display:"flex", gap:12, marginTop:30, flexWrap:"wrap" }}>
              {c.ctaLabel && <PrimaryBtn palette={palette} href={c.ctaHref || "/products"}>{c.ctaLabel}</PrimaryBtn>}
              {c.ghostLabel && <GhostBtn palette={palette} href={c.ghostHref || "/sample"}>{c.ghostLabel}</GhostBtn>}
            </div>
          </div>
        </div>
      </div>
      <style>{`
        @media (max-width: 900px){
          .about-grid{ grid-template-columns: 1fr !important; gap: 56px !important; }
        }
      `}</style>
    </section>
  );
}

/* ─────────── Products grid ─────────── */
function formatProductPrice(n) {
  return `₪${Number(n).toLocaleString("he-IL", { minimumFractionDigits: n % 1 ? 2 : 0, maximumFractionDigits: 2 })}`;
}
function productDiscountPercent(product) {
  if (!product.was) return null;
  return Math.round((1 - product.price / product.was) * 100);
}
function Products({ palette }){
  const [filter, setFilter] = useState("all");
  const c = HOME.productsSection || {};
  const filters = productFilters();
  const visible = filter === "all" ? PRODUCTS : PRODUCTS.filter(p => (p.categories||[]).includes(filter));
  return (
    <section id="products" data-screen-label="12 Products" className="pad-y" style={{ background: palette.bg }}>
      <div className="container">
        <div style={{ display:"flex", alignItems:"end", justifyContent:"space-between", flexWrap:"wrap", gap:24, marginBottom:36 }}>
          <div>
            <Eyebrow palette={palette}>{c.eyebrow}</Eyebrow>
            <h2 className="display" style={{ fontSize:"clamp(34px, 4.5vw, 56px)", margin:"14px 0 0" }}>{c.title}</h2>
          </div>
          <div style={{ display:"flex", gap:6, flexWrap:"wrap" }}>
            {filters.map(([k,l])=>(
              <button key={k} onClick={()=>setFilter(k)} style={{
                padding:"8px 16px", borderRadius:999, fontSize:13.5, fontWeight:500,
                background: filter===k ? palette.ink : "transparent",
                color: filter===k ? palette.bg : palette.ink,
                border: filter===k ? "none" : `1px solid ${palette.line}`,
              }}>{l} <span style={{ opacity:.62 }}>{k === "all" ? PRODUCTS.length : PRODUCTS.filter(p => (p.categories||[]).includes(k)).length}</span></button>
            ))}
          </div>
        </div>
        <div className="prod-grid" style={{ display:"grid", gridTemplateColumns:"repeat(4, 1fr)", gap:18 }}>
          {visible.map(p => <ProductCard key={p.id} palette={palette} product={p}/>)}
        </div>
        <div style={{ display:"flex", justifyContent:"center", marginTop:36 }}>
          <GhostBtn palette={palette} href="/products">{c.allLabel} <IconArrowL size={16}/></GhostBtn>
        </div>
      </div>
      <style>{`
        @media (max-width: 1100px){ .prod-grid{ grid-template-columns: repeat(3, 1fr) !important; } }
        @media (max-width: 760px){ .prod-grid{ grid-template-columns: repeat(2, 1fr) !important; } }
        @media (max-width: 480px){ .prod-grid{ grid-template-columns: 1fr !important; } }
      `}</style>
    </section>
  );
}

function ProductCard({ product, palette }){
  const [hover, setHover] = useState(false);
  const bg = product.img ? palette.surface : palette.rose;
  const discount = productDiscountPercent(product);
  const orderMsg = `${C("pages.productDetail.orderWaPrefix", "שלום סיגי, אשמח להזמין את")} ${product.title}`;
  return (
    <div
      onMouseEnter={()=>setHover(true)} onMouseLeave={()=>setHover(false)}
      style={{ background: palette.bg, overflow:"hidden", border:`1px solid ${palette.line}`, display:"flex", flexDirection:"column", transition:"transform .4s ease, border-color .4s ease", transform: hover ? "translateY(-3px)" : "none", borderColor: hover ? palette.gold : palette.line }}
    >
      <div style={{ position:"relative", aspectRatio:"4/5", overflow:"hidden", background: bg }}>
        {product.img === "book-cover" ? (
          <div style={{ display:"grid", placeItems:"center", height:"100%", background: bg }}>
            <img src="/assets/book-cover.jpg" alt={product.title} style={{ maxHeight:"86%", maxWidth:"72%", filter:"drop-shadow(0 20px 30px rgba(28,24,21,.2))", transform: hover ? "rotate(-2deg) scale(1.04)" : "rotate(-2deg)", transition:"transform .5s cubic-bezier(.2,.8,.2,1)" }}/>
          </div>
        ) : product.img ? (
          <div style={{ display:"grid", placeItems:"center", height:"100%", background: bg, padding:"6%" }}>
            <img src={productImageSrc(product.img)} alt={product.title} style={{ maxWidth:"100%", maxHeight:"100%", objectFit:"contain", transition:"transform .5s cubic-bezier(.2,.8,.2,1)", transform: hover ? "scale(1.04)" : "none" }}/>
          </div>
        ) : (
          <PhotoPlaceholder label={product.title} palette={palette} tone={product.tone} ratio=""/>
        )}
        {product.tag && (
          <div style={{ position:"absolute", insetInlineStart:14, top:14, color: palette.ink, fontSize:10, fontWeight:500, padding:"4px 0", letterSpacing:".22em", textTransform:"uppercase", borderBottom:`1px solid ${palette.gold}` }}>
            {product.tag}
          </div>
        )}
        {discount && (
          <div style={{ position:"absolute", insetInlineEnd:14, top:14, background: palette.accent, color: palette.bg, borderRadius:999, padding:"5px 9px", fontSize:11, fontWeight:700 }}>
            {discount}% הנחה
          </div>
        )}
        <a href={whatsappLink(orderMsg)} style={{
          position:"absolute", insetInlineEnd:14, bottom:14,
          background: palette.ink, color: palette.bg, border:0,
          width:38, height:38, display:"grid", placeItems:"center",
          opacity: hover ? 1 : .9, transform: hover ? "scale(1.08)" : "none", transition:"all .3s ease",
          borderRadius:0,
        }} aria-label={`הזמנת ${product.title}`}><IconPlus size={16}/></a>
      </div>
      <div style={{ padding:"20px 20px 22px", display:"flex", flexDirection:"column", gap:14, flex:1 }}>
        <a href={`/products/${product.slug}`} className="display" style={{ fontSize:17, fontWeight:600, lineHeight:1.3, color: palette.ink, letterSpacing:"-.005em" }}>{product.title}</a>
        <p style={{ fontSize:13.5, lineHeight:1.5, color: palette.ink2, margin:0 }}>{product.summary}</p>
        <div style={{ display:"flex", alignItems:"end", justifyContent:"space-between", gap:12, marginTop:"auto" }}>
          <div>
            <div style={{ fontSize:11, color: palette.accent, fontWeight:700, marginBottom:2 }}>{C("pages.productDetail.priceLabel", "מחיר מבצע")}</div>
            <span className="display" style={{ fontWeight:600, color: palette.ink, fontSize:20, letterSpacing:"-.01em" }}>{formatProductPrice(product.price)}</span>
            {product.was ? <span style={{ textDecoration:"line-through", color: palette.ink2, fontSize:13, opacity:.6, marginInlineStart:8 }}>{formatProductPrice(product.was)}</span> : null}
          </div>
          <a href={`/products/${product.slug}`} style={{ fontSize:13, fontWeight:700, color: palette.accent, borderBottom:`1px solid ${palette.accent}` }}>פרטים</a>
        </div>
      </div>
    </div>
  );
}

/* ─────────── Who it's for ─────────── */
function WhoItsFor({ palette }){
  const c = HOME.whoItsFor || {};
  const items = c.items || [];
  return (
    <section data-screen-label="15 Who It's For" className="pad-y" style={{ background: palette.bg }}>
      <div className="container">
        <Eyebrow palette={palette}>{c.eyebrow}</Eyebrow>
        <div style={{ display:"flex", alignItems:"end", justifyContent:"space-between", flexWrap:"wrap", gap:24, marginTop:14, marginBottom:40 }}>
          <h2 className="display" style={{ fontSize:"clamp(32px, 4vw, 50px)", margin:0, maxWidth:680 }}>
            {c.titlePre} <span style={{ color: palette.accent, fontStyle:"italic", fontWeight:500 }}>{c.titleAccent}</span> {c.titleEnd}
          </h2>
        </div>
        <div className="who-grid" style={{ display:"grid", gridTemplateColumns:`repeat(${Math.max(items.length,1)}, 1fr)`, gap:18 }}>
          {items.map((it,i)=>{
            const ItIcon = iconByName(it.icon);
            return (
            <div key={i} style={{ background: palette.surface, padding:"28px 24px", borderRadius:6, border:`1px solid ${palette.line}` }}>
              <div style={{ width:46, height:46, borderRadius:999, background: palette.rose, color: palette.accent2, display:"grid", placeItems:"center" }}><ItIcon/></div>
              <h3 className="display" style={{ fontSize:22, margin:"18px 0 8px", fontWeight:600 }}>{it.t}</h3>
              <p style={{ fontSize:14.5, lineHeight:1.6, color: palette.ink2, margin:0 }}>{it.d}</p>
            </div>
          )})}
        </div>
      </div>
      <style>{`
        @media (max-width: 800px){ .who-grid{ grid-template-columns: 1fr !important; } }
      `}</style>
    </section>
  );
}

/* ─────────── Reflection cards ─────────── */
function Testimonials({ palette }){
  const c = HOME.reflection || {};
  const cards = c.cards || [];
  return (
    <section data-screen-label="16 Testimonials" className="pad-y" style={{ background: palette.accent2, color: palette.bg, position:"relative" }}>
      <div className="container">
        <div style={{ display:"flex", alignItems:"end", justifyContent:"space-between", flexWrap:"wrap", gap:24, marginBottom:42 }}>
          <div>
            <Eyebrow palette={palette} color={palette.gold}>{c.eyebrow}</Eyebrow>
            <h2 className="display" style={{ fontSize:"clamp(34px, 4.5vw, 56px)", margin:"14px 0 0", color: palette.bg }}>{c.title}</h2>
          </div>
          <p style={{ maxWidth:420, fontSize:15.5, lineHeight:1.65, opacity:.82, margin:0 }}>
            {c.text}
          </p>
        </div>

        <div className="testi-grid" style={{ display:"grid", gridTemplateColumns:"repeat(4, 1fr)", gap:18 }}>
          {cards.map((t,i)=>(
            <figure key={i} style={{
              background: `${palette.bg}10`,
              color: palette.bg,
              padding: "24px 22px",
              borderRadius: 6, border: `1px solid ${palette.bg}22`,
              margin:0, display:"flex", flexDirection:"column",
            }}>
              <IconChat size={24} stroke={palette.gold}/>
              <blockquote className="display" style={{ fontSize:20, lineHeight:1.25, margin: "16px 0 14px", fontWeight:600 }}>
                {t.q}
              </blockquote>
              <p style={{ margin:"auto 0 0", opacity:.78, fontSize:14, lineHeight:1.6 }}>{t.a}</p>
            </figure>
          ))}
        </div>
      </div>
      <style>{`
        @media (max-width: 980px){
          .testi-grid{ grid-template-columns: 1fr 1fr !important; }
        }
        @media (max-width: 600px){
          .testi-grid{ grid-template-columns: 1fr !important; }
        }
      `}</style>
    </section>
  );
}

/* ─────────── Group purchase CTA ─────────── */
function GroupPurchase({ palette }){
  const c = HOME.group || {};
  const rows = c.rows || [];
  return (
    <section id="group" data-screen-label="17 Group Purchase" className="pad-y" style={{ background: palette.bg }}>
      <div className="container">
        <div className="group-grid" style={{ background: palette.surface, border:`1px solid ${palette.line}`, borderRadius:8, padding:"56px 56px", display:"grid", gridTemplateColumns:"1.2fr 1fr", gap:48, alignItems:"center" }}>
          <div>
            <Eyebrow palette={palette}>{c.eyebrow}</Eyebrow>
            <h2 className="display" style={{ fontSize:"clamp(30px, 3.8vw, 46px)", margin:"14px 0 18px", lineHeight:1.1 }}>
              {c.title} <span style={{ color: palette.accent, fontStyle:"italic", fontWeight:500 }}>{c.titleAccent}</span>
            </h2>
            <p style={{ fontSize:16, lineHeight:1.65, color: palette.ink2, margin:0 }}>
              {c.text}
            </p>
            <div style={{ display:"flex", gap:12, marginTop:28, flexWrap:"wrap" }}>
              <PrimaryBtn palette={palette} href={CONTACT.phoneHref}><IconPhone size={16}/> {c.ctaPrefix} {CONTACT.phone}</PrimaryBtn>
              <GhostBtn palette={palette} href={whatsappLink(c.waMessage)}><IconWa size={16}/> {c.ghostLabel}</GhostBtn>
            </div>
          </div>
          <div style={{ display:"grid", gap:14 }}>
            {rows.map((r,i)=>(
              <div key={i} style={{ display:"flex", alignItems:"baseline", gap:18, borderBottom: i<rows.length-1 ? `1px solid ${palette.line}` : "none", paddingBottom:14 }}>
                <div className="display" style={{ fontSize:34, color: palette.accent, fontWeight:700, minWidth:90 }}>{r.n}</div>
                <div style={{ fontSize:14.5, color: palette.ink2 }}>{r.l}</div>
              </div>
            ))}
          </div>
        </div>
      </div>
      <style>{`
        @media (max-width: 900px){
          .group-grid{ grid-template-columns: 1fr !important; padding: 36px 28px !important; gap: 32px !important; }
        }
      `}</style>
    </section>
  );
}

/* ─────────── Free chapter (lead magnet) ─────────── */
function LeadMagnet({ palette }){
  const c = HOME.leadMagnet || {};
  return (
    <section id="sample" data-screen-label="18 Lead Magnet" className="pad-y" style={{ background: palette.ink, color: palette.bg, position:"relative", overflow:"hidden" }}>
      <div aria-hidden="true" style={{ position:"absolute", insetInlineEnd:-100, top:-50, width:380, height:380, background: palette.accent, borderRadius:"50% 38% 60% 42% / 50% 50% 60% 50%", opacity:.22, filter:"blur(10px)" }}/>
      <div className="container" style={{ position:"relative" }}>
        <div className="lm-grid" style={{ display:"grid", gridTemplateColumns:"1.3fr 1fr", gap:48, alignItems:"center" }}>
          <div>
            <Eyebrow palette={palette} color={palette.gold}>{c.eyebrow}</Eyebrow>
            <h2 className="display" style={{ fontSize:"clamp(30px, 4vw, 50px)", margin:"14px 0 18px", color: palette.bg }}>
              {c.title}
            </h2>
            <p style={{ fontSize:16, lineHeight:1.65, opacity:.85, marginTop:0, maxWidth:"50ch" }}>
              {c.text}
            </p>
            <div style={{ marginTop:28, display:"flex", gap:10, flexWrap:"wrap" }}>
              <a href={whatsappLink(c.waMessage)} style={{ background: palette.accent, color: palette.bg, border:0, padding:"14px 24px", borderRadius:999, fontSize:15, fontWeight:600, display:"inline-flex", alignItems:"center", gap:8 }}>
                <IconWa size={16}/> {c.waLabel}
              </a>
              <a href={`mailto:${CONTACT.email}?subject=${encodeURIComponent(c.mailSubject || "")}`} style={{ background:"transparent", color: palette.bg, border:`1.5px solid ${palette.bg}55`, padding:"13px 22px", borderRadius:999, fontSize:15, fontWeight:600, display:"inline-flex", alignItems:"center", gap:8 }}>
                <IconMail size={16}/> {c.mailLabel}
              </a>
            </div>
          </div>
          <div style={{ display:"grid", placeItems:"center" }}>
            <div style={{ position:"relative", padding:32, background: `${palette.bg}0A`, borderRadius:12, border:`1px solid ${palette.bg}22` }}>
              <PdfPage palette={palette} label={c.pageExercise}/>
              <div style={{ position:"absolute", top:-12, insetInlineStart:-12, background: palette.gold, color: palette.ink, padding:"6px 14px", borderRadius:999, fontSize:12, fontWeight:700 }}>{c.badge}</div>
            </div>
          </div>
        </div>
      </div>
      <style>{`
        @media (max-width: 900px){ .lm-grid{ grid-template-columns: 1fr !important; } .lm-grid > div:nth-child(2){ display:none } }
      `}</style>
    </section>
  );
}

function PdfPage({ palette, label }){
  return (
    <svg width="220" height="280" viewBox="0 0 220 280" style={{ filter: "drop-shadow(0 30px 50px rgba(0,0,0,.4))" }}>
      <rect x="0" y="0" width="220" height="280" rx="6" fill={palette.bg}/>
      <rect x="20" y="22" width="80" height="6" rx="2" fill={palette.accent}/>
      <rect x="20" y="40" width="180" height="14" rx="2" fill={palette.ink}/>
      <rect x="20" y="60" width="140" height="14" rx="2" fill={palette.ink}/>
      <rect x="20" y="92" width="180" height="3" rx="1" fill={palette.ink} opacity=".25"/>
      <rect x="20" y="102" width="170" height="3" rx="1" fill={palette.ink} opacity=".25"/>
      <rect x="20" y="112" width="160" height="3" rx="1" fill={palette.ink} opacity=".25"/>
      <rect x="20" y="122" width="180" height="3" rx="1" fill={palette.ink} opacity=".25"/>
      <rect x="20" y="132" width="120" height="3" rx="1" fill={palette.ink} opacity=".25"/>
      <rect x="20" y="156" width="160" height="3" rx="1" fill={palette.ink} opacity=".2"/>
      <rect x="20" y="166" width="180" height="3" rx="1" fill={palette.ink} opacity=".2"/>
      <rect x="20" y="176" width="140" height="3" rx="1" fill={palette.ink} opacity=".2"/>
      <rect x="20" y="210" width="180" height="50" rx="4" fill={palette.rose}/>
      <text x="110" y="241" textAnchor="middle" fontFamily="Frank Ruhl Libre, serif" fontSize="13" fontStyle="italic" fill={palette.accent2}>{label}</text>
    </svg>
  );
}

/* ─────────── FAQ ─────────── */
function FAQ({ palette, asPage = false }){
  const [open, setOpen] = useState(0);
  const c = HOME.faqSection || {};
  const HeadingTag = asPage ? "h1" : "h2";
  return (
    <section data-screen-label="19 FAQ" className="pad-y" style={{ background: palette.surface }}>
      <div className="container">
        <div className="faq-grid" style={{ display:"grid", gridTemplateColumns:"1fr 1.5fr", gap:64, alignItems:"start" }}>
          <div style={{ position:"sticky", top:80 }}>
            <Eyebrow palette={palette}>{c.eyebrow}</Eyebrow>
            <HeadingTag className="display" style={{ fontSize:"clamp(32px, 4vw, 50px)", margin:"14px 0 20px", lineHeight:1.05 }}>
              {c.title} <span style={{ color: palette.accent, fontStyle:"italic", fontWeight:500 }}>{c.titleAccent}</span>
            </HeadingTag>
            <p style={{ fontSize:15, lineHeight:1.6, color: palette.ink2, margin:0 }}>
              {c.note} <a href="/contact" style={{ color: palette.accent, fontWeight:600, borderBottom:`1px solid ${palette.accent}` }}>{c.noteLink}</a>.
            </p>
          </div>
          <div>
            {FAQS.map((f,i)=>(
              <div key={i} style={{ borderTop:`1px solid ${palette.line}`, borderBottom: i===FAQS.length-1 ? `1px solid ${palette.line}` : "none" }}>
                <button onClick={()=>setOpen(open===i?-1:i)} aria-expanded={open===i}
                  style={{ width:"100%", textAlign:"start", display:"flex", alignItems:"center", justifyContent:"space-between", gap:16,
                    background:"transparent", border:0, padding:"22px 0", color: palette.ink, fontSize:17, fontWeight:600 }}>
                  <span className="display" style={{ fontWeight:600 }}>{f.q}</span>
                  <span style={{ flexShrink:0, transform: open===i ? "rotate(45deg)" : "none", transition:"transform .25s" }}>
                    <IconPlus size={20} stroke={palette.accent}/>
                  </span>
                </button>
                <div style={{ maxHeight: open===i ? 320 : 0, overflow:"hidden", transition:"max-height .35s ease" }}>
                  <p style={{ fontSize:15.5, lineHeight:1.7, color: palette.ink2, margin:"0 0 22px", maxWidth:"66ch" }}>{f.a}</p>
                </div>
              </div>
            ))}
          </div>
        </div>
      </div>
      <style>{`
        @media (max-width: 900px){ .faq-grid{ grid-template-columns: 1fr !important; gap: 32px !important; } .faq-grid > div:first-child{ position: static !important; } }
      `}</style>
    </section>
  );
}

/* ─────────── Footer ─────────── */
function Footer({ palette }){
  const f = FOOTER || {};
  return (
    <footer id="contact" data-screen-label="20 Footer" style={{ background: palette.ink, color: palette.bg }}>
      <div className="container" style={{ padding:"68px 24px 24px" }}>
        <div className="foot-grid" style={{ display:"grid", gridTemplateColumns:"1.4fr 1fr 1fr 1fr", gap:36 }}>
          <div>
            <Logo palette={{...palette, ink: palette.bg, accent: palette.gold}}/>
            <p style={{ fontSize:14, lineHeight:1.6, opacity:.75, marginTop:14, maxWidth:"36ch" }}>
              {f.about}
            </p>
            <div style={{ display:"flex", gap:8, marginTop:18 }}>
              <a href={CONTACT.instagram} style={{ width:38, height:38, display:"grid", placeItems:"center", border:`1px solid ${palette.bg}33`, borderRadius:999 }} aria-label="אינסטגרם"><IconInsta size={16}/></a>
              <a href={whatsappLink()} style={{ width:38, height:38, display:"grid", placeItems:"center", border:`1px solid ${palette.bg}33`, borderRadius:999 }} aria-label="וואטסאפ"><IconWa size={16}/></a>
              <a href={`mailto:${CONTACT.email}`} style={{ width:38, height:38, display:"grid", placeItems:"center", border:`1px solid ${palette.bg}33`, borderRadius:999 }} aria-label="אימייל"><IconMail size={16}/></a>
            </div>
          </div>
          <FooterCol title={f.col1Title}>
            {(f.col1Links || []).map((l,i)=><a key={i} href={l.href} style={{ display:"block", padding:"5px 0", fontSize:14, opacity:.78 }}>{l.label}</a>)}
          </FooterCol>
          <FooterCol title={f.col2Title}>
            {(f.col2Links || []).map((l,i)=><a key={i} href={l.href} style={{ display:"block", padding:"5px 0", fontSize:14, opacity:.78 }}>{l.label}</a>)}
          </FooterCol>
          <FooterCol title={f.col3Title}>
            <div style={{ fontSize:14, opacity:.78, lineHeight:1.7 }}>
              {CONTACT.hours}<br/>
              <a href={CONTACT.phoneHref} style={{ color: palette.gold, fontWeight:600 }}>{CONTACT.phone}</a><br/>
              <a href={`mailto:${CONTACT.email}`}>{CONTACT.email}</a><br/>
              <a href={whatsappLink()} style={{ display:"inline-flex", alignItems:"center", gap:6, marginTop:8, color: palette.gold }}><IconWa size={14}/> {f.waLabel}</a>
            </div>
          </FooterCol>
        </div>
        <div style={{ display:"flex", justifyContent:"space-between", flexWrap:"wrap", gap:14, marginTop:48, paddingTop:24, borderTop:`1px solid ${palette.bg}22`, fontSize:12.5, opacity:.65 }}>
          <div>{f.copyright}</div>
          <div style={{ display:"flex", gap:18 }}>
            {(f.legalLinks || []).map((l,i)=><a key={i} href={l.href}>{l.label}</a>)}
          </div>
        </div>
        <div className="built-by" style={{ marginTop:16, textAlign:"center", fontSize:12, opacity:.55 }}>
          <a href="https://webcoredigital.co.il/" target="_blank" rel="noopener noreferrer">
            בניית האתר ועיצובו · <span style={{ fontWeight:600, color: palette.gold }} className="latin">WebCore Digital</span>
          </a>
        </div>
      </div>
      <style>{`
        @media (max-width: 900px){ .foot-grid{ grid-template-columns: 1fr 1fr !important; } }
        @media (max-width: 560px){ .foot-grid{ grid-template-columns: 1fr !important; } }
        .built-by a{ transition: opacity .25s ease; }
        .built-by:hover{ opacity: .95 !important; }
      `}</style>
    </footer>
  );
}
function FooterCol({ title, children }){
  return (
    <div>
      <div style={{ fontSize:11, letterSpacing:".22em", textTransform:"uppercase", opacity:.65, marginBottom:14 }}>{title}</div>
      {children}
    </div>
  );
}

/* ─────────── Floating WhatsApp ─────────── */
function FloatingWa({ palette }){
  return (
    <a href={whatsappLink()} aria-label="וואטסאפ"
      className="float-wa"
      style={{ position:"fixed", insetInlineStart:22, bottom:22, zIndex:38,
        width:54, height:54, borderRadius:999, background: "#25D366", color:"#fff",
        display:"grid", placeItems:"center", boxShadow:"0 16px 36px rgba(0,0,0,.25)",
        transition:"transform .25s ease" }}
      onMouseEnter={e=>e.currentTarget.style.transform="scale(1.08)"}
      onMouseLeave={e=>e.currentTarget.style.transform="none"}
    >
      <IconWa size={26}/>
      <style>{`
        @media (max-width: 719px){
          .float-wa{ bottom: calc(90px + env(safe-area-inset-bottom, 0px)) !important; }
        }
      `}</style>
    </a>
  );
}

/* ─────────── Mobile sticky-buy bar ─────────── */
function MobileBuyBar({ palette }){
  const [show, setShow] = useState(false);
  const bar = CONTENT.mobileBar || {};
  useEffect(() => {
    const onScroll = () => {
      // show after ~600px scroll, hide near footer
      const y = window.scrollY;
      const docH = document.documentElement.scrollHeight;
      const vh = window.innerHeight;
      const nearBottom = (docH - (y + vh)) < 800;
      setShow(y > 600 && !nearBottom);
    };
    onScroll();
    window.addEventListener("scroll", onScroll, { passive:true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);
  if (bar.enabled === false) return null;
  const img = productImageSrc(bar.image);
  return (
    <div className="mobile-buy" style={{
      position:"fixed", insetInlineStart:0, insetInlineEnd:0, bottom:0, zIndex:39,
      transform: show ? "translateY(0)" : "translateY(110%)",
      transition: "transform .35s cubic-bezier(.2,.8,.2,1)",
      background: palette.bg, borderTop:`1px solid ${palette.line}`,
      padding:"10px 14px 14px",
      paddingBottom:"calc(14px + env(safe-area-inset-bottom, 0px))",
      boxShadow:"0 -8px 30px rgba(0,0,0,.08)",
      display:"flex", gap:10, alignItems:"center",
    }}>
      {img && <img src={img} alt="" aria-hidden="true" style={{ width:42, height:60, objectFit:"contain", flexShrink:0 }}/>}
      <div style={{ flex:1, minWidth:0 }}>
        <div className="display" style={{ fontSize:14, fontWeight:700, lineHeight:1.15 }}>{bar.title}</div>
        <div style={{ display:"flex", gap:8, alignItems:"baseline", marginTop:2 }}>
          <span style={{ fontSize:14, fontWeight:700, color: palette.accent }}>{bar.price}</span>
          <span style={{ fontSize:12, color: palette.ink2 }}>{bar.note}</span>
          {bar.discount && <span style={{ fontSize:11, color: palette.gold, fontWeight:600 }}>{bar.discount}</span>}
        </div>
      </div>
      <a href={whatsappLink(bar.waMessage)} style={{ background: palette.accent, color: palette.bg, border:0, padding:"12px 18px", borderRadius:999, fontSize:14, fontWeight:600, display:"inline-flex", gap:6, alignItems:"center", flexShrink:0 }}>
        <IconBag size={16}/> {bar.ctaLabel}
      </a>
      <style>{`
        @media (min-width: 720px){ .mobile-buy{ display: none !important; } }
      `}</style>
    </div>
  );
}

Object.assign(window, {
  whatsappLink, productFilters, formatProductPrice, productDiscountPercent,
  AnnouncementBar, Nav, Hero, TrustStrip, ValueProps, AboutBook,
  Products, ProductCard, WhoItsFor, Testimonials, GroupPurchase, LeadMagnet, FAQ, Footer, FloatingWa, MobileBuyBar,
  Logo, AdlerSeal,
});
