// b2b-app.jsx
// Main app: nav, hero, final CTA, footer.

const { useState, useEffect } = React;

const HERO_HEADLINES = {
  "intelligence-layer": ["The workforce intelligence layer", "for the AI era."],
  "rewrite-decade": ["AI is rewriting your workforce.", "Build the one that wins the next decade."],
  "rewrite-data": ["AI is rewriting your workforce.", "Lead the change with data."],
  "generation": ["The biggest workforce shift in a generation.", "Lead it with data."],
  "winning": ["Build the workforce", "that wins the next decade."]
};

const HERO_SUBS = {
  concise:
  "Measure AI readiness across every team, connect AI usage to real business impact, and know exactly where to invest to stay ahead.",
  short:
  "Stack turns AI tool usage into measurable proficiency, employee growth, and business value - the data behind workforce transformation."
};

// ─────────────────────────────────────────────────────────────────────
// NAV
// ─────────────────────────────────────────────────────────────────────
function Nav({ onCta, ctaLabel }) {
  const [menuOpen, setMenuOpen] = useState(false);

  const links = [];


  return (
    <nav style={{
      position: "sticky",
      top: 0,
      zIndex: 30,
      background: "rgba(250,250,247,0.78)",
      backdropFilter: "blur(18px)",
      WebkitBackdropFilter: "blur(18px)",
      borderBottom: "1px solid var(--b2b-hair)"
    }}>
      <div className="wrap nav-row" style={{
        display: "flex",
        alignItems: "center",
        justifyContent: "space-between",
        padding: "16px 32px",
        gap: 24
      }}>
        <a href="#" style={{ display: "flex", alignItems: "center", gap: 10 }}>
          <img src="/assets/b2b/stack-icon.jpg" alt="Stack" style={{ width: 28, height: 28, borderRadius: 7 }} />
        </a>

        <div className="nav-links" style={{
          display: "flex",
          alignItems: "center",
          gap: 28
        }}>
          {links.map(([l, h]) =>
          <a key={l} href={h} style={{
            fontFamily: "var(--font-sans)",
            fontSize: 14,
            fontWeight: 500,
            color: "var(--b2b-body)",
            transition: "color .2s"
          }}
          onMouseEnter={(e) => {e.currentTarget.style.color = "var(--b2b-accent-deep)";}}
          onMouseLeave={(e) => {e.currentTarget.style.color = "var(--b2b-body)";}}>
            {l}</a>
          )}
        </div>

        <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
          <button className="btn accent nav-cta" onClick={() => onCta('nav')} style={{ padding: "10px 18px", fontSize: 14 }}>
            {ctaLabel}
          </button>
        </div>
      </div>

      <style>{`
        @media (max-width: 880px) {
          .nav-links { display: none !important; }
          .nav-row { padding: 14px 22px !important; }
        }
      `}</style>
    </nav>);

}

// ─────────────────────────────────────────────────────────────────────
// HERO
// ─────────────────────────────────────────────────────────────────────
function Hero({ onCta, headline, subtext, ctaLabel }) {
  const h = HERO_HEADLINES[headline] || HERO_HEADLINES["ai-native"];
  const s = HERO_SUBS[subtext] || HERO_SUBS.concise;

  return (
    <section data-screen-label="01 Hero" style={{
      position: "relative",
      padding: "64px 0 120px",
      overflow: "hidden",
      background: "var(--b2b-bg)"
    }}>
      {/* Subtle accent glow */}
      <div style={{
        position: "absolute",
        top: -260,
        right: -260,
        width: 720,
        height: 720,
        borderRadius: "50%",
        background: "radial-gradient(circle at 30% 30%, rgba(243,126,77,0.22), rgba(243,126,77,0) 60%)",
        pointerEvents: "none"
      }} />
      {/* Dotted grid wash */}
      <div style={{
        position: "absolute",
        inset: 0,
        backgroundImage: "radial-gradient(rgba(11,11,12,0.05) 1px, transparent 1px)",
        backgroundSize: "26px 26px",
        maskImage: "linear-gradient(180deg, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0) 80%)",
        WebkitMaskImage: "linear-gradient(180deg, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0) 80%)",
        pointerEvents: "none"
      }} />

      <div className="wrap" style={{
        position: "relative",
        display: "grid",
        gridTemplateColumns: "minmax(0, 1fr) minmax(0, 1.05fr)",
        gap: 64,
        alignItems: "start"
      }}>
        <div style={{ minWidth: 0 }}>
          <h1 className="display" style={{
            fontSize: "clamp(38px, 4.8vw, 66px)",
            lineHeight: 1.02,
            color: "var(--b2b-ink)",
            textWrap: "balance",
            maxWidth: 820
          }}>
            <span style={{ display: "block" }}>{h[0]}</span>
            <span style={{ display: "block", color: "var(--b2b-accent-deep)" }}>{h[1]}</span>
          </h1>

          <p className="lede" style={{
            margin: "26px 0 36px",
            maxWidth: 540
          }}>{s}</p>

          <div style={{ display: "flex", flexWrap: "wrap", gap: 12, alignItems: "center" }}>
            <button className="btn accent lg" onClick={() => onCta('hero')}>
              {ctaLabel} →
            </button>
          </div>
        </div>

        <div style={{ display: "flex", justifyContent: "flex-end", minWidth: 0 }}>
          <HeroDashboard />
        </div>
      </div>

      <style>{`
        @media (max-width: 1080px) {
          section[data-screen-label="01 Hero"] .wrap {
            grid-template-columns: 1fr !important;
            gap: 48px !important;
          }
          section[data-screen-label="01 Hero"] .wrap > div:last-child {
            justify-content: flex-start !important;
          }
        }
      `}</style>
    </section>);

}

// ─────────────────────────────────────────────────────────────────────
// FINAL CTA
// ─────────────────────────────────────────────────────────────────────
function FinalCTA({ onCta, ctaLabel }) {
  return (
    <section data-screen-label="12 Final CTA" style={{
      background: "var(--b2b-ink-dark-bg)",
      color: "#FAFAF7",
      padding: "120px 0"
    }}>
      <div className="wrap" style={{
        maxWidth: 720,
        margin: "0 auto",
        textAlign: "center"
      }}>
        <div className="eyebrow" style={{ justifyContent: "center", color: "var(--b2b-accent)" }}>
          <span className="dot" />
          <span className="kicker" style={{ color: "var(--b2b-accent)" }}>Get started</span>
        </div>
        <h2 className="h-section" style={{ color: "#FAFAF7" }}>Find out exactly where your workforce stands on AI.

        </h2>
        <p className="lede" style={{
          color: "rgba(250,250,247,0.70)",
          marginTop: 24,
          maxWidth: 560,
          marginLeft: "auto",
          marginRight: "auto"
        }}>We'll connect your tools, benchmark every employee, and hand you the first set of action plans - in under two weeks.

        </p>

        <div style={{ marginTop: 40 }}>
          <button className="btn accent lg" onClick={() => onCta('final_cta')}>
            {ctaLabel} <span aria-hidden="true" style={{ marginLeft: 4 }}>→</span>
          </button>
        </div>
      </div>
    </section>);

}

// Removed: PilotRequestForm (simplified Final CTA to a single button)

// ─────────────────────────────────────────────────────────────────────
// FOOTER
// ─────────────────────────────────────────────────────────────────────
function Footer() {
  const columns = [
  {
    label: "Product",
    links: ["Overview", "AIQ Benchmark", "Integrations", "Security", "Pricing"]
  },
  {
    label: "Resources",
    links: ["Customer stories", "Workforce AI report", "Blog", "Help center"]
  },
  {
    label: "Company",
    links: ["About", "Careers", "Investors", "Press", "Contact"]
  },
  {
    label: "Legal",
    links: ["Privacy", "Terms", "DPA", "Subprocessors", "Status"]
  }];

  const investors = ["Fiverr", "Wix", "Anthropic", "Cursor", "Monday.com", "Udemy", "Calendly"];

  return (
    <footer style={{
      background: "var(--b2b-ink-dark-bg)",
      color: "rgba(250,250,247,0.55)",
      borderTop: "1px solid rgba(255,255,255,0.08)",
      padding: "72px 0 32px"
    }}>
      <div className="wrap">
        {/* Top: brand + trust strip */}
        <div className="footer-top" style={{
          display: "grid",
          gridTemplateColumns: "1.2fr 1fr 1fr 1fr 1fr",
          gap: 48,
          paddingBottom: 56,
          borderBottom: "1px solid rgba(255,255,255,0.08)"
        }}>
          <div>
            <img src="/assets/b2b/stack-wordmark-white.png" alt="Stack" style={{ height: 16, marginBottom: 18 }} />
            <p style={{
              fontFamily: "var(--font-sans)",
              fontSize: 13.5,
              lineHeight: 1.55,
              color: "rgba(250,250,247,0.55)",
              margin: 0,
              maxWidth: 260
            }}>
              Workforce intelligence for the AI era. Measure, monitor, and grow AI proficiency across every team.
            </p>

            <div style={{ marginTop: 28 }}>
              <div className="kicker" style={{
                color: "rgba(250,250,247,0.40)",
                marginBottom: 10,
                fontSize: 10
              }}>Backed by operators from</div>
              <div style={{
                fontFamily: "var(--font-sans)",
                fontSize: 12.5,
                lineHeight: 1.55,
                color: "rgba(250,250,247,0.70)",
                fontWeight: 500
              }}>{investors.join(" · ")}</div>
            </div>
          </div>

          {columns.map((col) =>
          <div key={col.label}>
              <div className="kicker" style={{ color: "rgba(250,250,247,0.40)", marginBottom: 16, fontSize: 10 }}>
                {col.label}
              </div>
              <ul style={{
              listStyle: "none",
              padding: 0,
              margin: 0,
              display: "flex",
              flexDirection: "column",
              gap: 10
            }}>
                {col.links.map((l) =>
              <li key={l}>
                    <a href="#" style={{
                  fontFamily: "var(--font-sans)",
                  fontSize: 13.5,
                  color: "rgba(250,250,247,0.70)",
                  textDecoration: "none",
                  transition: "color .15s var(--ease-out)"
                }}
                onMouseEnter={(e) => {e.currentTarget.style.color = "#FAFAF7";}}
                onMouseLeave={(e) => {e.currentTarget.style.color = "rgba(250,250,247,0.70)";}}>{l}</a>
                  </li>
              )}
              </ul>
            </div>
          )}
        </div>

        {/* Bottom: copyright + security badges + social */}
        <div className="footer-bottom" style={{
          display: "flex",
          justifyContent: "space-between",
          alignItems: "center",
          flexWrap: "wrap",
          gap: 20,
          paddingTop: 28
        }}>
          <div style={{
            fontFamily: "var(--font-mono)",
            fontSize: 10.5,
            letterSpacing: ".14em",
            textTransform: "uppercase",
            color: "rgba(250,250,247,0.45)"
          }}>
            © 2026 Stack Intelligence, Inc. · All rights reserved
          </div>

          <div style={{
            display: "flex",
            alignItems: "center",
            gap: 16,
            flexWrap: "wrap"
          }}>
            <div style={{
              display: "flex",
              alignItems: "center",
              gap: 12,
              fontFamily: "var(--font-mono)",
              fontSize: 10,
              letterSpacing: ".14em",
              textTransform: "uppercase",
              color: "rgba(250,250,247,0.40)"
            }}>
              <span>SOC 2 Type II</span>
              <span style={{ color: "rgba(250,250,247,0.18)" }}>·</span>
              <span>GDPR</span>
              <span style={{ color: "rgba(250,250,247,0.18)" }}>·</span>
              <span>ISO 27001</span>
            </div>

            <a href="#" aria-label="Stack on LinkedIn" style={{
              width: 32, height: 32,
              borderRadius: 8,
              border: "1px solid rgba(255,255,255,0.10)",
              display: "grid",
              placeItems: "center",
              color: "rgba(250,250,247,0.60)",
              transition: "color .15s var(--ease-out), border-color .15s var(--ease-out)"
            }}
            onMouseEnter={(e) => {e.currentTarget.style.color = "#FAFAF7";e.currentTarget.style.borderColor = "rgba(255,255,255,0.30)";}}
            onMouseLeave={(e) => {e.currentTarget.style.color = "rgba(250,250,247,0.60)";e.currentTarget.style.borderColor = "rgba(255,255,255,0.10)";}}>
              <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor">
                <path d="M20.5 2h-17A1.5 1.5 0 002 3.5v17A1.5 1.5 0 003.5 22h17a1.5 1.5 0 001.5-1.5v-17A1.5 1.5 0 0020.5 2zM8 19H5V9h3v10zm-1.5-11.6a1.7 1.7 0 110-3.4 1.7 1.7 0 010 3.4zM19 19h-3v-5.2c0-1.2-.4-2-1.5-2s-1.7.8-2 1.5c-.1.3-.1.7-.1 1.1V19h-3V9h3v1.3c.4-.6 1.1-1.6 2.7-1.6 2 0 3.5 1.3 3.5 4V19z" />
              </svg>
            </a>
          </div>
        </div>
      </div>

      <style>{`
        @media (max-width: 880px) {
          footer .footer-top { grid-template-columns: 1fr 1fr !important; gap: 36px 28px !important; }
          footer .footer-top > div:first-child { grid-column: span 2; }
        }
        @media (max-width: 540px) {
          footer .footer-top { grid-template-columns: 1fr !important; }
          footer .footer-top > div:first-child { grid-column: span 1; }
          footer .footer-bottom { flex-direction: column !important; align-items: flex-start !important; }
        }
      `}</style>
    </footer>);

}

// ─────────────────────────────────────────────────────────────────────
// APP
// ─────────────────────────────────────────────────────────────────────
function App() {
  // Production copy (the prototype's Tweaks panel has been dropped).
  const t = { heroHeadline: "intelligence-layer", heroSubtext: "concise", ctaLabel: "Request a demo" };

  // Opens the Tally demo-request popup. If embed.js hasn't finished loading yet
  // (a click that beats the async script), retry briefly instead of silently
  // no-opping; if it never loads (e.g. blocked), fall back to the standalone form.
  const openTallyPopup = () => {
    var w = (window.innerWidth && window.innerWidth < 600) ? window.innerWidth : 600;
    var opts = { layout: 'modal', width: w, hideTitle: true, autoClose: 1000 };
    var tries = 0;
    (function attempt() {
      if (window.Tally && window.Tally.openPopup) {
        try { Tally.openPopup('5BMOXM', opts); } catch (e) {}
        return;
      }
      if (tries++ < 50) { setTimeout(attempt, 100); return; } // ~5s of retries
      try { window.open('https://tally.so/r/5BMOXM', '_blank', 'noopener'); } catch (e) {}
    })();
  };

  // Fires the conversion events immediately (so it's logged even if the form is
  // slow), then opens the popup. `source` = nav / hero / pricing_* / final_cta.
  const onCta = (source) => {
    try { if (window.lpTrack) lpTrack('lp_demo_requested', { cta_location: source || 'unknown' }); } catch (e) {}
    try { if (window.fbq) fbq('track', 'Lead', { content_name: 'request_demo' }); } catch (e) {}
    openTallyPopup();
  };

  return (
    <div>
      <Nav onCta={onCta} ctaLabel={t.ctaLabel} />
      <Hero
        onCta={onCta}
        headline={t.heroHeadline}
        subtext={t.heroSubtext}
        ctaLabel={t.ctaLabel} />

      <InvestorsBanner />
      <div id="how"><SolutionSection /></div>
      <div id="product"><ProductVisualSection /></div>
      <ToolUsageSection />
      <IndividualsSection />
      <AssessmentSection />
      <IntegrationsSection />
      <PricingSection onCta={onCta} />
      <FAQSection onCta={onCta} />
      <FinalCTA onCta={onCta} ctaLabel={t.ctaLabel} />
    </div>);

}

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