// =============================================================
// Remote& website — Arabic mirror of shared chrome (Header, Footer, CTAs)
// RTL. Modern conversational MSA. Mint canvas.
// =============================================================

const NAV_ITEMS = [
  { label: 'المنتج', href: '#', cards: [
    {
      eyebrow: 'نظام الموظفين', title: 'HRMS', href: '/ar/hrms', icon: 'users-round',
      bg: '#2E5119', fg: '#E2F1D2', accent: '#A4CC7C',
      body: 'نظام موحد لجميع موظفيك حول العالم — كل عقد ومستند وعملية في مكان واحد.',
      stat: { value: '11', label: 'وحدات HRMS' },
      features: [
        { icon: 'network',       label: 'الهيكل التنظيمي',     desc: 'خطوط إدارة ومسارات اعتماد مباشرة' },
        { icon: 'user-plus',     label: 'الانضمام وإنهاء الخدمة', desc: 'جاهز من اليوم الأول، خروج موثّق' },
        { icon: 'calendar-days', label: 'الإجازات والوقت',       desc: 'عطلات محلية، أرصدة، استحقاقات' },
        { icon: 'file-text',     label: 'المستندات والتوقيع',    desc: 'عقود وسياسات وتوقيع داخل التطبيق' },
      ],
      modules: [
        { label: 'إدارة الموظفين',  icon: 'id-card',            href: '/ar/platform/people-management' },
        { label: 'الانضمام',        icon: 'user-plus',          href: '/ar/platform/onboarding' },
        { label: 'إنهاء الخدمة',    icon: 'user-minus',         href: '/ar/platform/offboarding' },
        { label: 'إدارة الإجازات',  icon: 'calendar-days',      href: '/ar/platform/leave-management' },
        { label: 'الرواتب والمكافآت', icon: 'circle-dollar-sign', href: '/ar/platform/compensation' },
        { label: 'المستندات',       icon: 'file-text',          href: '/ar/platform/documents' },
        { label: 'إدارة الأصول',    icon: 'laptop',             href: '/ar/platform/asset-management' },
      ],
    },
    {
      eyebrow: 'ادفع في أي مكان', title: 'إدارة الفرق العالمية', href: '/ar/global-workforce-management', icon: 'globe',
      bg: '#E2F1D2', fg: '#1B3210', accent: '#2E5119',
      body: 'وظّف موظفين مباشرين، وموظفي EOR، ومتعاقدين في أكثر من 150 دولة — رواتب دقيقة بالعملة المحلية وفي الوقت المحدد.',
      stat: { value: '150+', label: 'دولة مغطّاة' },
      features: [
        { icon: 'briefcase',  label: 'EOR (جهة التوظيف القانونية)', desc: 'وظّف بدون فتح كيان قانوني' },
        { icon: 'building-2', label: 'الرواتب المحلية',             desc: 'إقرارات نظامية تتم تلقائياً' },
        { icon: 'handshake',  label: 'المتعاقدون',                  desc: 'اتفاقيات وفواتير ممتثلة' },
        { icon: 'banknote',   label: 'دفع متعدد العملات',          desc: 'تحويلات محلية، صرف شفاف' },
      ],
      modules: [
        { label: 'الرواتب المحلية',     icon: 'building-2', href: '/ar/platform/local-payroll' },
        { label: 'استرداد المصاريف',   icon: 'receipt',    href: '/ar/platform/expense-reimbursements' },
        { label: 'جهة التوظيف القانونية', icon: 'briefcase',  href: '/ar/platform/employer-of-record' },
        { label: 'المتعاقدون عن بُعد', icon: 'handshake',  href: '/ar/platform/remote-contractors' },
      ],
    },
    {
      eyebrow: 'يعمل دائماً', title: 'وكلاء الذكاء الاصطناعي', href: '/ar/ai', icon: 'sparkles',
      bg: '#F26B4A', fg: '#FFF4EE', accent: '#FFD7C5',
      body: 'وكلاء AI متخصصون يديرون التوظيف والرواتب وعمليات الموظفين بجانب فريقك — بنطاق واضح وسجل تدقيق كامل.',
      stat: { value: '24/7', label: 'يعمل دائماً' },
      features: [
        { icon: 'wallet',        label: 'Payla — وكيل الرواتب', desc: 'يدير الدورات ويرصد الأخطاء' },
        { icon: 'users',         label: 'وكيل التوظيف',         desc: 'بحث، فرز، جدولة مقابلات' },
        { icon: 'life-buoy',     label: 'وكيل دعم الموظفين',    desc: 'يجيب الموظفين فوراً' },
        { icon: 'shield-check',  label: 'سجلات قابلة للتدقيق',  desc: 'كل خطوة موثّقة ومراجعة' },
      ],
      modules: [
        { label: 'نظرة على وكلاء AI',  icon: 'sparkles', href: '/ar/ai' },
        { label: 'Payla — وكيل الرواتب', icon: 'wallet', href: '/ar/agent-payla' },
        { label: 'التوظيف',            icon: 'search',   href: '/ar/platform/recruitment' },
      ],
    },
  ], footer: [
    { label: 'نظرة على HRMS',  href: '/ar/hrms',                          icon: 'layout-grid' },
    { label: 'اعرف الأسعار',   href: '/ar/pricing',                       icon: 'tag' },
    { label: 'احجز عرضاً توضيحياً', href: '/ar/book-a-demo',              icon: 'calendar' },
    { label: 'أدلة الدول',     href: '/ar/guides',                        icon: 'map' },
    { label: 'التكاملات',      href: '/ar/integrations',                  icon: 'plug' },
  ]},
  { label: 'الموارد', href: '#', library: {
    headline: 'الأطلس العالمي',
    tagline: '85 دليل دولة، حاسبات ومراجع — مصنوعة للفِرق التي توظف عبر الحدود.',
    countries: [
      { code: 'eg', name: 'مصر',                  flag: '🇪🇬', slug: 'egypt' },
      { code: 'sa', name: 'السعودية',             flag: '🇸🇦', slug: 'saudi-arabia' },
      { code: 'ae', name: 'الإمارات',             flag: '🇦🇪', slug: 'united-arab-emirates' },
      { code: 'kw', name: 'الكويت',               flag: '🇰🇼', slug: 'kuwait' },
      { code: 'bh', name: 'البحرين',              flag: '🇧🇭', slug: 'bahrain' },
      { code: 'qa', name: 'قطر',                  flag: '🇶🇦', slug: 'qatar' },
      { code: 'jo', name: 'الأردن',               flag: '🇯🇴', slug: 'jordan' },
      { code: 'ma', name: 'المغرب',               flag: '🇲🇦', slug: 'morocco' },
      { code: 'tn', name: 'تونس',                 flag: '🇹🇳', slug: 'tunisia' },
      { code: 'gb', name: 'المملكة المتحدة',     flag: '🇬🇧', slug: 'united-kingdom' },
      { code: 'de', name: 'ألمانيا',              flag: '🇩🇪', slug: 'germany' },
      { code: 'fr', name: 'فرنسا',                flag: '🇫🇷', slug: 'france' },
      { code: 'es', name: 'إسبانيا',              flag: '🇪🇸', slug: 'spain' },
      { code: 'it', name: 'إيطاليا',              flag: '🇮🇹', slug: 'italy' },
      { code: 'nl', name: 'هولندا',               flag: '🇳🇱', slug: 'netherlands' },
      { code: 'ie', name: 'أيرلندا',              flag: '🇮🇪', slug: 'ireland' },
      { code: 'ca', name: 'كندا',                 flag: '🇨🇦', slug: 'canada' },
      { code: 'br', name: 'البرازيل',             flag: '🇧🇷', slug: 'brazil' },
      { code: 'mx', name: 'المكسيك',              flag: '🇲🇽', slug: 'mexico' },
      { code: 'in', name: 'الهند',                flag: '🇮🇳', slug: 'india' },
      { code: 'sg', name: 'سنغافورة',             flag: '🇸🇬', slug: 'singapore' },
      { code: 'au', name: 'أستراليا',             flag: '🇦🇺', slug: 'australia' },
    ],
    tools: [
      { title: 'حاسبة التكاليف', desc: 'اعرف التكلفة الشهرية الكاملة لأي موظف حول العالم', icon: 'calculator', href: '/ar/tools/cost-calculator', tag: 'متاح' },
      { title: 'أدوات الدول',    desc: 'حاسبات سريعة لمهام خاصة بكل دولة',                  icon: 'wrench',     href: '/ar/country-tools',          tag: 'قريباً' },
    ],
    topics: ['ضرائب الرواتب', 'الإجازات النظامية', 'قواعد المكافآت', 'إنهاء الخدمة', 'الأسهم والخيارات', 'المزايا'],
  }, footer: [
    { label: 'اعرف الأسعار',    href: '/ar/pricing',      icon: 'tag' },
    { label: 'احجز عرضاً توضيحياً', href: '/ar/book-a-demo', icon: 'calendar' },
    { label: 'أدلة الدول',      href: '/ar/guides',       icon: 'map' },
    { label: 'التكاملات',       href: '/ar/integrations', icon: 'plug' },
  ]},
  { label: 'الأسعار', href: '/ar/pricing' },
];

const NavDropdown = ({ label, items, groups, cards, footer, library }) => {
  const [open, setOpen] = React.useState(false);
  const [headerEl, setHeaderEl] = React.useState(null);
  const ref = React.useRef(null);
  const closeTimer = React.useRef(null);
  const cancelClose = () => { if (closeTimer.current) { clearTimeout(closeTimer.current); closeTimer.current = null; } };
  const scheduleClose = () => { cancelClose(); closeTimer.current = setTimeout(() => setOpen(false), 180); };
  React.useEffect(() => {
    const handler = (e) => {
      if (!ref.current) return;
      if (ref.current.contains(e.target)) return;
      const panel = document.querySelector('[data-nav-panel]');
      if (panel && panel.contains(e.target)) return;
      setOpen(false);
    };
    document.addEventListener('mousedown', handler);
    if (ref.current) setHeaderEl(ref.current.closest('header'));
    return () => { document.removeEventListener('mousedown', handler); cancelClose(); };
  }, []);
  React.useEffect(() => {
    if (open && window.lucide && window.lucide.createIcons) window.lucide.createIcons();
  }, [open]);
  const isMega = !!(cards || groups || library);
  const linkStyle = { display: 'block', padding: '8px 12px', fontSize: 13, fontWeight: 500, color: '#111210', textDecoration: 'none', borderRadius: 8 };
  const Link = (it) => (
    <a key={it.label} href={it.href} style={linkStyle}
      onMouseOver={e => e.currentTarget.style.background = '#E2F1D2'}
      onMouseOut={e => e.currentTarget.style.background = 'transparent'}>
      {it.label}
    </a>
  );
  return (
    <div ref={ref} style={{ position: 'relative' }}
      onMouseEnter={() => { cancelClose(); setOpen(true); }}
      onMouseLeave={scheduleClose}>
      <button onClick={() => setOpen(o => !o)}
        style={{ background: 'none', border: 'none', cursor: 'pointer', color: '#111210', fontSize: 13, fontWeight: 500, padding: '4px 0', display: 'flex', alignItems: 'center', gap: 4, fontFamily: 'inherit' }}>
        {label}
        <i data-lucide="chevron-down" style={{ width: 13, height: 13, opacity: 0.6, transition: 'transform 0.15s', transform: open ? 'rotate(180deg)' : 'none' }}></i>
      </button>
      {open && (() => {
        const panel = (
          <div data-nav-panel={isMega ? '' : undefined} onMouseEnter={cancelClose} onMouseLeave={scheduleClose} style={{ position: 'absolute', top: '100%', right: isMega ? 0 : 0, left: isMega ? 0 : 'auto', paddingTop: isMega ? 0 : 10, zIndex: 100 }}>
        <div style={{ background: '#FAFAF7', border: '1px solid #E3E8DD', borderRadius: isMega ? 0 : 16, borderTop: isMega ? 'none' : undefined, borderLeft: isMega ? 'none' : undefined, borderRight: isMega ? 'none' : undefined, boxShadow: '0 24px 56px rgba(17,18,16,0.14)', padding: isMega ? '14px 0 14px' : 8, minWidth: isMega ? 0 : 220 }}>
          {cards ? (
            <div style={{ maxWidth: 'var(--max-w-wide, 1200px)', margin: '0 auto', padding: '0 28px' }}>
              <div style={{ display: 'grid', gridTemplateColumns: `repeat(${cards.length}, 1fr)`, gap: 12 }}>
              {cards.map(c => (
                <div key={c.title}
                  style={{ position: 'relative', minWidth: 0, background: c.bg, color: c.fg, borderRadius: 16, padding: 16, display: 'flex', flexDirection: 'column', transition: 'transform 0.2s', boxSizing: 'border-box', overflow: 'hidden', whiteSpace: 'normal' }}
                  onMouseOver={e => { e.currentTarget.style.transform = 'translateY(-4px)'; const a = e.currentTarget.querySelector('[data-arrow]'); if (a) a.style.transform = 'translateX(-4px)'; }}
                  onMouseOut={e => { e.currentTarget.style.transform = 'none'; const a = e.currentTarget.querySelector('[data-arrow]'); if (a) a.style.transform = 'none'; }}>
                  <div aria-hidden="true" style={{ position: 'absolute', left: -40, top: -40, width: 180, height: 180, borderRadius: '50%', background: c.accent, opacity: 0.22 }}></div>
                  <div aria-hidden="true" style={{ position: 'absolute', left: -16, bottom: -16, width: 90, height: 90, borderRadius: '50%', background: c.accent, opacity: 0.14 }}></div>
                  <div style={{ position: 'relative', display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 10 }}>
                    <div style={{ width: 34, height: 34, borderRadius: 10, background: 'rgba(255,255,255,0.14)', border: `1px solid ${c.accent}`, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
                      <i data-lucide={c.icon || 'sparkles'} style={{ width: 16, height: 16, color: c.fg }}></i>
                    </div>
                    {c.stat && (
                      <div style={{ textAlign: 'left' }}>
                        <div style={{ fontFamily: 'var(--font-display)', fontSize: 20, fontWeight: 500, lineHeight: 1, letterSpacing: '-0.02em' }}>{c.stat.value}</div>
                        <div style={{ fontFamily: 'var(--font-mono)', fontSize: 9, letterSpacing: '0.1em', color: c.accent, marginTop: 2 }}>{c.stat.label}</div>
                      </div>
                    )}
                  </div>
                  <div style={{ position: 'relative', fontFamily: 'var(--font-mono)', fontSize: 9.5, letterSpacing: '0.08em', color: c.accent, marginBottom: 4 }}>{c.eyebrow}</div>
                  <div style={{ position: 'relative', fontFamily: 'var(--font-display)', fontSize: 20, fontWeight: 500, letterSpacing: '-0.02em', lineHeight: 1.2, marginBottom: 6 }}>{c.title}</div>
                  <div style={{ position: 'relative', fontSize: 12, lineHeight: 1.6, opacity: 0.88, marginBottom: 10, overflowWrap: 'break-word' }}>{c.body}</div>
                  {c.features && (
                    <ul style={{ position: 'relative', listStyle: 'none', padding: 0, margin: '0 0 10px', display: 'flex', flexDirection: 'column', gap: 5 }}>
                      {c.features.map(f => (
                        <li key={f.label || f} style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
                          <span style={{ flexShrink: 0, width: 20, height: 20, borderRadius: 6, background: 'rgba(255,255,255,0.12)', border: `1px solid ${c.accent}`, display: 'inline-flex', alignItems: 'center', justifyContent: 'center' }}>
                            <i data-lucide={f.icon || 'check'} style={{ width: 11, height: 11, color: c.fg }}></i>
                          </span>
                          <span style={{ fontSize: 11.5, fontWeight: 500, lineHeight: 1.4 }}>{f.label || f}</span>
                        </li>
                      ))}
                    </ul>
                  )}
                  {c.modules && (
                    <div style={{ position: 'relative', paddingTop: 10, marginBottom: 10, borderTop: `1px solid ${c.accent}33` }}>
                      <div style={{ fontFamily: 'var(--font-mono)', fontSize: 8.5, letterSpacing: '0.08em', color: c.accent, marginBottom: 6, opacity: 0.95 }}>الوحدات</div>
                      <div style={{ display: 'flex', flexWrap: 'wrap', gap: 5 }}>
                        {c.modules.map(m => (
                          <a key={m.label} href={m.href}
                            onClick={e => e.stopPropagation()}
                            style={{ display: 'inline-flex', alignItems: 'center', gap: 5, padding: '4px 9px', borderRadius: 999, background: 'rgba(255,255,255,0.10)', border: `1px solid ${c.accent}66`, color: c.fg, fontSize: 10.5, fontWeight: 500, textDecoration: 'none', transition: 'background 0.15s, border-color 0.15s' }}
                            onMouseOver={e => { e.currentTarget.style.background = 'rgba(255,255,255,0.22)'; e.currentTarget.style.borderColor = c.accent; }}
                            onMouseOut={e => { e.currentTarget.style.background = 'rgba(255,255,255,0.10)'; e.currentTarget.style.borderColor = `${c.accent}66`; }}>
                            <i data-lucide={m.icon || 'circle'} style={{ width: 10, height: 10 }}></i>
                            {m.label}
                          </a>
                        ))}
                      </div>
                    </div>
                  )}
                  <a href={c.href} style={{ position: 'relative', marginTop: 'auto', fontSize: 12, fontWeight: 600, display: 'inline-flex', alignItems: 'center', gap: 5, borderBottom: `1px solid ${c.accent}`, paddingBottom: 2, alignSelf: 'flex-start', color: c.fg, textDecoration: 'none' }}>
                    اكتشف {c.title} <i data-arrow data-lucide="arrow-left" style={{ width: 12, height: 12, transition: 'transform 0.18s' }}></i>
                  </a>
                </div>
              ))}
              </div>
              {footer && (
                <div style={{ marginTop: 12, paddingTop: 10, borderTop: '1px solid #E3E8DD', display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 18, flexWrap: 'wrap' }}>
                  <div style={{ fontFamily: 'var(--font-mono)', fontSize: 10.5, letterSpacing: '0.08em', color: '#6B6F65' }}>روابط سريعة</div>
                  <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
                    {footer.map(f => (
                      <a key={f.label} href={f.href}
                        style={{ display: 'inline-flex', alignItems: 'center', gap: 6, padding: '8px 12px', borderRadius: 999, background: '#fff', border: '1px solid #E3E8DD', color: '#111210', fontSize: 12.5, fontWeight: 500, textDecoration: 'none', transition: 'background 0.15s, border-color 0.15s' }}
                        onMouseOver={e => { e.currentTarget.style.background = '#E2F1D2'; e.currentTarget.style.borderColor = '#A4CC7C'; }}
                        onMouseOut={e => { e.currentTarget.style.background = '#fff'; e.currentTarget.style.borderColor = '#E3E8DD'; }}>
                        <i data-lucide={f.icon} style={{ width: 13, height: 13 }}></i>
                        {f.label}
                      </a>
                    ))}
                  </div>
                </div>
              )}
            </div>
          ) : library ? (
            <div style={{ maxWidth: 'var(--max-w-wide, 1200px)', margin: '0 auto', padding: '0 28px' }}>
              <div style={{ position: 'relative', display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 18, padding: '10px 14px', marginBottom: 12, borderRadius: 14, background: 'linear-gradient(135deg, #2E5119 0%, #1B3210 100%)', color: '#E2F1D2', overflow: 'hidden' }}>
                <div aria-hidden="true" style={{ position: 'absolute', left: -30, top: -30, width: 160, height: 160, borderRadius: '50%', background: '#A4CC7C', opacity: 0.18 }}></div>
                <div style={{ position: 'relative', display: 'flex', alignItems: 'center', gap: 12 }}>
                  <div style={{ width: 38, height: 38, borderRadius: 10, background: 'rgba(255,255,255,0.12)', border: '1px solid #A4CC7C', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
                    <i data-lucide="library" style={{ width: 18, height: 18, color: '#E2F1D2' }}></i>
                  </div>
                  <div>
                    <div style={{ fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.08em', color: '#FFD86B' }}>الموارد</div>
                    <div style={{ fontFamily: 'var(--font-display)', fontSize: 20, fontWeight: 500, letterSpacing: '-0.02em', lineHeight: 1.3, marginTop: 1, color: '#FFFFFF' }}>{library.headline}</div>
                  </div>
                </div>
                <div style={{ position: 'relative', fontSize: 12.5, lineHeight: 1.6, opacity: 0.9, maxWidth: 420, whiteSpace: 'normal' }}>{library.tagline}</div>
                <a href="/ar/guides" style={{ position: 'relative', display: 'inline-flex', alignItems: 'center', gap: 6, padding: '8px 14px', borderRadius: 999, background: '#F26B4A', color: '#fff', fontSize: 12.5, fontWeight: 600, textDecoration: 'none', whiteSpace: 'nowrap', boxShadow: '0 6px 16px rgba(242,107,74,0.32)' }}>
                  <i data-lucide="arrow-left" style={{ width: 13, height: 13 }}></i>
                  تصفّح الـ85
                </a>
              </div>
              <div style={{ display: 'grid', gridTemplateColumns: '1.55fr 1fr', gap: 12 }}>
                <div style={{ position: 'relative', minWidth: 0, background: '#fff', border: '1px solid #E3E8DD', borderRadius: 14, padding: 14, overflow: 'hidden', whiteSpace: 'normal' }}>
                  <div aria-hidden="true" style={{ position: 'absolute', left: -50, top: -50, width: 180, height: 180, borderRadius: '50%', background: '#E2F1D2', opacity: 0.55 }}></div>
                  <div style={{ position: 'relative', display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 10 }}>
                    <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
                      <i data-lucide="globe-2" style={{ width: 14, height: 14, color: '#2E5119' }}></i>
                      <div style={{ fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.08em', color: '#2E5119' }}>أدلة الدول</div>
                    </div>
                    <a href="/ar/guides" style={{ fontSize: 11.5, fontWeight: 600, color: '#2E5119', textDecoration: 'none', display: 'inline-flex', alignItems: 'center', gap: 4, whiteSpace: 'nowrap' }}>
                      عرض الكل <i data-lucide="arrow-left" style={{ width: 11, height: 11 }}></i>
                    </a>
                  </div>
                  <div style={{ position: 'relative', display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 6 }}>
                    {library.countries.map(c => (
                      <a key={c.code} href={`/ar/guides/${c.slug}`}
                        style={{ display: 'flex', alignItems: 'center', gap: 8, padding: '8px 10px', borderRadius: 9, border: '1px solid #E3E8DD', background: '#FFFFFF', textDecoration: 'none', color: '#111210', transition: 'transform 0.12s, border-color 0.12s, background 0.12s', whiteSpace: 'normal', minWidth: 0 }}
                        onMouseOver={e => { e.currentTarget.style.background = '#E2F1D2'; e.currentTarget.style.borderColor = '#A4CC7C'; e.currentTarget.style.transform = 'translateY(-1px)'; }}
                        onMouseOut={e => { e.currentTarget.style.background = '#FFFFFF'; e.currentTarget.style.borderColor = '#E3E8DD'; e.currentTarget.style.transform = 'none'; }}>
                        <span style={{ fontSize: 20, lineHeight: 1, flexShrink: 0 }}>{c.flag}</span>
                        <span style={{ fontSize: 12, fontWeight: 600, lineHeight: 1.4, color: '#1B3210', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{c.name}</span>
                      </a>
                    ))}
                  </div>
                  <div style={{ position: 'relative', marginTop: 10, paddingTop: 10, borderTop: '1px dashed #CFD6C7', display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
                    <span style={{ fontFamily: 'var(--font-mono)', fontSize: 9.5, letterSpacing: '0.08em', color: '#6B6F65', marginLeft: 4 }}>المواضيع</span>
                    {library.topics.map(t => (
                      <a key={t} href="/ar/guides" style={{ fontSize: 11, color: '#2E5119', textDecoration: 'none', padding: '3px 8px', borderRadius: 999, background: '#E2F1D2', whiteSpace: 'nowrap' }}>{t}</a>
                    ))}
                  </div>
                </div>
                <div style={{ display: 'flex', flexDirection: 'column', gap: 8, minWidth: 0 }}>
                  {library.tools.map(t => (
                    <a key={t.title} href={t.href}
                      style={{ position: 'relative', display: 'flex', gap: 12, padding: 14, borderRadius: 14, background: '#fff', border: '1px solid #E3E8DD', textDecoration: 'none', color: '#111210', transition: 'transform 0.15s, box-shadow 0.15s, border-color 0.15s', overflow: 'hidden', whiteSpace: 'normal', minWidth: 0 }}
                      onMouseOver={e => { e.currentTarget.style.transform = 'translateY(-2px)'; e.currentTarget.style.boxShadow = '0 12px 28px rgba(17,18,16,0.08)'; e.currentTarget.style.borderColor = '#A4CC7C'; }}
                      onMouseOut={e => { e.currentTarget.style.transform = 'none'; e.currentTarget.style.boxShadow = 'none'; e.currentTarget.style.borderColor = '#E3E8DD'; }}>
                      <div aria-hidden="true" style={{ position: 'absolute', left: -20, top: -20, width: 80, height: 80, borderRadius: '50%', background: t.tag === 'متاح' ? '#FFE7DD' : '#E6F1F6', opacity: 0.7 }}></div>
                      <div style={{ position: 'relative', flexShrink: 0, width: 42, height: 42, borderRadius: 11, background: t.tag === 'متاح' ? '#F26B4A' : '#2E5119', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
                        <i data-lucide={t.icon} style={{ width: 18, height: 18, color: '#fff' }}></i>
                      </div>
                      <div style={{ position: 'relative', minWidth: 0, flex: 1 }}>
                        <div style={{ display: 'flex', alignItems: 'center', gap: 6, marginBottom: 3 }}>
                          <span style={{ fontFamily: 'var(--font-display)', fontSize: 16, fontWeight: 500, letterSpacing: '-0.01em' }}>{t.title}</span>
                          <span style={{ fontFamily: 'var(--font-mono)', fontSize: 8.5, letterSpacing: '0.08em', padding: '2px 7px', borderRadius: 999, background: t.tag === 'متاح' ? '#E2F1D2' : '#F6F7F2', color: t.tag === 'متاح' ? '#2E5119' : '#6B6F65' }}>{t.tag}</span>
                        </div>
                        <div style={{ fontSize: 11.5, color: '#6B6F65', lineHeight: 1.6 }}>{t.desc}</div>
                      </div>
                      <i data-lucide="arrow-left" style={{ position: 'relative', width: 14, height: 14, alignSelf: 'center', color: '#2E5119', flexShrink: 0 }}></i>
                    </a>
                  ))}
                  <div style={{ position: 'relative', padding: 12, borderRadius: 12, background: '#F6F7F2', border: '1px dashed #CFD6C7', display: 'flex', alignItems: 'center', gap: 10, whiteSpace: 'normal' }}>
                    <i data-lucide="lightbulb" style={{ width: 16, height: 16, color: '#74B144', flexShrink: 0 }}></i>
                    <div style={{ fontSize: 11.5, lineHeight: 1.6, color: '#3a3d36' }}>أدوات جديدة تنزل شهرياً. <a href="/ar/contact" style={{ color: '#2E5119', fontWeight: 600 }}>قل لنا ما تحتاج ←</a></div>
                  </div>
                </div>
              </div>
              {footer && (
                <div style={{ marginTop: 14, paddingTop: 12, borderTop: '1px solid #E3E8DD', display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 18, flexWrap: 'wrap' }}>
                  <div style={{ fontFamily: 'var(--font-mono)', fontSize: 10.5, letterSpacing: '0.08em', color: '#6B6F65' }}>روابط سريعة</div>
                  <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
                    {footer.map(f => (
                      <a key={f.label} href={f.href}
                        style={{ display: 'inline-flex', alignItems: 'center', gap: 6, padding: '8px 12px', borderRadius: 999, background: '#fff', border: '1px solid #E3E8DD', color: '#111210', fontSize: 12.5, fontWeight: 500, textDecoration: 'none', transition: 'background 0.15s, border-color 0.15s', whiteSpace: 'normal' }}
                        onMouseOver={e => { e.currentTarget.style.background = '#E2F1D2'; e.currentTarget.style.borderColor = '#A4CC7C'; }}
                        onMouseOut={e => { e.currentTarget.style.background = '#fff'; e.currentTarget.style.borderColor = '#E3E8DD'; }}>
                        <i data-lucide={f.icon} style={{ width: 13, height: 13 }}></i>
                        {f.label}
                      </a>
                    ))}
                  </div>
                </div>
              )}
            </div>
          ) : items.map(Link)}
        </div>
          </div>
        );
        return isMega && headerEl ? ReactDOM.createPortal(panel, headerEl) : panel;
      })()}
    </div>
  );
};

// ----------------- Header (with mobile menu) -----------------
const SiteHeader = ({ active }) => {
  const [open, setOpen] = React.useState(false);
  const enHref = (typeof window !== 'undefined')
    ? (window.location.pathname.replace(/^\/ar(?=\/|$)/, '') || '/')
    : '/';

  return (
    <header className="rmh-header">
      <style>{`
        .rmh-header {
          position: sticky; top: 0; z-index: 50;
          background: rgba(250,250,247,0.88);
          backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
          border-bottom: 1px solid rgba(17,18,16,0.06);
        }
        .rmh-header-row {
          max-width: var(--max-w-wide); margin: 0 auto;
          padding: 12px 28px;
          display: flex; align-items: center; gap: 18px;
        }
        .rmh-header-logo img { height: 38px; display: block; }
        @media (max-width: 980px) { .rmh-header-logo img { height: 32px; } }
        @media (max-width: 480px) { .rmh-header-logo img { height: 30px; } }
        .rmh-header-nav {
          display: flex; gap: 18px; flex: 1; min-width: 0;
          justify-content: center; align-items: center;
        }
        .rmh-header-nav a {
          color: #111210; font-size: 13px; font-weight: 500;
          text-decoration: none; position: relative;
          white-space: nowrap; padding: 4px 0;
        }
        .rmh-header-nav a.active { color: #2E5119; }
        .rmh-header-nav a.active::after {
          content: ""; position: absolute; left: 0; right: 0; bottom: -17px;
          height: 2px; background: #F26B4A; border-radius: 1px;
        }
        .rmh-header-cta { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
        .rmh-header-cta-primary {
          background: #F26B4A; color: #fff; text-decoration: none;
          padding: 9px 16px; border-radius: 11px; font-weight: 600; font-size: 13px;
          box-shadow: 0 6px 16px rgba(242,107,74,0.32); white-space: nowrap;
        }
        .rmh-lang-switch {
          display: inline-flex; align-items: center; justify-content: center;
          background: #F6F7F2; color: #2E5119; text-decoration: none;
          padding: 8px 14px; border-radius: 999px; font-weight: 600; font-size: 13px;
          border: 1px solid #E3E8DD; min-height: 36px;
        }
        .rmh-lang-switch:hover { background: #E2F1D2; border-color: #A4CC7C; }
        .rmh-lang-switch-mobile { display: none; }
        .rmh-header-burger {
          display: none; background: #2E5119; border: none;
          border-radius: 12px; padding: 10px 12px; cursor: pointer; color: #FAFAF7;
          box-shadow: 0 4px 12px rgba(46,81,25,0.22); transition: transform 0.15s ease, box-shadow 0.15s ease;
          min-width: 44px; min-height: 44px;
        }
        .rmh-header-burger:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(46,81,25,0.28); }
        .rmh-header-burger:active { transform: translateY(0); }
        .rmh-mobile-panel { display: none; }
        @media (max-width: 980px) {
          .rmh-header-row { padding: 10px 16px; gap: 12px; justify-content: space-between; }
          .rmh-header-nav { display: none; }
          .rmh-header-cta { margin-right: auto; margin-left: 0; }
          .rmh-header-burger { display: inline-flex; align-items: center; justify-content: center; }
          .rmh-mobile-panel {
            display: ${open ? 'block' : 'none'};
            position: absolute; left: 0; right: 0; top: 100%;
            background: #FAFAF7; border-bottom: 1px solid rgba(17,18,16,0.08);
            box-shadow: 0 20px 40px rgba(17,18,16,0.10);
            padding: 14px 16px 20px;
          }
          .rmh-mobile-panel a {
            display: block; padding: 14px 8px; font-size: 15px; font-weight: 500;
            color: #111210; text-decoration: none; border-bottom: 1px solid rgba(17,18,16,0.06);
            min-height: 44px;
          }
          .rmh-mobile-panel a.active { color: #2E5119; }
          .rmh-mobile-panel-cta { margin-top: 14px; }
        }
        @media (max-width: 560px) {
          .rmh-header-cta-primary { display: none; }
          .rmh-lang-switch { display: none; }
          .rmh-lang-switch-mobile { display: flex; }
        }
      `}</style>
      <div className="rmh-header-row">
        <a href="/ar" className="rmh-header-logo" style={{ display: 'flex', alignItems: 'center', gap: 8, textDecoration: 'none', flexShrink: 0 }}>
          <img src="/assets/logo-horizontal-mint.svg" alt="Remote&" />
        </a>
        <nav className="rmh-header-nav">
          {NAV_ITEMS.map(n => (n.items || n.groups || n.cards || n.library)
            ? <NavDropdown key={n.label} label={n.label} items={n.items} groups={n.groups} cards={n.cards} library={n.library} footer={n.footer} />
            : <a key={n.label} href={n.href} className={active === n.href ? 'active' : ''}>{n.label}</a>
          )}
        </nav>
        <div className="rmh-header-cta">
          <a href={enHref} className="rmh-lang-switch" aria-label="English">EN</a>
          <a href="/ar/book-a-demo" className="rmh-header-cta-primary">احجز عرضاً توضيحياً</a>
          <button className="rmh-header-burger" aria-label="القائمة" onClick={() => setOpen(o => !o)}>
            <i data-lucide={open ? 'x' : 'menu'} style={{ width: 20, height: 20 }}></i>
          </button>
        </div>
      </div>
      <div className="rmh-mobile-panel">
        {NAV_ITEMS.flatMap(n => {
          if (n.groups) return n.groups.flatMap(g => [
            <div key={n.label + g.title} style={{ fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.06em', color: '#2E5119', padding: '14px 8px 4px' }}>{g.title}</div>,
            ...g.items.map(it => <a key={it.label} href={it.href}>{it.label}</a>),
          ]);
          if (n.cards) return n.cards.flatMap(c => [
            <div key={n.label + c.title} style={{ fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.06em', color: '#2E5119', padding: '14px 8px 4px' }}>{c.title}</div>,
            <a key={c.title} href={c.href}>نظرة على {c.title}</a>,
            ...(c.modules || []).map(m => <a key={c.title + m.label} href={m.href}>{m.label}</a>),
          ]);
          if (n.library) return [
            <a key="guides" href="/ar/guides">أدلة الدول</a>,
            ...n.library.tools.map(t => <a key={t.title} href={t.href}>{t.title}</a>),
          ];
          if (n.items) return n.items.map(it => <a key={it.label} href={it.href}>{it.label}</a>);
          return [<a key={n.label} href={n.href} className={active === n.href ? 'active' : ''}>{n.label}</a>];
        })}
        <a className="rmh-mobile-panel-cta" href="/ar/book-a-demo" style={{ background: '#F26B4A', color: '#fff', textAlign: 'center', borderRadius: 12, fontWeight: 600, padding: '14px 16px', borderBottom: 'none' }}>احجز عرضاً توضيحياً</a>
        <a href={enHref} className="rmh-lang-switch-mobile" style={{ display: 'block', textAlign: 'center', background: '#F6F7F2', color: '#2E5119', borderRadius: 12, fontWeight: 600, padding: '12px 16px', marginTop: 10, borderBottom: 'none', border: '1px solid #E3E8DD', textDecoration: 'none' }}>English</a>
      </div>
    </header>
  );
};

// ----------------- Top notice strip -----------------
const SiteNotice = () => (
  <div style={{ background: 'linear-gradient(90deg, #2E5119 0%, #15554B 55%, #2E8C7D 100%)', color: '#FFFFFF', padding: '12px clamp(14px, 4vw, 32px)', textAlign: 'center', fontSize: 14, position: 'relative', zIndex: 60, overflow: 'hidden' }}>
    <style>{`
      .rmh-notice-inner { display:inline-flex; align-items:center; gap:12px; flex-wrap:wrap; justify-content:center; row-gap:8px; }
      .rmh-notice-claim { display:inline-flex; align-items:center; gap:6px; background:#FFFFFF; color:#2E5119; text-decoration:none; padding:9px 18px; border-radius:999px; font-size:13px; font-weight:600; min-height:36px; }
      @media (max-width: 560px) {
        .rmh-notice-inner { gap:8px; font-size:12.5px; }
        .rmh-notice-ending { display:none; }
      }
    `}</style>
    <span aria-hidden="true" style={{ position: 'absolute', left: -40, top: -60, fontFamily: 'var(--font-serif)', fontStyle: 'italic', fontSize: 140, color: 'rgba(255,255,255,0.06)', lineHeight: 1, pointerEvents: 'none', userSelect: 'none' }}>&amp;</span>
    <span className="rmh-notice-inner" style={{ position: 'relative' }}>
      <span style={{ background: '#F26B4A', color: '#FFFFFF', fontFamily: 'var(--font-mono)', fontSize: 10.5, padding: '4px 10px', borderRadius: 999, letterSpacing: '0.06em', fontWeight: 700, boxShadow: '0 4px 12px rgba(242,107,74,0.35)' }}>عرض إطلاق حصري</span>
      <span style={{ fontWeight: 500 }}>
        مجاناً لأول <strong style={{ color: '#FFD86B', fontWeight: 700 }}>30 موظفاً</strong> — HRMS كامل <span style={{ fontFamily: 'var(--font-serif)', fontStyle: 'italic', color: '#FFD86B' }}>&amp;</span> جميع وكلاء الذكاء الاصطناعي.
      </span>
      <span className="rmh-notice-ending" style={{ fontFamily: 'var(--font-mono)', fontSize: 11, color: '#FFD86B', letterSpacing: '0.06em' }}>⏳ ينتهي قريباً</span>
      <a href="/ar/book-a-demo" className="rmh-notice-claim">
        احصل عليه <span aria-hidden="true">←</span>
      </a>
    </span>
  </div>
);

// ----------------- Final CTA band -----------------
const FinalCTA = () => (
  <section style={{ background: '#FAFAF7', padding: '88px 0 0' }}>
    <div style={{ maxWidth: 'var(--max-w-wide)', margin: '0 auto', padding: '0 24px' }}>
      <div style={{
        background: '#FFF4DD', borderRadius: 24,
        padding: '40px 32px', display: 'flex',
        alignItems: 'center', gap: 24, flexWrap: 'wrap', justifyContent: 'space-between',
        marginBottom: 80,
      }}>
        <h3 style={{ fontFamily: 'var(--font-serif)', fontStyle: 'italic', fontSize: 'clamp(24px, 3.4vw, 36px)', fontWeight: 400, margin: 0, color: '#1B3210', letterSpacing: '-0.02em' }}>
          جرّبه على فريقك.
        </h3>
        <div style={{ display: 'flex', gap: 12, alignItems: 'center', flexWrap: 'wrap' }}>
          <a href="/ar/book-a-demo" style={{ background: '#F26B4A', color: '#fff', textDecoration: 'none', padding: '12px 22px', borderRadius: 12, fontWeight: 600, fontSize: 14, boxShadow: '0 6px 18px rgba(242,107,74,0.28)' }}>احجز عرضاً توضيحياً</a>
        </div>
      </div>
    </div>
  </section>
);

// ----------------- Footer -----------------
const SiteFooter = () => (
  <footer style={{ background: '#C8E6A8', color: '#1B3210', padding: '72px 0 32px' }}>
    <style>{`
      .rmh-footer-grid {
        display: grid;
        grid-template-columns: 2fr 1fr 1fr 1fr;
        gap: 32px; margin-bottom: 48px;
      }
      @media (max-width: 900px) {
        .rmh-footer-grid { grid-template-columns: 1fr 1fr; gap: 28px 24px; }
      }
      @media (max-width: 560px) {
        .rmh-footer-grid { grid-template-columns: 1fr; gap: 24px; }
      }
    `}</style>
    <div style={{ maxWidth: 'var(--max-w-wide)', margin: '0 auto', padding: '0 24px' }}>
      <div className="rmh-footer-grid">
        <div>
          <img src="/assets/logo-horizontal-mint.svg" alt="Remote&" style={{ height: 30 }} />
          <p style={{ marginTop: 16, fontSize: 14, lineHeight: 1.6, color: '#2E5119', maxWidth: 320 }}>
            نظام الذكاء الاصطناعي للموارد البشرية للتوظيف والدفع ودعم الفِرق في أكثر من 150 دولة.
          </p>
          <div style={{ display: 'flex', gap: 8, marginTop: 18 }}>
            {['linkedin','twitter','github'].map(ic => (
              <span key={ic} style={{ width: 32, height: 32, borderRadius: 8, background: '#FAFAF7', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', color: '#2E5119' }}>
                <i data-lucide={ic} style={{ width: 14, height: 14 }}></i>
              </span>
            ))}
          </div>
        </div>
        {[
          { h: 'المنصة', items: [
            { label: 'HRMS', href: '/ar/hrms' },
            { label: 'إدارة الفرق العالمية', href: '/ar/global-workforce-management' },
            { label: 'وكلاء الذكاء الاصطناعي', href: '/ar/ai' },
            { label: 'الأسعار', href: '/ar/pricing' },
          ] },
          { h: 'الموارد', items: [
            { label: 'أدوات الدول', href: '/ar/country-tools' },
            { label: 'التكاملات', href: '/ar/integrations' },
            { label: 'الأمان والثقة', href: '/ar/trust' },
          ] },
          { h: 'الشركة', items: [
            { label: 'عن الشركة', href: '/ar/about' },
            { label: 'تواصل معنا', href: '/ar/contact' },
            { label: 'احجز عرضاً توضيحياً', href: '/ar/book-a-demo' },
            { label: 'الشروط والأحكام', href: '/ar/legal/terms-and-conditions' },
          ] },
        ].map(col => (
          <div key={col.h}>
            <div style={{ fontFamily: 'var(--font-mono)', fontSize: 10, color: '#2E5119', letterSpacing: '0.06em', marginBottom: 14 }}>{col.h}</div>
            {col.items.map(it => <a key={it.label} href={it.href} style={{ display: 'block', fontSize: 14, color: '#1B3210', padding: '8px 0', textDecoration: 'none', minHeight: 36 }}>{it.label}</a>)}
          </div>
        ))}
      </div>
      <div style={{ borderTop: '1px solid rgba(27,50,16,0.18)', paddingTop: 24, display: 'flex', justifyContent: 'space-between', fontSize: 12, color: '#2E5119', flexWrap: 'wrap', gap: 12 }}>
        <span>© 2026 Remote&amp;.</span>
        <span>مصنوع للفِرق العالمية.</span>
      </div>
    </div>
  </footer>
);

// ----------------- Helpers -----------------
const Eyebrow = ({ children, color = '#2E5119' }) => (
  <p style={{
    fontFamily: 'var(--font-mono)', fontSize: 12, fontWeight: 500,
    letterSpacing: '0.06em',
    color, margin: '0 0 16px',
  }}>{children}</p>
);

const Amp = ({ color = '#F26B4A', size = '1.05em' }) => (
  <span style={{ fontFamily: 'var(--font-serif)', fontStyle: 'italic', color, fontSize: size, fontWeight: 400 }}>&amp;</span>
);

const SiteLogoStrip = () => null;

const LogoTile = ({ name, slug, mono = false }) => {
  const [failed, setFailed] = React.useState(false);
  const computedSlug = (slug || name).toLowerCase().replace(/[^a-z0-9]+/g, '');
  const src = mono
    ? `https://cdn.simpleicons.org/${computedSlug}/353833`
    : `https://cdn.simpleicons.org/${computedSlug}`;
  return (
    <div style={{
      background: '#FFFFFF', border: '1px solid #E3E8DD', borderRadius: 12,
      padding: '14px 12px', display: 'flex', alignItems: 'center',
      justifyContent: 'center', gap: 10, minHeight: 56,
    }}>
      {failed ? (
        <span style={{
          width: 22, height: 22, borderRadius: 5,
          background: '#E2F1D2', color: '#2E5119', fontSize: 11, fontWeight: 600,
          display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
        }}>{name[0]}</span>
      ) : (
        <img src={src} alt="" style={{ width: 22, height: 22, objectFit: 'contain' }} onError={() => setFailed(true)} />
      )}
      <span style={{ fontSize: 13, fontWeight: 500, color: '#353833' }}>{name}</span>
    </div>
  );
};

Object.assign(window, { SiteHeader, SiteNotice, SiteFooter, SiteLogoStrip, FinalCTA, Eyebrow, Amp, LogoTile });
