/* =========================================================
   AI Employees Overview — page composition (6 sections + footer)
   The roster page. Near-white canvas, ink panels, one cobalt accent.
   ========================================================= */

/* ---------- 1 · Hero (team lineup) ---------- */
function HeroOv() {
  const ref = useReveal();
  const order = ["summer", "april", "taylor", "avery", "riley", "lily"];
  return (
    <section style={{ position: "relative", padding: "76px 0 72px", background: "var(--bg)", overflow: "hidden" }}>
      <div aria-hidden style={{
        position: "absolute", inset: 0, pointerEvents: "none",
        background: "radial-gradient(circle at 50% 8%, rgba(31,93,255,0.08), transparent 55%)",
      }}></div>
      <div className="page" ref={ref} style={{ position: "relative", textAlign: "center" }}>
        <div style={{ display: "inline-flex", alignItems: "center", gap: 9, marginBottom: 24 }}>
          <span style={{ width: 7, height: 7, borderRadius: 999, background: "var(--cobalt-500)" }}></span>
          <span className="eyebrow">The AI Employees</span>
        </div>
        <h1 className="display" style={{ fontSize: "clamp(44px, 6vw, 88px)", maxWidth: 900, margin: "0 auto" }}>
          Meet the team that never clocks out.
        </h1>
        <p style={{ fontSize: 21, lineHeight: 1.5, color: "var(--body)", margin: "24px auto 36px", maxWidth: 520 }}>
          Six voice AI employees for sales and service — answering calls, working leads, and booking appointments around the clock.
        </p>
        <div style={{ display: "flex", gap: 14, flexWrap: "wrap", alignItems: "center", justifyContent: "center", marginBottom: 56 }}>
          <OvBtn variant="primary" href={DEMO_URL} icon="arrow">Book a Demo</OvBtn>
          <OvBtn variant="secondary" href="#proof" icon="play">Hear It Work</OvBtn>
        </div>

        {/* Six-headshot team lineup */}
        <div style={{
          display: "grid", gridTemplateColumns: "repeat(6, 1fr)", gap: 18,
          maxWidth: 920, margin: "0 auto",
        }}>
          {order.map((id, i) => {
            const a = AGENT_BY[id];
            return (
              <a key={id} href={AGENT_PAGES[id].href} style={{
                display: "flex", flexDirection: "column", alignItems: "center", gap: 12,
                animation: prefersReducedMotion ? "none" : `ovFloat ${3.4 + (i % 3) * 0.5}s ease-in-out infinite ${i * 0.2}s`,
              }}>
                <div style={{
                  width: "100%", aspectRatio: "1 / 1", borderRadius: 20, overflow: "hidden",
                  border: "1px solid var(--line)", boxShadow: "var(--e-2)", background: "var(--bg-alt)",
                }}>
                  <video src={a.video} poster={a.src} autoPlay loop muted playsInline
                    style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }} />
                </div>
                <div style={{ fontSize: 15, fontWeight: 800, color: "var(--ink)", letterSpacing: "-0.01em" }}>{a.name}</div>
              </a>
            );
          })}
        </div>
      </div>
    </section>
  );
}

/* ---------- 2 · The Roster (grouped) ---------- */
function RosterOv() {
  const ref = useReveal();
  const groups = [
    { label: "Sales",      ids: ["summer", "lily"] },
    { label: "Service",    ids: ["april", "taylor", "riley"] },
    { label: "Front desk", ids: ["avery"] },
  ];
  return (
    <section style={{ padding: "104px 0", background: "var(--bg-alt)" }}>
      <div className="page" ref={ref}>
        <p className="eyebrow" style={{ marginBottom: 18 }}>The full lineup</p>
        <h2 className="display" style={{ fontSize: "clamp(34px, 4.2vw, 56px)", maxWidth: 760, marginBottom: 56 }}>
          The right employee for every job.
        </h2>

        <div style={{ display: "flex", flexDirection: "column", gap: 48 }}>
          {groups.map((g) => (
            <div key={g.label}>
              <div style={{ display: "flex", alignItems: "center", gap: 14, marginBottom: 22 }}>
                <span style={{ fontSize: 20, fontWeight: 800, color: "var(--ink)", letterSpacing: "-0.01em" }}>{g.label}</span>
                <span style={{ flex: 1, height: 1, background: "var(--line)" }}></span>
                <span style={{ fontSize: 13, fontWeight: 600, color: "var(--body-dim)" }}>{g.ids.length} {g.ids.length === 1 ? "agent" : "agents"}</span>
              </div>
              <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 20 }}>
                {g.ids.map((id) => <RosterCard key={id} id={id} />)}
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ---------- 3 · What Every Employee Does ---------- */
function EveryOv() {
  const ref = useReveal();
  const items = [
    "Makes or answers real phone calls — voice, not just text",
    "Books into your CRM and service scheduler",
    "Hands off to a live rep the moment a deal needs one",
    "Plugs into your CRM, DMS, phone, and scheduler",
    "Works around the clock — nights, weekends, holidays",
    "TCPA-compliant, discloses AI if asked",
  ];
  return (
    <section style={{ padding: "104px 0", background: "var(--bg)" }}>
      <div className="page" ref={ref}>
        <p className="eyebrow" style={{ marginBottom: 18 }}>Every one of them</p>
        <h2 className="display" style={{ fontSize: "clamp(34px, 4.2vw, 56px)", maxWidth: 720, marginBottom: 48 }}>
          What every employee does.
        </h2>
        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "0 56px" }}>
          {items.map((it, i) => (
            <div key={i} style={{
              display: "flex", alignItems: "center", gap: 16,
              padding: "22px 0", borderTop: "1px solid var(--line)",
              fontSize: 19, fontWeight: 600, color: "var(--ink)",
            }}>
              <span style={{
                width: 30, height: 30, flexShrink: 0, borderRadius: 999, background: "var(--cobalt-50)",
                color: "var(--cobalt-600)", display: "inline-flex", alignItems: "center", justifyContent: "center",
              }}>
                <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round"><path d="M5 12l5 5L20 7"/></svg>
              </span>
              {it}
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ---------- 4 · How They Work Together (lifecycle band) ---------- */
function LifecycleOv() {
  const ref = useReveal();
  // Customer lifecycle order across the dealership
  const stages = [
    { id: "avery",  stage: "Reception" },
    { id: "summer", stage: "Sales" },
    { id: "lily",   stage: "Service-to-sales" },
    { id: "taylor", stage: "Inbound service" },
    { id: "april",  stage: "Service win-back" },
    { id: "riley",  stage: "Recall" },
  ];
  const [active, setActive] = useState(prefersReducedMotion ? -1 : 0);
  useEffect(() => {
    if (prefersReducedMotion) return;
    const t = setInterval(() => setActive((a) => (a + 1) % stages.length), 1400);
    return () => clearInterval(t);
  }, []);

  return (
    <section style={{ padding: "104px 0", background: "var(--ink)", color: "#fff", position: "relative", overflow: "hidden" }}>
      <div aria-hidden style={{
        position: "absolute", inset: 0, pointerEvents: "none",
        background: "radial-gradient(circle at 80% 18%, rgba(31,93,255,0.22), transparent 55%)",
      }}></div>
      <div className="page" ref={ref} style={{ position: "relative" }}>
        <p className="eyebrow on-dark" style={{ marginBottom: 18 }}>Better together</p>
        <h2 className="display" style={{ color: "#fff", fontSize: "clamp(34px, 4.2vw, 56px)", maxWidth: 740, marginBottom: 20 }}>
          Cover the full lifecycle.
        </h2>
        <p style={{ fontSize: 19, lineHeight: 1.55, color: "rgba(255,255,255,0.66)", maxWidth: 620, marginBottom: 48 }}>
          Run one, or stack several. Summer reactivates sales, April recovers service, Taylor catches every inbound call, Avery covers the desk — and 2+ agents automatically unlock a bundle discount.
        </p>

        {/* Lifecycle band */}
        <div style={{ position: "relative" }}>
          {/* routing line behind the row */}
          <svg viewBox="0 0 1136 4" preserveAspectRatio="none" aria-hidden style={{
            position: "absolute", top: 40, left: "8.33%", width: "83.33%", height: 4, pointerEvents: "none",
          }}>
            <path d="M0 2 L1136 2" stroke="rgba(255,255,255,0.16)" strokeWidth="2.5" fill="none" />
            <path d="M0 2 L1136 2" stroke="var(--cobalt-400)" strokeWidth="2.5" strokeDasharray="3 9"
              strokeLinecap="round" fill="none" style={{ animation: prefersReducedMotion ? "none" : "ovDash 1.6s linear infinite" }}/>
          </svg>

          <div style={{ display: "grid", gridTemplateColumns: "repeat(6, 1fr)", gap: 12, position: "relative" }}>
            {stages.map((s, i) => {
              const a = AGENT_BY[s.id];
              const on = i === active;
              return (
                <a key={s.id} href={AGENT_PAGES[s.id].href} style={{ display: "flex", flexDirection: "column", alignItems: "center", gap: 12, textAlign: "center" }}>
                  <div style={{
                    position: "relative", width: 80, height: 80, borderRadius: 999, overflow: "hidden",
                    border: on ? "3px solid var(--cobalt-400)" : "3px solid rgba(255,255,255,0.16)",
                    boxShadow: on ? "0 0 0 6px rgba(31,93,255,0.20)" : "none",
                    transition: "border-color 300ms ease, box-shadow 300ms ease, transform 300ms ease",
                    transform: on ? "translateY(-3px)" : "none",
                    background: "var(--ink-soft)",
                  }}>
                    <video src={a.video} poster={a.src} autoPlay loop muted playsInline
                      style={{ width: "100%", height: "100%", objectFit: "cover", display: "block",
                        filter: on ? "none" : "saturate(0.7) brightness(0.82)", transition: "filter 300ms ease" }} />
                  </div>
                  <div>
                    <div style={{ fontSize: 15, fontWeight: 800, color: "#fff", letterSpacing: "-0.01em" }}>{a.name}</div>
                    <div style={{ fontSize: 12, fontWeight: 600, color: on ? "var(--cobalt-300)" : "rgba(255,255,255,0.5)", marginTop: 3, transition: "color 300ms ease" }}>{s.stage}</div>
                  </div>
                </a>
              );
            })}
          </div>
        </div>

        {/* Bundle note */}
        <div style={{
          marginTop: 48, display: "inline-flex", alignItems: "center", gap: 14,
          padding: "16px 22px", borderRadius: 14,
          background: "rgba(255,255,255,0.06)", border: "1px solid rgba(255,255,255,0.14)",
        }}>
          <span style={{
            width: 34, height: 34, flexShrink: 0, borderRadius: 999, background: "var(--cobalt-500)",
            display: "inline-flex", alignItems: "center", justifyContent: "center",
          }}>
            <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#fff" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round"><path d="M20 12v10H4V12M2 7h20v5H2zM12 22V7M12 7H7.5a2.5 2.5 0 0 1 0-5C11 2 12 7 12 7zM12 7h4.5a2.5 2.5 0 0 0 0-5C13 2 12 7 12 7z"/></svg>
          </span>
          <span style={{ fontSize: 16, fontWeight: 600, color: "rgba(255,255,255,0.9)" }}>
            Run 2+ employees and a <span style={{ color: "var(--cobalt-300)", fontWeight: 800 }}>bundle discount</span> unlocks automatically.
          </span>
        </div>
      </div>
    </section>
  );
}

/* ---------- 5 · Proof (count-up strip) ---------- */
function ProofStatOv({ value, suffix, prefix, label }) {
  const [v, ref] = useCountUp(value, { duration: 1500 });
  return (
    <div ref={ref}>
      <div style={{ fontSize: "clamp(44px, 6vw, 78px)", fontWeight: 900, letterSpacing: "-0.045em", color: "var(--cobalt-500)", lineHeight: 0.95 }}>
        {(prefix || "") + Math.round(v) + (suffix || "")}
      </div>
      <div style={{ fontSize: 15, fontWeight: 600, color: "var(--body)", marginTop: 10 }}>{label}</div>
    </div>
  );
}

function ProofOv() {
  const ref = useReveal();
  return (
    <section id="proof" style={{ padding: "104px 0", background: "var(--bg)" }}>
      <div className="page" ref={ref}>
        <p className="eyebrow" style={{ marginBottom: 40 }}>The proof</p>
        <div style={{
          display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 32,
          paddingBottom: 56, borderBottom: "1px solid var(--line)", marginBottom: 40,
        }}>
          <ProofStatOv value={87} suffix="%" label="set rate once connected" />
          <ProofStatOv value={70} prefix="" suffix="+" label="service reactivations / mo" />
          <ProofStatOv value={60} suffix="%+" label="missed calls now caught" />
          <div>
            <div style={{ fontSize: "clamp(44px, 6vw, 78px)", fontWeight: 900, letterSpacing: "-0.045em", color: "var(--cobalt-500)", lineHeight: 0.95 }}>&lt;1%</div>
            <div style={{ fontSize: 15, fontWeight: 600, color: "var(--body)", marginTop: 10 }}>of customers know it's AI</div>
          </div>
        </div>
        <div style={{ display: "flex", alignItems: "center", gap: 16, flexWrap: "wrap" }}>
          <span style={{ fontSize: 18, color: "var(--body)" }}>Hear the actual calls — judge for yourself.</span>
          <OvBtn variant="primary" href={DEMO_URL} icon="play">Hear It Work</OvBtn>
        </div>
      </div>
    </section>
  );
}

/* ---------- 6 · Closing CTA ---------- */
function ClosingOv() {
  const ref = useReveal();
  const order = ["summer", "april", "taylor", "avery", "riley", "lily"];
  return (
    <section style={{ padding: "112px 0", background: "var(--bg-alt)" }}>
      <div className="page" ref={ref} style={{ textAlign: "center", maxWidth: 820, marginLeft: "auto", marginRight: "auto" }}>
        <div style={{ display: "inline-flex", alignItems: "center", marginBottom: 28 }}>
          {order.map((id, i) => (
            <img key={id} src={AGENT_BY[id].src} alt="" style={{
              width: 44, height: 44, borderRadius: 999, objectFit: "cover",
              border: "2px solid var(--bg-alt)", marginLeft: i === 0 ? 0 : -12, boxShadow: "var(--e-1)",
            }} />
          ))}
        </div>
        <h2 className="display" style={{ fontSize: "clamp(44px, 6.4vw, 88px)", marginBottom: 32 }}>
          Build your AI team.
        </h2>
        <div style={{ display: "inline-flex", gap: 14, flexWrap: "wrap", alignItems: "center", justifyContent: "center" }}>
          <OvBtn variant="primary" href={DEMO_URL} pulse icon="arrow">Book a Demo</OvBtn>
          <OvBtn variant="secondary" href="#proof" icon="play">Hear It Work</OvBtn>
        </div>
      </div>
    </section>
  );
}

/* ---------- Footer ---------- */
function FooterOv() {
  return (
    <footer style={{ background: "var(--ink)", color: "#fff", padding: "56px 0 40px" }}>
      <div className="page" style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-end", gap: 32, flexWrap: "wrap" }}>
        <div>
          <img src="logo-exports/horizontal/horizontal-white.png" alt="CarDealer.ai" style={{ height: 28 }} />
          <div style={{ fontSize: 13, color: "rgba(255,255,255,0.55)", marginTop: 16, maxWidth: 420, lineHeight: 1.6 }}>
            Voice AI employees built for the dealership floor — sales, service, recall, reception, and service-to-sales.
          </div>
        </div>
        <OvBtn variant="dark-ghost" href={DEMO_URL} icon="arrow">Book a Demo</OvBtn>
      </div>
    </footer>
  );
}

/* ---------- App ---------- */
function OverviewApp() {
  return (
    <div>
      <HeroOv />
      <RosterOv />
      <EveryOv />
      <LifecycleOv />
      <ProofOv />
      <ClosingOv />
    </div>
  );
}

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