// Top navigation with working dropdowns + cross-page links + theme toggle
const NAV_PRODUCTS_LIST = [
  { name: "CRM & Ninja", desc: "Sales, retention, lead routing", icon: "crm", href: "pages/crm.html" },
  { name: "Integrations", desc: "MT4/5, cTrader, PSPs, KYC, comms", icon: "integrations", href: "pages/integrations.html" },
  { name: "Client Area", desc: "Registration, KYC, deposits, accounts", icon: "client", href: "pages/client-area.html" },
  { name: "Payments", desc: "Cards, crypto, APMs, recovery", icon: "payments", href: "pages/payments.html" },
  { name: "KYC, AML & Suitability", desc: "Onboarding workflows + checks", icon: "kyc", href: "pages/kyc.html" },
  { name: "Trading Platform", desc: "Infrastructure connected to ops", icon: "trading", href: "pages/trading-platform.html" },
  { name: "Web Trader & Mobile App", desc: "Client trading experiences", icon: "mobile", href: "pages/web-trader.html" },
  { name: "Mobile Trader App", desc: "Native iOS + Android", icon: "mobile", href: "pages/mobile-trader.html" },
  { name: "Prop Trading Suite", desc: "Challenges, funded, payouts", icon: "prop", href: "pages/prop-trading.html" },
  { name: "Crypto Operations", desc: "Wallet login, swap, stake, farms, launchpad", icon: "crypto", href: "pages/crypto-trading.html" },
  { name: "BI & AI", desc: "Dashboards, alerts, next-best-action", icon: "bi", href: "pages/bi-ai.html" },
  { name: "IB System", desc: "Partner trees, commissions, reports", icon: "ib", href: "pages/ib-system.html" },
  { name: "Affiliate & Media Buying", desc: "CPA, RevShare, hybrid", icon: "affiliate", href: "pages/affiliate-media.html" },
];

// Top-3 featured (most-popular). The rest go in a smaller secondary list.
const NAV_SOLUTIONS_FEATURED = [
  {
    name: "FX / CFD Brokers",
    tag: "Most popular",
    desc: "Launch and scale a brokerage with MT4/5, cTrader, DXTrade — all wired to your CRM, KYC, payments, BI and IB program.",
    stats: [{ l: "Brokers live", v: "60+" }, { l: "FTD lift", v: "+24%" }],
    href: "pages/fx-cfd-brokers.html",
    glyph: "fx",
  },
  {
    name: "Crypto Trading Companies",
    tag: "Fastest growing",
    desc: "Run an exchange or crypto-only brokerage with on-chain KYT, custody connectors, fiat ramps and licensed entity controls.",
    stats: [{ l: "Chains supported", v: "12+" }, { l: "Withdrawal SLA", v: "minutes" }],
    href: "pages/crypto-companies.html",
    glyph: "crypto",
  },
  {
    name: "Prop Firms",
    tag: "Built for prop",
    desc: "Challenges, funded accounts, breach engine, addon upsells and instant payouts in fiat or crypto. Engineered for the prop boom.",
    stats: [{ l: "Active traders", v: "120K+" }, { l: "Auto-payouts", v: "24/7" }],
    href: "pages/prop-firms.html",
    glyph: "prop",
  },
];

const NAV_SOLUTIONS_OTHER = [
  { name: "Stock & Investment", desc: "Investor onboarding, subscriptions, advisory", href: "pages/stock-investment.html" },
  { name: "Multi-License Groups", desc: "One brand, many entities, group P&L", href: "pages/multi-license.html" },
  { name: "Financial Call Centers", desc: "Sales CRM, dialer, performance scoring", href: "pages/call-centers.html" },
  { name: "Online Academies", desc: "Subscriptions, signals, broker handoff", href: "pages/academies.html" },
];

// Backwards compat for any code still reading the flat list
const NAV_SOLUTIONS = [
  ...NAV_SOLUTIONS_FEATURED.map((s) => ({ name: s.name, desc: s.desc, href: s.href })),
  ...NAV_SOLUTIONS_OTHER,
];

// Resolve a path relative to whether we're at root or in pages/
function resolveHref(href) {
  if (!href) return "#";
  // Detect: are we currently inside /pages/?
  const inPages = window.location.pathname.includes("/pages/");
  if (href.startsWith("http") || href.startsWith("#")) return href;
  if (href === "index.html" || href === "/") {
    return inPages ? "../index.html" : "index.html";
  }
  if (href.startsWith("pages/")) {
    return inPages ? href.replace("pages/", "") : href;
  }
  return href;
}

window.resolveHref = resolveHref;

function NavIcon({ kind }) {
  const stroke = "url(#nav-icon-grad)";
  const common = { width: 18, height: 18, viewBox: "0 0 20 20", fill: "none", strokeWidth: 1.6, strokeLinecap: "round", strokeLinejoin: "round" };
  const paths = {
    crm: <><circle cx="10" cy="7" r="3" stroke={stroke}/><path d="M3 17c1.5-3 4-4.5 7-4.5s5.5 1.5 7 4.5" stroke={stroke}/></>,
    client: <><rect x="3" y="4" width="14" height="12" rx="2" stroke={stroke}/><path d="M3 9h14M7 13h3" stroke={stroke}/></>,
    payments: <><rect x="2" y="5" width="16" height="11" rx="2" stroke={stroke}/><path d="M2 9h16M6 13h3" stroke={stroke}/></>,
    kyc: <><path d="M10 2l6 3v5c0 4-3 6.5-6 7.5C7 16.5 4 14 4 10V5l6-3z" stroke={stroke}/><path d="M7.5 10l2 2 3.5-3.5" stroke={stroke}/></>,
    trading: <><path d="M3 14l4-4 3 2 7-7" stroke={stroke}/><path d="M14 5h3v3" stroke={stroke}/></>,
    mobile: <><rect x="6" y="2" width="8" height="16" rx="2" stroke={stroke}/><path d="M9 15h2" stroke={stroke}/></>,
    prop: <><circle cx="10" cy="10" r="6" stroke={stroke}/><path d="M10 6v4l2.5 1.5" stroke={stroke}/></>,
    crypto: <><circle cx="10" cy="10" r="6" stroke={stroke}/><path d="M10 6v8M7.5 8h4M7.5 12h4" stroke={stroke}/></>,
    bi: <><path d="M3 17V8M8 17V4M13 17v-7M18 17v-4" stroke={stroke}/></>,
    ib: <><circle cx="10" cy="4" r="2" stroke={stroke}/><circle cx="4" cy="14" r="2" stroke={stroke}/><circle cx="16" cy="14" r="2" stroke={stroke}/><path d="M10 6v3M8.5 10.5L5.5 12.5M11.5 10.5L14.5 12.5" stroke={stroke}/></>,
    affiliate: <><path d="M10 3l2.5 4.5 5 .8-3.7 3.5.9 5L10 14.5 5.3 16.8l.9-5L2.5 8.3l5-.8L10 3z" stroke={stroke}/></>,
  };
  return (
    <svg {...common}>
      <defs>
        <linearGradient id="nav-icon-grad" x1="0" y1="0" x2="20" y2="20" gradientUnits="userSpaceOnUse">
          <stop offset="0" stopColor="#9D80FF"/>
          <stop offset="1" stopColor="#F89BD6"/>
        </linearGradient>
      </defs>
      {paths[kind]}
    </svg>
  );
}

function ThemeToggle({ theme, onToggle }) {
  return (
    <button
      onClick={onToggle}
      aria-label={theme === "dark" ? "Switch to light mode" : "Switch to dark mode"}
      className="theme-toggle"
    >
      <span className="theme-icon" style={{ transform: theme === "dark" ? "rotate(0deg)" : "rotate(180deg)" }}>
        {theme === "dark" ? (
          <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
            <path d="M13 9.5A5.5 5.5 0 0 1 6.5 3a5.5 5.5 0 1 0 6.5 6.5z" fill="currentColor"/>
          </svg>
        ) : (
          <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
            <circle cx="8" cy="8" r="3" fill="currentColor"/>
            <path d="M8 1v2M8 13v2M1 8h2M13 8h2M3 3l1.5 1.5M11.5 11.5L13 13M3 13l1.5-1.5M11.5 4.5L13 3" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round"/>
          </svg>
        )}
      </span>
      <style>{`
        .theme-toggle {
          width: 38px; height: 38px; padding: 0;
          background: var(--surface-2); border: 1px solid var(--line);
          border-radius: 999px;
          color: var(--text-dim);
          display: inline-grid; place-items: center;
          transition: all .2s ease;
        }
        .theme-toggle:hover { color: var(--text); background: var(--surface-hover); }
        .theme-icon { display: inline-flex; transition: transform .4s ease; }
      `}</style>
    </button>
  );
}

function TopNav({ theme, setTheme, currentPage }) {
  const [open, setOpen] = React.useState(null);
  const [scrolled, setScrolled] = React.useState(false);
  const [mobileOpen, setMobileOpen] = React.useState(false);
  const [mobileSection, setMobileSection] = React.useState(null);
  const wrapRef = React.useRef(null);

  React.useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 8);
    onScroll();
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);

  React.useEffect(() => {
    const onClick = (e) => {
      if (wrapRef.current && !wrapRef.current.contains(e.target)) setOpen(null);
    };
    document.addEventListener("mousedown", onClick);
    return () => document.removeEventListener("mousedown", onClick);
  }, []);

  return (
    <div
      ref={wrapRef}
      className="topnav-wrap"
      style={{
        position: "fixed", top: 0, left: 0, right: 0, zIndex: 1000,
        transition: mobileOpen ? "none" : "background .25s ease, border-color .25s ease, backdrop-filter .25s ease",
        background: mobileOpen ? "transparent" : (scrolled || open ? (theme === "dark" ? "rgba(11,11,24,0.78)" : "rgba(250,250,247,0.82)") : "transparent"),
        backdropFilter: mobileOpen ? "none" : (scrolled || open ? "blur(14px) saturate(140%)" : "none"),
        WebkitBackdropFilter: mobileOpen ? "none" : (scrolled || open ? "blur(14px) saturate(140%)" : "none"),
        borderBottom: mobileOpen ? "1px solid transparent" : (scrolled || open ? "1px solid var(--line)" : "1px solid transparent"),
        pointerEvents: "auto",
      }}
    >
      <div className="container topnav-row" style={{ position: "relative", zIndex: 2 }}>
        <a href={resolveHref("index.html")} style={{ display: "inline-flex" }} aria-label="Antelope home"><Logo /></a>

        <nav className="topnav-desktop">
          <NavTrigger label="Product" active={open === "product"} onClick={() => setOpen(open === "product" ? null : "product")}/>
          <NavTrigger label="Solutions" active={open === "solutions"} onClick={() => setOpen(open === "solutions" ? null : "solutions")}/>
          <a className="nav-link" href={resolveHref("pages/why.html")}>Why Antelope</a>
          <a className="nav-link" href={resolveHref("pages/pricing.html")}>Pricing</a>
          <a className="nav-link" href={resolveHref("pages/about.html")}>Company</a>
          <a className="topnav-ai topnav-ai-inline" href={resolveHref("pages/ai.html")}>
            <span className="topnav-ai-spark" aria-hidden="true">
              <svg width="13" height="13" viewBox="0 0 14 14" fill="none">
                <path d="M7 1l1.4 4.2L12.6 6.6 8.4 8 7 12.2 5.6 8 1.4 6.6 5.6 5.2z" fill="currentColor"/>
              </svg>
            </span>
            AI Features
          </a>
        </nav>

        <div className="topnav-actions">
          {setTheme && <ThemeToggle theme={theme} onToggle={() => setTheme(theme === "dark" ? "light" : "dark")}/>}
          <a className="btn btn-ghost topnav-tg" href={resolveHref("pages/contact.html")}>
            <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path d="M21 4L2 12l7 2 2 7 10-17z"/></svg>
            Telegram
          </a>
          <a className="btn btn-primary topnav-cta" href={resolveHref("pages/contact.html")}>Book a demo</a>
          <button
            className="topnav-burger"
            aria-label="Open menu"
            onClick={() => setMobileOpen(true)}
            style={{ position: "relative", zIndex: 1001, touchAction: "manipulation" }}
          >
            <span/><span/><span/>
          </button>
        </div>
      </div>

      <style>{`
        .topnav-row { display: flex; align-items: center; height: 68px; gap: 28px; }
        .topnav-desktop { display: flex; align-items: center; gap: 4px; margin-left: 12px; }
        .topnav-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
        .topnav-burger { display: none; width: 40px; height: 40px; padding: 0; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; flex-direction: column; align-items: center; justify-content: center; gap: 4px; cursor: pointer; flex-shrink: 0; }
        .topnav-burger span { width: 18px; height: 2px; background: var(--text); border-radius: 2px; transition: transform .2s; pointer-events: none; }
        .topnav-ai {
          position: relative; display: inline-flex; align-items: center; gap: 7px;
          height: 40px; padding: 0 14px; border-radius: 10px;
          font-size: 13px; font-weight: 600; letter-spacing: -0.005em;
          color: #fff; text-decoration: none; white-space: nowrap;
          background: linear-gradient(110deg, #5A2DF4 0%, #F118B2 55%, #FF7A45 100%);
          background-size: 200% 100%; background-position: 0% 50%;
          box-shadow: 0 0 0 1px rgba(255,255,255,0.08) inset, 0 8px 22px -8px rgba(241,24,178,0.45), 0 0 24px -10px rgba(255,122,69,0.5);
          transition: background-position .5s ease, transform .15s ease, box-shadow .25s ease;
        }
        .topnav-ai:hover { background-position: 100% 50%; transform: translateY(-1px); box-shadow: 0 0 0 1px rgba(255,255,255,0.15) inset, 0 14px 30px -8px rgba(241,24,178,0.55), 0 0 32px -8px rgba(255,122,69,0.6); }
        .topnav-ai-spark { display: inline-flex; align-items: center; justify-content: center; color: #fff; filter: drop-shadow(0 0 6px rgba(255,255,255,0.5)); animation: ai-spark 2.4s ease-in-out infinite; }
        @keyframes ai-spark { 0%,100% { transform: scale(1) rotate(0deg); opacity: 1; } 50% { transform: scale(1.18) rotate(15deg); opacity: 0.85; } }
        @media (max-width: 1080px) { .topnav-ai { display: none; } }
        .nav-link {
          padding: 8px 12px; font-size: 14px; font-weight: 500;
          color: var(--text-dim); border-radius: 8px;
          transition: color .15s ease, background .15s ease;
        }
        .nav-link:hover { color: var(--text); background: var(--surface-2); }
        .nav-trigger {
          padding: 8px 12px; font-size: 14px; font-weight: 500;
          color: var(--text-dim); background: transparent; border: 0;
          border-radius: 8px; display: inline-flex; align-items: center; gap: 4px;
          transition: color .15s ease, background .15s ease;
        }
        .nav-trigger:hover, .nav-trigger.active { color: var(--text); background: var(--surface-2); }
        .nav-trigger svg { transition: transform .2s ease; }
        .nav-trigger.active svg { transform: rotate(180deg); }
        @media (max-width: 1080px) {
          .topnav-desktop { display: none; }
          .topnav-tg { display: none; }
          .topnav-burger { display: inline-flex; }
        }
        @media (max-width: 600px) {
          .topnav-row { height: 60px; gap: 12px; }
          .topnav-cta { padding: 0 12px; height: 38px; font-size: 13px; }
        }
      `}</style>

      {open === "product" && <ProductMega onClose={() => setOpen(null)} />}
      {open === "solutions" && <SolutionsMega onClose={() => setOpen(null)} />}
      {mobileOpen && (
        <MobileNav
          onClose={() => { setMobileOpen(false); setMobileSection(null); }}
          section={mobileSection}
          setSection={setMobileSection}
          theme={theme}
          setTheme={setTheme}
        />
      )}
    </div>
  );
}

function MobileNav({ onClose, section, setSection, theme, setTheme }) {
  // Lock body in place at current scroll position (iOS-safe)
  React.useEffect(() => {
    const scrollY = window.scrollY;
    const body = document.body;
    const prevPosition = body.style.position;
    const prevTop = body.style.top;
    const prevWidth = body.style.width;
    const prevOverflow = body.style.overflow;
    body.style.position = "fixed";
    body.style.top = `-${scrollY}px`;
    body.style.width = "100%";
    body.style.overflow = "hidden";
    return () => {
      body.style.position = prevPosition;
      body.style.top = prevTop;
      body.style.width = prevWidth;
      body.style.overflow = prevOverflow;
      window.scrollTo(0, scrollY);
    };
  }, []);
  const links = [
    { label: "AI Features", href: "pages/ai.html", ai: true },
    { label: "Why Antelope", href: "pages/why.html" },
    { label: "Pricing", href: "pages/pricing.html" },
    { label: "Company", href: "pages/about.html" },
    { label: "Security", href: "pages/security.html" },
    { label: "Contact", href: "pages/contact.html" },
  ];
  return (
    <div className="mobile-nav-overlay">
      <div className="mobile-nav-head">
        <div className="container topnav-row" style={{ gap: 0 }}>
          <a href={resolveHref("index.html")} style={{ display: "inline-flex" }} aria-label="Antelope home"><Logo/></a>
          <button className="mobile-nav-close" onClick={onClose} aria-label="Close menu" style={{ marginLeft: "auto" }}>✕</button>
        </div>
      </div>
      <div className="mobile-nav-body">
        {section === null && (
          <>
            <button className="mobile-nav-row mobile-nav-section" onClick={() => setSection("product")}>
              <span>Product</span><span>→</span>
            </button>
            <button className="mobile-nav-row mobile-nav-section" onClick={() => setSection("solutions")}>
              <span>Solutions</span><span>→</span>
            </button>
            {links.map((l) => (
              <a
                key={l.label}
                href={resolveHref(l.href)}
                className={l.ai ? "mobile-nav-row mobile-nav-ai" : "mobile-nav-row"}
              >
                {l.ai ? (
                  <>
                    <span className="mn-ai-spark" aria-hidden="true">
                      <svg width="14" height="14" viewBox="0 0 14 14" fill="none">
                        <path d="M7 1l1.4 4.2L12.6 6.6 8.4 8 7 12.2 5.6 8 1.4 6.6 5.6 5.2z" fill="currentColor"/>
                      </svg>
                    </span>
                    <span className="mn-ai-label">{l.label}</span>
                    <span className="mn-ai-pill">NEW</span>
                  </>
                ) : l.label}
              </a>
            ))}
            <div className="mobile-nav-cta">
              <a href={resolveHref("pages/contact.html")} className="btn btn-primary" style={{ width: "100%", justifyContent: "center" }}>Book a demo</a>
              {setTheme && (
                <button className="btn btn-ghost" style={{ width: "100%", justifyContent: "center", marginTop: 10 }} onClick={() => setTheme(theme === "dark" ? "light" : "dark")}>
                  {theme === "dark" ? "Switch to light" : "Switch to dark"}
                </button>
              )}
            </div>
          </>
        )}
        {section === "product" && (
          <>
            <button className="mobile-nav-back" onClick={() => setSection(null)}>← Back</button>
            <div className="mobile-nav-eyebrow">Product</div>
            {NAV_PRODUCTS_LIST.map((it) => (
              <a key={it.name} href={resolveHref(it.href)} className="mobile-nav-row">
                <div>
                  <div style={{ fontWeight: 600 }}>{it.name}</div>
                  <div style={{ fontSize: 12.5, color: "var(--text-dim)", marginTop: 2 }}>{it.desc}</div>
                </div>
              </a>
            ))}
          </>
        )}
        {section === "solutions" && (
          <>
            <button className="mobile-nav-back" onClick={() => setSection(null)}>← Back</button>
            <div className="mobile-nav-eyebrow">Solutions</div>
            {NAV_SOLUTIONS.map((s) => (
              <a key={s.name} href={resolveHref(s.href)} className="mobile-nav-row">
                <div>
                  <div style={{ fontWeight: 600 }}>{s.name}</div>
                  <div style={{ fontSize: 12.5, color: "var(--text-dim)", marginTop: 2 }}>{s.desc}</div>
                </div>
              </a>
            ))}
          </>
        )}
      </div>
      <style>{`
        .mobile-nav-overlay {
          position: fixed; inset: 0; z-index: 2000;
          background: var(--ink); display: flex; flex-direction: column;
        }
        :root[data-theme="dark"] .mobile-nav-overlay { background: #0B0B18; }
        :root:not([data-theme="dark"]) .mobile-nav-overlay { background: #FAFAF7; }
        .mobile-nav-head {
          display: block; padding: 0;
          border-bottom: 1px solid var(--line); flex-shrink: 0;
        }
        .mobile-nav-close { width: 40px; height: 40px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; color: var(--text); font-size: 18px; cursor: pointer; }
        .mobile-nav-body { flex: 1; overflow-y: auto; padding: 16px 22px 100px; }
        .mobile-nav-row {
          display: flex; align-items: center; justify-content: space-between;
          padding: 18px 0; border-bottom: 1px solid var(--line);
          color: var(--text); font-size: 17px; font-weight: 500;
          background: transparent; border-left: 0; border-right: 0; border-top: 0;
          width: 100%; text-align: left; cursor: pointer;
        }
        .mobile-nav-section { font-size: 18px; font-weight: 700; }
        .mobile-nav-back { background: transparent; border: 0; color: var(--purple-2); font-size: 14px; padding: 0; margin: 0 0 18px; cursor: pointer; }
        .mobile-nav-eyebrow { font-size: 11px; color: var(--text-mute); letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 6px; }
        .mobile-nav-cta { margin-top: 28px; }
        .mobile-nav-ai {
          position: relative;
          margin: 14px 0;
          padding: 14px 16px;
          border-radius: 14px;
          border-bottom: 0 !important;
          background: linear-gradient(110deg, #5A2DF4 0%, #7A52FF 30%, #F118B2 65%, #FF7A45 100%);
          color: #fff !important;
          font-weight: 600;
          gap: 10px;
          justify-content: flex-start !important;
          box-shadow: 0 8px 24px -8px rgba(241,24,178,0.45), 0 0 0 1px rgba(255,255,255,0.1) inset;
          overflow: hidden;
        }
        .mobile-nav-ai::after {
          content: ""; position: absolute; inset: 0;
          background: radial-gradient(circle at 90% 50%, rgba(255,255,255,0.18), transparent 50%);
          pointer-events: none;
        }
        .mn-ai-spark {
          display: inline-flex; align-items: center; justify-content: center;
          width: 28px; height: 28px; border-radius: 8px;
          background: rgba(255,255,255,0.18);
          color: #fff; flex-shrink: 0;
          animation: mn-ai-pulse 2.4s ease-in-out infinite;
        }
        @keyframes mn-ai-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.1); } }
        .mn-ai-label { flex: 1; font-size: 17px; }
        .mn-ai-pill {
          font-size: 10px; font-weight: 700; letter-spacing: 0.08em;
          padding: 4px 8px; border-radius: 999px;
          background: rgba(255,255,255,0.22); color: #fff;
          flex-shrink: 0;
        }
      `}</style>
    </div>
  );
}

function NavTrigger({ label, active, onClick }) {
  return (
    <button className={`nav-trigger ${active ? "active" : ""}`} onClick={onClick}>
      {label}
      <svg width="10" height="10" viewBox="0 0 12 12" fill="none"><path d="M3 5l3 3 3-3" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/></svg>
    </button>
  );
}

function ProductMega() {
  return (
    <div className="mega" style={{ padding: "8px 0 28px" }}>
      <div className="container" style={{ display: "grid", gridTemplateColumns: "260px 1fr", gap: 32, paddingTop: 16 }}>
        <div>
          <div className="eyebrow" style={{ marginBottom: 10 }}>Product OS</div>
          <h3 style={{ fontSize: 18, lineHeight: 1.3, marginBottom: 8 }}>Everything connected from lead to trading activity</h3>
          <p style={{ fontSize: 13 }}>CRM, Client Area, payments, KYC, trading, BI and AI in one platform.</p>
          <a href={resolveHref("index.html")} className="btn-link" style={{ marginTop: 14 }}>Product overview →</a>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(2, 1fr)", gap: 4 }}>
          {NAV_PRODUCTS_LIST.map((it) => (
            <a key={it.name} href={resolveHref(it.href)} className="mega-cell">
              <div className="mega-icon"><NavIcon kind={it.icon}/></div>
              <div>
                <div className="mega-name">{it.name}</div>
                <div className="mega-desc">{it.desc}</div>
              </div>
            </a>
          ))}
        </div>
      </div>
      <style>{`
        .mega { animation: mega-in .18s ease both; }
        @keyframes mega-in { from { opacity: 0; transform: translateY(-4px);} to { opacity: 1; transform: translateY(0);} }
        .mega-cell {
          display: flex; gap: 12px; padding: 12px 14px; border-radius: 12px;
          transition: background .15s ease;
        }
        .mega-cell:hover { background: var(--surface-2); }
        .mega-icon {
          width: 34px; height: 34px; flex: 0 0 34px;
          display: grid; place-items: center;
          background: rgba(122,82,255,0.08);
          border: 1px solid rgba(122,82,255,0.18);
          border-radius: 10px;
        }
        .mega-name { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 2px; }
        .mega-desc { font-size: 12.5px; color: var(--text-dim); line-height: 1.4; }
      `}</style>
    </div>
  );
}

function SolutionGlyph({ kind }) {
  const grad = "url(#sol-glyph-grad)";
  const wrap = (children) => (
    <svg width="36" height="36" viewBox="0 0 36 36" fill="none">
      <defs>
        <linearGradient id="sol-glyph-grad" x1="0" y1="0" x2="36" y2="36">
          <stop offset="0" stopColor="var(--purple-2)"/>
          <stop offset="1" stopColor="var(--pink)"/>
        </linearGradient>
      </defs>
      {children}
    </svg>
  );
  if (kind === "fx") return wrap(<><path d="M4 26 L11 18 L16 22 L24 12 L32 8" stroke={grad} strokeWidth="2" fill="none" strokeLinecap="round"/><circle cx="32" cy="8" r="2.5" fill={grad}/><path d="M4 30 H32" stroke={grad} strokeWidth="1" opacity="0.4" strokeDasharray="2 2"/></>);
  if (kind === "crypto") return wrap(<><circle cx="18" cy="18" r="11" stroke={grad} strokeWidth="2" fill="none"/><path d="M14 13 H20 Q23 13 23 16 Q23 19 20 19 H14 M14 19 H21 Q24 19 24 22 Q24 25 21 25 H14 M16 11 V13 M16 25 V27 M19 11 V13 M19 25 V27" stroke={grad} strokeWidth="1.6" fill="none"/></>);
  if (kind === "prop") return wrap(<><path d="M18 4 L30 11 L30 22 Q30 28 18 32 Q6 28 6 22 L6 11 Z" stroke={grad} strokeWidth="2" fill="none"/><path d="M12 18 L16 22 L24 13" stroke={grad} strokeWidth="2" fill="none" strokeLinecap="round" strokeLinejoin="round"/></>);
  return null;
}

function SolutionsMega() {
  return (
    <div className="mega solutions-mega" style={{ padding: "8px 0 28px" }}>
      <div className="container" style={{ paddingTop: 16 }}>
        <div className="sol-mega-head">
          <div>
            <div className="eyebrow" style={{ marginBottom: 8 }}>Who we help · By industry</div>
            <h3 style={{ fontSize: 20, lineHeight: 1.3, marginBottom: 4 }}>Pick the playbook that matches your business</h3>
            <p style={{ fontSize: 13, color: "var(--text-dim)" }}>Each comes with prebuilt workflows, KYC profiles, payment routes and BI dashboards — not a blank canvas.</p>
          </div>
          <a href={resolveHref("pages/why.html")} className="btn-link" style={{ alignSelf: "end" }}>See all solutions →</a>
        </div>

        <div className="sol-featured-grid">
          {NAV_SOLUTIONS_FEATURED.map((s) => (
            <a key={s.name} href={resolveHref(s.href)} className="sol-featured-card">
              <div className="sol-card-glow"/>
              <div className="sol-card-row">
                <div className="sol-card-glyph"><SolutionGlyph kind={s.glyph}/></div>
                <span className="sol-card-tag">{s.tag}</span>
              </div>
              <div className="sol-card-name">{s.name}</div>
              <div className="sol-card-desc">{s.desc}</div>
              <div className="sol-card-stats">
                {s.stats.map((st) => (
                  <div key={st.l} className="sol-card-stat">
                    <span className="sol-card-stat-v">{st.v}</span>
                    <span className="sol-card-stat-l">{st.l}</span>
                  </div>
                ))}
              </div>
              <div className="sol-card-cta">Open page <span>→</span></div>
            </a>
          ))}
        </div>

        <div className="sol-secondary-grid">
          {NAV_SOLUTIONS_OTHER.map((s) => (
            <a key={s.name} href={resolveHref(s.href)} className="sol-secondary-cell">
              <div>
                <div className="sol-sec-name">{s.name}</div>
                <div className="sol-sec-desc">{s.desc}</div>
              </div>
              <span className="sol-sec-arr">→</span>
            </a>
          ))}
        </div>
      </div>
      <style>{`
        .solutions-mega { background: var(--ink); }
        .sol-mega-head {
          display: flex; justify-content: space-between; gap: 24px;
          padding-bottom: 18px; margin-bottom: 18px;
          border-bottom: 1px solid var(--line);
        }
        .sol-featured-grid {
          display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px;
        }
        .sol-featured-card {
          position: relative; padding: 22px;
          background: var(--surface);
          border: 1px solid var(--line); border-radius: 16px;
          display: flex; flex-direction: column; gap: 10px;
          overflow: hidden;
          transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease, background .18s ease;
        }
        .sol-featured-card:hover {
          transform: translateY(-3px);
          background: var(--surface-2);
          border-color: color-mix(in oklab, var(--purple-2) 60%, var(--line));
          box-shadow: 0 18px 40px -20px var(--purple-glow);
        }
        .sol-card-glow {
          position: absolute; inset: -50%;
          background: radial-gradient(60% 60% at 50% 0%, var(--purple-glow), transparent 70%);
          opacity: 0; transition: opacity .25s ease;
          pointer-events: none;
        }
        .sol-featured-card:hover .sol-card-glow { opacity: 1; }
        .sol-card-row { display: flex; align-items: center; justify-content: space-between; }
        .sol-card-glyph {
          width: 44px; height: 44px; display: grid; place-items: center;
          background: rgba(122,82,255,0.1);
          border: 1px solid rgba(122,82,255,0.25);
          border-radius: 12px;
          position: relative; z-index: 1;
        }
        .sol-card-tag {
          font-size: 10px; font-weight: 600; letter-spacing: 0.06em;
          text-transform: uppercase;
          padding: 4px 8px; border-radius: 999px;
          background: rgba(241,24,178,0.12);
          color: var(--pink);
          border: 1px solid rgba(241,24,178,0.25);
          position: relative; z-index: 1;
        }
        .sol-card-name {
          font-size: 17px; font-weight: 700; letter-spacing: -0.01em;
          color: var(--text); position: relative; z-index: 1;
        }
        .sol-card-desc {
          font-size: 13px; color: var(--text-dim); line-height: 1.55;
          position: relative; z-index: 1;
        }
        .sol-card-stats {
          display: flex; gap: 16px; padding-top: 10px; margin-top: 4px;
          border-top: 1px solid var(--line);
          position: relative; z-index: 1;
        }
        .sol-card-stat { display: flex; flex-direction: column; gap: 2px; }
        .sol-card-stat-v {
          font-size: 14px; font-weight: 700;
          background: var(--gradient-text);
          -webkit-background-clip: text; background-clip: text; color: transparent;
        }
        .sol-card-stat-l { font-size: 10px; color: var(--text-mute); letter-spacing: 0.04em; }
        .sol-card-cta {
          font-size: 11.5px; font-weight: 600; color: var(--purple-2);
          display: flex; align-items: center; gap: 4px;
          margin-top: 2px; position: relative; z-index: 1;
        }
        .sol-card-cta span { transition: transform .18s ease; }
        .sol-featured-card:hover .sol-card-cta span { transform: translateX(3px); }
        .sol-secondary-grid {
          display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
          padding: 16px; margin-top: 4px;
          background: var(--surface);
          border: 1px solid var(--line);
          border-radius: 14px;
        }
        .sol-secondary-cell {
          display: flex; align-items: center; justify-content: space-between;
          padding: 14px 16px; border-radius: 10px;
          background: var(--surface-2);
          border: 1px solid var(--line);
          transition: background .15s ease, border-color .15s ease, transform .15s ease;
          gap: 10px;
        }
        .sol-secondary-cell:hover { background: var(--ink-2); border-color: color-mix(in oklab, var(--purple-2) 40%, var(--line)); transform: translateY(-2px); }
        .sol-sec-name { font-size: 14px; font-weight: 700; color: var(--text); letter-spacing: -0.005em; }
        .sol-sec-desc { font-size: 12px; color: var(--text-dim); margin-top: 3px; line-height: 1.45; }
        .sol-sec-arr { color: var(--purple-2); font-size: 14px; transition: transform .15s ease; opacity: 0.7; }
        .sol-secondary-cell:hover .sol-sec-arr { opacity: 1; transform: translateX(3px); }
        @media (max-width: 1024px) {
          .sol-featured-grid { grid-template-columns: 1fr; }
          .sol-secondary-grid { grid-template-columns: repeat(2, 1fr); }
        }
      `}</style>
    </div>
  );
}

window.TopNav = TopNav;
window.NAV_PRODUCTS_LIST = NAV_PRODUCTS_LIST;
window.NAV_SOLUTIONS = NAV_SOLUTIONS;
