// sections.jsx — page sections for HELVOX. Loaded after demo.jsx.

const { useState: useState_S, useEffect: useEffect_S, useRef: useRef_S, useMemo: useMemo_S } = React;

// —————————————————————————————————————————————
// Nav
// —————————————————————————————————————————————
function Nav({ name }) {
  const [scrolled, setScrolled] = useState_S(false);
  useEffect_S(() => {
    const onS = () => setScrolled(window.scrollY > 40);
    window.addEventListener("scroll", onS);
    return () => window.removeEventListener("scroll", onS);
  }, []);
  return (
    <header style={{
      position: "fixed", top: 0, left: 0, right: 0, zIndex: 100,
      padding: "18px 32px",
      background: scrolled ? "rgba(10,10,10,0.78)" : "transparent",
      backdropFilter: scrolled ? "blur(16px) saturate(140%)" : "none",
      WebkitBackdropFilter: scrolled ? "blur(16px) saturate(140%)" : "none",
      borderBottom: scrolled ? "1px solid #1a1a1a" : "1px solid transparent",
      transition: "background 220ms, border-color 220ms",
    }}>
      <div style={{
        maxWidth: 1400, margin: "0 auto",
        display: "flex", alignItems: "center", justifyContent: "space-between",
      }}>
        <a href="#top" style={{
          color: "#f5f5f1", textDecoration: "none",
          fontFamily: "Geist, sans-serif", fontWeight: 800, fontSize: 18,
          letterSpacing: "-0.02em", display: "flex", alignItems: "center", gap: 10,
        }}>
          <span style={{
            display: "inline-flex", alignItems: "center", justifyContent: "center",
            width: 22, height: 22, background: "#DA291C", borderRadius: 4,
            boxShadow: "0 0 0 4px rgba(218,41,28,0.18)", position: "relative",
          }}>
            <svg width="22" height="22" viewBox="0 0 32 32" style={{ display: "block" }} aria-hidden="true">
              <rect x="13" y="6" width="6" height="20" fill="#ffffff" />
              <rect x="6" y="13" width="20" height="6" fill="#ffffff" />
            </svg>
          </span>
          {name}
        </a>
        <nav style={{
          display: "flex", gap: 28, alignItems: "center",
          fontSize: 13.5, fontFamily: "Geist, sans-serif",
        }}>
          {["Produkt", "Dialekte", "Entwickler", "Preise", "Kunden"].map(l => (
            <a key={l} href={"#" + l.toLowerCase()} style={{
              color: "#8a8a85", textDecoration: "none", fontWeight: 500,
            }} onMouseEnter={e => e.target.style.color = "#f5f5f1"}
               onMouseLeave={e => e.target.style.color = "#8a8a85"}>{l}</a>
          ))}
          <a href="#login" style={{
            color: "#8a8a85", textDecoration: "none", fontSize: 13.5, fontWeight: 500,
          }}>Anmelden</a>
          <a href="#demo" style={{
            padding: "8px 16px", background: "#f5f5f1", color: "#0a0a0a",
            textDecoration: "none", borderRadius: 6, fontWeight: 600, fontSize: 13.5,
          }}>Demo starten →</a>
        </nav>
      </div>
    </header>
  );
}

// —————————————————————————————————————————————
// Live latency counter
// —————————————————————————————————————————————
function LatencyTick() {
  const [n, setN] = useState_S(412);
  useEffect_S(() => {
    const id = setInterval(() => setN(380 + Math.floor(Math.random() * 90)), 600);
    return () => clearInterval(id);
  }, []);
  return <span style={{ fontVariantNumeric: "tabular-nums" }}>{n}</span>;
}

// —————————————————————————————————————————————
// Hero
// —————————————————————————————————————————————
function Hero({ name, tagline }) {
  const [industry, setIndustry] = useState_S("sanitaer");
  return (
    <section style={{
      position: "relative",
      padding: "140px 32px 80px",
      background: "#0a0a0a",
      overflow: "hidden",
    }}>
      {/* Bg grid */}
      <div style={{
        position: "absolute", inset: 0,
        backgroundImage: `linear-gradient(#161616 1px, transparent 1px),
                          linear-gradient(90deg, #161616 1px, transparent 1px)`,
        backgroundSize: "80px 80px",
        maskImage: "radial-gradient(ellipse 80% 60% at 50% 30%, black, transparent 70%)",
        WebkitMaskImage: "radial-gradient(ellipse 80% 60% at 50% 30%, black, transparent 70%)",
        opacity: 0.5, pointerEvents: "none",
      }} />

      <div style={{
        position: "relative", maxWidth: 1400, margin: "0 auto",
      }}>
        {/* Top eyebrow */}
        <div style={{
          display: "flex", alignItems: "center", gap: 12,
          fontFamily: "Geist Mono, monospace", fontSize: 11,
          color: "#8a8a85", letterSpacing: "0.14em", textTransform: "uppercase",
          marginBottom: 36,
        }}>
          <span style={{
            width: 6, height: 6, borderRadius: 999, background: "#d2f24a",
            boxShadow: "0 0 8px #d2f24a",
          }} />
          v3.2 jetzt live · <LatencyTick />ms · Sprich Schweiz.
        </div>

        {/* Headline */}
        <h1 style={{
          fontFamily: "Geist, sans-serif",
          fontWeight: 800,
          fontSize: "clamp(56px, 11vw, 168px)",
          lineHeight: 0.92,
          letterSpacing: "-0.045em",
          color: "#f5f5f1",
          margin: 0, marginBottom: 28,
          maxWidth: "92%",
        }}>
          Schweizer&shy;deutsch.<br />
          <span style={{ color: "#8a8a85" }}>In jedem Anruf.</span>
        </h1>

        {/* Sub */}
        <p style={{
          fontFamily: "Geist, sans-serif",
          fontSize: "clamp(17px, 1.6vw, 22px)",
          lineHeight: 1.5,
          color: "#a8a8a3",
          maxWidth: 620, margin: 0, marginBottom: 36,
          fontWeight: 400,
        }}>
          {name} ist die Voice-AI-Plattform für die Schweiz. Sechs Dialekte, sub-500ms Latenz,
          und Integrationen die wirklich greifen — von Bexio bis Salesforce. Schneller, schärfer,
          und ehrlich gesagt: schöner als alles andere im Markt.
        </p>

        {/* CTAs */}
        <div style={{ display: "flex", gap: 12, flexWrap: "wrap", marginBottom: 64 }}>
          <a href="#demo" style={{
            padding: "16px 28px", background: "#f5f5f1", color: "#0a0a0a",
            textDecoration: "none", borderRadius: 8,
            fontFamily: "Geist, sans-serif", fontWeight: 600, fontSize: 15,
            display: "inline-flex", alignItems: "center", gap: 10,
          }}>
            Demo starten
            <span style={{ fontFamily: "Geist Mono, monospace", fontSize: 12, opacity: 0.6 }}>↵</span>
          </a>
          <a href="#entwickler" style={{
            padding: "16px 28px", background: "transparent", color: "#f5f5f1",
            textDecoration: "none", borderRadius: 8, border: "1px solid #2a2a26",
            fontFamily: "Geist, sans-serif", fontWeight: 500, fontSize: 15,
          }}>
            API-Dokumentation
          </a>
        </div>

        {/* Below: split with stat strip + demo */}
        <div style={{
          display: "grid",
          gridTemplateColumns: "minmax(0, 1fr) minmax(0, 1.4fr)",
          gap: 32,
          alignItems: "start",
        }}>
          {/* Stats column */}
          <div style={{ display: "flex", flexDirection: "column", gap: 0 }}>
            <Stat n="412 ms" label="Median Latenz (gemessen)" sub="P50, Region Basel" />
            <Stat n="6" label="Schweizer Dialekte" sub="BS · ZH · BE · LU · SG · VS" />
            <Stat n="0.09 CHF" label="ab pro Minute" sub="Enterprise · 76% unter Markt" />
            <Stat n="50+" label="Native Integrationen" sub="Bexio · Werkli · SORBA · SF" last />
          </div>

          {/* Demo */}
          <div id="demo">
            <LiveCallDemo industry={industry} onIndustryChange={setIndustry} />
          </div>
        </div>
      </div>
    </section>
  );
}

function Stat({ n, label, sub, last }) {
  return (
    <div style={{
      padding: "20px 0",
      borderBottom: last ? "none" : "1px solid #1a1a1a",
    }}>
      <div style={{
        fontFamily: "Geist, sans-serif", fontWeight: 700,
        fontSize: 38, lineHeight: 1, color: "#f5f5f1",
        letterSpacing: "-0.03em", marginBottom: 6,
      }}>{n}</div>
      <div style={{
        fontFamily: "Geist, sans-serif", fontSize: 14,
        color: "#a8a8a3", marginBottom: 2,
      }}>{label}</div>
      <div style={{
        fontFamily: "Geist Mono, monospace", fontSize: 10.5,
        color: "#666660", letterSpacing: "0.06em", textTransform: "uppercase",
      }}>{sub}</div>
    </div>
  );
}

// —————————————————————————————————————————————
// Logo bar
// —————————————————————————————————————————————
function LogoBar() {
  const logos = window.HELVOX_DATA.logos;
  return (
    <section style={{
      padding: "32px 32px", borderTop: "1px solid #1a1a1a",
      borderBottom: "1px solid #1a1a1a", background: "#0a0a0a",
    }}>
      <div style={{ maxWidth: 1400, margin: "0 auto" }}>
        <div style={{
          fontFamily: "Geist Mono, monospace", fontSize: 10.5,
          color: "#666660", letterSpacing: "0.14em", textTransform: "uppercase",
          marginBottom: 18, textAlign: "center",
        }}>
          Vertrauen über 200 Schweizer Betriebe — Pilotphase Q2/26
        </div>
        <div style={{
          display: "flex", flexWrap: "wrap", gap: 0,
          justifyContent: "space-around", alignItems: "center",
        }}>
          {logos.map((l, i) => (
            <div key={i} style={{
              fontFamily: "Geist, sans-serif", fontWeight: 700, fontSize: 13,
              letterSpacing: "0.16em", color: "#444",
              padding: "8px 14px",
            }}>{l}</div>
          ))}
        </div>
      </div>
    </section>
  );
}

// —————————————————————————————————————————————
// Section header
// —————————————————————————————————————————————
function SectionHead({ idx, kicker, title, sub, align = "left", invert = false }) {
  return (
    <div style={{
      maxWidth: align === "center" ? 920 : 1400,
      margin: align === "center" ? "0 auto" : "0",
      textAlign: align,
      marginBottom: 64,
    }}>
      <div style={{
        fontFamily: "Geist Mono, monospace", fontSize: 11,
        color: invert ? "#666660" : "#8a8a85",
        letterSpacing: "0.14em", textTransform: "uppercase",
        marginBottom: 18, display: "flex",
        alignItems: "center", gap: 12,
        justifyContent: align === "center" ? "center" : "flex-start",
      }}>
        <span style={{ color: "#DA291C" }}>{idx}</span>
        <span style={{ width: 24, height: 1, background: "#2a2a26" }} />
        <span>{kicker}</span>
      </div>
      <h2 style={{
        fontFamily: "Geist, sans-serif",
        fontWeight: 700,
        fontSize: "clamp(36px, 5.4vw, 76px)",
        lineHeight: 0.96,
        letterSpacing: "-0.035em",
        color: invert ? "#0a0a0a" : "#f5f5f1",
        margin: 0, marginBottom: 16,
        maxWidth: 1000,
      }}>{title}</h2>
      {sub && (
        <p style={{
          fontFamily: "Geist, sans-serif", fontSize: 18, lineHeight: 1.5,
          color: invert ? "#444" : "#a8a8a3", maxWidth: 720, margin: 0,
        }}>{sub}</p>
      )}
    </div>
  );
}

// —————————————————————————————————————————————
// Latency section
// —————————————————————————————————————————————
function LatencySection() {
  const data = [
    { name: "HELVOX",                ms: 412,  color: "#DA291C", featured: true },
    { name: "Suisse Voice",          ms: 902,  color: "#8a8a85" },
    { name: "Vapi (US)",             ms: 740,  color: "#8a8a85" },
    { name: "Retell (US)",           ms: 680,  color: "#8a8a85" },
    { name: "ElevenLabs Conversational", ms: 580, color: "#8a8a85" },
  ];
  const max = 1000;
  return (
    <section id="produkt" style={{
      padding: "140px 32px", background: "#0a0a0a",
      borderTop: "1px solid #1a1a1a",
    }}>
      <div style={{ maxWidth: 1400, margin: "0 auto" }}>
        <SectionHead
          idx="01"
          kicker="Realtime"
          title={<>Unter 500 ms.<br /><span style={{ color: "#8a8a85" }}>Spürbar, nicht laggy.</span></>}
          sub="Latenz ist der Unterschied zwischen einem Gespräch, das sich natürlich anfühlt, und einem, das wie ein Telefon-Bot klingt. Wir hosten in Basel, streamen STT/TTS parallel, und sparen jeden Roundtrip ein."
        />

        <div style={{
          display: "grid", gridTemplateColumns: "1fr 1fr", gap: 64, alignItems: "start",
        }}>
          {/* Chart */}
          <div>
            {data.map(d => (
              <div key={d.name} style={{ marginBottom: 18 }}>
                <div style={{
                  display: "flex", justifyContent: "space-between", alignItems: "baseline",
                  marginBottom: 6,
                }}>
                  <div style={{
                    fontFamily: "Geist, sans-serif", fontSize: 14,
                    color: d.featured ? "#f5f5f1" : "#a8a8a3",
                    fontWeight: d.featured ? 600 : 500,
                  }}>{d.name}{d.featured && <span style={{ color: "#DA291C", marginLeft: 8, fontSize: 10, letterSpacing: "0.1em" }}>WIR</span>}</div>
                  <div style={{
                    fontFamily: "Geist Mono, monospace", fontSize: 13,
                    color: d.featured ? "#DA291C" : "#8a8a85",
                  }}>{d.ms} ms</div>
                </div>
                <div style={{
                  height: 10, background: "#161614", borderRadius: 2, overflow: "hidden",
                }}>
                  <div style={{
                    width: `${(d.ms / max) * 100}%`, height: "100%",
                    background: d.color,
                    boxShadow: d.featured ? "0 0 16px rgba(218,41,28,0.5)" : "none",
                  }} />
                </div>
              </div>
            ))}
            <div style={{
              fontFamily: "Geist Mono, monospace", fontSize: 10.5,
              color: "#666660", letterSpacing: "0.06em", marginTop: 14,
            }}>
              Quelle: interne Messung, p50, n=500 Calls, Mai 2026 · Zielregion CH
            </div>
          </div>

          {/* Tech bullets */}
          <div>
            <TechBullet n="01" title="Streaming-STT im Edge"
              text="Audio wird in 80-ms-Chunks an unser CH-Modell gestreamt. Erste Tokens vor dem Satzende." />
            <TechBullet n="02" title="Parallelisierte TTS-Pipeline"
              text="Token-by-token TTS. Antwort startet, sobald der erste Halbsatz feststeht — nicht erst am Punkt." />
            <TechBullet n="03" title="Custom Acoustic Model"
              text="Eigene Modelle pro Schweizer Dialekt. Kein generisches mehrsprachiges Modell, das alles und nichts versteht." />
            <TechBullet n="04" title="Hosting in Basel"
              text="Datacenter Basel-Stadt. Datenresidenz Schweiz. Kein Hop nach Frankfurt oder Dublin." last />
          </div>
        </div>
      </div>
    </section>
  );
}

function TechBullet({ n, title, text, last }) {
  return (
    <div style={{
      padding: "20px 0", borderTop: "1px solid #1a1a1a",
      borderBottom: last ? "1px solid #1a1a1a" : "none",
      display: "grid", gridTemplateColumns: "40px 1fr", gap: 18,
    }}>
      <div style={{
        fontFamily: "Geist Mono, monospace", fontSize: 11,
        color: "#666660", letterSpacing: "0.06em",
      }}>{n}</div>
      <div>
        <div style={{
          fontFamily: "Geist, sans-serif", fontSize: 16, fontWeight: 600,
          color: "#f5f5f1", marginBottom: 6,
        }}>{title}</div>
        <div style={{
          fontFamily: "Geist, sans-serif", fontSize: 14.5, lineHeight: 1.55,
          color: "#a8a8a3",
        }}>{text}</div>
      </div>
    </div>
  );
}

window.Nav = Nav;
window.Hero = Hero;
window.LogoBar = LogoBar;
window.SectionHead = SectionHead;
window.LatencySection = LatencySection;
