// TAHAANN — non-book merchandise cards + category, review and story sections
const { Badge: DsBadge, SectionHeader: DsSectionHeader } = window.TAHANDesignSystem_a07997;

const PWRAP = { maxWidth: "1280px", margin: "0 auto", padding: "0 24px" };
const psvg = (children, size = 24, sw = 1.5) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={sw} strokeLinecap="round" strokeLinejoin="round" aria-hidden>{children}</svg>;

const CAT_ICONS = {
  book: <><path d="M4 5a2 2 0 0 1 2-2h9v16H6a2 2 0 0 0-2 2z" /><path d="M15 3h3a2 2 0 0 1 2 2v14a2 2 0 0 0-2-2h-3" /></>,
  food: <><path d="M4 3v7a3 3 0 0 0 3 3v8M7 3v7M12 21V3c3 0 5 2 5 5s-2 4-4 4" /></>,
  craft: <><path d="M9 3h6l-1 3h-4z" /><path d="M8 6c-2 2-3 4.5-3 7.5C5 18 8 21 12 21s7-3 7-7.5c0-3-1-5.5-3-7.5" /><path d="M6 12h12M9.5 9l2.5 2.5L14.5 9M9.5 16l2.5-2.5 2.5 2.5" /></>,
  tea: <><path d="M4 8h12v5a6 6 0 0 1-12 0z" /><path d="M16 9h2.5a2.5 2.5 0 0 1 0 5H16" /><path d="M4 20h12" /><path d="M10 5c0-2 1.5-3 3.5-3-.2 2-1.5 3-3.5 3z" /><path d="M10 5C10 3 8.5 2 6.5 2c.2 2 1.5 3 3.5 3z" /></>,
  coffee: <><path d="M5 8h11v6a5 5 0 0 1-10 0z" /><path d="M16 9h2a2.5 2.5 0 0 1 0 5h-2" /><path d="M4 20h13" /><path d="M9 5c0-1.2.8-1.6.8-3M12.5 5c0-1.2.8-1.6.8-3" /></>,
  wear: <><path d="M8 3 4 6l2 4-1 11h14l-1-11 2-4-4-3-4 2z" /></>,
  decor: <><path d="M10 3h4l1 5H9z" /><path d="M9 8c-2 2-3 5-3 8a4 4 0 0 0 4 4h4a4 4 0 0 0 4-4c0-3-1-6-3-8" /></>,
  gift: <><rect x="3" y="8" width="18" height="13" rx="1" /><path d="M3 12h18M12 8v13" /><path d="M12 8S10 3 7.5 3a2.5 2.5 0 0 0 0 5zM12 8s2-5 4.5-5a2.5 2.5 0 0 1 0 5z" /></>,
};

const IRibbon = <path d="M20.8 4.6a5.5 5.5 0 0 0-7.8 0L12 5.7l-1-1a5.5 5.5 0 1 0-7.8 7.8L12 21l8.8-8.5a5.5 5.5 0 0 0 0-7.9z" />;
const IBagSm = <><path d="M6 2 3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4z" /><path d="M3 6h18" /><path d="M16 10a4 4 0 0 1-8 0" /></>;

// Corner flags on a product image — one badge per flag the admin saved on the
// product (Bestseller, New arrival, …). No flags, no badge. They wrap short of
// the wishlist button on the right.
function Flag({ item }) {
  const badges = window.tahanFlagBadges(item.flags);
  if (!badges.length) return null;
  return (
    <span style={{ position: "absolute", top: "10px", left: "10px", maxWidth: "calc(100% - 62px)", display: "flex", flexWrap: "wrap", gap: "5px" }}>
      {badges.map((b) => (
        <span key={b.id} style={{ background: b.tone === "new" ? "var(--navy)" : b.tone === "gold" ? "var(--saffron)" : "var(--coral)", color: b.tone === "gold" ? "var(--navy)" : "#FFFFFF", fontFamily: "var(--font-ui)", fontSize: "10.5px", fontWeight: 700, letterSpacing: "0.04em", padding: "5px 10px", borderRadius: "var(--radius-sm)" }}>{b.label}</span>
      ))}
    </span>
  );
}

// Struck original first, then the live price in the sale colour.
function PriceRow({ price, original, size = 15 }) {
  return (
    <div style={{ display: "flex", alignItems: "baseline", gap: "9px", marginTop: "10px", fontFamily: "var(--font-ui)" }}>
      {original && <span style={{ fontSize: size - 3 + "px", color: "var(--text-muted)", textDecoration: "line-through" }}>₹{original.toLocaleString("en-IN")}</span>}
      <span style={{ fontWeight: 700, fontSize: size + "px", color: "var(--price)" }}>₹{price.toLocaleString("en-IN")}</span>
    </div>
  );
}

function ProductCard({ item, saved, onToggleSave, onAdd }) {
  const b = item.badge;
  const tone = b && (b.tone === "sale" ? "sale" : b.tone === "new" ? "new" : "gold");
  return (
    <article className="tahan-prod-card" style={{ background: "var(--surface-card)", border: "1px solid var(--border-hairline)", borderRadius: "var(--radius-md)", boxShadow: "var(--shadow-sm)", overflow: "hidden", display: "flex", flexDirection: "column" }}>
      <a href={`Product?id=${item.id}`} aria-label={item.title} style={{ position: "relative", aspectRatio: "4 / 3", background: "var(--cream-200)", display: "block", textDecoration: "none" }}>
        <image-slot id={`tahan-p-${item.id}`} shape="rect" fit="cover" placeholder={`Drop ${item.title} photo`} src={item.image || ""}></image-slot>
        {b && <span style={{ position: "absolute", top: "12px", left: "12px" }}><DsBadge tone={tone}>{b.label}</DsBadge></span>}
        <button onClick={(e) => { e.preventDefault(); e.stopPropagation(); onToggleSave(); }} aria-label={saved ? "Remove from wishlist" : "Save to wishlist"} style={{ position: "absolute", top: "10px", right: "10px", width: "34px", height: "34px", borderRadius: "999px", cursor: "pointer", border: "1px solid var(--border-hairline)", background: "rgba(255,255,255,0.94)", color: saved ? "var(--burgundy-800)" : "var(--text-muted)", display: "flex", alignItems: "center", justifyContent: "center", boxShadow: "var(--shadow-sm)" }}>
          <svg width="17" height="17" viewBox="0 0 24 24" fill={saved ? "currentColor" : "none"} stroke="currentColor" strokeWidth="1.75" strokeLinecap="round" aria-hidden>{IRibbon}</svg>
        </button>
      </a>
      <div style={{ padding: "18px 18px 20px", display: "flex", flexDirection: "column", flex: 1 }}>
        <a href={`Product?id=${item.id}`} style={{ fontFamily: "var(--font-display)", fontWeight: 700, fontSize: "17px", lineHeight: 1.25, color: "var(--text-heading)", textDecoration: "none", display: "block" }}>{item.title}</a>
        <div style={{ fontFamily: "var(--font-bengali)", fontSize: "14px", color: "var(--brand-secondary)", marginTop: "3px" }}>{item.titleBn}</div>
        <div style={{ fontFamily: "var(--font-ui)", fontSize: "12.5px", color: "var(--text-muted)", marginTop: "8px" }}>{item.tagline}</div>
        <div style={{ marginTop: "auto", paddingTop: "16px", display: "flex", alignItems: "center", justifyContent: "space-between", gap: "12px" }}>
          <div>
            <div style={{ display: "flex", alignItems: "baseline", gap: "8px" }}>
              <span style={{ fontFamily: "var(--font-ui)", fontWeight: 600, fontSize: "16px", color: "var(--text-body)" }}>₹{item.price.toLocaleString("en-IN")}</span>
              {item.original && <span style={{ fontFamily: "var(--font-ui)", fontSize: "12.5px", color: "var(--text-muted)", textDecoration: "line-through" }}>₹{item.original.toLocaleString("en-IN")}</span>}
            </div>
            <div style={{ marginTop: "6px" }}><span style={{ display: "inline-flex", alignItems: "center", gap: "6px", color: "var(--navy)", fontFamily: "var(--font-ui)", fontSize: "12px", fontWeight: 700 }}><span aria-hidden style={{ color: "var(--saffron)", fontSize: "13px", lineHeight: 1 }}>★</span>{item.rating.toFixed(1)} ({item.ratingCount})</span></div>
          </div>
          <button onClick={onAdd} style={{ cursor: "pointer", border: "none", borderRadius: "6px", background: "var(--navy)", color: "#FFFFFF", fontFamily: "var(--font-ui)", fontSize: "12.5px", fontWeight: 700, padding: "10px 18px" }}>Add to cart</button>
        </div>
      </div>
    </article>
  );
}

function ProductGrid({ items, saved, toggleSave, addToCart }) {
  return (
    <div style={{ display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: "28px", marginTop: "24px" }} className="tahan-book-grid">
      {items.map((p) => <ProductCard key={p.id} item={p} saved={!!saved[p.id]} onToggleSave={() => toggleSave(p.id)} onAdd={() => addToCart(p.id)} />)}
    </div>
  );
}

const CAT_GAP = 18;

// Arrow control for the collection carousel.
function CatArrow({ dir, disabled, onClick }) {
  return (
    <button type="button" onClick={onClick} disabled={disabled} aria-label={dir === "prev" ? "Previous collections" : "Next collections"}
      style={{ width: "36px", height: "36px", borderRadius: "999px", border: "1px solid var(--border-strong)", background: "var(--surface-card)", color: "var(--navy)", cursor: disabled ? "default" : "pointer", opacity: disabled ? 0.35 : 1, display: "grid", placeItems: "center", padding: 0, flexShrink: 0, transition: "opacity var(--dur-fast, 140ms) var(--ease-standard, ease)" }}>
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.1" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
        {dir === "prev" ? <path d="M15 19l-7-7 7-7" /> : <path d="M9 5l7 7-7 7" />}
      </svg>
    </button>
  );
}

function ShopByCategory({ data }) {
  const items = (data && data.categories) || [];
  const [perView, setPerView] = React.useState(5);
  const [page, setPage] = React.useState(0);
  const touchX = React.useRef(null);

  // Same column counts the grid used at each breakpoint, so the tiles keep
  // their familiar size — only the overflow behaviour changes.
  React.useEffect(() => {
    const calc = () => {
      const w = window.innerWidth;
      setPerView(w >= 1200 ? 5 : w >= 992 ? 4 : w >= 768 ? 3 : 2);
    };
    calc();
    window.addEventListener("resize", calc);
    return () => window.removeEventListener("resize", calc);
  }, []);

  const pages = Math.max(1, Math.ceil(items.length / perView));
  // Resizing can leave the current page past the end.
  React.useEffect(() => { if (page >= pages) setPage(0); }, [pages, page]);

  const go = (n) => setPage(Math.max(0, Math.min(pages - 1, n)));
  const onTouchStart = (e) => { touchX.current = e.touches[0].clientX; };
  const onTouchEnd = (e) => {
    if (touchX.current == null) return;
    const dx = e.changedTouches[0].clientX - touchX.current;
    touchX.current = null;
    if (pages > 1 && Math.abs(dx) > 40) go(page + (dx < 0 ? 1 : -1));
  };

  return (
    <section style={{ ...PWRAP, paddingTop: "80px" }}>
      <div className="tahan-section-head" style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: "16px" }}>
        <h2 style={{ fontFamily: "var(--font-display)", fontWeight: 800, fontSize: "clamp(1.6rem, 2.6vw, 2.1rem)", textTransform: "uppercase", letterSpacing: "-0.01em", color: "var(--navy)" }}>Explore by Collection</h2>
        {/* marginLeft:auto keeps the arrows hard right on narrow screens, where
            .tahan-section-head wraps them onto their own line. */}
        {pages > 1 && (
          <span style={{ display: "flex", gap: "8px", flexShrink: 0, marginLeft: "auto" }}>
            <CatArrow dir="prev" disabled={page === 0} onClick={() => go(page - 1)} />
            <CatArrow dir="next" disabled={page >= pages - 1} onClick={() => go(page + 1)} />
          </span>
        )}
      </div>
      <div style={{ overflow: "hidden", marginTop: "30px" }} onTouchStart={onTouchStart} onTouchEnd={onTouchEnd}>
        {/* Stepping by (100% + gap) lands each page flush rather than drifting
            by one gap per page. */}
        <div style={{ display: "flex", gap: CAT_GAP + "px", transform: `translateX(calc(${-page} * (100% + ${CAT_GAP}px)))`, transition: "transform 420ms var(--ease-standard, ease)" }}>
        {items.map((c) => (
          <div key={c.id} style={{ flex: `0 0 calc(${100 / perView}% - ${(CAT_GAP * (perView - 1)) / perView}px)`, minWidth: 0 }}>
            {/* A collection tile goes to the Shop filtered by that category — it
                used to swallow the click and scroll to a section on this page. */}
            <a href={window.tahanShopHref(c.id)} className="tahan-card-dark tahan-cat-card" style={{ aspectRatio: "3 / 4", background: c.tint }}>
              <span style={{ position: "absolute", inset: 0 }}>
                <image-slot id={`tahan-cat-${c.id}`} shape="rect" fit="cover" placeholder={`Drop a ${c.label} photo`} src={c.img || ""}></image-slot>
              </span>
              <span className="tahan-card-dark-scrim" style={{ textAlign: "center" }}>
                <span className="tahan-card-dark-title" style={{ fontSize: "14px", fontWeight: 800, letterSpacing: "0.04em", textTransform: "uppercase" }}>{c.label}</span>
              </span>
            </a>
          </div>
        ))}
        </div>
      </div>
    </section>
  );
}

function ShopShelfCard({ item, tint, saved, onToggleSave, onAdd }) {
  const [hover, setHover] = React.useState(false);
  return (
    <article className="tahan-shelf-card" onMouseEnter={() => setHover(true)} onMouseLeave={() => setHover(false)} style={{ background: "transparent", border: "none", borderRadius: 0, boxShadow: "none", transform: "none", display: "flex", flexDirection: "column" }}>
      <a href={`Product?id=${item.id}`} aria-label={item.title} style={{ position: "relative", aspectRatio: "4 / 5", borderRadius: "var(--radius-sm)", overflow: "hidden", background: tint, display: "block", textDecoration: "none" }}>
        <image-slot id={`tahan-p-${item.id}`} shape="rect" fit="cover" placeholder={`Drop ${item.title} photo`} src={item.image || item.img || ""}></image-slot>
        <Flag item={item} />
        <button onClick={(e) => { e.preventDefault(); e.stopPropagation(); onToggleSave(); }} aria-label={saved ? "Remove from wishlist" : "Save to wishlist"} style={{ position: "absolute", top: "10px", right: "10px", width: "32px", height: "32px", borderRadius: "999px", cursor: "pointer", border: "none", background: "rgba(255,255,255,0.94)", color: saved ? "var(--coral)" : "var(--text-muted)", display: "flex", alignItems: "center", justifyContent: "center", boxShadow: "var(--shadow-sm)", opacity: hover || saved ? 1 : 0, transition: "opacity var(--dur-fast) var(--ease-standard)" }}>
          <svg width="15" height="15" viewBox="0 0 24 24" fill={saved ? "currentColor" : "none"} stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" aria-hidden>{IRibbon}</svg>
        </button>
        <button onClick={(e) => { e.preventDefault(); e.stopPropagation(); onAdd(); }} aria-label="Add to cart" style={{ position: "absolute", bottom: "10px", right: "10px", width: "34px", height: "34px", borderRadius: "999px", cursor: "pointer", border: "none", background: "var(--navy)", color: "#FFFFFF", display: "flex", alignItems: "center", justifyContent: "center", boxShadow: "var(--shadow-sm)", opacity: hover ? 1 : 0, transition: "opacity var(--dur-fast) var(--ease-standard)" }}>
          <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" aria-hidden>{IBagSm}</svg>
        </button>
      </a>
      <div style={{ padding: "16px 2px 4px", display: "flex", flexDirection: "column", flex: 1, textAlign: "left" }}>
        {item.tagline && <div style={{ fontFamily: "var(--font-ui)", fontSize: "10.5px", fontWeight: 700, letterSpacing: "0.1em", textTransform: "uppercase", color: "var(--text-muted)" }}>{item.tagline}</div>}
        <a href={`Product?id=${item.id}`} style={{ fontFamily: "var(--font-ui)", fontWeight: 500, fontSize: "14.5px", lineHeight: 1.45, color: "var(--navy)", marginTop: "8px", textDecoration: "none", display: "block" }}>{item.title}</a>
        <PriceRow price={item.price} original={item.original} />
      </div>
    </article>
  );
}

function ShelfSection({ id, title, subtitle, items, tint, rowProps, cols = 4, shopCat }) {
  const [all, setAll] = React.useState(false);
  const shown = all ? items : items.slice(0, cols);
  return (
    <section id={id} style={{ ...PWRAP, paddingTop: "80px" }}>
      <div style={{ display: "flex", alignItems: "flex-end", justifyContent: "space-between", gap: "24px", flexWrap: "wrap" }}>
        <div><h2 style={{ fontFamily: "var(--font-ui)", fontWeight: 800, fontSize: "20px", letterSpacing: "0.08em", textTransform: "uppercase", color: "var(--navy)", margin: 0 }}>{title}</h2>{subtitle && <div style={{ fontFamily: "var(--font-ui)", fontSize: "13px", color: "var(--text-muted)", marginTop: "7px" }}>{subtitle}</div>}</div>
        {shopCat ? (
          <a href={window.tahanShopHref(shopCat)} style={{ fontFamily: "var(--font-ui)", fontWeight: 700, fontSize: "13px", color: "var(--brand-secondary)", textDecoration: "none", whiteSpace: "nowrap" }}>View All →</a>
        ) : (
          <button onClick={() => setAll(!all)} style={{ background: "none", border: "none", padding: 0, cursor: "pointer", fontFamily: "var(--font-ui)", fontWeight: 700, fontSize: "13px", color: "var(--brand-secondary)", whiteSpace: "nowrap" }}>{all ? "Show less ←" : "View All →"}</button>
        )}
      </div>
      <div style={{ display: "grid", gridTemplateColumns: `repeat(${cols}, 1fr)`, gap: "22px", marginTop: "26px" }} className="tahan-book-grid">
        {shown.map((p) => <ShopShelfCard key={p.id} item={p} tint={tint} saved={!!rowProps.saved[p.id]} onToggleSave={() => rowProps.toggleSave(p.id)} onAdd={() => rowProps.addToCart(p.id)} />)}
      </div>
    </section>
  );
}

function WearGridSection({ id, title, items, rowProps, shopCat }) {
  return (
    <section id={id} style={{ ...PWRAP, paddingTop: "80px" }}>
      <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: "24px", flexWrap: "wrap" }}>
        <h2 style={{ fontFamily: "var(--font-ui)", fontWeight: 800, fontSize: "20px", letterSpacing: "0.08em", textTransform: "uppercase", color: "var(--navy)", margin: 0 }}>{title}</h2>
        <a href={window.tahanShopHref(shopCat)} style={{ fontFamily: "var(--font-ui)", fontWeight: 700, fontSize: "13px", color: "var(--brand-secondary)", textDecoration: "none", whiteSpace: "nowrap" }}>View All →</a>
      </div>
      <div style={{ display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: "28px", marginTop: "28px" }} className="tahan-book-grid">
        {items.map((p) => {
          const saved = !!rowProps.saved[p.id];
          return (
            <article key={p.id} style={{ display: "flex", flexDirection: "column" }}>
              <div style={{ position: "relative", aspectRatio: "1 / 1", overflow: "hidden", borderRadius: "6px", background: "var(--surface-card)", border: "1px solid rgba(11,31,58,0.10)" }}>
                <image-slot id={`tahan-p-${p.id}`} shape="rect" fit="cover" placeholder={`Drop ${p.title} photo`} src={p.image || p.img || ""}></image-slot>
                <button onClick={() => rowProps.toggleSave(p.id)} aria-label={saved ? "Remove from wishlist" : "Save to wishlist"} style={{ position: "absolute", top: "8px", right: "8px", width: "30px", height: "30px", borderRadius: "999px", cursor: "pointer", border: "1px solid var(--border-hairline)", background: "rgba(255,255,255,0.92)", color: saved ? "var(--coral)" : "var(--text-muted)", display: "flex", alignItems: "center", justifyContent: "center" }}>
                  <svg width="15" height="15" viewBox="0 0 24 24" fill={saved ? "currentColor" : "none"} stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" aria-hidden>{IRibbon}</svg>
                </button>
              </div>
              <div style={{ fontFamily: "var(--font-ui)", fontWeight: 600, fontSize: "13.5px", color: "var(--navy)", marginTop: "14px" }}>{p.title}</div>
              <div style={{ display: "flex", alignItems: "baseline", gap: "8px", marginTop: "7px" }}>
                <span style={{ fontFamily: "var(--font-ui)", fontWeight: 600, fontSize: "16px", color: "var(--text-body)" }}>₹{p.price.toLocaleString("en-IN")}</span>
                {p.original && <span style={{ fontFamily: "var(--font-ui)", fontSize: "12.5px", color: "var(--text-muted)", textDecoration: "line-through" }}>₹{p.original.toLocaleString("en-IN")}</span>}
              </div>
              <div style={{ marginTop: "9px" }}><span style={{ display: "inline-flex", alignItems: "center", gap: "6px", color: "var(--navy)", fontFamily: "var(--font-ui)", fontSize: "12px", fontWeight: 700 }}><span aria-hidden style={{ color: "var(--saffron)", fontSize: "13px", lineHeight: 1 }}>★</span>{p.rating.toFixed(1)} ({p.ratingCount})</span></div>
              <button onClick={() => rowProps.addToCart(p.id)} style={{ marginTop: "14px", cursor: "pointer", border: "none", borderRadius: "6px", background: "var(--navy)", color: "#FFFFFF", fontFamily: "var(--font-ui)", fontSize: "12.5px", fontWeight: 700, padding: "10px 8px" }}>Add to cart</button>
            </article>
          );
        })}
      </div>
    </section>
  );
}

function ProductSection({ id, eyebrow, title, titleBn, lede, items, rowProps, tint, shopCat }) {
  return (
    <div id={id} style={{ background: tint, marginTop: "80px", padding: "6px 0 76px", "--accent-gold": "#0B1F3A", "--brand-secondary": "#C63C2A", "--text-muted": "#35495C", "--border-hairline": "rgba(11,31,58,0.22)" }}>
    <section style={{ ...PWRAP, paddingTop: "44px" }}>
      <DsSectionHeader eyebrow={eyebrow} title={title} titleBn={titleBn} action="View All" actionHref={window.tahanShopHref(shopCat)} />
      {lede && <p style={{ fontFamily: "var(--font-ui)", fontSize: "16px", lineHeight: 1.65, color: "var(--text-body)", maxWidth: "62ch", marginTop: "16px", marginBottom: 0 }}>{lede}</p>}
      <ProductGrid items={items.slice(0, 4)} {...rowProps} />
    </section>
    </div>
  );
}

function Reviews({ data }) {
  const [per, setPer] = React.useState(3);
  const [page, setPage] = React.useState(0);
  React.useEffect(() => {
    // Bootstrap tiers: 3 up from lg, 2 on md, 1 below md.
    const calc = () => setPer(window.innerWidth < 768 ? 1 : window.innerWidth < 992 ? 2 : 3);
    calc();
    window.addEventListener("resize", calc);
    return () => window.removeEventListener("resize", calc);
  }, []);
  const pages = Math.max(1, Math.ceil(data.reviews.length / per));
  React.useEffect(() => { if (page > pages - 1) setPage(0); }, [pages, page]);
  const go = (d) => setPage((p) => (p + d + pages) % pages);
  const arrow = { width: "40px", height: "40px", borderRadius: "999px", cursor: "pointer", border: "1px solid var(--border-strong)", background: "var(--surface-card)", color: "var(--forest-800)", fontSize: "16px", lineHeight: 1, display: "flex", alignItems: "center", justifyContent: "center" };
  return (
    <section style={{ marginTop: "80px", background: "var(--cream-50)", borderTop: "1px solid var(--border-hairline)", borderBottom: "1px solid var(--border-hairline)", padding: "80px 0" }}>
      <div style={PWRAP}>
        <div style={{ display: "flex", alignItems: "flex-end", justifyContent: "space-between", gap: "24px", flexWrap: "wrap" }}>
          <DsSectionHeader eyebrow="From the people who ordered" title="Reviews" titleBn="পাঠকের মত" />
          <div style={{ display: "flex", gap: "10px", paddingBottom: "6px" }}>
            <button onClick={() => go(-1)} aria-label="Previous reviews" className="tahan-rev-arrow" style={arrow}>←</button>
            <button onClick={() => go(1)} aria-label="Next reviews" className="tahan-rev-arrow" style={arrow}>→</button>
          </div>
        </div>
        <div style={{ overflow: "hidden", marginTop: "24px" }}>
          <div style={{ display: "flex", gap: "24px", transform: `translateX(calc(${-page} * (100% + 24px)))`, transition: "transform 420ms var(--ease-entrance)" }}>
            {data.reviews.map((r) => (
              <figure key={r.id} style={{ margin: 0, flex: `0 0 calc((100% - ${(per - 1) * 24}px) / ${per})`, background: "var(--surface-card)", border: "1px solid var(--border-hairline)", borderRadius: "var(--radius-md)", padding: "20px 20px 22px", display: "flex", flexDirection: "column" }}>
                <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: "12px" }}>
                  <span style={{ display: "inline-flex", alignItems: "center", gap: "7px", background: "var(--navy)", color: "#FFFFFF", fontFamily: "var(--font-ui)", fontWeight: 700, fontSize: "16px", padding: "9px 16px", borderRadius: "var(--radius-pill)" }}>
                    {r.rating.toFixed(1)}<span aria-hidden style={{ color: "var(--saffron)", fontSize: "14px", lineHeight: 1 }}>★</span>
                  </span>
                  {r.bought && <span style={{ fontFamily: "var(--font-ui)", fontSize: "11px", fontWeight: 600, letterSpacing: "0.1em", textTransform: "uppercase", color: "var(--text-muted)", textAlign: "right" }}>{r.bought}</span>}
                </div>
                <blockquote style={{ margin: "18px 0 0", fontFamily: "var(--font-ui)", fontWeight: 500, fontSize: "14.5px", lineHeight: 1.6, color: "var(--text-body)", textWrap: "pretty" }}>{r.text}</blockquote>
                <figcaption style={{ marginTop: "12px", fontFamily: "var(--font-ui)", fontSize: "11.5px", fontWeight: 700, letterSpacing: "0.08em", textTransform: "uppercase", color: "var(--saffron-deep)" }}>
                  — {r.name} <span aria-hidden style={{ opacity: 0.5 }}>|</span> {r.place}
                </figcaption>
                <div style={{ position: "relative", aspectRatio: "4 / 3", borderRadius: "var(--radius-sm)", overflow: "hidden", background: "var(--neutral-100)", marginTop: "16px" }}>
                  <image-slot id={`tahan-review-${r.id}`} shape="rect" fit="cover" placeholder={`Drop ${r.name}'s photo`}></image-slot>
                </div>
              </figure>
            ))}
          </div>
        </div>
        <div style={{ display: "flex", justifyContent: "center", gap: "8px", marginTop: "26px" }}>
          {Array.from({ length: pages }).map((_, i) => (
            <button key={i} onClick={() => setPage(i)} aria-label={`Reviews page ${i + 1}`} style={{ cursor: "pointer", border: "none", padding: 0, width: i === page ? "26px" : "8px", height: "8px", borderRadius: "999px", background: i === page ? "var(--coral)" : "var(--border-strong)", transition: "width var(--dur-med) var(--ease-standard), background var(--dur-med) var(--ease-standard)" }}></button>
          ))}
        </div>
      </div>
    </section>
  );
}

function StoryCards({ data }) {
  return (
    <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: "24px", marginTop: "28px" }} className="tahan-col3">
      {data.stories.map((s) => (
        <a key={s.id} href="#" onClick={(e) => e.preventDefault()} className="tahan-author-card" style={{ display: "block", textDecoration: "none", background: "var(--surface-card)", border: "1px solid rgba(11,31,58,0.12)", boxShadow: "var(--shadow-sm)", borderRadius: "var(--radius-md)", padding: "26px 24px" }}>
          <div style={{ fontFamily: "var(--font-ui)", fontSize: "11.5px", fontWeight: 700, letterSpacing: "0.18em", textTransform: "uppercase", color: "var(--brand-secondary)" }}>{s.kicker}</div>
          <div style={{ fontFamily: "var(--font-display)", fontWeight: 700, fontSize: "20px", lineHeight: 1.3, color: "var(--navy)", marginTop: "12px", textWrap: "pretty" }}>{s.title}</div>
          <div style={{ fontFamily: "var(--font-ui)", fontSize: "12.5px", color: "var(--text-muted)", marginTop: "14px" }}>{s.date} · {s.read}</div>
        </a>
      ))}
    </div>
  );
}

Object.assign(window, { ProductCard, ProductGrid, ShopByCategory, ProductSection, ShelfSection, Reviews, StoryCards });
