// Page sections.

const { useState: useS, useEffect: useE, useRef: useR } = React;

// ========== NAV ==========
function Nav({ t, lang, setLang }) {
  return (
    <header className="nav-blur" style={{
      position: "sticky", top: 0, zIndex: 50,
      width: "100%"
    }}>
      <div className="container" style={{
        display: "flex", alignItems: "center", height: 64, gap: 24
      }}>
        <a href="index.html" style={{ display: "flex", alignItems: "center", gap: 9, textDecoration: "none", color: "var(--fg-ink)" }}>
          <Icon.Logo size={26} />
          <span className="display" style={{ fontSize: 18, letterSpacing: "-0.02em", fontWeight: 700 }}>Sonaro</span>
        </a>

        <nav style={{ display: "flex", alignItems: "center", gap: 26, marginLeft: 32 }} className="nav-links">
          <a href="engagement.html" style={navLinkStyle}>{t.nav.smart}</a>
          <a href="voice.html" style={navLinkStyle}>{t.nav.voice}</a>
          <a href="pricing.html" style={navLinkStyle}>{t.nav.pricing}</a>
          <a href={lang === "it" ? "/privacy/it" : "/privacy"} style={navLinkStyle}>{t.nav.privacy}</a>
        </nav>

        <div style={{ flex: 1 }} />

        {/* language switcher — navigates between root (EN) and /it (IT),
            sets a cookie so the geo-redirect middleware respects the choice. */}
        <button
          onClick={() => {
            if (typeof window === "undefined") return;
            const path = window.location.pathname;
            const isIT = path === "/it" || path.startsWith("/it/");
            const nextLang = isIT ? "en" : "it";
            const target = isIT
              ? (path.replace(/^\/it/, "") || "/")
              : ("/it" + (path === "/" ? "" : path));
            // 1y cookie so the user's choice survives subsequent visits.
            document.cookie = "preferred-lang=" + nextLang + ";path=/;max-age=" + (60 * 60 * 24 * 365) + ";samesite=lax";
            window.location.assign(target);
          }}
          style={{
            display: "inline-flex", alignItems: "center", gap: 6,
            background: "transparent", border: "1px solid var(--border-light)",
            borderRadius: 999, padding: "6px 11px", cursor: "pointer",
            fontFamily: "var(--font-mono)", fontSize: 11, letterSpacing: "0.12em",
            color: "var(--muted-ink)"
          }}
          aria-label="Toggle language"
        >
          <Icon.Globe size={13} />
          {lang.toUpperCase()}
        </button>

        <a href="#book" className="btn btn-primary" style={{ fontSize: 14, padding: "9px 16px" }}>
          {t.nav.cta}
        </a>
      </div>

      <style>{`
        @media (max-width: 880px) {
          .nav-links { display: none !important; }
        }
      `}</style>
    </header>
  );
}
const navLinkStyle = {
  textDecoration: "none",
  color: "var(--fg-ink)",
  fontSize: 14,
  fontWeight: 500,
  letterSpacing: "-0.005em"
};

// ========== HERO (dark) ==========
function Hero({ t }) {
  const cycle = t.hero.h1Cycle || [];
  const [hIdx, setHIdx] = useS(0);

  useE(() => {
    if (cycle.length <= 1) return;
    const id = setInterval(() => setHIdx(i => (i + 1) % cycle.length), 3900);
    return () => clearInterval(id);
  }, [cycle.length]);

  const phrase = cycle[hIdx] || cycle[0] || { pre: "", word: "" };

  return (
    <section data-screen-label="hero" style={{
      position: "relative",
      background: "var(--bg-ink)",
      color: "var(--fg-cream)",
      overflow: "hidden",
      paddingTop: 64, paddingBottom: 48,
      minHeight: 880,
      display: "flex",
      alignItems: "center"
    }}>
      {/* (no asymmetric hero-wide ambient — keep only the card halo so the
          glow stays even on every side of the animation) */}

      <div className="container" style={{
        position: "relative",
        display: "grid",
        gridTemplateColumns: "minmax(0, 1.05fr) minmax(0, 0.95fr)",
        gap: 64,
        alignItems: "center",
        width: "100%"
      }} id="hero-grid">

        {/* LEFT — copy */}
        <div className="rise">
          <div className="eyebrow" style={{ color: "var(--muted-cream)" }}>
            {t.hero.eyebrow}
          </div>

          <h1 className="display-tight" style={{
            fontSize: "clamp(44px, 5.6vw, 84px)",
            margin: "22px 0 26px",
            color: "var(--fg-cream)",
            maxWidth: "13ch",
            lineHeight: 1.02
          }}>
            <RotatingPrefix pre={phrase.pre} hIdx={hIdx} />
            {" "}
            <RotatingWord words={cycle.map(p => p.word)} activeIdx={hIdx} />
          </h1>

          <p style={{
            fontSize: 19,
            lineHeight: 1.5,
            color: "var(--muted-cream)",
            maxWidth: "52ch",
            margin: 0
          }}>
            {t.hero.sub}
          </p>

          <div style={{ display: "flex", gap: 12, marginTop: 32, flexWrap: "wrap" }}>
            <a href="#book" className="btn" style={{
              fontSize: 15, padding: "13px 22px",
              background: "var(--accent-teal)",
              color: "var(--fg-ink)",
              fontWeight: 600
            }}>
              {t.hero.primaryCta} <Icon.Arrow size={14} />
            </a>
          </div>

          {/* trust microstrip */}
          <ul style={{
            display: "flex", flexWrap: "wrap", gap: "10px 18px",
            listStyle: "none", padding: 0, margin: "24px 0 0",
            fontFamily: "var(--font-mono)", fontSize: 11, letterSpacing: "0.08em",
            color: "var(--muted-cream)"
          }}>
            {t.hero.trustStrip.map((item, i) => (
              <li key={i} style={{ display: "inline-flex", alignItems: "center", gap: 8 }}>
                <span style={{ width: 4, height: 4, borderRadius: 999, background: "var(--cat-green)", opacity: 0.85 }} />
                {item}
              </li>
            ))}
          </ul>
        </div>

        {/* RIGHT — agenda card. Glow is now a tight rectangular rim around the
            card (via box-shadow on the card itself + a small radial that hugs
            the card outline) — no more big circular bloom. */}
        <div style={{ position: "relative", width: "100%", maxWidth: 580, marginLeft: "auto" }}>
          {/* soft rectangular rim halo — hugs the card outline */}
          <div aria-hidden="true" className="hero-halo" style={{
            position: "absolute", inset: "-22px",
            background: "rgba(155, 201, 210, 0.40)",
            borderRadius: 36,
            filter: "blur(28px)",
            pointerEvents: "none",
            zIndex: 0
          }} />
          <div
            className="hero-card-float"
            style={{ position: "relative", zIndex: 1, animation: "hero-card-float 7s ease-in-out infinite" }}
          >
            <AgendaAnimation />
          </div>
        </div>
      </div>

      <style>{`
        @media (max-width: 960px) {
          #hero-grid { grid-template-columns: 1fr !important; gap: 60px !important; }
        }
        @keyframes hero-card-float {
          0%, 100% { transform: translateY(0); }
          50%      { transform: translateY(-6px); }
        }
        /* gentle breathing on the rim halo */
        @keyframes hero-halo-breathe {
          0%, 100% { opacity: 0.90; }
          50%      { opacity: 1.00; }
        }
        .hero-halo { animation: hero-halo-breathe 9s ease-in-out infinite; }
      `}</style>
    </section>
  );
}

// Cross-fade prefix (animates only when the prefix value actually changes).
function RotatingPrefix({ pre, hIdx }) {
  const lastPre = useR(pre);
  const [animKey, setAnimKey] = useS(0);
  useE(() => {
    if (lastPre.current !== pre) {
      lastPre.current = pre;
      setAnimKey(k => k + 1);
    }
  }, [pre]);
  return (
    <span style={{
      display: "inline-block",
      overflow: "hidden",
      verticalAlign: "top",
      lineHeight: 1.02,
      paddingBottom: "0.08em"
    }}>
      <span
        key={animKey}
        style={{
          display: "inline-block",
          animation: "hero-prefix-swap 0.75s cubic-bezier(0.22, 1, 0.36, 1) both"
        }}
      >
        {pre}
      </span>
      <style>{`
        @keyframes hero-prefix-swap {
          0%   { opacity: 0; transform: translateY(72%) skewY(2deg); filter: blur(4px); }
          55%  { opacity: 1; transform: translateY(0) skewY(0); filter: blur(0); }
          100% { opacity: 1; transform: translateY(0) skewY(0); filter: blur(0); }
        }
      `}</style>
    </span>
  );
}

// Slot-machine word that scrolls vertically through the cycle.
function RotatingWord({ words, activeIdx }) {
  const lh = 1.2; // wider line-box so glyph descenders (g, y, p, j) don't bleed past the clip
  return (
    <span style={{
      display: "inline-block",
      position: "relative",
      verticalAlign: "top",
      overflow: "hidden",
      height: `${lh}em`,
      lineHeight: lh,
      color: "var(--accent-teal)"
    }}>
      <span style={{
        display: "flex",
        flexDirection: "column",
        transform: `translateY(-${activeIdx * lh}em)`,
        transition: "transform 1.05s cubic-bezier(0.65, 0, 0.35, 1)",
        willChange: "transform"
      }}>
        {words.map((w, i) => (
          <span key={i} style={{
            whiteSpace: "nowrap",
            lineHeight: lh,
            display: "block"
          }}>
            {w}
          </span>
        ))}
      </span>
    </span>
  );
}

// ========== PRODUCT SPLIT (light, two big router cards) ==========
function ProductSplit({ t }) {
  return (
    <section id="products" data-screen-label="split" style={{
      background: "var(--bg-cream)",
      padding: "120px 0 100px"
    }}>
      <div className="container">
        <div style={{ maxWidth: 760, marginBottom: 56 }}>
          <div className="eyebrow" style={{ color: "var(--muted-ink)" }}>{t.split.eyebrow}</div>
          <h2 className="display-tight" style={{ fontSize: "clamp(40px, 5vw, 64px)", margin: "18px 0 18px" }}>
            {t.split.h2Pre} <span style={{ color: "#5B9EAD" }}>{t.split.h2Accent}</span>
          </h2>
          <p style={{ fontSize: 18, color: "var(--muted-ink)", lineHeight: 1.5, margin: 0, maxWidth: "62ch" }}>
            {t.split.sub}
          </p>
        </div>

        <div style={{
          display: "grid",
          gridTemplateColumns: "repeat(2, minmax(0, 1fr))",
          gap: 20
        }} id="split-grid">
          <ProductCard data={t.split.voice} variant="dark"  anchor="voice" kind="voice" href="voice.html" />
          <ProductCard data={t.split.ses}   variant="light" anchor="smart" kind="ses"   href="engagement.html" />
        </div>
      </div>

      <style>{`
        @media (max-width: 940px) {
          #split-grid { grid-template-columns: 1fr !important; }
        }
      `}</style>
    </section>
  );
}

function ProductCard({ data, variant, anchor, kind, href }) {
  const isDark = variant === "dark";
  const fg     = isDark ? "var(--fg-cream)" : "var(--fg-ink)";
  const muted  = isDark ? "var(--muted-cream)" : "var(--muted-ink)";
  const border = isDark ? "var(--border-dark)" : "var(--border-light)";
  const accent = isDark ? "var(--accent-teal)" : "var(--accent-blue)";
  const surface = isDark ? "rgba(255,255,255,0.04)" : "var(--bg-cream)";
  const PreviewVisual = kind === "voice" ? VoiceCardMini : SESCardMini;

  return (
    <div
      id={anchor}
      style={{
        position: "relative",
        background: isDark ? "var(--bg-ink)" : "var(--bg-white)",
        color: fg,
        border: `1px solid ${border}`,
        borderRadius: 24,
        padding: "32px 32px 28px",
        overflow: "hidden",
        display: "flex",
        flexDirection: "column",
        minHeight: 640,
        transition: "transform 0.3s ease, box-shadow 0.3s ease"
      }}
      onMouseEnter={e => { e.currentTarget.style.transform = "translateY(-4px)"; e.currentTarget.style.boxShadow = isDark ? "0 30px 60px -25px rgba(0,0,0,0.5)" : "0 30px 60px -25px rgba(11,15,20,0.18)"; }}
      onMouseLeave={e => { e.currentTarget.style.transform = "translateY(0)"; e.currentTarget.style.boxShadow = "none"; }}
    >
      <div className={isDark ? "glow-blue" : "glow-teal"} />

      {/* header: eyebrow + name */}
      <div style={{ position: "relative", zIndex: 2 }}>
        <div className="eyebrow" style={{ color: muted }}>
          {data.product}
        </div>
        <div className="display-tight" style={{
          fontSize: "clamp(40px, 4.4vw, 56px)",
          margin: "20px 0 16px",
          maxWidth: "11ch"
        }}>
          {data.name}
        </div>
        <p style={{
          fontSize: 16.5,
          lineHeight: 1.45,
          color: muted,
          maxWidth: "36ch",
          margin: 0
        }}>
          {data.kicker}
        </p>
      </div>

      {/* mini preview visual */}
      <div style={{ position: "relative", zIndex: 2, marginTop: 28 }}>
        <PreviewVisual />
      </div>

      {/* problem framing */}
      <div style={{
        position: "relative", zIndex: 2, marginTop: 24,
        padding: "14px 16px",
        background: isDark ? "rgba(220, 38, 38, 0.08)" : "var(--soft-rose-bg)",
        border: isDark ? "1px solid rgba(220, 38, 38, 0.18)" : "1px solid rgba(185, 28, 28, 0.12)",
        borderRadius: 12,
        display: "flex", gap: 11, alignItems: "flex-start"
      }}>
        <span className="mono" style={{
          fontSize: 9.5, letterSpacing: "0.18em", color: isDark ? "#FCA5A5" : "var(--soft-rose-fg)",
          paddingTop: 2, flex: "none"
        }}>
          PROBLEM
        </span>
        <span style={{
          fontSize: 14.5, lineHeight: 1.45,
          color: isDark ? "#FECACA" : "var(--soft-rose-fg)",
          fontWeight: 500
        }}>
          {data.problem}
        </span>
      </div>

      {/* big outcome stat */}
      <div style={{
        position: "relative", zIndex: 2, marginTop: 16,
        padding: "18px 18px",
        background: surface,
        border: `1px solid ${border}`,
        borderRadius: 12,
        display: "flex", gap: 18, alignItems: "center"
      }}>
        <div className="display" style={{
          fontSize: "clamp(38px, 4vw, 52px)",
          letterSpacing: "-0.045em",
          color: accent,
          lineHeight: 1,
          fontWeight: 700,
          flex: "none"
        }}>
          {data.statBig}
        </div>
        <div style={{
          fontSize: 13.5, lineHeight: 1.45, color: muted,
          fontWeight: 500
        }}>
          {data.statSmall}
        </div>
      </div>

      {/* outcome bullets */}
      <ul style={{
        listStyle: "none", margin: "22px 0 0", padding: 0,
        display: "flex", flexDirection: "column", gap: 11,
        position: "relative", zIndex: 2
      }}>
        {data.bullets.map((b, i) => (
          <li key={i} style={{ display: "flex", gap: 12, alignItems: "flex-start", fontSize: 14.5, lineHeight: 1.4 }}>
            <span style={{
              flex: "none", marginTop: 2,
              width: 18, height: 18, borderRadius: 999,
              display: "grid", placeItems: "center",
              background: isDark ? "rgba(16, 185, 129, 0.16)" : "var(--soft-emerald-bg)",
              color: isDark ? "#34d399" : "var(--soft-emerald-fg)"
            }}>
              <Icon.Check size={10} />
            </span>
            <span style={{ color: fg }}>{b}</span>
          </li>
        ))}
      </ul>

      <div style={{ flex: 1 }} />

      {/* CTA */}
      <div style={{ position: "relative", zIndex: 2, marginTop: 28 }}>
        <a
          href={href || `#${anchor}-detail`}
          className={isDark ? "btn btn-primary" : "btn btn-outline-ink"}
          style={{ fontSize: 14.5, padding: "12px 18px" }}
        >
          {data.cta} <Icon.Arrow size={14} />
        </a>
      </div>
    </div>
  );
}

// Mini preview visuals — lightweight, decorative variants of the hero previews
function VoiceCardMini() {
  return (
    <div style={{
      background: "rgba(11,15,20,0.55)",
      border: "1px solid var(--border-dark)",
      borderRadius: 14,
      padding: "14px 16px",
      display: "flex", alignItems: "center", gap: 14
    }}>
      <div style={{
        width: 38, height: 38, borderRadius: 999,
        background: "rgba(96,165,250,0.14)",
        border: "1px solid rgba(96,165,250,0.35)",
        display: "grid", placeItems: "center",
        color: "var(--cat-blue)", flex: "none"
      }}>
        <Icon.Phone size={16} />
      </div>
      <div style={{ flex: 1, minWidth: 0 }}>
        <div style={{ display: "flex", alignItems: "center", gap: 8 }}>
          <span className="pulse-dot" />
          <span className="mono" style={{ fontSize: 10, letterSpacing: "0.16em", color: "var(--muted-cream)" }}>
            ON CALL
          </span>
          <span className="mono" style={{ fontSize: 11, color: "var(--fg-cream)", marginLeft: "auto" }}>
            00:42
          </span>
        </div>
        <div style={{ marginTop: 10 }}>
          <Waveform bars={28} height={26} color="var(--accent-teal)" />
        </div>
      </div>
    </div>
  );
}

function SESCardMini() {
  return (
    <div style={{
      background: "var(--bg-cream)",
      border: "1px solid var(--border-light)",
      borderRadius: 14,
      padding: "14px 14px",
      display: "flex", flexDirection: "column", gap: 10
    }}>
      <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
        <Icon.WhatsApp size={18} />
        <span className="mono" style={{ fontSize: 9.5, letterSpacing: "0.18em", color: "var(--muted-ink)" }}>
          WHATSAPP · STUDIO BIANCHI
        </span>
        <span className="mono" style={{ fontSize: 10.5, color: "var(--muted-ink)", marginLeft: "auto" }}>09:14</span>
      </div>
      <div style={{
        alignSelf: "flex-start", maxWidth: "88%",
        background: "var(--bg-white)",
        border: "1px solid var(--border-light)",
        padding: "8px 12px 9px",
        borderRadius: "12px 12px 12px 4px",
        fontSize: 13, lineHeight: 1.4, color: "var(--fg-ink)"
      }}>
        Slot just opened tomorrow at 10:00. Confirm with one tap?
      </div>
      <div style={{
        alignSelf: "flex-end", maxWidth: "60%",
        background: "#DCF8C6", color: "#1a2a16",
        padding: "6px 11px 7px",
        borderRadius: "12px 12px 4px 12px",
        fontSize: 13, fontWeight: 500
      }}>
        ✓ Confirmed
      </div>
    </div>
  );
}

// ========== WHY SONARO (light, single panel) ==========
function WhySonaro({ t }) {
  const w = t.why;
  return (
    <section data-screen-label="why" style={{ background: "var(--bg-cream)", padding: "120px 0 120px" }}>
      <div className="container">
        <div style={{
          position: "relative",
          background: "var(--bg-white)",
          border: "1px solid var(--border-light)",
          borderRadius: 28,
          padding: "clamp(40px, 5vw, 72px)",
          overflow: "hidden",
          display: "grid",
          gridTemplateColumns: "minmax(0, 1fr) minmax(0, 0.9fr)",
          gap: 56,
          alignItems: "center"
        }} id="why-panel">
          {/* corner glow */}
          <div style={{
            position: "absolute", inset: 0, pointerEvents: "none",
            background: "radial-gradient(45% 50% at 95% 8%, rgba(155,201,210,0.22), transparent 70%)"
          }} />

          {/* left: copy */}
          <div style={{ position: "relative", zIndex: 2 }}>
            <div className="eyebrow" style={{ color: "var(--muted-ink)" }}>{w.eyebrow}</div>
            <h2 className="display-tight" style={{
              fontSize: "clamp(36px, 4.6vw, 56px)",
              margin: "18px 0 22px"
            }}>
              {w.h2Pre} <span style={{ color: "var(--accent-blue)" }}>{w.h2Accent}</span>
            </h2>
            <p style={{
              fontSize: 17,
              lineHeight: 1.55,
              color: "var(--muted-ink)",
              maxWidth: "46ch",
              margin: 0
            }}>
              {w.body}
            </p>

            <div style={{ display: "flex", flexWrap: "wrap", gap: 8, marginTop: 26 }}>
              {w.tags.map((tag, i) => (
                <span key={i} style={{
                  display: "inline-flex", alignItems: "center", gap: 7,
                  padding: "6px 12px",
                  border: "1px solid var(--border-light)",
                  borderRadius: 999,
                  fontSize: 12.5, fontWeight: 500,
                  color: "var(--fg-ink)",
                  background: "var(--bg-cream)"
                }}>
                  <span style={{ width: 5, height: 5, borderRadius: 999, background: "var(--cat-green)" }} />
                  {tag}
                </span>
              ))}
            </div>
          </div>

          {/* right: stylized clinic glyph */}
          <div style={{
            position: "relative", zIndex: 2,
            display: "flex", justifyContent: "center", alignItems: "center",
            minHeight: 280
          }}>
            <WhyVisual />
          </div>
        </div>
      </div>

      <style>{`
        @media (max-width: 900px) {
          #why-panel { grid-template-columns: 1fr !important; }
        }
      `}</style>
    </section>
  );
}

// Stylized clinic visual: three orbiting circles with workflow icons,
// echoing the Sonaro logo's overlapping-disc shape language.
function WhyVisual() {
  return (
    <div style={{
      position: "relative", width: "min(340px, 100%)", aspectRatio: "1 / 1"
    }}>
      {/* concentric rings */}
      <div style={{
        position: "absolute", inset: 0, borderRadius: "50%",
        border: "1px dashed var(--border-light)"
      }} />
      <div style={{
        position: "absolute", inset: "14%", borderRadius: "50%",
        border: "1px solid var(--border-light)",
        background: "linear-gradient(180deg, rgba(155,201,210,0.10) 0%, transparent 100%)"
      }} />

      {/* center clinic mark */}
      <div style={{
        position: "absolute", top: "50%", left: "50%", transform: "translate(-50%, -50%)",
        width: 92, height: 92, borderRadius: 22,
        background: "var(--bg-ink)", color: "var(--accent-teal)",
        display: "grid", placeItems: "center",
        boxShadow: "0 18px 40px -20px rgba(11,15,20,0.5)"
      }}>
        <Icon.Clinic size={42} />
      </div>

      {/* satellite pills around the ring */}
      {[
        { angle: -90, icon: <Icon.Phone size={14} />, label: "Calls",     color: "var(--cat-blue)"   },
        { angle:  -30, icon: <Icon.Chat size={14} />,  label: "WhatsApp",  color: "var(--cat-teal)"   },
        { angle:   30, icon: <Icon.Cal size={14} />,   label: "Agenda",    color: "var(--cat-purple)" },
        { angle:   90, icon: <Icon.Star size={14} />,  label: "Reviews",   color: "var(--cat-green)"  },
        { angle:  150, icon: <Icon.Check size={14} />, label: "Recall",    color: "var(--soft-emerald-fg)" },
        { angle:  210, icon: <Icon.Spark size={14} />, label: "Intake",    color: "var(--accent-blue)" }
      ].map((sat, i) => {
        const r = 50; // radius % from center along the ring
        const x = 50 + r * Math.cos((sat.angle * Math.PI) / 180);
        const y = 50 + r * Math.sin((sat.angle * Math.PI) / 180);
        return (
          <div key={i} style={{
            position: "absolute",
            left: `${x}%`, top: `${y}%`,
            transform: "translate(-50%, -50%)",
            display: "inline-flex", alignItems: "center", gap: 7,
            padding: "5px 10px 5px 6px",
            background: "var(--bg-white)",
            border: "1px solid var(--border-light)",
            borderRadius: 999,
            boxShadow: "0 8px 20px -12px rgba(11,15,20,0.18)",
            whiteSpace: "nowrap",
            fontSize: 11.5, fontWeight: 500
          }}>
            <span style={{
              width: 18, height: 18, borderRadius: 999,
              background: "var(--bg-cream)",
              display: "grid", placeItems: "center",
              color: sat.color
            }}>
              {sat.icon}
            </span>
            <span style={{ color: "var(--fg-ink)" }}>{sat.label}</span>
          </div>
        );
      })}
    </div>
  );
}

// ========== INTEGRATIONS STRIP (dark, continues hero, infinite carousel) ==========
function IntegrationsStrip({ t }) {
  // Repeat the base set enough times to overflow any reasonable viewport,
  // then duplicate the full track so the -50% loop is seamless.
  const baseRepeated = [];
  for (let i = 0; i < 4; i++) baseRepeated.push(...t.hero.integrations);
  const items = [...baseRepeated, ...baseRepeated];
  return (
    <section data-screen-label="integrations" style={{
      background: "var(--bg-ink)",
      color: "var(--fg-cream)",
      padding: "24px 0 56px",
      borderTop: "1px solid var(--border-dark)"
    }}>
      <div className="container" style={{ marginBottom: 18 }}>
        <div className="eyebrow" style={{ color: "var(--muted-cream)" }}>
          {t.hero.integrationsEyebrow}
        </div>
      </div>

      <div style={{
        overflow: "hidden",
        maskImage: "linear-gradient(90deg, transparent 0, #000 6%, #000 94%, transparent 100%)",
        WebkitMaskImage: "linear-gradient(90deg, transparent 0, #000 6%, #000 94%, transparent 100%)"
      }}>
        <div className="logo-track" style={{
          display: "flex", gap: 14, width: "max-content",
          alignItems: "center", padding: "4px 7px"
        }}>
          {items.map((it, idx) => {
            const baseLen = t.hero.integrations.length;
            const isLast = (idx % baseLen) === baseLen - 1;
            // Items can be either a letter mark (legacy + the "+ Your PMS"
            // placeholder at the end) or a logo image path. Logos render
            // larger inside the chip to read at carousel speed.
            const hasLogo = !!it.logo;
            return (
              <div key={idx} style={{
                display: "inline-flex", alignItems: "center", gap: 10,
                padding: "8px 16px 8px 8px",
                border: "1px solid var(--border-dark)",
                borderRadius: 999,
                background: "rgba(255,255,255,0.025)",
                whiteSpace: "nowrap"
              }}>
                <span style={{
                  width: 26, height: 26, borderRadius: 8,
                  display: "grid", placeItems: "center",
                  // Brighter chip backing for image logos so dark or
                  // small marks have enough contrast on the ink section.
                  background: isLast
                    ? "rgba(155,201,210,0.14)"
                    : (hasLogo ? "rgba(245,243,235,0.92)" : "rgba(245,243,235,0.06)"),
                  color: isLast ? "var(--accent-teal)" : "var(--fg-cream)",
                  fontFamily: "var(--font-display)",
                  fontSize: 13, fontWeight: 700, letterSpacing: "-0.02em",
                  overflow: "hidden"
                }}>
                  {hasLogo ? (
                    <img
                      src={it.logo}
                      alt={it.name}
                      loading="lazy"
                      style={{
                        width: 20, height: 20, objectFit: "contain",
                        display: "block"
                      }}
                    />
                  ) : it.mark}
                </span>
                <span style={{
                  fontSize: 14, fontWeight: 500,
                  color: isLast ? "var(--muted-cream)" : "var(--fg-cream)"
                }}>
                  {it.name}
                </span>
              </div>
            );
          })}
        </div>
      </div>
    </section>
  );
}

// ========== DASHBOARD SNAPSHOT (dark) ==========
function DashboardSnapshot({ t }) {
  const d = t.dashboard;
  return (
    <section data-screen-label="dashboard" style={{
      background: "var(--bg-ink)",
      color: "var(--fg-cream)",
      padding: "100px 0 120px",
      borderTop: "1px solid var(--border-dark)",
      borderBottom: "1px solid var(--border-dark)"
    }}>
      <div className="container">
        <div style={{ maxWidth: 720, marginBottom: 44 }}>
          <div className="eyebrow" style={{ color: "var(--muted-cream)" }}>{d.eyebrow}</div>
          <h2 className="display-tight" style={{ fontSize: "clamp(36px, 4.6vw, 56px)", margin: "18px 0 18px", color: "var(--fg-cream)" }}>
            {d.h2Pre} <span style={{ color: "var(--accent-teal)" }}>{d.h2Accent}</span>
          </h2>
          <p style={{ fontSize: 17, color: "var(--muted-cream)", lineHeight: 1.5, margin: 0, maxWidth: "60ch" }}>
            {d.sub}
          </p>
        </div>

        {/* browser-chrome card */}
        <div style={{
          background: "var(--bg-white)",
          borderRadius: 18,
          overflow: "hidden",
          border: "1px solid var(--border-light)",
          boxShadow: "0 40px 80px -40px rgba(11,15,20,0.18), 0 12px 24px -16px rgba(11,15,20,0.08)"
        }}>
          {/* chrome */}
          <div style={{
            display: "flex", alignItems: "center", gap: 14,
            padding: "12px 16px",
            background: "#F2F0E6",
            borderBottom: "1px solid var(--border-light)"
          }}>
            <div style={{ display: "flex", gap: 6 }}>
              <span style={{ width: 11, height: 11, borderRadius: 999, background: "#E07F7F" }} />
              <span style={{ width: 11, height: 11, borderRadius: 999, background: "#E8C26A" }} />
              <span style={{ width: 11, height: 11, borderRadius: 999, background: "#8AC987" }} />
            </div>
            <div style={{
              flex: 1, maxWidth: 420,
              background: "var(--bg-white)",
              border: "1px solid var(--border-light)",
              borderRadius: 8,
              padding: "5px 10px 5px 26px",
              fontFamily: "var(--font-mono)",
              fontSize: 11,
              color: "var(--muted-ink)",
              position: "relative"
            }}>
              <Icon.Search size={11} style={{ position: "absolute", left: 9, top: "50%", transform: "translateY(-50%)" }} />
              {d.browserUrl}
            </div>
            <div style={{
              display: "inline-flex", alignItems: "center", gap: 6,
              fontFamily: "var(--font-mono)", fontSize: 10,
              letterSpacing: "0.16em", color: "var(--cat-green)"
            }}>
              <span style={{ width: 6, height: 6, borderRadius: 999, background: "var(--cat-green)" }} />
              {d.live}
            </div>
          </div>

          {/* body */}
          <div style={{ padding: "28px 28px 24px" }}>
            <div className="mono" style={{ fontSize: 11, letterSpacing: "0.14em", color: "var(--muted-ink)", textTransform: "uppercase" }}>
              {d.header}
            </div>

            <div style={{
              display: "grid",
              gridTemplateColumns: "minmax(0, 1.1fr) minmax(0, 2fr)",
              gap: 22,
              marginTop: 18
            }} id="dash-grid">
              {/* hero stat */}
              <div style={{
                background: "var(--bg-cream)",
                border: "1px solid var(--border-light)",
                borderRadius: 14,
                padding: "22px 22px"
              }}>
                <div style={{ fontSize: 12, color: "var(--muted-ink)" }}>{d.recovered}</div>
                <div className="display" style={{ fontSize: 52, margin: "10px 0 8px", letterSpacing: "-0.04em" }}>
                  € 3.820
                </div>
                <div style={{ display: "inline-flex", alignItems: "center", gap: 6, fontSize: 12.5, color: "var(--cat-green)" }}>
                  <Icon.ArrowUpRight size={12} /> +22% {d.vsLast}
                </div>
                {/* sparkline */}
                <Sparkline />
              </div>

              {/* tile grid */}
              <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 10 }} id="tiles-grid">
                {d.tiles.map((tile, i) => <DashTile key={i} tile={tile} />)}
              </div>
            </div>

            <div style={{
              display: "flex", justifyContent: "space-between", alignItems: "center",
              marginTop: 22, paddingTop: 16, borderTop: "1px solid var(--border-light)",
              fontSize: 12, color: "var(--muted-ink)"
            }}>
              <span>{d.footnote}</span>
              <span className="mono" style={{ display: "inline-flex", alignItems: "center", gap: 6 }}>
                <span style={{ width: 5, height: 5, borderRadius: 999, background: "var(--cat-green)" }} />
                Sync 60s
              </span>
            </div>
          </div>
        </div>
      </div>

      <style>{`
        @media (max-width: 900px) {
          #dash-grid { grid-template-columns: 1fr !important; }
          #tiles-grid { grid-template-columns: repeat(2, 1fr) !important; }
        }
        @media (max-width: 540px) {
          #tiles-grid { grid-template-columns: 1fr !important; }
        }
      `}</style>
    </section>
  );
}

function DashTile({ tile }) {
  const flavors = {
    "cat-blue":    { bg: "#EFF6FF", fg: "#1D4ED8", chip: "#DBEAFE" },
    "cat-teal":    { bg: "#ECFEFA", fg: "#0F766E", chip: "#CCFBF1" },
    "cat-purple":  { bg: "#F5F3FF", fg: "#6D28D9", chip: "#EDE9FE" },
    "cat-green":   { bg: "#ECFDF5", fg: "#047857", chip: "#D1FAE5" },
    "soft-rose":   { bg: "#FDE2E2", fg: "#B91C1C", chip: "#FECACA" },
    "soft-amber":  { bg: "#FCE7C8", fg: "#C2410C", chip: "#FED7AA" }
  };
  const f = flavors[tile.flavor] || flavors["cat-blue"];
  return (
    <div style={{
      background: "var(--bg-white)",
      border: "1px solid var(--border-light)",
      borderRadius: 12,
      padding: "14px 14px 12px",
      display: "flex", flexDirection: "column", gap: 8,
      minHeight: 110
    }}>
      <div style={{
        fontSize: 10.5, fontFamily: "var(--font-mono)", letterSpacing: "0.12em",
        textTransform: "uppercase", color: "var(--muted-ink)"
      }}>
        {tile.label}
      </div>
      <div className="display" style={{ fontSize: 28, letterSpacing: "-0.03em", color: "var(--fg-ink)" }}>
        {tile.value}
      </div>
      <div style={{
        display: "inline-flex", alignSelf: "flex-start", alignItems: "center", gap: 5,
        background: f.bg, color: f.fg,
        fontSize: 11, fontWeight: 500,
        padding: "3px 8px", borderRadius: 999,
        marginTop: "auto"
      }}>
        {tile.delta}
      </div>
    </div>
  );
}

function Sparkline() {
  // simple climbing line
  const pts = [10, 18, 14, 22, 19, 28, 24, 36, 32, 44, 40, 54];
  const w = 220, h = 56;
  const max = Math.max(...pts);
  const d = pts.map((v, i) => {
    const x = (i / (pts.length - 1)) * w;
    const y = h - (v / max) * h * 0.85 - 4;
    return `${i === 0 ? "M" : "L"} ${x.toFixed(1)} ${y.toFixed(1)}`;
  }).join(" ");
  return (
    <svg viewBox={`0 0 ${w} ${h}`} preserveAspectRatio="none" style={{ width: "100%", height: 56, marginTop: 14 }}>
      <defs>
        <linearGradient id="spark-fill" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="rgba(37,99,235,0.25)" />
          <stop offset="100%" stopColor="rgba(37,99,235,0)" />
        </linearGradient>
      </defs>
      <path d={`${d} L ${w} ${h} L 0 ${h} Z`} fill="url(#spark-fill)" />
      <path d={d} stroke="var(--accent-blue)" strokeWidth="1.8" fill="none" strokeLinecap="round" strokeLinejoin="round" />
    </svg>
  );
}

// ========== FAQ ==========
function FAQ({ t }) {
  return (
    <section data-screen-label="faq" style={{ background: "var(--bg-cream)", padding: "20px 0 120px" }}>
      <div className="container" style={{ maxWidth: 960 }}>
        <div style={{ display: "flex", alignItems: "flex-end", gap: 40, marginBottom: 36, flexWrap: "wrap" }}>
          <div style={{ flex: 1, minWidth: 280, maxWidth: 540 }}>
            <div className="eyebrow" style={{ color: "var(--muted-ink)" }}>{t.faq.eyebrow}</div>
            <h2 className="display-tight" style={{ fontSize: "clamp(32px, 4vw, 48px)", margin: "16px 0 0" }}>
              {t.faq.h2}
            </h2>
          </div>
        </div>

        <div>
          {t.faq.items.map((item, i) => (
            <details key={i} className="faq-item" {...(i === 0 ? { open: true } : {})}>
              <summary className="faq-summary">
                <span>{item.q}</span>
                <span className="faq-icon"><Icon.Plus size={14} /></span>
              </summary>
              <div className="faq-body">{item.a}</div>
            </details>
          ))}
        </div>
      </div>
    </section>
  );
}

// ========== FOOTER CTA (dark, single CTA) ==========
function FooterCTA({ t }) {
  return (
    <section id="book" data-screen-label="cta" style={{
      background: "var(--bg-ink)",
      color: "var(--fg-cream)",
      padding: "120px 0",
      position: "relative",
      overflow: "hidden"
    }}>
      <div style={{
        position: "absolute", top: "-30%", left: "50%", transform: "translateX(-50%)",
        width: 900, height: 600,
        background: "radial-gradient(closest-side, rgba(37,99,235,0.20), transparent 70%)",
        pointerEvents: "none"
      }} />

      <div className="container" style={{ position: "relative", maxWidth: 1040 }}>
        <div className="eyebrow" style={{ color: "var(--muted-cream)" }}>{t.footerCta.eyebrow}</div>
        <h2 className="display-tight" style={{
          fontSize: "clamp(40px, 6vw, 78px)",
          margin: "22px 0 22px",
          color: "var(--fg-cream)",
          maxWidth: "18ch"
        }}>
          {t.footerCta.h2Pre} <span style={{ color: "var(--accent-teal)" }}>{t.footerCta.h2Accent}</span>
        </h2>
        <p style={{
          fontSize: 18, color: "var(--muted-cream)",
          lineHeight: 1.5, margin: 0, maxWidth: "62ch"
        }}>
          {t.footerCta.sub}
        </p>

        <div style={{ display: "flex", gap: 12, marginTop: 32, flexWrap: "wrap", alignItems: "center" }}>
          <a href="mailto:demo@sonaro.ai" className="btn btn-primary" style={{ fontSize: 15, padding: "13px 22px" }}>
            {t.footerCta.cta} <Icon.Arrow size={14} />
          </a>
        </div>
      </div>
    </section>
  );
}

// ========== FOOTER ==========
function Footer({ t }) {
  return (
    <footer data-screen-label="footer" style={{ background: "var(--bg-ink)", color: "var(--fg-cream)", padding: "80px 0 36px", borderTop: "1px solid var(--border-dark)" }}>
      <div className="container">
        <div style={{
          display: "grid",
          gridTemplateColumns: "minmax(0, 1.4fr) repeat(4, minmax(0, 1fr))",
          gap: 32
        }} id="footer-grid">
          <div>
            <div style={{ display: "flex", alignItems: "center", gap: 9 }}>
              <Icon.LogoLight size={26} />
              <span className="display" style={{ fontSize: 18, fontWeight: 700 }}>Sonaro</span>
            </div>
            <div style={{ color: "var(--muted-cream)", fontSize: 14, marginTop: 14, maxWidth: "28ch", lineHeight: 1.5 }}>
              {t.footer.tag}
            </div>
          </div>
          {t.footer.cols.map((col, i) => (
            <div key={i}>
              <div className="mono" style={{ fontSize: 10.5, letterSpacing: "0.14em", color: "var(--muted-cream)", textTransform: "uppercase", marginBottom: 14 }}>
                {col.title}
              </div>
              <ul style={{ listStyle: "none", padding: 0, margin: 0, display: "flex", flexDirection: "column", gap: 10 }}>
                {col.links.map((l, j) => (
                  <li key={j}>
                    <a href="#" style={{ fontSize: 13.5, color: "var(--fg-cream)", textDecoration: "none", opacity: 0.85 }}>{l}</a>
                  </li>
                ))}
              </ul>
            </div>
          ))}
        </div>

        <hr className="hairline-dark" style={{ margin: "48px 0 22px" }} />

        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", flexWrap: "wrap", gap: 16 }}>
          <div style={{ fontSize: 12.5, color: "var(--muted-cream)" }}>{t.footer.foot}</div>
          <div style={{ display: "inline-flex", alignItems: "center", gap: 6, fontFamily: "var(--font-mono)", fontSize: 11, letterSpacing: "0.14em", color: "var(--muted-cream)" }}>
            <Icon.Shield size={13} /> GDPR · DATA IN EU
          </div>
        </div>
      </div>

      <style>{`
        @media (max-width: 880px) { #footer-grid { grid-template-columns: 1fr 1fr !important; } }
        @media (max-width: 520px) { #footer-grid { grid-template-columns: 1fr !important; } }
      `}</style>
    </footer>
  );
}

Object.assign(window, { Nav, Hero, IntegrationsStrip, ProductSplit, WhySonaro, DashboardSnapshot, FAQ, FooterCTA, Footer });
