// Shared form, trust signals, equation tagline
function HeroForm({ tone = "light", cta = "Start My Site" }) {
  const [url, setUrl] = React.useState("");
  const [email, setEmail] = React.useState("");
  const [expanded, setExpanded] = React.useState(false);
  const [sent, setSent] = React.useState(false);
  const formRef = React.useRef(null);
  const expand = () => { if (!expanded) setExpanded(true); };
  React.useEffect(() => {
    if (!expanded) return;
    const onDocPointer = (e) => {
      if (!formRef.current || formRef.current.contains(e.target)) return;
      if (!url && !email) setExpanded(false);
    };
    document.addEventListener("mousedown", onDocPointer);
    return () => document.removeEventListener("mousedown", onDocPointer);
  }, [expanded, url, email]);
  const onSubmit = (e) => {
    e.preventDefault();
    if (!expanded) { setExpanded(true); return; }
    if (!url || !email) return;
    setSent(true);
    setTimeout(() => setSent(false), 2400);
  };
  const isDark = tone === "dark";
  const step = expanded ? 2 : 1;
  return (
    <form ref={formRef} className={"hero-form hero-form-inline step-" + step + (isDark ? " is-dark" : "")} onSubmit={onSubmit}>
      <div className="hf-row hf-row-1">
        <div className="field field-url">
          <span className="icon icon-url" aria-hidden="true">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
              <path d="M10.5 13.5a4 4 0 0 0 5.66 0l3-3a4 4 0 1 0-5.66-5.66l-1.06 1.06"></path>
              <path d="M13.5 10.5a4 4 0 0 0-5.66 0l-3 3a4 4 0 1 0 5.66 5.66l1.06-1.06"></path>
            </svg>
          </span>
          <input type="text" placeholder="yourbusiness.com" value={url} onChange={(e) => setUrl(e.target.value)} onFocus={expand} onMouseDown={expand} required autoComplete="url" />
        </div>
      </div>
      <div className="hf-reveal" aria-hidden={!expanded}>
        <div className="hf-row hf-row-2">
          <div className="field field-email">
            <span className="icon icon-email" aria-hidden="true">
              <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
                <rect x="3" y="5" width="18" height="14" rx="3"></rect>
                <path d="M3.5 7l8.5 6 8.5-6"></path>
              </svg>
            </span>
            <input type="email" placeholder="you@yourbusiness.com" value={email} onChange={(e) => setEmail(e.target.value)} tabIndex={expanded ? 0 : -1} required autoComplete="email" />
          </div>
        </div>
      </div>
      <button className="submit submit-slot" type="submit" disabled={sent}>
        <span className="submit-label">{sent ? "On its way →" : cta}</span>
        <span className="arrow" aria-hidden="true">→</span>
      </button>
      <style>{`
        .hero-form-inline { position: relative; display: flex; flex-direction: column; gap: 0; max-width: 540px; width: 100%; background: rgba(255,255,255,.92); border: 1px solid rgba(15, 23, 42, .08); border-radius: 999px; padding: 4px; box-shadow: var(--card-shadow); transition: border-radius .35s cubic-bezier(.7,.0,.2,1), border-color .15s ease, box-shadow .15s ease, background .15s ease; }
        .hero-form-inline.step-2 { border-radius: 36px; }
        .hero-form-inline .field:focus-within .icon { background: var(--ink); color: #ffffff; }
        .hero-form-inline .hf-row { display: flex; align-items: stretch; }
        .hero-form-inline .field { position: relative; flex: 1; display: flex; align-items: center; background: transparent; border: none; border-radius: 999px; height: 56px; padding: 0 20px 0 62px; box-shadow: none; transition: padding-right .35s cubic-bezier(.7,.0,.2,1); min-width: 0; }
        .hero-form-inline.step-1 .field-url, .hero-form-inline.step-2 .field-email { padding-right: clamp(160px, 32%, 196px); }
        .hero-form-inline .field input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; height: 100%; font-size: 16px; font-weight: 500; color: var(--ink); }
        .hero-form-inline .field input::placeholder { color: var(--ink); -webkit-text-fill-color: var(--ink); opacity: 1; }
        .hero-form-inline .field .icon { position: absolute; left: 4px; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: color-mix(in oklch, #3a66dc 12%, white); color: var(--ink); }
        .hero-form-inline .field .icon svg { width: 18px; height: 18px; }
        .hero-form-inline .submit { height: 56px; padding: 0 26px; border-radius: 999px; border: 0; font-family: var(--font-display); font-size: 15px; font-weight: 600; letter-spacing: -0.01em; color: white; background: linear-gradient(135deg, var(--indigo) 0%, var(--violet) 55%, var(--coral) 110%); overflow: hidden; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; box-shadow: 0 10px 30px -10px color-mix(in oklch, var(--indigo) 55%, transparent), 0 2px 4px -1px rgba(15,23,42,.1), 0 0 0 1px rgba(255,255,255,.18) inset; }
        .hero-form-inline .submit-slot { position: absolute; right: 4px; top: 4px; z-index: 2; transition: top .35s cubic-bezier(.7,.0,.2,1), transform .2s ease, box-shadow .2s ease; }
        .hero-form-inline.step-2 .submit-slot { top: 70px; }
        .hero-form-inline .submit-slot:hover { transform: translateY(-1px); box-shadow: 0 14px 36px -8px color-mix(in oklch, var(--indigo) 60%, transparent), 0 0 0 1px rgba(255,255,255,.22) inset; }
        .hero-form-inline .submit::after { content: ""; position: absolute; inset: 0; background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,.35) 50%, transparent 70%); transform: translateX(-100%); transition: transform .8s ease; }
        .hero-form-inline .submit:hover::after { transform: translateX(100%); }
        .hero-form-inline .submit .arrow { display: inline-block; transition: transform .25s ease; }
        .hero-form-inline .submit:hover .arrow { transform: translateX(4px); }
        .hero-form-inline .submit-label { position: relative; z-index: 1; }
        .hero-form-inline .hf-reveal { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .35s cubic-bezier(.7,.0,.2,1), opacity .25s ease, margin-top .35s cubic-bezier(.7,.0,.2,1); opacity: 0; margin-top: 0; }
        .hero-form-inline .hf-reveal > .hf-row { overflow: hidden; min-height: 0; opacity: inherit; transform: translateY(-6px); transition: transform .35s cubic-bezier(.7,.0,.2,1); }
        .hero-form-inline.step-2 .hf-reveal { grid-template-rows: 1fr; opacity: 1; margin-top: 10px; }
        .hero-form-inline.step-2 .hf-reveal > .hf-row { transform: translateY(0); }
        .hero-form-inline.is-dark { background: rgba(255,255,255,.05); border-color: rgba(255,255,255,.12); }
        .hero-form-inline.is-dark .field input { color: #f7f8fc; }
        .hero-form-inline.is-dark .field input::placeholder { color: rgba(247,248,252,.45); }
        .hero-form-inline.is-dark .field .icon { color: rgba(247,248,252,.65); background: rgba(255,255,255,.08); }
        .hero-form-inline.is-dark .field:focus-within .icon { background: #ffffff; color: var(--ink); }
        @media (max-width: 560px) { .hero-form-inline.step-1 .field-url, .hero-form-inline.step-2 .field-email { padding-right: 148px; } .hero-form-inline .submit { padding: 0 18px; font-size: 14px; } }
      `}</style>
    </form>
  );
}
function Trust({ tone = "light", count = 2438 }) {
  return (
    <div className="trust">
      <span className="item"><svg className="check" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round"><path d="M5 12.5l4.5 4.5L19 7"></path></svg>No obligation</span>
      <span className="dot"></span>
      <span className="item"><svg className="check" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round"><path d="M5 12.5l4.5 4.5L19 7"></path></svg>Free preview in 2 days</span>
      <span className="dot"></span>
      <span className="item"><span className="counter" style={{ fontWeight: 600, color: "inherit", opacity: 1 }}><CountUp end={count} /></span><span>sites built</span></span>
    </div>);
}
function CountUp({ end, duration = 1400 }) {
  const [n, setN] = React.useState(0);
  React.useEffect(() => {
    let raf;
    const t0 = performance.now();
    const tick = (t) => {
      const p = Math.min(1, (t - t0) / duration);
      const eased = 1 - Math.pow(1 - p, 3);
      setN(Math.floor(eased * end));
      if (p < 1) raf = requestAnimationFrame(tick);
    };
    raf = requestAnimationFrame(tick);
    return () => cancelAnimationFrame(raf);
  }, [end]);
  return <span>{n.toLocaleString()}</span>;
}
function Equation({ accentA = "var(--indigo)", accentB = "var(--coral)" }) {
  return (
    <div className="eq"><span className="chip">AI efficiency</span><span className="op">+</span><span className="chip">Expert attention</span><span className="op">=</span><span style={{ opacity: .9 }}>your dream site, in 2 days</span></div>);
}
window.HeroForm = HeroForm;
window.Trust = Trust;
window.Equation = Equation;
window.CountUp = CountUp;
