/* Sticky top navigation */
function Nav() {
  const [scrolled, setScrolled] = useState(false);
  const [open, setOpen] = useState(false);
  const isMobile = useWindowWidth() < 768;

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

  const links = [
    { label: 'Services', href: '/services.html' },
    { label: 'About', href: '/about.html' },
    { label: 'Blogs', href: '/blogs.html' },
    { label: 'Contact', href: '/contact.html' },
  ];

  return (
    <>
      {/* Mobile overlay menu */}
      {open && (
        <div className="mobile-menu">
          {links.map(l => (
            <a key={l.label} href={l.href} onClick={() => setOpen(false)}>{l.label}</a>
          ))}
          <a href="https://calendly.com/ecomlifters/30min" target="_blank" rel="noopener noreferrer" className="mobile-cta" onClick={() => setOpen(false)}>
            Book a call →
          </a>
        </div>
      )}

      <header
        data-screen-label="00 Nav"
        style={{
          position: 'fixed', top: 16, left: 0, right: 0, zIndex: 80,
          display: 'flex', justifyContent: 'center', pointerEvents: 'none',
        }}
      >
        <nav
          style={{
            pointerEvents: 'auto',
            display: 'flex', alignItems: 'center', gap: 8,
            padding: '8px 8px 8px 20px',
            background: scrolled ? 'rgba(11,20,16,0.92)' : 'var(--ink)',
            backdropFilter: 'blur(14px)',
            color: 'var(--bg)',
            borderRadius: 999,
            border: '1px solid rgba(255,255,255,0.08)',
            boxShadow: scrolled ? '0 16px 36px -18px rgba(10,15,12,.4)' : '0 4px 20px -8px rgba(10,15,12,.2)',
            transition: 'all .3s var(--ease)',
            minHeight: 52,
          }}
        >
          {/* Brand — real logo */}
          <a href="/" style={{ display: 'flex', alignItems: 'center', paddingRight: 16, borderRight: isMobile ? 'none' : '1px solid rgba(255,255,255,.08)' }}>
            <img src="/images/logo.png" alt="ecomlifters" style={{ height: 28, display: 'block' }} />
          </a>

          {/* Links — hide on mobile */}
          {!isMobile && (
            <ul style={{ display: 'flex', alignItems: 'center', gap: 4, listStyle: 'none', margin: 0, padding: '0 8px' }}>
              {links.map((l) => (
                <li key={l.label}>
                  <a
                    href={l.href}
                    style={{
                      display: 'inline-flex', alignItems: 'center', gap: 4,
                      padding: '8px 14px', fontSize: 14, color: 'rgba(255,255,255,.78)',
                      borderRadius: 999, transition: 'color .2s, background .2s',
                    }}
                    onMouseEnter={e => { e.currentTarget.style.color = 'white'; e.currentTarget.style.background = 'rgba(255,255,255,.05)'; }}
                    onMouseLeave={e => { e.currentTarget.style.color = 'rgba(255,255,255,.78)'; e.currentTarget.style.background = 'transparent'; }}
                  >
                    {l.label}
                  </a>
                </li>
              ))}
            </ul>
          )}

          {/* CTA — hide on mobile */}
          {!isMobile && (
            <a href="https://calendly.com/ecomlifters/30min" target="_blank" rel="noopener noreferrer" style={{
              display: 'inline-flex', alignItems: 'center', gap: 8,
              background: 'var(--green)', color: 'white',
              padding: '8px 8px 8px 16px', borderRadius: 999,
              fontWeight: 500, fontSize: 14,
              boxShadow: '0 10px 24px -8px rgba(15,191,97,.5)',
            }}>
              Book a call
              <span style={{ width: 26, height: 26, borderRadius: '50%', background: 'rgba(0,0,0,.25)', display: 'inline-flex', alignItems: 'center', justifyContent: 'center' }}>
                <Icon.Arrow size={11} />
              </span>
            </a>
          )}

          {/* Hamburger — show on mobile */}
          {isMobile && (
            <button
              onClick={() => setOpen(!open)}
              style={{
                background: 'rgba(255,255,255,.08)', color: 'white', fontSize: 17,
                width: 36, height: 36, border: 'none', borderRadius: '50%',
                display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
                marginLeft: 8, flexShrink: 0, lineHeight: 1, paddingTop: 0,
              }}
            >
              {open ? '✕' : '☰'}
            </button>
          )}
        </nav>
      </header>
    </>
  );
}

window.Nav = Nav;
