/* Stratum Leads — Marketing website UI kit (public homepage).
   Recreates stratumleads.com hero → pillars → workflow → trust → plans. */
const M = window.StratumLeadsDesignSystem_6367ed;
const { Button, Card, StatusChip, TierBadge, StrataAmount, Field, Checkbox } = M;
const I = (n, s) => <i data-lucide={n} style={s}></i>;
const refresh = () => requestAnimationFrame(() => window.lucide && window.lucide.createIcons({ attrs: { "stroke-width": 1.9 } }));

/* Responsive viewport hook — inline styles can't use CSS media queries, so we
   read window width and switch layouts in JS. isMobile → single column, isTablet
   → collapse the multi-column grids and the nav links. */
function useViewport() {
  const [w, setW] = React.useState(typeof window !== "undefined" ? window.innerWidth : 1280);
  React.useEffect(() => {
    const onResize = () => setW(window.innerWidth);
    window.addEventListener("resize", onResize);
    return () => window.removeEventListener("resize", onResize);
  }, []);
  return { w, isMobile: w < 760, isTablet: w < 1040 };
}

const CONTACT = {
  address1: "1629 K St NW, Suite 300",
  address2: "Washington, DC 20006",
  phone: "(202) 643-6467",
  phoneHref: "tel:+12026436467",
  email: "support@stratumleads.com",
};

function Nav({ onSignup, onSignin }) {
  const { isMobile, isTablet } = useViewport();
  return (
    <header style={{ position: "sticky", top: 0, zIndex: 30, display: "flex", alignItems: "center", justifyContent: "space-between", gap: isMobile ? 12 : 24, padding: isMobile ? "12px 18px" : "14px 40px", borderBottom: "1px solid var(--border)", background: "color-mix(in srgb, var(--bg) 85%, transparent)", backdropFilter: "blur(12px)" }}>
      <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
        <img src="/app/assets/stratum-mark.svg" alt="" style={{ width: 28, height: 28 }} />
        <span style={{ fontSize: isMobile ? 15 : 16, fontWeight: 800, letterSpacing: "0.5px" }}><span style={{ color: "var(--text)" }}>STRATUM</span> <span style={{ color: "var(--accent)" }}>LEADS</span></span>
      </div>
      {!isTablet &&
      <nav style={{ display: "flex", gap: 28, fontSize: 14, fontWeight: 600, color: "var(--text-muted)" }}>
        {["Product", "Auctions", "Workflow", "Trust", "Plans"].map((x) => <a key={x} href={"#" + x.toLowerCase()} style={{ color: "inherit" }}>{x}</a>)}
      </nav>}
      <div style={{ display: "flex", gap: isMobile ? 8 : 10 }}>
        <Button variant="secondary" icon={isMobile ? undefined : I("log-in")} onClick={() => onSignin()}>Sign In</Button>
        <Button variant="primary" iconRight={isMobile ? undefined : I("arrow-right")} onClick={() => onSignup("Beta")}>Sign Up</Button>
      </div>
    </header>
  );
}

function Hero({ onSignup }) {
  const { isMobile, isTablet } = useViewport();
  return (
    <section style={{ display: "grid", gridTemplateColumns: isTablet ? "1fr" : "1.05fr 1fr", gap: isMobile ? 32 : 48, alignItems: "center", padding: isMobile ? "40px 20px" : "72px 40px", maxWidth: 1280, margin: "0 auto" }}>
      <div>
        <p className="eyebrow">Verified Lead Operating System</p>
        <h1 style={{ margin: "0 0 18px", fontSize: "clamp(32px, 6vw, 60px)", fontWeight: 900, lineHeight: 1.03, letterSpacing: "-0.02em" }}>
          Verified property leads.<br />Won at auction, not guessed.
        </h1>
        <p style={{ margin: "0 0 28px", fontSize: isMobile ? 16 : 18, color: "var(--text-muted)", lineHeight: 1.6, maxWidth: 520 }}>
          Stratum Leads is where real-estate investors and agents find county-verified property leads, win them in live Strata auctions, and close them in a built-in CRM — one governed workspace instead of five scattered tools.
        </p>
        <div style={{ display: "flex", gap: 12, marginBottom: 28, flexWrap: "wrap" }}>
          <Button variant="primary" size="lg" iconRight={I("arrow-right")} onClick={() => onSignup("Beta")}>Join the beta</Button>
          <Button variant="secondary" size="lg" icon={I("circle-play")}>How it works</Button>
        </div>
        <div style={{ display: "flex", gap: isMobile ? 12 : 20, flexWrap: "wrap", fontSize: 13, color: "var(--text-muted)" }}>
          {[["store", "Verified marketplace"], ["gavel", "Live auction desk"], ["briefcase-business", "Won-lead CRM"], ["wallet-cards", "Wallet + account"]].map(([ic, t]) => (
            <span key={t} style={{ display: "inline-flex", alignItems: "center", gap: 6 }}>{I(ic, { width: 15, color: "var(--accent)" })}{t}</span>
          ))}
        </div>
      </div>
      <HeroMock />
    </section>
  );
}

function HeroMock() {
  return (
    <div style={{ borderRadius: "var(--radius-lg)", border: "1px solid var(--border)", background: "var(--surface)", boxShadow: "var(--shadow-lg)", overflow: "hidden" }}>
      <div style={{ display: "flex", alignItems: "center", gap: 8, padding: "12px 14px", borderBottom: "1px solid var(--border)", background: "var(--surface-subtle)" }}>
        <span style={{ width: 10, height: 10, borderRadius: "50%", background: "#e4788a" }} />
        <span style={{ width: 10, height: 10, borderRadius: "50%", background: "#f2c14e" }} />
        <span style={{ width: 10, height: 10, borderRadius: "50%", background: "#57c98a" }} />
        <span style={{ marginLeft: 8, fontSize: 12, color: "var(--text-muted)", fontFamily: "var(--font-mono)" }}>app.stratumleads.com</span>
      </div>
      <div style={{ padding: 16, display: "grid", gap: 12 }}>
        {[["AAA", "1234 E Desert Cove Ave", "Pre-Foreclosure", 230], ["AA", "8521 Meadow Ridge Dr", "Tax Delinquent", 175]].map(([tier, addr, trig, bid]) => (
          <div key={addr} style={{ border: "1px solid var(--border)", borderRadius: "var(--radius-md)", padding: 12, display: "grid", gap: 8 }}>
            <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between" }}>
              <div style={{ display: "flex", alignItems: "center", gap: 8 }}><TierBadge tier={tier} /><span style={{ fontSize: 12, color: "var(--text-muted)" }}>{trig}</span></div>
              <StatusChip status="live">Live</StatusChip>
            </div>
            <strong style={{ fontSize: 15 }}>{addr}</strong>
            <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between" }}>
              <span style={{ fontSize: 12, color: "var(--text-muted)" }}>Current bid</span>
              <div style={{ display: "flex", gap: 8, alignItems: "center" }}><StrataAmount amount={bid - 15} size="sm" /><Button size="sm" variant="primary">Bid {bid}</Button></div>
            </div>
          </div>
        ))}
      </div>
    </div>
  );
}

function Pillars() {
  const items = [
    ["store", "Marketplace", "Scan verified inventory by county, trigger, tier, and quality before any clock starts."],
    ["gavel", "Auction Desk", "Compete with wallet-aware bid controls and clear outbid pressure signals."],
    ["briefcase-business", "Won-Lead CRM", "Work won opportunities with vault access, tasks, notes, and next-best action."],
    ["wallet-cards", "Wallet & Account", "Escrow, credits, billing, and subscription — controlled, audit-ready."],
  ];
  const { isMobile, isTablet } = useViewport();
  return (
    <section id="product" style={{ padding: isMobile ? "24px 20px 40px" : "40px 40px 64px", maxWidth: 1280, margin: "0 auto" }}>
      <p className="eyebrow" style={{ textAlign: "center" }}>Product Pillars</p>
      <h2 style={{ textAlign: "center", margin: "0 0 36px", fontSize: isMobile ? 24 : 32, fontWeight: 800 }}>Not an IDX template. A lead acquisition workspace.</h2>
      <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : isTablet ? "repeat(2,1fr)" : "repeat(4,1fr)", gap: 16 }}>
        {items.map(([ic, t, d]) => (
          <Card key={t} interactive>
            <span style={{ width: 42, height: 42, display: "grid", placeItems: "center", borderRadius: "var(--radius-md)", background: "var(--accent-soft)", color: "var(--accent)", marginBottom: 12 }}>{I(ic, { width: 20 })}</span>
            <h3 style={{ margin: "0 0 6px", fontSize: 16, fontWeight: 800 }}>{t}</h3>
            <p style={{ margin: 0, fontSize: 13, color: "var(--text-muted)", lineHeight: 1.55 }}>{d}</p>
          </Card>
        ))}
      </div>
    </section>
  );
}

function Split({ id, eyebrow, title, body, steps, reverse }) {
  const copy = (
    <div>
      <p className="eyebrow">{eyebrow}</p>
      <h2 style={{ margin: "0 0 14px", fontSize: 28, fontWeight: 800, lineHeight: 1.15 }}>{title}</h2>
      <p style={{ margin: 0, fontSize: 16, color: "var(--text-muted)", lineHeight: 1.6 }}>{body}</p>
    </div>
  );
  const list = (
    <div style={{ display: "grid", gap: 12 }}>
      {steps.map(([ic, t, d]) => (
        <div key={t} style={{ display: "flex", gap: 12, padding: 16, border: "1px solid var(--border)", borderRadius: "var(--radius-md)", background: "var(--surface)" }}>
          <span style={{ width: 38, height: 38, flex: "0 0 auto", display: "grid", placeItems: "center", borderRadius: "var(--radius-sm)", background: "var(--accent-soft)", color: "var(--accent)" }}>{I(ic, { width: 18 })}</span>
          <div><strong style={{ fontSize: 15 }}>{t}</strong><p style={{ margin: "2px 0 0", fontSize: 13, color: "var(--text-muted)", lineHeight: 1.5 }}>{d}</p></div>
        </div>
      ))}
    </div>
  );
  const { isMobile, isTablet } = useViewport();
  return (
    <section id={id} style={{ padding: isMobile ? "24px 20px" : "40px 40px", maxWidth: 1280, margin: "0 auto" }}>
      <div style={{ display: "grid", gridTemplateColumns: isTablet ? "1fr" : "1fr 1fr", gap: isMobile ? 24 : 48, alignItems: "center" }}>
        {reverse && !isTablet ? <React.Fragment>{list}{copy}</React.Fragment> : <React.Fragment>{copy}{list}</React.Fragment>}
      </div>
    </section>
  );
}

function Trust() {
  const items = [
    ["shield-check", "Gated mutations", "Bids, ticket replies, wallet reloads, and account actions run through explicit gates."],
    ["lock-keyhole", "Locked payloads", "Private lead details stay hidden until the right delivery state exists."],
    ["receipt-text", "Audit-ready context", "Wallet, billing, and subscription summaries stay visible without uncontrolled writes."],
  ];
  const { isMobile } = useViewport();
  return (
    <section id="trust" style={{ padding: isMobile ? "36px 20px" : "56px 40px", background: "var(--surface-subtle)", borderTop: "1px solid var(--border)", borderBottom: "1px solid var(--border)" }}>
      <div style={{ maxWidth: 1280, margin: "0 auto" }}>
        <p className="eyebrow" style={{ textAlign: "center" }}>Trust, Security, Governance</p>
        <h2 style={{ textAlign: "center", margin: "0 0 36px", fontSize: isMobile ? 24 : 30, fontWeight: 800 }}>Obvious actions, controlled writes.</h2>
        <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "repeat(3,1fr)", gap: 16 }}>
          {items.map(([ic, t, d]) => (
            <Card key={t}>
              <span style={{ width: 42, height: 42, display: "grid", placeItems: "center", borderRadius: "var(--radius-md)", background: "var(--surface-sunken)", color: "var(--accent)", marginBottom: 12 }}>{I(ic, { width: 20 })}</span>
              <h3 style={{ margin: "0 0 6px", fontSize: 16, fontWeight: 800 }}>{t}</h3>
              <p style={{ margin: 0, fontSize: 13, color: "var(--text-muted)", lineHeight: 1.55 }}>{d}</p>
            </Card>
          ))}
        </div>
      </div>
    </section>
  );
}

function Plans({ onSignup }) {
  const plans = [
    ["Launch", "$49", "Start buying verified leads", ["Marketplace access", "Daily Free Strata", "1 seat"], false],
    ["Scale", "$149", "Higher volume and bid readiness", ["Everything in Launch", "Priority auction alerts", "3 seats", "CRM workspace"], true],
    ["Broker", "Custom", "Team access when seats are enabled", ["Everything in Scale", "Unlimited seats", "Governance controls"], false],
  ];
  const { isMobile } = useViewport();
  return (
    <section id="plans" style={{ padding: isMobile ? "40px 20px" : "64px 40px", maxWidth: 1180, margin: "0 auto" }}>
      <p className="eyebrow" style={{ textAlign: "center" }}>Plans</p>
      <h2 style={{ textAlign: "center", margin: "0 0 36px", fontSize: isMobile ? 24 : 30, fontWeight: 800 }}>Select a plan, then finish setup.</h2>
      <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "repeat(3,1fr)", gap: 16, alignItems: "start" }}>
        {plans.map(([name, price, tag, feats, feat]) => (
          <div key={name} style={{ position: "relative", padding: 24, borderRadius: "var(--radius-lg)", border: feat ? "2px solid var(--accent)" : "1px solid var(--border)", background: "var(--surface)", boxShadow: feat ? "var(--shadow-md)" : "var(--shadow-xs)", display: "grid", gap: 14 }}>
            {feat && <span style={{ position: "absolute", top: 16, right: 16 }}><StatusChip tone="violet">Popular</StatusChip></span>}
            <div><div style={{ fontSize: 13, fontWeight: 700, color: "var(--text-muted)" }}>{name}</div><div style={{ display: "flex", alignItems: "baseline", gap: 4 }}><span style={{ fontSize: 36, fontWeight: 900, fontFamily: "var(--font-mono)" }}>{price}</span>{price !== "Custom" && <span style={{ color: "var(--text-muted)", fontSize: 13 }}>/mo</span>}</div></div>
            <p style={{ margin: 0, fontSize: 14, color: "var(--text-muted)" }}>{tag}</p>
            <ul style={{ listStyle: "none", margin: 0, padding: 0, display: "grid", gap: 8 }}>
              {feats.map((f) => <li key={f} style={{ display: "flex", gap: 8, fontSize: 13 }}>{I("check", { width: 16, color: "var(--success)" })}{f}</li>)}
            </ul>
            <Button variant="secondary" fullWidth disabled onClick={(e) => { if (e && e.preventDefault) e.preventDefault(); }} style={{ opacity: 0.5, cursor: "not-allowed" }}>Coming soon</Button>
          </div>
        ))}
      </div>
      <p style={{ textAlign: "center", marginTop: 22, fontSize: 13, color: "var(--text-muted)", maxWidth: 640, marginLeft: "auto", marginRight: "auto", lineHeight: 1.6 }}>
        <a href="#beta" onClick={(e) => { e.preventDefault(); onSignup("Beta"); }} style={{ color: "var(--accent)", fontWeight: 700, textDecoration: "none" }}>Join the Beta Tester program — $19/mo</a>
        {" — "}early access to every feature as we ship it. In exchange, testers must provide meaningful, ongoing feedback; inactive members are removed from the program.
      </p>
    </section>
  );
}

function Footer() {
  const { isMobile } = useViewport();
  const linkStyle = { color: "inherit", display: "inline-flex", alignItems: "center", gap: 7 };
  return (
    <footer style={{ borderTop: "1px solid var(--border)", background: "var(--surface-subtle)", color: "var(--text-muted)", fontSize: 13 }}>
      <div style={{ maxWidth: 1280, margin: "0 auto", padding: isMobile ? "36px 20px 24px" : "48px 40px 32px", display: "grid", gridTemplateColumns: isMobile ? "1fr" : "1.4fr 1fr 1fr", gap: isMobile ? 28 : 40 }}>
        <div>
          <div style={{ display: "flex", alignItems: "center", gap: 8, marginBottom: 12 }}><img src="/app/assets/stratum-mark.svg" alt="" style={{ width: 24, height: 24 }} /><span style={{ fontSize: 15, fontWeight: 800, letterSpacing: "0.5px" }}><span style={{ color: "var(--text)" }}>STRATUM</span> <span style={{ color: "var(--accent)" }}>LEADS</span></span></div>
          <p style={{ margin: 0, maxWidth: 320, lineHeight: 1.6 }}>The verified lead operating system for real-estate investors and agents — marketplace, auctions, and CRM in one governed workspace.</p>
        </div>
        <div>
          <div style={{ fontWeight: 700, color: "var(--text)", marginBottom: 12 }}>Company</div>
          <div style={{ display: "grid", gap: 10 }}>
            <a href="#product" style={linkStyle}>Product</a>
            <a href="#plans" style={linkStyle}>Plans</a>
            <a href="#trust" style={linkStyle}>Trust &amp; Security</a>
            <a href={"mailto:" + CONTACT.email} style={linkStyle}>Support</a>
          </div>
        </div>
        <div>
          <div style={{ fontWeight: 700, color: "var(--text)", marginBottom: 12 }}>Contact</div>
          <address style={{ display: "grid", gap: 10, fontStyle: "normal" }}>
            <span style={{ display: "flex", alignItems: "flex-start", gap: 8 }}>{I("map-pin", { width: 15, color: "var(--accent)", marginTop: 2 })}<span>{CONTACT.address1}<br />{CONTACT.address2}</span></span>
            <a href={CONTACT.phoneHref} style={linkStyle}>{I("phone", { width: 15, color: "var(--accent)" })}{CONTACT.phone}</a>
            <a href={"mailto:" + CONTACT.email} style={linkStyle}>{I("mail", { width: 15, color: "var(--accent)" })}{CONTACT.email}</a>
          </address>
        </div>
      </div>
      <div style={{ borderTop: "1px solid var(--border)" }}>
        <div style={{ maxWidth: 1280, margin: "0 auto", padding: isMobile ? "16px 20px" : "18px 40px", display: "flex", flexWrap: "wrap", alignItems: "center", justifyContent: "space-between", gap: 12 }}>
          <span>© 2026 Stratum Leads. All rights reserved.</span>
          <div style={{ display: "flex", gap: 20 }}>{["Terms", "Privacy"].map((x) => <a key={x} href="#" style={{ color: "inherit" }}>{x}</a>)}</div>
        </div>
      </div>
    </footer>
  );
}

/* ============================ Sign-up workflow ============================ */
const PLAN_INFO = {
  Launch: { price: "$49/mo", tag: "Start buying verified leads" },
  Scale: { price: "$149/mo", tag: "Higher volume and bid readiness" },
  Broker: { price: "Custom", tag: "Team access when seats are enabled" },
};

function OtpInput({ value, onChange, length = 6, autoFocus }) {
  const refs = React.useRef([]);
  React.useEffect(() => {if (autoFocus && refs.current[0]) refs.current[0].focus();}, [autoFocus]);
  const digits = Array.from({ length }, (_, i) => value[i] || "");
  const setAt = (i, raw) => {
    const d = raw.replace(/\D/g, "");
    if (d.length > 1) {
      const merged = (value.slice(0, i) + d).slice(0, length);
      onChange(merged);
      const f = Math.min(i + d.length, length - 1);
      if (refs.current[f]) refs.current[f].focus();
      return;
    }
    const arr = value.padEnd(length).split("");
    arr[i] = d;
    const joined = arr.join("").replace(/\s/g, "").slice(0, length);
    onChange(joined);
    if (d && i < length - 1 && refs.current[i + 1]) refs.current[i + 1].focus();
  };
  const onKey = (i, e) => {if (e.key === "Backspace" && !value[i] && i > 0 && refs.current[i - 1]) refs.current[i - 1].focus();};
  return (
    <div style={{ display: "flex", gap: 8, justifyContent: "center" }}>
      {digits.map((d, i) =>
      <input key={i} ref={(el) => refs.current[i] = el} value={d} inputMode="numeric" maxLength={i === 0 ? length : 1} aria-label={`Digit ${i + 1}`}
        onChange={(e) => setAt(i, e.target.value)} onKeyDown={(e) => onKey(i, e)}
        style={{ width: 46, height: 54, textAlign: "center", fontSize: 22, fontWeight: 800, fontFamily: "var(--font-mono)", borderRadius: "var(--radius-sm)", border: "1.5px solid " + (d ? "var(--accent)" : "var(--border)"), background: "var(--surface)", color: "var(--text)", outline: "none" }} />
      )}
    </div>);

}

function Resend({ onResend }) {
  const [secs, setSecs] = React.useState(30);
  React.useEffect(() => {if (secs <= 0) return;const t = setTimeout(() => setSecs((s) => s - 1), 1000);return () => clearTimeout(t);}, [secs]);
  if (secs > 0) return <span style={{ fontSize: 13, color: "var(--text-subtle)" }}>Resend code in {secs}s</span>;
  return <button onClick={() => {setSecs(30);onResend && onResend();}} style={{ border: "none", background: "transparent", color: "var(--accent)", fontSize: 13, fontWeight: 700, cursor: "pointer", padding: 0 }}>Resend code</button>;
}

const STEPS = ["Account", "Email", "Phone", "Done"];

function SignupFlow({ plan, onClose, onSwitchToSignin }) {
  const [step, setStep] = React.useState(0);
  const [form, setForm] = React.useState({ name: "", email: "", password: "", agree: false, cc: "+1", phone: "" });
  const [emailCode, setEmailCode] = React.useState("");
  const [phoneCode, setPhoneCode] = React.useState("");
  const [errors, setErrors] = React.useState({});
  const [busy, setBusy] = React.useState(false);
  React.useEffect(() => {refresh();});
  React.useEffect(() => {const onKey = (e) => e.key === "Escape" && onClose();window.addEventListener("keydown", onKey);return () => window.removeEventListener("keydown", onKey);}, []);

  const set = (k) => (e) => setForm((f) => ({ ...f, [k]: e.target.value }));
  const advance = (n) => {setBusy(true);setTimeout(() => {setBusy(false);setStep(n);}, 550);};

  const submitAccount = () => {
    const err = {};
    if (!form.name.trim()) err.name = "Enter your full name.";
    if (!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(form.email)) err.email = "Enter a valid email address.";
    if (form.password.length < 8) err.password = "Use at least 8 characters.";
    if (!form.agree) err.agree = "Please accept the terms to continue.";
    setErrors(err);
    if (Object.keys(err).length === 0) {setEmailCode("");advance(1);}
  };
  const verifyEmail = () => {
    if (emailCode.length < 6) {setErrors({ emailCode: "Enter the full 6-digit code." });return;}
    setErrors({});advance(2);
  };
  const submitPhone = () => {
    const digits = form.phone.replace(/\D/g, "");
    if (digits.length < 10) {setErrors({ phone: "Enter a valid phone number." });return;}
    setErrors({});setPhoneCode("");advance(3);
  };
  const verifyPhone = () => {
    if (phoneCode.length < 6) {setErrors({ phoneCode: "Enter the full 6-digit code." });return;}
    setErrors({});setStep(4);
  };

  const headerIcon = { 0: "user-plus", 1: "mail-check", 2: "smartphone", 3: "message-square-lock", 4: "party-popper" }[step];
  const activeStage = step >= 4 ? 3 : step;

  const overlay = { position: "fixed", inset: 0, zIndex: 100, background: "rgba(16,22,38,0.62)", backdropFilter: "blur(3px)", display: "grid", placeItems: "center", padding: 20, overflowY: "auto" };
  const cardStyle = { width: "min(468px, 100%)", background: "var(--surface)", borderRadius: "var(--radius-lg)", boxShadow: "var(--shadow-xl)", overflow: "hidden", margin: "auto" };
  const bodyPad = { padding: "26px 30px 30px" };
  const backBtn = (to) => <button onClick={() => {setErrors({});setStep(to);}} style={{ display: "inline-flex", alignItems: "center", gap: 5, border: "none", background: "transparent", color: "var(--text-muted)", fontSize: 13, fontWeight: 700, cursor: "pointer", padding: 0 }}>{I("arrow-left", { width: 14 })}Back</button>;

  return (
    <div style={overlay} onClick={onClose}>
      <div style={cardStyle} onClick={(e) => e.stopPropagation()}>
        {/* Header + progress */}
        <div style={{ padding: "20px 30px 0", position: "relative" }}>
          <div style={{ display: "flex", alignItems: "center", gap: 10, marginBottom: 16 }}>
            <span style={{ width: 40, height: 40, display: "grid", placeItems: "center", borderRadius: "var(--radius-md)", background: "var(--accent-soft)", color: "var(--accent)" }}>{I(headerIcon, { width: 20 })}</span>
            <div>
              <div style={{ fontSize: 15, fontWeight: 800 }}>Create your account</div>
              <div style={{ fontSize: 12, color: "var(--text-muted)" }}>{plan ? `${plan} plan · ${PLAN_INFO[plan] ? PLAN_INFO[plan].price : ""}` : "Stratum Leads"}</div>
            </div>
          </div>
          {/* Stepper */}
          <div style={{ display: "flex", alignItems: "center", gap: 6, marginBottom: 4 }}>
            {STEPS.map((s, i) => {
              const done = i < activeStage;
              const on = i === activeStage;
              return (
                <React.Fragment key={s}>
                  <div style={{ display: "flex", alignItems: "center", gap: 7 }}>
                    <span style={{ width: 22, height: 22, flexShrink: 0, display: "grid", placeItems: "center", borderRadius: "50%", fontSize: 11, fontWeight: 800, background: done ? "var(--accent)" : on ? "var(--accent-soft)" : "var(--surface-sunken)", color: done ? "#fff" : on ? "var(--accent)" : "var(--text-subtle)", border: on ? "1.5px solid var(--accent)" : "none" }}>{done ? I("check", { width: 12 }) : i + 1}</span>
                    <span style={{ fontSize: 12, fontWeight: 700, color: on ? "var(--text)" : "var(--text-subtle)" }}>{s}</span>
                  </div>
                  {i < STEPS.length - 1 && <span style={{ flex: 1, height: 2, borderRadius: 2, background: i < activeStage ? "var(--accent)" : "var(--border)" }} />}
                </React.Fragment>);

            })}
          </div>
        </div>

        <div style={{ height: 1, background: "var(--border)", margin: "18px 0 0" }} />

        {/* Step 0 — Account */}
        {step === 0 &&
        <div style={bodyPad}>
            {plan && PLAN_INFO[plan] &&
          <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 10, padding: "12px 14px", borderRadius: "var(--radius-md)", background: "var(--surface-subtle)", border: "1px solid var(--border)", marginBottom: 18 }}>
                <div><strong style={{ fontSize: 14 }}>{plan}</strong><div style={{ fontSize: 12, color: "var(--text-muted)" }}>{PLAN_INFO[plan].tag}</div></div>
                <strong style={{ fontSize: 15, fontFamily: "var(--font-mono)" }}>{PLAN_INFO[plan].price}</strong>
              </div>}
            <div style={{ display: "grid", gap: 14 }}>
              <Field label="Full name" placeholder="Jordan Avery" icon={I("user", { width: 16 })} value={form.name} onChange={set("name")} error={errors.name} />
              <Field label="Work email" type="email" placeholder="you@brokerage.com" icon={I("mail", { width: 16 })} value={form.email} onChange={set("email")} error={errors.email} />
              <Field label="Password" type="password" placeholder="At least 8 characters" icon={I("lock", { width: 16 })} value={form.password} onChange={set("password")} error={errors.password} hint={!errors.password ? "Use 8+ characters with a mix of letters and numbers." : undefined} />
              <div>
                <Checkbox checked={form.agree} onChange={(v) => setForm((f) => ({ ...f, agree: typeof v === "boolean" ? v : !f.agree }))} label="I agree to the Terms of Service and Privacy Policy." />
                {errors.agree && <div style={{ fontSize: 12, color: "var(--danger)", marginTop: 4 }}>{errors.agree}</div>}
              </div>
            </div>
            <Button variant="primary" fullWidth iconRight={I("arrow-right")} onClick={submitAccount} disabled={busy} style={{ marginTop: 20 }}>{busy ? "Sending code…" : "Continue"}</Button>
            <p style={{ margin: "14px 0 0", textAlign: "center", fontSize: 13, color: "var(--text-muted)" }}>Already have an account? <button onClick={onSwitchToSignin} style={{ border: "none", background: "transparent", color: "var(--accent)", fontWeight: 700, fontSize: 13, cursor: "pointer", padding: 0 }}>Sign in</button></p>
          </div>}


        {/* Step 1 — Verify email */}
        {step === 1 &&
        <div style={bodyPad}>
            <p style={{ margin: "0 0 4px", fontSize: 14, color: "var(--text)" }}>We sent a 6-digit code to</p>
            <p style={{ margin: "0 0 20px", fontSize: 14, fontWeight: 700 }}>{form.email} <button onClick={() => setStep(0)} style={{ border: "none", background: "transparent", color: "var(--accent)", fontSize: 13, fontWeight: 700, cursor: "pointer" }}>Edit</button></p>
            <OtpInput value={emailCode} onChange={setEmailCode} autoFocus />
            {errors.emailCode && <p style={{ margin: "10px 0 0", textAlign: "center", fontSize: 12, color: "var(--danger)" }}>{errors.emailCode}</p>}
            <div style={{ display: "flex", alignItems: "center", justifyContent: "center", gap: 6, margin: "16px 0 0", fontSize: 13, color: "var(--text-muted)" }}>Didn't get it? <Resend /></div>
            <div style={{ display: "flex", alignItems: "center", gap: 6, justifyContent: "center", margin: "14px 0 20px", fontSize: 12, color: "var(--text-subtle)" }}>{I("info", { width: 13 })}Demo: enter any 6 digits.</div>
            <Button variant="primary" fullWidth iconRight={I("arrow-right")} onClick={verifyEmail} disabled={busy}>{busy ? "Verifying…" : "Verify email"}</Button>
            <div style={{ marginTop: 16 }}>{backBtn(0)}</div>
          </div>}


        {/* Step 2 — Phone */}
        {step === 2 &&
        <div style={bodyPad}>
            <div style={{ display: "flex", alignItems: "center", gap: 6, fontSize: 13, color: "var(--success)", fontWeight: 700, marginBottom: 16 }}>{I("check-circle-2", { width: 15 })}Email verified</div>
            <p style={{ margin: "0 0 18px", fontSize: 14, color: "var(--text-muted)", lineHeight: 1.55 }}>Add a mobile number for account security. We'll text you a verification code.</p>
            <label style={{ display: "grid", gap: 6 }}>
              <span style={{ fontSize: "var(--text-sm)", fontWeight: "var(--weight-semibold)" }}>Mobile number</span>
              <div style={{ display: "flex", gap: 8 }}>
                <select value={form.cc} onChange={set("cc")} style={{ width: 92, height: "var(--control-h)", padding: "0 8px", borderRadius: "var(--radius-sm)", border: "1px solid var(--border)", background: "var(--surface)", color: "var(--text)", fontSize: 14, cursor: "pointer" }}>
                  {["+1", "+44", "+61", "+91", "+52"].map((c) => <option key={c} value={c}>{c}</option>)}
                </select>
                <div style={{ flex: 1 }}>
                  <Field type="tel" placeholder="(602) 555-0140" icon={I("smartphone", { width: 16 })} value={form.phone} onChange={set("phone")} error={errors.phone} />
                </div>
              </div>
            </label>
            <Button variant="primary" fullWidth iconRight={I("arrow-right")} onClick={submitPhone} disabled={busy} style={{ marginTop: 20 }}>{busy ? "Texting code…" : "Send code"}</Button>
            <div style={{ marginTop: 16 }}>{backBtn(1)}</div>
          </div>}


        {/* Step 3 — Verify phone */}
        {step === 3 &&
        <div style={bodyPad}>
            <p style={{ margin: "0 0 4px", fontSize: 14, color: "var(--text)" }}>We texted a 6-digit code to</p>
            <p style={{ margin: "0 0 20px", fontSize: 14, fontWeight: 700 }}>{form.cc} {form.phone} <button onClick={() => setStep(2)} style={{ border: "none", background: "transparent", color: "var(--accent)", fontSize: 13, fontWeight: 700, cursor: "pointer" }}>Edit</button></p>
            <OtpInput value={phoneCode} onChange={setPhoneCode} autoFocus />
            {errors.phoneCode && <p style={{ margin: "10px 0 0", textAlign: "center", fontSize: 12, color: "var(--danger)" }}>{errors.phoneCode}</p>}
            <div style={{ display: "flex", alignItems: "center", justifyContent: "center", gap: 6, margin: "16px 0 0", fontSize: 13, color: "var(--text-muted)" }}>Didn't get it? <Resend /></div>
            <div style={{ display: "flex", alignItems: "center", gap: 6, justifyContent: "center", margin: "14px 0 20px", fontSize: 12, color: "var(--text-subtle)" }}>{I("info", { width: 13 })}Demo: enter any 6 digits.</div>
            <Button variant="primary" fullWidth iconRight={I("check")} onClick={verifyPhone} disabled={busy}>{busy ? "Verifying…" : "Verify & create account"}</Button>
            <div style={{ marginTop: 16 }}>{backBtn(2)}</div>
          </div>}


        {/* Step 4 — Done */}
        {step === 4 &&
        <div style={{ ...bodyPad, textAlign: "center" }}>
            <div style={{ width: 64, height: 64, margin: "6px auto 18px", display: "grid", placeItems: "center", borderRadius: "50%", background: "var(--success-soft)", color: "var(--success)" }}>{I("check", { width: 30 })}</div>
            <h3 style={{ margin: "0 0 8px", fontSize: 20, fontWeight: 800 }}>You're all set, {form.name.split(" ")[0] || "there"}!</h3>
            <p style={{ margin: "0 0 20px", fontSize: 14, color: "var(--text-muted)", lineHeight: 1.55 }}>Your email and phone are verified{plan ? ` and your ${plan} plan is ready` : ""}. Jump into the marketplace and start finding verified leads.</p>
            <div style={{ display: "grid", gap: 8, textAlign: "left", marginBottom: 22 }}>
              {[["mail-check", `Email verified · ${form.email}`], ["smartphone", `Phone verified · ${form.cc} ${form.phone}`], ["shield-check", "Account secured with 2-step verification"]].map(([ic, t]) =>
            <div key={t} style={{ display: "flex", alignItems: "center", gap: 10, fontSize: 13, padding: "10px 12px", borderRadius: "var(--radius-sm)", background: "var(--surface-subtle)" }}>
                  <span style={{ color: "var(--success)", display: "grid" }}>{I(ic, { width: 16 })}</span>{t}
                </div>
            )}
            </div>
            <a href="/app/Stratum Leads Product App.src?use_live=true" style={{ textDecoration: "none" }}><Button variant="primary" fullWidth iconRight={I("arrow-right")}>Launch Stratum Leads</Button></a>
          </div>}

      </div>
    </div>);

}

function SignInFlow({ onClose, onSwitchToSignup }) {
  const [step, setStep] = React.useState(0);
  const [form, setForm] = React.useState({ email: "", password: "", remember: true });
  const [code, setCode] = React.useState("");
  const [errors, setErrors] = React.useState({});
  const [busy, setBusy] = React.useState(false);
  React.useEffect(() => {refresh();});
  React.useEffect(() => {const onKey = (e) => e.key === "Escape" && onClose();window.addEventListener("keydown", onKey);return () => window.removeEventListener("keydown", onKey);}, []);

  const set = (k) => (e) => setForm((f) => ({ ...f, [k]: e.target.value }));
  const submitCreds = async () => {
    const err = {};
    if (!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(form.email)) err.email = "Enter a valid email address.";
    if (!form.password) err.password = "Enter your password.";
    setErrors(err);
    if (Object.keys(err).length > 0) return;
    if (!window.__sb) {setErrors({ auth: "Supabase client is not configured." });return;}
    setBusy(true);
    const { error } = await window.__sb.auth.signInWithPassword({ email: form.email, password: form.password });
    setBusy(false);
    if (error) {setErrors({ auth: error.message });return;}
    window.localStorage.setItem("STRATUM_USE_LIVE", "true");
    window.location.href = "/app/Stratum Leads Product App.src?use_live=true";
  };
  const verify = () => {
    if (code.length < 6) {setErrors({ code: "Enter the full 6-digit code." });return;}
    setErrors({});setStep(2);
  };

  const headerIcon = { 0: "log-in", 1: "shield-check", 2: "party-popper" }[step];
  const overlay = { position: "fixed", inset: 0, zIndex: 100, background: "rgba(16,22,38,0.62)", backdropFilter: "blur(3px)", display: "grid", placeItems: "center", padding: 20, overflowY: "auto" };
  const cardStyle = { width: "min(440px, 100%)", background: "var(--surface)", borderRadius: "var(--radius-lg)", boxShadow: "var(--shadow-xl)", overflow: "hidden", margin: "auto" };
  const bodyPad = { padding: "26px 30px 30px" };

  return (
    <div style={overlay} onClick={onClose}>
      <div style={cardStyle} onClick={(e) => e.stopPropagation()}>
        <div style={{ padding: "22px 30px 20px", position: "relative", borderBottom: "1px solid var(--border)" }}>
          <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
            <span style={{ width: 40, height: 40, display: "grid", placeItems: "center", borderRadius: "var(--radius-md)", background: "var(--accent-soft)", color: "var(--accent)" }}>{I(headerIcon, { width: 20 })}</span>
            <div>
              <div style={{ fontSize: 15, fontWeight: 800 }}>{step === 2 ? "Signed in" : step === 1 ? "2-step verification" : "Welcome back"}</div>
              <div style={{ fontSize: 12, color: "var(--text-muted)" }}>Sign in to Stratum Leads</div>
            </div>
          </div>
        </div>

        {/* Step 0 — Credentials */}
        {step === 0 &&
        <div style={bodyPad}>
            <div style={{ display: "grid", gap: 14 }}>
              <Field label="Email" type="email" placeholder="you@brokerage.com" icon={I("mail", { width: 16 })} value={form.email} onChange={set("email")} error={errors.email} />
              <div>
                <Field label="Password" type="password" placeholder="Your password" icon={I("lock", { width: 16 })} value={form.password} onChange={set("password")} error={errors.password} />
                <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginTop: 10 }}>
                  <Checkbox checked={form.remember} onChange={(v) => setForm((f) => ({ ...f, remember: typeof v === "boolean" ? v : !f.remember }))} label="Remember me" />
                  <a href="#" style={{ fontSize: 13, fontWeight: 700, color: "var(--accent)" }}>Forgot password?</a>
                </div>
              </div>
            </div>
            {errors.auth && <p role="alert" style={{ margin: "12px 0 0", padding: "10px 12px", borderRadius: "var(--radius-sm)", background: "#fee2e2", color: "#991b1b", fontSize: 12.5, fontWeight: 700 }}>{errors.auth}</p>}
            <Button variant="primary" fullWidth iconRight={I("arrow-right")} onClick={submitCreds} disabled={busy} style={{ marginTop: 20 }}>{busy ? "Signing in…" : "Sign in"}</Button>
            <div style={{ display: "flex", alignItems: "center", gap: 10, margin: "18px 0" }}>
              <span style={{ flex: 1, height: 1, background: "var(--border)" }} /><span style={{ fontSize: 12, color: "var(--text-subtle)" }}>OR</span><span style={{ flex: 1, height: 1, background: "var(--border)" }} />
            </div>
            <div style={{ display: "grid", gap: 8 }}>
              <Button variant="secondary" fullWidth icon={I("chrome")}>Continue with Google</Button>
              <Button variant="secondary" fullWidth icon={I("building-2")}>Continue with Microsoft</Button>
            </div>
            <p style={{ margin: "16px 0 0", textAlign: "center", fontSize: 13, color: "var(--text-muted)" }}>New to Stratum Leads? <button onClick={onSwitchToSignup} style={{ border: "none", background: "transparent", color: "var(--accent)", fontWeight: 700, fontSize: 13, cursor: "pointer", padding: 0 }}>Create account</button></p>
          </div>}


        {/* Step 1 — 2FA */}
        {step === 1 &&
        <div style={bodyPad}>
            <p style={{ margin: "0 0 4px", fontSize: 14, color: "var(--text)" }}>Enter the 6-digit code we sent to your registered device to finish signing in.</p>
            <p style={{ margin: "0 0 20px", fontSize: 13, color: "var(--text-muted)" }}>Protecting {form.email}</p>
            <OtpInput value={code} onChange={setCode} autoFocus />
            {errors.code && <p style={{ margin: "10px 0 0", textAlign: "center", fontSize: 12, color: "var(--danger)" }}>{errors.code}</p>}
            <div style={{ display: "flex", alignItems: "center", justifyContent: "center", gap: 6, margin: "16px 0 0", fontSize: 13, color: "var(--text-muted)" }}>Didn't get it? <Resend /></div>
            <div style={{ display: "flex", alignItems: "center", gap: 6, justifyContent: "center", margin: "14px 0 20px", fontSize: 12, color: "var(--text-subtle)" }}>{I("info", { width: 13 })}Demo: enter any 6 digits.</div>
            <Button variant="primary" fullWidth iconRight={I("check")} onClick={verify} disabled={busy}>{busy ? "Verifying…" : "Verify & sign in"}</Button>
            <div style={{ marginTop: 16 }}><button onClick={() => {setErrors({});setStep(0);}} style={{ display: "inline-flex", alignItems: "center", gap: 5, border: "none", background: "transparent", color: "var(--text-muted)", fontSize: 13, fontWeight: 700, cursor: "pointer", padding: 0 }}>{I("arrow-left", { width: 14 })}Back</button></div>
          </div>}


        {/* Step 2 — Done */}
        {step === 2 &&
        <div style={{ ...bodyPad, textAlign: "center" }}>
            <div style={{ width: 64, height: 64, margin: "6px auto 18px", display: "grid", placeItems: "center", borderRadius: "50%", background: "var(--success-soft)", color: "var(--success)" }}>{I("check", { width: 30 })}</div>
            <h3 style={{ margin: "0 0 8px", fontSize: 20, fontWeight: 800 }}>Welcome back!</h3>
            <p style={{ margin: "0 0 22px", fontSize: 14, color: "var(--text-muted)", lineHeight: 1.55 }}>You're verified and signed in. Pick up where you left off in your workspace.</p>
            <a href="/app/Stratum Leads Product App.src?use_live=true" style={{ textDecoration: "none" }}><Button variant="primary" fullWidth iconRight={I("arrow-right")}>Launch Stratum Leads</Button></a>
          </div>}

      </div>
    </div>);

}

function Site() {
  React.useEffect(() => {refresh();});
  const [signup, setSignup] = React.useState(null); // null | { plan }
  // Sign-in modal stays closed until the visitor clicks "Sign In" — never auto-opens.
  const [signin, setSignin] = React.useState(false);
  const openSignup = (plan) => {setSignin(false);setSignup({ plan: typeof plan === "string" ? plan : null });};
  const openSignin = () => {setSignup(null);setSignin(true);};
  return (
    <div>
      <Nav onSignup={openSignup} onSignin={openSignin} />
      <Hero onSignup={openSignup} />
      <Pillars />
      <Split id="auction" eyebrow="Marketplace + Auction Desk" title="Find the opportunity, then compete." body="Browse verified inventory, review locked details, watch auctions, track outbid pressure, and prepare gated bids with wallet eligibility visible before you act." steps={[["search", "Discover", "Search by county, trigger, tier, quality, and release window."], ["file-search", "Review", "Inspect evidence and locked payload boundaries before bidding."], ["gavel", "Compete", "Submit bids through the financial mutation gate."]]} />
      <Split id="workflow" reverse eyebrow="CRM + Account Control" title="After the win, work the lead without leaving." body="Won opportunities move into a CRM workspace with vault access state, tasks, notes, related tickets, wallet visibility, and account support." steps={[["trophy", "Win", "Lead delivery state and contact vault status stay clear."], ["list-checks", "Work", "Tasks, notes, follow-up history, and next-best action."], ["headphones", "Resolve", "Support tickets connect back to lead and account context."]]} />
      <Trust />
      <Plans onSignup={openSignup} />
      <Footer />
      {signup && <SignupFlow plan={signup.plan} onClose={() => setSignup(null)} onSwitchToSignin={openSignin} />}
      {signin && <SignInFlow onClose={() => setSignin(false)} onSwitchToSignup={() => openSignup()} />}
    </div>
  );
}

{ const __r = typeof document !== "undefined" && document.getElementById("root"); if (__r && !window.__rootMounted) { window.__rootMounted = true; ReactDOM.createRoot(__r).render(<Site />); refresh(); } }
