// Hero — pill nav + giant headline + product preview
// Passes pattern: floating pill nav top-center, eyebrow + huge headline w/ gradient accent,
// subhead, dual CTA (white pill + ghost), then a hero product visual

function PillNav() {
  const [scrolled, setScrolled] = React.useState(false);
  const [compact, setCompact] = React.useState(() => typeof window !== 'undefined' && window.innerWidth < 760);
  React.useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 24);
    const onResize = () => setCompact(window.innerWidth < 760);
    window.addEventListener('scroll', onScroll);
    window.addEventListener('resize', onResize);
    return () => {
      window.removeEventListener('scroll', onScroll);
      window.removeEventListener('resize', onResize);
    };
  }, []);

  return (
    <nav aria-label="Main navigation" style={{
      position: 'fixed', top: 16, left: '50%', transform: 'translateX(-50%)',
      zIndex: 50,
      display: 'flex', alignItems: 'center', gap: 8,
      padding: '8px 8px 8px 20px',
      borderRadius: 999,
      background: scrolled ? 'rgba(10,10,10,0.85)' : 'rgba(10,10,10,0.65)',
      backdropFilter: 'blur(18px)',
      WebkitBackdropFilter: 'blur(18px)',
      border: '1px solid rgba(255,255,255,0.08)',
      transition: 'background 220ms ease'
    }}>
      <a href="#home" style={{ display: 'flex', alignItems: 'center', gap: 10, paddingRight: compact ? 8 : 24, borderRight: compact ? 'none' : '1px solid rgba(255,255,255,0.08)', color: '#fff', textDecoration: 'none' }}>
        <div style={{
          width: 26, height: 26,
          display: 'flex', alignItems: 'center', justifyContent: 'center'
        }}>
          <BrandMark size={26} />
        </div>
        <span style={{ fontSize: 15, fontWeight: 600, letterSpacing: '-0.01em' }}>rellay</span>
      </a>
      {!compact && (
        <>
          <NavItem label="Product" href="#bento" />
          <NavItem label="Workflow" href="#streams" />
          <NavItem label="ROI" href="#calculator" />
          <NavItem label="Proof" href="#testimonials" />
        </>
      )}
      <a href="#cta" style={{
        marginLeft: 4,
        padding: '8px 18px', borderRadius: 999,
        background: '#fff', color: '#000', border: 'none',
        fontSize: 13.5, fontWeight: 600, cursor: 'pointer',
        letterSpacing: '-0.005em',
        textDecoration: 'none',
        whiteSpace: 'nowrap'
      }}>
        Get early access
      </a>
    </nav>);

}

function NavItem({ label, href }) {
  return (
    <a href={href} style={{
      display: 'flex', alignItems: 'center', gap: 4,
      padding: '8px 14px', background: 'transparent', border: 'none',
      color: 'rgba(255,255,255,0.75)', fontSize: 13.5, fontWeight: 500, cursor: 'pointer',
      fontFamily: 'inherit',
      textDecoration: 'none'
    }}>
      {label}
    </a>);

}

// Hero product preview — agent inbox card w/ live email reply being typed
function HeroPreview() {
  const [typed, setTyped] = React.useState('');
  const [compact, setCompact] = React.useState(() => typeof window !== 'undefined' && window.innerWidth < 720);
  const fullText = "Hi Marcus — circling on Maya Okafor's Brooklyn Steel show on Oct 18. We still need (1) hotel block confirmation for 4 rooms Oct 17–19, (2) the signed rider, and (3) the timetable. Deposit cleared yesterday. Can you have these to me by Friday?";

  React.useEffect(() => {
    const onResize = () => setCompact(window.innerWidth < 720);
    window.addEventListener('resize', onResize);
    return () => window.removeEventListener('resize', onResize);
  }, []);

  React.useEffect(() => {
    let i = 0;
    const id = setInterval(() => {
      i += 1;
      setTyped(fullText.slice(0, i));
      if (i >= fullText.length) clearInterval(id);
    }, 22);
    return () => clearInterval(id);
  }, []);

  return (
    <div style={{
      position: 'relative',
      width: '100%',
      maxWidth: 1080,
      margin: '0 auto',
      borderRadius: 24,
      overflow: 'hidden',
      background: '#0a0a0a',
      border: '1px solid rgba(255,255,255,0.08)',
      boxShadow: '0 40px 120px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.02)'
    }}>
      {/* App chrome */}
      <div style={{
        display: 'flex', alignItems: 'center', gap: 12,
        padding: '14px 20px',
        borderBottom: '1px solid rgba(255,255,255,0.06)',
        background: 'rgba(255,255,255,0.02)'
      }}>
        <div style={{ display: 'flex', gap: 6 }}>
          <div style={{ width: 11, height: 11, borderRadius: 999, background: '#3a3a3a' }} />
          <div style={{ width: 11, height: 11, borderRadius: 999, background: '#3a3a3a' }} />
          <div style={{ width: 11, height: 11, borderRadius: 999, background: '#3a3a3a' }} />
        </div>
        <div style={{ flex: 1, minWidth: 0, fontSize: 12, color: 'rgba(255,255,255,0.4)', fontFamily: 'JetBrains Mono, monospace', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
          rellay.app/shows/maya-okafor-brooklyn-steel
        </div>
        {!compact && <Pill tone="cyan">Agent active</Pill>}
      </div>

      {/* Two pane layout */}
      <div style={{ display: 'grid', gridTemplateColumns: compact ? '1fr' : '280px 1fr', minHeight: compact ? 0 : 520 }}>
        {/* Sidebar */}
        {!compact && <div style={{ borderRight: '1px solid rgba(255,255,255,0.06)', padding: '20px 14px', background: 'rgba(255,255,255,0.015)' }}>
          <div style={{ fontSize: 11, fontWeight: 600, color: 'rgba(255,255,255,0.4)', letterSpacing: '0.1em', textTransform: 'uppercase', padding: '4px 8px', marginBottom: 8 }}>
            Active shows
          </div>
          {[
          { name: 'Maya — Brooklyn Steel', role: 'Oct 18 · 78% ready', unread: 3, active: true },
          { name: 'Junot — Fonda LA', role: 'Oct 22 · 92% ready', unread: 0 },
          { name: 'Verandas — Pickathon', role: 'Oct 25 · at risk', unread: 2 },
          { name: 'Sable — Berghain', role: 'Nov 02 · 64% ready', unread: 1 },
          { name: 'Lior — Primavera', role: 'Jun 06 · advancing', unread: 0 }].
          map((a, i) =>
          <div key={i} style={{
            display: 'flex', alignItems: 'center', gap: 10,
            padding: '8px', borderRadius: 8,
            background: a.active ? 'rgba(56,189,248,0.08)' : 'transparent',
            border: a.active ? '1px solid var(--accent-line)' : '1px solid transparent',
            marginBottom: 2
          }}>
              <Avatar initials={a.name.split(' ').map((n) => n[0]).join('').slice(0, 2)} color={a.active ? 'var(--accent-deep)' : '#1f2937'} size={28} />
              <div style={{ flex: 1, minWidth: 0 }}>
                <div style={{ fontSize: 13, fontWeight: 500, color: '#fff', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{a.name}</div>
                <div style={{ fontSize: 11, color: 'rgba(255,255,255,0.4)' }}>{a.role}</div>
              </div>
              {a.unread > 0 &&
            <div style={{
              fontSize: 10, fontWeight: 600, padding: '2px 6px', borderRadius: 999,
              background: a.active ? 'var(--accent)' : 'rgba(255,255,255,0.1)',
              color: a.active ? '#000' : 'rgba(255,255,255,0.7)'
            }}>{a.unread}</div>
            }
            </div>
          )}
        </div>}

        {/* Main */}
        <div style={{ minWidth: 0, padding: compact ? '18px' : '24px 28px' }}>
          {/* Email being replied to */}
          <div style={{ marginBottom: 18 }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 10 }}>
              <Avatar initials="BS" color="#7c3aed" size={32} />
              <div style={{ flex: 1 }}>
                <div style={{ fontSize: 13, fontWeight: 600 }}>Marcus Bell <span style={{ color: 'rgba(255,255,255,0.4)', fontWeight: 400 }}>· Bowery / Brooklyn Steel</span></div>
                <div style={{ fontSize: 11, color: 'rgba(255,255,255,0.4)' }}>9 days to show · last reply 6 days ago</div>
              </div>
              {!compact && <div style={{ fontSize: 11, color: 'rgba(255,255,255,0.4)', fontFamily: 'JetBrains Mono, monospace' }}>thread · 14 msgs</div>}
            </div>
            <div style={{ fontSize: 13.5, lineHeight: 1.55, color: 'rgba(255,255,255,0.7)', paddingLeft: 40 }}>
              Last from Marcus: “Working on the hotel — should have it locked by EOW. Will send rider once production confirms the spec.” Outstanding: hotel block, signed rider, timetable.
            </div>
          </div>

          <div style={{ borderTop: '1px solid rgba(255,255,255,0.06)', margin: '18px 0' }} />

          {/* Agent reply being typed */}
          <div>
            <div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 12 }}>
              <div style={{
                width: 32, height: 32, borderRadius: 999,
                background: 'linear-gradient(135deg, var(--accent), var(--accent-deep))',
                display: 'flex', alignItems: 'center', justifyContent: 'center',
                boxShadow: '0 0 0 2px #000, 0 0 16px var(--accent-soft)'
              }}>
                <Icon name="sparkle" size={14} color="#000" />
              </div>
              <div style={{ flex: 1 }}>
                <div style={{ fontSize: 13, fontWeight: 600 }}>
                  Agent follow-up draft <span style={{ color: 'var(--accent)', fontWeight: 500 }}>· awaiting approval</span>
                </div>
                <div style={{ fontSize: 11, color: 'rgba(255,255,255,0.4)' }}>cited 4 prior threads + show packet · risk: hotel</div>
              </div>
              <Pill tone="success">3 actions queued</Pill>
            </div>
            <div style={{
              padding: 16, borderRadius: 12,
              background: 'rgba(56,189,248,0.04)',
              border: '1px solid var(--accent-line)',
              fontSize: 14, lineHeight: 1.6, color: '#fff',
              minHeight: 96
            }}>
              {typed}
              <span style={{
                display: 'inline-block', width: 8, height: 16, marginLeft: 2,
                background: 'var(--accent)', verticalAlign: 'text-bottom',
                animation: 'blink 1s step-start infinite'
              }} />
            </div>

            {/* Action chips */}
            <div style={{ display: 'flex', gap: 8, marginTop: 14, flexWrap: 'wrap' }}>
              <ActionChip icon="folder" label="Update show packet · 3 missing items" />
              <ActionChip icon="mail" label="Send to Marcus @ Bowery" />
              <ActionChip icon="calendar" label="Auto-chase Friday if no reply" />
            </div>

            <div style={{ display: 'flex', gap: 10, marginTop: 18, flexWrap: 'wrap' }}>
              <button style={{
                padding: '10px 18px', borderRadius: 8,
                background: '#fff', color: '#000', border: 'none',
                fontSize: 13, fontWeight: 600, cursor: 'pointer', fontFamily: 'inherit'
              }}>Approve & send</button>
              <button style={{
                padding: '10px 18px', borderRadius: 8,
                background: 'rgba(255,255,255,0.06)', color: '#fff',
                border: '1px solid rgba(255,255,255,0.1)',
                fontSize: 13, fontWeight: 500, cursor: 'pointer', fontFamily: 'inherit'
              }}>Edit draft</button>
              <button style={{
                padding: '10px 18px', borderRadius: 8,
                background: 'transparent', color: 'rgba(255,255,255,0.6)',
                border: '1px solid rgba(255,255,255,0.06)',
                fontSize: 13, fontWeight: 500, cursor: 'pointer', fontFamily: 'inherit',
                marginLeft: compact ? 0 : 'auto'
              }}>Snooze</button>
            </div>
          </div>
        </div>
      </div>

      <style>{`@keyframes blink { 50% { opacity: 0; } }`}</style>
    </div>);

}

function ActionChip({ icon, label }) {
  return (
    <div style={{
      display: 'inline-flex', alignItems: 'center', gap: 8,
      padding: '6px 12px 6px 8px', borderRadius: 999,
      background: 'rgba(255,255,255,0.04)',
      border: '1px solid rgba(255,255,255,0.08)',
      fontSize: 12, color: 'rgba(255,255,255,0.8)'
    }}>
      <div style={{
        width: 18, height: 18, borderRadius: 999,
        background: 'var(--accent-soft)',
        display: 'flex', alignItems: 'center', justifyContent: 'center',
        color: 'var(--accent)'
      }}>
        <Icon name={icon} size={11} />
      </div>
      {label}
    </div>);

}

function Hero() {
  return (
    <section id="home" data-screen-label="01 Hero" style={{
      position: 'relative',
      paddingTop: 160, paddingBottom: 100,
      overflow: 'hidden'
    }}>
      <GuideRails />

      {/* Ambient cyan glow behind hero */}
      <div style={{
        position: 'absolute', top: -200, left: '50%', transform: 'translateX(-50%)',
        width: 'min(1100px, 100vw)', height: 600,
        background: 'radial-gradient(ellipse at center, var(--accent-soft) 0%, transparent 60%)',
        pointerEvents: 'none', filter: 'blur(40px)'
      }} />

      <div style={{ position: 'relative', maxWidth: 1280, margin: '0 auto', padding: '0 24px' }}>
        <div style={{ textAlign: 'center', maxWidth: 920, margin: '0 auto 56px' }}>
          <div style={{
            display: 'inline-flex', alignItems: 'center', gap: 8,
            padding: '6px 14px 6px 6px', borderRadius: 999,
            background: 'rgba(255,255,255,0.04)',
            border: '1px solid rgba(255,255,255,0.08)',
            fontSize: 12, color: 'rgba(255,255,255,0.7)',
            marginBottom: 32
          }}>
            <span style={{
              padding: '2px 8px', borderRadius: 999,
              background: 'var(--accent)', color: '#000',
              fontWeight: 600, fontSize: 11
            }}>NEW</span>
            Now in private beta with 12 agencies
          </div>

          <h1 style={{
            fontFamily: 'var(--font-display)',
            fontSize: 'clamp(56px, 8vw, 104px)',
            fontWeight: 500,
            lineHeight: 0.98,
            letterSpacing: 0,
            margin: 0,
            color: '#fff'
          }}>
            The AI Agent<br />
            <span style={{
              background: 'linear-gradient(180deg, var(--accent) 0%, var(--accent-deep) 100%)',
              WebkitBackgroundClip: 'text',
              WebkitTextFillColor: 'transparent',
              backgroundClip: 'text'
            }}>for agencies.</span>
          </h1>

          <p style={{
            fontSize: 19, lineHeight: 1.5,
            color: 'rgba(255,255,255,0.6)',
            maxWidth: 600, margin: '28px auto 0'
          }}>
            Connect Gmail and your active shows. The agent chases missing logistics, updates every show packet, drafts promoter follow-ups, prepares travel options, and generates artist itineraries — across every tool the agency already uses.
          </p>

          <div style={{ display: 'flex', gap: 12, justifyContent: 'center', marginTop: 36 }}>
            <button style={{
              padding: '14px 24px', borderRadius: 999,
              background: '#fff', color: '#000', border: 'none',
              fontSize: 14.5, fontWeight: 600, cursor: 'pointer', fontFamily: 'inherit',
              letterSpacing: '-0.005em'
            }}>Get early access</button>
            <button style={{
              padding: '14px 24px', borderRadius: 999,
              background: 'transparent', color: '#fff',
              border: '1px solid rgba(255,255,255,0.15)',
              fontSize: 14.5, fontWeight: 500, cursor: 'pointer', fontFamily: 'inherit',
              display: 'inline-flex', alignItems: 'center', gap: 8
            }}>
              <Icon name="play" size={12} /> See it work
            </button>
          </div>

          {/* Trust bar */}
          <div style={{
            marginTop: 56,
            display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 40,
            color: 'rgba(255,255,255,0.35)',
            fontSize: 12, fontWeight: 500, letterSpacing: '0.08em', textTransform: 'uppercase',
            flexWrap: 'wrap'
          }}>
            <span>Trusted at</span>
            {['Wasserman', 'WME', 'CAA', 'Paradigm', 'UTA', 'Primary Talent'].map((n) =>
            <span key={n} style={{ fontFamily: 'JetBrains Mono, monospace' }}>{n}</span>
            )}
          </div>
        </div>

        <HeroPreview />
      </div>
    </section>);

}

Object.assign(window, { PillNav, Hero });
