const HERO_Q = "Pre-seed SaaS investors in the UK & US writing $500K–$2M cheques";
const HERO_ROWS = [0, 2, 11, 3, 4, 14, 5].map(i => CH.investors[i]);
const HERO_FILTERS = [["Stage", "is", "Pre-Seed, Seed", "Layers"], ["Sector", "is", "SaaS", "Tag"], ["Geography", "in", "UK, US", "Globe"], ["Cheque", "between", "$500K–$2M", "Wallet"]];

function InvestorLine({ v, sel, d }) {
  return (
    <div className={"irow rowin" + (sel ? " sel" : "")} style={{ "--d": d }}>
      <div style={{ display: "flex", alignItems: "center", gap: 11, minWidth: 0 }}>
        <LogoAvatar dom={v.dom} name={v.firm} size={36} />
        <div style={{ minWidth: 0 }}>
          <div style={{ display: "flex", alignItems: "center", gap: 5 }}><span className="trunc" style={{ fontSize: 14, fontWeight: 600 }}>{v.name}</span><VerifiedBadge compact /></div>
          <span className="trunc" style={{ fontSize: 12, color: "var(--text-muted)", display: "block", marginTop: 2 }}>{v.title} · {v.firm}</span>
        </div>
      </div>
      <div><InvestorTypeTag type={v.type} size="sm" /></div>
      <span className="trunc" style={{ fontSize: 13, color: "var(--text-secondary)" }}>{v.stages.join(", ")}</span>
      <span className="mono trunc" style={{ fontSize: 12 }}>{v.check}</span>
      <div><MatchScore value={v.match} /></div>
    </div>
  );
}

function ProfilePane({ v }) {
  const reasons = [v.fact, `Invests at ${v.stages.join(" and ")}, matching your stage filter`, `Based in the ${v.geo}, matching your geography filter`].filter(Boolean);
  return (
    <aside key={v.name} style={{ width: 300, flexShrink: 0, borderLeft: "1px solid var(--border-subtle)", display: "flex", flexDirection: "column", animation: "ch-drawer-in .5s var(--ease-out-expo)" }}>
      <div style={{ padding: 20, display: "flex", gap: 12 }}>
        <span style={{ width: 52, height: 52, borderRadius: 14, border: "1px solid var(--border-subtle)", display: "flex", alignItems: "center", justifyContent: "center", flexShrink: 0, background: "#fff", overflow: "hidden" }}><FirmLogo dom={v.dom} name={v.firm} size={50} style={{ border: "none" }} /></span>
        <div style={{ minWidth: 0 }}>
          <p style={{ fontFamily: "var(--font-display)", fontSize: 18, fontWeight: 700 }}>{v.name}</p>
          <div style={{ display: "flex", alignItems: "center", gap: 6, marginTop: 2 }}><FirmLogo dom={v.dom} name={v.firm} size={14} /><span className="trunc" style={{ fontSize: 12, color: "var(--text-secondary)" }}>{v.title} at {v.firm}</span></div>
          <div style={{ display: "flex", gap: 6, marginTop: 8 }}><InvestorTypeTag type={v.type} size="sm" /><VerifiedBadge /></div>
        </div>
      </div>
      <div style={{ padding: "16px 20px", borderTop: "1px solid var(--border-subtle)" }}>
        <p className="mono" style={{ fontSize: 10, letterSpacing: ".1em", color: "var(--text-muted)", textTransform: "uppercase", marginBottom: 10 }}>Why this match</p>
        <MatchScore value={v.match} variant="ring" size={56} showLabel />
        <ul style={{ listStyle: "none", padding: 0, margin: "14px 0 0", display: "flex", flexDirection: "column", gap: 8 }}>{reasons.map(r => <li key={r} style={{ display: "flex", gap: 8, fontSize: 12.5, lineHeight: 1.45, color: "var(--text-secondary)" }}><Icon name="Sparkles" size={13} color="var(--accent-gold)" style={{ marginTop: 2 }} />{r}</li>)}</ul>
      </div>
      <div style={{ padding: "16px 20px", borderTop: "1px solid var(--border-subtle)", display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12 }}>
        {[["Cheque size", v.check], ["Stages", v.stages.join(", ")], ["Geography", v.geo], ["Type", v.type === "vc" ? "VC" : "Angel"]].map(([k, x]) => <div key={k}><p style={{ fontSize: 11, color: "var(--text-muted)" }}>{k}</p><p className="trunc" style={{ fontSize: 13, fontWeight: 600, marginTop: 2 }}>{x}</p></div>)}
      </div>
      <div style={{ marginTop: "auto", padding: 16, borderTop: "1px solid var(--border-subtle)", display: "flex", gap: 8 }}><Button variant="solid" iconLeft="Send" fullWidth>Request intro</Button><Button variant="soft" iconLeft="Bookmark">Save</Button></div>
    </aside>
  );
}

function HeroApp() {
  const [typed, done] = useTyping(HERO_Q, { speed: 38, hold: 7000 });
  const [sel, setSel] = React.useState(0);
  React.useEffect(() => { const t = setInterval(() => setSel(s => (s + 1) % 4), 2800); return () => clearInterval(t); }, []);
  return (
    <div className="win" style={{ height: 640 }}>
      <div className="win-bar"><i></i><i></i><i></i><span className="win-url"><Icon name="Lock" size={11} />app.capitalhunt.io/search</span><span style={{ width: 45 }}></span></div>
      <div style={{ display: "flex", height: "calc(100% - 40px)" }}>
        <div className="rail"><img src="assets/logos/icon-blue.png" alt="" style={{ width: 28, height: 28, borderRadius: 8, marginBottom: 10 }} />{["House", "Search", "Sparkles", "Radio", "Users", "FolderOpen"].map((n, i) => <span key={n} className={i === 1 ? "on" : ""}><Icon name={n} size={18} /></span>)}</div>
        <div style={{ flex: 1, minWidth: 0, display: "flex", flexDirection: "column" }}>
          <div style={{ padding: "18px 18px 14px", display: "flex", flexDirection: "column", gap: 12, borderBottom: "1px solid var(--border-subtle)" }}>
            <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between" }}>
              <p style={{ fontFamily: "var(--font-display)", fontSize: 20, fontWeight: 700 }}>Investor Search</p>
              <div style={{ display: "flex", gap: 8 }}><Button variant="ghost" size="sm" iconLeft="Download">Export</Button><Button variant="soft" size="sm" iconLeft="Bookmark">Save search</Button></div>
            </div>
            <div style={{ position: "relative" }}>
              <AskBar value={typed} onChange={() => {}} placeholder="" />
              
            </div>
            <div style={{ display: "flex", gap: 8, flexWrap: "wrap", minHeight: 30 }}>{done && HERO_FILTERS.map(([f, o, v, ic], i) => <span key={f} className="rowin" style={{ "--d": i * 120 + "ms" }}><QueryFilter field={f} op={o} value={v} icon={ic} onRemove={() => {}} /></span>)}</div>
          </div>
          <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", padding: "10px 18px" }}>
            <span style={{ fontSize: 13, color: "var(--text-secondary)", display: "flex", alignItems: "center", gap: 8 }}><span style={{ width: 7, height: 7, borderRadius: 9, background: "var(--status-live)", animation: "ch-live-pulse 2s infinite" }}></span><b className="mono" style={{ color: "var(--text-primary)" }}>{done ? "12,847" : "200,000+"}</b> investors {done ? "match all filters" : "in database"}</span>
            <span className="mono" style={{ fontSize: 11, color: "var(--text-muted)" }}>Sorted by AI match</span>
          </div>
          <div className="irow ihead" style={{ borderTop: "1px solid var(--border-subtle)" }}><span>Investor</span><span>Type</span><span>Stage</span><span>Cheque</span><span>Match</span></div>
          <div style={{ flex: 1, overflow: "hidden" }}>{HERO_ROWS.map((v, i) => <InvestorLine key={v.name} v={v} sel={i === sel} d={400 + i * 90 + "ms"} />)}</div>
        </div>
        <div className="hide-md" style={{ display: "flex" }}><ProfilePane v={HERO_ROWS[sel]} /></div>
      </div>
    </div>
  );
}

function HeroFloats() {
  return (
    <>
      <div className="float" style={{ left: -22, top: 128, "--fd": "0s" }}>
        <div className="fcard" style={{ width: 256 }}>
          <p className="mono" style={{ fontSize: 10, letterSpacing: ".12em", color: "var(--status-success)", display: "flex", alignItems: "center", gap: 6 }}><span style={{ width: 6, height: 6, borderRadius: 6, background: "var(--status-live)", animation: "ch-live-pulse 2s infinite" }}></span>LIVE SIGNAL</p>
          <div style={{ display: "flex", gap: 10, marginTop: 10, alignItems: "center" }}><LogoAvatar dom="sequoiacap.com" name="Sequoia" size={38} /><div><p style={{ fontSize: 13, fontWeight: 600, lineHeight: 1.35 }}>Sequoia opened your pitch deck</p><p style={{ fontSize: 11.5, color: "var(--text-muted)", marginTop: 2 }}>Slide 7 of 14 · Just now</p></div></div>
        </div>
      </div>
      <div className="float" style={{ right: -22, bottom: 48, "--fd": "-2.5s" }}>
        <div className="fcard" style={{ width: 248 }}>
          <div style={{ display: "flex", alignItems: "center", gap: 10 }}><span style={{ width: 34, height: 34, borderRadius: 10, background: "var(--status-success-bg)", color: "var(--status-success)", display: "flex", alignItems: "center", justifyContent: "center" }}><Icon name="CalendarCheck" size={18} /></span><div><p style={{ fontSize: 13.5, fontWeight: 700 }}>Meeting confirmed</p><p className="mono" style={{ fontSize: 11, color: "var(--text-muted)" }}>Thu · 14:00 GMT</p></div></div>
          <div style={{ display: "flex", alignItems: "center", gap: 8, marginTop: 12, paddingTop: 12, borderTop: "1px solid var(--border-subtle)" }}><LogoAvatar dom="a16z.com" name="a16z" size={24} /><p style={{ fontSize: 12.5, color: "var(--text-secondary)" }}><b style={{ color: "var(--text-primary)" }}>Partner call</b> · a16z</p></div>
        </div>
      </div>
    </>
  );
}

Object.assign(window, { HeroApp, HeroFloats, InvestorLine });
