<?php
$lang   = stb_lang();
$is_rtl = stb_is_rtl_lang();
$dir    = $is_rtl ? 'rtl' : 'ltr';
$ln     = ['en'=>'en-US','fa'=>'fa-IR','ar'=>'ar','ru'=>'ru-RU','es'=>'es-ES'];
$html_lang = $ln[$lang] ?? 'en-US';

// ── Nav data — 5 ecosystem divisions + Company ──────────────────────────────
$nav = [
  'broker' => [
    'label' => $lang==='fa' ? 'بروکر' : 'Broker',
    'icon'  => '<path d="M3 3v18h18" stroke-width="1.5"/><polyline points="7 16 11 10 15 14 19 7" stroke-width="1.5"/>',
    'color' => '#C8102E',
    'items' => $lang==='fa' ? [
      ['حساب‌های معاملاتی','/NewSite/trading-accounts/','حساب استاندارد، ECN، پرایم، Zero'],
      ['بازارها','/NewSite/markets/','۳۵۰+ ابزار CFD و اسپات'],
      ['پلتفرم‌ها','/NewSite/platforms/','MetaTrader 5 — نسخه کامل'],
      ['اجرا و اسپرد','/NewSite/execution/','اسپرد از ۰.۰ پیپ، NDD'],
      ['واریز و برداشت','/NewSite/deposit/','واریز آنی و بدون کارمزد'],
    ] : [
      ['Trading Accounts','/NewSite/trading-accounts/','Standard, ECN, Prime, Zero'],
      ['Markets','/NewSite/markets/','350+ CFD & Spot instruments'],
      ['Platforms','/NewSite/platforms/','MetaTrader 5 — Full power'],
      ['Execution & Spreads','/NewSite/execution/','From 0.0 pips, NDD, STP/ECN'],
      ['Deposit & Withdrawal','/NewSite/deposit/','Instant, zero-fee deposits'],
    ],
  ],
  'investment' => [
    'label' => $lang==='fa' ? 'سرمایه‌گذاری' : 'Investment',
    'icon'  => '<path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z" stroke-width="1.5"/>',
    'color' => '#C8102E',
    'items' => $lang==='fa' ? [
      ['PAMM','/NewSite/pamm/','سرمایه‌گذاری در مدیران تأیید شده'],
      ['کپی تریدینگ','/NewSite/copy-trading/','دنبال کردن معامله‌گران برتر'],
    ] : [
      ['PAMM','/NewSite/pamm/','Invest in verified professional managers'],
      ['Copy Trading','/NewSite/copy-trading/','Follow top-performing traders'],
    ],
  ],
  // 'venture' => [
  //   'label' => $lang==='fa' ? 'ونچر' : 'Venture',
  //   'icon'  => '<path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z" stroke-width="1.5" stroke-linecap="round"/>',
  //   'color' => '#14e0a3',
  //   'items' => $lang==='fa' ? [
  //     ['چالش دو مرحله‌ای','/NewSite/venture/','هدف ۸٪ و ۵٪، بدون محدودیت زمانی'],
  //     ['چالش یک مرحله‌ای','/NewSite/venture/','هدف ۱۰٪، سریع‌تر'],
  //     ['فاندد فوری','/NewSite/venture/','واریز فوری بدون ارزیابی'],
  //     ['قوانین و شرایط','/NewSite/venture/','همه جزئیات برنامه'],
  //   ] : [
  //     ['2-Step Challenge','/NewSite/venture/','8% & 5% targets, no time limit'],
  //     ['1-Step Challenge','/NewSite/venture/','10% target, faster path'],
  //     ['Instant Funded','/NewSite/venture/','Funded immediately, no evaluation'],
  //     ['Rules & Conditions','/NewSite/venture/','Full programme details'],
  //   ],
  // ],
  'academy' => [
    'label' => $lang==='fa' ? 'آکادمی' : 'Academy',
    'icon'  => '<path d="M22 10v6M2 10l10-5 10 5-10 5-10-5z" stroke-width="1.5"/><path d="M6 12v5c0 2.21 2.686 4 6 4s6-1.79 6-4v-5" stroke-width="1.5"/>',
    'color' => '#14e0a3',
    'items' => $lang==='fa' ? [
      ['دوره‌های معاملاتی','/NewSite/academy/','۵ دوره ساختاریافته، رایگان'],
      ['وبینارهای زنده','/NewSite/webinar/','جلسات زنده و ضبط‌شده'],
      ['دانشنامه','/encyclopedia/','۱۰۰+ اصطلاح معاملاتی A–Z'],
      ['مقالات بازار','/NewSite/blog/','تحلیل و استراتژی'],
    ] : [
      ['Trading Courses','/NewSite/academy/','5 structured courses, free'],
      ['Live Webinars','/NewSite/webinar/','Live sessions & on-demand recordings'],
      ['Encyclopedia','/encyclopedia/','100+ trading terms A–Z'],
      ['Market Articles','/NewSite/blog/','Analysis, strategy & psychology'],
    ],
  ],
  'society' => [
    'label' => $lang==='fa' ? 'جامعه' : 'Society',
    'icon'  => '<path d="M17 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2" stroke-width="1.5"/><circle cx="9" cy="7" r="4" stroke-width="1.5"/><path d="M23 21v-2a4 4 0 00-3-3.87M16 3.13a4 4 0 010 7.75" stroke-width="1.5"/>',
    'color' => '#C8102E',
    'items' => $lang==='fa' ? [
      ['معرفی بروکر (IB)','/NewSite/ib/','کمیسیون مادام‌العمر بر اساس حجم'],
      ['برنامه همکاری','/NewSite/affiliate/','CPA، RevShare و ترکیبی'],
      ['سفیر برند','/NewSite/ambassador/','برنامه سفیر STB'],
      ['فروشگاه جامعه','/NewSite/community-shop/','دسترسی بر اساس تراز حساب'],
    ] : [
      ['Introducing Broker (IB)','/NewSite/ib/','Lifetime commissions on volume'],
      ['Affiliate Program','/NewSite/affiliate/','CPA, RevShare & Hybrid models'],
      ['Brand Ambassador','/NewSite/ambassador/','STB Ambassador programme'],
      ['Community Shop','/NewSite/community-shop/','Access based on account tier'],
    ],
  ],
  'company' => [
    'label' => $lang==='fa' ? 'شرکت' : 'Company',
    'icon'  => '<circle cx="12" cy="12" r="10" stroke-width="1.5"/><path d="M12 8v4l3 3" stroke-width="1.5" stroke-linecap="round"/>',
    'color' => '#C8102E',
    'items' => $lang==='fa' ? [
      ['درباره ما','/NewSite/company/','داستان و مأموریت STB'],
      ['تماس با ما','/NewSite/contact/','پشتیبانی ۲۴/۷'],
      ['اسناد قانونی','/NewSite/legal/','مجوز، سیاست‌ها، افشا'],
      ['سوالات متداول','/NewSite/faq/','پاسخ به سوالات رایج'],
      ['ابزارها','/NewSite/tools/','ماشین‌حساب و تبدیل‌گر'],
    ] : [
      ['About Us','/NewSite/company/','The STB story & mission'],
      ['Contact Us','/NewSite/contact/','24/7 professional support'],
      ['Legal & Docs','/NewSite/legal/','Licences, policies & disclosure'],
      ['FAQ','/NewSite/faq/','Answers to common questions'],
      ['Tools','/NewSite/tools/','Calculators & converters'],
    ],
  ],
];

$flag_map = ['en'=>'🇬🇧','fa'=>'🇮🇷','ar'=>'🇦🇪','ru'=>'🇷🇺','es'=>'🇪🇸'];
$login_label    = $lang==='fa' ? 'ورود' : 'Login';
$register_label = $lang==='fa' ? 'ثبت‌نام' : 'Register';
$login_label_url = $lang==='fa' ? 'https://crm.stbbrokers.com/fa':'https://crm.stbbrokers.com/';
$register_label_url = $lang==='fa' ? 'https://crm.stbbrokers.com/fa/register':'https://crm.stbbrokers.com/register/';

?><!DOCTYPE html>
<html lang="<?php echo $html_lang; ?>" dir="<?php echo $dir; ?>">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="preload" href="<?php echo get_template_directory_uri(); ?>/assets/images/logo.png" as="image">
<?php wp_head(); ?>
</head>
<body <?php body_class('lang-'.$lang.($is_rtl?' rtl':' ltr')); ?>>
<?php wp_body_open(); ?>

<style>
/* ════════════════════════════════════════
   HEADER + MEGA MENU
════════════════════════════════════════ */
.stb-header{
  position:sticky;top:0;z-index:9999;
  height:var(--hh,68px);
  background:rgba(8,10,13,.95);
  backdrop-filter:blur(20px);-webkit-backdrop-filter:blur(20px);
  border-bottom:1px solid rgba(255,255,255,.07);
}
/* Animated top accent line */
.stb-header::before{
  content:'';position:absolute;top:0;left:0;right:0;height:1px;
  background:linear-gradient(90deg,transparent,rgba(200,16,46,.5),transparent);
  animation:hdr-line 4s ease-in-out infinite;
}
@keyframes hdr-line{0%,100%{opacity:.4}50%{opacity:1}}
.stb-header-inner{
  display:flex;align-items:center;gap:0;height:100%;
  max-width:1280px;margin:0 auto;padding:0 32px;
}
@media(max-width:768px){.stb-header-inner{padding:0 16px}}
.stb-logo img{height:34px;width:auto;display:block}
.stb-logo{flex-shrink:0;margin-right:32px}
body.rtl .stb-logo{margin-right:0;margin-left:32px}

/* ── Desktop Nav ── */
.stb-nav{flex:1;display:flex;align-items:center;gap:0}
.stb-nav-item{position:relative}
.stb-nav-link{
  display:flex;align-items:center;gap:5px;
  padding:0 14px;height:var(--hh,68px);
  font-size:13.5px;font-weight:600;
  color:rgba(255,255,255,.6);
  cursor:pointer;white-space:nowrap;
  transition:color .15s;
  border-bottom:2px solid transparent;
  position:relative;
}
.stb-nav-link svg{width:9px;height:9px;stroke:currentColor;fill:none;transition:transform .2s;flex-shrink:0}
.stb-nav-item:hover>.stb-nav-link{color:#fff;border-bottom-color:var(--nc,#C8102E)}
.stb-nav-item:hover>.stb-nav-link svg{transform:rotate(180deg)}

/* ── Mega dropdown ── */
.stb-mega{
  display:none;
  position:absolute;top:100%;left:50%;transform:translateX(-50%);
  min-width:320px;
  background:rgba(10,12,16,.98);
  border:1px solid rgba(255,255,255,.09);
  border-top:2px solid var(--nc,#C8102E);
  border-radius:0 0 16px 16px;
  padding:8px;
  box-shadow:0 24px 60px rgba(0,0,0,.8);
  backdrop-filter:blur(20px);
}
.stb-nav-item:hover .stb-mega{display:block;animation:mega-drop .15s ease-out both}
@keyframes mega-drop{from{opacity:0;transform:translateX(-50%) translateY(-6px)}to{opacity:1;transform:translateX(-50%) translateY(0)}}
/* Mega header */
.stb-mega-head{
  display:flex;align-items:center;gap:10px;
  padding:10px 12px 12px;
  border-bottom:1px solid rgba(255,255,255,.07);
  margin-bottom:4px;
}
.stb-mega-head-icon{
  width:32px;height:32px;border-radius:8px;flex-shrink:0;
  background:rgba(255,255,255,.05);border:1px solid rgba(255,255,255,.08);
  display:flex;align-items:center;justify-content:center;
}
.stb-mega-head-icon svg{stroke:var(--nc,#C8102E);fill:none;width:16px;height:16px}
.stb-mega-head-title{font-size:13px;font-weight:700;color:#fff}
.stb-mega-head-sub{font-size:11px;color:rgba(255,255,255,.35);margin-top:1px}
/* Mega items */
.stb-mega a{
  display:flex;flex-direction:column;gap:2px;
  padding:10px 12px;border-radius:10px;
  transition:background .12s;
  text-decoration:none;
}
.stb-mega a:hover{background:rgba(255,255,255,.06)}
.stb-mega-item-title{font-size:13.5px;font-weight:600;color:rgba(255,255,255,.85);line-height:1.3}
.stb-mega a:hover .stb-mega-item-title{color:#fff}
.stb-mega-item-sub{font-size:11.5px;color:rgba(255,255,255,.35);line-height:1.4}

/* ── Header right ── */
.stb-header-right{
  display:flex;align-items:center;gap:8px;
  margin-left:auto;flex-shrink:0;
}
body.rtl .stb-header-right{margin-left:0;margin-right:auto}
.stb-lang-wrap{position:relative}
.stb-lang-btn{
  display:flex;align-items:center;gap:5px;
  padding:6px 10px;border-radius:8px;
  font-size:12.5px;font-weight:600;
  color:rgba(255,255,255,.5);
  background:rgba(255,255,255,.04);border:1px solid rgba(255,255,255,.08);
  cursor:pointer;transition:all .15s;
}
.stb-lang-btn:hover,.stb-lang-wrap.open .stb-lang-btn{color:#fff;background:rgba(255,255,255,.08);border-color:rgba(255,255,255,.2)}
.stb-lang-drop{
  display:none;
  position:absolute;top:calc(100% + 8px);right:0;
  background:rgba(10,12,16,.98);
  border:1px solid rgba(255,255,255,.1);
  border-radius:12px;padding:6px;
  min-width:160px;
  box-shadow:0 16px 48px rgba(0,0,0,.7);
  backdrop-filter:blur(20px);
  z-index:9999;
}
.stb-lang-wrap.open .stb-lang-drop{display:block;animation:lang-drop .15s ease-out}
@keyframes lang-drop{from{opacity:0;transform:translateY(-4px)}to{opacity:1;transform:none}}
.stb-lang-option{
  display:flex;align-items:center;gap:10px;
  padding:9px 12px;border-radius:8px;
  font-size:13px;font-weight:500;color:rgba(255,255,255,.6);
  text-decoration:none;transition:background .12s,color .12s;
}
.stb-lang-option:hover{background:rgba(255,255,255,.07);color:#fff}
.stb-lang-option.active{background:rgba(200,16,46,.1);color:#fff;font-weight:700}
.stb-lang-option-flag{font-size:16px;line-height:1}
.stb-lang-option-name{flex:1}
.stb-lang-option-current{
  font-size:10px;font-weight:700;padding:2px 6px;border-radius:3px;
  background:rgba(200,16,46,.2);color:#C8102E;
}
.stb-btn-login{
  padding:7px 16px;border-radius:8px;font-size:13px;font-weight:600;
  color:rgba(255,255,255,.7);
  background:rgba(255,255,255,.05);border:1px solid rgba(255,255,255,.1);
  text-decoration:none;transition:all .15s;
}
.stb-btn-login:hover{color:#fff;border-color:rgba(255,255,255,.25)}
.stb-btn-register{
  padding:7px 18px;border-radius:8px;font-size:13px;font-weight:700;
  color:#fff;background:#C8102E;
  box-shadow:0 2px 12px rgba(200,16,46,.35);
  text-decoration:none;transition:filter .15s,transform .12s;
}
.stb-btn-register:hover{filter:brightness(1.1);transform:translateY(-1px);color:#fff}

/* ── Burger ── */
.stb-burger{display:none;flex-direction:column;gap:5px;padding:8px;cursor:pointer;border:none;background:none}
body.rtl .stb-burger{order:-1}
body.rtl .stb-lang-wrap{order:1}
body.rtl .stb-btn-login{order:2}
body.rtl .stb-btn-register{order:3}
.stb-burger span{display:block;width:22px;height:2px;background:rgba(255,255,255,.6);border-radius:2px;transition:all .25s}
.stb-burger.open span:nth-child(1){transform:translateY(7px) rotate(45deg)}
.stb-burger.open span:nth-child(2){opacity:0;transform:scaleX(0)}
.stb-burger.open span:nth-child(3){transform:translateY(-7px) rotate(-45deg)}
@media(max-width:960px){.stb-nav{display:none}.stb-burger{display:flex}}

/* ── Mobile drawer ── */
.stb-mob{
  display:none;position:fixed;inset:0;
  background:rgba(8,10,13,.98);backdrop-filter:blur(20px);
  z-index:9998;flex-direction:column;overflow-y:auto;
  -webkit-overflow-scrolling:touch;
}
.stb-mob.open{display:flex}
.stb-mob-header{
  display:flex;align-items:center;justify-content:space-between;
  padding:14px 20px;
  border-bottom:1px solid rgba(255,255,255,.1);
  flex-shrink:0;height:64px;
  background:rgba(8,10,13,1);
  position:sticky;top:0;z-index:10;
}
.stb-mob-header img{height:28px!important;width:auto!important;display:block;object-fit:contain}
.stb-mob-close{
  padding:10px;cursor:pointer;
  color:#fff;
  background:rgba(200,16,46,.15);
  border:1px solid rgba(200,16,46,.35);
  border-radius:10px;
  display:flex;align-items:center;justify-content:center;
  min-width:44px;min-height:44px;
  flex-shrink:0;
  transition:background .15s,transform .15s;
}
.stb-mob-close:hover,.stb-mob-close:active{background:rgba(200,16,46,.35);transform:scale(.95)}
.stb-mob-close svg{width:20px;height:20px;stroke:currentColor;fill:none;display:block}
.stb-mob-body{flex:1;padding:12px 16px;display:flex;flex-direction:column;gap:4px}
.stb-mob-section{}
.stb-mob-section-title{
  display:flex;align-items:center;gap:10px;
  padding:14px 12px;border-radius:10px;
  font-size:15px;font-weight:700;color:#fff;cursor:pointer;
  transition:background .15s;
  min-height:52px;
}
.stb-mob-section-title:hover{background:rgba(255,255,255,.06)}
.stb-mob-section-icon{
  width:30px;height:30px;border-radius:8px;
  background:rgba(255,255,255,.05);border:1px solid rgba(255,255,255,.08);
  display:flex;align-items:center;justify-content:center;flex-shrink:0;
}
.stb-mob-section-icon svg{stroke:var(--nc,#C8102E);fill:none;width:14px;height:14px}
.stb-mob-section-arr{margin-left:auto;color:rgba(255,255,255,.3);transition:transform .2s}
body.rtl .stb-mob-section-arr{margin-left:0;margin-right:auto}
.stb-mob-section-arr svg{stroke:currentColor;fill:none;width:14px;height:14px}
.stb-mob-section.open .stb-mob-section-arr{transform:rotate(180deg)}
.stb-mob-links{display:none;padding:4px 0 8px 52px;flex-direction:column;gap:2px}
.stb-mob-section.open .stb-mob-links{display:flex}
.stb-mob-links a{
  padding:11px 12px;border-radius:8px;font-size:14px;
  color:rgba(255,255,255,.55);text-decoration:none;
  transition:color .12s,background .12s;
  display:block;min-height:44px;display:flex;align-items:center;
}
.stb-mob-links a:hover{color:#fff;background:rgba(255,255,255,.05)}
.stb-mob-footer{
  padding:16px 20px;border-top:1px solid rgba(255,255,255,.08);
  display:flex;gap:10px;
}
.stb-mob-footer a{flex:1;padding:11px;border-radius:10px;text-align:center;font-size:14px;font-weight:600;text-decoration:none;transition:all .15s}

/* RTL tweaks */
body.rtl .stb-mega{left:auto;right:50%;transform:translateX(50%)}
body.rtl .stb-nav-item:hover .stb-mega{animation-name:mega-drop-rtl}
@keyframes mega-drop-rtl{from{opacity:0;transform:translateX(50%) translateY(-6px)}to{opacity:1;transform:translateX(50%) translateY(0)}}

/* ── FA desktop nav order ── */
/* Layout: [Logo] [...space...] [شرکت|جامعه|آکادمی|ونچر|سرمایه‌گذاری|بروکر] [FA][ورود][ثبت‌نام] */
@media(min-width:961px){
  /* Header: LTR row, logo left, right-group right */
  body.rtl .stb-header-inner{
    flex-direction:row!important;
    direction:rtl!important;
  }
  body.rtl .stb-logo{
    order:0;
    flex-shrink:0;
    margin-right:0!important;
    margin-left:0!important;
  }
  /* Nav fills space, items right-aligned via justify-content */
  body.rtl .stb-nav{
    order:1;
    flex:1!important;
    display:flex!important;
    flex-direction:row!important;
    justify-content:center!important;
    direction:ltr!important;
    margin-left:0!important;
    margin-right:0!important;
  }
  /* Reorder nav items via order property
     DOM: 1=بروکر 2=سرمایه‌گذاری 3=ونچر 4=آکادمی 5=جامعه 6=شرکت
     Want L→R: شرکت(6->1) جامعه(5->2) آکادمی(4->3) ونچر(3->4) سرمایه‌گذاری(2->5) بروکر(1->6) */
  body.rtl .stb-nav .stb-nav-item:nth-child(1){order:6}
  body.rtl .stb-nav .stb-nav-item:nth-child(2){order:5}
  body.rtl .stb-nav .stb-nav-item:nth-child(3){order:4}
  body.rtl .stb-nav .stb-nav-item:nth-child(4){order:3}
  body.rtl .stb-nav .stb-nav-item:nth-child(5){order:2}
  body.rtl .stb-nav .stb-nav-item:nth-child(6){order:1}
  /* Nav link text direction */
  body.rtl .stb-nav-link{
    direction:rtl!important;
    flex-direction:row-reverse!important;
  }
  /* Mega dropdown */
  body.rtl .stb-mega{
    left:50%!important;
    right:auto!important;
    transform:translateX(-50%)!important;
  }
  body.rtl .stb-nav-item:hover .stb-mega{
    animation-name:mega-drop-fa-desktop;
  }
  @keyframes mega-drop-fa-desktop{
    from{opacity:0;transform:translateX(-50%) translateY(-6px)}
    to{opacity:1;transform:translateX(-50%) translateY(0)}
  }
  body.rtl .stb-mega-head{
    flex-direction:row-reverse;
    text-align:right;
  }
  body.rtl .stb-mega a{
    text-align:right;
    direction:rtl;
  }
  /* Right buttons: lang ورود ثبت‌نام */
  body.rtl .stb-header-right{
    order:2;
    flex-shrink:0;
    margin-left:0!important;
    margin-right:0!important;
    flex-direction:row!important;
    direction:ltr;
    gap:8px;
  }
  body.rtl .stb-lang-wrap{order:0!important}
  body.rtl .stb-btn-login{order:1!important}
  body.rtl .stb-btn-register{order:2!important}
  body.rtl .stb-burger{display:none!important}
  body.rtl .stb-lang-drop{
    right:0!important;
    left:auto!important;
  }
}
</style>

<!-- HEADER -->
<header class="stb-header" id="stb-header" role="banner">
  <div class="stb-header-inner">
    <a href="<?php echo home_url('/') . ($lang!=='en' ? '?lang='.$lang : ''); ?>" class="stb-logo" aria-label="STB Provider">
      <img src="<?php echo get_template_directory_uri(); ?>/assets/images/logo.png" alt="STB Provider" width="120" height="34" fetchpriority="high" loading="eager">
    </a>

    <!-- Desktop nav -->
    <nav class="stb-nav" aria-label="Primary navigation">
      <?php foreach($nav as $key => $section): ?>
      <div class="stb-nav-item" style="--nc:<?php echo $section['color']; ?>">
        <span class="stb-nav-link" tabindex="0" role="button"
              aria-haspopup="true" aria-expanded="false">
          <?php echo esc_html($section['label']); ?>
          <svg viewBox="0 0 10 6"><path d="M1 1l4 4 4-4" stroke-width="1.5" stroke-linecap="round"/></svg>
        </span>
        <div class="stb-mega" role="menu">
          <div class="stb-mega-head">
            <div class="stb-mega-head-icon">
              <svg viewBox="0 0 24 24" stroke="currentColor" fill="none"><?php echo $section['icon']; ?></svg>
            </div>
            <div>
              <div class="stb-mega-head-title"><?php echo esc_html($section['label']); ?></div>
              <div class="stb-mega-head-sub">STB <?php echo esc_html($section['label']); ?></div>
            </div>
          </div>
          <?php foreach($section['items'] as $item): ?>
          <a href="<?php echo esc_url(stb_url($item[1])); ?>" role="menuitem">
            <span class="stb-mega-item-title"><?php echo esc_html($item[0]); ?></span>
            <?php if(!empty($item[2])): ?>
            <span class="stb-mega-item-sub"><?php echo esc_html($item[2]); ?></span>
            <?php endif; ?>
          </a>
          <?php endforeach; ?>
        </div>
      </div>
      <?php endforeach; ?>
    </nav>

    <!-- Right buttons -->
    <div class="stb-header-right">
      <div class="stb-lang-wrap" id="stb-lang-wrap">
        <button class="stb-lang-btn" id="stb-lang-btn" aria-label="Language selector" aria-haspopup="true" aria-expanded="false">
          <?php echo $flag_map[$lang] ?? '🌐'; ?> <?php echo strtoupper($lang); ?>
          <svg viewBox="0 0 10 6" style="width:8px;height:8px;stroke:currentColor;fill:none"><path d="M1 1l4 4 4-4" stroke-width="1.5"/></svg>
        </button>
        <div class="stb-lang-drop" role="menu">
          <?php
          $lang_options = [
            'en' => ['🇬🇧','English','EN'],
            'fa' => ['🇮🇷','فارسی','FA'],
          ];
          foreach($lang_options as $code => $opt):
            $url = home_url('/') . ($code !== 'en' ? '?lang='.$code : '');
            $active = ($code === $lang) ? ' active' : '';
          ?>
          <a href="<?php echo esc_url($url); ?>" class="stb-lang-option<?php echo $active; ?>" role="menuitem">
            <span class="stb-lang-option-flag"><?php echo $opt[0]; ?></span>
            <span class="stb-lang-option-name"><?php echo esc_html($opt[1]); ?></span>
            <?php if($code === $lang): ?><span class="stb-lang-option-current"><?php echo $opt[2]; ?></span><?php endif; ?>
          </a>
          <?php endforeach; ?>
        </div>
      </div>
      <a href="<?php echo esc_html($login_label_url);?>" class="stb-btn-login"><?php echo esc_html($login_label); ?></a>
      <a href="<?php echo esc_html($register_label_url);?>" class="stb-btn-register"><?php echo esc_html($register_label); ?></a>
      <button class="stb-burger" id="stb-burger" aria-label="Menu" aria-expanded="false">
        <span></span><span></span><span></span>
      </button>
    </div>
  </div>
</header>

<!-- LIVE TICKER -->
<div class="stb-ticker" aria-label="Live market prices" role="marquee">
  <div class="stb-ticker-track" id="stb-ticker">
    <?php
    $items = [
      ['S&P 500','6,337.5','-0.28%','dn','SP','#C8102E'],
      ['EUR / USD','1.1452','-0.39%','dn','€$','#14e0a3'],
      ['NAS 100','22,918','-0.65%','dn','NQ','#C8102E'],
      ['Bitcoin','66,612','+1.00%','up','₿','#C8102E'],
      ['XAU / USD','2,318.4','+0.53%','up','Au','#14e0a3'],
      ['GBP / USD','1.3175','-0.06%','dn','£$','#14e0a3'],
      ['Ethereum','2,042.5','+2.94%','up','Ξ','#C8102E'],
      ['US 30','42,518','-0.21%','dn','DJ','#C8102E'],
    ];
    $all = array_merge($items,$items);
    foreach($all as $item): ?>
    <div class="stb-ticker-item">
      <div class="stb-ticker-icon" style="background:<?php echo $item[5]; ?>22;color:<?php echo $item[5]; ?>"><?php echo $item[4]; ?></div>
      <span class="stb-ticker-name"><?php echo $item[0]; ?></span>
      <span class="stb-ticker-price"><?php echo $item[1]; ?></span>
      <span class="stb-ticker-change <?php echo $item[3]; ?>"><?php echo ($item[3]==='up'?'▲ ':'▼ ').$item[2]; ?></span>
    </div>
    <?php endforeach; ?>
  </div>
</div>

<!-- Mobile drawer -->
<div class="stb-mob" id="stb-mob" aria-hidden="true" role="dialog">
  <div class="stb-mob-header">
    <a href="<?php echo home_url('/') . ($lang!=='en' ? '?lang='.$lang : ''); ?>" style="display:flex;align-items:center">
      <img src="<?php echo get_template_directory_uri(); ?>/assets/images/logo.png" alt="STB" height="28" style="height:28px;width:auto;display:block" fetchpriority="high" loading="eager">
    </a>
    <button class="stb-mob-close" id="stb-mob-close" aria-label="Close">
      <svg viewBox="0 0 24 24"><path d="M18 6L6 18M6 6l12 12" stroke-width="2" stroke-linecap="round"/></svg>
    </button>
  </div>
  <div class="stb-mob-body">
    <?php foreach($nav as $key => $section): ?>
    <div class="stb-mob-section" style="--nc:<?php echo $section['color']; ?>">
      <div class="stb-mob-section-title" onclick="mobToggle(this)">
        <div class="stb-mob-section-icon">
          <svg viewBox="0 0 24 24" stroke="currentColor" fill="none"><?php echo $section['icon']; ?></svg>
        </div>
        <?php echo esc_html($section['label']); ?>
        <div class="stb-mob-section-arr">
          <svg viewBox="0 0 24 24"><path d="M6 9l6 6 6-6" stroke-width="1.5" stroke-linecap="round"/></svg>
        </div>
      </div>
      <div class="stb-mob-links">
        <?php foreach($section['items'] as $item): ?>
        <a href="<?php echo esc_url(stb_url($item[1])); ?>"><?php echo esc_html($item[0]); ?></a>
        <?php endforeach; ?>
      </div>
    </div>
    <?php endforeach; ?>
  </div>
  <div class="stb-mob-footer">
    <a href="<?php echo esc_html($login_label_url);?>" style="background:rgba(255,255,255,.06);border:1px solid rgba(255,255,255,.1);color:rgba(255,255,255,.7)"><?php echo esc_html($login_label); ?></a>
    <a href="<?php echo esc_html($register_label_url);?>" style="background:#C8102E;color:#fff;box-shadow:0 2px 12px rgba(200,16,46,.3)"><?php echo esc_html($register_label); ?></a>
  </div>
</div>

<script>
// Burger
// Burger
var burger=document.getElementById('stb-burger');
var mob=document.getElementById('stb-mob');
var close=document.getElementById('stb-mob-close');

function openMob(){
  if(!mob || !burger) return;
  mob.classList.add('open');
  mob.setAttribute('aria-hidden','false');
  burger.setAttribute('aria-expanded','true');
  burger.classList.add('open');
  document.body.style.overflow='hidden';
}

function closeMob(){
  if(!mob || !burger) return;
  mob.classList.remove('open');
  mob.setAttribute('aria-hidden','true');
  burger.setAttribute('aria-expanded','false');
  burger.classList.remove('open');
  document.body.style.overflow='';
}

function toggleMob(e){
  if(e) e.preventDefault();
  if(!mob || !burger) return;

  if(mob.classList.contains('open')){
    closeMob();
  } else {
    openMob();
  }
}

if(burger) burger.addEventListener('click', toggleMob);
if(close) close.addEventListener('click', function(e){ if(e) e.preventDefault(); closeMob(); });
if(mob) mob.addEventListener('click', function(e){ if(e.target===mob) closeMob(); });
document.addEventListener('keydown', function(e){ if(e.key==='Escape') closeMob(); });
// Mobile accordion
function mobToggle(el){var s=el.closest('.stb-mob-section');s.classList.toggle('open');}
// Header scroll shadow
var hdr=document.getElementById('stb-header');
if(hdr)window.addEventListener('scroll',function(){hdr.style.boxShadow=scrollY>4?'0 4px 40px rgba(0,0,0,.6)':'';},{passive:true});
// Language dropdown toggle
var langWrap=document.getElementById('stb-lang-wrap');
var langBtn=document.getElementById('stb-lang-btn');
if(langBtn){
  langBtn.addEventListener('click',function(e){
    e.stopPropagation();
    var open=langWrap.classList.toggle('open');
    langBtn.setAttribute('aria-expanded',open?'true':'false');
  });
}
document.addEventListener('click',function(e){
  if(langWrap&&!langWrap.contains(e.target)){
    langWrap.classList.remove('open');
    if(langBtn)langBtn.setAttribute('aria-expanded','false');
  }
});
document.addEventListener('keydown',function(e){
  if(e.key==='Escape'&&langWrap){langWrap.classList.remove('open');if(langBtn)langBtn.setAttribute('aria-expanded','false');}
});
// Keyboard nav on mega menu
document.querySelectorAll('.stb-nav-link').forEach(function(el){
  el.addEventListener('keydown',function(e){
    if(e.key==='Enter'||e.key===' '){e.preventDefault();el.closest('.stb-nav-item').classList.toggle('open');}
    if(e.key==='Escape')el.closest('.stb-nav-item').classList.remove('open');
  });
});
</script>
