/* Navigation — ported from src/components/Navigation.jsx */
const { useState, useEffect, useRef } = React;
const { motion, AnimatePresence, useScroll, useMotionValueEvent } = window.Motion;

const BLUE = '#02528A';
const GOLD = '#FDC327';
const RED  = '#E8192C';

const NAV_DATA = [
  { id: 'home', label: 'Home', href: 'index.html', internal: true },
  {
    id: 'about', label: 'About Us',
    items: [
      { label: 'Overview',       href: 'about-us.html', internal: true },
      { label: 'RR-FILA group',  href: 'rr-fila-group.html', internal: true },
      { label: 'Infrastructure', href: 'infrastructure.html', internal: true },
    ],
  },
  {
    id: 'investor', label: 'Investor Relations', href: 'investor-relations.html', internal: true,
    items: [
      { label: 'Financial Highlights', group: true, items: [
        { label: 'Financial Statements', href: 'financial-statements.html', internal: true },
        { label: 'Financial Statement of Subsidiaries and Associate', href: 'financial-statement-of-subsidiaries.html', internal: true },
        { label: 'Investor Presentation and Transcripts', href: 'investor-presentation-transcripts.html', internal: true },
        { label: 'Material Creditors', href: 'doc-viewer.html?src=https%3A%2F%2Fdomsindia.com%2Fpdf%2FInvestor_Relations%2FMaterial_Creditors.pdf&title=Material%20Creditors', internal: true },
        { label: 'Industry Report', href: 'doc-viewer.html?src=https%3A%2F%2Fdomsindia.com%2Fpdf%2FInvestor_Relations%2FIndustry_Report.pdf&title=Industry%20Report', internal: true },
      ] },
      { label: 'Shareholders and Board of Directors', group: true, items: [
        { label: 'Shareholding Pattern', href: 'shareholding-pattern.html', internal: true },
        { label: 'Board of Directors', href: 'board-of-directors.html', internal: true },
        { label: 'Board Committees', href: 'board-committees.html', internal: true },
      ] },
      { label: 'Disclosure Under Regulation 46 of SEBI (LODR)', href: 'disclosure-regulation-46.html', internal: true },
      { label: 'Governance', group: true, items: [
        { label: 'Policies', href: 'policies.html', internal: true },
      ] },
      { label: 'Dividend', group: true, items: [
        { label: 'Final Dividend FY 2023-24', href: 'dividend.html', internal: true },
      ] },
      { label: 'Corporate Social Responsibility', href: 'corporate-social-responsibility.html', internal: true },
      { label: 'Intimation to Stock Exchanges', href: 'intimation-to-stock-exchanges.html', internal: true },
      { label: 'Postal Ballot', href: 'postal-ballot.html', internal: true },
      { label: 'Employee Stock Option Plan', href: 'esop-disclosure.html', internal: true },
      { label: 'Draft Red Herring Prospectus', href: 'draft-red-herring-prospectus.html', internal: true },
      { label: 'Red Herring Prospectus', href: 'red-herring-prospectus.html', internal: true },
      { label: 'Prospectus', href: 'prospectus.html', internal: true },
      { label: 'Allotment Advertisement', href: 'doc-viewer.html?src=https%3A%2F%2Fdomsindia.com%2Fpdf%2FInvestor_Relations%2FDOMS_Industries_Limited_BoA_Ad.pdf&title=Allotment%20Advertisement', internal: true },
      { label: 'Press Release', href: 'press-release.html', internal: true },
      { label: 'Memorandum and Articles of Association', href: 'doc-viewer.html?src=https%3A%2F%2Fdomsindia.com%2Fpdf%2FInvestor_Relations%2FMemorandum_and_Articles_of_Association.pdf&title=Memorandum%20and%20Articles%20of%20Association', internal: true },
      { label: 'Contact for Investor Grievance', href: 'contact-for-investor-grievance.html', internal: true },
    ],
  },
  {
    id: 'products', label: 'Products', mega: true, href: 'products.html', internal: true,
    categories: [
      { name: 'Pencils & Accessories', color: '#F5A623', img: 'images/pencil.jpg',        href: 'products.html#cat/pencils-accessories', internal: true },
      { name: 'Pens & Writing',        color: '#7B5EA7', img: 'images/pens.jpg',           href: 'products.html#cat/pens-writing-instruments', internal: true },
      { name: 'Drawing & Colouring',   color: '#E8192C', img: 'images/Art-Range.webp',     href: 'products.html#cat/drawing-colouring', internal: true },
      { name: 'Math Instruments',      color: BLUE,      img: 'images/product-inxon.webp', href: 'products.html#cat/mathematical-drawing-instruments', internal: true },
      { name: 'Paper Stationery',      color: '#27AE60', img: 'images/product-brush.webp', href: 'products.html#cat/paper-stationery', internal: true },
      { name: 'Gifting',               color: '#E67E22', img: 'images/product-wax.webp',   href: 'products.html#cat/gifting', internal: true },
    ],
  },
  {
    id: 'engage', label: 'Engage',
    items: [
      { label: 'Blogs',          href: 'blogs.html', internal: true },
      { label: 'Media Coverage', href: 'media-coverage.html', internal: true },
      { label: 'Events',         href: 'events.html', internal: true },
      { label: 'Videos',         href: 'videos.html', internal: true },
    ],
  },
  { id: 'contact', label: 'Contact Us', href: 'contact-us.html', internal: true },
];

const GLASS = {
  none: {
    background: 'transparent',
    backdropFilter: 'none',
    WebkitBackdropFilter: 'none',
    boxShadow: 'none',
    border: 'none',
  },
  island: {
    background: 'rgba(255,255,255,0.07)',
    backdropFilter: 'blur(48px) saturate(500%) brightness(1.1)',
    WebkitBackdropFilter: 'blur(48px) saturate(500%) brightness(1.1)',
    boxShadow: [
      'inset 0 1.5px 0 rgba(255,255,255,0.65)',
      'inset 0 -1px 0 rgba(255,255,255,0.1)',
      '0 20px 50px rgba(0,0,0,0.22)',
      '0 6px 20px rgba(0,0,0,0.1)',
      '0 0 0 0.5px rgba(255,255,255,0.18)',
    ].join(','),
    border: '1px solid rgba(255,255,255,0.26)',
  },
};

const dropGlass = {
  background: 'rgba(255,255,255,0.75)',
  backdropFilter: 'blur(48px) saturate(300%) brightness(1.05)',
  WebkitBackdropFilter: 'blur(48px) saturate(300%) brightness(1.05)',
  border: '1px solid rgba(255,255,255,0.4)',
  boxShadow: [
    'inset 0 1.5px 0 rgba(255,255,255,0.8)',
    '0 20px 60px rgba(2,82,138,0.15)',
    '0 6px 20px rgba(0,0,0,0.08)',
  ].join(','),
};

function NavBtn({ label, hasArrow, isActive, onClick, restColor = 'rgba(15,30,70,0.80)' }) {
  const [hov, setHov] = useState(false);
  const lit = hov || isActive;

  return (
    <motion.button
      onClick={onClick}
      onHoverStart={() => setHov(true)}
      onHoverEnd={() => setHov(false)}
      animate={{ y: lit ? -2 : 0 }}
      transition={{ type: 'spring', stiffness: 560, damping: 28 }}
      whileTap={{ scale: 0.96, y: 0 }}
      style={{ position: 'relative', padding: '11px 18px', background: 'none', border: 'none', cursor: 'pointer', display: 'flex', alignItems: 'center', gap: 5 }}
    >
      <AnimatePresence>
        {lit && (
          <motion.div key="pill"
            initial={{ opacity: 0, scaleY: 0.6, scaleX: 0.88, y: 6 }}
            animate={{ opacity: 1, scaleY: 1, scaleX: 1, y: 0 }}
            exit={{ opacity: 0, scaleY: 0.65, y: 5, transition: { duration: 0.15 } }}
            transition={{ type: 'spring', stiffness: 520, damping: 24 }}
            style={{
              position: 'absolute', inset: 0, borderRadius: 10, pointerEvents: 'none',
              background: 'rgba(255,255,255,0.88)',
              backdropFilter: 'blur(20px) saturate(180%)',
              WebkitBackdropFilter: 'blur(20px) saturate(180%)',
              boxShadow: '0 4px 18px rgba(2,82,138,0.13), 0 1px 4px rgba(0,0,0,0.06), inset 0 1.5px 0 rgba(255,255,255,1)',
              border: '1px solid rgba(2,82,138,0.08)',
            }}
          />
        )}
      </AnimatePresence>
      <motion.span animate={{ color: lit ? BLUE : restColor }} transition={{ duration: 0.15 }}
        style={{ position: 'relative', zIndex: 1, fontSize: 17, fontWeight: 600, whiteSpace: 'nowrap', letterSpacing: '0.1px', textShadow: restColor === '#fff' ? '0 1px 8px rgba(0,0,0,0.25)' : 'none' }}>
        {label}
      </motion.span>
      {hasArrow && (
        <motion.svg width="8" height="5" viewBox="0 0 9 6" fill="none"
          style={{ position: 'relative', zIndex: 1, flexShrink: 0 }}
          animate={{ rotate: isActive ? 180 : 0, color: lit ? BLUE : restColor }}
          transition={{ duration: 0.2 }}>
          <path d="M1 1l3.5 3.5L8 1" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round"/>
        </motion.svg>
      )}
    </motion.button>
  );
}

const ddV = {
  hidden:  { opacity: 0, y: -10, scale: 0.96 },
  visible: { opacity: 1, y: 0, scale: 1,
    transition: { type: 'spring', stiffness: 420, damping: 32, staggerChildren: 0.045 } },
  exit:    { opacity: 0, y: -8,  scale: 0.96, transition: { duration: 0.15 } },
};
const ddI = {
  hidden:  { opacity: 0, x: -10 },
  visible: { opacity: 1, x: 0, transition: { type: 'spring', stiffness: 500, damping: 36 } },
};

const FLY_ARROW = (
  <svg width="9" height="11" viewBox="0 0 9 11" fill="none" aria-hidden="true">
    <path d="M1 1l6 4.5L1 10" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"/>
  </svg>
);

function SimpleDropdown({ items }) {
  const hasGroups = items.some(it => it.items);

  // ── Flyout style (Investor Relations): left list + right sub-panel ──
  if (hasGroups) {
    const firstGroup = items.find(it => it.items);
    const [activeG, setActiveG] = useState(firstGroup ? firstGroup.label : null);
    const [offset, setOffset] = useState(3);
    const active = items.find(it => it.label === activeG && it.items);
    const LEFT_W = 372, RIGHT_W = 360;
    return (
      <motion.div
        variants={ddV} initial="hidden" animate="visible" exit="exit"
        style={{
          position: 'absolute', top: 'calc(100% + 10px)', left: 0,
          padding: 0, zIndex: 600,
          display: 'flex', alignItems: 'flex-start',
          filter: 'drop-shadow(0 18px 40px rgba(13,27,75,0.18))',
        }}
      >
        {/* left column — every IR item in order */}
        <div style={{ width: LEFT_W, position: 'relative', borderRadius: '12px 0 0 12px', overflowY: 'auto', overflowX: 'hidden', maxHeight: 'calc(100vh - 130px)', ...dropGlass, boxShadow: 'none' }}>
          <div style={{ height: 3, background: `linear-gradient(90deg,${BLUE},${GOLD})` }}/>
          {items.map((it, i) => {
            const isGroup = !!it.items;
            const isActive = isGroup && it.label === activeG;
            const last = i === items.length - 1;
            return isGroup ? (
              <div key={it.label}
                onMouseEnter={(e) => { setActiveG(it.label); setOffset(e.currentTarget.offsetTop); }}
                className="doms-flyrow"
                style={{
                  display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12,
                  padding: '12px 18px', cursor: 'default',
                  borderBottom: last ? 'none' : '1px solid #edf1f4',
                  background: isActive ? BLUE : 'transparent',
                  color: isActive ? '#fff' : '#1e2933',
                }}
              >
                <span style={{ fontSize: 14, fontWeight: 600, lineHeight: 1.3 }}>{it.label}</span>
                <span style={{ display: 'flex', color: isActive ? '#fff' : GOLD, flexShrink: 0 }}>{FLY_ARROW}</span>
              </div>
            ) : (
              <a key={it.label} href={it.href} target={it.internal ? '_self' : '_blank'} rel="noreferrer"
                onMouseEnter={() => setActiveG(null)}
                className="doms-flyrow"
                style={{
                  display: 'block', padding: '12px 18px', textDecoration: 'none',
                  borderBottom: last ? 'none' : '1px solid #edf1f4',
                  fontSize: 14, fontWeight: 500, color: BLUE, lineHeight: 1.3,
                }}
              >{it.label}</a>
            );
          })}
        </div>
        {/* right column — sub-items of the active group */}
        <AnimatePresence mode="wait">
          {active && (
            <motion.div key={active.label}
              initial={{ opacity: 0, x: -8 }} animate={{ opacity: 1, x: 0 }} exit={{ opacity: 0, x: -8 }}
              transition={{ duration: 0.16 }}
              style={{ width: RIGHT_W, alignSelf: 'flex-start', marginTop: offset, overflow: 'hidden', ...dropGlass, boxShadow: 'none', borderLeft: '1px solid rgba(2,82,138,0.12)', borderRadius: '12px 12px 12px 12px' }}
            >
              {active.items.map((sub, j) => (
                <a key={sub.label} href={sub.href} target={sub.internal ? '_self' : '_blank'} rel="noreferrer"
                  className="doms-flyrow"
                  style={{
                    display: 'block', padding: '12px 20px', textDecoration: 'none',
                    borderBottom: j === active.items.length - 1 ? 'none' : '1px solid #edf1f4',
                    fontSize: 14, fontWeight: 500, color: BLUE, lineHeight: 1.35,
                  }}
                >{sub.label}</a>
              ))}
            </motion.div>
          )}
        </AnimatePresence>
      </motion.div>
    );
  }

  // ── Simple list (About Us, Engage) ──
  return (
    <motion.div
      variants={ddV} initial="hidden" animate="visible" exit="exit"
      style={{
        position: 'absolute', top: 'calc(100% + 10px)', right: 0,
        ...dropGlass, borderRadius: 14,
        padding: '6px 8px 10px', width: 252, zIndex: 600,
      }}
    >
      <div style={{ height: 3, background: `linear-gradient(90deg,${BLUE},${GOLD})`, borderRadius: '8px 8px 0 0', margin: '-6px -8px 8px' }}/>
      {items.map(it => (
        <a key={it.label} href={it.href} target={it.internal ? '_self' : '_blank'} rel="noreferrer" className="doms-dd-link"
          style={{ display: 'block', padding: '9px 14px', borderRadius: 8, textDecoration: 'none' }}
        >
          <div style={{ fontSize: 13, fontWeight: 700, color: '#1a1a1a', lineHeight: 1.3 }}>{it.label}</div>
          {it.desc && <div style={{ fontSize: 11, color: '#999', marginTop: 2 }}>{it.desc}</div>}
        </a>
      ))}
    </motion.div>
  );
}

const megaV = {
  hidden:  { opacity: 0, y: -14, scale: 0.96 },
  visible: { opacity: 1, y: 0, scale: 1,
    transition: { type: 'spring', stiffness: 380, damping: 30, staggerChildren: 0.055 } },
  exit:    { opacity: 0, y: -10, scale: 0.96, transition: { duration: 0.18 } },
};
const tileV = {
  hidden:  { opacity: 0, y: 12 },
  visible: { opacity: 1, y: 0, transition: { type: 'spring', stiffness: 460, damping: 32 } },
};

function MegaMenu({ categories }) {
  const [active, setActive] = useState(categories[0]);
  return (
    <motion.div
      variants={megaV} initial="hidden" animate="visible" exit="exit"
      style={{
        position: 'absolute', top: 'calc(100% + 10px)',
        right: 0,
        ...dropGlass, borderRadius: 18,
        overflow: 'hidden', zIndex: 600, width: 700, maxWidth: 'calc(100vw - 40px)',
      }}
    >
      <div style={{ height: 4, background: `linear-gradient(90deg,${BLUE},${GOLD},${RED})` }}/>
      <div style={{ display: 'flex' }}>
        <div style={{ flex: 1, padding: '18px 14px 18px 18px' }}>
          <p style={{ fontSize: 10, fontWeight: 800, color: '#bbb', letterSpacing: '1.8px', textTransform: 'uppercase', marginBottom: 12 }}>
            Browse Categories
          </p>
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 8 }}>
            {categories.map(cat => {
              const sel = active?.name === cat.name;
              return (
                <motion.a key={cat.name} href={cat.href} target={cat.internal ? '_self' : '_blank'} rel="noreferrer"
                  variants={tileV} onHoverStart={() => setActive(cat)}
                  style={{
                    display: 'flex', alignItems: 'center', gap: 10,
                    padding: '10px 12px', borderRadius: 10, textDecoration: 'none',
                    border: `1.5px solid ${sel ? cat.color : 'transparent'}`,
                    background: sel ? `${cat.color}12` : 'transparent',
                    transition: 'border-color 0.15s, background 0.15s',
                  }}
                >
                  <motion.div
                    animate={{ scale: sel ? 1.35 : 1, boxShadow: sel ? `0 0 8px ${cat.color}80` : 'none' }}
                    transition={{ duration: 0.18 }}
                    style={{ width: 10, height: 10, borderRadius: '50%', background: cat.color, flexShrink: 0 }}
                  />
                  <span style={{ fontSize: 12.5, fontWeight: 700, color: '#1a1a1a', lineHeight: 1.3 }}>{cat.name}</span>
                </motion.a>
              );
            })}
          </div>
          <motion.a href="products.html#all" target="_self" rel="noreferrer"
            whileHover={{ scale: 1.02, background: '#013d6b' }} whileTap={{ scale: 0.97 }}
            style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 6, marginTop: 14, padding: '10px', background: BLUE, color: '#fff', borderRadius: 9, textDecoration: 'none', fontSize: 12.5, fontWeight: 700 }}
          >
            View All Products
            <svg width="13" height="13" viewBox="0 0 13 13" fill="none">
              <path d="M2.5 6.5h8m-3.5-3.5 3.5 3.5-3.5 3.5" stroke="#fff" strokeWidth="1.8" strokeLinecap="round"/>
            </svg>
          </motion.a>
        </div>
        <div style={{
          width: 210, flexShrink: 0,
          background: 'rgba(240,248,255,0.5)',
          backdropFilter: 'blur(12px)',
          padding: '22px 16px',
          borderLeft: '1px solid rgba(2,82,138,0.08)',
          display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center',
        }}>
          <AnimatePresence mode="wait">
            <motion.div key={active?.name}
              initial={{ opacity: 0, scale: 0.85, y: 12 }}
              animate={{ opacity: 1, scale: 1, y: 0 }}
              exit={{ opacity: 0, scale: 0.85, y: -12 }}
              transition={{ duration: 0.26, ease: [0.34, 1.56, 0.64, 1] }}
              style={{ textAlign: 'center', width: '100%' }}
            >
              <div style={{
                width: 120, height: 120, borderRadius: '50%',
                background: `radial-gradient(circle at 40% 35%, ${active?.color}28, ${active?.color}06)`,
                border: `2px solid ${active?.color}35`,
                display: 'flex', alignItems: 'center', justifyContent: 'center',
                margin: '0 auto 12px', boxShadow: `0 0 28px ${active?.color}18`,
              }}>
                <img src={active?.img} alt={active?.name}
                  style={{ width: 88, height: 88, objectFit: 'contain', filter: 'drop-shadow(0 4px 10px rgba(0,0,0,0.14))' }}
                  onError={e => { e.currentTarget.style.opacity = '0'; }}
                />
              </div>
              <p style={{ fontSize: 12, fontWeight: 800, color: '#1a1a1a', lineHeight: 1.3, marginBottom: 6 }}>{active?.name}</p>
              <motion.div animate={{ background: active?.color }} style={{ width: 32, height: 3, borderRadius: 2, margin: '0 auto 10px' }}/>
              <motion.a href={active?.href} target={active?.internal ? '_self' : '_blank'} rel="noreferrer"
                whileHover={{ scale: 1.05 }} whileTap={{ scale: 0.95 }}
                style={{ display: 'inline-block', fontSize: 11, fontWeight: 800, color: active?.color, border: `1.5px solid ${active?.color}`, borderRadius: 7, padding: '5px 13px', textDecoration: 'none' }}
              >
                Explore →
              </motion.a>
            </motion.div>
          </AnimatePresence>
        </div>
      </div>
    </motion.div>
  );
}

function MobileMenu({ open, onClose }) {
  const [exp, setExp] = useState(null);
  const [gexp, setGexp] = useState({});
  const toggleG = k => setGexp(s => ({ ...s, [k]: !s[k] }));

  const caret = (isOpen, color) => (
    <motion.svg width="13" height="8" viewBox="0 0 12 8" fill="none"
      animate={{ rotate: isOpen ? 180 : 0 }} transition={{ duration: 0.2 }} style={{ flexShrink: 0 }}>
      <path d="M1 1l5 5 5-5" stroke={color} strokeWidth="1.7" strokeLinecap="round"/>
    </motion.svg>
  );

  const leaf = (it, pad) => (
    <a key={it.label} href={it.href} target={it.internal ? '_self' : '_blank'} rel="noreferrer" onClick={onClose}
      style={{ display: 'block', padding: `13px 24px 13px ${pad}px`, fontSize: 14.5, color: '#26303c', textDecoration: 'none', borderBottom: '1px solid #eceef1', background: '#fff', lineHeight: 1.4 }}>
      {it.label}
    </a>
  );

  return (
    <AnimatePresence>
      {open && (
        <motion.div
          initial={{ opacity: 0, clipPath: 'inset(0 0 100% 0)' }}
          animate={{ opacity: 1, clipPath: 'inset(0 0 0% 0)' }}
          exit={{ opacity: 0, clipPath: 'inset(0 0 100% 0)' }}
          transition={{ duration: 0.4, ease: [0.16, 1, 0.3, 1] }}
          style={{ position: 'fixed', inset: 0, background: '#fff', zIndex: 9999, overflowY: 'auto' }}
        >
          {/* header — soft yellow gradient like the DOMS site */}
          <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '18px 22px', background: 'linear-gradient(180deg, #fbe7a4 0%, #fdf3cf 55%, #fffdf6 100%)', position: 'sticky', top: 0, zIndex: 5 }}>
            <img src="images/logo.webp" alt="DOMS" style={{ height: 50 }}/>
            <motion.button onClick={onClose}
              whileHover={{ scale: 1.1 }} whileTap={{ scale: 0.92 }}
              aria-label="Close menu"
              style={{ width: 42, height: 42, borderRadius: 8, background: 'none', border: 'none', cursor: 'pointer', color: '#111', fontSize: 26, lineHeight: 1, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
              ✕
            </motion.button>
          </div>

          <div>
            {NAV_DATA.map((item, i) => {
              const directHref = item.href || (item.mega ? item.mobileHref : null);
              const children = item.items || (item.mega ? item.categories.map(c => ({ label: c.name, href: c.href, internal: c.internal })) : null);
              return (                <motion.div key={item.id}
                  initial={{ opacity: 0, x: -20 }} animate={{ opacity: 1, x: 0 }}
                  transition={{ delay: 0.08 + i * 0.05, type: 'spring', stiffness: 440, damping: 34 }}
                >
                  {(directHref && !children) ? (
                    <a href={directHref} target={item.internal ? '_self' : '_blank'} rel="noreferrer" onClick={onClose}
                      style={{ display: 'block', padding: '16px 24px', background: BLUE, color: '#fff', fontFamily: "'Barlow Condensed', sans-serif", fontSize: 20, fontWeight: 600, letterSpacing: '0.3px', textDecoration: 'none', borderBottom: '1px solid rgba(255,255,255,0.14)' }}>
                      {item.label}
                    </a>
                  ) : (
                    <>
                      <button onClick={() => setExp(e => e === item.id ? null : item.id)}
                        style={{ width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12, padding: '16px 24px', background: BLUE, border: 'none', borderBottom: '1px solid rgba(255,255,255,0.14)', cursor: 'pointer', color: '#fff', fontFamily: "'Barlow Condensed', sans-serif", fontSize: 20, fontWeight: 600, letterSpacing: '0.3px', textAlign: 'left' }}>
                        {item.label}
                        {caret(exp === item.id, '#fff')}
                      </button>
                      <AnimatePresence>
                        {exp === item.id && (
                          <motion.div
                            initial={{ height: 0, opacity: 0 }} animate={{ height: 'auto', opacity: 1 }}
                            exit={{ height: 0, opacity: 0 }} transition={{ duration: 0.28, ease: [0.16, 1, 0.3, 1] }}
                            style={{ overflow: 'hidden' }}
                          >
                            {directHref && (
                              <a href={directHref} target={item.internal ? '_self' : '_blank'} rel="noreferrer" onClick={onClose}
                                style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '13px 24px', fontSize: 14.5, fontWeight: 700, color: '#02528A', textDecoration: 'none', borderBottom: '1px solid #eceef1', background: '#eef4fa' }}>
                                View {item.label} <span style={{ fontSize: 16 }}>→</span>
                              </a>
                            )}
                            {children.map(sub => sub.group ? (
                              <div key={sub.label}>
                                <button onClick={() => toggleG(sub.label)}
                                  style={{ width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12, padding: '13px 24px', background: BLUE, border: 'none', borderBottom: '1px solid rgba(255,255,255,0.14)', cursor: 'pointer', color: '#fff', fontFamily: "'Barlow Condensed', sans-serif", fontSize: 17, fontWeight: 600, textAlign: 'left' }}>
                                  {sub.label}
                                  {caret(!!gexp[sub.label], '#fff')}
                                </button>
                                <AnimatePresence>
                                  {gexp[sub.label] && (
                                    <motion.div
                                      initial={{ height: 0, opacity: 0 }} animate={{ height: 'auto', opacity: 1 }}
                                      exit={{ height: 0, opacity: 0 }} transition={{ duration: 0.24 }}
                                      style={{ overflow: 'hidden' }}
                                    >
                                      {sub.items.map(g => leaf(g, 40))}
                                    </motion.div>
                                  )}
                                </AnimatePresence>
                              </div>
                            ) : leaf(sub, 24))}
                          </motion.div>
                        )}
                      </AnimatePresence>
                    </>
                  )}
                </motion.div>
              );
            })}
          </div>

          <div style={{ padding: '20px 24px 36px' }}>
            <motion.a href="artleague/index.html" target="_self" rel="noreferrer"
              initial={{ opacity: 0, y: 16 }} animate={{ opacity: 1, y: 0 }}
              transition={{ delay: 0.12 + NAV_DATA.length * 0.05 }}
              whileHover={{ scale: 1.02 }} whileTap={{ scale: 0.97 }}
              style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', background: RED, color: '#fff', padding: '14px', borderRadius: 10, fontFamily: "'Barlow Condensed', sans-serif", fontSize: 18, fontWeight: 800, textDecoration: 'none' }}>
              DOMS Art League
            </motion.a>
          </div>
        </motion.div>
      )}
    </AnimatePresence>
  );
}

function Navigation() {
  const [active, setActive] = useState(null);
  const [island, setIsland] = useState(false);
  const [mobileOpen, setMobileOpen] = useState(false);
  const [heroDark, setHeroDark] = useState(true); // first hero slide (blue) is dark
  const navRef = useRef(null);
  const hoverTimer = useRef(null);
  const openMenu = id => { if (hoverTimer.current) clearTimeout(hoverTimer.current); setActive(id); };
  const closeMenuSoon = () => { if (hoverTimer.current) clearTimeout(hoverTimer.current); hoverTimer.current = setTimeout(() => setActive(null), 160); };
  const { scrollY } = useScroll();

  useMotionValueEvent(scrollY, 'change', v => setIsland(v > 80));

  useEffect(() => {
    const onColor = e => setHeroDark(!e.detail.light);
    window.addEventListener('doms-hero-color', onColor);
    return () => window.removeEventListener('doms-hero-color', onColor);
  }, []);

  useEffect(() => {
    const close = e => { if (navRef.current && !navRef.current.contains(e.target)) setActive(null); };
    document.addEventListener('mousedown', close);
    return () => { document.removeEventListener('mousedown', close); };
  }, []);

  const spring = { type: 'spring', stiffness: 280, damping: 28 };
  /* over the hero (rest state), keep the nav light/white on every room colour for a consistent look */
  const overHeroLight = !island;                      // always white nav elements over the hero
  const restColor = overHeroLight ? '#fff' : 'rgba(15,30,70,0.85)';
  const logoFilter = 'drop-shadow(0 2px 10px rgba(0,0,0,0.18))';

  return (
    <>
      <div className="doms-navwrap" style={{
        position: 'fixed', top: 0, left: 0, right: 0, zIndex: 500,
        display: 'flex', justifyContent: 'center',
        pointerEvents: 'none',
      }}>
        <motion.nav
          ref={navRef}
          className="doms-navshell"
          animate={{
            marginTop: island ? 14 : 0,
            borderRadius: island ? 56 : 0,
            maxWidth: island ? 960 : 2110,
          }}
          transition={spring}
          style={{
            width: '100%',
            pointerEvents: 'all',
            position: 'relative',
            overflow: 'visible',
            ...(island ? GLASS.island : GLASS.none),
          }}
        >
          <div className="doms-navbar" style={{
            width: '100%', boxSizing: 'border-box',
            padding: island ? '0 16px' : '5px 40px',
            height: island ? 58 : 110,
            transition: 'height 0.35s cubic-bezier(0.16,1,0.3,1), padding 0.35s cubic-bezier(0.16,1,0.3,1)',
            display: 'flex', alignItems: 'center', gap: island ? 2 : 0,
          }}>

            <a href="/" onClick={e => { e.preventDefault(); window.scrollTo({ top: 0, behavior: 'smooth' }); }} style={{
              flexShrink: 0, marginRight: island ? 10 : 0,
              textDecoration: 'none', position: 'relative',
              display: 'flex', alignItems: 'center',
            }}>
              <AnimatePresence>
                {island && (
                  <motion.div
                    key="logo-indent"
                    initial={{ opacity: 0 }}
                    animate={{ opacity: 1 }}
                    exit={{ opacity: 0, transition: { duration: 0.15 } }}
                    transition={spring}
                    style={{
                      position: 'absolute', inset: '-7px -12px',
                      borderRadius: 15,
                      background: 'radial-gradient(112% 132% at 50% 38%, rgba(0,0,0,0.14) 0%, rgba(0,0,0,0.04) 55%, transparent 78%)',
                      boxShadow: [
                        'inset 0 4px 11px rgba(0,0,0,0.18)',
                        'inset 0 -3px 7px rgba(255,255,255,0.5)',
                      ].join(','),
                      filter: 'blur(0.4px)',
                      pointerEvents: 'none',
                    }}
                  />
                )}
              </AnimatePresence>
              <motion.img
                src="images/doms-logo-new.png" alt="DOMS Industries"
                animate={{ height: island ? 38 : 70 }}
                transition={spring}
                style={{
                  display: 'block', position: 'relative',
                  objectFit: 'contain',
                  filter: logoFilter,
                  transition: 'filter 0.35s ease',
                }}
                whileHover={{ scale: 1.04 }}
              />
            </a>

            <div style={{ flex: island ? 0 : 1, minWidth: island ? 0 : 40, transition: 'flex 0.35s, min-width 0.35s' }} />

            <div className="doms-desknav" style={{ display: 'flex', alignItems: 'center', gap: 0, ...(island ? { flex: 1 } : {}) }}>
              {NAV_DATA.map(item => {
                const hasMenu = item.mega || item.items;
                const navTo = () => {
                  if (item.internal) {
                    const p = location.pathname;
                    const here = p.endsWith(item.href) || (item.href === 'index.html' && (p.endsWith('/') || p.endsWith('index.html')));
                    if (here) window.scrollTo({ top: 0, behavior: 'smooth' });
                    else window.location.href = item.href;
                  } else window.open(item.href, '_blank');
                };
                return (
                <div key={item.id} style={{ position: 'relative' }}
                  onMouseEnter={() => hasMenu && openMenu(item.id)}
                  onMouseLeave={() => hasMenu && closeMenuSoon()}>
                  {!hasMenu ? (
                    <NavBtn label={item.label} hasArrow={false} isActive={false} restColor={restColor}
                      onClick={navTo}
                    />
                  ) : (
                    <>
                      <NavBtn label={item.label} hasArrow isActive={active === item.id} restColor={restColor}
                        onClick={() => item.href ? navTo() : setActive(p => p === item.id ? null : item.id)}
                      />
                      <AnimatePresence>
                        {active === item.id && (
                          item.mega
                            ? <MegaMenu key="mega" categories={item.categories}/>
                            : <SimpleDropdown key="dd" items={item.items}/>
                        )}
                      </AnimatePresence>
                    </>
                  )}
                </div>
                );
              })}
            </div>

            {!island && (
              <motion.a
                href="artleague/index.html" target="_self" rel="noreferrer"
                className="doms-deskcta"
                initial={{ opacity: 0, scale: 0.88 }}
                animate={{ opacity: 1, scale: 1 }}
                exit={{ opacity: 0, scale: 0.88 }}
                whileHover={{ scale: 1.05, boxShadow: '0 8px 28px rgba(2,82,138,0.22), 0 0 0 1.5px rgba(2,82,138,0.4)' }}
                whileTap={{ scale: 0.96 }}
                transition={{ duration: 0.22 }}
                style={{
                  flexShrink: 0, marginLeft: 12,
                  background: 'rgba(255,255,255,0.96)',
                  color: BLUE,
                  border: '1.5px solid rgba(2,82,138,0.2)',
                  padding: '9px 22px',
                  borderRadius: 50,
                  fontSize: 13, fontWeight: 800, letterSpacing: '0.4px',
                  textDecoration: 'none', whiteSpace: 'nowrap',
                  boxShadow: '0 2px 16px rgba(2,82,138,0.1), 0 0 0 1px rgba(2,82,138,0.1)',
                }}
              >
                DOMS Art League
              </motion.a>
            )}

            <motion.button onClick={() => setMobileOpen(true)}
              whileHover={{ scale: 1.08 }} whileTap={{ scale: 0.92 }}
              style={{ display: 'none', background: 'none', border: 'none', cursor: 'pointer', padding: 8, marginLeft: 'auto', color: restColor }}
              className="doms-ham"
            >
              <svg width="24" height="18" viewBox="0 0 24 18" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round">
                <path d="M0 2h24M0 9h24M0 16h24"/>
              </svg>
            </motion.button>
          </div>

          <AnimatePresence>
            {island && (
              <motion.div
                initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }}
                style={{
                  position: 'absolute', bottom: 0, left: '10%', right: '10%', height: 1,
                  background: `linear-gradient(90deg, transparent, ${GOLD}60, ${BLUE}60, transparent)`,
                  borderRadius: '50%',
                }}
              />
            )}
          </AnimatePresence>
        </motion.nav>

        <AnimatePresence>
          {active && (
            <motion.div
              initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }}
              transition={{ duration: 0.2 }}
              onClick={() => setActive(null)}
              style={{
                position: 'fixed', inset: 0, top: island ? 90 : 76,
                background: 'rgba(0,8,28,0.18)',
                backdropFilter: 'blur(4px)',
                WebkitBackdropFilter: 'blur(4px)',
                zIndex: -1, pointerEvents: 'all',
              }}
            />
          )}
        </AnimatePresence>
      </div>

      <MobileMenu open={mobileOpen} onClose={() => setMobileOpen(false)}/>

      <style>{`
        @media (max-width: 1024px) {
          .doms-ham { display: flex !important; }
          .doms-desknav { display: none !important; }
          .doms-deskcta { display: none !important; }
          .doms-navwrap { padding: 0 10px; box-sizing: border-box; }
          .doms-navshell { width: calc(100vw - 20px) !important; max-width: calc(100vw - 20px) !important; margin-left: auto !important; margin-right: auto !important; }
          .doms-navbar { padding: 12px 18px !important; height: 72px !important; align-items: center !important; }
          .doms-navbar img { height: 44px !important; max-height: 44px !important; width: auto !important; }
        }
        @media (min-width: 1025px) { .doms-ham { display: none !important; } }
        .doms-flyrow { transition: background 0.15s, color 0.15s; }
        a.doms-flyrow:hover { background: #f3f7fb; color: #013d6b !important; }
      `}</style>
    </>
  );
}

window.Navigation = Navigation;
