/* ============================================================
   Digital Odyssey, site chrome: TopNav · CtaBand · Footer
   ============================================================ */

const NAV = [
['Home', 'index.html', 'home'],
['Services', 'services.html', 'services'],
['Work', 'work.html', 'work'],
['About', 'about.html', 'about'],
['Contact', 'contact.html', 'contact']];


function TopNav({ active }) {
  const [open, setOpen] = React.useState(false);
  const [scrolled, setScrolled] = React.useState(false);
  const [narrow, setNarrow] = React.useState(false);
  React.useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 16);
    onScroll();window.addEventListener('scroll', onScroll, { passive: true });
    const mq = window.matchMedia('(max-width: 920px)');
    const fn = (e) => setNarrow(e.matches);fn(mq);mq.addEventListener('change', fn);
    return () => {window.removeEventListener('scroll', onScroll);mq.removeEventListener('change', fn);};
  }, []);
  React.useEffect(() => {document.body.style.overflow = open ? 'hidden' : '';}, [open]);

  return (
    <header style={{ position: 'sticky', top: 0, zIndex: 100 }}>
      <div style={{
        background: 'var(--nav-bg)', backdropFilter: 'blur(18px)', WebkitBackdropFilter: 'blur(18px)',
        borderBottom: `1px solid ${scrolled ? 'var(--nav-border)' : 'transparent'}`,
        transition: 'border-color .3s ease' }}>
        <Container style={{ height: 72, display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
          <Logo size={19} />
          {!narrow &&
          <nav style={{ display: 'flex', gap: 34, alignItems: 'center' }}>
              {NAV.map(([label, href, key]) =>
            <a key={key} href={href} className={`nav-link ${active === key ? 'active' : ''}`}>{label}</a>
            )}
            </nav>
          }
          {!narrow ?
          <div style={{ display: 'flex', alignItems: 'center', gap: 14 }}>
              <ThemeToggle />
              <Button href="contact.html" size="sm" variant="primary">Let's Talk Growth</Button>
            </div> :

          <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
              <ThemeToggle />
              <button onClick={() => setOpen((o) => !o)} aria-label="Menu"
            style={{ width: 44, height: 44, borderRadius: 9999, border: '1px solid var(--border)', background: 'var(--chip-bg)', color: 'var(--text)', cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
                <Icon name={open ? 'x' : 'menu'} size={22} color="currentColor" />
              </button>
            </div>
          }
        </Container>
      </div>

      {/* Mobile sheet */}
      {narrow &&
      <div style={{
        position: 'fixed', inset: '72px 0 0 0', zIndex: 99,
        background: 'var(--page-bg)', padding: '24px',
        transform: open ? 'translateY(0)' : 'translateY(-12px)',
        opacity: open ? 1 : 0, pointerEvents: open ? 'auto' : 'none',
        transition: 'opacity .25s ease, transform .25s ease',
        display: 'flex', flexDirection: 'column' }}>
          <nav style={{ display: 'flex', flexDirection: 'column' }}>
            {NAV.map(([label, href, key]) =>
          <a key={key} href={href} onClick={() => setOpen(false)}
          style={{ padding: '20px 4px', fontFamily: 'var(--font-display)', fontWeight: 500, fontSize: 28, letterSpacing: '-0.6px',
            color: active === key ? 'var(--text)' : 'var(--text-2)', borderBottom: '1px solid var(--border-soft)',
            display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
                {label}<Icon name="arrow-up-right" size={20} color={active === key ? 'var(--cyan)' : 'var(--text-3)'} />
              </a>
          )}
          </nav>
          <div style={{ marginTop: 32 }}>
            <Button href="contact.html" size="lg" variant="cyan" full icon="arrow-right">Book a discovery call</Button>
          </div>
        </div>
      }
    </header>);

}

/* ---------- Pre-footer CTA band (always dark) ---------- */
function CtaBand({ title = "Let's talk growth.", body = "Tell us where you want to go. We'll map the route, paid, social, content, search, and own the execution.", primary = "Book a discovery call", primaryHref = "contact.html", secondary = "See the results", secondaryHref = "work.html" }) {
  return (
    <section style={{ background: 'var(--navy-deep)', color: '#fff', position: 'relative', overflow: 'hidden' }}>
      <div className="grid-bg" style={{ position: 'absolute', inset: 0, opacity: .6 }}></div>
      <div style={{ position: 'absolute', width: 520, height: 520, borderRadius: '50%', background: 'radial-gradient(circle, rgba(26,224,230,.16), transparent 65%)', top: '-180px', right: '-120px' }}></div>
      <div style={{ position: 'absolute', width: 480, height: 480, borderRadius: '50%', background: 'radial-gradient(circle, rgba(0,82,255,.22), transparent 65%)', bottom: '-220px', left: '-100px' }}></div>

      <Container style={{ position: 'relative', padding: 'clamp(64px,8vw,104px) 16px', textAlign: 'center' }}>
        <div className="reveal" style={{ display: 'flex', justifyContent: 'center', marginBottom: 28 }}><LaunchMark size={64} /></div>
        <h2 className="reveal do-display-md" style={{ color: '#fff', margin: '0 auto 20px', maxWidth: 640 }}>{title}</h2>
        <p className="reveal do-body-lg" style={{ color: 'rgba(255,255,255,.7)', margin: '0 auto 36px', maxWidth: 520 }}>{body}</p>
        <div className="reveal cta-band-buttons" style={{ display: 'flex', gap: 14, justifyContent: 'center', flexWrap: 'wrap' }}>
          <Button href={primaryHref} size="lg" variant="cyan" icon="arrow-right">{primary}</Button>
          <Button href={secondaryHref} size="lg" variant="outline" style={{ color: '#fff', borderColor: 'rgba(255,255,255,.25)' }}>{secondary}</Button>
        </div>
      </Container>
    </section>);

}

/* ---------- Footer ---------- */
const FOOT_COLS = [
['Services', [['Performance Marketing', 'services.html'], ['AI Video Making', 'services.html'], ['AI Dashboards', 'services.html'], ['Web Design & Development', 'services.html'], ['Social Media Marketing', 'services.html'], ['Content Creation', 'services.html'], ['Graphic Design', 'services.html'], ['Video Making & Editing', 'services.html'], ['SEO', 'services.html'], ['Analytics & CRO', 'services.html']]],
['Company', [['About us', 'about.html'], ['Our work', 'work.html'], ['Careers', 'about.html'], ['Contact', 'contact.html']]],
['Resources', [['Growth Playbook', 'playbook.html'], ['Case studies', 'work.html'], ['FAQ', 'faq.html'], ['Book a call', 'contact.html']]]];

const SOCIALS = [['instagram', '#'], ['facebook', '#']];

function Footer() {
  const [email, setEmail] = React.useState('');
  const [sent, setSent] = React.useState(false);
  return (
    <footer style={{ background: 'var(--navy-deep)', color: '#fff', position: 'relative', overflow: 'hidden', borderTop: '1px solid rgba(255,255,255,.06)' }}>
      <Container style={{ padding: '72px 24px 40px' }}>
        <div style={{ display: 'grid', gridTemplateColumns: '1.5fr 1fr 1fr 1fr', gap: 40 }} className="foot-grid" >
          <div>
            <div style={{ display: 'flex', alignItems: 'center', gap: 11, marginBottom: 20 }}>
              <span style={{ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', background: '#fff', borderRadius: '9999px', padding: 6, lineHeight: 0, boxShadow: '0 2px 10px rgba(0,0,0,.25)' }}>
                <img src="assets/logo.png" alt="Digital Odyssey" width={34} height={34} style={{ display: 'block' }} />
              </span>
              <span style={{ fontFamily: 'var(--font-display)', fontWeight: 600, fontSize: 20, letterSpacing: '-0.6px' }}>Digital<span style={{ fontWeight: 300 }}> Odyssey</span></span>
            </div>
            <p style={{ fontFamily: 'var(--font-display)', fontWeight: 300, fontSize: 22, lineHeight: 1.25, letterSpacing: '-0.6px', color: '#fff', maxWidth: 300, margin: '0 0 24px' }}>Navigate growth.<br />Own your space.</p>
            <div style={{ marginBottom: 14, fontFamily: 'var(--font-sans)', fontSize: 13, color: 'rgba(255,255,255,.55)' }}>Monthly growth playbook, no fluff.</div>
            <form onSubmit={(e) => {e.preventDefault();if (email.includes('@')) setSent(true);}}
            style={{ display: 'flex', gap: 8, maxWidth: 320 }}>
              {sent ?
              <div style={{ display: 'flex', alignItems: 'center', gap: 8, color: 'var(--cyan)', fontSize: 14, fontWeight: 600 }}>
                  <Icon name="check-circle" size={18} color="var(--cyan)" /> You're subscribed.
                </div> :

              <>
                  <input value={email} onChange={(e) => setEmail(e.target.value)} type="email" placeholder="you@company.com"
                style={{ flex: 1, height: 44, borderRadius: 'var(--radius-pill)', border: '1px solid rgba(255,255,255,.16)', background: 'rgba(255,255,255,.04)', color: '#fff', padding: '0 18px', fontFamily: 'var(--font-sans)', fontSize: 14, outline: 'none' }} />
                  <button type="submit" style={{ width: 44, height: 44, flexShrink: 0, borderRadius: 9999, border: 'none', cursor: 'pointer', background: 'var(--grad-energy)', color: '#04122b', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
                    <Icon name="arrow-right" size={18} color="currentColor" />
                  </button>
                </>
              }
            </form>
          </div>
          {FOOT_COLS.map(([title, links]) =>
          <div key={title}>
              <div style={{ fontFamily: 'var(--font-sans)', fontWeight: 600, fontSize: 13, letterSpacing: '.08em', textTransform: 'uppercase', color: 'rgba(255,255,255,.5)', marginBottom: 18 }}>{title}</div>
              <ul style={{ listStyle: 'none', padding: 0, margin: 0, display: 'flex', flexDirection: 'column', gap: 13 }}>
                {links.map(([l, h]) =>
              <li key={l}><a href={h} style={{ fontFamily: 'var(--font-sans)', fontSize: 14.5, color: 'rgba(255,255,255,.75)' }} onMouseEnter={(e) => e.target.style.color = '#fff'} onMouseLeave={(e) => e.target.style.color = 'rgba(255,255,255,.75)'}>{l}</a></li>
              )}
              </ul>
            </div>
          )}
        </div>
        <div className="foot-bottom" style={{ borderTop: '1px solid rgba(255,255,255,.08)', marginTop: 56, paddingTop: 28, display: 'flex', justifyContent: 'space-between', alignItems: 'center', flexWrap: 'wrap', gap: 16 }}>
          <div style={{ display:'flex', alignItems:'center', gap:20, flexWrap:'wrap' }}>
            <span style={{ fontFamily: 'var(--font-sans)', fontSize: 13, color: 'rgba(255,255,255,.5)' }}>© 2026 Digital Odyssey. All rights reserved.</span>
            <a href="privacy.html" style={{ fontFamily:'var(--font-sans)', fontSize:13, color:'rgba(255,255,255,.6)' }} onMouseEnter={(e)=>e.target.style.color='#fff'} onMouseLeave={(e)=>e.target.style.color='rgba(255,255,255,.6)'}>Privacy Policy</a>
            <a href="terms.html" style={{ fontFamily:'var(--font-sans)', fontSize:13, color:'rgba(255,255,255,.6)' }} onMouseEnter={(e)=>e.target.style.color='#fff'} onMouseLeave={(e)=>e.target.style.color='rgba(255,255,255,.6)'}>Terms &amp; Conditions</a>
          </div>
          <div style={{ display: 'flex', gap: 10 }}>
            {SOCIALS.map(([n, h]) =>
            <a key={n} href={h} aria-label={n} style={{ width: 38, height: 38, borderRadius: 9999, border: '1px solid rgba(255,255,255,.14)', display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'rgba(255,255,255,.75)', transition: 'all .15s ease' }}
            onMouseEnter={(e) => {e.currentTarget.style.borderColor = 'var(--cyan)';e.currentTarget.style.color = 'var(--cyan)';}}
            onMouseLeave={(e) => {e.currentTarget.style.borderColor = 'rgba(255,255,255,.14)';e.currentTarget.style.color = 'rgba(255,255,255,.75)';}}>
                <Icon name={n} size={16} color="currentColor" />
              </a>
            )}
          </div>
        </div>
      </Container>
    </footer>);

}

Object.assign(window, { TopNav, CtaBand, Footer });