// Header.jsx — Full-bleed editorial mega-menu
function Header({ onBook }) {
  const [scrolled, setScrolled] = React.useState(false);
  const [menuOpen, setMenuOpen] = React.useState(false);
  const [activeCat, setActiveCat] = React.useState(0);
  const [vw, setVw] = React.useState(typeof window !== 'undefined' ? window.innerWidth : 1440);

  // Utility-link icons: socials get glyphs, shops get a chevron
  const utilityIcon = (label) => {
    const props = { width: 14, height: 14, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round', strokeLinejoin: 'round' };
    if (label === 'Instagram') return (
      <svg {...props}><rect x="3" y="3" width="18" height="18" rx="5"/><circle cx="12" cy="12" r="4"/><circle cx="17.5" cy="6.5" r="0.6" fill="currentColor" stroke="none"/></svg>
    );
    if (label === 'Google Reviews') return (
      <svg {...props}><path d="M12 2.5l2.6 6 6.4.6-4.9 4.3 1.5 6.3L12 16.4l-5.6 3.3 1.5-6.3-4.9-4.3 6.4-.6z"/></svg>
    );
    if (label === 'Facebook') return (
      <svg {...props}><path d="M18 2h-3a5 5 0 0 0-5 5v3H7v4h3v8h4v-8h3l1-4h-4V7a1 1 0 0 1 1-1h3z"/></svg>
    );
    if (label === 'TikTok') return (
      <svg {...props}><path d="M9 12.5a4 4 0 1 0 4 4V4.5a5.5 5.5 0 0 0 5.5 5.5"/></svg>
    );
    // shop links: arrow
    return (
      <svg {...props}><path d="M5 12h14M13 6l6 6-6 6"/></svg>
    );
  };


  React.useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 24);
    const onResize = () => setVw(window.innerWidth);
    window.addEventListener('scroll', onScroll);
    window.addEventListener('resize', onResize);
    return () => { window.removeEventListener('scroll', onScroll); window.removeEventListener('resize', onResize); };
  }, []);

  React.useEffect(() => {
    const onKey = (e) => { if (e.key === 'Escape') setMenuOpen(false); };
    window.addEventListener('keydown', onKey);
    return () => { window.removeEventListener('keydown', onKey); };
  }, [menuOpen]);
  if (typeof window !== 'undefined' && window.useScrollLock) {
    window.useScrollLock(menuOpen);
  }

  const isMobile = vw < 820;
  const [mobileDetail, setMobileDetail] = React.useState(false);

  // Reset mobile drawer state when menu closes
  React.useEffect(() => { if (!menuOpen) setMobileDetail(false); }, [menuOpen]);

  const categories = [
    {
      label: 'Face',
      num: '01',
      tag: 'Skin · Injectables · Laser',
      lede: 'From first injectables to advanced resurfacing — treatments tuned to your skin, not a trend.',
      items: [
        { n: 'Botox & Neuromodulators', d: 'Micro-dosed relaxation for lines' },
        { n: 'Dermal Fillers', d: 'Juvederm, Radiesse · restoration & contour' },
        { n: 'Sylfirm X', d: 'RF microneedling · 12 benefits' },
        { n: 'MOXI', d: 'Gentle laser · low-downtime glow' },
        { n: 'BBL Hero', d: 'BroadBand Light · tone & pigment' },
        { n: 'Skinvive', d: 'Injectable hydrator · microdroplet' },
        { n: 'Skin Care', d: 'Medical-grade products & peels' },
      ],
      accent: 'linear-gradient(135deg, #F7EDE1 0%, #E7C9A0 100%)',
    },
    {
      label: 'Body',
      num: '02',
      tag: 'Contour · Hair · Wellness',
      lede: 'Refinement, not transformation. Sculpting and regenerative care grounded in evidence.',
      items: [
        { n: 'CoolSculpting Elite', d: 'Non-invasive fat reduction' },
        { n: 'BBL Heroic', d: 'BroadBand Light for body' },
        { n: 'Body Sculpting', d: 'NuEra Tight · RF contouring' },
        { n: 'Weight Loss', d: 'Medically supervised programs' },
        { n: 'IV Drips', d: 'Hydration & recovery protocols' },
        { n: 'PRP Hair Restoration', d: 'Regenerative follicle support' },
        { n: 'Laser Hair Removal', d: 'Full-body smoothing' },
        { n: 'Vein Therapy', d: 'Spider & reticular veins' },
      ],
      accent: 'linear-gradient(135deg, #EBDCEA 0%, #C4A0EF 100%)',
    },
    {
      label: 'Membership',
      num: '03',
      tag: 'Annual savings',
      lede: 'Two annual tiers built around how often you visit. Renew unlocks core injectable savings. Reviv goes deeper — across face, body, skin, and the Renewal Rituals.',
      groups: [
        {
          title: 'Compare tiers',
          sub: 'Annual',
          items: [
            { n: 'Renew · $99 / year', d: '20–30% off neurotoxin · core perks' },
            { n: 'Reviv · $299 / year', d: 'Deeper savings · 12 categories included' },
            { n: 'Member benefits in full', d: 'Side-by-side comparison' },
            { n: 'Gift a Membership', d: 'Digital gift cards' },
          ],
        },
        {
          title: 'What members save on',
          sub: 'Highlights',
          items: [
            { n: 'Neurotoxin', d: '20–30% off both tiers' },
            { n: 'Filler', d: '10% off · Reviv tier' },
            { n: 'CoolSculpting Elite', d: '20–25% off · Reviv tier' },
            { n: 'Sylfirm X RF', d: 'Included for both tiers' },
            { n: 'SkinMedica skincare', d: '25% off · Reviv tier' },
          ],
        },
      ],
      items: [
        { n: 'Compare Membership', d: 'Renew vs Reviv side-by-side' },
        { n: 'Renew · $99 / year', d: 'Core injectable savings' },
        { n: 'Reviv · $299 / year', d: 'Full menu savings' },
        { n: 'Member benefits in full', d: 'See the comparison table' },
        { n: 'Gift a Membership', d: 'Digital gift cards' },
      ],
      accent: 'linear-gradient(135deg, #3E1F6B 0%, #9F65E6 100%)',
      dark: true,
    },
    {
      label: 'Featured',
      num: '04',
      tag: 'Signature technology',
      lede: 'The devices and modalities we believe in — each selected for a reason we can explain.',
      items: [
        { n: 'Sylfirm X', d: 'RF microneedling' },
        { n: 'Exosomes', d: 'Regenerative signaling' },
        { n: 'MOXI', d: 'Gentle laser resurfacing' },
        { n: 'CoolSculpting Elite', d: 'Non-invasive contouring' },
        { n: 'BBL Hero / Heroic', d: 'Broadband light' },
        { n: 'Skinvive', d: 'Microdroplet hydrator' },
      ],
      accent: 'linear-gradient(135deg, #1A1625 0%, #6B3BB8 100%)',
      dark: true,
    },
    {
      label: 'Practice',
      num: '05',
      tag: 'The team · The space',
      lede: 'A multidisciplinary team of physicians, nurses, aestheticians, and wellness specialists.',
      items: [
        { n: 'About Reviv', d: 'Philosophy & approach' },
        { n: 'Our Team', d: 'Providers & credentials' },
        { n: 'The Space', d: 'Visiting Millbrae' },
        { n: 'Gallery', d: 'Before & after case studies' },
        { n: 'Contact', d: '(650) 697-3339 · hello@reviv.com' },
        { n: 'Careers', d: 'Now hiring · 4 roles' },
      ],
      accent: 'linear-gradient(135deg, #F5F1FA 0%, #E7E0EF 100%)',
    },
  ];

  const cat = categories[activeCat];

  return (
    <>
    <header style={{
      position: 'fixed', top: 0, left: 0, right: 0, zIndex: 50,
      background: scrolled || menuOpen ? 'rgba(255,255,255,0.95)' : 'rgba(255,255,255,0.55)',
      backdropFilter: 'blur(20px)', WebkitBackdropFilter: 'blur(20px)',
      borderBottom: `1px solid ${scrolled ? 'rgba(26,22,37,0.08)' : 'transparent'}`,
      transition: 'all 300ms var(--rv-ease)',
    }}>
      <div style={{
        maxWidth: 1440, margin: '0 auto', padding: isMobile ? '0 20px' : '0 40px', height: 84,
        display: 'grid', gridTemplateColumns: '1fr auto 1fr', alignItems: 'center', gap: 16,
      }}>
        {/* Left: Menu trigger */}
        <div style={{ display: 'flex', alignItems: 'center', gap: 22 }}>
          <button onClick={() => setMenuOpen(v => !v)} style={{
            background: 'none', border: 0, cursor: 'pointer', padding: 0,
            display: 'inline-flex', alignItems: 'center', gap: 14,
            fontSize: 12, letterSpacing: '0.22em', textTransform: 'uppercase',
            color: 'var(--rv-ink)', fontWeight: 500, fontFamily: 'inherit',
          }}>
            <span style={{
              position: 'relative', display: 'inline-block', width: 28, height: 14,
            }}>
              <span style={{
                position: 'absolute', left: 0, top: 3, width: 28, height: 1.5,
                background: menuOpen ? 'var(--rv-purple)' : 'var(--rv-ink)',
                transition: 'transform 300ms var(--rv-ease), background 240ms var(--rv-ease)',
                transform: menuOpen ? 'translateY(4px) rotate(45deg)' : 'none',
              }}></span>
              <span style={{
                position: 'absolute', left: 0, top: 10, width: 20, height: 1.5,
                background: menuOpen ? 'var(--rv-purple)' : 'var(--rv-ink)',
                transition: 'transform 300ms var(--rv-ease), width 300ms, background 240ms var(--rv-ease)',
                transform: menuOpen ? 'translateY(-3px) rotate(-45deg)' : 'none',
                width: menuOpen ? 28 : 20,
              }}></span>
            </span>
            {!isMobile && <span style={{ color: menuOpen ? 'var(--rv-purple)' : 'var(--rv-ink)', transition: 'color 240ms var(--rv-ease)' }}>{menuOpen ? 'Close' : 'Menu'}</span>}
          </button>
          {!isMobile && (
            <a href="tel:6506973339" style={{
              fontSize: 12, letterSpacing: '0.18em', textTransform: 'uppercase',
              color: 'var(--rv-muted)', fontWeight: 500, marginLeft: 16,
            }}>(650) 697-3339</a>
          )}
        </div>

        {/* Center: logo */}
        <a href="#top" aria-label="Reviv Med Spa home" style={{ justifySelf: 'center' }}>
          <img src="assets/logo-lockup.png" alt="Reviv Med Spa" width="180" height="52" style={{ height: isMobile ? 40 : 52, display: 'block', width: 'auto' }} />
        </a>

        {/* Right: Book */}
        <div style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center', gap: 18 }}>
          {!isMobile && (
            <span style={{ fontSize: 12, color: 'var(--rv-muted)', letterSpacing: '0.14em', textTransform: 'uppercase' }}>Millbrae, CA</span>
          )}
          <a
            href="Booking.html"
            onClick={onBook ? (e) => { e.preventDefault(); onBook(); } : undefined}
            style={{
            background: 'var(--rv-ink)', color: 'white', border: 0,
            padding: isMobile ? '12px 16px' : '14px 22px',
            fontSize: 12, letterSpacing: '0.18em', textTransform: 'uppercase',
            fontWeight: 500, cursor: 'pointer', transition: 'background 200ms',
            textDecoration: 'none', display: 'inline-block',
          }}
            onMouseEnter={e => e.currentTarget.style.background = 'var(--rv-purple-700)'}
            onMouseLeave={e => e.currentTarget.style.background = 'var(--rv-ink)'}
          >Book {isMobile ? '' : 'Consult'}</a>
        </div>
      </div>
    </header>

    {/* Mega-menu overlay */}
    <div style={{
      position: 'fixed', inset: 0, zIndex: 40, pointerEvents: menuOpen ? 'auto' : 'none',
      background: menuOpen ? 'rgba(255,255,255,1)' : 'rgba(255,255,255,0)',
      transition: 'background 400ms var(--rv-ease)',
      opacity: menuOpen ? 1 : 0,
    }}>
      {menuOpen && (
        <div style={{
          position: 'absolute', inset: 0, paddingTop: 84, overflow: 'auto',
        }}>
          {/* Ambient ghost wordmark */}
          <div aria-hidden="true" className="rv-futura" style={{
            position: 'absolute', bottom: '-6vw', left: '-4vw', right: '-4vw',
            fontSize: 'clamp(200px, 28vw, 440px)', fontWeight: 300,
            color: 'var(--rv-purple-050)', pointerEvents: 'none', userSelect: 'none',
            lineHeight: 0.82, letterSpacing: '-0.04em', zIndex: 0, whiteSpace: 'nowrap',
            textTransform: 'lowercase',
          }}>reviv</div>

          {/* MOBILE: two-pane slider (category list ↔ detail) */}
          {isMobile && (
            <div style={{
              position: 'relative', zIndex: 1, overflow: 'hidden',
              minHeight: 'calc(100dvh - 84px)',
            }}>
              <div style={{
                display: 'flex', width: '200%',
                transform: mobileDetail ? 'translateX(-50%)' : 'translateX(0)',
                transition: 'transform 420ms var(--rv-ease)',
              }}>
                {/* Pane 1: category list */}
                <div style={{ width: '50%', padding: '32px 20px 40px' }}>
                  <div className="rv-eyebrow" style={{ marginBottom: 24, color: 'var(--rv-purple-700)' }}>
                    <span style={{ display: 'inline-block', width: 20, height: 1, background: 'var(--rv-purple)', verticalAlign: 'middle', marginRight: 10 }}></span>
                    Explore
                  </div>
                  <div>
                    {categories.map((c, i) => (
                      <button key={i}
                        onClick={() => { setActiveCat(i); setMobileDetail(true); }}
                        style={{
                          display: 'grid', gridTemplateColumns: 'auto 1fr auto', alignItems: 'baseline',
                          width: '100%', textAlign: 'left', background: 'none', border: 0,
                          padding: '20px 0', cursor: 'pointer', fontFamily: 'inherit',
                          borderBottom: '1px solid var(--rv-border)', gap: 16,
                        }}>
                        <span style={{ fontSize: 11, color: 'var(--rv-purple)', letterSpacing: '0.18em' }}>{c.num}</span>
                        <span className="rv-futura" style={{
                          fontSize: 40, fontWeight: 300, color: 'var(--rv-ink)',
                          lineHeight: 1, letterSpacing: '-0.01em',
                        }}>{c.label}</span>
                        <span style={{ fontSize: 18, color: 'var(--rv-purple)', justifySelf: 'end' }}>→</span>
                      </button>
                    ))}
                  </div>

                  {/* Contact block */}
                  <div style={{ marginTop: 40, paddingTop: 28, borderTop: '1px solid var(--rv-border)' }}>
                    {[
                      ['Call', '(650) 697-3339'],
                      ['Visit', '31 S. El Camino Real · Millbrae'],
                      ['Hours', 'Tue–Fri 10–6 · Sat 10–3'],
                    ].map(([l, v], i) => (
                      <div key={i} style={{ marginBottom: 18 }}>
                        <div style={{ fontSize: 10, letterSpacing: '0.24em', textTransform: 'uppercase', color: 'var(--rv-purple-700)', fontWeight: 500, marginBottom: 4 }}>{l}</div>
                        <div style={{ fontSize: 15, color: 'var(--rv-ink)' }}>{v}</div>
                      </div>
                    ))}
                  </div>

                  <div style={{ marginTop: 28, display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 14 }}>
                    {['Instagram', 'Google Reviews', 'Shop SkinMedica', 'Shop Supplements'].map(s => (
                      <a key={s} href="#" className="rv-social-row" style={{ fontSize: 11 }}>
                        <span className="rv-social-link rv-social-link--sm" aria-hidden="true">
                          {utilityIcon(s.replace(/^Shop /, ''))}
                        </span>
                        {s}
                      </a>
                    ))}
                  </div>
                </div>

                {/* Pane 2: category detail */}
                <div style={{ width: '50%', padding: '24px 20px 40px' }}>
                  <button onClick={() => setMobileDetail(false)} style={{
                    background: 'none', border: 0, padding: '8px 0', cursor: 'pointer',
                    fontFamily: 'inherit', fontSize: 11, letterSpacing: '0.22em',
                    textTransform: 'uppercase', color: 'var(--rv-ink)', fontWeight: 500,
                    display: 'inline-flex', alignItems: 'center', gap: 10, marginBottom: 24,
                  }}>
                    <span style={{
                      width: 28, height: 28, border: '1px solid var(--rv-ink)', borderRadius: '50%',
                      display: 'inline-flex', alignItems: 'center', justifyContent: 'center', fontSize: 13,
                    }}>←</span>
                    All Categories
                  </button>

                  {/* Feature tile — full width on mobile, moves to top */}
                  <div style={{
                    position: 'relative', aspectRatio: '16/10',
                    background: cat.accent, overflow: 'hidden',
                    color: cat.dark ? 'white' : 'var(--rv-ink)',
                    padding: 22, marginBottom: 28,
                    display: 'flex', flexDirection: 'column', justifyContent: 'space-between',
                  }}>
                    <svg viewBox="0 0 400 250" preserveAspectRatio="none" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', opacity: 0.18 }}>
                      {Array.from({length: 5}).map((_, k) => (
                        <line key={k} x1={k*100} y1="0" x2={k*100} y2="250" stroke={cat.dark ? 'white' : 'currentColor'} strokeWidth="0.5"/>
                      ))}
                    </svg>
                    <svg viewBox="0 0 400 250" preserveAspectRatio="none" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
                      <path d="M 120 250 L 120 130 Q 120 60 200 60 Q 280 60 280 130 L 280 250 Z"
                        fill="none" stroke={cat.dark ? 'rgba(255,255,255,0.28)' : 'rgba(26,22,37,0.22)'} strokeWidth="1"/>
                    </svg>
                    <img src="assets/dragonfly-real.png" alt="" loading="lazy" decoding="async" width="110" height="148" style={{
                      position: 'absolute', right: -10, bottom: -12, width: 110, height: 'auto',
                      opacity: cat.dark ? 0.5 : 0.35,
                      filter: cat.dark ? 'brightness(0) invert(1)' : 'none',
                    }}/>
                    <div style={{ position: 'relative' }}>
                      <div style={{ fontSize: 10, letterSpacing: '0.24em', textTransform: 'uppercase', opacity: 0.78, marginBottom: 10 }}>
                        {cat.num} · {cat.label}
                      </div>
                      <div className="rv-futura" style={{ fontSize: 30, fontWeight: 300, lineHeight: 1, letterSpacing: '-0.01em' }}>
                        {cat.label}
                      </div>
                    </div>
                    <div style={{ position: 'relative', fontSize: 11, letterSpacing: '0.18em', textTransform: 'uppercase', opacity: 0.8 }}>
                      {cat.tag}
                    </div>
                  </div>

                  <h3 className="rv-futura" style={{
                    fontSize: 22, fontWeight: 300, color: 'var(--rv-ink)',
                    margin: '0 0 24px', lineHeight: 1.3, letterSpacing: '-0.005em',
                  }}>{cat.lede}</h3>

                  {/* Items list */}
                  {cat.groups ? (
                    <div style={{ display: 'grid', gap: 24 }}>
                      {cat.groups.map((g, gi) => (
                        <div key={gi}>
                          <div style={{
                            display: 'flex', alignItems: 'baseline', justifyContent: 'space-between',
                            paddingBottom: 8, marginBottom: 2,
                            borderBottom: '1px solid var(--rv-border)',
                          }}>
                            <span className="rv-futura" style={{
                              fontSize: 20, fontWeight: 300, color: 'var(--rv-ink)',
                              letterSpacing: '-0.005em', lineHeight: 1,
                            }}>{g.title}</span>
                            <span style={{
                              fontSize: 9, letterSpacing: '0.2em', textTransform: 'uppercase',
                              color: 'var(--rv-purple-700)', fontWeight: 500,
                            }}>{g.sub}</span>
                          </div>
                          {g.items.map((it, ii) => (
                            <a key={ii} href="#" style={{
                              display: 'grid', gridTemplateColumns: 'auto 1fr auto', alignItems: 'center',
                              padding: '14px 0', gap: 14,
                              borderBottom: '1px solid var(--rv-border)',
                              textDecoration: 'none',
                            }}>
                              <span style={{ fontSize: 10, color: 'var(--rv-muted)', letterSpacing: '0.14em' }}>
                                {String(ii+1).padStart(2,'0')}
                              </span>
                              <span>
                                <div style={{ fontSize: 15, fontWeight: 500, color: 'var(--rv-ink)', marginBottom: 2 }}>{it.n}</div>
                                <div style={{ fontSize: 12, color: 'var(--rv-muted)' }}>{it.d}</div>
                              </span>
                              <span style={{ fontSize: 16, color: 'var(--rv-purple)' }}>→</span>
                            </a>
                          ))}
                        </div>
                      ))}
                    </div>
                  ) : (
                    <div style={{ borderTop: '1px solid var(--rv-border)' }}>
                      {cat.items.map((it, ii) => (
                        <a key={ii} href="#" style={{
                          display: 'grid', gridTemplateColumns: 'auto 1fr auto', alignItems: 'center',
                          padding: '16px 0', gap: 14,
                          borderBottom: '1px solid var(--rv-border)',
                          textDecoration: 'none',
                        }}>
                          <span style={{ fontSize: 10, color: 'var(--rv-muted)', letterSpacing: '0.14em' }}>
                            {String(ii+1).padStart(2,'0')}
                          </span>
                          <span>
                            <div style={{ fontSize: 16, fontWeight: 500, color: 'var(--rv-ink)', marginBottom: 2 }}>{it.n}</div>
                            <div style={{ fontSize: 12, color: 'var(--rv-muted)' }}>{it.d}</div>
                          </span>
                          <span style={{ fontSize: 16, color: 'var(--rv-purple)' }}>→</span>
                        </a>
                      ))}
                    </div>
                  )}

                  <button style={{
                    marginTop: 28, width: '100%',
                    background: 'var(--rv-ink)', color: 'white', border: 0,
                    padding: '18px 22px', fontSize: 12, letterSpacing: '0.18em',
                    textTransform: 'uppercase', fontWeight: 500, cursor: 'pointer',
                  }}>Book a Consultation →</button>
                </div>
              </div>

              {/* Pane indicator */}
              <div style={{
                position: 'sticky', bottom: 20, left: 0, right: 0,
                display: 'flex', justifyContent: 'center', gap: 6, pointerEvents: 'none',
                marginTop: 20,
              }}>
                <span style={{ width: mobileDetail ? 6 : 20, height: 4, background: mobileDetail ? 'var(--rv-border)' : 'var(--rv-purple)', transition: 'all 300ms var(--rv-ease)', borderRadius: 2 }}></span>
                <span style={{ width: mobileDetail ? 20 : 6, height: 4, background: mobileDetail ? 'var(--rv-purple)' : 'var(--rv-border)', transition: 'all 300ms var(--rv-ease)', borderRadius: 2 }}></span>
              </div>
            </div>
          )}

          {/* DESKTOP grid — unchanged */}
          {!isMobile && (
          <div style={{
            position: 'relative', zIndex: 1,
            maxWidth: 1440, margin: '0 auto', padding: '56px 40px 80px',
            display: 'grid',
            gridTemplateColumns: '1fr 1.4fr',
            gap: 72,
          }}>
            {/* Left: category list */}
            <div style={{ display: 'flex', flexDirection: 'column' }}>
              <div className="rv-eyebrow" style={{ marginBottom: 32, color: 'var(--rv-purple-700)' }}>
                <span style={{ display: 'inline-block', width: 20, height: 1, background: 'var(--rv-purple)', verticalAlign: 'middle', marginRight: 10 }}></span>
                Explore
              </div>
              <div>
                {categories.map((c, i) => (
                  <button key={i}
                    onMouseEnter={() => !isMobile && setActiveCat(i)}
                    onClick={() => setActiveCat(i)}
                    style={{
                      display: 'grid', gridTemplateColumns: 'auto 1fr auto', alignItems: 'baseline',
                      width: '100%', textAlign: 'left', background: 'none', border: 0,
                      padding: '18px 0', cursor: 'pointer', fontFamily: 'inherit',
                      borderBottom: '1px solid var(--rv-border)', gap: 18,
                      opacity: activeCat === i ? 1 : 0.4,
                      transition: 'opacity 300ms var(--rv-ease)',
                    }}>
                    <span style={{ fontSize: 11, color: 'var(--rv-purple)', letterSpacing: '0.18em' }}>{c.num}</span>
                    <span className="rv-futura" style={{
                      fontSize: 'clamp(32px, 4.8vw, 64px)', fontWeight: 300,
                      color: 'var(--rv-ink)', lineHeight: 1, letterSpacing: '-0.01em',
                      display: 'flex', alignItems: 'baseline', gap: 14,
                      textTransform: 'none',
                    }}>
                      {c.label}
                      {activeCat === i && (
                        <img src="assets/dragonfly-real.png" alt="" loading="lazy" decoding="async" width="14" height="20" style={{ width: 14, height: 20, opacity: 0.7 }}/>
                      )}
                    </span>
                    <span style={{ fontSize: 11, letterSpacing: '0.18em', textTransform: 'uppercase', color: 'var(--rv-muted)', whiteSpace: 'nowrap', justifySelf: 'end' }}>
                      {activeCat === i ? '→' : String(c.items.length).padStart(2,'0')}
                    </span>
                  </button>
                ))}
              </div>

              {/* Utility links */}
              <div style={{
                marginTop: 48, paddingTop: 0,
                display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 18,
              }}>
                {['Instagram', 'Google Reviews', 'Shop SkinMedica', 'Shop Supplements'].map(s => (
                  <a key={s} href="#" className="rv-social-row">
                    <span className="rv-social-link rv-social-link--sm" aria-hidden="true">
                      {utilityIcon(s.replace(/^Shop /, ''))}
                    </span>
                    {s}
                  </a>
                ))}
              </div>
            </div>

            {/* Right: category detail */}
            <div key={activeCat} style={{
              position: 'relative',
              display: 'grid', gridTemplateRows: 'auto 1fr auto', gap: 24,
              animation: 'rv-panel-in 500ms var(--rv-ease)',
            }}>
              {/* Panel header */}
              <div>
                <div style={{ display: 'inline-flex', alignItems: 'center', gap: 14, fontSize: 11, letterSpacing: '0.22em', textTransform: 'uppercase', color: 'var(--rv-purple-700)', fontWeight: 500, marginBottom: 16 }}>
                  <span style={{ display: 'inline-block', width: 20, height: 1, background: 'var(--rv-purple)' }}></span>
                  {cat.tag}
                </div>
                <h3 className="rv-futura" style={{
                  fontSize: 'clamp(26px, 2.4vw, 34px)', fontWeight: 300,
                  color: 'var(--rv-ink)', margin: 0, lineHeight: 1.25,
                  maxWidth: 620, letterSpacing: '-0.005em',
                }}>
                  {cat.lede}
                </h3>
              </div>

              {/* Panel body — treatment list + feature tile */}
              <div style={{
                display: 'grid',
                gridTemplateColumns: isMobile ? '1fr' : '1.3fr 1fr',
                gap: isMobile ? 24 : 48, alignItems: 'start',
              }}>
                {/* Item list — grouped if cat.groups present, else flat */}
                {cat.groups ? (
                  <div style={{ display: 'grid', gap: 28 }}>
                    {cat.groups.map((g, gi) => (
                      <div key={gi}>
                        <div style={{
                          display: 'flex', alignItems: 'baseline', justifyContent: 'space-between',
                          paddingBottom: 10, marginBottom: 2,
                          borderBottom: '1px solid var(--rv-border)',
                        }}>
                          <span className="rv-futura" style={{
                            fontSize: 22, fontWeight: 300, color: 'var(--rv-ink)',
                            letterSpacing: '-0.005em', lineHeight: 1,
                          }}>{g.title}</span>
                          <span style={{
                            fontSize: 10, letterSpacing: '0.22em', textTransform: 'uppercase',
                            color: 'var(--rv-purple-700)', fontWeight: 500,
                          }}>{g.sub}</span>
                        </div>
                        {g.items.map((it, ii) => (
                          <a key={ii} href="#" style={{
                            display: 'grid', gridTemplateColumns: 'auto 1fr auto', alignItems: 'baseline',
                            padding: '13px 0', gap: 18,
                            borderBottom: '1px solid var(--rv-border)',
                            textDecoration: 'none',
                            transition: 'padding 240ms var(--rv-ease)',
                          }}
                            onMouseEnter={e => {
                              e.currentTarget.style.paddingLeft = '14px';
                              e.currentTarget.querySelector('.rv-arr').style.opacity = '1';
                              e.currentTarget.querySelector('.rv-arr').style.transform = 'translateX(0)';
                            }}
                            onMouseLeave={e => {
                              e.currentTarget.style.paddingLeft = '0';
                              e.currentTarget.querySelector('.rv-arr').style.opacity = '0';
                              e.currentTarget.querySelector('.rv-arr').style.transform = 'translateX(-8px)';
                            }}
                          >
                            <span style={{ fontSize: 11, color: 'var(--rv-muted)', letterSpacing: '0.14em' }}>
                              {String(ii+1).padStart(2,'0')}
                            </span>
                            <span>
                              <div style={{ fontSize: 16, fontWeight: 500, color: 'var(--rv-ink)', marginBottom: 2 }}>{it.n}</div>
                              <div style={{ fontSize: 12.5, color: 'var(--rv-muted)', letterSpacing: '0.02em' }}>{it.d}</div>
                            </span>
                            <span className="rv-arr" style={{
                              fontSize: 12, letterSpacing: '0.18em', textTransform: 'uppercase',
                              color: 'var(--rv-purple)', opacity: 0, transform: 'translateX(-8px)',
                              transition: 'all 240ms var(--rv-ease)', whiteSpace: 'nowrap',
                            }}>Explore →</span>
                          </a>
                        ))}
                      </div>
                    ))}
                  </div>
                ) : (
                  <div style={{ borderTop: '1px solid var(--rv-border)' }}>
                    {cat.items.map((it, ii) => (
                      <a key={ii} href="#" style={{
                        display: 'grid', gridTemplateColumns: 'auto 1fr auto', alignItems: 'baseline',
                        padding: '16px 0', gap: 20,
                        borderBottom: '1px solid var(--rv-border)',
                        textDecoration: 'none',
                        transition: 'padding 240ms var(--rv-ease)',
                      }}
                        onMouseEnter={e => {
                          e.currentTarget.style.paddingLeft = '14px';
                          e.currentTarget.querySelector('.rv-arr').style.opacity = '1';
                          e.currentTarget.querySelector('.rv-arr').style.transform = 'translateX(0)';
                        }}
                        onMouseLeave={e => {
                          e.currentTarget.style.paddingLeft = '0';
                          e.currentTarget.querySelector('.rv-arr').style.opacity = '0';
                          e.currentTarget.querySelector('.rv-arr').style.transform = 'translateX(-8px)';
                        }}
                      >
                        <span style={{ fontSize: 11, color: 'var(--rv-muted)', letterSpacing: '0.14em' }}>
                          {String(ii+1).padStart(2,'0')}
                        </span>
                        <span>
                          <div style={{ fontSize: 18, fontWeight: 500, color: 'var(--rv-ink)', marginBottom: 2 }}>{it.n}</div>
                          <div style={{ fontSize: 13, color: 'var(--rv-muted)', letterSpacing: '0.02em' }}>{it.d}</div>
                        </span>
                        <span className="rv-arr" style={{
                          fontSize: 13, letterSpacing: '0.18em', textTransform: 'uppercase',
                          color: 'var(--rv-purple)', opacity: 0, transform: 'translateX(-8px)',
                          transition: 'all 240ms var(--rv-ease)', whiteSpace: 'nowrap',
                        }}>Explore →</span>
                      </a>
                    ))}
                  </div>
                )}

                {/* Feature tile */}
                <div style={{
                  position: 'relative', aspectRatio: '4/5',
                  background: cat.accent, overflow: 'hidden',
                  color: cat.dark ? 'white' : 'var(--rv-ink)',
                  padding: 28,
                  display: 'flex', flexDirection: 'column', justifyContent: 'space-between',
                }}>
                  {/* Hairline grid */}
                  <svg viewBox="0 0 400 500" preserveAspectRatio="none" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', opacity: 0.18 }}>
                    {Array.from({length: 5}).map((_, k) => (
                      <line key={k} x1={k*100} y1="0" x2={k*100} y2="500" stroke={cat.dark ? 'white' : 'currentColor'} strokeWidth="0.5"/>
                    ))}
                  </svg>
                  {/* Arch */}
                  <svg viewBox="0 0 400 500" preserveAspectRatio="none" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
                    <path d="M 100 500 L 100 220 Q 100 100 200 100 Q 300 100 300 220 L 300 500 Z"
                      fill="none" stroke={cat.dark ? 'rgba(255,255,255,0.28)' : 'rgba(26,22,37,0.22)'} strokeWidth="1"/>
                  </svg>
                  <img src="assets/dragonfly-real.png" alt="" loading="lazy" decoding="async" width="160" height="215" style={{
                    position: 'absolute', right: -10, bottom: -14, width: 160, height: 'auto',
                    opacity: cat.dark ? 0.5 : 0.35,
                    filter: cat.dark ? 'brightness(0) invert(1)' : 'none',
                  }}/>

                  <div style={{ position: 'relative' }}>
                    <div style={{ fontSize: 11, letterSpacing: '0.24em', textTransform: 'uppercase', opacity: 0.78, marginBottom: 14 }}>
                      Featured · {cat.label}
                    </div>
                    <div className="rv-futura" style={{ fontSize: 'clamp(34px, 3vw, 48px)', fontWeight: 300, lineHeight: 1, letterSpacing: '-0.01em' }}>
                      {cat.items[0].n}
                    </div>
                  </div>
                  <div style={{ position: 'relative' }}>
                    <div style={{ fontSize: 14, lineHeight: 1.55, opacity: 0.82, marginBottom: 20, maxWidth: 280 }}>
                      {cat.items[0].d}
                    </div>
                    <button style={{
                      background: cat.dark ? 'white' : 'var(--rv-ink)',
                      color: cat.dark ? 'var(--rv-ink)' : 'white', border: 0,
                      padding: '14px 22px', fontSize: 11, letterSpacing: '0.18em',
                      textTransform: 'uppercase', fontWeight: 500, cursor: 'pointer',
                    }}>Learn More →</button>
                  </div>
                </div>
              </div>

              {/* Compact footer line */}
              <div style={{
                display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: '0 28px',
                paddingTop: 18, borderTop: '1px solid var(--rv-border)',
                fontSize: 12, color: 'var(--rv-muted)', letterSpacing: '0.04em',
              }}>
                <a href="tel:6506973339" style={{ color: 'var(--rv-ink)', textDecoration: 'none', fontWeight: 500 }}>(650) 697-3339</a>
                <span>31 S. El Camino Real · Millbrae</span>
                <span>Tue–Fri 10–6 · Sat 10–3</span>
              </div>
            </div>
          </div>
          )}
        </div>
      )}
      <style>{`
        @keyframes rv-panel-in {
          from { opacity: 0; transform: translateY(12px); }
          to { opacity: 1; transform: translateY(0); }
        }
      `}</style>
    </div>
    </>
  );
}
window.Header = Header;
