/* BARAH V66.9.1 — SURGICAL MOBILE LATEST CARD FIX
   Base: user active V66.9, no extra modules or observers.
   Preserves old stable render and desktop; only text/layout within V64.3 mobile cards.
   Mobile items remain manually defined; not automatically latest-by-created-at.
*/
/* BARAH V65.9 SAFE HOTFIX V2 — 2026-10-09
   Preserves existing theme logic. Two targeted fixes:
   - No stale/unverified 10% offer can render from injected product manifests.
   - Empty daily native-component section removed after 7s.
   NOTE: Browser cannot establish actual Salla prices by trusting an injected JS list.
   To activate discounts, backend must first apply Salla sale prices, read them back,
   and provide freshly verified items. No actual prices are modified by this file.
*/
/* BARAH V65.9 HOME NAVIGATION EARLY GUARD */
(function(){
  'use strict';
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  if(!(/^\/(ar|en)?$/.test(p))) return;
  var category='https://barahstore.com/ar/home-kitchen/c127906256';
  document.addEventListener('click',function(e){
    var a=e.target && e.target.closest ? e.target.closest('#barah-step-hero-v12 .barah-hero-primary') : null;
    if(!a || e.button!==0 || e.ctrlKey || e.metaKey || e.shiftKey || e.altKey)return;
    e.preventDefault();e.stopImmediatePropagation();
    window.location.assign(category);
  },true);
})();
/* BARAH V65.8 — NAVIGATION FIX: removed obsolete click interceptor; corrected catalog routes. Existing product page & six cards unchanged. */
/* ============================================================
BARAH V64.8 — REMOTE POPULAR CORS PREVIEW GUARD V4.2
- Live barahstore.com: remote popular.json remains enabled.
- Salla theme preview/editor: remote fetch is disabled; built-in fallback is used.
- No design/layout changes.
============================================================ */
(function(){
'use strict';
var h=String(location.hostname||'').toLowerCase();
window.__BARAH_CAN_REMOTE_POPULAR__=(h==='barahstore.com' || h==='www.barahstore.com');
})();

/* ============================================================
BARAH V64.8 — NON-HOME FIREWALL V3
FINAL RULE:
If this is not the homepage, NO homepage section is allowed to start,
mount, move, or reappear — before or after the footer.
============================================================ */
(function(){
'use strict';

var path=String(location.pathname||'/').replace(/\/+$/,'')||'/';

var HOME=(
  path==='/' ||
  path==='/ar' ||
  path==='/en' ||
  (location.hostname==='salla.sa' && path==='/br1')
);

if(HOME){
  document.documentElement.setAttribute('data-barah-route-v3','home');
  return;
}

document.documentElement.setAttribute('data-barah-route-v3','nonhome');

/* ------------------------------------------------------------
   STOP HOMEPAGE MODULES BEFORE THEIR CODE RUNS
------------------------------------------------------------ */
[
  '__BARAH_V641_EARLY_GATE__',
  '__BARAH_V614_EARLY_PRIORITY__',
  '__BARAH_STEP_HERO_V12__',
  '__BARAH_STEP_V24_SHIPPING__',

  '__BARAH_STEP_V15_DISCOVERY__',
  '__BARAH_STEP_HOME_V9__',
  '__BARAH_STEP_V18_PERSONAL__',
  '__BARAH_STEP_GATEWAY_V36__',

  '__BARAH_STEP_V37__',
  '__BARAH_STEP_V38__',
  '__BARAH_STEP_V39_BAR_FIX__',
  '__BARAH_STEP_V40_STRIP_FIX__',
  '__BARAH_STEP_V41_TRUE_DEDUPE__',
  '__BARAH_STEP_V44_SMART_STOREFRONT__',
  '__BARAH_STEP_V45_SEO_VISUAL__',

  '__BARAH_STEP_SEASON_V49__',
  '__BARAH_STEP_HOME_GOLDEN_V49__',
  '__BARAH_STEP_SPECIAL_SUGGESTION_V48__',

  '__BARAH_V50_CONVERSION__',
  '__BARAH_V511_CARD_FIT__',
  '__BARAH_V512_LATEST_CARD_ONLY__',
  '__BARAH_V53_CONVERSION_LIFT__',

  '__BARAH_V51_NEEDS_SECTION__',
  '__BARAH_V52_SMART_MERGE__',
  '__BARAH_V54_NATIVE_CARD__',

  '__BARAH_V55_PREGNANCY_PICKS__',
  '__BARAH_V57_SENIOR_PICKS__',
  '__BARAH_V61_PREGNANCY_STORY__',
  '__BARAH_V614_EARLY_PRIORITY__',
  '__BARAH_V622_COMPACT_PREG__',
  '__BARAH_V624_SENIOR_SMALL_IMAGES__',
  '__BARAH_V625_PREG_6_MINI__',
  '__BARAH_V626_PREG_FIX__',

  '__BARAH_V611_FOOTER_PAIR__',
  '__BARAH_V615_FINAL_HOME__',
  '__BARAH_V616_HYBRID_DISCOVERY__',
  '__BARAH_V617_FINAL_POLISH__',
  '__BARAH_V618_MOBILE_POLISH__',
  '__BARAH_V619_HEADING_CLEANUP__',
  '__BARAH_V621_MOBILE_HERO_6__',
  '__BARAH_V623_SECTION_ORDER__',
  '__BARAH_V62_MOBILE_REFINED__',

  '__BARAH_STEP_MOST_VIEWED_FINAL_V3__',
  '__BARAH_V643_MOBILE_LATEST_MIRROR__',
  '__BARAH_V644_DEDUPE_LATEST__',
  '__BARAH_V645_MOST_VIEWED_MOBILE_GRID__',
  '__BARAH_V646_MOST_VIEWED_DATA__',
  '__BARAH_V647_MOBILE_MOST_CUSTOM__',
  '__BARAH_V6482_VIEWPORT_FIT__',
  '__BARAH_V6483_HERO_STACK__',
  '__BARAH_V6484_PREG_CLEAN__',
  '__BARAH_V6485_SENIOR_PREFOOTER__',
  '__BARAH_V648_FINAL_POLISH__',
  '__BARAH_V64_MOBILE_LATEST_NOFLICKER__'
].forEach(function(key){
  window[key]=true;
});

/* ------------------------------------------------------------
   HARD CSS FIREWALL
------------------------------------------------------------ */
var STYLE_ID='barah-v648-nonhome-firewall-v3-style';

var style=document.createElement('style');
style.id=STYLE_ID;
style.textContent=`
html[data-barah-route-v3="nonhome"] #barah-step-hero-v12,
html[data-barah-route-v3="nonhome"] #barah-step-shipping-v24,
html[data-barah-route-v3="nonhome"] #barah-v616-quick-discovery,
html[data-barah-route-v3="nonhome"] #barah-step-smart-storefront-v52,
html[data-barah-route-v3="nonhome"] #barah-step-needs-v51,
html[data-barah-route-v3="nonhome"] #barah-step-pregnancy-v55,
html[data-barah-route-v3="nonhome"] #barah-step-senior-v57,
html[data-barah-route-v3="nonhome"] #barah-v617-decision-strip,
html[data-barah-route-v3="nonhome"] #barah-step-most-viewed,
html[data-barah-route-v3="nonhome"] #barah-step-catalog-v32,
html[data-barah-route-v3="nonhome"] #barah-step-wholesale-v32,
html[data-barah-route-v3="nonhome"] #barah-v643-mobile-latest,
html[data-barah-route-v3="nonhome"] #barah-v647-mobile-most-viewed,
html[data-barah-route-v3="nonhome"] #barah-mobile-premium-access-v650,
html[data-barah-route-v3="nonhome"] #barah-mobile-smart-discovery-v263,
html[data-barah-route-v3="nonhome"] #barah-mobile-premium-access-v264,
html[data-barah-route-v3="nonhome"] #barah-popular-v1,
html[data-barah-route-v3="nonhome"] #barah-discovery-hub,
html[data-barah-route-v3="nonhome"] section.barah-v35-latest{
  display:none!important;
  visibility:hidden!important;
  height:0!important;
  min-height:0!important;
  max-height:0!important;
  margin:0!important;
  padding:0!important;
  border:0!important;
  overflow:hidden!important;
  pointer-events:none!important;
}
`;

(document.head||document.documentElement).appendChild(style);

/* ------------------------------------------------------------
   REMOVE ANY ALREADY-MOUNTED HOMEPAGE SECTIONS
------------------------------------------------------------ */
var HOME_IDS=[
  'barah-step-hero-v12',
  'barah-step-shipping-v24',
  'barah-v616-quick-discovery',
  'barah-step-smart-storefront-v52',
  'barah-step-needs-v51',
  'barah-step-pregnancy-v55',
  'barah-step-senior-v57',
  'barah-v617-decision-strip',
  'barah-step-most-viewed',
  'barah-step-catalog-v32',
  'barah-step-wholesale-v32',
  'barah-v643-mobile-latest',
  'barah-v647-mobile-most-viewed',
  'barah-mobile-premium-access-v650',
  'barah-mobile-smart-discovery-v263',
  'barah-mobile-premium-access-v264',
  'barah-popular-v1',
  'barah-discovery-hub'
];

var HOME_TEXT=[
  'اختصر الطريق',
  'راحة واهتمام لكبار السن',
  'اختيارات الحمل والراحة',
  'يشاهدها العملاء الآن',
  'الأكثر مشاهدة',
  'تسوّق حسب احتياجك'
];

function isProductSpecific(sec){
  if(!sec) return false;

  return !!(
    sec.id==='barah-product-bundle' ||
    sec.closest('#barah-product-bundle') ||
    sec.closest('.page--product-details') ||
    sec.closest('.product-single') ||
    sec.closest('.product-details')
  );
}

function clean(){
  HOME_IDS.forEach(function(id){
    var el=document.getElementById(id);
    if(el) el.remove();
  });

  document.querySelectorAll(
    'section.barah-v35-latest,'+
    'section.home-block.barah-v35-latest'
  ).forEach(function(el){
    el.remove();
  });

  document.querySelectorAll('section').forEach(function(sec){
    if(isProductSpecific(sec)) return;

    var t=String(sec.textContent||'')
      .replace(/\s+/g,' ')
      .trim();

    if(!t) return;

    var leak=HOME_TEXT.some(function(label){
      return t.indexOf(label)!==-1;
    });

    if(leak){
      sec.remove();
    }
  });

  /* Absolute rule: known BARAH homepage blocks after footer are forbidden */
  var footer=document.querySelector('footer');
  if(footer){
    var n=footer.nextElementSibling;

    while(n){
      var next=n.nextElementSibling;
      var id=n.id||'';
      var t=String(n.textContent||'').replace(/\s+/g,' ').trim();

      var barahHome=
        HOME_IDS.indexOf(id)!==-1 ||
        (n.classList && n.classList.contains('barah-v35-latest')) ||
        HOME_TEXT.some(function(label){
          return t.indexOf(label)!==-1;
        });

      if(barahHome){
        n.remove();
      }

      n=next;
    }
  }
}

/* Run immediately */
clean();

/* Run once DOM is ready */
if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',clean,{once:true});
}

/* Keep guard alive because old bundle has delayed mounts */
var cleanTimer;
if(window.MutationObserver){
  new MutationObserver(function(){
    clearTimeout(cleanTimer);
    cleanTimer=setTimeout(clean,30);
  }).observe(document.documentElement,{
    childList:true,
    subtree:true
  });
}

/* Extra launch checks */
[100,300,700,1500,3000,6000,10000,15000].forEach(function(ms){
  setTimeout(clean,ms);
});

})();

/* ============================================================
   BARAH V64.8 — MOBILE-FIRST LAUNCH STABILITY GUARD
   95% mobile traffic: skip obsolete legacy modules before they run.
   This reduces DOM churn, late section moves, and unnecessary timers.
   ============================================================ */
(function(){
'use strict';
var OFF=[
  '__BARAH_STEP_V15_DISCOVERY__',
  '__BARAH_STEP_HOME_V9__',
  '__BARAH_STEP_V18_PERSONAL__',
  '__BARAH_STEP_GATEWAY_V36__',
  '__BARAH_STEP_V37__',
  '__BARAH_STEP_V38__',
  '__BARAH_STEP_V39_BAR_FIX__',
  '__BARAH_STEP_V40_STRIP_FIX__',
  '__BARAH_STEP_V41_TRUE_DEDUPE__',
  '__BARAH_STEP_V44_SMART_STOREFRONT__',
  '__BARAH_STEP_V45_SEO_VISUAL__',
  '__BARAH_STEP_SEASON_V49__',
  '__BARAH_STEP_HOME_GOLDEN_V49__',
  '__BARAH_STEP_SPECIAL_SUGGESTION_V48__',
  '__BARAH_V50_CONVERSION__',
  '__BARAH_V511_CARD_FIT__',
  '__BARAH_V512_LATEST_CARD_ONLY__',
  '__BARAH_V53_CONVERSION_LIFT__',
  '__BARAH_V625_PREG_6_MINI__',
  '__BARAH_V615_FINAL_HOME__',
  '__BARAH_V623_SECTION_ORDER__'
];
OFF.forEach(function(k){window[k]=true;});
document.documentElement.setAttribute('data-barah-v648-legacy','disabled');
})();

/* ============================================================
   BARAH V64.1 — EARLY ANTI-FLICKER GATE
   Must stay at the very first bytes of the custom JS file.
   Holds homepage content briefly until core sections are mounted,
   then reveals once with no transition.
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V641_EARLY_GATE__) return;
window.__BARAH_V641_EARLY_GATE__=true;

var html=document.documentElement;
html.setAttribute('data-barah-v641-gate','hold');

var style=document.createElement('style');
style.id='barah-v641-early-gate-style';
style.textContent=`
html[data-barah-v641-gate="hold"] main{
  visibility:hidden!important;
}
html[data-barah-v641-gate="hold"] main{
  min-height:720px!important;
}
html[data-barah-v641-gate="ready"] main{
  visibility:visible!important;
}
html[data-barah-v641-gate="ready"] main,
html[data-barah-v641-gate="ready"] main *{
  animation:none!important;
}
`;
(document.head||document.documentElement).appendChild(style);

var start=Date.now();
var released=false;

function latest(){
  return document.querySelector('section.barah-v35-latest') ||
    Array.prototype.slice.call(
      document.querySelectorAll('section.home-block.home-block--fixed-products.show-all')
    ).find(function(sec){
      var t=(sec.textContent||'').replace(/\s+/g,' ').trim();
      return t.indexOf('وصل حديث')!==-1 ||
             t.indexOf('جديد بارعة')!==-1 ||
             t.indexOf('أحدث المنتجات')!==-1;
    });
}

function coreReady(){
  var base=!!(
    document.getElementById('barah-step-hero-v12') &&
    document.getElementById('barah-step-pregnancy-v55') &&
    document.getElementById('barah-step-senior-v57')
  );

  if(!base) return false;

  var mobile=window.matchMedia && window.matchMedia('(max-width: 767px)').matches;

  if(mobile){
    return !!(
      document.getElementById('barah-v643-mobile-latest') &&
      document.getElementById('barah-v647-mobile-most-viewed')
    );
  }

  return !!(
    document.getElementById('barah-step-most-viewed') &&
    latest()
  );
}

function release(){
  if(released) return;
  released=true;

  requestAnimationFrame(function(){
    requestAnimationFrame(function(){
      html.setAttribute('data-barah-v641-gate','ready');
      html.removeAttribute('data-barah-v641-waiting');
    });
  });
}

function check(){
  if(released) return;

  var elapsed=Date.now()-start;

  /* reveal as soon as the important homepage pieces exist;
     hard cap keeps content accessible even if one optional block fails */
  if(coreReady() && elapsed>=260){
    release();
    return;
  }

  if(elapsed>=850){
    release();
    return;
  }

  setTimeout(check,45);
}

html.setAttribute('data-barah-v641-waiting','1');

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',check,{once:true});
}else{
  check();
}

/* absolute accessibility failsafe */
setTimeout(release,1000);
})();

/* ============================================================
   BARAH V63 — LAUNCH APPROVED
   Final reviewed build based on V62.6
   - Syntax checked
   - Mobile/Desktop layout reviewed
   - Core product/category targets verified
   - Legacy observers/intervals are bounded and self-stop
   ============================================================ */


/* ============================================================
   BARAH V61.4 — EARLY PRIORITY BOOT
   IMPORTANT:
   This block is intentionally at the TOP of the file.
   It guarantees Home button + Senior Care angle render before
   any long legacy/theme blocks can interfere or be truncated.
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V614_EARLY_PRIORITY__) return;
window.__BARAH_V614_EARLY_PRIORITY__=true;

var ROOT='barah-step-senior-v57';
var STYLE='barah-v614-early-senior-style';

function style(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
#${ROOT}{
  direction:rtl!important;
  width:min(1180px,calc(100% - 40px))!important;
  margin:18px auto 22px!important;
  box-sizing:border-box!important;
  font-family:inherit!important;
  display:block!important;
  visibility:visible!important;
  opacity:1!important;
}
#${ROOT} *{box-sizing:border-box!important}
#${ROOT} .v614-shell{
  padding:20px!important;
  border:1px solid #dfe9e3!important;
  border-radius:22px!important;
  background:
    radial-gradient(circle at 92% 8%,rgba(67,111,91,.14),transparent 27%),
    radial-gradient(circle at 8% 92%,rgba(255,122,24,.07),transparent 30%),
    linear-gradient(180deg,#fff,#fbfdfb)!important;
  box-shadow:0 14px 34px rgba(35,24,18,.05)!important;
}
#${ROOT} .v614-head{
  display:flex!important;
  align-items:flex-end!important;
  justify-content:space-between!important;
  gap:15px!important;
  margin-bottom:14px!important;
}
#${ROOT} .v614-kicker{
  display:inline-flex!important;
  min-height:28px!important;
  align-items:center!important;
  padding:0 10px!important;
  margin-bottom:7px!important;
  border-radius:999px!important;
  background:#edf5f0!important;
  color:#315f4a!important;
  font-size:10px!important;
  font-weight:950!important;
}
#${ROOT} .v614-head h2{
  margin:0!important;
  color:#202a24!important;
  font-size:27px!important;
  line-height:1.35!important;
  font-weight:950!important;
}
#${ROOT} .v614-head p{
  margin:6px 0 0!important;
  max-width:760px!important;
  color:#6f776f!important;
  font-size:12px!important;
  line-height:1.85!important;
}
#${ROOT} .v614-all{
  flex:0 0 auto!important;
  min-height:39px!important;
  padding:0 13px!important;
  display:inline-flex!important;
  align-items:center!important;
  justify-content:center!important;
  border:1px solid #d9e6de!important;
  border-radius:11px!important;
  background:#fff!important;
  color:#315f4a!important;
  text-decoration:none!important;
  font-size:11px!important;
  font-weight:950!important;
}
#${ROOT} .v614-grid{
  display:grid!important;
  grid-template-columns:repeat(4,minmax(0,1fr))!important;
  gap:9px!important;
}
#${ROOT} .v614-path{
  min-height:128px!important;
  padding:14px!important;
  display:flex!important;
  flex-direction:column!important;
  text-decoration:none!important;
  border:1px solid #e4ebe7!important;
  border-radius:16px!important;
  background:#fff!important;
}
#${ROOT} .v614-icon{
  width:42px!important;
  height:42px!important;
  display:grid!important;
  place-items:center!important;
  margin-bottom:10px!important;
  border-radius:12px!important;
  background:#edf5f0!important;
  font-size:20px!important;
}
#${ROOT} .v614-path strong{
  display:block!important;
  color:#28352e!important;
  font-size:13px!important;
  line-height:1.5!important;
  font-weight:950!important;
}
#${ROOT} .v614-path small{
  display:block!important;
  margin:5px 0 10px!important;
  color:#778079!important;
  font-size:10px!important;
  line-height:1.65!important;
}
#${ROOT} .v614-go{
  margin-top:auto!important;
  color:#d65b27!important;
  font-size:10px!important;
  font-weight:950!important;
}
#${ROOT} .v614-note{
  margin-top:11px!important;
  color:#867a72!important;
  font-size:9px!important;
  line-height:1.7!important;
}
.barah-home-direct{
  display:inline-flex!important;
  align-items:center!important;
  justify-content:center!important;
}
@media(max-width:900px){
  #${ROOT} .v614-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important}
}
@media(max-width:600px){
  #${ROOT}{
    width:calc(100% - 24px)!important;
    margin:14px 12px 18px!important;
  }
  #${ROOT} .v614-shell{padding:14px!important;border-radius:18px!important}
  #${ROOT} .v614-head{align-items:flex-start!important;flex-direction:column!important}
  #${ROOT} .v614-head h2{font-size:22px!important}
  #${ROOT} .v614-all{width:100%!important}
  #${ROOT} .v614-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:7px!important}
  #${ROOT} .v614-path{min-height:122px!important;padding:11px!important}
}
`;
  (document.head||document.documentElement).appendChild(s);
}

function buildSenior(){
  var sec=document.getElementById(ROOT);
  if(sec) return sec;

  sec=document.createElement('section');
  sec.id=ROOT;
  sec.setAttribute('aria-label','راحة واهتمام لكبار السن');
  sec.innerHTML=
    '<div class="v614-shell">'+
      '<div class="v614-head">'+
        '<div>'+
          '<span class="v614-kicker">🤍 زاوية مختارة بعناية</span>'+
          '<h2>راحة واهتمام لكبار السن</h2>'+
          '<p>وصول سريع لأهم الاحتياجات اليومية: التنقل، الحركة في المنزل، دعم الركبة، والراحة والمساج.</p>'+
        '</div>'+
        '<a class="v614-all" href="https://barahstore.com/ar/search?q='+encodeURIComponent('راحة')+'">عرض كل الاختيارات ←</a>'+
      '</div>'+
      '<div class="v614-grid">'+
        '<a class="v614-path" href="https://barahstore.com/ar/search?q='+encodeURIComponent('عكاز')+'">'+
          '<span class="v614-icon">🦯</span><strong>العكاز والتنقل</strong>'+
          '<small>خيارات عملية للمشي والحركة اليومية والسفر.</small><span class="v614-go">شاهد الاختيارات ←</span>'+
        '</a>'+
        '<a class="v614-path" href="https://barahstore.com/ar/search?q='+encodeURIComponent('بيدال')+'">'+
          '<span class="v614-icon">🚲</span><strong>البيدال والحركة</strong>'+
          '<small>حركة منزلية بسيطة لليدين والساقين.</small><span class="v614-go">شاهد الاختيارات ←</span>'+
        '</a>'+
        '<a class="v614-path" href="https://barahstore.com/ar/search?q='+encodeURIComponent('ركبة')+'">'+
          '<span class="v614-icon">🦵</span><strong>دعم الركبة</strong>'+
          '<small>مشدات ودعامات قابلة للضبط للاستخدام اليومي.</small><span class="v614-go">شاهد الاختيارات ←</span>'+
        '</a>'+
        '<a class="v614-path" href="https://barahstore.com/ar/search?q='+encodeURIComponent('مساج')+'">'+
          '<span class="v614-icon">✦</span><strong>الراحة والمساج</strong>'+
          '<small>اختيارات للاسترخاء والراحة ضمن الروتين اليومي.</small><span class="v614-go">شاهد الاختيارات ←</span>'+
        '</a>'+
      '</div>'+
      '<div class="v614-note">منتجات للاستخدام العام والراحة اليومية، وليست بديلًا عن المشورة الطبية عند الحاجة.</div>'+
    '</div>';

  return sec;
}

function ensureHomeButton(){
  var hero=document.getElementById('barah-step-hero-v12');
  if(!hero) return false;

  var actions=hero.querySelector('.barah-hero-actions');
  if(!actions) return false;

  if(!actions.querySelector('.barah-home-direct')){
    var a=document.createElement('a');
    a.className='barah-hero-secondary barah-home-direct';
    a.href='https://barahstore.com/ar';
    a.setAttribute('aria-label','الصفحة الرئيسية');
    a.textContent='⌂ الصفحة الرئيسية';
    actions.appendChild(a);
  }
  return true;
}

function placeSenior(){
  style();
  var sec=buildSenior();
  var preg=document.getElementById('barah-step-pregnancy-v55');
  var smart=document.getElementById('barah-step-needs-v51') ||
            document.getElementById('barah-step-smart-storefront-v52');
  var latest=document.querySelector('section.barah-v35-latest');
  var main=document.querySelector('main')||document.body;

  if(smart && smart.parentNode){
    if(smart.nextElementSibling!==sec) smart.insertAdjacentElement('afterend',sec);
  }else if(preg && preg.parentNode){
    if(preg.nextElementSibling!==sec) preg.insertAdjacentElement('afterend',sec);
  }else if(latest && latest.parentNode){
    latest.insertAdjacentElement('beforebegin',sec);
  }else if(main && !sec.parentNode){
    main.appendChild(sec);
  }

  sec.style.setProperty('display','block','important');
  sec.style.setProperty('visibility','visible','important');
  sec.style.setProperty('opacity','1','important');

  document.documentElement.setAttribute('data-barah-v614-senior','ready');
  return true;
}

function run(){
  style();
  placeSenior();
}

function boot(){
  [0,180,450,900,1600,2800,4500,7000,9500].forEach(function(ms){
    setTimeout(run,ms);
  });
}
if(document.readyState==='loading') document.addEventListener('DOMContentLoaded',boot,{once:true});
else boot();

})();



(function(){
'use strict';
if(window.__BARAH_STEP_RC23_BOOT__)return;
window.__BARAH_STEP_RC23_BOOT__=true;
function pre(h){
  if(document.querySelector('link[rel="preconnect"][href="'+h+'"]'))return;
  var l=document.createElement('link');
  l.rel='preconnect';l.href=h;l.crossOrigin='anonymous';
  document.head.appendChild(l);
}
pre('https://cdn.salla.sa');
pre('https://cdn.files.salla.network');
})();

(function(){
  'use strict';

  if(window.__BARAH_STEP_HERO_V12__) return;
  window.__BARAH_STEP_HERO_V12__ = true;

  var ROOT='barah-step-hero-v12';
  var STYLE='barah-step-hero-v12-style';

  function isHome(){
    var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
    if(/^\/(ar|en)?$/.test(p)) return true;
    if(location.hostname==='salla.sa' && /^\/br1$/.test(p)) return true;
    return !!document.querySelector('main');
  }

  if(!isHome()) return;

  function addStyle(){
    if(document.getElementById(STYLE)) return;

    var s=document.createElement('style');
    s.id=STYLE;
    s.textContent=`
#${ROOT}{
  direction:rtl;
  width:min(1180px,calc(100% - 40px));
  margin:22px auto 26px;
  box-sizing:border-box
}
#${ROOT} *{box-sizing:border-box}
#${ROOT} .barah-hero-shell{
  display:grid;
  grid-template-columns:1.05fr .95fr;
  gap:18px;
  align-items:stretch;
  padding:26px;
  border-radius:24px;
  border:1px solid #eee3da;
  background:
    radial-gradient(circle at 10% 15%,rgba(255,122,24,.13),transparent 31%),
    radial-gradient(circle at 88% 18%,rgba(239,68,68,.08),transparent 28%),
    #fffdfb;
  box-shadow:0 14px 42px rgba(37,27,20,.06)
}
#${ROOT} .barah-hero-copy{
  display:flex;
  flex-direction:column;
  justify-content:center;
  min-height:310px;
  padding:6px 8px
}
#${ROOT} .barah-hero-badge{
  display:inline-flex;
  align-self:flex-start;
  margin-bottom:12px;
  padding:7px 11px;
  border-radius:999px;
  background:#fff1e8;
  color:#b84a18;
  font-size:12px;
  font-weight:900
}
#${ROOT} h1{
  margin:0;
  color:#18120f;
  font-size:38px;
  line-height:1.3;
  font-weight:950
}
#${ROOT} .barah-hero-copy p{
  margin:12px 0 20px;
  color:#6e6058;
  font-size:15px;
  line-height:1.9
}
#${ROOT} .barah-hero-actions{
  display:flex;
  flex-wrap:wrap;
  gap:10px
}
#${ROOT} .barah-hero-primary,
#${ROOT} .barah-hero-secondary{
  text-decoration:none;
  padding:12px 16px;
  border-radius:12px;
  font-size:13px;
  font-weight:900
}
#${ROOT} .barah-hero-primary{
  color:#fff;
  background:linear-gradient(135deg,#ff7a18 0%,#ef4444 100%);
  box-shadow:0 9px 22px rgba(239,68,68,.18)
}
#${ROOT} .barah-hero-secondary{
  color:#332922;
  background:#fff;
  border:1px solid #e9ddd4
}
#${ROOT} .barah-hero-products{
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:12px
}
#${ROOT} .barah-hero-product{
  position:relative;
  display:flex;
  flex-direction:column;
  overflow:hidden;
  text-decoration:none;
  background:#fff;
  border:1px solid #eee4dc;
  border-radius:18px;
  box-shadow:0 8px 22px rgba(35,24,18,.045)
}
#${ROOT} .barah-hero-product img{
  display:block;
  width:100%;
  aspect-ratio:1/1;
  object-fit:contain;
  padding:12px;
  background:#fff
}
#${ROOT} .barah-hero-product strong{
  display:block;
  min-height:48px;
  padding:0 12px 4px;
  color:#241b17;
  font-size:13px;
  line-height:1.55;
  font-weight:850
}
#${ROOT} .barah-hero-product small{
  display:block;
  padding:0 12px 12px;
  color:#d94c21;
  font-size:14px;
  font-weight:900
}
#${ROOT} .barah-hero-pill{
  position:absolute;
  top:10px;
  right:10px;
  padding:5px 8px;
  border-radius:999px;
  background:rgba(18,18,18,.88);
  color:#fff;
  font-size:10px;
  font-weight:800
}
#${ROOT} .barah-hero-trust{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-top:16px
}
#${ROOT} .barah-hero-trust span{
  padding:7px 10px;
  border-radius:999px;
  background:#fff;
  border:1px solid #eee4dc;
  color:#5a4d45;
  font-size:11px;
  font-weight:800
}
@media(max-width:900px){
  #${ROOT} .barah-hero-shell{grid-template-columns:1fr}
  #${ROOT} .barah-hero-copy{min-height:auto}
}
@media(max-width:600px){
  #${ROOT}{
    width:calc(100% - 24px);
    margin:16px 12px 20px
  }
  #${ROOT} .barah-hero-shell{
    padding:16px;
    border-radius:18px
  }
  #${ROOT} h1{font-size:27px}
  #${ROOT} .barah-hero-copy p{font-size:13px}
  #${ROOT} .barah-hero-products{gap:9px}
  #${ROOT} .barah-hero-product strong{
    min-height:44px;
    font-size:12px
  }
}
`;
    document.head.appendChild(s);
  }

  function findCategoriesBlock(){
    var main=document.querySelector('main');
    var titles=Array.prototype.slice.call(
      document.querySelectorAll('h1,h2,h3,h4,.title,.section-title,.s-block__title,[class*="title"]')
    );

    var t=titles.find(function(el){
      var x=(el.textContent||'').replace(/\s+/g,' ').trim();
      return (
        x.indexOf('أبرز التصنيفات')!==-1 ||
        x.indexOf('التصنيفات')!==-1 ||
        x.indexOf('Categories')!==-1
      );
    });

    if(!t) return null;

    var node=
      t.closest('section') ||
      t.closest('.home-block') ||
      t.closest('[class*="categories"]') ||
      t.closest('.container') ||
      t.parentElement;

    if(main){
      while(
        node &&
        node.parentElement &&
        node.parentElement!==main &&
        node.parentElement!==document.body
      ){
        node=node.parentElement;
      }
    }

    return node;
  }

  function render(){
    if(document.getElementById(ROOT)) return true;

    var main=document.querySelector('main')||document.body;
    if(!main) return false;

    addStyle();

    var section=document.createElement('section');
    section.id=ROOT;
    section.setAttribute('aria-label','واجهة بارعة');

    section.innerHTML=`
      <div class="barah-hero-shell">
        <div class="barah-hero-copy">
          <span class="barah-hero-badge">بارعة • اختيارات عملية تستحق التجربة</span>
          <h1>حلول صغيرة… تصنع فرقًا كبيرًا في يومك</h1>
          <p>منتجات عملية للمنزل والعناية والرياضة والسفر، اخترنا لك منها الأكثر فائدة والأسهل وصولًا.</p>

          <div class="barah-hero-actions">
            <a class="barah-hero-primary" href="https://barahstore.com/ar/home-kitchen/c127906256">تسوّق الأكثر مبيعًا ←</a>
            <a class="barah-hero-secondary" href="https://barahstore.com/ar/home-kitchen/c127906256">اكتشف المنزل والمطبخ</a>
          </div>

          <div class="barah-hero-trust">
            <span>🚚 شحن داخل المملكة</span>
            <span>💳 تابي وتمارا</span>
            <span>🔒 دفع آمن</span>
          </div>
        </div>

        <div class="barah-hero-products">
          <a class="barah-hero-product" href="https://barahstore.com/ar/product-1810209528/p1810209528">
            <span class="barah-hero-pill">الأكثر طلبًا</span>
            <img src="https://cdn.salla.sa/qwxGZ/d2bd95f3-f864-4270-a3e3-b0c6354fe1f5-500x500-1lZRaxLMEAsnXSJQrarwnmmbIEVWVS5TxCkSS8s5.jpg" alt="مشد قميص رجالي نصف كم لتنسيق البطن والقوام" decoding="async" fetchpriority="high">
            <strong>مشد قميص رجالي نصف كم لتنسيق البطن والقوام</strong>
            <small>36 ر.س</small>
          </a>

          <a class="barah-hero-product" href="https://barahstore.com/ar/شنطة-العبايه-لحفظ-العبايات/p2109998159">
            <span class="barah-hero-pill">مفيد للسفر</span>
            <img src="https://cdn.salla.sa/qwxGZ/4b815965-eff9-484b-b074-272bb289edf1-500x500-gQJhQXaDTOpKkdVxnRgwyg1krORqeeEi2V3xZcqr.webp" alt="شنطة حفظ العباية للسفر والمناسبات مع بطاقة اسم" decoding="async">
            <strong>شنطة حفظ العباية للسفر والمناسبات مع بطاقة اسم</strong>
            <small>15 ر.س</small>
          </a>
        </div>
      </div>`;

    var categories=findCategoriesBlock();

    if(categories && categories.parentNode){
      categories.insertAdjacentElement('beforebegin',section);
    }else{
      main.prepend(section);
    }

    return true;
  }

  if(!render()){
    var n=0;
    var timer=setInterval(function(){
      n++;
      if(render()||n>=20) clearInterval(timer);
    },150);
  }
})();

/* ============================================================
   BARAH — STEP V24 SHIPPING VALUE PROPOSITION
   رسالة جذب قوية للشحن:
   - مجاني فوق 149 ريال
   - يبدأ من 9 ريال
   - تغطية كامل المملكة عبر عدة شركاء لوجستيين
   ============================================================ */

(function(){
'use strict';

if(window.__BARAH_STEP_V24_SHIPPING__)return;
window.__BARAH_STEP_V24_SHIPPING__=true;

var ROOT='barah-step-shipping-v24';
var STYLE='barah-step-shipping-v24-style';

function isHome(){
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  if(/^\/(ar|en)?$/.test(p))return true;
  if(location.hostname==='salla.sa'&&/^\/br1$/.test(p))return true;
  return false;
}

if(!isHome())return;

function addStyle(){
  if(document.getElementById(STYLE))return;

  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
#${ROOT}{
  direction:rtl;
  width:min(1180px,calc(100% - 40px));
  margin:12px auto 18px;
  box-sizing:border-box;
  font-family:inherit
}
#${ROOT} *{box-sizing:border-box}
#${ROOT} .barah-v24-shell{
  display:grid;
  grid-template-columns:1.2fr .8fr;
  gap:14px;
  align-items:center;
  padding:15px 18px;
  overflow:hidden;
  border:1px solid #f0d9c9;
  border-radius:17px;
  background:
    radial-gradient(circle at 8% 20%,rgba(255,122,24,.13),transparent 30%),
    linear-gradient(135deg,#fff8f2,#fff);
  box-shadow:0 8px 24px rgba(39,27,20,.045)
}
#${ROOT} .barah-v24-main{
  display:flex;
  align-items:center;
  gap:12px
}
#${ROOT} .barah-v24-icon{
  display:flex;
  flex:0 0 48px;
  width:48px;
  height:48px;
  align-items:center;
  justify-content:center;
  border-radius:14px;
  background:linear-gradient(135deg,#ff7a18,#ef4444);
  color:#fff;
  font-size:23px;
  box-shadow:0 8px 20px rgba(239,68,68,.18)
}
#${ROOT} .barah-v24-copy strong{
  display:block;
  margin-bottom:3px;
  color:#1f1713;
  font-size:15px;
  font-weight:950
}
#${ROOT} .barah-v24-copy span{
  display:block;
  color:#716159;
  font-size:11px;
  line-height:1.7
}
#${ROOT} .barah-v24-points{
  display:grid;
  grid-template-columns:repeat(3,minmax(0,1fr));
  gap:7px
}
#${ROOT} .barah-v24-point{
  display:flex;
  min-height:44px;
  align-items:center;
  justify-content:center;
  padding:8px 9px;
  border:1px solid #eee2d9;
  border-radius:11px;
  background:rgba(255,255,255,.85);
  color:#55473e;
  font-size:10px;
  font-weight:900;
  text-align:center
}
#${ROOT} .barah-v24-point b{
  color:#d94c21;
  margin-left:3px
}
@media(max-width:800px){
  #${ROOT} .barah-v24-shell{
    grid-template-columns:1fr
  }
}
@media(max-width:600px){
  #${ROOT}{
    width:calc(100% - 24px);
    margin:10px 12px 16px
  }
  #${ROOT} .barah-v24-shell{
    padding:13px;
    border-radius:15px
  }
  #${ROOT} .barah-v24-icon{
    flex-basis:42px;
    width:42px;
    height:42px;
    font-size:20px
  }
  #${ROOT} .barah-v24-copy strong{
    font-size:13px
  }
  #${ROOT} .barah-v24-copy span{
    font-size:10px
  }
  #${ROOT} .barah-v24-points{
    grid-template-columns:1fr
  }
}
`;
  document.head.appendChild(s);
}

function render(){
  if(document.getElementById(ROOT))return true;

  var hero=document.getElementById('barah-step-hero-v12');
  if(!hero||!hero.parentNode)return false;

  addStyle();

  var section=document.createElement('section');
  section.id=ROOT;
  section.setAttribute('aria-label','مزايا الشحن');

  section.innerHTML=
    '<div class="barah-v24-shell">'+
      '<div class="barah-v24-main">'+
        '<span class="barah-v24-icon">🚚</span>'+
        '<div class="barah-v24-copy">'+
          '<strong>مجاني للطلبات فوق 149 ريال</strong>'+
          '<span>شحن إلى جميع مناطق المملكة، مع خيارات متعددة من شركاء الخدمات اللوجستية.</span>'+
        '</div>'+
      '</div>'+
      '<div class="barah-v24-points">'+
        '<div class="barah-v24-point">مجاني للطلبات <b>فوق 149 ريال</b></div>'+
        '<div class="barah-v24-point">يبدأ من <b>9 ر.س</b></div>'+
        '<div class="barah-v24-point">تغطية <b>كامل المملكة</b></div>'+
      '</div>'+
    '</div>';

  hero.insertAdjacentElement('afterend',section);
  return true;
}

if(!render()){
  var n=0,t=setInterval(function(){
    n++;
    if(render()||n>=20)clearInterval(t);
  },150);
}
})();

(function(){
  'use strict';

  if(window.__BARAH_STEP_V15_DISCOVERY__) return;
  window.__BARAH_STEP_V15_DISCOVERY__ = true;

  var ROOT='barah-step-discovery-v15';
  var STYLE='barah-step-discovery-v15-style';

  var WORLDS=[
    {
      icon:'⌂',
      title:'المنزل والمطبخ',
      text:'حلول عملية للترتيب والاستخدام اليومي',
      url:'https://barahstore.com/ar/home-kitchen/c127906256'
    },
    {
      icon:'✦',
      title:'العناية والأناقة',
      text:'عناية شخصية، أناقة ودعم القوام',
      url:'https://barahstore.com/ar/care-style/c727852954'
    },
    {
      icon:'⚡',
      title:'الرياضة واللياقة',
      text:'معدات وتمارين منزلية وحركة أكثر',
      url:'https://barahstore.com/ar/fitness/c511828448'
    },
    {
      icon:'✈',
      title:'السفر والرحلات',
      text:'تنظيم وتجهيزات تجعل الرحلة أسهل',
      url:'https://barahstore.com/ar/travel/c336613091'
    },
    {
      icon:'◈',
      title:'السيارة',
      text:'تنظيم، استخدام يومي وإكسسوارات عملية',
      url:'https://barahstore.com/ar/car/c228633582'
    },
    {
      icon:'★',
      title:'الطفل والألعاب',
      text:'اختيارات للطفل واللعب والاستخدام اليومي',
      url:'https://barahstore.com/ar/baby-toys/c694872552'
    },
    {
      icon:'♡',
      title:'الحيوانات الأليفة',
      text:'عناية وتنظيف وإكسسوارات منزلية',
      url:'https://barahstore.com/ar/pets/c92693286'
    },
    {
      icon:'❄',
      title:'موسم الشتاء',
      text:'اختيارات موسمية وتجهيزات للبرد',
      url:'https://barahstore.com/ar/offers/c558473504'
    }
  ];

  var MISSIONS=[
    {
      eyebrow:'للبيت',
      title:'أبي شيء يرتب ويختصر علي الوقت',
      text:'ابدأ من حلول المنزل والمطبخ والتنظيم.',
      url:'https://barahstore.com/ar/home-kitchen/c127906256'
    },
    {
      eyebrow:'لنفسي',
      title:'أبي عناية وأناقة وقوام أفضل',
      text:'منتجات عناية وأناقة ومشدات للاستخدام اليومي.',
      url:'https://barahstore.com/ar/care-style/c727852954'
    },
    {
      eyebrow:'للحركة',
      title:'أبي أبدأ تمرين بسيط في البيت',
      text:'معدات خفيفة وتمارين منزلية واختيارات للحركة.',
      url:'https://barahstore.com/ar/fitness/c511828448'
    },
    {
      eyebrow:'للسفر',
      title:'أبي أجهز الرحلة بدون ما أنسى شيء',
      text:'تنظيم، حفظ، تنقل وتجهيزات صغيرة تفرق.',
      url:'https://barahstore.com/ar/travel/c336613091'
    },
    {
      eyebrow:'للسيارة',
      title:'أبي السيارة أرتب وأسهل يوميًا',
      text:'حوامل، تنظيم وإكسسوارات عملية.',
      url:'https://barahstore.com/ar/car/c228633582'
    },
    {
      eyebrow:'للهدية',
      title:'أبي شيء عملي وخفيف كهدية',
      text:'استكشف المنتجات العملية والمتنوعة في بارعة.',
      url:'https://barahstore.com/ar/home-kitchen/c127906256'
    }
  ];

  function isHome(){
    var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
    if(/^\/(ar|en)?$/.test(p)) return true;
    if(location.hostname==='salla.sa' && /^\/br1$/.test(p)) return true;
    return !!document.querySelector('main');
  }

  if(!isHome()) return;

  function style(){
    if(document.getElementById(STYLE)) return;

    var s=document.createElement('style');
    s.id=STYLE;
    s.textContent=`
#${ROOT}{
  direction:rtl;
  width:min(1180px,calc(100% - 40px));
  margin:24px auto;
  box-sizing:border-box;
  font-family:inherit
}
#${ROOT} *{box-sizing:border-box}
#${ROOT} .barah-v15-head{
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap:18px;
  margin-bottom:14px
}
#${ROOT} .barah-v15-kicker{
  display:inline-block;
  margin-bottom:6px;
  padding:5px 9px;
  border-radius:999px;
  background:#fff1e8;
  color:#b84a18;
  font-size:11px;
  font-weight:900
}
#${ROOT} h2{
  margin:0;
  color:#18120f;
  font-size:26px;
  line-height:1.35;
  font-weight:950
}
#${ROOT} .barah-v15-sub{
  margin:6px 0 0;
  color:#74645b;
  font-size:13px;
  line-height:1.7
}
#${ROOT} .barah-v15-worlds{
  display:grid;
  grid-template-columns:repeat(4,minmax(0,1fr));
  gap:11px
}
#${ROOT} .barah-v15-world{
  position:relative;
  display:flex;
  align-items:flex-start;
  gap:12px;
  min-height:104px;
  padding:15px;
  overflow:hidden;
  text-decoration:none;
  border:1px solid #eee4dd;
  border-radius:16px;
  background:#fff;
  transition:transform .18s ease,box-shadow .18s ease,border-color .18s ease
}
#${ROOT} .barah-v15-world:hover{
  transform:translateY(-2px);
  border-color:#f1c8ac;
  box-shadow:0 10px 24px rgba(32,22,16,.06)
}
#${ROOT} .barah-v15-icon{
  display:flex;
  flex:0 0 42px;
  width:42px;
  height:42px;
  align-items:center;
  justify-content:center;
  border-radius:13px;
  background:linear-gradient(135deg,#fff3e9,#ffe8df);
  color:#d95725;
  font-size:21px;
  font-weight:900
}
#${ROOT} .barah-v15-world strong{
  display:block;
  margin:2px 0 4px;
  color:#261d18;
  font-size:14px;
  font-weight:900
}
#${ROOT} .barah-v15-world small{
  display:block;
  color:#7a6a61;
  font-size:11px;
  line-height:1.55
}
#${ROOT} .barah-v15-missions{
  margin-top:18px;
  padding:20px;
  border:1px solid #eee2d9;
  border-radius:20px;
  background:
    radial-gradient(circle at 8% 20%,rgba(255,122,24,.09),transparent 30%),
    #fffdfb
}
#${ROOT} .barah-v15-missions-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:12px
}
#${ROOT} .barah-v15-missions-head h3{
  margin:0;
  color:#251b16;
  font-size:20px;
  font-weight:950
}
#${ROOT} .barah-v15-missions-head span{
  color:#8a786e;
  font-size:11px;
  font-weight:800
}
#${ROOT} .barah-v15-mission-grid{
  display:grid;
  grid-template-columns:repeat(3,minmax(0,1fr));
  gap:10px
}
#${ROOT} .barah-v15-mission{
  display:block;
  min-height:132px;
  padding:15px;
  text-decoration:none;
  border:1px solid #efe5de;
  border-radius:15px;
  background:#fff
}
#${ROOT} .barah-v15-mission em{
  display:inline-block;
  margin-bottom:7px;
  color:#d95522;
  font-size:10px;
  font-style:normal;
  font-weight:900
}
#${ROOT} .barah-v15-mission strong{
  display:block;
  margin-bottom:6px;
  color:#211914;
  font-size:14px;
  line-height:1.55;
  font-weight:900
}
#${ROOT} .barah-v15-mission p{
  margin:0 0 10px;
  color:#796960;
  font-size:11px;
  line-height:1.6
}
#${ROOT} .barah-v15-mission b{
  color:#d94c21;
  font-size:11px;
  font-weight:900
}
#${ROOT} .barah-v15-search{
  display:flex;
  gap:8px;
  margin-top:14px;
  padding-top:14px;
  border-top:1px solid #eee4dd
}
#${ROOT} .barah-v15-search input{
  flex:1;
  min-width:0;
  height:44px;
  padding:0 13px;
  border:1px solid #e9ddd4;
  border-radius:12px;
  background:#fff;
  color:#2c231e;
  outline:none;
  font:inherit;
  font-size:13px
}
#${ROOT} .barah-v15-search button{
  height:44px;
  padding:0 16px;
  border:0;
  border-radius:12px;
  background:#171717;
  color:#fff;
  cursor:pointer;
  font:inherit;
  font-size:12px;
  font-weight:900
}
@media(max-width:900px){
  #${ROOT} .barah-v15-worlds{grid-template-columns:repeat(2,minmax(0,1fr))}
  #${ROOT} .barah-v15-mission-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
}
@media(max-width:600px){
  #${ROOT}{
    width:calc(100% - 24px);
    margin:18px 12px
  }
  #${ROOT} h2{font-size:21px}
  #${ROOT} .barah-v15-worlds{grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
  #${ROOT} .barah-v15-world{
    min-height:104px;
    padding:11px;
    gap:8px
  }
  #${ROOT} .barah-v15-icon{
    flex-basis:36px;
    width:36px;
    height:36px;
    border-radius:11px;
    font-size:18px
  }
  #${ROOT} .barah-v15-world strong{font-size:12px}
  #${ROOT} .barah-v15-world small{font-size:10px}
  #${ROOT} .barah-v15-missions{padding:14px}
  #${ROOT} .barah-v15-missions-head{
    align-items:flex-start;
    flex-direction:column
  }
  #${ROOT} .barah-v15-mission-grid{grid-template-columns:1fr}
  #${ROOT} .barah-v15-search{flex-direction:column}
  #${ROOT} .barah-v15-search button{width:100%}
}
`;
    document.head.appendChild(s);
  }

  function findAnchor(){
    var homePro=document.getElementById('barah-step-home-v9');
    if(homePro) return homePro;

    var main=document.querySelector('main');
    var titles=Array.prototype.slice.call(
      document.querySelectorAll('h1,h2,h3,h4,.title,.section-title,.s-block__title,[class*="title"]')
    );

    var cats=titles.find(function(el){
      var t=(el.textContent||'').replace(/\s+/g,' ').trim();
      return (
        t.indexOf('أبرز التصنيفات')!==-1 ||
        t.indexOf('التصنيفات')!==-1 ||
        t.indexOf('Categories')!==-1
      );
    });

    if(!cats) return null;

    var node=
      cats.closest('section') ||
      cats.closest('.home-block') ||
      cats.closest('[class*="categories"]') ||
      cats.closest('.container') ||
      cats.parentElement;

    if(main){
      while(
        node &&
        node.parentElement &&
        node.parentElement!==main &&
        node.parentElement!==document.body
      ){
        node=node.parentElement;
      }
    }

    return node;
  }

  function render(){
    if(document.getElementById(ROOT)) return true;

    var main=document.querySelector('main')||document.body;
    if(!main) return false;

    style();

    var worlds=WORLDS.map(function(w){
      return (
        '<a class="barah-v15-world" href="'+w.url+'">' +
          '<span class="barah-v15-icon">'+w.icon+'</span>' +
          '<span>' +
            '<strong>'+w.title+'</strong>' +
            '<small>'+w.text+'</small>' +
          '</span>' +
        '</a>'
      );
    }).join('');

    var missions=MISSIONS.map(function(m){
      return (
        '<a class="barah-v15-mission" href="'+m.url+'">' +
          '<em>'+m.eyebrow+'</em>' +
          '<strong>'+m.title+'</strong>' +
          '<p>'+m.text+'</p>' +
          '<b>استكشف الآن ←</b>' +
        '</a>'
      );
    }).join('');

    var section=document.createElement('section');
    section.id=ROOT;
    section.setAttribute('aria-label','اكتشف بارعة');

    section.innerHTML=
      '<div class="barah-v15-head">' +
        '<div>' +
          '<span class="barah-v15-kicker">اكتشف بارعة</span>' +
          '<h2>ابدأ من احتياجك</h2>' +
          '<p class="barah-v15-sub">اختر احتياجك ووصل للمنتج مباشرة</p>' +
        '</div>' +
      '</div>' +
      '<div class="barah-v15-worlds">'+worlds+'</div>' +
      '<div class="barah-v15-missions">' +
        '<div class="barah-v15-missions-head">' +
          '<h3>وش تبغى تحل اليوم؟</h3>' +
          '<span>مسارات سريعة للشراء</span>' +
        '</div>' +
        '<div class="barah-v15-mission-grid">'+missions+'</div>' +
        '<form class="barah-v15-search" action="https://barahstore.com/ar/search" method="get">' +
          '<input type="search" name="q" placeholder="ابحث عن منتج أو فكرة… مثل: سفر، مشد، تنظيم، سيارة" aria-label="ابحث في بارعة">' +
          '<button type="submit">ابحث في بارعة</button>' +
        '</form>' +
      '</div>';

    var anchor=findAnchor();

    if(anchor && anchor.parentNode){
      anchor.insertAdjacentElement('beforebegin',section);
    }else{
      var footer=document.querySelector('footer');
      if(footer && footer.parentNode) footer.insertAdjacentElement('beforebegin',section);
      else main.appendChild(section);
    }

    return true;
  }

  if(!render()){
    var n=0,t=setInterval(function(){
      n++;
      if(render()||n>=20) clearInterval(t);
    },150);
  }
})();

(function () {
  'use strict';

  if (window.__BARAH_STEP_HOME_V9__) return;
  window.__BARAH_STEP_HOME_V9__ = true;

  var HOME_ID = 'barah-step-home-v9';
  var STYLE_ID = 'barah-step-home-v9-style';

  var PICKS = [
    {
      name: 'مشد قميص رجالي نصف كم لتنسيق البطن والقوام',
      price: '36 ر.س',
      url: 'https://barahstore.com/ar/product-1810209528/p1810209528',
      image: 'https://cdn.salla.sa/qwxGZ/d2bd95f3-f864-4270-a3e3-b0c6354fe1f5-500x500-1lZRaxLMEAsnXSJQrarwnmmbIEVWVS5TxCkSS8s5.jpg',
      tag: 'اختيار قوي'
    },
    {
      name: 'شنطة حفظ العباية للسفر والمناسبات مع بطاقة اسم',
      price: '15 ر.س',
      url: 'https://barahstore.com/ar/شنطة-العبايه-لحفظ-العبايات/p2109998159',
      image: 'https://cdn.salla.sa/qwxGZ/4b815965-eff9-484b-b074-272bb289edf1-500x500-gQJhQXaDTOpKkdVxnRgwyg1krORqeeEi2V3xZcqr.webp',
      tag: 'عملي للسفر'
    },
    {
      name: 'مشد فانيلة رجالي بدون أكمام لشد البطن وتنسيق القوام',
      price: '29 ر.س',
      url: 'https://barahstore.com/ar/product-574838634/p574838634',
      image: 'https://cdn.salla.sa/qwxGZ/a47e89cb-b606-429b-803c-85dd149fdc0f-500x500-LWLWeC4DUGKkXBZROhFH9Rnlc8OIj8PftecUd3dk.png',
      tag: 'الأكثر طلبًا'
    },
    {
      name: 'حزام خصر حراري قابل للتعديل – أسود ووردي',
      price: '19 ر.س',
      url: 'https://barahstore.com/ar/product-1279211537/p1279211537',
      image: 'https://cdn.salla.sa/qwxGZ/3027a529-9076-46b2-9772-b1f422d1e893-500x500-V4uNs2ZE9ypIodHWmzZLcR9nOdxYlk4S2Z7eIHJl.jpg',
      tag: 'للرياضة والحركة'
    }
  ];

  var CATS = [
    ['المنزل والمطبخ','https://barahstore.com/ar/home-kitchen/c127906256'],
    ['العناية والأناقة','https://barahstore.com/ar/care-style/c727852954'],
    ['الرياضة واللياقة','https://barahstore.com/ar/fitness/c511828448'],
    ['السفر والرحلات','https://barahstore.com/ar/travel/c336613091'],
    ['السيارة','https://barahstore.com/ar/car/c228633582'],
    ['الطفل والألعاب','https://barahstore.com/ar/baby-toys/c694872552']
  ];

  function isHome() {
    var path = (location.pathname || '/').replace(/\/+$/, '') || '/';
    if (/^\/(ar|en)?$/.test(path)) return true;
    if (location.hostname === 'salla.sa' && /^\/br1$/.test(path)) return true;
    return !!document.querySelector('main');
  }

  if (!isHome()) return;

  function ensureStyle() {
    if (document.getElementById(STYLE_ID)) return;

    var s = document.createElement('style');
    s.id = STYLE_ID;
    s.textContent = `
#${HOME_ID}{
  direction:rtl;
  width:min(1320px,calc(100% - 40px));
  margin:26px auto;
  box-sizing:border-box;
  font-family:inherit
}
#${HOME_ID} *{box-sizing:border-box}
#${HOME_ID} .barah-v9-shell{
  position:relative;
  overflow:hidden;
  padding:26px;
  border:1px solid #f1e3d7;
  border-radius:24px;
  background:
    radial-gradient(circle at 12% 10%,rgba(255,122,24,.10),transparent 28%),
    radial-gradient(circle at 92% 12%,rgba(239,68,68,.08),transparent 26%),
    #fffdfa;
  box-shadow:0 16px 45px rgba(31,24,19,.06)
}
#${HOME_ID} .barah-v9-head{
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap:18px;
  margin-bottom:18px
}
#${HOME_ID} .barah-v9-kicker{
  display:inline-flex;
  align-items:center;
  gap:7px;
  margin-bottom:7px;
  padding:6px 10px;
  border-radius:999px;
  background:#fff1e8;
  color:#b94716;
  font-size:12px;
  font-weight:800
}
#${HOME_ID} h2{
  margin:0;
  color:#18120f;
  font-size:28px;
  line-height:1.25;
  font-weight:900
}
#${HOME_ID} .barah-v9-sub{
  margin:7px 0 0;
  color:#76665d;
  font-size:14px;
  line-height:1.7
}
#${HOME_ID} .barah-v9-all{
  flex:0 0 auto;
  text-decoration:none;
  padding:11px 16px;
  border-radius:12px;
  color:#fff;
  background:linear-gradient(135deg,#ff7a18 0%,#ef4444 100%);
  font-size:13px;
  font-weight:800;
  box-shadow:0 8px 20px rgba(239,68,68,.18)
}
#${HOME_ID} .barah-v9-grid{
  display:grid;
  grid-template-columns:repeat(4,minmax(0,1fr));
  gap:14px
}
#${HOME_ID} .barah-v9-card{
  display:flex;
  min-width:0;
  flex-direction:column;
  overflow:hidden;
  background:#fff;
  border:1px solid #eee5df;
  border-radius:18px;
  box-shadow:0 8px 24px rgba(30,20,14,.045)
}
#${HOME_ID} .barah-v9-media{
  position:relative;
  display:block;
  aspect-ratio:1/1;
  overflow:hidden;
  background:#fff
}
#${HOME_ID} .barah-v9-media img{
  display:block;
  width:100%;
  height:100%;
  object-fit:contain;
  padding:12px;
  transition:transform .22s ease
}
#${HOME_ID} .barah-v9-card:hover .barah-v9-media img{
  transform:scale(1.025)
}
#${HOME_ID} .barah-v9-tag{
  position:absolute;
  top:10px;
  right:10px;
  z-index:2;
  padding:6px 9px;
  border-radius:999px;
  background:rgba(18,18,18,.86);
  color:#fff;
  font-size:11px;
  font-weight:800;
  backdrop-filter:blur(6px)
}
#${HOME_ID} .barah-v9-body{
  display:flex;
  flex:1;
  flex-direction:column;
  padding:13px
}
#${HOME_ID} .barah-v9-name{
  min-height:46px;
  max-height:46px;
  overflow:hidden;
  margin:0 0 8px;
  color:#201915;
  font-size:14px;
  line-height:1.6;
  font-weight:800
}
#${HOME_ID} .barah-v9-price{
  margin-bottom:11px;
  color:#d94c21;
  font-size:16px;
  font-weight:900
}
#${HOME_ID} .barah-v9-buy{
  display:block;
  margin-top:auto;
  text-align:center;
  text-decoration:none;
  padding:10px;
  border-radius:11px;
  color:#fff;
  background:linear-gradient(135deg,#ff7a18 0%,#ef4444 100%);
  font-size:13px;
  font-weight:900
}
#${HOME_ID} .barah-v9-quick{
  display:flex;
  align-items:center;
  gap:9px;
  overflow-x:auto;
  margin-top:18px;
  padding:2px 0 4px;
  scrollbar-width:none
}
#${HOME_ID} .barah-v9-quick::-webkit-scrollbar{display:none}
#${HOME_ID} .barah-v9-quick-title{
  flex:0 0 auto;
  color:#5f5149;
  font-size:12px;
  font-weight:900
}
#${HOME_ID} .barah-v9-chip{
  flex:0 0 auto;
  text-decoration:none;
  padding:8px 11px;
  border:1px solid #eadfd7;
  border-radius:999px;
  background:#fff;
  color:#3a302a;
  font-size:12px;
  font-weight:800
}
#${HOME_ID} .barah-v9-trust{
  display:grid;
  grid-template-columns:repeat(4,1fr);
  gap:8px;
  margin-top:14px
}
#${HOME_ID} .barah-v9-trust span{
  display:flex;
  align-items:center;
  justify-content:center;
  min-height:42px;
  padding:8px;
  border-radius:12px;
  background:rgba(255,255,255,.8);
  border:1px solid #eee4dd;
  color:#564940;
  font-size:12px;
  font-weight:800;
  text-align:center
}
@media(max-width:900px){
  #${HOME_ID} .barah-v9-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
  #${HOME_ID} .barah-v9-trust{grid-template-columns:repeat(2,1fr)}
}
@media(max-width:600px){
  #${HOME_ID}{
    width:calc(100% - 24px);
    margin:18px 12px
  }
  #${HOME_ID} .barah-v9-shell{
    padding:16px;
    border-radius:18px
  }
  #${HOME_ID} .barah-v9-head{
    align-items:flex-start
  }
  #${HOME_ID} h2{font-size:22px}
  #${HOME_ID} .barah-v9-sub{font-size:13px}
  #${HOME_ID} .barah-v9-all{padding:9px 11px;font-size:12px}
  #${HOME_ID} .barah-v9-grid{gap:10px}
  #${HOME_ID} .barah-v9-card{border-radius:14px}
  #${HOME_ID} .barah-v9-media img{padding:8px}
  #${HOME_ID} .barah-v9-name{
    min-height:44px;
    max-height:44px;
    font-size:13px
  }
  #${HOME_ID} .barah-v9-price{font-size:15px}
}
`;
    document.head.appendChild(s);
  }

  function findAnchor() {
    var main = document.querySelector('main');

    function liftToMainChild(node) {
      if (!node || !main) return node;
      while (
        node.parentElement &&
        node.parentElement !== main &&
        node.parentElement !== document.body
      ) {
        node = node.parentElement;
      }
      return node;
    }

    var titles = Array.prototype.slice.call(
      document.querySelectorAll(
        'h1,h2,h3,h4,.title,.section-title,.s-block__title,[class*="title"]'
      )
    );

    var cats = titles.find(function (el) {
      var t = (el.textContent || '').replace(/\s+/g,' ').trim();
      return (
        t.indexOf('أبرز التصنيفات') !== -1 ||
        t.indexOf('التصنيفات') !== -1 ||
        t.indexOf('Categories') !== -1
      );
    });

    if (cats) {
      var block =
        cats.closest('section') ||
        cats.closest('.home-block') ||
        cats.closest('[class*="categories"]') ||
        cats.closest('.container') ||
        cats.parentElement;

      return liftToMainChild(block);
    }

    return null;
  }

  function render() {
    if (document.getElementById(HOME_ID)) return true;

    ensureStyle();

    var section = document.createElement('section');
    section.id = HOME_ID;
    section.setAttribute('aria-label','مختارات بارعة');

    var cards = PICKS.map(function (p) {
      return (
        '<article class="barah-v9-card">' +
          '<a class="barah-v9-media" href="' + p.url + '">' +
            '<span class="barah-v9-tag">' + p.tag + '</span>' +
            '<img loading="lazy" decoding="async" src="' + p.image + '" alt="' + p.name.replace(/"/g,'&quot;') + '">' +
          '</a>' +
          '<div class="barah-v9-body">' +
            '<h3 class="barah-v9-name">' + p.name + '</h3>' +
            '<div class="barah-v9-price">' + p.price + '</div>' +
            '<a class="barah-v9-buy" href="' + p.url + '">عرض وشراء ←</a>' +
          '</div>' +
        '</article>'
      );
    }).join('');

    var chips = CATS.map(function (c) {
      return '<a class="barah-v9-chip" href="' + c[1] + '">' + c[0] + '</a>';
    }).join('');

    section.innerHTML =
      '<div class="barah-v9-shell">' +
        '<div class="barah-v9-head">' +
          '<div>' +
            '<span class="barah-v9-kicker">✦ مختارات بارعة</span>' +
            '<h2>مختارات بارعة التي تستحق التجربة</h2>' +
            '<p class="barah-v9-sub">منتجات عملية اخترناها لتظهر لك بسرعة، مع صور أوضح ووصول مباشر للشراء.</p>' +
          '</div>' +
          '<a class="barah-v9-all" href="https://barahstore.com/ar/home-kitchen/c127906256">عرض الأكثر مبيعًا ←</a>' +
        '</div>' +
        '<div class="barah-v9-grid">' + cards + '</div>' +
        '<div class="barah-v9-quick">' +
          '<span class="barah-v9-quick-title">اختصر الطريق:</span>' +
          chips +
        '</div>' +
        '<div class="barah-v9-trust">' +
          '<span>🚚 شحن لجميع مناطق المملكة</span>' +
          '<span>🔒 دفع آمن</span>' +
          '<span>💳 تابي وتمارا</span>' +
          '<span>↩️ استبدال واسترجاع</span>' +
        '</div>' +
      '</div>';

    var anchor = findAnchor();
    var main = document.querySelector('main') || document.body;

    if (anchor && anchor.parentNode) {
      anchor.insertAdjacentElement('afterend', section);
    } else {
      var footer = document.querySelector('footer');
      if (footer && footer.parentNode) {
        footer.insertAdjacentElement('beforebegin', section);
      } else {
        main.appendChild(section);
      }
    }

    return true;
  }

  if (!render()) {
    var tries = 0;
    var timer = setInterval(function () {
      tries++;
      if (render() || tries >= 20) clearInterval(timer);
    }, 150);
  }
})();

/* ============================================================
   BARAH STORE — STEP THEME — MOST VIEWED FINAL MERGED V3
   ملف واحد فقط: JavaScript + CSS + fallback + refresh
   الصق الملف كاملًا في JavaScript المخصص في ثيم خطوة، بدون <script>
   ============================================================ */

(function () {
  'use strict';

  if (window.__BARAH_STEP_MOST_VIEWED_FINAL_V3__) return;
  window.__BARAH_STEP_MOST_VIEWED_FINAL_V3__ = true;

  var ROOT_ID = 'barah-step-most-viewed';
  var STYLE_ID = 'barah-step-most-viewed-style';

  /* مصدر تحديث الأكثر مشاهدة — إن فشل نستخدم FALLBACK فورًا */
  var SOURCE_URL = 'https://barah-popular-products.hussho.chatgpt.site/popular.json';

  var FALLBACK = {
    periodLabel: 'الأكثر مشاهدة مؤخرًا',
    items: [
      {
        id: '1747191075',
        name: 'سماعة القرآن الكريم للمنزل بالمقبس مع ريموت – SQ669',
        url: 'https://barahstore.com/ar/سماعة-القرآن-الكريم-للمنزل-sq669-مع-ريموت-بارعة/p1747191075',
        image: 'https://cdn.files.salla.network/products/71627348/fedf598a-5a4c-4473-89b5-4972a2c3bdf3-original.webp',
        available: true
      },
      {
        id: '1923506631',
        name: 'مشط إزالة القمل الكهربائي بفلتر وإضاءة LED',
        url: 'https://barahstore.com/ar/product-1923506631/p1923506631',
        image: 'https://cdn.salla.sa/qwxGZ/8c8b724b-302f-4e36-9241-4cb4888ce28e-500x500-LIvqUHKA4iwYzlUxDutVqmDDxC8RgDZ7YBpAfou2.png',
        available: true
      },
      {
        id: '898468432',
        name: 'طقم أدوات العناية بالأظافر',
        url: 'https://barahstore.com/ar/product-898468432/p898468432',
        image: 'https://cdn.salla.sa/qwxGZ/1ab1a1ee-80bd-4baa-800e-6674ceae4c3c-454.6875x500-b6p5enTzDYrOXFY6N6dodENKQUAYF5KUpMeld6m7.jpg',
        available: true
      },
      {
        id: '1396688213',
        name: 'عربة نقل للرحلات قابلة للطي بأربع عجلات',
        url: 'https://barahstore.com/ar/product-1396688213/p1396688213',
        image: 'https://cdn.salla.sa/qwxGZ/e8645ae5-4e96-489c-b407-7562321e3c8f-475.0265674814x500-xhHmlplr26h80IHOv3BKcddgAf6fOI52tKEa0fYB.jpg',
        available: true
      },
      {
        id: '1455538329',
        name: 'طقم حبال مقاومة رياضية 11 قطعة – 5 مستويات للتمارين المنزلية',
        url: 'https://barahstore.com/ar/product-1455538329/p1455538329',
        image: 'https://cdn.salla.sa/qwxGZ/515fab97-aab3-448a-8a7b-6b9287691cb0-500x500-EA6WdMUjzvNizNpEGrkn2zERP8MWbIpNct1GNX0K.webp',
        available: true
      },
      {
        id: '1169543961',
        name: 'عقلة جدارية لتمارين السحب المنزلية | Pull Up Bar',
        url: 'https://barahstore.com/ar/product-1169543961/p1169543961',
        image: 'https://cdn.salla.sa/qwxGZ/25c7de6c-9062-4044-83f1-06e5030dd533-454.6875x500-awxqbgLolsoZzf8uYEmAfrQE8wJ6746kM0sr26ex.jpg',
        available: true
      }
    ]
  };

  function isHome() {
    var path = (location.pathname || '/').replace(/\/+$/, '') || '/';

    if (/^\/(ar|en)?$/.test(path)) return true;

    if (location.hostname === 'salla.sa' && /^\/br1$/.test(path)) return true;

    if (
      document.body &&
      !/\/p\d+/.test(path) &&
      !/\/c\d+/.test(path) &&
      document.querySelector('main')
    ) return true;

    return false;
  }

  if (!isHome()) return;

  function safeURL(value, image) {
    try {
      var u = new URL(value, location.origin);

      if (u.protocol !== 'https:') return null;

      if (image) {
        if (
          u.hostname !== 'cdn.salla.sa' &&
          u.hostname !== 'cdn.files.salla.network'
        ) return null;
      } else {
        if (
          u.hostname !== 'barahstore.com' &&
          u.hostname !== 'www.barahstore.com'
        ) return null;
      }

      return u.href;
    } catch (e) {
      return null;
    }
  }

  function normalizeData(data) {
    if (!data || !Array.isArray(data.items)) return null;

    var seen = {};
    var items = [];

    for (var i = 0; i < data.items.length; i++) {
      var p = data.items[i];

      if (!p || p.available === false) continue;
      if (!/^\d+$/.test(String(p.id || ''))) continue;
      if (typeof p.name !== 'string' || !p.name.trim()) continue;

      var url = safeURL(p.url, false);
      var image = safeURL(p.image, true);

      if (!url || !image) continue;
      if (seen[p.id]) continue;

      seen[p.id] = true;

      items.push({
        id: String(p.id),
        name: p.name.trim().slice(0, 180),
        url: url,
        image: image,
        available: true
      });

      if (items.length >= 6) break;
    }

    if (!items.length) return null;

    return {
      periodLabel:
        typeof data.periodLabel === 'string'
          ? data.periodLabel.trim().slice(0, 100)
          : '',
      items: items
    };
  }

  function ensureStyle() {
    if (document.getElementById(STYLE_ID)) return;

    var style = document.createElement('style');
    style.id = STYLE_ID;
    style.textContent = `
#barah-step-most-viewed{
  direction:rtl;
  width:min(1180px,calc(100% - 40px));
  max-width:1180px;
  margin:20px auto 24px;
  padding:16px;
  min-height:0;
  background:#fffaf6;
  border:1px solid #f1e5dc;
  border-radius:18px;
  box-sizing:border-box
}
#barah-step-most-viewed *{box-sizing:border-box}
#barah-step-most-viewed .barah-step-most-viewed__head{
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap:12px;
  margin-bottom:14px
}
#barah-step-most-viewed h2{
  margin:0 0 3px;
  font-size:20px;
  line-height:1.4;
  font-weight:900;
  color:#7c2d12
}
#barah-step-most-viewed .barah-step-most-viewed__head p{
  margin:0;
  font-size:13px;
  color:#72584b
}
#barah-step-most-viewed .barah-step-most-viewed__track{
  display:grid;
  grid-template-columns:repeat(4,minmax(0,1fr));
  gap:12px;
  overflow:visible;
  padding:2px 2px 4px
}
#barah-step-most-viewed .barah-step-most-viewed__card{
  min-width:0;
  display:grid;
  grid-template-columns:92px minmax(0,1fr);
  grid-template-rows:auto auto;
  gap:8px 10px;
  align-items:center;
  background:#fff;
  border:1px solid #eee3db;
  border-radius:14px;
  padding:10px
}
#barah-step-most-viewed a{text-decoration:none}
#barah-step-most-viewed .barah-step-most-viewed__product{
  display:contents
}
#barah-step-most-viewed .barah-step-most-viewed__product img{
  grid-column:1;
  grid-row:1 / span 2;
  display:block;
  width:92px;
  height:92px;
  object-fit:contain;
  background:#fff;
  border-radius:10px
}
#barah-step-most-viewed .barah-step-most-viewed__product h3{
  grid-column:2;
  grid-row:1;
  margin:0;
  min-height:0;
  max-height:42px;
  overflow:hidden;
  color:#29211d;
  font-size:13px;
  font-weight:800;
  line-height:1.6
}
#barah-step-most-viewed .barah-step-most-viewed__cta{
  grid-column:2;
  grid-row:2;
  display:inline-block;
  width:max-content;
  max-width:100%;
  margin:0;
  padding:8px 10px;
  border-radius:9px;
  text-align:center;
  font-size:12px;
  font-weight:900;
  color:#fff;
  background:linear-gradient(135deg,#ff7a18 0%,#ef4444 100%)
}
#barah-step-most-viewed a:focus-visible{
  outline:3px solid #9a3412;
  outline-offset:3px
}
@media(max-width:1100px){
  #barah-step-most-viewed .barah-step-most-viewed__track{
    grid-template-columns:repeat(2,minmax(0,1fr))
  }
}
@media(max-width:767px){
  #barah-step-most-viewed{
    width:calc(100% - 24px);
    margin:16px 12px 20px;
    padding:14px 12px
  }
  #barah-step-most-viewed h2{font-size:19px}
  #barah-step-most-viewed .barah-step-most-viewed__track{
    display:grid;
    grid-template-columns:1fr;
    gap:9px;
    overflow:visible;
    padding:2px 0
  }
  #barah-step-most-viewed .barah-step-most-viewed__card{
    grid-template-columns:82px minmax(0,1fr)
  }
  #barah-step-most-viewed .barah-step-most-viewed__product img{
    width:82px;
    height:82px
  }
}
`;

    document.head.appendChild(style);
  }

  function track(item) {
    try {
      if (typeof window.gtag === 'function') {
        window.gtag('event', 'select_item', {
          item_list_id: 'barah_step_most_viewed',
          item_list_name: 'الأكثر مشاهدة',
          items: [
            {
              item_id: String(item.id),
              item_name: item.name
            }
          ]
        });
      }
    } catch (e) {}
  }

  function findInsertPoint() {
    var main = document.querySelector('main');
    var titles = Array.prototype.slice.call(
      document.querySelectorAll(
        'h1,h2,h3,h4,.title,.section-title,.s-block__title,[class*="title"]'
      )
    );

    function norm(el) {
      return (el.textContent || '')
        .replace(/\s+/g, ' ')
        .trim();
    }

    function baseBlock(el) {
      if (!el) return null;

      return (
        el.closest('section') ||
        el.closest('.home-block') ||
        el.closest('[class*="products"]') ||
        el.closest('[class*="categories"]') ||
        el.closest('.container') ||
        el.parentElement
      );
    }

    function liftToMainChild(el) {
      if (!el) return null;

      if (!main) return el;

      var node = el;

      while (
        node.parentElement &&
        node.parentElement !== main &&
        node.parentElement !== document.body
      ) {
        node = node.parentElement;
      }

      return node;
    }

    function resolve(el) {
      return liftToMainChild(baseBlock(el));
    }

    /* Preferred: after latest products */
    var latest = titles.find(function (el) {
      var t = norm(el);
      return (
        t.indexOf('أحدث المنتجات') !== -1 ||
        t.indexOf('وصل حديث') !== -1 ||
        t.indexOf('Latest Products') !== -1
      );
    });

    if (latest) return resolve(latest);

    /* Step preview fallback: after categories */
    var categories = titles.find(function (el) {
      var t = norm(el);
      return (
        t.indexOf('أبرز التصنيفات') !== -1 ||
        t.indexOf('التصنيفات') !== -1 ||
        t.indexOf('Categories') !== -1
      );
    });

    if (categories) return resolve(categories);

    /* Last fallback: after best selling */
    var best = titles.find(function (el) {
      var t = norm(el);
      return (
        t.indexOf('الأكثر مبيع') !== -1 ||
        t.indexOf('Best Selling') !== -1
      );
    });

    return resolve(best);
  }
  function render(data) {
    data = normalizeData(data) || normalizeData(FALLBACK);
    if (!data) return false;

    var main = document.querySelector('main') || document.body;
    if (!main) return false;

    ensureStyle();

    var old = document.getElementById(ROOT_ID);
    if (old) old.remove();

    var section = document.createElement('section');
    section.id = ROOT_ID;
    section.className = 'barah-step-most-viewed';
    section.setAttribute('aria-label', 'الأكثر مشاهدة');

    var head = document.createElement('div');
    head.className = 'barah-step-most-viewed__head';

    var titleWrap = document.createElement('div');

    var title = document.createElement('h2');
    title.textContent = 'الأكثر مشاهدة مؤخرًا';

    var subtitle = document.createElement('p');
    subtitle.textContent = data.periodLabel
      ? String(data.periodLabel).replace(/^بحسب مشاهدات\s*/,'')
      : 'منتجات لفتت انتباه الزوار مؤخرًا';

    titleWrap.appendChild(title);
    titleWrap.appendChild(subtitle);
    head.appendChild(titleWrap);

    var trackEl = document.createElement('div');
    trackEl.className = 'barah-step-most-viewed__track';
    trackEl.setAttribute('role', 'list');

    data.items.forEach(function (item) {
      var card = document.createElement('article');
      card.className = 'barah-step-most-viewed__card';
      card.setAttribute('role', 'listitem');

      var productLink = document.createElement('a');
      productLink.className = 'barah-step-most-viewed__product';
      productLink.href = item.url;
      productLink.setAttribute('aria-label', item.name);

      var img = document.createElement('img');
      img.src = item.image;
      img.alt = item.name;
      img.loading = 'lazy';
      img.decoding = 'async';
      img.width = 220;
      img.height = 220;

      var name = document.createElement('h3');
      name.textContent = item.name;

      var cta = document.createElement('a');
      cta.className = 'barah-step-most-viewed__cta';
      cta.href = item.url;
      cta.textContent = 'عرض وشراء ←';

      productLink.addEventListener('click', function () {
        track(item);
      });

      cta.addEventListener('click', function () {
        track(item);
      });

      productLink.appendChild(img);
      productLink.appendChild(name);

      card.appendChild(productLink);
      card.appendChild(cta);

      trackEl.appendChild(card);
    });

    section.appendChild(head);
    section.appendChild(trackEl);

    var homePro = document.getElementById('barah-step-home-v9');
    var anchor = homePro || findInsertPoint();

    if (anchor && anchor.parentNode) {
      anchor.insertAdjacentElement('afterend', section);
    } else {
      /*
        Safe final fallback:
        append inside main only. Never use generic [class*="footer"]
        because Step contains internal footer-like wrappers that can
        constrain the section width.
      */
      var realFooter = document.querySelector('footer');

      if (
        realFooter &&
        realFooter.parentNode &&
        main.contains(realFooter)
      ) {
        realFooter.insertAdjacentElement('beforebegin', section);
      } else {
        main.appendChild(section);
      }
    }

    document.documentElement.setAttribute(
      'data-barah-step-most-viewed',
      'ready'
    );

    /*
      One bounded correction after Step hydration:
      re-evaluate the intended content anchor once, without observers.
    */
    setTimeout(function () {
      var current = document.getElementById(ROOT_ID);
      if (!current) return;

      var homePro = document.getElementById('barah-step-home-v9');
      var finalAnchor = homePro || findInsertPoint();

      if (
        finalAnchor &&
        finalAnchor.parentNode &&
        current.previousElementSibling !== finalAnchor
      ) {
        finalAnchor.insertAdjacentElement('afterend', current);
      }
    }, 700);

    return true;
  }

  function start() {
    var fallback = normalizeData(FALLBACK);

    if (!render(fallback)) {
      var tries = 0;

      var timer = setInterval(function () {
        tries++;

        if (render(fallback) || tries >= 20) {
          clearInterval(timer);
        }
      }, 150);
    }

    /* تحديث خلفي: لا يؤخر ظهور القسم */
    if (!SOURCE_URL || !window.__BARAH_CAN_REMOTE_POPULAR__) return;

    try {
      var controller = new AbortController();
      var timeout = setTimeout(function () {
        controller.abort();
      }, 3500);

      var url = new URL(SOURCE_URL);
      url.searchParams.set(
        'barah_refresh',
        String(Math.floor(Date.now() / 300000))
      );

      fetch(url.href, {
        signal: controller.signal,
        credentials: 'omit',
        cache: 'no-store'
      })
        .then(function (response) {
          if (!response.ok) {
            throw new Error('source unavailable');
          }

          return response.json();
        })
        .then(function (payload) {
          var fresh = normalizeData(payload);

          if (fresh) {
            try {
              localStorage.setItem(
                'barah-step-most-viewed-last',
                JSON.stringify(payload)
              );
            } catch (e) {}

            render(fresh);
          }
        })
        .catch(function () {
          try {
            var cached = normalizeData(
              JSON.parse(
                localStorage.getItem(
                  'barah-step-most-viewed-last'
                )
              )
            );

            if (cached) render(cached);
          } catch (e) {}
        })
        .finally(function () {
          clearTimeout(timeout);
        });
    } catch (e) {}
  }

  if (document.body) {
    start();
  } else {
    document.addEventListener(
      'DOMContentLoaded',
      start,
      { once: true }
    );
  }
})();

/* ============================================================
   BARAH — STEP HOME PRO V11 SAFE STRUCTURE
   Structural positioning instead of CSS breakout transforms.
   ============================================================ */

(function(){
  'use strict';

  if(window.__BARAH_STEP_V18_PERSONAL__) return;
  window.__BARAH_STEP_V18_PERSONAL__ = true;

  var RECENT_KEY='barah_recent_products_v18';
  var INTEREST_KEY='barah_interest_v18';
  var ROOT='barah-step-personal-v18';
  var STYLE='barah-step-personal-v18-style';

  var CAT_MAP=[
    {key:'home',label:'المنزل والمطبخ',url:'/ar/home-kitchen/c127906256'},
    {key:'care',label:'العناية والأناقة',url:'/ar/care-style/c727852954'},
    {key:'fitness',label:'الرياضة واللياقة',url:'/ar/fitness/c511828448'},
    {key:'travel',label:'السفر والرحلات',url:'/ar/travel/c336613091'},
    {key:'car',label:'السيارة',url:'/ar/car/c228633582'},
    {key:'baby',label:'الطفل والألعاب',url:'/ar/baby-toys/c694872552'},
    {key:'pets',label:'الحيوانات الأليفة',url:'/ar/pets/c92693286'}
  ];

  function safeJSON(value,fallback){
    try{
      var parsed=JSON.parse(value);
      return parsed || fallback;
    }catch(e){
      return fallback;
    }
  }

  function getRecent(){
    return safeJSON(localStorage.getItem(RECENT_KEY),[]);
  }

  function setRecent(items){
    try{
      localStorage.setItem(RECENT_KEY,JSON.stringify(items.slice(0,12)));
    }catch(e){}
  }

  function getInterest(){
    return safeJSON(localStorage.getItem(INTEREST_KEY),{});
  }

  function setInterest(obj){
    try{
      localStorage.setItem(INTEREST_KEY,JSON.stringify(obj));
    }catch(e){}
  }

  function cleanText(s,max){
    return String(s||'').replace(/\s+/g,' ').trim().slice(0,max||180);
  }

  function isProductPage(){
    return /\/p\d+(?:[/?#]|$)/.test(location.pathname);
  }

  function isHome(){
    var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
    if(/^\/(ar|en)?$/.test(p)) return true;
    if(location.hostname==='salla.sa' && /^\/br1$/.test(p)) return true;
    return false;
  }

  function captureProduct(){
    if(!isProductPage()) return;

    var title=
      document.querySelector('meta[property="og:title"]')?.content ||
      document.querySelector('h1')?.textContent ||
      document.title;

    var image=
      document.querySelector('meta[property="og:image"]')?.content ||
      '';

    var canonical=
      document.querySelector('link[rel="canonical"]')?.href ||
      location.href.split('?')[0];

    var price=
      document.querySelector('meta[property="product:price:amount"]')?.content ||
      document.querySelector('[itemprop="price"]')?.content ||
      '';

    if(!title || !canonical) return;

    var item={
      id:(location.pathname.match(/p(\d+)/)||[])[1]||canonical,
      title:cleanText(title,150),
      image:image,
      url:canonical,
      price:cleanText(price,30),
      ts:Date.now()
    };

    var items=getRecent().filter(function(x){
      return x && x.url!==item.url;
    });

    items.unshift(item);
    setRecent(items);
  }

  function trackCategoryClicks(){
    document.addEventListener('click',function(e){
      var a=e.target.closest && e.target.closest('a[href]');
      if(!a) return;

      var href=a.getAttribute('href')||'';
      var match=CAT_MAP.find(function(c){
        return href.indexOf(c.url)!==-1;
      });

      if(!match) return;

      var data=getInterest();
      data[match.key]=(data[match.key]||0)+1;
      setInterest(data);
    },{passive:true});
  }

  function topInterest(){
    var data=getInterest();
    var best=null;
    var score=0;

    CAT_MAP.forEach(function(c){
      var n=Number(data[c.key]||0);
      if(n>score){
        score=n;
        best=c;
      }
    });

    return best;
  }

  function addStyle(){
    if(document.getElementById(STYLE)) return;

    var s=document.createElement('style');
    s.id=STYLE;
    s.textContent=`
#${ROOT}{
  direction:rtl;
  width:min(1180px,calc(100% - 40px));
  margin:22px auto;
  box-sizing:border-box;
  font-family:inherit
}
#${ROOT} *{box-sizing:border-box}
#${ROOT} .barah-v18-shell{
  padding:20px;
  border:1px solid #ece2db;
  border-radius:20px;
  background:#fff;
  box-shadow:0 10px 28px rgba(35,24,18,.04)
}
#${ROOT} .barah-v18-head{
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap:16px;
  margin-bottom:13px
}
#${ROOT} .barah-v18-head small{
  display:block;
  margin-bottom:4px;
  color:#d35420;
  font-size:10px;
  font-weight:900
}
#${ROOT} .barah-v18-head h2{
  margin:0;
  color:#211914;
  font-size:21px;
  font-weight:950
}
#${ROOT} .barah-v18-head p{
  margin:5px 0 0;
  color:#786960;
  font-size:11px
}
#${ROOT} .barah-v18-interest{
  flex:0 0 auto;
  text-decoration:none;
  padding:8px 11px;
  border-radius:999px;
  background:#fff2e9;
  color:#bd4b1b;
  font-size:11px;
  font-weight:900
}
#${ROOT} .barah-v18-track{
  display:grid;
  grid-template-columns:repeat(4,minmax(0,1fr));
  gap:10px
}
#${ROOT} .barah-v18-card{
  display:grid;
  grid-template-columns:88px minmax(0,1fr);
  gap:10px;
  align-items:center;
  min-width:0;
  padding:10px;
  text-decoration:none;
  border:1px solid #eee5df;
  border-radius:14px;
  background:#fffdfb
}
#${ROOT} .barah-v18-card img{
  display:block;
  width:88px;
  height:88px;
  object-fit:contain;
  border-radius:10px;
  background:#fff
}
#${ROOT} .barah-v18-card strong{
  display:block;
  max-height:43px;
  overflow:hidden;
  margin-bottom:7px;
  color:#2a211c;
  font-size:12px;
  line-height:1.6;
  font-weight:850
}
#${ROOT} .barah-v18-card span{
  color:#d65420;
  font-size:11px;
  font-weight:900
}
@media(max-width:900px){
  #${ROOT} .barah-v18-track{grid-template-columns:repeat(2,minmax(0,1fr))}
}
@media(max-width:600px){
  #${ROOT}{
    width:calc(100% - 24px);
    margin:16px 12px
  }
  #${ROOT} .barah-v18-shell{padding:14px}
  #${ROOT} .barah-v18-head{align-items:flex-start;flex-direction:column}
  #${ROOT} .barah-v18-track{grid-template-columns:1fr}
}
`;
    document.head.appendChild(s);
  }

  function renderHome(){
    if(!isHome()) return;
    if(document.getElementById(ROOT)) return;

    var recent=getRecent()
      .filter(function(x){return x && x.title && x.url;})
      .slice(0,4);

    var interest=topInterest();

    /* لا نظهر القسم للزائر الجديد؛ نمنع الزحمة ونحافظ على تجربة نظيفة */
    if(!recent.length && !interest) return;

    addStyle();

    var section=document.createElement('section');
    section.id=ROOT;
    section.setAttribute('aria-label','اقتراحات مخصصة');

    var interestHTML='';
    if(interest){
      interestHTML=
        '<a class="barah-v18-interest" href="'+interest.url+'">'+
          'يبدو أنك مهتم بـ '+interest.label+' ←'+
        '</a>';
    }

    var cards=recent.map(function(p){
      var img=p.image
        ? '<img loading="lazy" decoding="async" src="'+p.image+'" alt="'+p.title.replace(/"/g,'&quot;')+'">'
        : '<span style="width:88px;height:88px;border-radius:10px;background:#f7f3ef;display:block"></span>';

      var price=p.price ? p.price+' ر.س' : 'عرض المنتج';

      return (
        '<a class="barah-v18-card" href="'+p.url+'">'+
          img+
          '<span>'+
            '<strong>'+p.title+'</strong>'+
            '<span>'+price+' ←</span>'+
          '</span>'+
        '</a>'
      );
    }).join('');

    section.innerHTML=
      '<div class="barah-v18-shell">'+
        '<div class="barah-v18-head">'+
          '<div>'+
            '<small>تجربة أذكى</small>'+
            '<h2>كمل من وين وقفت</h2>'+
            '<p>آخر منتجات شاهدتها محفوظة على جهازك فقط.</p>'+
          '</div>'+
          interestHTML+
        '</div>'+
        (cards ? '<div class="barah-v18-track">'+cards+'</div>' : '')+
      '</div>';

    var discovery=document.getElementById('barah-step-discovery-v15');
    var editorial=document.getElementById('barah-step-editorial-v17');
    var anchor=editorial || discovery;

    if(anchor && anchor.parentNode){
      anchor.insertAdjacentElement('afterend',section);
    }else{
      var main=document.querySelector('main')||document.body;
      main.appendChild(section);
    }
  }

  captureProduct();
  trackCategoryClicks();

  if(document.readyState==='loading'){
    document.addEventListener('DOMContentLoaded',renderHome,{once:true});
  }else{
    renderHome();
  }
})();

(function(){
'use strict';
if(window.__BARAH_V32_SUPPORT_SECTIONS__)return;
window.__BARAH_V32_SUPPORT_SECTIONS__=true;

function home(){
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  return /^\/(ar|en)?$/.test(p)||(location.hostname==='salla.sa'&&/^\/br1$/.test(p));
}
if(!home())return;

var style=document.createElement('style');
style.id='barah-v32-support-style';
style.textContent=`
#barah-step-catalog-v32,#barah-step-wholesale-v32{
 direction:rtl;width:min(1240px,calc(100% - 32px));margin:18px auto;box-sizing:border-box;font-family:inherit
}
#barah-step-catalog-v32 * ,#barah-step-wholesale-v32 *{box-sizing:border-box}
#barah-step-catalog-v32 .v32box,#barah-step-wholesale-v32 .v32box{
 display:grid;grid-template-columns:1.1fr .9fr;gap:16px;align-items:center;padding:18px 20px;
 border:1px solid #eadfd7;border-radius:18px;background:linear-gradient(135deg,#fffaf6,#fff)
}
#barah-step-catalog-v32 h3,#barah-step-wholesale-v32 h3{margin:0;color:#201813;font-size:20px;font-weight:900}
#barah-step-catalog-v32 p,#barah-step-wholesale-v32 p{margin:6px 0 0;color:#76665d;font-size:12px;line-height:1.7}
.v32actions{display:flex;flex-wrap:wrap;justify-content:flex-end;gap:8px}
.v32actions a{text-decoration:none;padding:10px 12px;border-radius:10px;border:1px solid #e8ddd5;background:#fff;color:#302620;font-size:11px;font-weight:900}
.v32actions a:first-child{color:#fff;border:0;background:linear-gradient(135deg,#ff7a18,#ef4444)}
@media(max-width:767px){
 #barah-step-catalog-v32,#barah-step-wholesale-v32{width:calc(100% - 24px);margin:16px 12px}
 #barah-step-catalog-v32 .v32box,#barah-step-wholesale-v32 .v32box{grid-template-columns:1fr;padding:15px}
 .v32actions{justify-content:flex-start}
 .v32actions a{flex:1 1 auto;text-align:center}
}
`;
document.head.appendChild(style);

function ensure(id,html){
  var el=document.getElementById(id);
  if(el)return el;
  el=document.createElement('section');
  el.id=id;
  el.innerHTML=html;
  (document.querySelector('main')||document.body).appendChild(el);
  return el;
}

ensure('barah-step-catalog-v32',
 '<div class="v32box"><div><h3>كل كتالوج بارعة على بعد خطوة</h3><p>استكشف كل المنتجات أو ابدأ من الأعلى طلبًا والجديد.</p></div><div class="v32actions"><a href="https://barahstore.com/ar/home-kitchen/c127906256">عرض كل المنتجات ←</a><a href="https://barahstore.com/ar/home-kitchen/c127906256">الأعلى طلبًا</a><a href="https://barahstore.com/ar/search?q=وصل%20حديثاً">وصل حديثًا</a></div></div>'
);
ensure('barah-step-wholesale-v32',
 '<div class="v32box"><div><h3>تشتري بالجملة أو تجهّز متجرك؟</h3><p>سعر الجملة يبدأ من 6 قطع لبعض الأصناف، مع خيارات للكميات الأكبر وشحن داخل السعودية.</p></div><div class="v32actions"><a href="https://wa.me/966533302737?text=%D9%85%D8%B1%D8%AD%D8%A8%D8%A7%D8%8C%20%D8%A3%D8%B1%D9%8A%D8%AF%20%D8%A7%D9%84%D8%A7%D8%B3%D8%AA%D9%81%D8%B3%D8%A7%D8%B1%20%D8%B9%D9%86%20%D8%A7%D9%84%D8%AC%D9%85%D9%84%D8%A9">استفسر عن الجملة ←</a><a href="https://barahstore.com/ar/home-kitchen/c127906256">ابدأ بالأعلى طلبًا</a></div></div>'
);
})();

(function(){
'use strict';
if(window.__BARAH_STEP_RC23_STYLE__)return;
window.__BARAH_STEP_RC23_STYLE__=true;

var id='barah-step-rc23-style';
if(document.getElementById(id))return;

var s=document.createElement('style');
s.id=id;
s.textContent=`
html{overflow-x:hidden}
#barah-step-hero-v12,
#barah-step-modes-v19,
#barah-step-orchestrator-v20,
#barah-step-discovery-v15,
#barah-step-editorial-v17,
#barah-step-home-v9,
#barah-step-catalog-cta-v21,
#barah-step-most-viewed,
#barah-step-wholesale-v16,
#barah-step-personal-v18{
  box-sizing:border-box
}
#barah-step-hero-v12 img,
#barah-step-home-v9 img,
#barah-step-most-viewed img,
#barah-step-personal-v18 img{
  aspect-ratio:1/1
}
@media(prefers-reduced-motion:reduce){
  #barah-step-hero-v12 *,
  #barah-step-modes-v19 *,
  #barah-step-orchestrator-v20 *,
  #barah-step-discovery-v15 *,
  #barah-step-editorial-v17 *,
  #barah-step-home-v9 *,
  #barah-step-most-viewed *{
    animation:none!important;
    transition:none!important;
    scroll-behavior:auto!important
  }
}
`;
document.head.appendChild(s);
})();

(function(){
'use strict';
if(window.__BARAH_V32_POLISH__)return;
window.__BARAH_V32_POLISH__=true;
var s=document.createElement('style');
s.id='barah-v32-final-style';
s.textContent=`
html{overflow-x:hidden}
#barah-step-home-v9,#barah-step-most-viewed{width:min(1240px,calc(100% - 32px))!important;max-width:1240px!important}
#barah-step-home-v9 .barah-v9-shell{padding:26px!important;border-radius:24px!important;box-shadow:0 14px 32px rgba(35,24,18,.05)!important}
#barah-step-home-v9 .barah-v9-grid{grid-template-columns:repeat(4,minmax(0,1fr))!important;gap:16px!important}
#barah-step-home-v9 .barah-v9-card{border-radius:18px!important}
#barah-step-home-v9 .barah-v9-media{min-height:220px!important}
#barah-step-home-v9 .barah-v9-body{padding:14px!important}
#barah-step-most-viewed .barah-step-most-viewed__card{grid-template-columns:100px minmax(0,1fr)!important;padding:12px!important;border-radius:16px!important}
#barah-step-most-viewed .barah-step-most-viewed__product img{width:100px!important;height:100px!important}
@media(max-width:1100px){#barah-step-home-v9 .barah-v9-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important}}
@media(max-width:767px){
 #barah-step-home-v9,#barah-step-most-viewed{width:calc(100% - 24px)!important;margin-left:12px!important;margin-right:12px!important}
 #barah-step-home-v9 .barah-v9-shell{padding:16px!important}
 #barah-step-home-v9 .barah-v9-media{min-height:165px!important}
 #barah-step-most-viewed .barah-step-most-viewed__card{grid-template-columns:86px minmax(0,1fr)!important}
 #barah-step-most-viewed .barah-step-most-viewed__product img{width:86px!important;height:86px!important}
}
`;
document.head.appendChild(s);
})();

(function(){
'use strict';
if(window.__BARAH_V32_ORCHESTRATOR__)return;
window.__BARAH_V32_ORCHESTRATOR__=true;

function home(){
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  return /^\/(ar|en)?$/.test(p)||(location.hostname==='salla.sa'&&/^\/br1$/.test(p));
}
if(!home()){
  document.documentElement.setAttribute('data-barah-v32','ready');
  return;
}

var topIds=['barah-step-hero-v12','barah-step-shipping-v24','barah-step-discovery-v15','barah-step-personal-v18'];
var afterIds=['barah-step-home-v9','barah-step-catalog-v32','barah-step-most-viewed'];

function custom(el){
  return !!(el&&el.closest&&el.closest(
    '#barah-step-hero-v12,#barah-step-shipping-v24,#barah-step-discovery-v15,#barah-step-personal-v18,#barah-step-home-v9,#barah-step-most-viewed,#barah-step-catalog-v32,#barah-step-wholesale-v32'
  ));
}

function shelf(){
  var nodes=Array.prototype.slice.call(document.querySelectorAll(
    'section,.home-block,[class*="products"],[class*="product-slider"],[class*="latest"],[class*="featured"]'
  ));
  var best=null,bestScore=-1;
  nodes.forEach(function(el){
    if(custom(el))return;
    var cards=el.querySelectorAll('custom-salla-product-card,product-card,[class*="product-card"],[class*="product-block"]').length;
    var t=(el.textContent||'').replace(/\s+/g,' ').trim();
    var score=cards*10;
    if(t.indexOf('أحدث المنتجات')!==-1)score+=120;
    if(t.indexOf('الأكثر مبيع')!==-1)score+=100;
    if(cards>=4&&score>bestScore){best=el;bestScore=score}
  });
  return best;
}

function moveBefore(anchor,ids){
  var frag=document.createDocumentFragment();
  ids.forEach(function(id){var n=document.getElementById(id);if(n)frag.appendChild(n)});
  if(frag.childNodes.length)anchor.parentNode.insertBefore(frag,anchor);
}
function moveAfter(anchor,ids){
  var cur=anchor;
  ids.forEach(function(id){
    var n=document.getElementById(id);
    if(!n)return;
    cur.insertAdjacentElement('afterend',n);
    cur=n;
  });
}

var done=false,obs=null;
function run(){
  if(done)return true;
  var sh=shelf();
  if(!sh)return false;
  moveBefore(sh,topIds);
  moveAfter(sh,afterIds);
  var w=document.getElementById('barah-step-wholesale-v32');
  var f=document.querySelector('footer');
  if(w&&f&&f.parentNode)f.insertAdjacentElement('beforebegin',w);
  document.documentElement.setAttribute('data-barah-v32','ready');
  done=true;
  if(obs)obs.disconnect();
  return true;
}

obs=new MutationObserver(function(){run()});
obs.observe(document.documentElement,{childList:true,subtree:true});
run();
document.addEventListener('DOMContentLoaded',run,{once:true});
setTimeout(run,200);
setTimeout(run,500);
setTimeout(function(){
  if(obs)obs.disconnect();
  if(!done)document.documentElement.setAttribute('data-barah-v32','ready');
},1800);
})();

/* ============================================================
   BARAH — STEP V33 LATEST PRODUCTS REDESIGN
   يعيد تقديم "أحدث المنتجات" كرف أنيق وخفيف بدل الشبكة الطويلة.
   ============================================================ */
(function(){
'use strict';

if(window.__BARAH_STEP_V33_LATEST__)return;
window.__BARAH_STEP_V33_LATEST__=true;

var STYLE='barah-step-v33-latest-style';
var CLASS='barah-v33-latest';
var CARD='barah-v33-latest-card';

function isHome(){
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  if(/^\/(ar|en)?$/.test(p))return true;
  if(location.hostname==='salla.sa'&&/^\/br1$/.test(p))return true;
  return false;
}
if(!isHome())return;

function addStyle(){
  if(document.getElementById(STYLE))return;

  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
.${CLASS}{
  width:min(1240px,calc(100% - 32px))!important;
  max-width:1240px!important;
  margin:20px auto 24px!important;
  padding:20px!important;
  border:1px solid #eee2d9!important;
  border-radius:22px!important;
  background:#fff!important;
  box-shadow:0 12px 30px rgba(34,24,18,.045)!important;
  box-sizing:border-box!important
}
.${CLASS} .barah-v33-head{
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap:14px;
  margin-bottom:16px
}
.${CLASS} .barah-v33-head-copy small{
  display:block;
  margin-bottom:4px;
  color:#d65420;
  font-size:10px;
  font-weight:900
}
.${CLASS} .barah-v33-head-copy h2{
  margin:0;
  color:#211914;
  font-size:24px;
  line-height:1.35;
  font-weight:950
}
.${CLASS} .barah-v33-head-copy p{
  margin:5px 0 0;
  color:#796960;
  font-size:12px
}
.${CLASS} .barah-v33-all{
  flex:0 0 auto;
  text-decoration:none;
  padding:9px 12px;
  border-radius:10px;
  border:1px solid #eadfd7;
  background:#fff;
  color:#332923;
  font-size:11px;
  font-weight:900
}

/* strip old visual chrome from Step title area */
.${CLASS} > h1,
.${CLASS} > h2,
.${CLASS} > h3,
.${CLASS} > h4,
.${CLASS} > .section-title,
.${CLASS} > .s-block__title{
  display:none!important
}

/* product container */
.${CLASS} .barah-v33-track{
  display:grid!important;
  grid-template-columns:repeat(4,minmax(0,1fr))!important;
  gap:14px!important;
  align-items:stretch!important
}

/* outer cards only */
.${CLASS} .${CARD}{
  min-width:0!important;
  display:flex!important;
  flex-direction:column!important;
  height:100%!important;
  overflow:hidden!important;
  padding:0!important;
  border:1px solid #eee5df!important;
  border-radius:18px!important;
  background:#fff!important;
  box-shadow:0 8px 22px rgba(31,24,19,.04)!important
}
.${CLASS} .${CARD} img{
  display:block!important;
  width:100%!important;
  height:220px!important;
  object-fit:contain!important;
  padding:12px!important;
  background:#fff!important
}

/* title */
.${CLASS} .${CARD} h3,
.${CLASS} .${CARD} h4,
.${CLASS} .${CARD} [class*="title"]{
  display:-webkit-box!important;
  -webkit-box-orient:vertical!important;
  -webkit-line-clamp:2!important;
  overflow:hidden!important;
  min-height:44px!important;
  max-height:44px!important;
  margin:8px 12px!important;
  color:#241c17!important;
  font-size:13px!important;
  line-height:1.65!important;
  font-weight:850!important
}

/* price emphasis */
.${CLASS} .${CARD} [class*="price"]{
  color:#d94c21!important;
  font-size:15px!important;
  font-weight:900!important
}

/* purchase CTA - convert the dominant action from black to BARAH identity */
.${CLASS} .${CARD} button,
.${CLASS} .${CARD} a[class*="add"],
.${CLASS} .${CARD} [class*="add-to-cart"]{
  min-height:42px!important;
  border-radius:10px!important
}
.${CLASS} .${CARD} button[class*="btn"],
.${CLASS} .${CARD} [class*="add-to-cart"]{
  background:linear-gradient(135deg,#ff7a18,#ef4444)!important;
  color:#fff!important;
  border-color:transparent!important
}

.${CLASS} .barah-v33-hidden{
  display:none!important
}

/* desktop: no giant vertical shelf */
@media(min-width:1101px){
  .${CLASS} .barah-v33-track{
    grid-template-columns:repeat(4,minmax(0,1fr))!important
  }
}

/* tablet */
@media(max-width:1100px){
  .${CLASS} .barah-v33-track{
    grid-template-columns:repeat(2,minmax(0,1fr))!important
  }
}

/* mobile: horizontal browse, 1.35 cards visible */
@media(max-width:767px){
  .${CLASS}{
    width:calc(100% - 24px)!important;
    margin:16px 12px 20px!important;
    padding:14px 12px!important;
    border-radius:18px!important
  }
  .${CLASS} .barah-v33-head{
    align-items:flex-start
  }
  .${CLASS} .barah-v33-head-copy h2{
    font-size:20px!important
  }
  .${CLASS} .barah-v33-track{
    display:flex!important;
    gap:10px!important;
    overflow-x:auto!important;
    scroll-snap-type:x mandatory!important;
    scrollbar-width:none!important;
    padding-bottom:4px!important
  }
  .${CLASS} .barah-v33-track::-webkit-scrollbar{display:none!important}
  .${CLASS} .${CARD}{
    flex:0 0 72%!important;
    max-width:260px!important;
    scroll-snap-align:start!important
  }
  .${CLASS} .${CARD} img{
    height:190px!important
  }
}
`;
  document.head.appendChild(s);
}

function allCards(section){
  var raw=Array.prototype.slice.call(
    section.querySelectorAll(
      'custom-salla-product-card,product-card,[class*="product-card"],[class*="product-block"]'
    )
  );

  return raw.filter(function(card){
    return !raw.some(function(other){
      return other!==card && other.contains(card);
    });
  });
}

function findLatest(){
  var candidates=Array.prototype.slice.call(
    document.querySelectorAll(
      'section,.home-block,[class*="products"],[class*="product-slider"],[class*="latest"]'
    )
  );

  var best=null;
  var bestScore=-1;

  candidates.forEach(function(el){
    if(el.closest('#barah-step-home-v9,#barah-step-most-viewed,#barah-step-discovery-v15'))return;

    var text=(el.textContent||'').replace(/\s+/g,' ').trim();
    var cards=allCards(el);
    var score=0;

    if(text.indexOf('أحدث المنتجات')!==-1)score+=200;
    if(text.indexOf('وصل حديث')!==-1)score+=180;
    if(text.indexOf('Latest Products')!==-1)score+=180;
    if(cards.length>=4)score+=cards.length*3;

    if(score>bestScore){
      bestScore=score;
      best={el:el,cards:cards};
    }
  });

  return bestScore>=180 ? best : null;
}

function enhance(){
  addStyle();

  var found=findLatest();
  if(!found||!found.el||found.cards.length<4)return false;

  var section=found.el;
  section.classList.add(CLASS);

  if(!section.querySelector('.barah-v33-head')){
    var head=document.createElement('div');
    head.className='barah-v33-head';
    head.innerHTML=
      '<div class="barah-v33-head-copy">'+
        '<small>جديد بارعة</small>'+
        '<h2>وصل حديثًا ✨</h2>'+
        '<p>منتجات جديدة تستحق النظرة الأولى.</p>'+
      '</div>'+
      '<a class="barah-v33-all" href="https://barahstore.com/ar/home-kitchen/c127906256">عرض كل المنتجات ←</a>';

    section.insertBefore(head,section.firstChild);
  }

  var cards=allCards(section);

  cards.forEach(function(card,index){
    card.classList.add(CARD);
    card.classList.toggle('barah-v33-hidden',index>=8);
  });

  /* Detect the smallest parent that contains all outer cards and make it the track */
  var parentCounts=new Map();

  cards.forEach(function(card){
    var p=card.parentElement;
    var depth=0;
    while(p && p!==section && depth<4){
      parentCounts.set(p,(parentCounts.get(p)||0)+1);
      p=p.parentElement;
      depth++;
    }
  });

  var track=null,max=0;
  parentCounts.forEach(function(count,node){
    if(count>max){
      max=count;
      track=node;
    }
  });

  if(track && max>=4){
    track.classList.add('barah-v33-track');
  }

  document.documentElement.setAttribute('data-barah-v33-latest','ready');
  return true;
}

var done=enhance();

if(!done){
  var obs=new MutationObserver(function(){
    if(enhance())obs.disconnect();
  });
  obs.observe(document.documentElement,{childList:true,subtree:true});
  setTimeout(function(){obs.disconnect()},1800);
}
})();

/* ============================================================
   BARAH — STEP V34 PREMIUM VISUAL SYSTEM
   ارتقاء بصري شامل بدون إضافة أقسام جديدة:
   - توحيد الهوية البصرية
   - رفع جودة البطاقات والمسافات
   - تحسين Hero والشحن والتصنيفات
   - جعل أحدث المنتجات ومختارات بارعة بمستوى واحد
   - تحسين الجوال والوضوح والهرمية
   ============================================================ */
(function(){
'use strict';

if(window.__BARAH_STEP_V34_PREMIUM__)return;
window.__BARAH_STEP_V34_PREMIUM__=true;

var STYLE='barah-step-v34-premium-style';

function isHome(){
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  if(/^\/(ar|en)?$/.test(p))return true;
  if(location.hostname==='salla.sa'&&/^\/br1$/.test(p))return true;
  return false;
}
if(!isHome())return;

function addStyle(){
  if(document.getElementById(STYLE))return;

  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
:root{
  --barah-v34-orange:#ff7a18;
  --barah-v34-red:#ef4444;
  --barah-v34-ink:#1f1713;
  --barah-v34-muted:#74655d;
  --barah-v34-line:#eadfd7;
  --barah-v34-soft:#fff8f3;
  --barah-v34-surface:#ffffff;
  --barah-v34-radius:20px;
  --barah-v34-shadow:0 14px 34px rgba(34,24,18,.055);
}

/* ---------- Global homepage rhythm ---------- */
#barah-step-hero-v12,
#barah-step-shipping-v24,
#barah-step-discovery-v15,
.barah-v33-latest,
#barah-step-home-v9,
#barah-step-catalog-v32,
#barah-step-most-viewed,
#barah-step-wholesale-v32{
  width:min(1240px,calc(100% - 32px))!important;
  max-width:1240px!important;
  margin-left:auto!important;
  margin-right:auto!important;
}

#barah-step-hero-v12{margin-top:22px!important;margin-bottom:14px!important}
#barah-step-shipping-v24{margin-top:0!important;margin-bottom:18px!important}
#barah-step-discovery-v15{margin-top:18px!important;margin-bottom:22px!important}
.barah-v33-latest{margin-top:20px!important;margin-bottom:24px!important}
#barah-step-home-v9{margin-top:22px!important;margin-bottom:18px!important}
#barah-step-catalog-v32{margin-top:12px!important;margin-bottom:18px!important}
#barah-step-most-viewed{margin-top:16px!important;margin-bottom:20px!important}
#barah-step-wholesale-v32{margin-top:20px!important;margin-bottom:28px!important}

/* ---------- HERO ---------- */
#barah-step-hero-v12 .barah-hero-shell{
  grid-template-columns:1.08fr .92fr!important;
  gap:24px!important;
  padding:30px!important;
  border:1px solid var(--barah-v34-line)!important;
  border-radius:28px!important;
  background:
    radial-gradient(circle at 8% 10%,rgba(255,122,24,.13),transparent 30%),
    radial-gradient(circle at 92% 8%,rgba(239,68,68,.08),transparent 28%),
    linear-gradient(135deg,#fffaf6 0%,#fff 58%,#fff8f6 100%)!important;
  box-shadow:var(--barah-v34-shadow)!important;
}

#barah-step-hero-v12 h1{
  font-size:40px!important;
  letter-spacing:-.35px!important;
  max-width:650px!important;
}
#barah-step-hero-v12 .barah-hero-copy p{
  max-width:610px!important;
  color:var(--barah-v34-muted)!important;
  font-size:15px!important;
}
#barah-step-hero-v12 .barah-hero-primary{
  min-height:44px!important;
  display:inline-flex!important;
  align-items:center!important;
  justify-content:center!important;
  padding:0 18px!important;
  border-radius:12px!important;
}
#barah-step-hero-v12 .barah-hero-secondary{
  min-height:44px!important;
  display:inline-flex!important;
  align-items:center!important;
  justify-content:center!important;
  padding:0 16px!important;
  border-radius:12px!important;
}
#barah-step-hero-v12 .barah-hero-product{
  border-radius:20px!important;
  border-color:#eee2d9!important;
  box-shadow:0 10px 24px rgba(34,24,18,.05)!important;
}
#barah-step-hero-v12 .barah-hero-product img{
  padding:14px!important;
}
#barah-step-hero-v12 .barah-hero-product strong{
  font-size:13px!important;
  line-height:1.65!important;
}

/* ---------- Shipping hook ---------- */
#barah-step-shipping-v24 .barah-v24-shell{
  padding:16px 18px!important;
  border-radius:18px!important;
  border-color:#f0d7c5!important;
  background:linear-gradient(135deg,#fff7f0,#fff)!important;
  box-shadow:0 8px 22px rgba(35,24,18,.035)!important;
}
#barah-step-shipping-v24 .barah-v24-copy strong{
  font-size:15px!important;
}
#barah-step-shipping-v24 .barah-v24-point{
  min-height:46px!important;
  border-radius:12px!important;
  background:#fff!important;
}

/* ---------- Discovery ---------- */
#barah-step-discovery-v15 .barah-v15-head{
  margin-bottom:16px!important;
}
#barah-step-discovery-v15 h2{
  font-size:27px!important;
}
#barah-step-discovery-v15 .barah-v15-worlds{
  grid-template-columns:repeat(4,minmax(0,1fr))!important;
  gap:12px!important;
}
#barah-step-discovery-v15 .barah-v15-world{
  min-height:124px!important;
  padding:17px!important;
  border-radius:18px!important;
  border-color:#eee3da!important;
  background:linear-gradient(180deg,#fff,#fffdfa)!important;
  box-shadow:0 9px 22px rgba(34,24,18,.035)!important;
}
#barah-step-discovery-v15 .barah-v15-icon{
  width:44px!important;
  height:44px!important;
  flex-basis:44px!important;
  border-radius:14px!important;
  background:linear-gradient(135deg,#fff1e6,#ffe7dc)!important;
}
#barah-step-discovery-v15 .barah-v15-world strong{
  font-size:14px!important;
}
#barah-step-discovery-v15 .barah-v15-world small{
  font-size:11px!important;
  color:#7b6b62!important;
}

/* ---------- Latest products ---------- */
.barah-v33-latest{
  padding:22px!important;
  border-radius:24px!important;
  border-color:#eee1d8!important;
  box-shadow:var(--barah-v34-shadow)!important;
  background:
    radial-gradient(circle at 92% 8%,rgba(255,122,24,.07),transparent 24%),
    #fff!important;
}
.barah-v33-latest .barah-v33-head{
  margin-bottom:18px!important;
}
.barah-v33-latest .barah-v33-head-copy h2{
  font-size:25px!important;
}
.barah-v33-latest .barah-v33-track{
  gap:16px!important;
}
.barah-v33-latest .barah-v33-latest-card{
  border-radius:19px!important;
  border-color:#eee3db!important;
  box-shadow:0 10px 24px rgba(35,24,18,.045)!important;
  transition:transform .18s ease,box-shadow .18s ease!important;
}
.barah-v33-latest .barah-v33-latest-card:hover{
  transform:translateY(-3px)!important;
  box-shadow:0 16px 28px rgba(35,24,18,.07)!important;
}
.barah-v33-latest .barah-v33-latest-card img{
  height:232px!important;
  padding:14px!important;
}
.barah-v33-latest .barah-v33-all{
  min-height:40px!important;
  display:inline-flex!important;
  align-items:center!important;
  justify-content:center!important;
}

/* ---------- BARAH Picks ---------- */
#barah-step-home-v9 .barah-v9-shell{
  padding:28px!important;
  border-radius:26px!important;
  border-color:#eee0d6!important;
  background:
    radial-gradient(circle at 8% 10%,rgba(255,122,24,.09),transparent 26%),
    linear-gradient(135deg,#fffaf6,#fff)!important;
  box-shadow:0 18px 38px rgba(34,24,18,.055)!important;
}
#barah-step-home-v9 h2{
  font-size:28px!important;
}
#barah-step-home-v9 .barah-v9-grid{
  gap:18px!important;
}
#barah-step-home-v9 .barah-v9-card{
  border-radius:20px!important;
  border-color:#eee2da!important;
  box-shadow:0 12px 26px rgba(31,24,19,.045)!important;
  transition:transform .18s ease,box-shadow .18s ease!important;
}
#barah-step-home-v9 .barah-v9-card:hover{
  transform:translateY(-3px)!important;
  box-shadow:0 17px 32px rgba(31,24,19,.07)!important;
}
#barah-step-home-v9 .barah-v9-media{
  min-height:230px!important;
}
#barah-step-home-v9 .barah-v9-media img{
  padding:14px!important;
}
#barah-step-home-v9 .barah-v9-body{
  padding:15px!important;
}
#barah-step-home-v9 .barah-v9-buy{
  min-height:43px!important;
  display:flex!important;
  align-items:center!important;
  justify-content:center!important;
  border-radius:11px!important;
}

/* ---------- Catalog gateway ---------- */
#barah-step-catalog-v32 .v32box{
  border-radius:18px!important;
  border-color:#eadfd7!important;
  background:linear-gradient(135deg,#fffdfb,#fff8f3)!important;
  box-shadow:0 8px 20px rgba(35,24,18,.03)!important;
}

/* ---------- Most viewed ---------- */
#barah-step-most-viewed{
  padding:18px!important;
  border-radius:20px!important;
  border-color:#eee4dc!important;
  background:#fff!important;
}
#barah-step-most-viewed .barah-step-most-viewed__track{
  gap:14px!important;
}
#barah-step-most-viewed .barah-step-most-viewed__card{
  grid-template-columns:104px minmax(0,1fr)!important;
  gap:10px 12px!important;
  padding:12px!important;
  border-radius:16px!important;
  border-color:#eee5df!important;
  box-shadow:0 9px 20px rgba(31,24,19,.035)!important;
}
#barah-step-most-viewed .barah-step-most-viewed__product img{
  width:104px!important;
  height:104px!important;
  border-radius:12px!important;
}

/* ---------- Wholesale ---------- */
#barah-step-wholesale-v32 .v32box{
  border-radius:20px!important;
  padding:20px 22px!important;
  border-color:#eadfd7!important;
  background:
    radial-gradient(circle at 10% 20%,rgba(255,122,24,.08),transparent 28%),
    linear-gradient(135deg,#fffaf6,#fff)!important;
  box-shadow:0 10px 24px rgba(35,24,18,.035)!important;
}

/* ---------- Smooth but restrained interactions ---------- */
@media(hover:hover){
  #barah-step-discovery-v15 .barah-v15-world:hover{
    transform:translateY(-2px)!important;
    box-shadow:0 14px 26px rgba(35,24,18,.06)!important;
  }
}

/* ---------- Tablet ---------- */
@media(max-width:1100px){
  #barah-step-discovery-v15 .barah-v15-worlds{
    grid-template-columns:repeat(2,minmax(0,1fr))!important
  }
  .barah-v33-latest .barah-v33-track{
    grid-template-columns:repeat(2,minmax(0,1fr))!important
  }
}

/* ---------- Mobile ---------- */
@media(max-width:767px){
  #barah-step-hero-v12,
  #barah-step-shipping-v24,
  #barah-step-discovery-v15,
  .barah-v33-latest,
  #barah-step-home-v9,
  #barah-step-catalog-v32,
  #barah-step-most-viewed,
  #barah-step-wholesale-v32{
    width:calc(100% - 24px)!important;
    margin-left:12px!important;
    margin-right:12px!important;
  }

  #barah-step-hero-v12 .barah-hero-shell{
    padding:17px!important;
    border-radius:20px!important;
  }
  #barah-step-hero-v12 h1{
    font-size:28px!important;
  }
  #barah-step-hero-v12 .barah-hero-products{
    gap:10px!important;
  }

  #barah-step-shipping-v24 .barah-v24-shell{
    padding:13px!important;
  }

  #barah-step-discovery-v15 h2{
    font-size:21px!important;
  }
  #barah-step-discovery-v15 .barah-v15-worlds{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:9px!important;
  }
  #barah-step-discovery-v15 .barah-v15-world{
    min-height:108px!important;
    padding:12px!important;
  }

  .barah-v33-latest{
    padding:14px 12px!important;
    border-radius:18px!important;
  }
  .barah-v33-latest .barah-v33-latest-card{
    flex-basis:76%!important;
  }
  .barah-v33-latest .barah-v33-latest-card img{
    height:196px!important;
  }

  #barah-step-home-v9 .barah-v9-shell{
    padding:16px!important;
    border-radius:18px!important;
  }
  #barah-step-home-v9 h2{
    font-size:22px!important;
  }
  #barah-step-home-v9 .barah-v9-grid{
    gap:10px!important;
  }
  #barah-step-home-v9 .barah-v9-media{
    min-height:168px!important;
  }

  #barah-step-most-viewed{
    padding:14px 12px!important;
  }
  #barah-step-most-viewed .barah-step-most-viewed__card{
    grid-template-columns:88px minmax(0,1fr)!important;
  }
  #barah-step-most-viewed .barah-step-most-viewed__product img{
    width:88px!important;
    height:88px!important;
  }
}

/* reduced motion */
@media(prefers-reduced-motion:reduce){
  #barah-step-hero-v12 *,
  #barah-step-discovery-v15 *,
  .barah-v33-latest *,
  #barah-step-home-v9 *,
  #barah-step-most-viewed *{
    transition:none!important;
    animation:none!important
  }
}
`;
  document.head.appendChild(s);
}

addStyle();
})();


/* ============================================================
   BARAH — STEP V35 EXACT DOM + EDITOR SAFE
   مبني على DOM الفعلي لثيم خطوة:
   header#site-header-outer
   main
   section.home-block.home-block--fixed-products.show-all
   .grid-block.products-list-container.vertical-products
   custom-salla-product-card.product-block
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V35_EXACT__)return;
window.__BARAH_V35_EXACT__=true;

var STYLE='barah-v35-exact-style';

function homepage(){
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  if(/\/p\d+(?:\/|$)/.test(p))return false;
  if(/^\/(ar|en)?$/.test(p))return true;
  if(location.hostname==='salla.sa'&&/^\/br1$/.test(p))return true;
  /* Salla theme editor preview */
  return !!document.querySelector(
    'main section.home-block, main .home-block--fixed-products, section.home-block--fixed-products'
  );
}

function addStyle(){
  if(document.getElementById(STYLE))return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
/* ===== Latest products: exact Step selectors ===== */
section.home-block.home-block--fixed-products.show-all.barah-v35-latest{
  width:min(1240px,calc(100% - 32px))!important;
  max-width:1240px!important;
  margin:22px auto 26px!important;
  padding:22px!important;
  border:1px solid #eee1d8!important;
  border-radius:24px!important;
  background:
    radial-gradient(circle at 92% 8%,rgba(255,122,24,.07),transparent 25%),
    #fff!important;
  box-shadow:0 14px 32px rgba(35,24,18,.05)!important;
  box-sizing:border-box!important;
}
section.barah-v35-latest > .title.title--primary.title--x-large{
  display:none!important;
}
section.barah-v35-latest .barah-v35-latest-head{
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap:16px;
  margin-bottom:18px;
}
section.barah-v35-latest .barah-v35-copy small{
  display:block;
  margin-bottom:5px;
  color:#d65420;
  font-size:11px;
  font-weight:900;
}
section.barah-v35-latest .barah-v35-copy h2{
  margin:0;
  color:#201813;
  font-size:26px;
  line-height:1.35;
  font-weight:950;
}
section.barah-v35-latest .barah-v35-copy p{
  margin:6px 0 0;
  color:#78685f;
  font-size:12px;
}
section.barah-v35-latest .barah-v35-all{
  flex:0 0 auto;
  text-decoration:none;
  padding:10px 13px;
  border:1px solid #eadfd7;
  border-radius:11px;
  background:#fff;
  color:#302620;
  font-size:11px;
  font-weight:900;
}

/* Exact product grid */
section.barah-v35-latest .grid-block.products-list-container.vertical-products{
  display:grid!important;
  grid-template-columns:repeat(4,minmax(0,1fr))!important;
  gap:16px!important;
  align-items:stretch!important;
}

/* Only 8 newest items on homepage */
section.barah-v35-latest custom-salla-product-card.product-block:nth-child(n+9){
  display:none!important;
}

/* Card host */
section.barah-v35-latest custom-salla-product-card.product-block{
  width:100%!important;
  min-width:0!important;
  height:100%!important;
  margin:0!important;
  padding:0!important;
  border:1px solid #eee3db!important;
  border-radius:19px!important;
  overflow:hidden!important;
  background:#fff!important;
  box-shadow:0 10px 24px rgba(35,24,18,.045)!important;
}

/* Card internals where Step exposes them */
section.barah-v35-latest custom-salla-product-card.product-block img{
  object-fit:contain!important;
}
section.barah-v35-latest custom-salla-product-card.product-block .product-block__thumb,
section.barah-v35-latest custom-salla-product-card.product-block [class*="image"]{
  border-radius:16px 16px 0 0!important;
}
section.barah-v35-latest custom-salla-product-card.product-block .btn--add-to-cart,
section.barah-v35-latest custom-salla-product-card.product-block [class*="add-to-cart"],
section.barah-v35-latest custom-salla-product-card.product-block button{
  border-radius:10px!important;
}

/* ===== Custom BARAH sections: stable content width ===== */
#barah-step-hero-v12,
#barah-step-shipping-v24,
#barah-step-discovery-v15,
#barah-step-personal-v18,
#barah-step-home-v9,
#barah-step-catalog-v32,
#barah-step-most-viewed,
#barah-step-wholesale-v32{
  width:min(1240px,calc(100% - 32px))!important;
  max-width:1240px!important;
  margin-left:auto!important;
  margin-right:auto!important;
}

/* calmer visual hierarchy */
#barah-step-discovery-v15 .barah-v15-world{
  box-shadow:0 8px 20px rgba(34,24,18,.035)!important;
}
#barah-step-home-v9 .barah-v9-card{
  box-shadow:0 10px 24px rgba(31,24,19,.045)!important;
}
#barah-step-most-viewed{
  box-shadow:none!important;
}

/* ===== Mobile ===== */
@media(max-width:900px){
  section.barah-v35-latest .grid-block.products-list-container.vertical-products{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
  }
}
@media(max-width:767px){
  section.home-block.home-block--fixed-products.show-all.barah-v35-latest{
    width:calc(100% - 24px)!important;
    margin:16px 12px 20px!important;
    padding:14px 12px!important;
    border-radius:18px!important;
  }
  section.barah-v35-latest .barah-v35-latest-head{
    align-items:flex-start;
  }
  section.barah-v35-latest .barah-v35-copy h2{
    font-size:21px!important;
  }
  section.barah-v35-latest .grid-block.products-list-container.vertical-products{
    display:flex!important;
    gap:10px!important;
    overflow-x:auto!important;
    scroll-snap-type:x mandatory!important;
    scrollbar-width:none!important;
    padding-bottom:4px!important;
  }
  section.barah-v35-latest .grid-block.products-list-container.vertical-products::-webkit-scrollbar{
    display:none!important;
  }
  section.barah-v35-latest custom-salla-product-card.product-block{
    flex:0 0 74%!important;
    max-width:270px!important;
    scroll-snap-align:start!important;
  }

  #barah-step-hero-v12,
  #barah-step-shipping-v24,
  #barah-step-discovery-v15,
  #barah-step-personal-v18,
  #barah-step-home-v9,
  #barah-step-catalog-v32,
  #barah-step-most-viewed,
  #barah-step-wholesale-v32{
    width:calc(100% - 24px)!important;
    margin-left:12px!important;
    margin-right:12px!important;
  }
}
`;
  document.head.appendChild(s);
}

function latestSection(){
  var secs=Array.prototype.slice.call(
    document.querySelectorAll('section.home-block.home-block--fixed-products.show-all')
  );
  return secs.find(function(sec){
    var t=(sec.textContent||'').replace(/\s+/g,' ').trim();
    return (
      t.indexOf('اكتشفها أولاً')!==-1 ||
      t.indexOf('أحدث المنتجات')!==-1 ||
      t.indexOf('وصل حديث')!==-1
    );
  }) || secs[0] || null;
}

function enhanceLatest(sec){
  if(!sec)return false;
  sec.classList.add('barah-v35-latest');

  if(!sec.querySelector('.barah-v35-latest-head')){
    var head=document.createElement('div');
    head.className='barah-v35-latest-head';
    head.innerHTML=
      '<div class="barah-v35-copy">'+
        '<small>جديد بارعة</small>'+
        '<h2>وصل حديثًا ✨</h2>'+
        '<p>أحدث الإضافات التي تستحق نظرة سريعة.</p>'+
      '</div>'+
      '<a class="barah-v35-all" href="https://barahstore.com/ar/home-kitchen/c127906256">عرض كل المنتجات ←</a>';

    var grid=sec.querySelector('.grid-block.products-list-container.vertical-products');
    if(grid)sec.insertBefore(head,grid);
    else sec.insertBefore(head,sec.firstChild);
  }
  return true;
}

function moveBefore(anchor,ids){
  if(!anchor||!anchor.parentNode)return;
  var frag=document.createDocumentFragment();
  ids.forEach(function(id){
    var n=document.getElementById(id);
    if(n)frag.appendChild(n);
  });
  if(frag.childNodes.length)anchor.parentNode.insertBefore(frag,anchor);
}

function moveAfter(anchor,ids){
  if(!anchor)return;
  var cur=anchor;
  ids.forEach(function(id){
    var n=document.getElementById(id);
    if(!n)return;
    cur.insertAdjacentElement('afterend',n);
    cur=n;
  });
}

function arrange(){
  if(!homepage()){
    document.documentElement.setAttribute('data-barah-v35','ready');
    return true;
  }

  addStyle();

  var main=document.querySelector('main');
  var latest=latestSection();
  if(!main||!latest)return false;

  enhanceLatest(latest);

  /* Exact desired order inside MAIN, therefore always below header#site-header-outer */
  moveBefore(latest,[
    'barah-step-hero-v12',
    'barah-step-shipping-v24',
    'barah-step-discovery-v15',
    'barah-step-personal-v18'
  ]);

  moveAfter(latest,[
    'barah-step-home-v9',
    'barah-step-catalog-v32',
    'barah-step-most-viewed'
  ]);

  var wholesale=document.getElementById('barah-step-wholesale-v32');
  var footer=document.querySelector('footer');
  if(wholesale&&footer&&footer.parentNode){
    footer.insertAdjacentElement('beforebegin',wholesale);
  }

  document.documentElement.setAttribute('data-barah-v35','ready');
  return true;
}

if(!homepage()){
  document.documentElement.setAttribute('data-barah-v35','ready');
  return;
}

var done=arrange();
if(!done){
  var obs=new MutationObserver(function(){
    if(arrange())obs.disconnect();
  });
  obs.observe(document.documentElement,{childList:true,subtree:true});
  document.addEventListener('DOMContentLoaded',arrange,{once:true});
  setTimeout(arrange,200);
  setTimeout(arrange,500);
  setTimeout(function(){
    obs.disconnect();
    document.documentElement.setAttribute('data-barah-v35','ready');
  },1800);
}
})();

/* ============================================================
   BARAH STEP HOME PRO V36 — CATALOG EXPANSION GATEWAY
   الهدف: جعل الوصول للمنتجات أكثر تشويقًا وقابلية للتوسع حتى 2000+ صنف
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_STEP_GATEWAY_V36__) return;
window.__BARAH_STEP_GATEWAY_V36__ = true;

var ROOT='barah-step-gateway-v36';
var STYLE=ROOT+'-style';

var CARDS=[
  {
    title:'ابدأ من الأكثر طلبًا',
    note:'مدخل سريع للمنتجات الأعلى جذبًا وطلبًا.',
    cta:'تسوّق الأكثر شعبية',
    href:'https://barahstore.com/ar/home-kitchen/c127906256',
    tone:'is-warm',
    chips:[
      {t:'الأكثر مبيعًا',u:'https://barahstore.com/ar/home-kitchen/c127906256'},
      {t:'وصل حديثًا',u:'https://barahstore.com/ar/search?q=وصل%20حديثاً'},
      {t:'هدايا عملية',u:'https://barahstore.com/ar/search?q=هدايا'},
      {t:'منتجات ترند',u:'https://barahstore.com/ar/search?q=ترند'}
    ]
  },
  {
    title:'حلول البيت واليوميات',
    note:'تنظيم، مطبخ، إضاءات وأشياء صغيرة تغيّر يومك.',
    cta:'اكتشف احتياجات المنزل',
    href:'https://barahstore.com/ar/search?q=المنزل',
    tone:'is-soft',
    chips:[
      {t:'تنظيم المنزل',u:'https://barahstore.com/ar/search?q=تنظيم'},
      {t:'أدوات المطبخ',u:'https://barahstore.com/ar/search?q=المطبخ'},
      {t:'الإضاءات',u:'https://barahstore.com/ar/search?q=إضاءات'},
      {t:'اكسسوارات',u:'https://barahstore.com/ar/search?q=اكسسوارات'}
    ]
  },
  {
    title:'للسفر والحركة والرياضة',
    note:'كل ما يساعدك خارج المنزل أو أثناء النشاط اليومي.',
    cta:'تسوّق السفر والرياضة',
    href:'https://barahstore.com/ar/search?q=سفر',
    tone:'is-cool',
    chips:[
      {t:'السفر',u:'https://barahstore.com/ar/search?q=سفر'},
      {t:'الرحلات',u:'https://barahstore.com/ar/search?q=رحلات'},
      {t:'السيارة',u:'https://barahstore.com/ar/search?q=السيارة'},
      {t:'رياضية منزلية',u:'https://barahstore.com/ar/search?q=رياضة'}
    ]
  },
  {
    title:'العناية والمظهر الشخصي',
    note:'منتجات عملية للعناية، الراحة، والمظهر اليومي.',
    cta:'اكتشف العناية الشخصية',
    href:'https://barahstore.com/ar/search?q=العناية%20الشخصية',
    tone:'is-neutral',
    chips:[
      {t:'العناية الشخصية',u:'https://barahstore.com/ar/search?q=العناية%20الشخصية'},
      {t:'مشدات الجسم',u:'https://barahstore.com/ar/search?q=مشد'},
      {t:'الحيوانات الأليفة',u:'https://barahstore.com/ar/search?q=الحيوانات'},
      {t:'الطفل',u:'https://barahstore.com/ar/search?q=الطفل'}
    ]
  }
];

var QUICK=[
  {t:'الأكثر مبيعًا',u:'https://barahstore.com/ar/home-kitchen/c127906256'},
  {t:'وصل حديثًا',u:'https://barahstore.com/ar/search?q=وصل%20حديثاً'},
  {t:'مشدات وتخسيس',u:'https://barahstore.com/ar/search?q=مشد'},
  {t:'المنزل والمطبخ',u:'https://barahstore.com/ar/search?q=المطبخ'},
  {t:'السفر والرحلات',u:'https://barahstore.com/ar/search?q=سفر'},
  {t:'اكسسوارات',u:'https://barahstore.com/ar/search?q=اكسسوارات'},
  {t:'العناية الشخصية',u:'https://barahstore.com/ar/search?q=العناية%20الشخصية'},
  {t:'الإضاءات',u:'https://barahstore.com/ar/search?q=إضاءات'},
  {t:'السيارة',u:'https://barahstore.com/ar/search?q=السيارة'},
  {t:'الحفلات',u:'https://barahstore.com/ar/search?q=حفلات'},
  {t:'الطفل',u:'https://barahstore.com/ar/search?q=الطفل'},
  {t:'الحيوانات الأليفة',u:'https://barahstore.com/ar/search?q=الحيوانات'}
];

function isHome(){
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  if(/^\/(ar|en)?$/.test(p)) return true;
  if(location.hostname==='salla.sa' && /^\/br1$/.test(p)) return true;
  return !!document.querySelector('main');
}
if(!isHome()) return;

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
#${ROOT}{
  direction:rtl;
  width:min(1240px,calc(100% - 32px));
  max-width:1240px;
  margin:18px auto 22px;
  box-sizing:border-box;
}
#${ROOT} *{box-sizing:border-box}
#${ROOT} .barah-v36-shell{
  position:relative;
  padding:22px;
  border:1px solid #eee3da;
  border-radius:24px;
  background:
    radial-gradient(circle at 8% 10%,rgba(255,122,24,.08),transparent 24%),
    radial-gradient(circle at 92% 10%,rgba(239,68,68,.06),transparent 26%),
    #fffdfb;
  box-shadow:0 14px 34px rgba(36,25,19,.05);
  overflow:hidden;
}
#${ROOT} .barah-v36-shell:before{
  content:'';
  position:absolute;
  inset:auto -30px -50px auto;
  width:180px;
  height:180px;
  background:radial-gradient(circle,rgba(255,122,24,.12),transparent 68%);
  pointer-events:none;
}
#${ROOT} .barah-v36-head{
  display:flex;
  align-items:end;
  justify-content:space-between;
  gap:14px;
  margin-bottom:16px;
}
#${ROOT} .barah-v36-copy small{
  display:block;
  margin-bottom:6px;
  color:#d55721;
  font-size:11px;
  font-weight:900;
}
#${ROOT} .barah-v36-copy h2{
  margin:0;
  color:#1d1714;
  font-size:28px;
  line-height:1.35;
  font-weight:950;
}
#${ROOT} .barah-v36-copy p{
  margin:8px 0 0;
  color:#73655d;
  font-size:13px;
  line-height:1.85;
  max-width:760px;
}
#${ROOT} .barah-v36-badge{
  flex:0 0 auto;
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding:11px 14px;
  border-radius:14px;
  background:#fff4ec;
  border:1px solid #f5dccd;
  color:#7c2d12;
  font-size:12px;
  font-weight:900;
}
#${ROOT} .barah-v36-grid{
  display:grid;
  grid-template-columns:repeat(4,minmax(0,1fr));
  gap:14px;
  margin-bottom:16px;
}
#${ROOT} .barah-v36-card{
  position:relative;
  display:flex;
  flex-direction:column;
  min-height:220px;
  padding:18px;
  border-radius:20px;
  border:1px solid #eee1d8;
  background:#fff;
  box-shadow:0 8px 20px rgba(34,24,18,.04);
}
#${ROOT} .barah-v36-card.is-warm{background:linear-gradient(180deg,#fff8f3 0%,#ffffff 100%)}
#${ROOT} .barah-v36-card.is-soft{background:linear-gradient(180deg,#fffdf9 0%,#ffffff 100%)}
#${ROOT} .barah-v36-card.is-cool{background:linear-gradient(180deg,#fbfcff 0%,#ffffff 100%)}
#${ROOT} .barah-v36-card.is-neutral{background:linear-gradient(180deg,#fefcfb 0%,#ffffff 100%)}
#${ROOT} .barah-v36-card .icon{
  width:42px;height:42px;border-radius:14px;
  display:grid;place-items:center;
  margin-bottom:12px;
  background:#fff;
  border:1px solid #f1e3da;
  color:#e56726;
  font-size:18px;
  box-shadow:0 6px 14px rgba(239,68,68,.07);
}
#${ROOT} .barah-v36-card h3{
  margin:0 0 8px;
  color:#221915;
  font-size:18px;
  line-height:1.45;
  font-weight:900;
}
#${ROOT} .barah-v36-card p{
  margin:0 0 14px;
  min-height:44px;
  color:#75675f;
  font-size:12px;
  line-height:1.8;
}
#${ROOT} .barah-v36-chipset{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-top:auto;
}
#${ROOT} .barah-v36-chip,
#${ROOT} .barah-v36-quick a{
  text-decoration:none;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:6px;
  padding:8px 10px;
  border-radius:999px;
  border:1px solid #eaded5;
  background:#fff;
  color:#342923;
  font-size:11px;
  font-weight:800;
}
#${ROOT} .barah-v36-card .cta{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  margin-top:14px;
  text-decoration:none;
  padding:11px 13px;
  border-radius:12px;
  background:linear-gradient(135deg,#ff7a18 0%,#ef4444 100%);
  color:#fff;
  font-size:12px;
  font-weight:900;
  box-shadow:0 9px 18px rgba(239,68,68,.15);
}
#${ROOT} .barah-v36-quick{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  padding-top:14px;
  border-top:1px dashed #eadfd7;
}
#${ROOT} .barah-v36-foot{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
  margin-top:14px;
  padding:12px 14px;
  border-radius:16px;
  background:#fff7f1;
  border:1px solid #f2dfd1;
}
#${ROOT} .barah-v36-foot strong{
  color:#241b17;
  font-size:13px;
}
#${ROOT} .barah-v36-foot span{
  color:#7a6a61;
  font-size:12px;
}
#${ROOT} .barah-v36-foot a{
  flex:0 0 auto;
  text-decoration:none;
  padding:10px 13px;
  border-radius:12px;
  background:#fff;
  border:1px solid #eaded4;
  color:#2e2520;
  font-size:12px;
  font-weight:900;
}
#barah-step-discovery-v15{display:none!important}
@media(max-width:1100px){
  #${ROOT} .barah-v36-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
}
@media(max-width:767px){
  #${ROOT}{width:calc(100% - 24px);margin:14px 12px 18px}
  #${ROOT} .barah-v36-shell{padding:16px;border-radius:18px}
  #${ROOT} .barah-v36-head{display:block}
  #${ROOT} .barah-v36-copy h2{font-size:22px}
  #${ROOT} .barah-v36-badge{display:none}
  #${ROOT} .barah-v36-grid{grid-template-columns:1fr;gap:12px}
  #${ROOT} .barah-v36-card{min-height:0;padding:15px;border-radius:16px}
  #${ROOT} .barah-v36-card p{min-height:0}
  #${ROOT} .barah-v36-quick{overflow-x:auto;flex-wrap:nowrap;padding-bottom:4px;scrollbar-width:none}
  #${ROOT} .barah-v36-quick::-webkit-scrollbar{display:none}
  #${ROOT} .barah-v36-quick a{flex:0 0 auto}
  #${ROOT} .barah-v36-foot{display:block}
  #${ROOT} .barah-v36-foot a{display:inline-flex;margin-top:10px}
}
`;
  document.head.appendChild(s);
}

function iconFor(i){
  return ['⚡','⌂','➜','✦'][i%4];
}

function cardHTML(card,i){
  return '<article class="barah-v36-card '+card.tone+'">'+
    '<div class="icon">'+iconFor(i)+'</div>'+
    '<h3>'+card.title+'</h3>'+
    '<p>'+card.note+'</p>'+
    '<div class="barah-v36-chipset">'+card.chips.map(function(c){
      return '<a class="barah-v36-chip" href="'+c.u+'">'+c.t+'</a>';
    }).join('')+'</div>'+
    '<a class="cta" href="'+card.href+'">'+card.cta+' ←</a>'+
  '</article>';
}

function build(){
  var el=document.getElementById(ROOT);
  if(el) return el;
  el=document.createElement('section');
  el.id=ROOT;
  el.innerHTML=
    '<div class="barah-v36-shell">'+
      '<div class="barah-v36-head">'+
        '<div class="barah-v36-copy">'+
          '<small>وصول ذكي لأقسام أكبر</small>'+
          '<h2>إذا كبر الكتالوج… الوصول لازم يصير أسرع وأمتع ✨</h2>'+
          '<p>بدل ما نغرق الصفحة بعشرات الأصناف، هنا جمعنا لك أقصر الطرق للوصول حسب الاهتمام والاستخدام. هذا الأسلوب يخدم التوسع القادم إلى 2000+ منتج ويحافظ على وضوح المتجر وسهولة الاستكشاف.</p>'+
        '</div>'+
        '<div class="barah-v36-badge">الشحن يبدأ من 9 ريال • مجاني للطلبات فوق 149 ريال • شحن لكل المملكة</div>'+
      '</div>'+
      '<div class="barah-v36-grid">'+CARDS.map(cardHTML).join('')+'</div>'+
      '<div class="barah-v36-quick">'+QUICK.map(function(q){
        return '<a href="'+q.u+'">'+q.t+'</a>';
      }).join('')+'</div>'+
      '<div class="barah-v36-foot">'+
        '<div><strong>تسوّق بسهولة:</strong> <span>اكتشف الأقسام والمنتجات التي تناسب احتياجك.</span></div>'+
        '<a href="https://barahstore.com/ar/home-kitchen/c127906256">ادخل الكتالوج الكامل ←</a>'+
      '</div>'+
    '</div>';
  return el;
}

function mount(){
  addStyle();
  var latest=document.querySelector('section.home-block.home-block--fixed-products.show-all.barah-v35-latest') ||
             document.querySelector('section.home-block.home-block--fixed-products.show-all');
  var shipping=document.getElementById('barah-step-shipping-v24');
  var personal=document.getElementById('barah-step-personal-v18');
  var root=build();
  if(!root) return false;

  if(shipping && shipping.parentNode){
    if(root.previousElementSibling !== shipping){
      shipping.insertAdjacentElement('afterend', root);
    }
  }else if(personal && personal.parentNode){
    personal.parentNode.insertBefore(root, personal);
  }else if(latest && latest.parentNode){
    latest.parentNode.insertBefore(root, latest);
  }else{
    return false;
  }
  return true;
}

function run(){
  if(mount()) return true;
  return false;
}

if(!run()){
  var obs=new MutationObserver(function(){
    if(run()) obs.disconnect();
  });
  obs.observe(document.documentElement,{childList:true,subtree:true});
  document.addEventListener('DOMContentLoaded',run,{once:true});
  setTimeout(run,250);
  setTimeout(run,800);
  setTimeout(function(){obs.disconnect();},2500);
}
})();

/* ============================================================
   BARAH STEP HOME PRO V37 — NO BANNER + 10X VISUAL UPGRADE
   إزالة الشريط الإعلاني + تنظيف التسلسل + رفع الواجهة بصريًا
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_STEP_V37__) return;
window.__BARAH_STEP_V37__ = true;

var STYLE_ID='barah-step-home-v37-style';

function isHome(){
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  if(/^\/(ar|en)?$/.test(p)) return true;
  if(location.hostname==='salla.sa' && /^\/br1$/.test(p)) return true;
  return !!document.querySelector('main');
}
if(!isHome()) return;

function addStyle(){
  if(document.getElementById(STYLE_ID)) return;
  var s=document.createElement('style');
  s.id=STYLE_ID;
  s.textContent=`
/* 1) إزالة الشريط الإعلاني/التركيزي غير الضروري */
#barah-step-shipping-v24,
.s-announcement,
.store-announcement,
.announcement-bar,
.top-navbar,
.topbar,
.site-topbar,
.marquee-bar,
.marquee,
.ticker-bar,
.ticker-wrap{
  display:none!important;
}

/* 2) حاوية أهدأ وأرقى */
body{background:#fbfbfb!important}
main{
  padding-top:10px!important;
}
#barah-step-hero-v12,
#barah-step-gateway-v36,
#barah-step-personal-v18,
section.home-block.home-block--fixed-products.show-all.barah-v35-latest,
#barah-step-most-viewed,
#barah-step-catalog-v32,
#barah-step-wholesale-v32{
  width:min(1180px,calc(100% - 36px))!important;
  max-width:1180px!important;
  margin-left:auto!important;
  margin-right:auto!important;
}
#barah-step-hero-v12{margin-top:14px!important;margin-bottom:18px!important}
#barah-step-gateway-v36,
#barah-step-personal-v18,
section.home-block.home-block--fixed-products.show-all.barah-v35-latest,
#barah-step-most-viewed,
#barah-step-catalog-v32,
#barah-step-wholesale-v32{
  margin-top:0!important;
  margin-bottom:18px!important;
}

/* 3) الهيرو: أفخم وأكثر هدوء */
#barah-step-hero-v12 .barah-hero-shell{
  border-radius:26px!important;
  background:linear-gradient(180deg,#fffdfb 0%,#fff7f1 100%)!important;
  border:1px solid #f0e4dc!important;
  box-shadow:0 18px 40px rgba(40,24,18,.06)!important;
  padding:22px!important;
}
#barah-step-hero-v12 h1{
  font-size:34px!important;
  line-height:1.35!important;
  letter-spacing:0!important;
}
#barah-step-hero-v12 .barah-hero-copy p{
  color:#6f625b!important;
  font-size:14px!important;
}
#barah-step-hero-v12 .barah-hero-primary{
  box-shadow:0 12px 22px rgba(239,68,68,.16)!important;
}
#barah-step-hero-v12 .barah-hero-products{
  gap:12px!important;
}
#barah-step-hero-v12 .barah-hero-product{
  border-radius:18px!important;
  border:1px solid #efe1d7!important;
  box-shadow:0 8px 18px rgba(35,24,18,.05)!important;
}

/* 4) قسم الوصول الذكي (V36) بشكل أهدأ وأقوى */
#barah-step-gateway-v36 .barah-v36-shell{
  border-radius:26px!important;
  padding:24px!important;
  background:linear-gradient(180deg,#fffdfb 0%,#ffffff 100%)!important;
  border:1px solid #efe3da!important;
  box-shadow:0 16px 36px rgba(35,23,18,.05)!important;
}
#barah-step-gateway-v36 .barah-v36-copy h2{
  font-size:31px!important;
  line-height:1.35!important;
}
#barah-step-gateway-v36 .barah-v36-copy p{
  font-size:14px!important;
  max-width:820px!important;
}
#barah-step-gateway-v36 .barah-v36-grid{
  gap:16px!important;
}
#barah-step-gateway-v36 .barah-v36-card{
  min-height:230px!important;
  padding:20px!important;
  border-radius:22px!important;
  box-shadow:0 12px 24px rgba(35,24,19,.05)!important;
  transition:transform .18s ease, box-shadow .18s ease;
}
#barah-step-gateway-v36 .barah-v36-card:hover{
  transform:translateY(-3px);
  box-shadow:0 18px 32px rgba(35,24,19,.08)!important;
}
#barah-step-gateway-v36 .barah-v36-card h3{font-size:19px!important}
#barah-step-gateway-v36 .barah-v36-card p{font-size:12.5px!important}
#barah-step-gateway-v36 .barah-v36-foot{
  border-radius:18px!important;
}

/* 5) إخفاء أي شبكة منتجات خام تسبب تشتيت قبل الأقسام الذكية */
section.home-block.barah-v37-noisy-grid{
  display:none!important;
}

/* 6) تحسين رفوف المنتجات الظاهرة */
section.home-block.home-block--fixed-products.show-all.barah-v35-latest,
#barah-step-most-viewed{
  padding:18px!important;
  border-radius:24px!important;
  background:linear-gradient(180deg,#fffdfc 0%,#fffaf7 100%)!important;
  border:1px solid #efe2d8!important;
  box-shadow:0 16px 34px rgba(36,25,19,.05)!important;
}
section.barah-v35-latest .barah-v35-copy h2,
#barah-step-most-viewed .title,
#barah-step-most-viewed h2{
  font-size:24px!important;
  line-height:1.4!important;
}
section.barah-v35-latest custom-salla-product-card.product-block,
#barah-step-most-viewed custom-salla-product-card.product-block,
#barah-step-personal-v18 custom-salla-product-card.product-block,
main section.home-block custom-salla-product-card.product-block{
  border-radius:18px!important;
  border:1px solid #efe2d8!important;
  background:#fff!important;
  box-shadow:0 10px 22px rgba(35,25,19,.04)!important;
  overflow:hidden!important;
  transition:transform .18s ease, box-shadow .18s ease;
}
section.barah-v35-latest custom-salla-product-card.product-block:hover,
#barah-step-most-viewed custom-salla-product-card.product-block:hover,
#barah-step-personal-v18 custom-salla-product-card.product-block:hover,
main section.home-block custom-salla-product-card.product-block:hover{
  transform:translateY(-3px);
  box-shadow:0 18px 30px rgba(35,25,19,.08)!important;
}
section.barah-v35-latest custom-salla-product-card.product-block .btn--add-to-cart,
section.barah-v35-latest custom-salla-product-card.product-block [class*="add-to-cart"],
section.barah-v35-latest custom-salla-product-card.product-block button,
#barah-step-most-viewed custom-salla-product-card.product-block .btn--add-to-cart,
#barah-step-most-viewed custom-salla-product-card.product-block [class*="add-to-cart"],
#barah-step-most-viewed custom-salla-product-card.product-block button,
main section.home-block custom-salla-product-card.product-block .btn--add-to-cart,
main section.home-block custom-salla-product-card.product-block [class*="add-to-cart"],
main section.home-block custom-salla-product-card.product-block button{
  border-radius:11px!important;
  min-height:40px!important;
  font-weight:900!important;
  background:linear-gradient(135deg,#ff7a18 0%,#ef4444 100%)!important;
  color:#fff!important;
  border:none!important;
  box-shadow:none!important;
}

/* 7) تحسين أقسام التصفية / الاهتمام */
#barah-step-personal-v18,
#barah-step-catalog-v32,
#barah-step-wholesale-v32{
  padding:16px!important;
  border-radius:22px!important;
  background:#fffdfa!important;
  border:1px solid #efe2d9!important;
  box-shadow:0 14px 30px rgba(36,24,18,.04)!important;
}
#barah-step-personal-v18 .barah-v18-card,
#barah-step-catalog-v32 .barah-v32-card,
#barah-step-wholesale-v32 .barah-v32-card{
  border-radius:18px!important;
  box-shadow:none!important;
}

/* 8) تحسين الفوتر السفلي */
footer,.store-footer,.footer{
  margin-top:10px!important;
}

/* 9) موبايل */
@media(max-width:767px){
  #barah-step-hero-v12,
  #barah-step-gateway-v36,
  #barah-step-personal-v18,
  section.home-block.home-block--fixed-products.show-all.barah-v35-latest,
  #barah-step-most-viewed,
  #barah-step-catalog-v32,
  #barah-step-wholesale-v32{
    width:calc(100% - 20px)!important;
  }
  #barah-step-hero-v12 .barah-hero-shell,
  #barah-step-gateway-v36 .barah-v36-shell,
  section.home-block.home-block--fixed-products.show-all.barah-v35-latest,
  #barah-step-most-viewed,
  #barah-step-personal-v18,
  #barah-step-catalog-v32,
  #barah-step-wholesale-v32{
    border-radius:18px!important;
    padding:14px!important;
  }
  #barah-step-hero-v12 h1{font-size:24px!important}
  #barah-step-gateway-v36 .barah-v36-copy h2{font-size:22px!important}
}
`;
  document.head.appendChild(s);
}

function reorder(){
  var hero=document.getElementById('barah-step-hero-v12');
  var gateway=document.getElementById('barah-step-gateway-v36');
  var personal=document.getElementById('barah-step-personal-v18');
  var latest=document.querySelector('section.home-block.home-block--fixed-products.show-all.barah-v35-latest');
  var most=document.getElementById('barah-step-most-viewed');

  if(hero && gateway && hero.nextElementSibling !== gateway){
    hero.insertAdjacentElement('afterend', gateway);
  }
  if(gateway && personal && gateway.nextElementSibling !== personal){
    gateway.insertAdjacentElement('afterend', personal);
  }
  if(personal && latest && personal.nextElementSibling !== latest){
    personal.insertAdjacentElement('afterend', latest);
  }
  if(latest && most && latest.nextElementSibling !== most){
    latest.insertAdjacentElement('afterend', most);
  }
}

function hideNoisyRawGrids(){
  var keepIds={
    'barah-step-most-viewed':1,
    'barah-step-personal-v18':1,
    'barah-step-catalog-v32':1,
    'barah-step-wholesale-v32':1,
    'barah-step-gateway-v36':1,
    'barah-step-hero-v12':1
  };

  document.querySelectorAll('main section.home-block').forEach(function(sec){
    if(!sec || keepIds[sec.id]) return;
    if(sec.classList.contains('barah-v35-latest')) return;
    if(sec.closest('#barah-step-most-viewed') || sec.closest('#barah-step-personal-v18')) return;
    var count=sec.querySelectorAll('custom-salla-product-card.product-block').length;
    if(count >= 8){
      sec.classList.add('barah-v37-noisy-grid');
    }
  });
}

function run(){
  addStyle();
  reorder();
  hideNoisyRawGrids();
}

run();
var mo=new MutationObserver(function(){ run(); });
mo.observe(document.documentElement,{childList:true,subtree:true});
setTimeout(function(){ mo.disconnect(); }, 3500);
document.addEventListener('DOMContentLoaded', run, {once:true});
setTimeout(run,250);
setTimeout(run,800);
})();

/* ============================================================
   BARAH STEP HOME PRO V38 — DEDUPE + DIVERSITY ENGINE
   حل تكرار الأصناف + إبراز التنوع + رف ذكي اكتشافي
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_STEP_V38__) return;
window.__BARAH_STEP_V38__=true;

var ROOT='barah-step-smart-showcase-v38';
var STYLE=ROOT+'-style';
var KEYWORDS={
  body:['مشد','خصر','بطن','قوام','حراري','رياضي','رياضي','تنحيف','تخسيس','ظهر'],
  home:['مطبخ','منزل','تنظيم','عسل','شراب','موزع','دولاب','معلق','ستاند','إضاءة','اضاءة'],
  travel:['سفر','رحلات','رحلة','سيارة','شنطة','مخيم','خارج'],
  tech:['جوال','هاتف','تابلت','ipad','ايباد','شاحن','حامل','led','usb','موبايل','كمبيوتر'],
  beauty:['عناية','بشرة','شعر','مكياج','تجميل','مرآة','مرآه','أظافر','اظافر','قدم','وجه'],
  baby:['طفل','أطفال','اطفال','رضيع','حامل','pregnancy'],
  pet:['حيوان','حيوانات','قطط','كلاب','أليف','اليف'],
  fun:['حفلات','لعبة','لعب','كرة','هدايا','ترند','اكسسوار','اكسسوارات']
};
var LABELS={
  body:'العناية والمشدات',
  home:'المنزل واليوميات',
  travel:'السفر والحركة',
  tech:'الجوال والتقنية',
  beauty:'العناية والجمال',
  baby:'الطفل والأم',
  pet:'الحيوانات الأليفة',
  fun:'مقتنيات وأفكار مميزة',
  other:'اختيارات متنوعة'
};

function $(s,r){return (r||document).querySelector(s)}
function $$(s,r){return Array.prototype.slice.call((r||document).querySelectorAll(s))}
function txt(el){return ((el&&el.textContent)||'').replace(/\s+/g,' ').trim()}

function isHome(){
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  return /^\/(ar|en)?$/.test(p) || !!$('main');
}
if(!isHome()) return;

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
#${ROOT}{
  width:min(1180px,calc(100% - 36px))!important;
  max-width:1180px!important;
  margin:18px auto!important;
  direction:rtl;
}
#${ROOT} *{box-sizing:border-box}
#${ROOT} .barah-v38-shell{
  border-radius:28px;
  padding:22px;
  background:linear-gradient(180deg,#fffdfb 0%,#fff8f3 100%);
  border:1px solid #efe2d8;
  box-shadow:0 18px 38px rgba(35,24,19,.06);
}
#${ROOT} .barah-v38-head{
  display:flex;align-items:end;justify-content:space-between;gap:14px;flex-wrap:wrap;margin-bottom:16px;
}
#${ROOT} .barah-v38-copy small{
  display:block;margin-bottom:6px;font-size:11px;font-weight:900;color:#de5f22;
}
#${ROOT} .barah-v38-copy h2{
  margin:0;font-size:28px;line-height:1.35;color:#201815;font-weight:950;
}
#${ROOT} .barah-v38-copy p{
  margin:8px 0 0;font-size:13px;line-height:1.9;color:#74665e;max-width:760px;
}
#${ROOT} .barah-v38-badge{
  display:inline-flex;align-items:center;gap:8px;padding:12px 14px;border-radius:16px;
  background:#fff;border:1px solid #efdccf;color:#7b341e;font-size:12px;font-weight:900;
}
#${ROOT} .barah-v38-chips{display:flex;flex-wrap:wrap;gap:8px;margin:14px 0 18px}
#${ROOT} .barah-v38-chip{
  display:inline-flex;align-items:center;justify-content:center;text-decoration:none;
  padding:8px 12px;border-radius:999px;background:#fff;border:1px solid #ebddd4;color:#342a25;
  font-size:11px;font-weight:800;
}
#${ROOT} .barah-v38-grid{
  display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:14px;
}
#${ROOT} .barah-v38-card{
  background:#fff;border:1px solid #ecdfd6;border-radius:20px;padding:12px;
  box-shadow:0 10px 20px rgba(35,24,18,.04);display:flex;flex-direction:column;min-height:100%;
  transition:transform .18s ease, box-shadow .18s ease;
}
#${ROOT} .barah-v38-card:hover{transform:translateY(-3px);box-shadow:0 16px 28px rgba(35,24,18,.08)}
#${ROOT} .barah-v38-thumb{
  aspect-ratio:1/1;border-radius:16px;background:#fff;display:block;overflow:hidden;border:1px solid #f1e5dd;margin-bottom:10px;
}
#${ROOT} .barah-v38-thumb img{width:100%;height:100%;object-fit:contain;display:block}
#${ROOT} .barah-v38-cat{display:inline-flex;align-self:flex-start;padding:5px 8px;border-radius:999px;background:#fff7f1;color:#c75522;font-size:10px;font-weight:900;margin-bottom:8px;border:1px solid #f4dfd3}
#${ROOT} .barah-v38-title{margin:0 0 8px;font-size:13px;line-height:1.7;font-weight:800;color:#201815;min-height:44px}
#${ROOT} .barah-v38-meta{margin-top:auto;display:flex;align-items:center;justify-content:space-between;gap:8px}
#${ROOT} .barah-v38-price{font-size:12px;font-weight:900;color:#d55e22;white-space:nowrap}
#${ROOT} .barah-v38-cta{display:inline-flex;align-items:center;justify-content:center;text-decoration:none;padding:10px 12px;border-radius:11px;background:linear-gradient(135deg,#ff7a18 0%,#ef4444 100%);color:#fff;font-size:12px;font-weight:900}
[data-barah-v38-duplicate='1']{display:none!important}
[data-barah-v38-hidden='1']{display:none!important}
@media(max-width:991px){
  #${ROOT} .barah-v38-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
}
@media(max-width:767px){
  #${ROOT}{width:calc(100% - 20px)!important}
  #${ROOT} .barah-v38-shell{padding:14px;border-radius:18px}
  #${ROOT} .barah-v38-copy h2{font-size:22px}
  #${ROOT} .barah-v38-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
  #${ROOT} .barah-v38-title{font-size:12px;min-height:40px}
}
`;
  document.head.appendChild(s);
}

function normHref(h){
  if(!h) return '';
  try{
    var u=new URL(h,location.origin);
    return (u.origin+u.pathname).replace(/\/+$/,'');
  }catch(_){return h}
}
function getHref(card){
  var a=card && card.querySelector && card.querySelector('a[href*="/product-"],a[href*="/p"],a[href]');
  return normHref(a&&a.href||'');
}
function getTitle(card){
  if(!card) return '';
  var t = txt(card.querySelector('h3,h4,.product-title,.product-block__title,[class*="title"]'));
  if(!t){
    var a=card.querySelector('a[title]');
    t=(a&&a.getAttribute('title'))||'';
  }
  if(!t){
    var img=card.querySelector('img[alt]');
    t=(img&&img.getAttribute('alt'))||'';
  }
  return t.replace(/\s+/g,' ').trim();
}
function getImage(card){
  var img=card&&card.querySelector&&card.querySelector('img');
  return (img&& (img.getAttribute('src') || img.getAttribute('data-src') || img.currentSrc)) || '';
}
function getPrice(card){
  if(!card) return '';
  var candidates=$$('.price,.product-price,.price-wrapper,[class*="price"]',card).map(txt).filter(Boolean);
  if(candidates.length) return candidates[0];
  var all=txt(card);
  var m=all.match(/(?:ر\.س|SAR|ريال)\s*\d+[\d\.,]*/i) || all.match(/\d+[\d\.,]*\s*(?:ر\.س|SAR|ريال)/i);
  return m?m[0]:'';
}
function classify(title){
  var t=(title||'').toLowerCase();
  for(var k in KEYWORDS){
    if(KEYWORDS[k].some(function(w){return t.indexOf(w.toLowerCase())>-1;})) return k;
  }
  return 'other';
}
function collectProducts(){
  var out=[]; var seen={};
  $$('main custom-salla-product-card.product-block, main .product-block').forEach(function(card){
    if(card.closest('#'+ROOT)) return;
    var href=getHref(card), title=getTitle(card), img=getImage(card);
    if(!href || !title || !img) return;
    if(seen[href]) return;
    seen[href]=1;
    out.push({href:href,title:title,img:img,price:getPrice(card),cat:classify(title),node:card});
  });
  return out;
}
function buildDiverseList(products, max){
  var buckets={};
  products.forEach(function(p){(buckets[p.cat]=buckets[p.cat]||[]).push(p);});
  Object.keys(buckets).forEach(function(k){buckets[k]=buckets[k].slice(0,4);});
  var order=['body','home','travel','tech','beauty','baby','pet','fun','other'];
  var res=[]; var rounds=0;
  while(res.length<max && rounds<8){
    order.forEach(function(k){ if(buckets[k] && buckets[k].length && res.length<max) res.push(buckets[k].shift()); });
    rounds++;
  }
  if(res.length<max){
    products.forEach(function(p){ if(res.indexOf(p)===-1 && res.length<max) res.push(p); });
  }
  return res.slice(0,max);
}
function renderShowcase(list){
  if(!list.length) return;
  var root=document.getElementById(ROOT);
  if(!root){
    root=document.createElement('section');
    root.id=ROOT;
    root.className='home-block';
  }
  var cats=[];
  list.forEach(function(p){ if(cats.indexOf(p.cat)===-1) cats.push(p.cat); });
  root.innerHTML='';
  var shell=document.createElement('div'); shell.className='barah-v38-shell';
  shell.innerHTML='\
    <div class="barah-v38-head">\
      <div class="barah-v38-copy">\
        <small>تجربة اكتشاف أذكى</small>\
        <h2>تنوع أوضح... ووصول أذكى لما يناسبك</h2>\
        <p>بدلاً من تكرار نفس الأصناف، هذا الرف يلتقط منتجات متنوعة من أقسام مختلفة ليُظهر اتساع متجر بارعة ويجعل التصفح أكثر تشويقًا مع التوسع إلى آلاف الأصناف.</p>\
      </div>\
      <div class="barah-v38-badge">✨ بدون تكرار • تنوع أعلى • عرض أذكى</div>\
    </div>';
  var chips=document.createElement('div'); chips.className='barah-v38-chips';
  cats.slice(0,6).forEach(function(cat){
    var a=document.createElement('a'); a.className='barah-v38-chip';
    a.href='https://barahstore.com/ar/search?q='+encodeURIComponent(LABELS[cat]||LABELS.other);
    a.textContent=LABELS[cat]||LABELS.other;
    chips.appendChild(a);
  });
  shell.appendChild(chips);
  var grid=document.createElement('div'); grid.className='barah-v38-grid';
  list.forEach(function(p){
    var art=document.createElement('article'); art.className='barah-v38-card'; art.setAttribute('data-barah-href',p.href);
    art.innerHTML='\
      <a class="barah-v38-thumb" href="'+p.href+'"><img loading="lazy" src="'+p.img+'" alt="'+p.title.replace(/"/g,'&quot;')+'"></a>\
      <span class="barah-v38-cat">'+(LABELS[p.cat]||LABELS.other)+'</span>\
      <h3 class="barah-v38-title">'+p.title+'</h3>\
      <div class="barah-v38-meta">\
        <span class="barah-v38-price">'+(p.price||'تسوّق الآن')+'</span>\
        <a class="barah-v38-cta" href="'+p.href+'">عرض المنتج</a>\
      </div>';
    grid.appendChild(art);
  });
  shell.appendChild(grid); root.appendChild(shell);

  var anchor=document.getElementById('barah-step-gateway-v36') || document.getElementById('barah-step-personal-v18');
  if(anchor) anchor.insertAdjacentElement('afterend', root);
  else ($('main')||document.body).prepend(root);
}

function dedupeAcrossSections(){
  var seen={};
  var selectors=[
    '#'+ROOT+' [data-barah-href]',
    '#barah-step-most-viewed custom-salla-product-card.product-block',
    'section.home-block.home-block--fixed-products.show-all.barah-v35-latest custom-salla-product-card.product-block',
    'main section.home-block custom-salla-product-card.product-block'
  ];
  selectors.forEach(function(sel){
    $$(sel).forEach(function(card){
      var href=card.getAttribute('data-barah-href') || getHref(card);
      if(!href) return;
      if(seen[href]){ card.setAttribute('data-barah-v38-duplicate','1'); }
      else{ seen[href]=1; card.removeAttribute('data-barah-v38-duplicate'); }
    });
  });
}

function hideRawNoisySections(){
  $$('main section.home-block').forEach(function(sec){
    if(sec.id===ROOT || sec.id==='barah-step-gateway-v36' || sec.id==='barah-step-personal-v18' || sec.id==='barah-step-most-viewed' || sec.id==='barah-step-catalog-v32' || sec.id==='barah-step-wholesale-v32' || sec.id==='barah-step-hero-v12') return;
    if(sec.classList.contains('barah-v35-latest')) return;
    var cards=sec.querySelectorAll('custom-salla-product-card.product-block').length;
    if(cards>=10) sec.setAttribute('data-barah-v38-hidden','1');
  });
}

function keepSectionHealthy(){
  var latest=$('section.home-block.home-block--fixed-products.show-all.barah-v35-latest');
  if(latest){
    var visible=$$('custom-salla-product-card.product-block:not([data-barah-v38-duplicate="1"])',latest);
    visible.forEach(function(card,i){ if(i>3) card.setAttribute('data-barah-v38-hidden','1'); else card.removeAttribute('data-barah-v38-hidden'); });
  }
  var most=$('#barah-step-most-viewed');
  if(most){
    var vis2=$$('custom-salla-product-card.product-block:not([data-barah-v38-duplicate="1"])',most);
    vis2.forEach(function(card,i){ if(i>3) card.setAttribute('data-barah-v38-hidden','1'); else card.removeAttribute('data-barah-v38-hidden'); });
  }
}

function run(){
  addStyle();
  var products=collectProducts();
  var diverse=buildDiverseList(products, 8);
  renderShowcase(diverse);
  hideRawNoisySections();
  dedupeAcrossSections();
  keepSectionHealthy();
}

run();
var mo=new MutationObserver(function(){run();});
mo.observe(document.documentElement,{childList:true,subtree:true});
setTimeout(function(){mo.disconnect();},3500);
setTimeout(run,300); setTimeout(run,900); document.addEventListener('DOMContentLoaded',run,{once:true});
})();

/* ============================================================
   BARAH STEP HOME PRO V39 — ANNOUNCEMENT BAR FIX + HEADER SAFE
   - إزالة شريط الإعلان المتحرك إذا ظهر داخل محرر خطوة
   - منع بقاء فراغ بعده
   - ضمان أن أقسام بارعة كلها تحت الهيدر، لا فوقه
   ============================================================ */
(function(){
'use strict';

if(window.__BARAH_STEP_V39_BAR_FIX__) return;
window.__BARAH_STEP_V39_BAR_FIX__ = true;

var STYLE='barah-step-v39-bar-fix-style';

function addStyle(){
  if(document.getElementById(STYLE)) return;

  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
/* markers added by JS only — safe, no guessing */
[data-barah-v39-announcement="1"]{
  display:none!important;
  visibility:hidden!important;
  height:0!important;
  min-height:0!important;
  max-height:0!important;
  margin:0!important;
  padding:0!important;
  border:0!important;
  overflow:hidden!important;
}
[data-barah-v39-announcement-wrap="1"]{
  margin-top:0!important;
  padding-top:0!important;
  min-height:0!important;
}

/* ensure custom homepage blocks never visually float above header */
#site-header-outer{
  position:relative;
  z-index:50;
}
main{
  position:relative;
  z-index:1;
}
`;
  (document.head||document.documentElement).appendChild(s);
}

function text(el){
  return ((el&&el.textContent)||'').replace(/\s+/g,' ').trim();
}

function looksLikeAnnouncement(el){
  if(!el || el===document.body || el===document.documentElement) return false;
  if(el.id==='site-header-outer' || el.closest('#site-header-outer')) return false;

  var t=text(el);
  if(!t) return false;

  var mentionsShipping =
    /شحن مجاني/i.test(t) ||
    /مجاني.*149/i.test(t) ||
    /الشحن يبدأ/i.test(t) ||
    /171\s*ريال/i.test(t);

  if(!mentionsShipping) return false;

  var r=el.getBoundingClientRect();
  var cs=getComputedStyle(el);

  var compact =
    (r.height>0 && r.height<=80) ||
    /marquee|ticker|announcement|topbar|notice/i.test(
      (el.id||'')+' '+(el.className||'')
    );

  var horizontal =
    r.width >= Math.min(window.innerWidth*0.65, 700);

  var visuallyBarLike =
    cs.whiteSpace==='nowrap' ||
    cs.overflow==='hidden' ||
    cs.display==='flex' ||
    cs.position==='sticky' ||
    cs.position==='relative';

  return compact && horizontal && visuallyBarLike;
}

function hideAnnouncement(){
  var candidates=Array.prototype.slice.call(
    document.querySelectorAll(
      'div,section,aside,p,ul,[class*="announcement"],[class*="ticker"],[class*="marquee"],[class*="topbar"],[class*="notice"]'
    )
  );

  var match=candidates.find(looksLikeAnnouncement);
  if(!match) return false;

  match.setAttribute('data-barah-v39-announcement','1');

  var parent=match.parentElement;
  if(parent){
    var children=Array.prototype.slice.call(parent.children).filter(function(n){
      return n.nodeType===1 && getComputedStyle(n).display!=='none';
    });
    if(children.length===1){
      parent.setAttribute('data-barah-v39-announcement-wrap','1');
    }
  }

  return true;
}

var CUSTOM_ORDER=[
  'barah-step-hero-v12',
  'barah-step-gateway-v36',
  'barah-step-smart-showcase-v38',
  'barah-step-personal-v18'
];

var CUSTOM_AFTER=[
  'barah-step-home-v9',
  'barah-step-catalog-v32',
  'barah-step-most-viewed'
];

function latestSection(){
  return document.querySelector(
    'main section.home-block.home-block--fixed-products.show-all.barah-v35-latest'
  ) || document.querySelector(
    'main section.home-block.home-block--fixed-products.show-all'
  );
}

function moveBefore(anchor,ids){
  if(!anchor||!anchor.parentNode) return;
  var frag=document.createDocumentFragment();
  ids.forEach(function(id){
    var n=document.getElementById(id);
    if(n) frag.appendChild(n);
  });
  if(frag.childNodes.length) anchor.parentNode.insertBefore(frag,anchor);
}

function moveAfter(anchor,ids){
  if(!anchor) return;
  var cur=anchor;
  ids.forEach(function(id){
    var n=document.getElementById(id);
    if(!n) return;
    cur.insertAdjacentElement('afterend',n);
    cur=n;
  });
}

function enforceOrder(){
  var main=document.querySelector('main');
  var latest=latestSection();
  if(!main || !latest) return false;

  moveBefore(latest,CUSTOM_ORDER);
  moveAfter(latest,CUSTOM_AFTER);

  var wholesale=document.getElementById('barah-step-wholesale-v32');
  var footer=document.querySelector('footer');
  if(wholesale && footer && footer.parentNode){
    footer.insertAdjacentElement('beforebegin',wholesale);
  }

  return true;
}

function run(){
  addStyle();
  hideAnnouncement();
  enforceOrder();
}

run();

var obs=new MutationObserver(function(){
  run();
});

obs.observe(document.documentElement,{childList:true,subtree:true});

document.addEventListener('DOMContentLoaded',run,{once:true});
setTimeout(run,150);
setTimeout(run,450);
setTimeout(run,900);
setTimeout(function(){
  run();
  obs.disconnect();
},2600);
})();

/* ============================================================
   BARAH STEP HOME PRO V40 — GEOMETRIC ANNOUNCEMENT STRIP KILLER
   حل أقوى لمشكلة الشريط داخل محرر/معاينة خطوة:
   - لا يعتمد على النص
   - يحدد الشريط هندسيًا بالنسبة للهيدر الفعلي
   - يزيل الشريط والفراغ الناتج عنه
   ============================================================ */
(function(){
'use strict';

if(window.__BARAH_STEP_V40_STRIP_FIX__) return;
window.__BARAH_STEP_V40_STRIP_FIX__=true;

var STYLE='barah-step-v40-strip-fix-style';

function addStyle(){
  if(document.getElementById(STYLE)) return;

  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
[data-barah-v40-strip="1"]{
  display:none!important;
  visibility:hidden!important;
  height:0!important;
  min-height:0!important;
  max-height:0!important;
  margin:0!important;
  padding:0!important;
  border:0!important;
  overflow:hidden!important;
}
[data-barah-v40-strip-wrap="1"]{
  margin-top:0!important;
  margin-bottom:0!important;
  padding-top:0!important;
  padding-bottom:0!important;
  min-height:0!important;
  height:auto!important;
}
#site-header-outer{
  margin-top:0!important;
}
`;
  (document.head||document.documentElement).appendChild(s);
}

function visible(el){
  if(!el || !el.getBoundingClientRect) return false;
  var cs=getComputedStyle(el);
  if(cs.display==='none' || cs.visibility==='hidden' || parseFloat(cs.opacity||'1')===0) return false;
  var r=el.getBoundingClientRect();
  return r.width>0 && r.height>0;
}

function scoreCandidate(el, headerRect){
  if(!visible(el)) return -9999;
  if(el===document.body || el===document.documentElement) return -9999;
  if(el.id==='site-header-outer' || el.closest('#site-header-outer')) return -9999;
  if(el.closest('[id^="barah-step-"]')) return -9999;

  var r=el.getBoundingClientRect();
  var cs=getComputedStyle(el);

  if(r.width < window.innerWidth*0.65) return -9999;
  if(r.height < 8 || r.height > 90) return -9999;

  /* candidate should sit immediately before/above header */
  var gap = Math.abs(headerRect.top - r.bottom);
  if(gap > 36) return -9999;

  var score=0;

  if(r.width >= window.innerWidth*0.9) score+=35;
  if(r.height <= 55) score+=25;
  if(gap <= 8) score+=30;

  var cls=((el.id||'')+' '+(typeof el.className==='string'?el.className:'')).toLowerCase();
  if(/announcement|ticker|marquee|notice|promo|topbar|top-bar/.test(cls)) score+=40;

  if(cs.whiteSpace==='nowrap') score+=15;
  if(cs.overflow==='hidden') score+=10;
  if(cs.display==='flex') score+=6;

  /* dark/teal strip in current Step preview */
  var bg=cs.backgroundColor || '';
  var m=bg.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/i);
  if(m){
    var rr=+m[1], gg=+m[2], bb=+m[3];
    if(gg > rr && gg >= bb) score+=16;   // teal/green family
    if(rr<70 && gg<120 && bb<130) score+=10; // dark bar
  }

  if((el.textContent||'').trim().length>15) score+=5;

  return score;
}

function killStrip(){
  addStyle();

  var header=document.querySelector('#site-header-outer');
  if(!header || !visible(header)) return false;

  var hr=header.getBoundingClientRect();
  var candidates=Array.prototype.slice.call(
    document.querySelectorAll('body *')
  );

  var best=null, bestScore=-9999;

  candidates.forEach(function(el){
    var s=scoreCandidate(el,hr);
    if(s>bestScore){
      bestScore=s;
      best=el;
    }
  });

  if(best && bestScore>=45){
    best.setAttribute('data-barah-v40-strip','1');

    /* if its wrapper only exists to host the strip, collapse that too */
    var p=best.parentElement;
    if(p && p!==document.body && p!==document.documentElement){
      var visChildren=Array.prototype.slice.call(p.children).filter(function(ch){
        return visible(ch) && ch!==best;
      });
      if(visChildren.length===0){
        p.setAttribute('data-barah-v40-strip-wrap','1');
      }
    }

    return true;
  }

  /* fallback: check direct siblings before header */
  var prev=header.previousElementSibling;
  var hops=0;

  while(prev && hops<4){
    if(visible(prev)){
      var r=prev.getBoundingClientRect();
      if(r.width>=window.innerWidth*0.65 && r.height>=8 && r.height<=90){
        prev.setAttribute('data-barah-v40-strip','1');
        return true;
      }
    }
    prev=prev.previousElementSibling;
    hops++;
  }

  return false;
}

function run(){
  killStrip();
}

run();

var obs=new MutationObserver(function(){
  run();
});

obs.observe(document.documentElement,{childList:true,subtree:true,attributes:true});

document.addEventListener('DOMContentLoaded',run,{once:true});
setTimeout(run,120);
setTimeout(run,350);
setTimeout(run,700);
setTimeout(run,1200);
setTimeout(function(){
  run();
  obs.disconnect();
},3000);
})();

/* ============================================================
   BARAH STEP HOME PRO V41 — TRUE DEDUPE + SECTION ROLES
   - آخر نسخة لمعالجة تكرار الأصناف فعليًا بمعرّف المنتج
   - Hero = منتجات بطل
   - Latest = 8 منتجات مختلفة عن Hero ومختارات بارعة
   - Most Viewed = مختلف عن كل ما سبق
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_STEP_V41_TRUE_DEDUPE__) return;
window.__BARAH_STEP_V41_TRUE_DEDUPE__=true;

var STYLE='barah-step-v41-dedupe-style';

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
/* V41 controls visibility; release old V35/V38 hiding rules */
section.barah-v35-latest custom-salla-product-card.product-block:nth-child(n+9){
  display:block!important;
}
[data-barah-v38-duplicate="1"]{
  display:revert!important;
}
[data-barah-v41-hidden="1"]{
  display:none!important;
}

/* keep latest as a clean 4×2 grid on desktop */
section.barah-v35-latest .grid-block.products-list-container.vertical-products{
  display:grid!important;
  grid-template-columns:repeat(4,minmax(0,1fr))!important;
  gap:14px!important;
}
@media(max-width:900px){
  section.barah-v35-latest .grid-block.products-list-container.vertical-products{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
  }
}
@media(max-width:767px){
  section.barah-v35-latest .grid-block.products-list-container.vertical-products{
    display:flex!important;
    overflow-x:auto!important;
    gap:10px!important;
  }
  section.barah-v35-latest custom-salla-product-card.product-block:not([data-barah-v41-hidden="1"]){
    flex:0 0 74%!important;
    max-width:270px!important;
  }
}
`;
  document.head.appendChild(s);
}

function productIdFromUrl(href){
  if(!href) return '';
  var s=String(href);
  var m=s.match(/\/p(\d+)(?:[/?#]|$)/i);
  if(m) return m[1];
  m=s.match(/product-(\d+)/i);
  if(m) return m[1];
  return '';
}

function nodeProductId(node){
  if(!node) return '';

  var attrs=['data-product-id','product-id','data-id','id'];
  for(var i=0;i<attrs.length;i++){
    var v=node.getAttribute && node.getAttribute(attrs[i]);
    if(v){
      var m=String(v).match(/(\d{6,})/);
      if(m) return m[1];
    }
  }

  var anchors=Array.prototype.slice.call(
    node.querySelectorAll ? node.querySelectorAll('a[href]') : []
  );

  for(var j=0;j<anchors.length;j++){
    var id=productIdFromUrl(anchors[j].href || anchors[j].getAttribute('href'));
    if(id) return id;
  }

  return '';
}

function uniqueIdsFrom(root){
  var set={};
  if(!root) return set;

  Array.prototype.slice.call(root.querySelectorAll('a[href]')).forEach(function(a){
    var id=productIdFromUrl(a.href || a.getAttribute('href'));
    if(id) set[id]=1;
  });

  return set;
}

function merge(a,b){
  Object.keys(b||{}).forEach(function(k){a[k]=1;});
  return a;
}

function clearOldFlags(){
  document.querySelectorAll('[data-barah-v38-duplicate]').forEach(function(el){
    el.removeAttribute('data-barah-v38-duplicate');
  });
  document.querySelectorAll('[data-barah-v41-hidden]').forEach(function(el){
    el.removeAttribute('data-barah-v41-hidden');
  });
}

function curateLatest(reserved){
  var section=document.querySelector(
    'section.home-block.home-block--fixed-products.show-all.barah-v35-latest'
  );
  if(!section) return reserved;

  var cards=Array.prototype.slice.call(
    section.querySelectorAll('custom-salla-product-card.product-block')
  );

  var used={};
  var visible=0;

  cards.forEach(function(card){
    var id=nodeProductId(card);

    var duplicate =
      !id ||
      reserved[id] ||
      used[id] ||
      visible>=8;

    if(duplicate){
      card.setAttribute('data-barah-v41-hidden','1');
    }else{
      used[id]=1;
      reserved[id]=1;
      visible++;
    }
  });

  return reserved;
}

function curateMostViewed(reserved){
  var root=document.getElementById('barah-step-most-viewed');
  if(!root) return reserved;

  var cards=Array.prototype.slice.call(
    root.querySelectorAll(
      '.barah-step-most-viewed__card, [data-product-id], article, li'
    )
  ).filter(function(card){
    return nodeProductId(card);
  });

  var used={};
  var visible=0;

  cards.forEach(function(card){
    var id=nodeProductId(card);

    if(!id || reserved[id] || used[id] || visible>=4){
      card.setAttribute('data-barah-v41-hidden','1');
    }else{
      used[id]=1;
      reserved[id]=1;
      visible++;
    }
  });

  return reserved;
}

function run(){
  addStyle();
  clearOldFlags();

  var reserved={};

  /* Hero products are allowed once only */
  merge(reserved, uniqueIdsFrom(document.getElementById('barah-step-hero-v12')));

  /* Preserve BARAH Picks as the flagship shelf */
  merge(reserved, uniqueIdsFrom(document.getElementById('barah-step-home-v9')));

  /* Latest now skips anything already used above */
  reserved=curateLatest(reserved);

  /* Most viewed becomes the discovery tail, no repeats */
  curateMostViewed(reserved);

  document.documentElement.setAttribute('data-barah-v41-dedupe','ready');
}

run();

var obs=new MutationObserver(function(){
  run();
});
obs.observe(document.documentElement,{childList:true,subtree:true});

document.addEventListener('DOMContentLoaded',run,{once:true});
setTimeout(run,250);
setTimeout(run,800);
setTimeout(run,1800);
setTimeout(run,3800);
setTimeout(function(){
  run();
  obs.disconnect();
},5200);
})();

/* ============================================================
   BARAH STEP HOME PRO V44 — SMART STOREFRONT ARCHITECTURE
   مبني على بيانات الكتالوج الحالية:
   المنزل والمطبخ / العناية والأناقة / الرياضة واللياقة /
   السفر والرحلات / السيارة / الطفل والألعاب /
   الحيوانات الأليفة / الحفلات / الشتاء
   + مسارات فعلية من المنتجات الحالية:
   كبار السن، الحوامل، السفر، السيارة، المنزل، الجوال، الحيوانات.
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_STEP_V44_SMART_STOREFRONT__) return;
window.__BARAH_STEP_V44_SMART_STOREFRONT__=true;

var ROOT='barah-step-smart-storefront-v44';
var STYLE=ROOT+'-style';

var LINKS={
  home:'/ar',
  all:'https://barahstore.com/ar/home-kitchen/c127906256',
  best:'https://barahstore.com/ar/home-kitchen/c127906256',
  offers:'/ar/offers/c558473504',
  homeKitchen:'/ar/home-kitchen/c127906256',
  care:'/ar/care-style/c727852954',
  fitness:'/ar/fitness/c511828448',
  travel:'/ar/travel/c336613091',
  car:'/ar/car/c228633582',
  baby:'/ar/baby-toys/c694872552',
  pets:'/ar/pets/c92693286',
  parties:'/ar/الحفلات-والمناسبات/c1851175671',
  winter:'/ar/offers/c558473504'
};

var SEARCH={
  cane:'/ar/search?q='+encodeURIComponent('عكاز'),
  pedal:'/ar/search?q='+encodeURIComponent('بيدال'),
  knee:'/ar/search?q='+encodeURIComponent('ركبة'),
  massage:'/ar/search?q='+encodeURIComponent('مساج'),
  pregnancy:'/ar/search?q='+encodeURIComponent('Pregnancy'),
  maternity:'/ar/search?q='+encodeURIComponent('حامل'),
  travelKit:'/ar/search?q='+encodeURIComponent('سفر'),
  organizer:'/ar/search?q='+encodeURIComponent('تنظيم'),
  kitchen:'/ar/search?q='+encodeURIComponent('مطبخ'),
  phone:'/ar/search?q='+encodeURIComponent('جوال'),
  cat:'/ar/search?q='+encodeURIComponent('قطط'),
  gifts:'/ar/search?q='+encodeURIComponent('هدية')
};

function isHome(){
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  return p==='/' || p==='/ar' || p==='/en';
}
if(!isHome()) return;

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
#barah-step-gateway-v36,
#barah-step-smart-showcase-v38,
#barah-step-personal-v18{
  display:none!important;
}

#${ROOT}{
  direction:rtl!important;
  width:min(1180px,calc(100% - 32px))!important;
  max-width:1180px!important;
  margin:18px auto 26px!important;
  font-family:inherit!important;
}
#${ROOT} *{box-sizing:border-box!important}

#${ROOT} .v44-shell{
  position:relative!important;
  overflow:hidden!important;
  border-radius:28px!important;
  border:1px solid #ede1d8!important;
  background:
    radial-gradient(circle at 10% 8%,rgba(255,122,24,.10),transparent 24%),
    radial-gradient(circle at 90% 10%,rgba(239,68,68,.07),transparent 24%),
    linear-gradient(180deg,#fffdfb 0%,#fff8f3 100%)!important;
  box-shadow:0 20px 48px rgba(33,23,18,.07)!important;
}

#${ROOT} .v44-head{
  display:grid!important;
  grid-template-columns:minmax(0,1.25fr) minmax(280px,.75fr)!important;
  gap:18px!important;
  padding:26px 26px 20px!important;
  border-bottom:1px solid rgba(229,205,190,.55)!important;
}
#${ROOT} .v44-eyebrow{
  display:inline-flex!important;
  align-items:center!important;
  width:max-content!important;
  padding:7px 11px!important;
  margin-bottom:9px!important;
  border-radius:999px!important;
  background:#fff0e5!important;
  color:#a55222!important;
  font-size:11px!important;
  font-weight:900!important;
}
#${ROOT} .v44-title{
  margin:0!important;
  color:#201915!important;
  font-size:36px!important;
  line-height:1.3!important;
  font-weight:950!important;
  letter-spacing:-.2px!important;
}
#${ROOT} .v44-sub{
  margin:10px 0 0!important;
  max-width:780px!important;
  color:#74665e!important;
  font-size:14px!important;
  line-height:1.95!important;
}
#${ROOT} .v44-head-actions{
  display:flex!important;
  flex-direction:column!important;
  justify-content:center!important;
  gap:10px!important;
}
#${ROOT} .v44-btn{
  min-height:46px!important;
  padding:0 16px!important;
  border-radius:14px!important;
  display:flex!important;
  align-items:center!important;
  justify-content:center!important;
  gap:8px!important;
  text-decoration:none!important;
  font-size:12px!important;
  font-weight:900!important;
}
#${ROOT} .v44-btn.primary{
  color:#fff!important;
  background:linear-gradient(135deg,#ff7a18,#ef4444)!important;
  box-shadow:0 12px 26px rgba(239,68,68,.18)!important;
}
#${ROOT} .v44-btn.secondary{
  color:#4b3d35!important;
  background:#fff!important;
  border:1px solid #eadcd3!important;
}

/* flagship intent cards */
#${ROOT} .v44-featured{
  display:grid!important;
  grid-template-columns:repeat(2,minmax(0,1fr))!important;
  gap:14px!important;
  padding:20px 26px 16px!important;
}
#${ROOT} .v44-feature{
  position:relative!important;
  min-height:240px!important;
  padding:20px!important;
  border-radius:22px!important;
  overflow:hidden!important;
  text-decoration:none!important;
  display:flex!important;
  flex-direction:column!important;
  justify-content:space-between!important;
  border:1px solid rgba(233,216,205,.9)!important;
  box-shadow:0 12px 28px rgba(34,24,18,.05)!important;
}
#${ROOT} .v44-feature.senior{
  background:
    radial-gradient(circle at 88% 12%,rgba(255,175,113,.28),transparent 30%),
    linear-gradient(135deg,#fff8f1,#fff)!important;
}
#${ROOT} .v44-feature.mom{
  background:
    radial-gradient(circle at 88% 12%,rgba(255,200,187,.24),transparent 30%),
    linear-gradient(135deg,#fff9f6,#fff)!important;
}
#${ROOT} .v44-label{
  display:inline-flex!important;
  width:max-content!important;
  padding:6px 9px!important;
  border-radius:999px!important;
  background:#fff!important;
  border:1px solid #f0ddd0!important;
  color:#aa5e2e!important;
  font-size:10px!important;
  font-weight:900!important;
}
#${ROOT} .v44-feature h3{
  margin:14px 0 8px!important;
  color:#251e19!important;
  font-size:25px!important;
  line-height:1.45!important;
  font-weight:950!important;
}
#${ROOT} .v44-feature p{
  margin:0!important;
  color:#746861!important;
  max-width:560px!important;
  font-size:13px!important;
  line-height:1.9!important;
}
#${ROOT} .v44-feature-chips{
  display:flex!important;
  flex-wrap:wrap!important;
  gap:8px!important;
  margin-top:18px!important;
}
#${ROOT} .v44-feature-chip{
  display:inline-flex!important;
  min-height:34px!important;
  align-items:center!important;
  padding:0 10px!important;
  border-radius:999px!important;
  background:rgba(255,255,255,.88)!important;
  border:1px solid #eadfd7!important;
  color:#5d4e45!important;
  font-size:11px!important;
  font-weight:800!important;
}
#${ROOT} .v44-feature-cta{
  display:inline-flex!important;
  align-items:center!important;
  margin-top:16px!important;
  color:#ef5d2d!important;
  font-size:12px!important;
  font-weight:950!important;
}

/* mission grid */
#${ROOT} .v44-missions{
  padding:8px 26px 18px!important;
}
#${ROOT} .v44-section-head{
  display:flex!important;
  align-items:end!important;
  justify-content:space-between!important;
  gap:12px!important;
  margin-bottom:12px!important;
}
#${ROOT} .v44-section-head h3{
  margin:0!important;
  color:#241e1a!important;
  font-size:21px!important;
  font-weight:950!important;
}
#${ROOT} .v44-section-head span{
  color:#8b7d74!important;
  font-size:11px!important;
}
#${ROOT} .v44-mission-grid{
  display:grid!important;
  grid-template-columns:repeat(4,minmax(0,1fr))!important;
  gap:11px!important;
}
#${ROOT} .v44-mission{
  min-height:138px!important;
  padding:15px!important;
  border-radius:18px!important;
  background:#fff!important;
  border:1px solid #eee2da!important;
  text-decoration:none!important;
  box-shadow:0 8px 18px rgba(34,24,18,.035)!important;
  transition:transform .18s ease,box-shadow .18s ease!important;
}
#${ROOT} .v44-mission:hover{
  transform:translateY(-2px)!important;
  box-shadow:0 14px 24px rgba(34,24,18,.07)!important;
}
#${ROOT} .v44-icon{
  width:38px!important;
  height:38px!important;
  display:grid!important;
  place-items:center!important;
  border-radius:13px!important;
  margin-bottom:10px!important;
  background:#fff3e9!important;
  color:#e3672a!important;
  font-size:18px!important;
}
#${ROOT} .v44-mission b{
  display:block!important;
  color:#28211d!important;
  font-size:14px!important;
  margin-bottom:5px!important;
}
#${ROOT} .v44-mission small{
  display:block!important;
  color:#776a62!important;
  font-size:11px!important;
  line-height:1.75!important;
}

/* category rails */
#${ROOT} .v44-categories{
  padding:2px 26px 22px!important;
}
#${ROOT} .v44-cat-row{
  display:flex!important;
  flex-wrap:wrap!important;
  gap:8px!important;
}
#${ROOT} .v44-cat{
  min-height:38px!important;
  display:inline-flex!important;
  align-items:center!important;
  padding:0 12px!important;
  border-radius:999px!important;
  text-decoration:none!important;
  background:#fff!important;
  border:1px solid #e9ddd4!important;
  color:#50423a!important;
  font-size:11px!important;
  font-weight:850!important;
}
#${ROOT} .v44-footer{
  display:flex!important;
  align-items:center!important;
  justify-content:space-between!important;
  gap:12px!important;
  margin:0 26px 24px!important;
  padding:14px 16px!important;
  border-radius:16px!important;
  background:#fff3ea!important;
  border:1px solid #f0dacb!important;
}
#${ROOT} .v44-footer strong{
  color:#2b221d!important;
  font-size:12px!important;
}
#${ROOT} .v44-footer span{
  color:#7d6d63!important;
  font-size:11px!important;
}
#${ROOT} .v44-footer a{
  flex:0 0 auto!important;
  text-decoration:none!important;
  color:#fff!important;
  background:#222!important;
  border-radius:11px!important;
  padding:9px 12px!important;
  font-size:11px!important;
  font-weight:900!important;
}

@media(max-width:980px){
  #${ROOT} .v44-head{grid-template-columns:1fr!important;}
  #${ROOT} .v44-featured{grid-template-columns:1fr!important;}
  #${ROOT} .v44-mission-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important;}
}
@media(max-width:767px){
  #${ROOT}{width:calc(100% - 20px)!important;margin:14px 10px 20px!important;}
  #${ROOT} .v44-shell{border-radius:20px!important;}
  #${ROOT} .v44-head{padding:18px 14px 14px!important;}
  #${ROOT} .v44-title{font-size:25px!important;}
  #${ROOT} .v44-featured{padding:14px!important;}
  #${ROOT} .v44-feature{min-height:auto!important;padding:16px!important;border-radius:18px!important;}
  #${ROOT} .v44-feature h3{font-size:21px!important;}
  #${ROOT} .v44-missions{padding:4px 14px 14px!important;}
  #${ROOT} .v44-mission-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:8px!important;}
  #${ROOT} .v44-mission{min-height:128px!important;padding:12px!important;}
  #${ROOT} .v44-categories{padding:0 14px 16px!important;}
  #${ROOT} .v44-cat-row{overflow-x:auto!important;flex-wrap:nowrap!important;scrollbar-width:none!important;}
  #${ROOT} .v44-cat-row::-webkit-scrollbar{display:none!important;}
  #${ROOT} .v44-cat{flex:0 0 auto!important;}
  #${ROOT} .v44-footer{margin:0 14px 16px!important;display:block!important;}
  #${ROOT} .v44-footer a{display:inline-flex!important;margin-top:10px!important;}
}
`;
  document.head.appendChild(s);
}

function mission(icon,title,desc,href){
  return '<a class="v44-mission" href="'+href+'">'+
    '<span class="v44-icon">'+icon+'</span>'+
    '<b>'+title+'</b>'+
    '<small>'+desc+'</small>'+
  '</a>';
}

function cat(label,href){
  return '<a class="v44-cat" href="'+href+'">'+label+'</a>';
}

function build(){
  var root=document.getElementById(ROOT);
  if(root) return root;

  root=document.createElement('section');
  root.id=ROOT;

  root.innerHTML=
  '<div class="v44-shell">'+
    '<div class="v44-head">'+
      '<div>'+
        '<span class="v44-eyebrow">واجهة بارعة الجديدة • مبنية على احتياج العميل لا على كثرة المنتجات</span>'+
        '<h2 class="v44-title">تسوّق حسب اللحظة… وليس حسب الزحمة</h2>'+
        '<p class="v44-sub">كتالوج بارعة الحالي متنوع جدًا: منزل ومطبخ، عناية وأناقة، رياضة، سفر، سيارة، طفل، حيوانات أليفة وحفلات. لذلك الواجهة الأفضل لا تعرض كل شيء مرة واحدة؛ بل تعطي العميل بوابات ذكية توصله لاحتياجه خلال ثوانٍ.</p>'+
      '</div>'+
      '<div class="v44-head-actions">'+
        '<a class="v44-btn primary" href="'+LINKS.best+'">ابدأ من الأكثر طلبًا ←</a>'+

      '</div>'+
    '</div>'+

    '<div class="v44-featured">'+
      '<a class="v44-feature senior" href="'+SEARCH.cane+'">'+
        '<div>'+
          '<span class="v44-label">🎁 زاوية هدية لها معنى</span>'+
          '<h3>راحة واهتمام لكبار السن</h3>'+
          '<p>من العكازات القابلة للطي إلى بيدال التمارين ومشدات الركبة ومنتجات الراحة؛ هذه زاوية للعميل الذي يريد هدية نافعة تخدم اليوم، لا مجرد قطعة جميلة.</p>'+
          '<div class="v44-feature-chips">'+
            '<span class="v44-feature-chip">عكازات</span>'+
            '<span class="v44-feature-chip">بيدال منزلي</span>'+
            '<span class="v44-feature-chip">دعم الركبة</span>'+
            '<span class="v44-feature-chip">راحة ومساج</span>'+
          '</div>'+
        '</div>'+
        '<span class="v44-feature-cta">اكتشف هدايا عملية لكبار السن ←</span>'+
      '</a>'+

      '<a class="v44-feature mom" href="'+SEARCH.pregnancy+'">'+
        '<div>'+
          '<span class="v44-label">🤍 للأم والطفل</span>'+
          '<h3>اختيارات أهدأ للحمل وبداية الطفل</h3>'+
          '<p>الحزام الداعم للحامل، شنطة مستلزمات الطفل، سرير السفر 4 في 1، ولوازم الطفل اليومية؛ مسار أكثر لطفًا للأم التي تريد الوصول بسرعة دون البحث داخل عشرات الأقسام.</p>'+
          '<div class="v44-feature-chips">'+
            '<span class="v44-feature-chip">دعم الحمل</span>'+
            '<span class="v44-feature-chip">شنط الطفل</span>'+
            '<span class="v44-feature-chip">السفر مع الطفل</span>'+
            '<span class="v44-feature-chip">الاستخدام اليومي</span>'+
          '</div>'+
        '</div>'+
        '<span class="v44-feature-cta">تسوّقي للأم والطفل ←</span>'+
      '</a>'+
    '</div>'+

    '<div class="v44-missions">'+
      '<div class="v44-section-head"><h3>اختاري الهدف… ونحن نختصر الطريق</h3><span>مسارات مستخرجة من منتجات الكتالوج الحالية</span></div>'+
      '<div class="v44-mission-grid">'+
        mission('✈','قبل السفر','عبوات سفر، تنظيم الحقائب، ميزان، وسادة وإكسسوارات التنقل.',LINKS.travel)+
        mission('⌂','رتّب البيت','منظمات، أدوات مطبخ، ستاندات، تنظيف وحلول يومية بسيطة.',LINKS.homeKitchen)+
        mission('🚗','جهّز سيارتك','حوامل جوال، فواحات، تنظيم المقعد وإكسسوارات عملية للطريق.',LINKS.car)+
        mission('📱','خلّ الشاشة أريح','حوامل هاتف وتابلت، حامل رقبة، قواعد قابلة للطي ومكبر شاشة.',SEARCH.phone)+
        mission('🏃','حركة أخف في البيت','بيدال، مقاومات، دعم ركبة وتمارين منزلية تناسب الروتين اليومي.',LINKS.fitness)+
        mission('✨','عناية لنفسك','مساج، عناية بالوجه والقدمين، أدوات شعر وأناقة شخصية.',LINKS.care)+
        mission('🐾','وقت ممتع للحيوانات','ألعاب تفاعلية وإكسسوارات تجعل وقت الحيوان الأليف أكثر حركة.',LINKS.pets)+
        mission('🎉','للمناسبة والهديّة','منتجات مرحة، هدايا عملية، ألعاب ولمسات صغيرة تلفت الانتباه.',LINKS.parties)+
      '</div>'+
    '</div>'+

    '<div class="v44-categories">'+
      '<div class="v44-section-head"><h3>أقسام بارعة الرئيسية</h3><span>هيكل قابل للتوسع إلى آلاف المنتجات</span></div>'+
      '<div class="v44-cat-row">'+
        cat('المنزل والمطبخ',LINKS.homeKitchen)+
        cat('العناية والأناقة',LINKS.care)+
        cat('الرياضة واللياقة',LINKS.fitness)+
        cat('السفر والرحلات',LINKS.travel)+
        cat('السيارة',LINKS.car)+
        cat('الطفل والألعاب',LINKS.baby)+
        cat('الحيوانات الأليفة',LINKS.pets)+
        cat('الحفلات والمناسبات',LINKS.parties)+
        cat('العروض',LINKS.offers)+
      '</div>'+
    '</div>'+

    '<div class="v44-footer">'+
      '<div><strong>فكرة الواجهة:</strong> <span>كل مساحة لها وظيفة مختلفة: هدية، احتياج، مناسبة أو روتين. بهذا نحافظ على التنوع حتى عندما يتجاوز الكتالوج 2000 صنف.</span></div>'+
      '<a href="'+LINKS.all+'">استكشف الكتالوج كاملًا ←</a>'+
    '</div>'+
  '</div>';

  return root;
}

function mount(){
  addStyle();
  var root=build();
  var hero=document.getElementById('barah-step-hero-v12');
  var latest=document.querySelector('section.home-block.home-block--fixed-products.show-all.barah-v35-latest');

  if(hero && hero.parentNode){
    if(hero.nextElementSibling!==root){
      hero.insertAdjacentElement('afterend',root);
    }
    return true;
  }

  if(latest && latest.parentNode){
    latest.parentNode.insertBefore(root,latest);
    return true;
  }

  return false;
}

mount();
var observer=new MutationObserver(function(){
  if(mount()) observer.disconnect();
});
observer.observe(document.documentElement,{childList:true,subtree:true});
document.addEventListener('DOMContentLoaded',mount,{once:true});
setTimeout(mount,250);
setTimeout(mount,700);
setTimeout(function(){observer.disconnect();},2200);
})();

/* ============================================================
   BARAH STEP HOME PRO V45 — SEO CONVERSION + PREMIUM TITLES
   - تحسين العناوين حسب نية البحث
   - تقوية الربط الداخلي للفئات
   - رفع الوضوح البصري والتحويل
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_STEP_V45_SEO_VISUAL__) return;
window.__BARAH_STEP_V45_SEO_VISUAL__=true;

var ROOT='barah-step-smart-storefront-v44';
var STYLE='barah-step-v45-seo-visual-style';

var CAT_URLS={
  home:'/ar/home-kitchen/c127906256',
  care:'/ar/care-style/c727852954',
  fitness:'/ar/fitness/c511828448',
  travel:'/ar/travel/c336613091',
  car:'/ar/car/c228633582',
  baby:'/ar/baby-toys/c694872552',
  pets:'/ar/pets/c92693286',
  parties:'/ar/الحفلات-والمناسبات/c1851175671',
  offers:'/ar/offers/c558473504'
};

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
#${ROOT} .v44-shell{
  border-color:#eadbcf!important;
  background:
    radial-gradient(circle at 8% 4%,rgba(255,122,24,.12),transparent 25%),
    radial-gradient(circle at 92% 8%,rgba(239,68,68,.08),transparent 25%),
    linear-gradient(180deg,#fffdfb 0%,#fff8f2 100%)!important;
}
#${ROOT} .v44-head{
  padding:30px 28px 22px!important;
}
#${ROOT} .v44-eyebrow{
  background:#fff1e7!important;
  color:#a94d1b!important;
}
#${ROOT} .v44-title{
  max-width:840px!important;
  font-size:39px!important;
  line-height:1.28!important;
  letter-spacing:-.3px!important;
}
#${ROOT} .v44-sub{
  max-width:900px!important;
  font-size:14.5px!important;
}
#${ROOT} .v44-head-actions{
  align-self:center!important;
}
#${ROOT} .v44-btn{
  min-height:48px!important;
  border-radius:13px!important;
}
#${ROOT} .v44-featured{
  gap:16px!important;
}
#${ROOT} .v44-feature{
  min-height:255px!important;
  padding:22px!important;
  border-radius:24px!important;
}
#${ROOT} .v44-feature h3{
  font-size:26px!important;
}
#${ROOT} .v44-feature p{
  font-size:13.5px!important;
}
#${ROOT} .v44-feature.senior{
  border-top:3px solid #f59e61!important;
}
#${ROOT} .v44-feature.mom{
  border-top:3px solid #f6b1a0!important;
}
#${ROOT} .v44-section-head{
  margin-bottom:14px!important;
}
#${ROOT} .v44-section-head h3{
  font-size:23px!important;
}
#${ROOT} .v44-mission-grid{
  gap:12px!important;
}
#${ROOT} .v44-mission{
  min-height:150px!important;
  padding:16px!important;
  border-radius:19px!important;
  position:relative!important;
  overflow:hidden!important;
}
#${ROOT} .v44-mission::after{
  content:''!important;
  position:absolute!important;
  width:76px!important;
  height:76px!important;
  left:-18px!important;
  bottom:-22px!important;
  border-radius:50%!important;
  background:radial-gradient(circle,rgba(255,132,62,.10),transparent 70%)!important;
  pointer-events:none!important;
}
#${ROOT} .v44-mission b{
  font-size:14.5px!important;
}
#${ROOT} .v44-mission small{
  font-size:11.5px!important;
}
#${ROOT} .v44-cat{
  min-height:40px!important;
  padding:0 14px!important;
  font-size:11.5px!important;
}
#${ROOT} .v45-seo-links{
  margin:0 26px 20px!important;
  padding:16px!important;
  border:1px solid #eadfd7!important;
  border-radius:18px!important;
  background:#fff!important;
}
#${ROOT} .v45-seo-links h4{
  margin:0 0 10px!important;
  color:#241d19!important;
  font-size:14px!important;
  font-weight:900!important;
}
#${ROOT} .v45-seo-row{
  display:flex!important;
  flex-wrap:wrap!important;
  gap:8px!important;
}
#${ROOT} .v45-seo-link{
  display:inline-flex!important;
  align-items:center!important;
  min-height:36px!important;
  padding:0 11px!important;
  border-radius:999px!important;
  background:#fff8f3!important;
  border:1px solid #f0ded2!important;
  color:#694c3a!important;
  text-decoration:none!important;
  font-size:11px!important;
  font-weight:850!important;
}
@media(max-width:767px){
  #${ROOT} .v44-head{padding:20px 14px 15px!important;}
  #${ROOT} .v44-title{font-size:27px!important;}
  #${ROOT} .v44-feature{min-height:auto!important;}
  #${ROOT} .v44-feature h3{font-size:21px!important;}
  #${ROOT} .v45-seo-links{margin:0 14px 16px!important;padding:13px!important;}
  #${ROOT} .v45-seo-row{
    overflow-x:auto!important;
    flex-wrap:nowrap!important;
    scrollbar-width:none!important;
  }
  #${ROOT} .v45-seo-row::-webkit-scrollbar{display:none!important;}
  #${ROOT} .v45-seo-link{flex:0 0 auto!important;}
}
`;
  document.head.appendChild(s);
}

function setText(sel,value){
  var el=document.querySelector(sel);
  if(el) el.textContent=value;
}
function setLink(el,href,title){
  if(!el) return;
  el.href=href;
  if(title){
    el.setAttribute('title',title);
    el.setAttribute('aria-label',title);
  }
}
function upgrade(){
  addStyle();

  var root=document.getElementById(ROOT);
  if(!root) return false;

  root.setAttribute('aria-label','تسوّق حسب الاحتياج في متجر بارعة');

  setText('#'+ROOT+' .v44-eyebrow','اكتشاف أسرع • ربط داخلي أقوى • اختيارات حسب الاحتياج');
  setText('#'+ROOT+' .v44-title','اكتشف احتياجك أسرع: منزل، عناية، سفر، رياضة وهدايا عملية');
  setText('#'+ROOT+' .v44-sub',
    'تسوّق في بارعة عبر مسارات واضحة بدل التشتت بين مئات المنتجات: أدوات المنزل والمطبخ، العناية الشخصية، الرياضة واللياقة، مستلزمات السفر والرحلات، إكسسوارات السيارة، الطفل والألعاب، الحيوانات الأليفة والهدايا العملية.'
  );

  var features=root.querySelectorAll('.v44-feature');
  if(features[0]){
    var h=features[0].querySelector('h3');
    var p=features[0].querySelector('p');
    if(h) h.textContent='هدايا عملية لكبار السن | عكازات، بيدال ودعم الركبة';
    if(p) p.textContent='اختيارات نافعة تخدم الراحة والحركة اليومية: عكازات قابلة للطي، بيدال للتمارين المنزلية، دعامات ومشدات للركبة ومنتجات الراحة والمساج.';
    setLink(features[0],'/ar/search?q='+encodeURIComponent('عكاز'),'هدايا عملية لكبار السن من بارعة');
  }
  if(features[1]){
    var h2=features[1].querySelector('h3');
    var p2=features[1].querySelector('p');
    if(h2) h2.textContent='احتياجات الحامل والطفل | دعم الحمل والتنقل والتجهيز اليومي';
    if(p2) p2.textContent='مسار مريح للأم يبدأ من دعم الحمل ويصل إلى شنط ومستلزمات الطفل وتجهيزات السفر والتنقل اليومية.';
    setLink(features[1],'/ar/search?q='+encodeURIComponent('Pregnancy'),'احتياجات الحامل والطفل في بارعة');
  }

  setText('#'+ROOT+' .v44-missions .v44-section-head h3','تسوّق حسب احتياجك اليوم');
  var missions=root.querySelectorAll('.v44-mission');
  var data=[
    ['✈','مستلزمات السفر والرحلات','عبوات سفر، منظمات حقائب، ميزان، وسائد وإكسسوارات تجعل التجهيز أسهل.',CAT_URLS.travel,'مستلزمات السفر والرحلات في السعودية'],
    ['⌂','أدوات المنزل والمطبخ والتنظيم','منظمات، أدوات مطبخ، حلول تنظيف وقطع عملية للروتين المنزلي.',CAT_URLS.home,'أدوات المنزل والمطبخ والتنظيم'],
    ['🚗','إكسسوارات ولوازم السيارة','حوامل جوال، فواحات، تنظيم المقعد وإكسسوارات للاستخدام اليومي.',CAT_URLS.car,'إكسسوارات ولوازم السيارة'],
    ['📱','إكسسوارات الجوال والاستخدام المريح','حوامل هاتف وتابلت، حامل رقبة وقواعد تساعد على مشاهدة أكثر راحة.','/ar/search?q='+encodeURIComponent('جوال'),'إكسسوارات الجوال والحوامل'],
    ['🏃','معدات التمارين المنزلية ودعم الركبة','بيدال، مقاومات، دعامات ركبة وتمارين مناسبة للحركة داخل المنزل.',CAT_URLS.fitness,'معدات التمارين المنزلية ودعم الركبة'],
    ['✨','العناية الشخصية والمساج','منتجات للعناية بالوجه والقدمين والمساج والراحة اليومية.',CAT_URLS.care,'العناية الشخصية والمساج'],
    ['🐾','مستلزمات الحيوانات الأليفة','ألعاب تفاعلية وإكسسوارات للعناية واللعب داخل المنزل.',CAT_URLS.pets,'مستلزمات الحيوانات الأليفة'],
    ['🎉','هدايا وحفلات ومناسبات','أفكار عملية ومرحة للهدايا والحفلات والمناسبات المختلفة.',CAT_URLS.parties,'هدايا وحفلات ومناسبات']
  ];
  missions.forEach(function(m,i){
    if(!data[i]) return;
    var icon=m.querySelector('.v44-icon');
    var b=m.querySelector('b');
    var sm=m.querySelector('small');
    if(icon) icon.textContent=data[i][0];
    if(b) b.textContent=data[i][1];
    if(sm) sm.textContent=data[i][2];
    setLink(m,data[i][3],data[i][4]);
  });

  setText('#'+ROOT+' .v44-categories .v44-section-head h3','تصفّح أقسام بارعة');
  setText('#'+ROOT+' .v44-categories .v44-section-head span','روابط داخلية مباشرة لأهم أقسام المتجر');

  var catLinks=root.querySelectorAll('.v44-cat');
  var catData=[
    ['أدوات المنزل والمطبخ',CAT_URLS.home,'أدوات المنزل والمطبخ'],
    ['العناية الشخصية والأناقة',CAT_URLS.care,'العناية الشخصية والأناقة'],
    ['الرياضة واللياقة',CAT_URLS.fitness,'الرياضة واللياقة'],
    ['مستلزمات السفر والرحلات',CAT_URLS.travel,'مستلزمات السفر والرحلات'],
    ['إكسسوارات السيارة',CAT_URLS.car,'إكسسوارات ولوازم السيارة'],
    ['مستلزمات الطفل والألعاب',CAT_URLS.baby,'مستلزمات الطفل والألعاب'],
    ['مستلزمات الحيوانات الأليفة',CAT_URLS.pets,'مستلزمات الحيوانات الأليفة'],
    ['الحفلات والمناسبات',CAT_URLS.parties,'الحفلات والمناسبات'],
    ['عروض بارعة',CAT_URLS.offers,'عروض بارعة']
  ];
  catLinks.forEach(function(a,i){
    if(!catData[i]) return;
    a.textContent=catData[i][0];
    setLink(a,catData[i][1],catData[i][2]);
  });

  if(!root.querySelector('.v45-seo-links')){
    var block=document.createElement('nav');
    block.className='v45-seo-links';
    block.setAttribute('aria-label','روابط تسوق سريعة');
    block.innerHTML=
      '<h4>روابط سريعة حسب نية الشراء</h4>'+
      '<div class="v45-seo-row">'+
        '<a class="v45-seo-link" href="/ar/search?q='+encodeURIComponent('عكاز')+'">عكازات لكبار السن</a>'+
        '<a class="v45-seo-link" href="/ar/search?q='+encodeURIComponent('بيدال')+'">بيدال تمارين منزلي</a>'+
        '<a class="v45-seo-link" href="/ar/search?q='+encodeURIComponent('ركبة')+'">دعامات ومشدات الركبة</a>'+
        '<a class="v45-seo-link" href="/ar/search?q='+encodeURIComponent('Pregnancy')+'">احتياجات الحوامل</a>'+
        '<a class="v45-seo-link" href="'+CAT_URLS.travel+'">تجهيزات السفر</a>'+
        '<a class="v45-seo-link" href="'+CAT_URLS.home+'">تنظيم المنزل والمطبخ</a>'+
        '<a class="v45-seo-link" href="'+CAT_URLS.car+'">إكسسوارات السيارة</a>'+
        '<a class="v45-seo-link" href="'+CAT_URLS.pets+'">منتجات الحيوانات الأليفة</a>'+
      '</div>';
    var footer=root.querySelector('.v44-footer');
    if(footer) root.querySelector('.v44-shell').insertBefore(block,footer);
  }

  var footerStrong=root.querySelector('.v44-footer strong');
  var footerSpan=root.querySelector('.v44-footer span');
  if(footerStrong) footerStrong.textContent='واجهة مبنية للتحويل وSEO:';
  if(footerSpan) footerSpan.textContent='عناوين واضحة، روابط داخلية وصفية، ومسارات شراء مختلفة حتى يتوسع الكتالوج بدون فوضى أو تكرار.';

  return true;
}

if(!upgrade()){
  var obs=new MutationObserver(function(){
    if(upgrade()) obs.disconnect();
  });
  obs.observe(document.documentElement,{childList:true,subtree:true});
  document.addEventListener('DOMContentLoaded',upgrade,{once:true});
  setTimeout(upgrade,250);
  setTimeout(upgrade,700);
  setTimeout(function(){obs.disconnect();},2200);
}
})();

/* ============================================================
   BARAH STEP HOME V49 — SEASON EDITORIAL + TRUST RAIL
   مبني على الأقسام الفعلية في متجر بارعة:
   - مستلزمات الشتاء
   - الحفلات والمناسبات
   الهدف: إبراز أقسام غير حاضرة بوضوح في واجهة الصفحة الرئيسية
   بدون صور إضافية = تحميل أخف
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_STEP_SEASON_V49__)return;
window.__BARAH_STEP_SEASON_V49__=true;

var ROOT='barah-step-season-v49';
var STYLE=ROOT+'-style';

function isHome(){
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  return /^\/(ar|en)?$/.test(p) || (location.hostname==='salla.sa'&&/^\/br1$/.test(p));
}
if(!isHome())return;

function style(){
  if(document.getElementById(STYLE))return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
#${ROOT}{
  direction:rtl!important;
  width:min(1180px,calc(100% - 36px))!important;
  max-width:1180px!important;
  margin:0 auto 24px!important;
  box-sizing:border-box!important;
  font-family:inherit!important;
}
#${ROOT} *{box-sizing:border-box!important}
#${ROOT} .v49-shell{
  position:relative!important;
  overflow:hidden!important;
  padding:22px!important;
  border:1px solid #eee1d8!important;
  border-radius:26px!important;
  background:
    radial-gradient(circle at 7% 0%,rgba(255,122,24,.10),transparent 24%),
    radial-gradient(circle at 93% 8%,rgba(239,68,68,.065),transparent 24%),
    linear-gradient(180deg,#fffdfb 0%,#fff 100%)!important;
  box-shadow:0 14px 34px rgba(38,25,18,.05)!important;
}
#${ROOT} .v49-head{
  display:flex!important;
  align-items:flex-end!important;
  justify-content:space-between!important;
  gap:16px!important;
  margin-bottom:15px!important;
}
#${ROOT} .v49-kicker{
  display:inline-flex!important;
  margin-bottom:7px!important;
  padding:6px 10px!important;
  border-radius:999px!important;
  background:#fff1e8!important;
  color:#b84a18!important;
  font-size:10.5px!important;
  font-weight:950!important;
}
#${ROOT} h2{
  margin:0!important;
  color:#211914!important;
  font-size:26px!important;
  line-height:1.35!important;
  font-weight:950!important;
}
#${ROOT} .v49-sub{
  margin:7px 0 0!important;
  color:#77675f!important;
  font-size:12px!important;
  line-height:1.8!important;
}
#${ROOT} .v49-grid{
  display:grid!important;
  grid-template-columns:repeat(2,minmax(0,1fr))!important;
  gap:12px!important;
}
#${ROOT} .v49-card{
  position:relative!important;
  display:flex!important;
  min-height:152px!important;
  align-items:center!important;
  justify-content:space-between!important;
  gap:16px!important;
  padding:20px!important;
  overflow:hidden!important;
  text-decoration:none!important;
  border:1px solid #eadfd7!important;
  border-radius:20px!important;
  transition:border-color .16s ease,box-shadow .16s ease!important;
}
#${ROOT} .v49-card:hover{
  transform:none!important;
  border-color:#efc9b1!important;
  box-shadow:0 12px 26px rgba(35,24,18,.06)!important;
}
#${ROOT} .v49-card.winter{
  background:linear-gradient(135deg,#f7fbff 0%,#fff9f3 100%)!important;
}
#${ROOT} .v49-card.party{
  background:linear-gradient(135deg,#fff8fb 0%,#fffaf2 100%)!important;
}
#${ROOT} .v49-card-copy{position:relative!important;z-index:2!important;min-width:0!important}
#${ROOT} .v49-card small{
  display:block!important;
  margin-bottom:5px!important;
  color:#c65b28!important;
  font-size:10px!important;
  font-weight:950!important;
}
#${ROOT} .v49-card h3{
  margin:0 0 7px!important;
  color:#211914!important;
  font-size:20px!important;
  line-height:1.45!important;
  font-weight:950!important;
}
#${ROOT} .v49-card p{
  margin:0!important;
  max-width:470px!important;
  color:#77685f!important;
  font-size:11.5px!important;
  line-height:1.75!important;
}
#${ROOT} .v49-cta{
  display:inline-flex!important;
  margin-top:11px!important;
  color:#e85a25!important;
  font-size:11.5px!important;
  font-weight:950!important;
}
#${ROOT} .v49-symbol{
  flex:0 0 82px!important;
  width:82px!important;
  height:82px!important;
  display:flex!important;
  align-items:center!important;
  justify-content:center!important;
  border-radius:22px!important;
  background:rgba(255,255,255,.82)!important;
  border:1px solid rgba(235,219,209,.9)!important;
  font-size:34px!important;
  box-shadow:0 10px 24px rgba(35,24,18,.04)!important;
}
#${ROOT} .v49-trust{
  display:grid!important;
  grid-template-columns:repeat(4,minmax(0,1fr))!important;
  gap:8px!important;
  margin-top:12px!important;
}
#${ROOT} .v49-trust span{
  display:flex!important;
  align-items:center!important;
  justify-content:center!important;
  min-height:42px!important;
  padding:9px 10px!important;
  border:1px solid #eee3dc!important;
  border-radius:12px!important;
  background:#fff!important;
  color:#5e5149!important;
  font-size:10.5px!important;
  font-weight:900!important;
  text-align:center!important;
}
@media(max-width:767px){
  #${ROOT}{width:calc(100% - 20px)!important;margin:0 10px 18px!important}
  #${ROOT} .v49-shell{padding:14px!important;border-radius:18px!important}
  #${ROOT} h2{font-size:21px!important}
  #${ROOT} .v49-grid{grid-template-columns:1fr!important;gap:9px!important}
  #${ROOT} .v49-card{min-height:132px!important;padding:15px!important;border-radius:16px!important}
  #${ROOT} .v49-card h3{font-size:17px!important}
  #${ROOT} .v49-symbol{flex-basis:60px!important;width:60px!important;height:60px!important;border-radius:17px!important;font-size:27px!important}
  #${ROOT} .v49-trust{grid-template-columns:repeat(2,minmax(0,1fr))!important}
}
@media(prefers-reduced-motion:reduce){#${ROOT} *{transition:none!important;animation:none!important}}
`;
  document.head.appendChild(s);
}

function mount(){
  style();
  var root=document.getElementById(ROOT);
  if(!root){
    root=document.createElement('section');
    root.id=ROOT;
    root.setAttribute('aria-label','موسم بارعة');
    root.innerHTML=`
      <div class="v49-shell">
        <div class="v49-head">
          <div>
            <span class="v49-kicker">موسم بارعة</span>
            <h2>أقسام تستحق الواجهة الآن</h2>
            <p class="v49-sub">مساران إضافيان يوسّعان تنوع الصفحة بدل تكرار نفس المنتجات والأقسام.</p>
          </div>
        </div>
        <div class="v49-grid">
          <a class="v49-card winter" href="https://barahstore.com/ar/search?q=${encodeURIComponent('شتاء')}">
            <div class="v49-card-copy">
              <small>موسم قريب</small>
              <h3>استعد للشتاء بدري</h3>
              <p>اختيارات الشتاء والدفء والاستخدام اليومي في مسار واحد سريع.</p>
              <span class="v49-cta">اكتشف مستلزمات الشتاء ←</span>
            </div>
            <span class="v49-symbol" aria-hidden="true">❄</span>
          </a>
          <a class="v49-card party" href="https://barahstore.com/ar/search?q=${encodeURIComponent('حفلات')}">
            <div class="v49-card-copy">
              <small>تفاصيل المناسبة</small>
              <h3>أشياء صغيرة… تكمل الحفلة</h3>
              <p>ادخل مباشرة إلى مستلزمات الحفلات والمناسبات بدل أن تضيع بين الأقسام.</p>
              <span class="v49-cta">اكتشف الحفلات والمناسبات ←</span>
            </div>
            <span class="v49-symbol" aria-hidden="true">✦</span>
          </a>
        </div>
        <div class="v49-trust" aria-label="مزايا متجر بارعة">
          <span>✓ متجر سلة موثّق</span>
          <span>🚚 شحن لجميع مناطق المملكة</span>
          <span>⌖ توصيل داخل الرياض</span>
          <span>💳 تابي وتمارا ووسائل دفع متعددة</span>
        </div>
      </div>`;
  }

  var storefront=document.getElementById('barah-step-smart-storefront-v44');
  var latest=document.querySelector('section.home-block.home-block--fixed-products.show-all.barah-v35-latest');
  if(storefront&&storefront.parentNode){
    if(storefront.nextElementSibling!==root)storefront.insertAdjacentElement('afterend',root);
    return true;
  }
  if(latest&&latest.parentNode){
    latest.parentNode.insertBefore(root,latest);
    return true;
  }
  return false;
}

if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',mount,{once:true});
else mount();
[220,700,1500].forEach(function(ms){setTimeout(mount,ms)});
})();

/* ============================================================
   BARAH STEP HOME GOLDEN V49 — LAUNCH ORCHESTRATOR
   النسخة النهائية للإطلاق:
   - ترتيب ثابت وواضح
   - إخفاء الطبقات القديمة المكررة
   - لا MutationObserver مستمر
   - تصحيحات تحميل محدودة فقط
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_STEP_HOME_GOLDEN_V49__)return;
window.__BARAH_STEP_HOME_GOLDEN_V49__=true;

var STYLE='barah-step-home-golden-v49-style';
var HIDDEN_IDS=[
  'barah-step-discovery-v15',
  'barah-step-personal-v18',
  'barah-step-gateway-v36',
  'barah-step-smart-showcase-v38',
  'barah-step-home-v9',
  'barah-step-interest-v46'
];

function isHome(){
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  if(/^\/(ar|en)?$/.test(p))return true;
  if(location.hostname==='salla.sa'&&/^\/br1$/.test(p))return true;
  return !!document.querySelector('main section.home-block,main .home-block--fixed-products');
}
if(!isHome())return;

function latest(){
  return document.querySelector('section.home-block.home-block--fixed-products.show-all.barah-v35-latest') ||
    Array.prototype.slice.call(document.querySelectorAll('section.home-block.home-block--fixed-products.show-all')).find(function(sec){
      var t=(sec.textContent||'').replace(/\s+/g,' ').trim();
      return t.indexOf('وصل حديث')!==-1||t.indexOf('أحدث المنتجات')!==-1||t.indexOf('اكتشفها أولاً')!==-1;
    }) || null;
}

function addStyle(){
  if(document.getElementById(STYLE))return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
${HIDDEN_IDS.map(function(id){return '#'+id}).join(',\n')}{display:none!important}
html{overflow-x:hidden!important}
body{background:#fbfaf9!important}
main{overflow:visible!important;padding-top:6px!important}
#barah-step-hero-v12,
#barah-step-shipping-v24,
#barah-step-smart-storefront-v44,
#barah-step-season-v49,
section.home-block.home-block--fixed-products.show-all.barah-v35-latest,
#barah-step-most-viewed,
#barah-step-special-suggestion-v48,
#barah-step-catalog-v32,
#barah-step-wholesale-v32{
  width:min(1180px,calc(100% - 36px))!important;
  max-width:1180px!important;
  margin-left:auto!important;
  margin-right:auto!important;
  box-sizing:border-box!important;
}
#barah-step-hero-v12{margin-top:12px!important;margin-bottom:9px!important}
#barah-step-shipping-v24{margin-top:0!important;margin-bottom:20px!important}
#barah-step-smart-storefront-v44,
#barah-step-season-v49,
section.home-block.home-block--fixed-products.show-all.barah-v35-latest,
#barah-step-most-viewed,
#barah-step-special-suggestion-v48{margin-top:0!important;margin-bottom:22px!important}
#barah-step-catalog-v32{margin-top:0!important;margin-bottom:12px!important}
#barah-step-wholesale-v32{margin-top:0!important;margin-bottom:24px!important}

/* Hero */
#barah-step-hero-v12 .barah-hero-shell{
  border-radius:26px!important;
  border-color:#eee1d8!important;
  background:radial-gradient(circle at 10% 12%,rgba(255,122,24,.11),transparent 30%),radial-gradient(circle at 90% 12%,rgba(239,68,68,.065),transparent 26%),linear-gradient(180deg,#fffdfb,#fff8f3)!important;
  box-shadow:0 16px 38px rgba(38,25,18,.055)!important;
}
#barah-step-shipping-v24 .barah-v24-shell{border-radius:16px!important;box-shadow:none!important}

/* Main discovery */
#barah-step-smart-storefront-v44 .v44-shell{border-radius:26px!important;box-shadow:0 14px 34px rgba(38,25,18,.05)!important}
#barah-step-smart-storefront-v44 .v44-mission,
#barah-step-smart-storefront-v44 .v44-feature,
#barah-step-smart-storefront-v44 .v44-cat{transition:border-color .16s ease,box-shadow .16s ease!important}
#barah-step-smart-storefront-v44 .v44-mission:hover,
#barah-step-smart-storefront-v44 .v44-feature:hover{transform:none!important;border-color:#efcfbc!important;box-shadow:0 11px 23px rgba(34,24,18,.06)!important}

/* Latest products */
section.home-block.home-block--fixed-products.show-all.barah-v35-latest{
  padding:20px!important;
  border:1px solid #eee1d8!important;
  border-radius:24px!important;
  background:#fff!important;
  box-shadow:0 14px 34px rgba(38,25,18,.05)!important;
}
section.barah-v35-latest .barah-v35-latest-head{margin-bottom:15px!important;padding-bottom:13px!important;border-bottom:1px solid #f1e8e2!important}
section.barah-v35-latest custom-salla-product-card.product-block{border-radius:17px!important;box-shadow:0 7px 18px rgba(35,24,18,.04)!important;transition:border-color .16s ease,box-shadow .16s ease!important}
section.barah-v35-latest custom-salla-product-card.product-block:hover{transform:none!important;filter:none!important;border-color:#efcfbc!important;box-shadow:0 10px 22px rgba(35,24,18,.06)!important}

/* Most viewed + special recommendation: visually related pair */
#barah-step-most-viewed,
#barah-step-special-suggestion-v48{
  border-radius:24px!important;
  border-color:#eee1d8!important;
  background:linear-gradient(180deg,#fff,#fffcfa)!important;
  box-shadow:0 12px 30px rgba(38,25,18,.045)!important;
}
#barah-step-special-suggestion-v48{border-style:solid!important}

/* End CTAs */
#barah-step-catalog-v32 .v32box{border-radius:18px!important;background:linear-gradient(135deg,#fffaf6,#fff)!important;box-shadow:none!important}
#barah-step-wholesale-v32 .v32box{border-radius:20px!important;background:radial-gradient(circle at 8% 18%,rgba(255,122,24,.08),transparent 28%),linear-gradient(135deg,#fff8f2,#fff)!important;box-shadow:0 10px 24px rgba(35,24,18,.035)!important}

/* Keep images stable: no zoom/color flash */
#barah-step-hero-v12 img,
#barah-step-smart-storefront-v44 img,
section.barah-v35-latest img,
#barah-step-most-viewed img,
#barah-step-special-suggestion-v48 img{
  opacity:1!important;filter:none!important;transform:none!important;mix-blend-mode:normal!important;transition:none!important
}

@media(max-width:767px){
  #barah-step-hero-v12,
  #barah-step-shipping-v24,
  #barah-step-smart-storefront-v44,
  #barah-step-season-v49,
  section.home-block.home-block--fixed-products.show-all.barah-v35-latest,
  #barah-step-most-viewed,
  #barah-step-special-suggestion-v48,
  #barah-step-catalog-v32,
  #barah-step-wholesale-v32{
    width:calc(100% - 20px)!important;margin-left:10px!important;margin-right:10px!important
  }
  #barah-step-hero-v12 .barah-hero-shell{padding:15px!important;border-radius:18px!important}
  #barah-step-hero-v12 h1{font-size:25px!important}
  #barah-step-smart-storefront-v44 .v44-title{font-size:24px!important}
  section.home-block.home-block--fixed-products.show-all.barah-v35-latest{padding:13px 11px!important;border-radius:18px!important}
  section.barah-v35-latest custom-salla-product-card.product-block{flex-basis:68%!important;max-width:245px!important}
  #barah-step-most-viewed,#barah-step-special-suggestion-v48{border-radius:18px!important}
}
@media(prefers-reduced-motion:reduce){
  #barah-step-hero-v12 *,#barah-step-smart-storefront-v44 *,#barah-step-season-v49 *,section.barah-v35-latest *,#barah-step-most-viewed *,#barah-step-special-suggestion-v48 *{transition:none!important;animation:none!important}
}
`;
  document.head.appendChild(s);
}

function placeAfter(anchor,node){
  if(!anchor||!node||!anchor.parentNode)return anchor;
  if(anchor.nextElementSibling!==node)anchor.insertAdjacentElement('afterend',node);
  return node;
}

function arrange(){
  addStyle();
  HIDDEN_IDS.forEach(function(id){var el=document.getElementById(id);if(el)el.setAttribute('data-barah-v49-retired','1')});

  var hero=document.getElementById('barah-step-hero-v12');
  if(!hero||!hero.parentNode)return false;
  var cursor=hero;
  cursor=placeAfter(cursor,document.getElementById('barah-step-shipping-v24'));
  cursor=placeAfter(cursor,document.getElementById('barah-step-smart-storefront-v44'));
  cursor=placeAfter(cursor,document.getElementById('barah-step-season-v49'));
  cursor=placeAfter(cursor,latest());
  cursor=placeAfter(cursor,document.getElementById('barah-step-most-viewed'));
  cursor=placeAfter(cursor,document.getElementById('barah-step-special-suggestion-v48'));
  cursor=placeAfter(cursor,document.getElementById('barah-step-catalog-v32'));
  cursor=placeAfter(cursor,document.getElementById('barah-step-wholesale-v32'));
  document.documentElement.setAttribute('data-barah-v49','ready');
  return true;
}

if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',arrange,{once:true});
else arrange();
/* Bounded hydration corrections only — no observer loop */
[180,520,1000,1800,3000].forEach(function(ms){setTimeout(arrange,ms)});
})();

/* ============================================================
   BARAH STEP HOME GOLDEN V48 — SPECIAL SUGGESTION
   اقتراح خاص = منتجات من الأكثر مشاهدة غير ظاهرة في الرئيسية
   نفس شكل وحجم قسم "يشاهدها العملاء الآن"
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_STEP_SPECIAL_SUGGESTION_V48__)return;
window.__BARAH_STEP_SPECIAL_SUGGESTION_V48__=true;

var ROOT='barah-step-special-suggestion-v48';
var STYLE=ROOT+'-style';
var SOURCE_URL='https://barah-popular-products.hussho.chatgpt.site/popular.json';
var MAX_ITEMS=4;

function isHome(){
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  if(/\/p\d+(?:\/|$)/.test(p))return false;
  if(/^\/(ar|en)?$/.test(p))return true;
  if(location.hostname==='salla.sa'&&/^\/br1$/.test(p))return true;
  return !!document.querySelector('main section.home-block,main #barah-step-hero-v12');
}
if(!isHome())return;

function productId(url){
  var s=String(url||'');
  var m=s.match(/(?:\/p|product-)(\d{5,})/i);
  if(m&&m[1])return m[1];
  m=s.match(/\/(\d{7,})(?:[/?#]|$)/);
  return m&&m[1]?m[1]:'';
}

function itemFromCard(card){
  if(!card)return null;
  var link=card.querySelector('.barah-step-most-viewed__product[href],a[href]');
  var img=card.querySelector('img');
  var name=card.querySelector('h3');
  var url=link?(link.href||link.getAttribute('href')):'';
  var id=productId(url);
  if(!id||!url||!img||!name)return null;
  return {
    id:id,
    name:(name.textContent||'').replace(/\s+/g,' ').trim(),
    url:url,
    image:img.currentSrc||img.src||img.getAttribute('src')||''
  };
}

function visible(el){
  if(!el)return false;
  if(el.hidden)return false;
  if(el.getAttribute('aria-hidden')==='true')return false;
  if(el.hasAttribute('data-barah-v41-hidden'))return false;
  if(el.hasAttribute('data-barah-v38-hidden'))return false;
  if(el.hasAttribute('data-barah-v38-duplicate'))return false;
  var s=window.getComputedStyle?getComputedStyle(el):null;
  if(s&&(s.display==='none'||s.visibility==='hidden'||Number(s.opacity)===0))return false;
  return true;
}

function sectionVisible(el){
  var node=el;
  while(node&&node!==document.body){
    if(node.nodeType===1){
      if(node.hasAttribute('data-barah-v47-retired'))return false;
      var s=window.getComputedStyle?getComputedStyle(node):null;
      if(s&&(s.display==='none'||s.visibility==='hidden'))return false;
    }
    node=node.parentElement;
  }
  return true;
}

/* المنتجات الظاهرة فعلًا في الرئيسية باستثناء مصدر الأكثر مشاهدة نفسه */
function usedIds(){
  var out={};
  var main=document.querySelector('main')||document.body;
  Array.prototype.slice.call(main.querySelectorAll('a[href]')).forEach(function(a){
    if(a.closest('#'+ROOT))return;
    if(a.closest('#barah-step-most-viewed'))return;
    if(!sectionVisible(a))return;
    var id=productId(a.href||a.getAttribute('href'));
    if(id)out[id]=1;
  });

  /* استبعد أيضًا المنتجات الظاهرة حاليًا داخل الأكثر مشاهدة */
  var most=document.getElementById('barah-step-most-viewed');
  if(most){
    Array.prototype.slice.call(most.querySelectorAll('.barah-step-most-viewed__card')).forEach(function(card){
      if(!visible(card)||!sectionVisible(card))return;
      var item=itemFromCard(card);
      if(item)out[item.id]=1;
    });
  }
  return out;
}

function ensureStyle(){
  if(document.getElementById(STYLE))return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
#${ROOT}{
  direction:rtl;
  width:min(1180px,calc(100% - 36px))!important;
  max-width:1180px!important;
  margin:0 auto 24px!important;
  padding:18px!important;
  min-height:0;
  background:linear-gradient(180deg,#fff,#fffcfa)!important;
  border:1px solid #eee1d8!important;
  border-radius:24px!important;
  box-shadow:0 14px 34px rgba(38,25,18,.055)!important;
  box-sizing:border-box!important;
  font-family:inherit!important
}
#${ROOT} *{box-sizing:border-box!important}
#${ROOT} .barah-step-most-viewed__head{
  display:flex;align-items:flex-end;justify-content:space-between;gap:12px;margin-bottom:14px
}
#${ROOT} h2{
  margin:0 0 3px;font-size:20px;line-height:1.4;font-weight:900;color:#7c2d12
}
#${ROOT} .barah-step-most-viewed__head p{
  margin:0;font-size:13px;color:#72584b
}
#${ROOT} .barah-step-most-viewed__track{
  display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:14px!important;overflow:visible;padding:2px 2px 4px
}
#${ROOT} .barah-step-most-viewed__card{
  min-width:0;display:grid;grid-template-columns:100px minmax(0,1fr)!important;
  grid-template-rows:auto auto;gap:10px 12px!important;align-items:center;background:#fff;
  border:1px solid #eee5df!important;border-radius:16px!important;padding:12px!important;
  box-shadow:0 9px 20px rgba(31,24,19,.035)!important
}
#${ROOT} a{text-decoration:none!important}
#${ROOT} .barah-step-most-viewed__product{display:contents!important}
#${ROOT} .barah-step-most-viewed__product img{
  grid-column:1;grid-row:1 / span 2;display:block;width:100px!important;height:100px!important;
  object-fit:contain;background:#fff;border-radius:12px!important;opacity:1!important;filter:none!important;
  transform:none!important;transition:none!important;mix-blend-mode:normal!important
}
#${ROOT} .barah-step-most-viewed__product h3{
  grid-column:2;grid-row:1;margin:0;min-height:0;max-height:42px;overflow:hidden;
  color:#29211d;font-size:13px;font-weight:800;line-height:1.6
}
#${ROOT} .barah-step-most-viewed__cta{
  grid-column:2;grid-row:2;display:inline-block;width:max-content;max-width:100%;margin:0;
  padding:8px 10px;border-radius:9px;text-align:center;font-size:12px;font-weight:900;color:#fff;
  background:linear-gradient(135deg,#ff7a18 0%,#ef4444 100%)
}
#${ROOT} a:focus-visible{outline:3px solid #9a3412;outline-offset:3px}
@media(max-width:1100px){
  #${ROOT} .barah-step-most-viewed__track{grid-template-columns:repeat(2,minmax(0,1fr))}
}
@media(max-width:767px){
  #${ROOT}{width:calc(100% - 20px)!important;margin:0 10px 18px!important;padding:14px 12px!important;border-radius:18px!important}
  #${ROOT} h2{font-size:19px}
  #${ROOT} .barah-step-most-viewed__track{display:grid;grid-template-columns:1fr;gap:9px!important;overflow:visible;padding:2px 0}
  #${ROOT} .barah-step-most-viewed__card{grid-template-columns:86px minmax(0,1fr)!important}
  #${ROOT} .barah-step-most-viewed__product img{width:86px!important;height:86px!important}
}
@media(prefers-reduced-motion:reduce){#${ROOT} *{animation:none!important;transition:none!important}}
`;
  document.head.appendChild(s);
}

function createCard(item){
  var card=document.createElement('article');
  card.className='barah-step-most-viewed__card';
  card.setAttribute('role','listitem');
  card.setAttribute('data-barah-special-id',String(item.id||''));

  var productLink=document.createElement('a');
  productLink.className='barah-step-most-viewed__product';
  productLink.href=item.url;
  productLink.setAttribute('aria-label',item.name||'عرض المنتج');

  var img=document.createElement('img');
  img.src=item.image;
  img.alt=item.name||'';
  img.loading='lazy';
  img.decoding='async';
  img.width=220;
  img.height=220;

  var name=document.createElement('h3');
  name.textContent=item.name||'منتج مقترح';

  var cta=document.createElement('a');
  cta.className='barah-step-most-viewed__cta';
  cta.href=item.url;
  cta.textContent='عرض وشراء ←';

  function track(){
    try{
      if(typeof window.gtag==='function'){
        window.gtag('event','select_item',{
          item_list_id:'barah_special_suggestion',
          item_list_name:'اقتراح خاص',
          items:[{item_id:String(item.id||''),item_name:item.name||''}]
        });
      }
    }catch(e){}
  }
  productLink.addEventListener('click',track);
  cta.addEventListener('click',track);

  productLink.appendChild(img);
  productLink.appendChild(name);
  card.appendChild(productLink);
  card.appendChild(cta);
  return card;
}

function getLocalCandidates(excluded){
  var out=[],seen={};
  var most=document.getElementById('barah-step-most-viewed');
  if(!most)return out;
  Array.prototype.slice.call(most.querySelectorAll('.barah-step-most-viewed__card')).forEach(function(card){
    var item=itemFromCard(card);
    if(!item||!item.id||excluded[item.id]||seen[item.id])return;
    seen[item.id]=1;
    out.push(item);
  });
  return out;
}

function normalizeRemote(data){
  var arr=data&&Array.isArray(data.items)?data.items:[];
  return arr.map(function(x){
    var url=x&&x.url?String(x.url):'';
    var id=x&&x.id?String(x.id):productId(url);
    return {
      id:id,
      name:x&&x.name?String(x.name):'',
      url:url,
      image:x&&x.image?String(x.image):''
    };
  }).filter(function(x){return x.id&&x.name&&x.url&&x.image;});
}

function render(items){
  var most=document.getElementById('barah-step-most-viewed');
  if(!most||!most.parentNode)return false;

  var root=document.getElementById(ROOT);
  if(!items||!items.length){
    if(root)root.remove();
    return false;
  }

  ensureStyle();
  if(!root){
    root=document.createElement('section');
    root.id=ROOT;
    root.className='barah-step-most-viewed barah-step-special-suggestion';
    root.setAttribute('aria-label','اقتراح خاص');
  }

  root.innerHTML='';
  var head=document.createElement('div');
  head.className='barah-step-most-viewed__head';
  var wrap=document.createElement('div');
  var h=document.createElement('h2');
  h.textContent='اقتراح خاص لك ✨';
  var p=document.createElement('p');
  p.textContent='من المنتجات الأكثر مشاهدة التي لم تظهر لك في الصفحة الرئيسية';
  wrap.appendChild(h);wrap.appendChild(p);head.appendChild(wrap);

  var track=document.createElement('div');
  track.className='barah-step-most-viewed__track';
  track.setAttribute('role','list');
  items.slice(0,MAX_ITEMS).forEach(function(item){track.appendChild(createCard(item));});

  root.appendChild(head);root.appendChild(track);
  if(most.nextElementSibling!==root)most.insertAdjacentElement('afterend',root);

  /* الكتالوج يجب أن يأتي بعد اقتراح خاص لا قبله */
  var catalog=document.getElementById('barah-step-catalog-v32');
  if(catalog&&root.nextElementSibling!==catalog)root.insertAdjacentElement('afterend',catalog);
  var wholesale=document.getElementById('barah-step-wholesale-v32');
  if(wholesale&&catalog&&catalog.nextElementSibling!==wholesale)catalog.insertAdjacentElement('afterend',wholesale);

  return true;
}

var remoteItems=[];
var fetching=false;
function refresh(){
  var most=document.getElementById('barah-step-most-viewed');
  if(!most)return false;

  var excluded=usedIds();
  var result=[],seen={};

  function take(item){
    if(!item||!item.id||excluded[item.id]||seen[item.id])return;
    seen[item.id]=1;
    result.push(item);
  }

  getLocalCandidates(excluded).forEach(take);
  remoteItems.forEach(take);
  render(result.slice(0,MAX_ITEMS));
  return result.length>0;
}

function fetchRemote(){
  if(fetching||!SOURCE_URL||!window.__BARAH_CAN_REMOTE_POPULAR__)return;
  fetching=true;
  try{
    var controller=new AbortController();
    var timeout=setTimeout(function(){controller.abort();},3500);
    var url=new URL(SOURCE_URL);
    url.searchParams.set('barah_refresh',String(Math.floor(Date.now()/300000)));
    fetch(url.toString(),{cache:'no-store',signal:controller.signal})
      .then(function(r){if(!r.ok)throw new Error('HTTP '+r.status);return r.json();})
      .then(function(data){
        clearTimeout(timeout);
        remoteItems=normalizeRemote(data);
        refresh();
      })
      .catch(function(){clearTimeout(timeout);})
      .finally(function(){fetching=false;});
  }catch(e){fetching=false;}
}

function run(){
  ensureStyle();
  refresh();
  fetchRemote();
}

/* V48.1 STABLE: no MutationObserver, no continuous DOM polling */
function stableStart(){
  ensureStyle();
  refresh();
  fetchRemote();
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',stableStart,{once:true});
}else{
  stableStart();
}

/* Two bounded hydration corrections only, then stop completely */
setTimeout(refresh,700);
setTimeout(refresh,1800);
})();

/* ============================================================
   BARAH STEP HOME GOLDEN V50 — CONVERSION CTA LAYER
   هدفها: وضوح النية + CTA أقوى + نص إضافة للسلة واضح
   مبنية على مراجعة الطلبات والسلال المتروكة الحالية.
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V50_CONVERSION__)return;
window.__BARAH_V50_CONVERSION__=true;

var STYLE='barah-v50-conversion-style';

function isHome(){
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  return /^\/(ar|en)?$/.test(p) || (location.hostname==='salla.sa'&&/^\/br1$/.test(p)) || !!document.querySelector('main');
}
if(!isHome())return;

function addStyle(){
  if(document.getElementById(STYLE))return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
/* CTA المنتج: واضح، مريح، بدون مبالغة */
#barah-step-most-viewed .barah-step-most-viewed__cta,
#barah-step-special-suggestion-v48 .barah-step-most-viewed__cta,
#barah-step-home-v9 .barah-v9-buy{
  min-height:42px!important;
  display:flex!important;
  align-items:center!important;
  justify-content:center!important;
  width:100%!important;
  max-width:none!important;
  padding:10px 13px!important;
  border-radius:11px!important;
  border:0!important;
  background:linear-gradient(135deg,#ff7a18 0%,#ef4444 100%)!important;
  color:#fff!important;
  font-size:12px!important;
  font-weight:950!important;
  line-height:1.2!important;
  letter-spacing:0!important;
  box-shadow:0 8px 18px rgba(239,68,68,.15)!important;
  text-decoration:none!important;
  transition:box-shadow .16s ease,transform .16s ease!important;
}
@media(hover:hover){
  #barah-step-most-viewed .barah-step-most-viewed__cta:hover,
  #barah-step-special-suggestion-v48 .barah-step-most-viewed__cta:hover,
  #barah-step-home-v9 .barah-v9-buy:hover{
    transform:translateY(-1px)!important;
    box-shadow:0 11px 22px rgba(239,68,68,.19)!important;
  }
}

/* رفوف سلة الأصلية: تحويل زر الأيقونة إلى CTA مقروء */
section.barah-v35-latest custom-salla-product-card.product-block button,
section.barah-v35-latest custom-salla-product-card.product-block .btn--add-to-cart,
section.barah-v35-latest custom-salla-product-card.product-block [class*="add-to-cart"]{
  min-height:43px!important;
  border-radius:11px!important;
  font-weight:950!important;
  font-size:12px!important;
  background:linear-gradient(135deg,#ff7a18 0%,#ef4444 100%)!important;
  color:#fff!important;
  border:0!important;
  box-shadow:0 7px 16px rgba(239,68,68,.13)!important;
}
section.barah-v35-latest .barah-atc-label{
  display:inline-block!important;
  margin-inline-start:6px!important;
  color:#fff!important;
  font-size:12px!important;
  font-weight:950!important;
  white-space:nowrap!important;
}

/* تحسين زر عرض كل المنتجات: ثانوي حتى لا ينافس شراء المنتج */
section.barah-v35-latest .barah-v35-all,
#barah-step-catalog-v32 .v32actions a:not(:first-child){
  box-shadow:none!important;
  background:#fff!important;
  color:#4b3d35!important;
  border:1px solid #e8ddd5!important;
}

/* إضافة إشارة ثقة هادئة أسفل رأس الأكثر مشاهدة والاقتراح الخاص */
.barah-v50-trustline{
  display:flex;
  flex-wrap:wrap;
  gap:6px;
  margin-top:8px;
}
.barah-v50-trustline span{
  display:inline-flex;
  align-items:center;
  min-height:26px;
  padding:4px 8px;
  border-radius:999px;
  border:1px solid #eee3db;
  background:#fffaf6;
  color:#66584f;
  font-size:10px;
  font-weight:800;
}

@media(max-width:767px){
  #barah-step-most-viewed .barah-step-most-viewed__cta,
  #barah-step-special-suggestion-v48 .barah-step-most-viewed__cta{
    min-height:40px!important;
    padding:9px 11px!important;
    font-size:11px!important;
  }
  section.barah-v35-latest custom-salla-product-card.product-block button,
  section.barah-v35-latest custom-salla-product-card.product-block .btn--add-to-cart,
  section.barah-v35-latest custom-salla-product-card.product-block [class*="add-to-cart"]{
    min-height:42px!important;
  }
}
@media(prefers-reduced-motion:reduce){
  #barah-step-most-viewed .barah-step-most-viewed__cta,
  #barah-step-special-suggestion-v48 .barah-step-most-viewed__cta,
  #barah-step-home-v9 .barah-v9-buy{transition:none!important;transform:none!important}
}
`;
  document.head.appendChild(s);
}

function normalizeProductCTAs(){
  document.querySelectorAll(
    '#barah-step-most-viewed .barah-step-most-viewed__cta,'+
    '#barah-step-special-suggestion-v48 .barah-step-most-viewed__cta,'+
    '#barah-step-home-v9 .barah-v9-buy'
  ).forEach(function(a){
    if(!a)return;
    a.textContent='شاهد المنتج ←';
    a.setAttribute('aria-label','شاهد تفاصيل المنتج');
  });
}

function labelNativeAddToCart(){
  var cards=document.querySelectorAll('section.barah-v35-latest custom-salla-product-card.product-block');
  cards.forEach(function(card){
    var buttons=card.querySelectorAll('button,.btn--add-to-cart,[class*="add-to-cart"]');
    buttons.forEach(function(btn){
      if(!btn || btn.querySelector('.barah-atc-label'))return;
      var txt=(btn.textContent||'').replace(/\s+/g,' ').trim();
      /* لا نغير أزرار الخيارات أو التنبيهات ذات النص الواضح */
      if(txt && txt.length>3 && !/^(إضافة|أضف|شراء|السلة|add)/i.test(txt))return;
      var sp=document.createElement('span');
      sp.className='barah-atc-label';
      sp.textContent='أضف للسلة';
      btn.appendChild(sp);
      btn.setAttribute('aria-label','أضف المنتج للسلة');
    });
  });
}

function addTrustLine(root){
  if(!root || root.querySelector('.barah-v50-trustline'))return;
  var head=root.querySelector('.barah-step-most-viewed__head');
  if(!head)return;
  var wrap=head.firstElementChild || head;
  var line=document.createElement('div');
  line.className='barah-v50-trustline';
  line.innerHTML='<span>🚚 شحن داخل المملكة</span><span>💳 دفع مرن</span><span>🔒 دفع آمن</span>';
  wrap.appendChild(line);
}

function run(){
  addStyle();
  normalizeProductCTAs();
  labelNativeAddToCart();
  addTrustLine(document.getElementById('barah-step-most-viewed'));
  addTrustLine(document.getElementById('barah-step-special-suggestion-v48'));
}

if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',run,{once:true});
else run();
/* تصحيحات محدودة فقط بعد hydration — بدون observer مستمر */
/* V66.6: late remount timers removed */
})();


/* ============================================================
   BARAH V51 — IDENTITY + NEEDS-BASED CONVERSION SECTION
   تركيز على الهوية البصرية + التسوق حسب الهدف
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V51_NEEDS_SECTION__) return;
window.__BARAH_V51_NEEDS_SECTION__ = true;

var ROOT='barah-step-needs-v51';
var STYLE=ROOT+'-style';

function isHome(){
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  return /^\/(ar|en)?$/.test(p) || !!document.querySelector('main');
}
if(!isHome()) return;

var CARDS=[
  {
    icon:'🤰',
    tone:'soft',
    title:'للحوامل',
    desc:'اختيارات مريحة تساعد على الاستخدام اليومي والوصول الأسرع لما قد تحتاجينه خلال هذه المرحلة.',
    tags:['راحة يومية','اكتشاف سريع'],
    q:'Pregnancy'
  },
  {
    icon:'🧓',
    tone:'calm',
    title:'لكبار السن',
    desc:'مستلزمات عملية للدعم والراحة وسهولة الاستخدام داخل المنزل وأثناء الحركة.',
    tags:['دعم وراحة','استخدام أسهل'],
    q:'دعامة'
  },
  {
    icon:'🏃',
    tone:'sport',
    title:'للرياضيين',
    desc:'تجهيزات منزلية للتمارين والحركة تساعد على الاستمرار وبناء روتين يومي أبسط.',
    tags:['رياضة منزلية','أدوات عملية'],
    q:'رياضة'
  },
  {
    icon:'🔥',
    tone:'hot',
    title:'للتعرق وشد القوام',
    desc:'مشدات وأحزمة حرارية وخيارات داعمة للمشي والتمارين مع وصول مباشر للأصناف الأقرب للفكرة.',
    tags:['مشدات','حزام حراري'],
    q:'مشد حراري'
  },
  {
    icon:'🦴',
    tone:'calm',
    title:'لدعم الظهر والمفاصل',
    desc:'حلول مساعدة للرقبة والظهر والمفاصل لراحة أفضل واستخدام أقرب للحاجة.',
    tags:['الظهر','الرقبة'],
    q:'ظهر'
  },
  {
    icon:'🏠',
    tone:'soft',
    title:'لراحة البيت والتنظيم',
    desc:'أفكار يومية ذكية تجعل البيت أهدأ وتنظيمه أسهل من أول نظرة.',
    tags:['تنظيم','مطبخ ومنزل'],
    q:'تنظيم'
  }
];

var HOT=[
  {t:'رياضة منزلية',q:'رياضة منزلية'},
  {t:'مشدات وتعرق',q:'مشد'},
  {t:'تنظيم المنزل',q:'تنظيم'},
  {t:'العناية اليومية',q:'عناية'}
];

function urlForQuery(q){
  return 'https://barahstore.com/ar/search?q='+encodeURIComponent(q);
}

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
#${ROOT}{
  direction:rtl!important;
  width:min(1240px,calc(100% - 32px))!important;
  max-width:1240px!important;
  margin:0 auto 22px!important;
  font-family:inherit!important;
}
#${ROOT} *{box-sizing:border-box!important}
#${ROOT} .barah-v51-shell{
  position:relative!important;
  overflow:hidden!important;
  border:1px solid #eaded5!important;
  border-radius:24px!important;
  background:
    radial-gradient(circle at 8% 12%,rgba(255,122,24,.10),transparent 26%),
    radial-gradient(circle at 92% 16%,rgba(239,68,68,.06),transparent 24%),
    linear-gradient(180deg,#fffdfb 0%,#fff8f3 100%)!important;
  box-shadow:0 16px 36px rgba(35,24,18,.05)!important;
  padding:22px!important;
}
#${ROOT} .barah-v51-head{
  display:grid!important;
  grid-template-columns:minmax(0,1.1fr) minmax(250px,.9fr)!important;
  gap:16px!important;
  align-items:end!important;
  margin-bottom:18px!important;
}
#${ROOT} .barah-v51-kicker{
  display:inline-flex!important;
  align-items:center!important;
  gap:8px!important;
  width:max-content!important;
  padding:8px 12px!important;
  border-radius:999px!important;
  background:#fff0e5!important;
  color:#b45309!important;
  font-size:12px!important;
  font-weight:900!important;
  margin-bottom:10px!important;
}
#${ROOT} h2{
  margin:0!important;
  color:#241b16!important;
  font-size:31px!important;
  line-height:1.3!important;
  font-weight:950!important;
}
#${ROOT} .barah-v51-sub{
  margin:8px 0 0!important;
  color:#7a695f!important;
  font-size:14px!important;
  line-height:1.95!important;
  max-width:760px!important;
}
#${ROOT} .barah-v51-insight{
  border:1px solid #efe3da!important;
  background:rgba(255,255,255,.78)!important;
  border-radius:18px!important;
  padding:14px 14px 12px!important;
}
#${ROOT} .barah-v51-insight strong{
  display:block!important;
  color:#2a211d!important;
  font-size:14px!important;
  font-weight:900!important;
  margin-bottom:8px!important;
}
#${ROOT} .barah-v51-insight p{
  margin:0!important;
  color:#786a61!important;
  font-size:12px!important;
  line-height:1.9!important;
}
#${ROOT} .barah-v51-hot{
  display:flex!important;
  flex-wrap:wrap!important;
  gap:8px!important;
  margin-top:12px!important;
}
#${ROOT} .barah-v51-hot a{
  text-decoration:none!important;
  display:inline-flex!important;
  align-items:center!important;
  justify-content:center!important;
  min-height:34px!important;
  padding:0 12px!important;
  border-radius:999px!important;
  background:#fff!important;
  border:1px solid #eaded5!important;
  color:#3d312a!important;
  font-size:12px!important;
  font-weight:900!important;
}
#${ROOT} .barah-v51-grid{
  display:grid!important;
  grid-template-columns:repeat(3,minmax(0,1fr))!important;
  gap:14px!important;
}
#${ROOT} .barah-v51-card{
  position:relative!important;
  border:1px solid #eee4dc!important;
  border-radius:20px!important;
  background:#fff!important;
  box-shadow:0 10px 22px rgba(35,24,18,.035)!important;
  padding:16px!important;
  min-height:212px!important;
  display:flex!important;
  flex-direction:column!important;
}
#${ROOT} .barah-v51-card::before{
  content:'';
  position:absolute!important;
  inset-inline-start:0!important;
  inset-block-start:0!important;
  width:100%!important;
  height:4px!important;
  border-radius:20px 20px 0 0!important;
  background:linear-gradient(90deg,#ff7a18,#ef4444)!important;
}
#${ROOT} .barah-v51-badge{
  width:48px!important;
  height:48px!important;
  border-radius:15px!important;
  display:flex!important;
  align-items:center!important;
  justify-content:center!important;
  font-size:24px!important;
  margin-bottom:12px!important;
  background:#fff4ec!important;
}
#${ROOT} .barah-v51-card[data-tone="sport"] .barah-v51-badge{background:#fff0e6!important}
#${ROOT} .barah-v51-card[data-tone="hot"] .barah-v51-badge{background:#ffece8!important}
#${ROOT} .barah-v51-card h3{
  margin:0 0 7px!important;
  color:#241c17!important;
  font-size:20px!important;
  line-height:1.4!important;
  font-weight:900!important;
}
#${ROOT} .barah-v51-card p{
  margin:0 0 12px!important;
  color:#786960!important;
  font-size:13px!important;
  line-height:1.9!important;
  min-height:72px!important;
}
#${ROOT} .barah-v51-tags{
  display:flex!important;
  flex-wrap:wrap!important;
  gap:7px!important;
  margin-bottom:13px!important;
}
#${ROOT} .barah-v51-tags span{
  display:inline-flex!important;
  align-items:center!important;
  min-height:28px!important;
  padding:0 10px!important;
  border-radius:999px!important;
  background:#f8f5f2!important;
  color:#6d5e55!important;
  font-size:11px!important;
  font-weight:800!important;
}
#${ROOT} .barah-v51-go{
  margin-top:auto!important;
  text-decoration:none!important;
  min-height:42px!important;
  display:flex!important;
  align-items:center!important;
  justify-content:center!important;
  gap:8px!important;
  border-radius:12px!important;
  color:#fff!important;
  font-size:13px!important;
  font-weight:900!important;
  background:linear-gradient(135deg,#ff7a18,#ef4444)!important;
  box-shadow:0 12px 24px rgba(239,68,68,.15)!important;
}
#${ROOT} .barah-v51-note{
  margin-top:14px!important;
  padding-top:14px!important;
  border-top:1px dashed #eadfd7!important;
  color:#7b6b61!important;
  font-size:12px!important;
  line-height:1.9!important;
}
/* identity polish around connected sections */
#barah-step-hero-v12 .barah-hero-shell,
#barah-step-home-v9 .barah-v9-shell,
#barah-step-most-viewed,
#barah-step-special-suggestion-v48,
#barah-step-catalog-v32 .v32box,
#barah-step-wholesale-v32 .v32box,
section.home-block.home-block--fixed-products.show-all.barah-v35-latest{
  border-color:#eadfd7!important;
  box-shadow:0 14px 30px rgba(35,24,18,.045)!important;
}
#barah-step-home-v9 .barah-v9-kicker,
section.barah-v35-latest .barah-v35-copy small{
  letter-spacing:.2px!important;
}
@media(max-width:1100px){
  #${ROOT} .barah-v51-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important}
  #${ROOT} .barah-v51-head{grid-template-columns:1fr!important}
}
@media(max-width:767px){
  #${ROOT}{
    width:calc(100% - 24px)!important;
    margin:0 12px 18px!important;
  }
  #${ROOT} .barah-v51-shell{
    padding:16px 14px!important;
    border-radius:20px!important;
  }
  #${ROOT} h2{font-size:24px!important}
  #${ROOT} .barah-v51-grid{grid-template-columns:1fr!important;gap:11px!important}
  #${ROOT} .barah-v51-card{min-height:auto!important;padding:14px!important;border-radius:18px!important}
  #${ROOT} .barah-v51-card p{min-height:0!important}
}
`;
  document.head.appendChild(s);
}

function build(){
  var section=document.createElement('section');
  section.id=ROOT;
  section.setAttribute('aria-label','تسوّق حسب احتياجك');
  var cards=[
    ['رياضة في البيت','https://barahstore.com/ar/fitness/c511828448','https://cdn.salla.sa/qwxGZ/515fab97-aab3-448a-8a7b-6b9287691cb0-500x500-EA6WdMUjzvNizNpEGrkn2zERP8MWbIpNct1GNX0K.webp'],
    ['تنظيم المنزل','https://barahstore.com/ar/home-kitchen/c127906256','https://cdn.salla.sa/qwxGZ/dbc9d5dd-0582-4f97-bac6-8c9ece063747-323.4894772573x500-inYOFj01wp7Ri6vXUT7FsSPL4lu9XhrIov1cEC14.jpg'],
    ['العناية اليومية','https://barahstore.com/ar/search?q='+encodeURIComponent('عناية'),'https://cdn.salla.sa/qwxGZ/4b49dd72-12c5-4455-a5f7-d0c942e60320-435.16597510373x500-dHYRsRNvNR5dTgfDBHyUEelffvXIEOeN9rIZpdVc.jpg'],
    ['للسيارة','https://barahstore.com/ar/car/c228633582','https://cdn.salla.sa/qwxGZ/699f9b0d-3277-4a0b-951e-34bf7435720a-500x500-8gdk8IfwVfqkW2aR4ELvw9vzOGcububLcjxskQur.png'],
    ['للأم والطفل','https://barahstore.com/ar/product-630210826/p630210826','https://cdn.salla.sa/qwxGZ/d42bb3c8-3255-4dea-a514-044eec312fcf-500x500-tr82vVN6HKoCGxpAtZIm96tvIF7dUurqL0yC2SFM.jpg'],
    ['الراحة والمساج','https://barahstore.com/ar/search?q='+encodeURIComponent('مساج'),'https://cdn.salla.sa/qwxGZ/86d24bce-2195-4637-8ee0-d400b5e1026b-488.4437596302x500-YuMFAmfGPeCJBgrTOUXiUxqPRFT0QxSbaPMApbxX.jpg']
  ];
  section.innerHTML='<div class="barah-v664-needs-shell"><div class="barah-v664-head"><h2>تسوّق حسب احتياجك</h2><p>اختر احتياجك ووصل للمنتج مباشرة</p></div><div class="barah-v664-needs-grid">'+cards.map(function(c){return '<a class="barah-v664-need" href="'+c[1]+'"><img src="'+c[2]+'" alt="'+c[0]+'" loading="lazy" decoding="async" width="96" height="96"><span><strong>'+c[0]+'</strong><small>استكشف ←</small></span></a>'}).join('')+'</div></div>';
  return section;
}

function findAnchor(){
  return document.getElementById('barah-step-discovery-v15') ||
         document.getElementById('barah-step-shipping-v24') ||
         document.getElementById('barah-step-home-v9') ||
         document.querySelector('section.home-block.home-block--fixed-products.show-all.barah-v35-latest');
}

function mount(){
  addStyle();
  var old=document.getElementById(ROOT);
  if(old) return true; // V66.6: preserve existing section, avoid flicker
  var anchor=findAnchor();
  var sec=build();
  var main=document.querySelector('main') || document.body;
  if(anchor && anchor.parentNode){
    anchor.insertAdjacentElement('afterend',sec);
  }else if(main){
    main.prepend(sec);
  }
  return true;
}

function run(){ mount(); }
if(document.readyState==='loading') document.addEventListener('DOMContentLoaded',run,{once:true});
else run();
setTimeout(run,500);
setTimeout(run,1400);
setTimeout(run,2800);
})();

/* ============================================================
   BARAH V51.1 — PRODUCT CARD FIT & PROPORTION FIX
   تصغير وضبط كروت المنتجات للصفحة الرئيسية
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V511_CARD_FIT__) return;
window.__BARAH_V511_CARD_FIT__=true;
var id='barah-v511-card-fit-style';
if(document.getElementById(id))return;
var s=document.createElement('style');
s.id=id;
s.textContent=`
/* رف وصل حديثًا: مقاس متوازن وأقل طولًا */
section.barah-v35-latest .grid-block.products-list-container.vertical-products{
  grid-template-columns:repeat(4,minmax(0,1fr))!important;
  gap:13px!important;
  align-items:start!important;
}
section.barah-v35-latest custom-salla-product-card.product-block{
  height:auto!important;
  min-height:0!important;
  align-self:start!important;
  border-radius:16px!important;
  box-shadow:0 6px 16px rgba(35,24,18,.035)!important;
}
/* مساحة الصورة */
section.barah-v35-latest custom-salla-product-card.product-block .product-block__thumb,
section.barah-v35-latest custom-salla-product-card.product-block .product-block__image,
section.barah-v35-latest custom-salla-product-card.product-block .product-image,
section.barah-v35-latest custom-salla-product-card.product-block [class*="thumb"]{
  min-height:0!important;
  height:190px!important;
  max-height:190px!important;
  overflow:hidden!important;
}
section.barah-v35-latest custom-salla-product-card.product-block img{
  display:block!important;
  width:100%!important;
  height:190px!important;
  max-height:190px!important;
  object-fit:contain!important;
  padding:7px!important;
}
/* العنوان: سطران بدل تمدد الكرت */
section.barah-v35-latest custom-salla-product-card.product-block .product-block__title,
section.barah-v35-latest custom-salla-product-card.product-block .product-title,
section.barah-v35-latest custom-salla-product-card.product-block h3,
section.barah-v35-latest custom-salla-product-card.product-block h4{
  display:-webkit-box!important;
  -webkit-box-orient:vertical!important;
  -webkit-line-clamp:2!important;
  line-clamp:2!important;
  overflow:hidden!important;
  min-height:38px!important;
  max-height:42px!important;
  line-height:1.55!important;
  font-size:12px!important;
  margin-bottom:5px!important;
}
/* تقليل الحشو الداخلي إن كان مكشوفًا */
section.barah-v35-latest custom-salla-product-card.product-block .product-block__info,
section.barah-v35-latest custom-salla-product-card.product-block .product-block__content,
section.barah-v35-latest custom-salla-product-card.product-block [class*="content"]{
  padding-top:8px!important;
  padding-bottom:9px!important;
}
/* CTA لا يأخذ مساحة زائدة */
section.barah-v35-latest custom-salla-product-card.product-block button,
section.barah-v35-latest custom-salla-product-card.product-block .btn--add-to-cart,
section.barah-v35-latest custom-salla-product-card.product-block [class*="add-to-cart"]{
  min-height:38px!important;
  height:38px!important;
  padding:7px 10px!important;
  border-radius:10px!important;
  font-size:11px!important;
}
section.barah-v35-latest .barah-atc-label{font-size:11px!important}

/* الأكثر مشاهدة + اقتراح خاص: أصغر قليلًا وأكثر إحكامًا */
#barah-step-most-viewed .barah-step-most-viewed__card,
#barah-step-special-suggestion-v48 .barah-step-most-viewed__card{
  grid-template-columns:88px minmax(0,1fr)!important;
  gap:8px 10px!important;
  padding:10px!important;
  min-height:108px!important;
  border-radius:14px!important;
}
#barah-step-most-viewed .barah-step-most-viewed__product img,
#barah-step-special-suggestion-v48 .barah-step-most-viewed__product img{
  width:88px!important;
  height:88px!important;
  padding:3px!important;
}
#barah-step-most-viewed .barah-step-most-viewed__product h3,
#barah-step-special-suggestion-v48 .barah-step-most-viewed__product h3{
  font-size:12px!important;
  line-height:1.5!important;
  max-height:37px!important;
}
#barah-step-most-viewed .barah-step-most-viewed__cta,
#barah-step-special-suggestion-v48 .barah-step-most-viewed__cta{
  min-height:34px!important;
  padding:7px 10px!important;
  font-size:11px!important;
  border-radius:9px!important;
}

@media(max-width:1100px) and (min-width:768px){
  section.barah-v35-latest .grid-block.products-list-container.vertical-products{
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
  }
  section.barah-v35-latest custom-salla-product-card.product-block img,
  section.barah-v35-latest custom-salla-product-card.product-block .product-block__thumb,
  section.barah-v35-latest custom-salla-product-card.product-block .product-block__image,
  section.barah-v35-latest custom-salla-product-card.product-block .product-image{
    height:175px!important;
    max-height:175px!important;
  }
}

@media(max-width:767px){
  section.barah-v35-latest .grid-block.products-list-container.vertical-products{
    gap:9px!important;
  }
  section.barah-v35-latest custom-salla-product-card.product-block{
    flex:0 0 61%!important;
    flex-basis:61%!important;
    width:61%!important;
    max-width:220px!important;
    border-radius:14px!important;
  }
  section.barah-v35-latest custom-salla-product-card.product-block img,
  section.barah-v35-latest custom-salla-product-card.product-block .product-block__thumb,
  section.barah-v35-latest custom-salla-product-card.product-block .product-block__image,
  section.barah-v35-latest custom-salla-product-card.product-block .product-image{
    height:150px!important;
    max-height:150px!important;
  }
  section.barah-v35-latest custom-salla-product-card.product-block .product-block__title,
  section.barah-v35-latest custom-salla-product-card.product-block .product-title,
  section.barah-v35-latest custom-salla-product-card.product-block h3,
  section.barah-v35-latest custom-salla-product-card.product-block h4{
    min-height:36px!important;
    max-height:38px!important;
    font-size:11px!important;
  }
  section.barah-v35-latest custom-salla-product-card.product-block button,
  section.barah-v35-latest custom-salla-product-card.product-block .btn--add-to-cart,
  section.barah-v35-latest custom-salla-product-card.product-block [class*="add-to-cart"]{
    min-height:36px!important;
    height:36px!important;
    font-size:10.5px!important;
  }
  #barah-step-most-viewed .barah-step-most-viewed__card,
  #barah-step-special-suggestion-v48 .barah-step-most-viewed__card{
    grid-template-columns:78px minmax(0,1fr)!important;
    min-height:96px!important;
    padding:9px!important;
  }
  #barah-step-most-viewed .barah-step-most-viewed__product img,
  #barah-step-special-suggestion-v48 .barah-step-most-viewed__product img{
    width:78px!important;
    height:78px!important;
  }
}
`;
document.head.appendChild(s);
})();


/* ============================================================
   BARAH V51.2 — LATEST PRODUCTS CARD SIZE ONLY
   ضبط كروت "وصل حديثًا" فقط — بدون التأثير على باقي الأقسام
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V512_LATEST_CARD_ONLY__) return;
window.__BARAH_V512_LATEST_CARD_ONLY__=true;
var id='barah-v512-latest-card-only-style';
if(document.getElementById(id))return;
var s=document.createElement('style');
s.id=id;
s.textContent=`
/* ===== وصل حديثًا فقط ===== */
section.barah-v35-latest .grid-block.products-list-container.vertical-products{
  display:grid!important;
  grid-template-columns:repeat(5,minmax(0,1fr))!important;
  gap:12px!important;
  align-items:start!important;
}
section.barah-v35-latest custom-salla-product-card.product-block{
  width:100%!important;
  min-width:0!important;
  height:auto!important;
  min-height:0!important;
  align-self:start!important;
  margin:0!important;
  border-radius:15px!important;
  overflow:hidden!important;
  box-shadow:0 6px 15px rgba(35,24,18,.035)!important;
}
/* صورة المنتج: أقصر وأكثر تناسبًا */
section.barah-v35-latest custom-salla-product-card.product-block .product-block__thumb,
section.barah-v35-latest custom-salla-product-card.product-block .product-block__image,
section.barah-v35-latest custom-salla-product-card.product-block .product-image,
section.barah-v35-latest custom-salla-product-card.product-block [class*="thumb"]{
  min-height:0!important;
  height:165px!important;
  max-height:165px!important;
  overflow:hidden!important;
}
section.barah-v35-latest custom-salla-product-card.product-block img{
  width:100%!important;
  height:165px!important;
  max-height:165px!important;
  object-fit:contain!important;
  padding:6px!important;
}
/* اسم المنتج: سطران فقط */
section.barah-v35-latest custom-salla-product-card.product-block .product-block__title,
section.barah-v35-latest custom-salla-product-card.product-block .product-title,
section.barah-v35-latest custom-salla-product-card.product-block h3,
section.barah-v35-latest custom-salla-product-card.product-block h4{
  display:-webkit-box!important;
  -webkit-box-orient:vertical!important;
  -webkit-line-clamp:2!important;
  line-clamp:2!important;
  overflow:hidden!important;
  min-height:36px!important;
  max-height:39px!important;
  line-height:1.5!important;
  font-size:11.5px!important;
  margin-bottom:5px!important;
}
section.barah-v35-latest custom-salla-product-card.product-block .product-block__info,
section.barah-v35-latest custom-salla-product-card.product-block .product-block__content,
section.barah-v35-latest custom-salla-product-card.product-block [class*="content"]{
  padding-top:7px!important;
  padding-bottom:8px!important;
}
/* زر الإضافة متوازن مع حجم الكرت */
section.barah-v35-latest custom-salla-product-card.product-block button,
section.barah-v35-latest custom-salla-product-card.product-block .btn--add-to-cart,
section.barah-v35-latest custom-salla-product-card.product-block [class*="add-to-cart"]{
  min-height:36px!important;
  height:36px!important;
  padding:6px 9px!important;
  border-radius:9px!important;
  font-size:10.5px!important;
}
section.barah-v35-latest .barah-atc-label{font-size:10.5px!important}

@media(max-width:1180px) and (min-width:901px){
  section.barah-v35-latest .grid-block.products-list-container.vertical-products{
    grid-template-columns:repeat(4,minmax(0,1fr))!important;
  }
  section.barah-v35-latest custom-salla-product-card.product-block img,
  section.barah-v35-latest custom-salla-product-card.product-block .product-block__thumb,
  section.barah-v35-latest custom-salla-product-card.product-block .product-block__image,
  section.barah-v35-latest custom-salla-product-card.product-block .product-image{
    height:170px!important;
    max-height:170px!important;
  }
}
@media(max-width:900px) and (min-width:768px){
  section.barah-v35-latest .grid-block.products-list-container.vertical-products{
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
  }
  section.barah-v35-latest custom-salla-product-card.product-block img,
  section.barah-v35-latest custom-salla-product-card.product-block .product-block__thumb,
  section.barah-v35-latest custom-salla-product-card.product-block .product-block__image,
  section.barah-v35-latest custom-salla-product-card.product-block .product-image{
    height:165px!important;
    max-height:165px!important;
  }
}
@media(max-width:767px){
  /* ثيم خطوة يحول الرف أفقيًا على الجوال؛ نصغر عرض الكرت فقط */
  section.barah-v35-latest .grid-block.products-list-container.vertical-products{
    display:flex!important;
    gap:9px!important;
    overflow-x:auto!important;
    scroll-snap-type:x mandatory!important;
  }
  section.barah-v35-latest custom-salla-product-card.product-block{
    flex:0 0 58%!important;
    flex-basis:58%!important;
    width:58%!important;
    max-width:205px!important;
    border-radius:13px!important;
    scroll-snap-align:start!important;
  }
  section.barah-v35-latest custom-salla-product-card.product-block img,
  section.barah-v35-latest custom-salla-product-card.product-block .product-block__thumb,
  section.barah-v35-latest custom-salla-product-card.product-block .product-block__image,
  section.barah-v35-latest custom-salla-product-card.product-block .product-image{
    height:142px!important;
    max-height:142px!important;
  }
  section.barah-v35-latest custom-salla-product-card.product-block .product-block__title,
  section.barah-v35-latest custom-salla-product-card.product-block .product-title,
  section.barah-v35-latest custom-salla-product-card.product-block h3,
  section.barah-v35-latest custom-salla-product-card.product-block h4{
    min-height:34px!important;
    max-height:36px!important;
    font-size:10.8px!important;
  }
}
`;
document.head.appendChild(s);
})();


/* ============================================================
   BARAH V52 — SMART MERGE
   تطوير أفضل أفكار V44/V45 داخل V51 بدون تكرار الأقسام
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V52_SMART_MERGE__) return;
window.__BARAH_V52_SMART_MERGE__=true;

var ROOT='barah-step-needs-v51';
var STYLE='barah-v52-smart-merge-style';

function isHome(){
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  return /^\/(ar|en)?$/.test(p) || !!document.querySelector('main');
}
if(!isHome()) return;

var LINKS={
  best:'https://barahstore.com/ar/home-kitchen/c127906256',
  all:'https://barahstore.com/ar/home-kitchen/c127906256',
  homeKitchen:'https://barahstore.com/ar/home-kitchen/c127906256',
  care:'https://barahstore.com/ar/care-style/c727852954',
  fitness:'https://barahstore.com/ar/fitness/c511828448',
  travel:'https://barahstore.com/ar/travel/c336613091',
  car:'https://barahstore.com/ar/car/c228633582',
  baby:'https://barahstore.com/ar/baby-toys/c694872552',
  pets:'https://barahstore.com/ar/pets/c92693286',
  parties:'https://barahstore.com/ar/الحفلات-والمناسبات/c1851175671',
  winter:'https://barahstore.com/ar/offers/c558473504'
};
function search(q){return 'https://barahstore.com/ar/search?q='+encodeURIComponent(q)}

var MISSIONS=[
  {icon:'🏃',title:'للرياضة المنزلية',desc:'مقاومات، عقلة، دمبلز، بيدال وأدوات تساعدك تبني روتين حركة أبسط.',url:LINKS.fitness},
  {icon:'🔥',title:'لشد القوام والتعرق',desc:'مشدات وأحزمة حرارية وخيارات مناسبة للمشي والتمارين اليومية.',url:search('مشد حراري')},
  {icon:'✈',title:'قبل السفر',desc:'تنظيم الحقائب، حفظ الملابس، تجهيزات خفيفة وإكسسوارات للتنقل.',url:LINKS.travel},
  {icon:'⌂',title:'لبيت أرتب',desc:'منظمات وأدوات مطبخ وحلول يومية تقلل الفوضى وتختصر الوقت.',url:LINKS.homeKitchen},
  {icon:'🚗',title:'للسيارة',desc:'حوامل جوال، تنظيم وإكسسوارات صغيرة تجعل الاستخدام اليومي أسهل.',url:LINKS.car},
  {icon:'✨',title:'للعناية اليومية',desc:'اختيارات للوجه والقدمين والشعر وأدوات شخصية عملية للاستخدام اليومي.',url:LINKS.care}
];
var CATS=[
  ['المنزل والمطبخ',LINKS.homeKitchen],
  ['العناية والأناقة',LINKS.care],
  ['الرياضة واللياقة',LINKS.fitness],
  ['السفر والرحلات',LINKS.travel],
  ['السيارة',LINKS.car],
  ['الطفل والألعاب',LINKS.baby],
  ['الحيوانات الأليفة',LINKS.pets],
  ['الحفلات والمناسبات',LINKS.parties],
  ['الشتاء والعروض',LINKS.winter]
];

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
#${ROOT}{
  direction:rtl!important;
  width:min(1240px,calc(100% - 32px))!important;
  max-width:1240px!important;
  margin:0 auto 22px!important;
  font-family:inherit!important;
}
#${ROOT} *{box-sizing:border-box!important}
#${ROOT} .barah-v52-shell{
  overflow:hidden!important;
  border:1px solid #eadbcf!important;
  border-radius:26px!important;
  background:
    radial-gradient(circle at 8% 5%,rgba(255,122,24,.11),transparent 25%),
    radial-gradient(circle at 92% 8%,rgba(239,68,68,.07),transparent 25%),
    linear-gradient(180deg,#fffdfb 0%,#fff8f3 100%)!important;
  box-shadow:0 18px 40px rgba(35,24,18,.055)!important;
}
#${ROOT} .v52-head{
  display:grid!important;
  grid-template-columns:minmax(0,1.25fr) minmax(260px,.75fr)!important;
  gap:18px!important;
  align-items:end!important;
  padding:26px 26px 20px!important;
  border-bottom:1px solid rgba(229,205,190,.58)!important;
}
#${ROOT} .v52-eyebrow{
  display:inline-flex!important;
  width:max-content!important;
  padding:7px 11px!important;
  border-radius:999px!important;
  background:#fff0e5!important;
  color:#a95322!important;
  font-size:11px!important;
  font-weight:900!important;
  margin-bottom:9px!important;
}
#${ROOT} .v52-title{
  margin:0!important;
  color:#211914!important;
  font-size:34px!important;
  line-height:1.32!important;
  font-weight:950!important;
}
#${ROOT} .v52-sub{
  margin:10px 0 0!important;
  max-width:790px!important;
  color:#75675f!important;
  font-size:14px!important;
  line-height:1.95!important;
}
#${ROOT} .v52-head-actions{
  display:flex!important;
  flex-direction:column!important;
  gap:9px!important;
}
#${ROOT} .v52-head-actions a{
  min-height:44px!important;
  display:flex!important;
  align-items:center!important;
  justify-content:center!important;
  border-radius:13px!important;
  text-decoration:none!important;
  font-size:12px!important;
  font-weight:900!important;
}
#${ROOT} .v52-head-actions .primary{
  color:#fff!important;
  background:linear-gradient(135deg,#ff7a18,#ef4444)!important;
  box-shadow:0 11px 23px rgba(239,68,68,.16)!important;
}
#${ROOT} .v52-head-actions .secondary{
  color:#4d4038!important;
  background:#fff!important;
  border:1px solid #e9ddd4!important;
}
#${ROOT} .v52-featured{
  display:grid!important;
  grid-template-columns:repeat(2,minmax(0,1fr))!important;
  gap:14px!important;
  padding:20px 26px 18px!important;
}
#${ROOT} .v52-feature{
  min-height:238px!important;
  padding:20px!important;
  border-radius:22px!important;
  overflow:hidden!important;
  text-decoration:none!important;
  display:flex!important;
  flex-direction:column!important;
  justify-content:space-between!important;
  border:1px solid rgba(233,216,205,.95)!important;
  box-shadow:0 12px 27px rgba(34,24,18,.045)!important;
}
#${ROOT} .v52-feature.senior{
  background:radial-gradient(circle at 88% 12%,rgba(255,175,113,.27),transparent 31%),linear-gradient(135deg,#fff8f1,#fff)!important;
}
#${ROOT} .v52-feature.mom{
  background:radial-gradient(circle at 88% 12%,rgba(255,200,187,.24),transparent 31%),linear-gradient(135deg,#fff9f6,#fff)!important;
}
#${ROOT} .v52-label{
  display:inline-flex!important;
  width:max-content!important;
  padding:6px 9px!important;
  border-radius:999px!important;
  background:#fff!important;
  border:1px solid #f0ddd0!important;
  color:#aa5e2e!important;
  font-size:10px!important;
  font-weight:900!important;
}
#${ROOT} .v52-feature h3{
  margin:14px 0 8px!important;
  color:#251e19!important;
  font-size:24px!important;
  line-height:1.45!important;
  font-weight:950!important;
}
#${ROOT} .v52-feature p{
  margin:0!important;
  color:#746861!important;
  font-size:13px!important;
  line-height:1.9!important;
  max-width:560px!important;
}
#${ROOT} .v52-chips{
  display:flex!important;
  flex-wrap:wrap!important;
  gap:7px!important;
  margin-top:16px!important;
}
#${ROOT} .v52-chip{
  display:inline-flex!important;
  align-items:center!important;
  min-height:31px!important;
  padding:0 10px!important;
  border-radius:999px!important;
  background:rgba(255,255,255,.88)!important;
  border:1px solid #eadfd7!important;
  color:#5d4e45!important;
  font-size:10.5px!important;
  font-weight:800!important;
}
#${ROOT} .v52-feature-cta{
  display:inline-flex!important;
  margin-top:16px!important;
  color:#ef5d2d!important;
  font-size:12px!important;
  font-weight:950!important;
}
#${ROOT} .v52-missions{padding:4px 26px 18px!important}
#${ROOT} .v52-section-head{
  display:flex!important;
  align-items:end!important;
  justify-content:space-between!important;
  gap:12px!important;
  margin-bottom:12px!important;
}
#${ROOT} .v52-section-head h3{
  margin:0!important;
  color:#241e1a!important;
  font-size:21px!important;
  font-weight:950!important;
}
#${ROOT} .v52-section-head span{
  color:#8b7d74!important;
  font-size:11px!important;
}
#${ROOT} .v52-mission-grid{
  display:grid!important;
  grid-template-columns:repeat(3,minmax(0,1fr))!important;
  gap:10px!important;
}
#${ROOT} .v52-mission{
  min-height:132px!important;
  padding:14px!important;
  border-radius:17px!important;
  background:#fff!important;
  border:1px solid #eee2da!important;
  text-decoration:none!important;
  box-shadow:0 7px 17px rgba(34,24,18,.03)!important;
}
#${ROOT} .v52-mission-icon{
  width:38px!important;
  height:38px!important;
  display:grid!important;
  place-items:center!important;
  border-radius:12px!important;
  margin-bottom:9px!important;
  background:#fff3e9!important;
  font-size:18px!important;
}
#${ROOT} .v52-mission strong{
  display:block!important;
  color:#28211d!important;
  font-size:14px!important;
  margin-bottom:5px!important;
  font-weight:900!important;
}
#${ROOT} .v52-mission small{
  display:block!important;
  color:#776a62!important;
  font-size:11px!important;
  line-height:1.75!important;
}
#${ROOT} .v52-categories{padding:2px 26px 22px!important}
#${ROOT} .v52-cat-row{
  display:flex!important;
  flex-wrap:wrap!important;
  gap:8px!important;
}
#${ROOT} .v52-cat{
  min-height:37px!important;
  display:inline-flex!important;
  align-items:center!important;
  padding:0 12px!important;
  border-radius:999px!important;
  text-decoration:none!important;
  background:#fff!important;
  border:1px solid #e9ddd4!important;
  color:#50423a!important;
  font-size:11px!important;
  font-weight:850!important;
}
#${ROOT} .v52-footer{
  display:flex!important;
  align-items:center!important;
  justify-content:space-between!important;
  gap:12px!important;
  margin:0 26px 24px!important;
  padding:13px 15px!important;
  border-radius:15px!important;
  background:#fff3ea!important;
  border:1px solid #f0dacb!important;
}
#${ROOT} .v52-footer p{
  margin:0!important;
  color:#78685e!important;
  font-size:11px!important;
  line-height:1.8!important;
}
#${ROOT} .v52-footer strong{color:#2b221d!important}
#${ROOT} .v52-footer a{
  flex:0 0 auto!important;
  text-decoration:none!important;
  color:#fff!important;
  background:#222!important;
  border-radius:10px!important;
  padding:9px 12px!important;
  font-size:11px!important;
  font-weight:900!important;
}
@media(hover:hover){
  #${ROOT} .v52-mission:hover,
  #${ROOT} .v52-cat:hover{
    transform:translateY(-1px)!important;
    border-color:#f0c7ae!important;
  }
}
@media(max-width:980px){
  #${ROOT} .v52-head{grid-template-columns:1fr!important}
  #${ROOT} .v52-featured{grid-template-columns:1fr!important}
  #${ROOT} .v52-mission-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important}
}
@media(max-width:767px){
  #${ROOT}{width:calc(100% - 20px)!important;margin:0 10px 18px!important}
  #${ROOT} .barah-v52-shell{border-radius:20px!important}
  #${ROOT} .v52-head{padding:18px 14px 14px!important}
  #${ROOT} .v52-title{font-size:24px!important}
  #${ROOT} .v52-sub{font-size:12px!important}
  #${ROOT} .v52-featured{padding:14px!important}
  #${ROOT} .v52-feature{min-height:auto!important;padding:15px!important;border-radius:18px!important}
  #${ROOT} .v52-feature h3{font-size:20px!important}
  #${ROOT} .v52-missions{padding:2px 14px 14px!important}
  #${ROOT} .v52-mission-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:8px!important}
  #${ROOT} .v52-mission{min-height:126px!important;padding:11px!important}
  #${ROOT} .v52-categories{padding:0 14px 15px!important}
  #${ROOT} .v52-cat-row{overflow-x:auto!important;flex-wrap:nowrap!important;scrollbar-width:none!important}
  #${ROOT} .v52-cat-row::-webkit-scrollbar{display:none!important}
  #${ROOT} .v52-cat{flex:0 0 auto!important}
  #${ROOT} .v52-footer{margin:0 14px 15px!important;display:block!important}
  #${ROOT} .v52-footer a{display:inline-flex!important;margin-top:9px!important}
}
`;
  document.head.appendChild(s);
}

function missionHTML(m){
  return '<a class="v52-mission" href="'+m.url+'">'+
    '<span class="v52-mission-icon">'+m.icon+'</span>'+
    '<strong>'+m.title+'</strong>'+
    '<small>'+m.desc+'</small>'+
  '</a>';
}
function catHTML(c){return '<a class="v52-cat" href="'+c[1]+'">'+c[0]+'</a>'}

function upgrade(){
  addStyle();
  var oldV44=document.getElementById('barah-step-smart-storefront-v44');
  if(oldV44) oldV44.style.display='none';
  var root=document.getElementById(ROOT);
  if(!root) return false;

  root.setAttribute('aria-label','تسوّق حسب الاحتياج في متجر بارعة');
  root.innerHTML=''+
    '<div class="barah-v52-shell">'+
      '<div class="v52-head">'+
        '<div>'+ 
          '<span class="v52-eyebrow">واجهة بارعة الذكية • اكتشاف أسرع حسب الاحتياج</span>'+ 
          '<h2 class="v52-title">مو لازم تعرف اسم المنتج… ابدأ من اللي تحتاجه اليوم</h2>'+ 
          '<p class="v52-sub">بدل التصفح بين مئات المنتجات، رتّبنا لك مسارات واضحة حسب الشخص والموقف والهدف: راحة كبار السن، احتياجات الحمل والطفل، الرياضة المنزلية، شد القوام والتعرق، السفر، المنزل والعناية اليومية.</p>'+ 
        '</div>'+ 
        '<div class="v52-head-actions">'+ 
          '<a class="primary" href="'+LINKS.best+'">ابدأ من الأكثر طلبًا ←</a>'+ 
          '<a class="secondary" href="'+LINKS.all+'">استكشف كل المنتجات</a>'+ 
        '</div>'+ 
      '</div>'+ 

      '<div class="v52-featured">'+ 
        '<a class="v52-feature senior" href="'+search('عكاز')+'">'+ 
          '<div>'+ 
            '<span class="v52-label">🎁 راحة لها معنى</span>'+ 
            '<h3>اختيارات عملية لكبار السن</h3>'+ 
            '<p>مسار أسرع للراحة والحركة اليومية: عكازات، بيدال منزلي، دعم الركبة والرقبة ومنتجات مساعدة للاستخدام اليومي.</p>'+ 
            '<div class="v52-chips"><span class="v52-chip">عكازات</span><span class="v52-chip">بيدال منزلي</span><span class="v52-chip">دعم الركبة</span><span class="v52-chip">راحة يومية</span></div>'+ 
          '</div>'+ 
          '<span class="v52-feature-cta">اكتشف اختيارات كبار السن ←</span>'+ 
        '</a>'+ 

        '<a class="v52-feature mom" href="'+search('Pregnancy')+'">'+ 
          '<div>'+ 
            '<span class="v52-label">🤍 للأم والطفل</span>'+ 
            '<h3>احتياجات الحمل وبداية الطفل</h3>'+ 
            '<p>وصول أسرع لما قد تحتاجه الأم خلال الحمل والتنقل وبداية الطفل، من الدعم اليومي إلى مستلزمات السفر والتنظيم.</p>'+ 
            '<div class="v52-chips"><span class="v52-chip">دعم الحمل</span><span class="v52-chip">مستلزمات الطفل</span><span class="v52-chip">التنقل</span><span class="v52-chip">تنظيم يومي</span></div>'+ 
          '</div>'+ 
          '<span class="v52-feature-cta">تسوّقي للأم والطفل ←</span>'+ 
        '</a>'+ 
      '</div>'+ 

      '<div class="v52-missions">'+ 
        '<div class="v52-section-head"><h3>اختر الهدف… ونختصر عليك الطريق</h3><span>مسارات سريعة للشراء</span></div>'+ 
        '<div class="v52-mission-grid">'+MISSIONS.map(missionHTML).join('')+'</div>'+ 
      '</div>'+ 

      '<div class="v52-categories">'+ 
        '<div class="v52-section-head"><h3>أقسام بارعة الرئيسية</h3><span>وصول مباشر بدون زحمة</span></div>'+ 
        '<div class="v52-cat-row">'+CATS.map(catHTML).join('')+'</div>'+ 
      '</div>'+ 

      '<div class="v52-footer">'+ 
        '<p><strong>فكرة الواجهة:</strong> كل مساحة لها وظيفة مختلفة؛ شخص، موقف أو هدف. هذا يقلل الحيرة ويعطي المنتجات الأقل ظهورًا فرصة وصول أفضل بدون تكرار نفس الرفوف.</p>'+ 
        '<a href="'+LINKS.all+'">الكتالوج الكامل ←</a>'+ 
      '</div>'+ 
    '</div>';
  return true;
}

function run(){upgrade()}
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',run,{once:true});
else run();
setTimeout(run,450);
setTimeout(run,1200);
setTimeout(run,2600);
})();


/* ============================================================
   BARAH V53 — CONVERSION LIFT
   - قرار أسرع حسب الاهتمام الفعلي
   - طمأنة قبل رفوف المنتجات
   - دعم وصل حديثًا دون تغيير مقاساته
   - بدون عدادات وهمية / ندرة مصطنعة / observers مستمرة
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V53_CONVERSION_LIFT__) return;
window.__BARAH_V53_CONVERSION_LIFT__=true;

var ROOT='barah-step-conversion-v53';
var STYLE=ROOT+'-style';

function isHome(){
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  return p==='/'||p==='/ar'||p==='/en'||!!document.querySelector('main');
}
if(!isHome())return;

function search(q){return 'https://barahstore.com/ar/search?q='+encodeURIComponent(q)}

var INTENTS=[
  {
    icon:'🏋️',
    title:'للرياضة المنزلية',
    desc:'حبال مقاومة، عقلة، دمبلز وتمارين منزلية لمن يريد بداية عملية بدون تعقيد.',
    href:'https://barahstore.com/ar/fitness/c511828448',
    tag:'اهتمام قوي'
  },
  {
    icon:'🔥',
    title:'لشد القوام والتعرق',
    desc:'مشدات وأحزمة حرارية وخيارات دعم للمشي والتمارين والاستخدام اليومي.',
    href:'https://barahstore.com/ar/shapewear-support/c1338082535',
    tag:'اختيارات مباشرة'
  },
  {
    icon:'✈️',
    title:'للسفر والتنظيم',
    desc:'شنط وحلول تنظيم تجعل تجهيز الرحلة والدوام أبسط وأسرع.',
    href:'https://barahstore.com/ar/travel/c336613091',
    tag:'مفيد يوميًا'
  },
  {
    icon:'✨',
    title:'للعناية اليومية',
    desc:'حلول عملية للأسنان، الشعر، البشرة والعناية الشخصية بخطوات أبسط.',
    href:'https://barahstore.com/ar/personal-care/c290880391',
    tag:'اكتشاف سريع'
  }
];

function addStyle(){
  if(document.getElementById(STYLE))return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
#${ROOT}{
  direction:rtl!important;
  width:min(1240px,calc(100% - 32px))!important;
  max-width:1240px!important;
  margin:0 auto 22px!important;
  font-family:inherit!important;
}
#${ROOT} *{box-sizing:border-box!important}
#${ROOT} .v53-shell{
  border:1px solid #eadfd7!important;
  border-radius:24px!important;
  padding:20px!important;
  background:
    radial-gradient(circle at 8% 5%,rgba(255,122,24,.08),transparent 26%),
    linear-gradient(180deg,#fffdfb,#fff)!important;
  box-shadow:0 14px 30px rgba(35,24,18,.04)!important;
}
#${ROOT} .v53-head{
  display:flex!important;
  align-items:flex-end!important;
  justify-content:space-between!important;
  gap:18px!important;
  margin-bottom:14px!important;
}
#${ROOT} .v53-kicker{
  display:inline-flex!important;
  align-items:center!important;
  width:max-content!important;
  min-height:28px!important;
  padding:0 10px!important;
  border-radius:999px!important;
  background:#fff0e5!important;
  color:#b45309!important;
  font-size:11px!important;
  font-weight:900!important;
  margin-bottom:7px!important;
}
#${ROOT} h2{
  margin:0!important;
  color:#211914!important;
  font-size:26px!important;
  line-height:1.35!important;
  font-weight:950!important;
}
#${ROOT} .v53-sub{
  margin:6px 0 0!important;
  color:#796a61!important;
  font-size:13px!important;
  line-height:1.8!important;
}
#${ROOT} .v53-best{
  flex:0 0 auto!important;
  text-decoration:none!important;
  min-height:42px!important;
  padding:0 14px!important;
  border-radius:12px!important;
  display:inline-flex!important;
  align-items:center!important;
  justify-content:center!important;
  color:#fff!important;
  background:linear-gradient(135deg,#ff7a18,#ef4444)!important;
  font-size:12px!important;
  font-weight:900!important;
  box-shadow:0 10px 20px rgba(239,68,68,.14)!important;
}
#${ROOT} .v53-intents{
  display:grid!important;
  grid-template-columns:repeat(4,minmax(0,1fr))!important;
  gap:11px!important;
}
#${ROOT} .v53-card{
  min-width:0!important;
  min-height:150px!important;
  padding:14px!important;
  border:1px solid #eee4dc!important;
  border-radius:17px!important;
  background:#fff!important;
  text-decoration:none!important;
  display:flex!important;
  flex-direction:column!important;
  box-shadow:0 8px 18px rgba(35,24,18,.03)!important;
}
#${ROOT} .v53-top{display:flex!important;align-items:center!important;justify-content:space-between!important;gap:8px!important;margin-bottom:9px!important}
#${ROOT} .v53-icon{
  width:38px!important;height:38px!important;border-radius:12px!important;
  display:flex!important;align-items:center!important;justify-content:center!important;
  background:#fff3ea!important;font-size:20px!important
}
#${ROOT} .v53-tag{
  padding:5px 8px!important;border-radius:999px!important;background:#f8f5f2!important;
  color:#806f64!important;font-size:10px!important;font-weight:900!important
}
#${ROOT} .v53-card strong{display:block!important;color:#29201b!important;font-size:15px!important;font-weight:950!important;margin-bottom:5px!important}
#${ROOT} .v53-card p{margin:0!important;color:#796960!important;font-size:11.5px!important;line-height:1.75!important}
#${ROOT} .v53-go{margin-top:auto!important;padding-top:10px!important;color:#d95622!important;font-size:11px!important;font-weight:950!important}
#${ROOT} .v53-trust{
  display:grid!important;
  grid-template-columns:repeat(5,minmax(0,1fr))!important;
  gap:8px!important;
  margin-top:14px!important;
  padding-top:14px!important;
  border-top:1px dashed #eadfd7!important;
}
#${ROOT} .v53-trust span{
  min-height:38px!important;padding:7px!important;border-radius:11px!important;
  border:1px solid #eee4dd!important;background:#fff!important;color:#5d5048!important;
  display:flex!important;align-items:center!important;justify-content:center!important;
  text-align:center!important;font-size:10.5px!important;font-weight:850!important
}
/* ===== Latest conversion support: keep V51.2 sizes untouched ===== */
section.barah-v35-latest .barah-v53-latest-proof{
  display:flex!important;
  flex-wrap:wrap!important;
  align-items:center!important;
  gap:7px!important;
  margin:-8px 0 14px!important;
}
section.barah-v35-latest .barah-v53-latest-proof span{
  min-height:28px!important;
  padding:0 9px!important;
  border-radius:999px!important;
  border:1px solid #eee3db!important;
  background:#fff!important;
  color:#6b5d55!important;
  display:inline-flex!important;
  align-items:center!important;
  font-size:10.5px!important;
  font-weight:850!important;
}
section.barah-v35-latest custom-salla-product-card.product-block button,
section.barah-v35-latest custom-salla-product-card.product-block .btn--add-to-cart,
section.barah-v35-latest custom-salla-product-card.product-block [class*="add-to-cart"]{
  min-height:38px!important;
  border-radius:10px!important;
  font-weight:900!important;
}
@media(max-width:1000px){
  #${ROOT} .v53-intents{grid-template-columns:repeat(2,minmax(0,1fr))!important}
  #${ROOT} .v53-trust{grid-template-columns:repeat(3,minmax(0,1fr))!important}
}
@media(max-width:767px){
  #${ROOT}{width:calc(100% - 24px)!important;margin:0 12px 18px!important}
  #${ROOT} .v53-shell{padding:14px 12px!important;border-radius:19px!important}
  #${ROOT} .v53-head{align-items:flex-start!important;flex-direction:column!important;gap:11px!important}
  #${ROOT} h2{font-size:21px!important}
  #${ROOT} .v53-intents{display:flex!important;overflow-x:auto!important;gap:9px!important;scroll-snap-type:x mandatory!important;scrollbar-width:none!important}
  #${ROOT} .v53-intents::-webkit-scrollbar{display:none!important}
  #${ROOT} .v53-card{flex:0 0 78%!important;max-width:270px!important;min-height:145px!important;scroll-snap-align:start!important}
  #${ROOT} .v53-trust{grid-template-columns:repeat(2,minmax(0,1fr))!important}
}
`;
  document.head.appendChild(s);
}

function cardHTML(x){
  return '<a class="v53-card" href="'+x.href+'">'+
    '<div class="v53-top"><span class="v53-icon">'+x.icon+'</span><span class="v53-tag">'+x.tag+'</span></div>'+ 
    '<strong>'+x.title+'</strong>'+ 
    '<p>'+x.desc+'</p>'+ 
    '<span class="v53-go">استكشف الآن ←</span>'+ 
  '</a>';
}

function build(){
  var sec=document.createElement('section');
  sec.id=ROOT;
  sec.setAttribute('aria-label','مسارات تساعد على اتخاذ قرار الشراء');
  sec.innerHTML=''+
    '<div class="v53-shell">'+
      '<div class="v53-head">'+
        '<div>'+ 
          '<span class="v53-kicker">محتار من وين تبدأ؟</span>'+ 
          '<h2>ابدأ بالمسارات التي عليها اهتمام أعلى الآن</h2>'+ 
          '<p class="v53-sub">اختصرنا لك أكثر الأفكار التي تجذب العملاء حاليًا حتى تصل للمنتج الأقرب لاحتياجك بدون تصفح طويل.</p>'+ 
        '</div>'+ 
        '<a class="v53-best" href="https://barahstore.com/ar/home-kitchen/c127906256">شاهد الأكثر طلبًا ←</a>'+ 
      '</div>'+ 
      '<div class="v53-intents">'+INTENTS.map(cardHTML).join('')+'</div>'+ 
      '<div class="v53-trust">'+
        '<span>✓ متجر سلة موثق</span>'+ 
        '<span>🚚 شحن من الرياض</span>'+ 
        '<span>🎁 مجاني للطلبات فوق 149 ريال</span>'+ 
        '<span>💳 تابي وتمارا</span>'+ 
        '<span>↩️ استبدال واسترجاع</span>'+ 
      '</div>'+ 
    '</div>';
  return sec;
}

function latest(){
  return document.querySelector('section.home-block.home-block--fixed-products.show-all.barah-v35-latest');
}

function mount(){
  addStyle();
  var old=document.getElementById(ROOT);
  if(old)old.remove();
  var smart=document.getElementById('barah-step-smart-storefront-v52');
  var l=latest();
  var sec=build();
  if(smart&&smart.parentNode){smart.insertAdjacentElement('afterend',sec)}
  else if(l&&l.parentNode){l.parentNode.insertBefore(sec,l)}
  else (document.querySelector('main')||document.body).appendChild(sec);

  if(l&&!l.querySelector('.barah-v53-latest-proof')){
    var head=l.querySelector('.barah-v35-latest-head');
    if(head){
      var proof=document.createElement('div');
      proof.className='barah-v53-latest-proof';
      proof.innerHTML='<span>🚚 شحن داخل المملكة</span><span>💳 دفع مرن</span><span>↩️ استبدال واسترجاع</span>';
      head.insertAdjacentElement('afterend',proof);
    }
  }
}

function run(){mount()}
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',run,{once:true});
else run();
setTimeout(run,500);
setTimeout(run,1400);
setTimeout(run,2800);
})();


/* ============================================================
   BARAH V54 — NATIVE SALLA PRODUCT CARD
   اعتماد كرت المنتج الأصلي في المتجر داخل "وصل حديثًا"
   - لا نفرض ارتفاع صورة أو حجم عنوان أو شكل زر
   - لا نضيف نص داخل زر سلة الأصلي
   - نحافظ فقط على تطوير حاوية القسم وعنوانه
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V54_NATIVE_CARD__) return;
window.__BARAH_V54_NATIVE_CARD__=true;

function isOurStyleSheet(sheet){
  try{
    var n=sheet.ownerNode;
    return !!(n && n.id && /^barah-/i.test(n.id));
  }catch(e){return false;}
}

function shouldRemoveRule(rule){
  var sel='';
  try{ sel=rule.selectorText||''; }catch(e){}
  if(!sel) return false;
  return (
    sel.indexOf('section.barah-v35-latest custom-salla-product-card')!==-1 ||
    sel.indexOf('.barah-v35-latest custom-salla-product-card')!==-1 ||
    sel.indexOf('section.barah-v35-latest .barah-atc-label')!==-1 ||
    sel.indexOf('.barah-v35-latest .barah-atc-label')!==-1
  );
}

function scrubRules(ruleList){
  if(!ruleList) return;
  for(var i=ruleList.length-1;i>=0;i--){
    var rule=ruleList[i];
    try{
      if(rule.cssRules && rule.cssRules.length){
        scrubRules(rule.cssRules);
      }
      if(shouldRemoveRule(rule)){
        rule.parentStyleSheet ? rule.parentStyleSheet.deleteRule(i) : null;
      }
    }catch(e){}
  }
}

function scrubBarahCardOverrides(){
  /* V51.2 كان أكبر مصدر لتغيير مقاس الكرت */
  var forced=document.getElementById('barah-v512-latest-card-only-style');
  if(forced) forced.remove();

  /* احذف فقط قواعدنا التي تدخل داخل الكرت، واترك تصميم القسم الخارجي */
  Array.prototype.slice.call(document.styleSheets).forEach(function(sheet){
    if(!isOurStyleSheet(sheet)) return;
    try{
      var rules=sheet.cssRules;
      if(!rules) return;
      for(var i=rules.length-1;i>=0;i--){
        var rule=rules[i];
        if(rule.cssRules && rule.cssRules.length){
          /* nested @media */
          for(var j=rule.cssRules.length-1;j>=0;j--){
            if(shouldRemoveRule(rule.cssRules[j])){
              try{rule.deleteRule(j);}catch(e){}
            }
          }
        }
        if(shouldRemoveRule(rule)){
          try{sheet.deleteRule(i);}catch(e){}
        }
      }
    }catch(e){}
  });
}

function restoreNativeButton(){
  var latest=document.querySelector('section.barah-v35-latest');
  if(!latest) return;

  /* إزالة النص الذي كنا نضيفه برمجيًا لزر السلة حتى يبقى زر الثيم الأصلي */
  latest.querySelectorAll('.barah-atc-label').forEach(function(el){el.remove();});
  latest.querySelectorAll('button,[class*="add-to-cart"],.btn--add-to-cart').forEach(function(btn){
    if(btn && btn.getAttribute('aria-label')==='أضف المنتج للسلة'){
      btn.removeAttribute('aria-label');
    }
  });
}

function addSectionOnlyStyle(){
  var id='barah-v54-latest-section-only-style';
  if(document.getElementById(id)) return;
  var s=document.createElement('style');
  s.id=id;
  s.textContent=`
/* تصميم الحاوية فقط — الكرت نفسه Native من ثيم سلة */
section.home-block.home-block--fixed-products.show-all.barah-v35-latest{
  overflow:visible!important;
}
section.barah-v35-latest .barah-v35-latest-head{
  margin-bottom:16px!important;
}
section.barah-v35-latest .grid-block.products-list-container.vertical-products{
  align-items:stretch!important;
}
@media(max-width:767px){
  section.barah-v35-latest .barah-v35-latest-head{
    margin-bottom:12px!important;
  }
}
`;
  document.head.appendChild(s);
}

function run(){
  scrubBarahCardOverrides();
  restoreNativeButton();
  addSectionOnlyStyle();
  document.documentElement.setAttribute('data-barah-v54-native-card','ready');
}

if(document.readyState==='loading') document.addEventListener('DOMContentLoaded',run,{once:true});
else run();
/* تصحيحات محدودة بعد hydration فقط */
setTimeout(run,450);
setTimeout(run,1300);
setTimeout(run,2600);
})();
/* ============================================================
   BARAH V55 — PREGNANCY PICKS
   اختيارات للحمل والراحة — منتجات فعلية من كتالوج بارعة
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V55_PREGNANCY_PICKS__) return;
window.__BARAH_V55_PREGNANCY_PICKS__=true;

var ROOT='barah-step-pregnancy-v55';
var STYLE=ROOT+'-style';
var ALL='https://barahstore.com/ar/search?q=Pregnancy';

var ITEMS=[
  {
    id:'1939425047',
    name:'حزام دعم البطن وأسفل الظهر للحامل قابل للتعديل',
    tag:'دعم يومي',
    desc:'خيار قابل للتعديل للاستخدام اليومي خلال الحمل.',
    price:'39 ر.س',
    image:'https://cdn.salla.sa/qwxGZ/e7bfbe78-5498-466e-94ee-70f6d06518bc-500x500-knAmD7F4CMgQ8BaJFPaMyNDU7ZuZ2EU5C6PgnkIB.jpg',
    url:'https://barahstore.com/ar/product-1939425047/p1939425047'
  },
  {
    id:'1737673536',
    name:'وسادة حمل على شكل U – ألوان متعددة',
    tag:'للراحة',
    desc:'تصميم يحيط بالجسم للاسترخاء والجلوس والنوم.',
    price:'69 ر.س',
    image:'https://cdn.salla.sa/qwxGZ/0b82500c-5a87-478c-a484-f16d9a901c67-333.33333333333x500-Twa9CKkmDHovBQ32KtRinKbG8WrlpFol1FiCeCp0.png',
    url:'https://barahstore.com/ar/product-1737673536/p1737673536'
  },
  {
    id:'1126035679',
    name:'وسادة حمل على شكل J – 3 ألوان',
    tag:'اختيار مرن',
    desc:'شكل J عملي لمن تفضّل وسادة أقل حجمًا وسهلة الترتيب.',
    price:'69 ر.س',
    image:'https://cdn.salla.sa/qwxGZ/5b4f7bb2-e850-48ae-a22e-7bff074399e9-500x500-TAaTsNuBMGKc5J7cWuTujvAD3zMIXuK7WPZ7bOcf.png',
    url:'https://barahstore.com/ar/product-1126035679/p1126035679'
  },
  {
    id:'1629509591',
    name:'حزام دعم ما بعد الولادة 3 في 1 للبطن والخصر والحوض',
    tag:'بعد الولادة',
    desc:'خيار دعم متعدد الأجزاء مخصص لمرحلة ما بعد الولادة.',
    price:'69 ر.س',
    image:'https://cdn.salla.sa/qwxGZ/f3310939-ae33-4bb3-84c0-c639a967ac0c-500x395.04716981132-wZL0syD3j3YWqNdwtKRoZ9iK4PjJqVUTjD9E3pag.jpg',
    url:'https://barahstore.com/ar/product-1629509591/p1629509591'
  }
];

function home(){
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  return p==='/'||p==='/ar'||p==='/en'||(location.hostname==='salla.sa'&&p==='/br1');
}
if(!home())return;

function addStyle(){
  if(document.getElementById(STYLE))return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
#${ROOT}{direction:rtl;width:min(1240px,calc(100% - 32px));margin:0 auto 22px;font-family:inherit;box-sizing:border-box}
#${ROOT} *{box-sizing:border-box}
#${ROOT} .preg-shell{
  overflow:hidden;border:1px solid #eadfd8;border-radius:24px;padding:22px;
  background:radial-gradient(circle at 7% 8%,rgba(255,122,24,.08),transparent 28%),linear-gradient(180deg,#fffdfb,#fff8f4);
  box-shadow:0 14px 32px rgba(35,24,18,.045)
}
#${ROOT} .preg-head{display:flex;justify-content:space-between;align-items:flex-end;gap:18px;margin-bottom:16px}
#${ROOT} .preg-kicker{display:inline-flex;padding:7px 11px;border-radius:999px;background:#fff0e7;color:#b45309;font-size:11px;font-weight:900;margin-bottom:8px}
#${ROOT} h2{margin:0;color:#241b17;font-size:28px;line-height:1.35;font-weight:950}
#${ROOT} .preg-sub{margin:7px 0 0;color:#786860;font-size:13px;line-height:1.8}
#${ROOT} .preg-all{flex:0 0 auto;text-decoration:none;border:1px solid #eadbd2;background:#fff;color:#3d312a;border-radius:12px;padding:10px 14px;font-size:12px;font-weight:900}
#${ROOT} .preg-grid{display:grid;grid-template-columns:1.2fr repeat(3,minmax(0,1fr));gap:12px}
#${ROOT} .preg-card{position:relative;overflow:hidden;display:flex;flex-direction:column;text-decoration:none;background:#fff;border:1px solid #eee4dd;border-radius:18px;min-width:0;box-shadow:0 8px 20px rgba(35,24,18,.035)}
#${ROOT} .preg-card.hero{background:linear-gradient(160deg,#fff,#fff6f0)}
#${ROOT} .preg-media{position:relative;display:flex;align-items:center;justify-content:center;min-height:176px;background:#fff;padding:12px}
#${ROOT} .hero .preg-media{min-height:210px}
#${ROOT} img{display:block;width:100%;height:170px;object-fit:contain;filter:none!important;transform:none!important;transition:none!important}
#${ROOT} .hero img{height:205px}
#${ROOT} .preg-tag{position:absolute;top:10px;right:10px;padding:6px 9px;border-radius:999px;background:#fff1e8;color:#b84a18;border:1px solid #f3d5c2;font-size:10px;font-weight:900}
#${ROOT} .preg-body{display:flex;flex:1;flex-direction:column;padding:13px 14px 14px}
#${ROOT} h3{margin:0 0 7px;color:#261d18;font-size:14px;line-height:1.55;font-weight:900;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
#${ROOT} .hero h3{font-size:17px}
#${ROOT} .preg-desc{margin:0 0 9px;color:#7a6a61;font-size:11px;line-height:1.7;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
#${ROOT} .preg-bottom{margin-top:auto;display:flex;align-items:center;justify-content:space-between;gap:8px}
#${ROOT} .preg-price{color:#d94c21;font-size:15px;font-weight:950;white-space:nowrap}
#${ROOT} .preg-cta{display:inline-flex;align-items:center;justify-content:center;min-height:36px;padding:0 11px;border-radius:10px;background:linear-gradient(135deg,#ff7a18,#ef4444);color:#fff;font-size:11px;font-weight:900;white-space:nowrap}
#${ROOT} .preg-note{margin-top:12px;color:#8a7a70;font-size:10px;line-height:1.7}
@media(max-width:1000px){#${ROOT} .preg-grid{grid-template-columns:repeat(2,minmax(0,1fr))}#${ROOT} .preg-card.hero{grid-column:span 2}}
@media(max-width:767px){
 #${ROOT}{width:calc(100% - 24px);margin:0 12px 18px}
 #${ROOT} .preg-shell{padding:15px 13px;border-radius:20px}
 #${ROOT} .preg-head{align-items:flex-start;flex-direction:column;gap:10px}
 #${ROOT} h2{font-size:22px}
 #${ROOT} .preg-all{width:100%;text-align:center}
 #${ROOT} .preg-grid{display:flex;overflow-x:auto;gap:10px;scroll-snap-type:x proximity;padding-bottom:3px;scrollbar-width:none}
 #${ROOT} .preg-grid::-webkit-scrollbar{display:none}
 #${ROOT} .preg-card,#${ROOT} .preg-card.hero{flex:0 0 72%;max-width:260px;grid-column:auto;scroll-snap-align:start}
 #${ROOT} .preg-media,#${ROOT} .hero .preg-media{min-height:155px}
 #${ROOT} img,#${ROOT} .hero img{height:150px}
 #${ROOT} .hero h3{font-size:14px}
}
@media(prefers-reduced-motion:reduce){#${ROOT} *{scroll-behavior:auto!important;transition:none!important;animation:none!important}}
`;
  document.head.appendChild(s);
}

function build(){
  var sec=document.createElement('section');
  sec.id=ROOT;
  sec.setAttribute('aria-label','اختيارات الحمل والراحة');
  var cards=ITEMS.map(function(p,i){
    return '<a class="preg-card'+(i===0?' hero':'')+'" href="'+p.url+'" data-product-id="'+p.id+'">'+
      '<div class="preg-media"><span class="preg-tag">'+p.tag+'</span><img loading="lazy" decoding="async" src="'+p.image+'" alt="'+p.name.replace(/"/g,'&quot;')+'"></div>'+
      '<div class="preg-body"><h3>'+p.name+'</h3><p class="preg-desc">'+p.desc+'</p><div class="preg-bottom"><span class="preg-price">'+p.price+'</span><span class="preg-cta">شاهد المنتج ←</span></div></div>'+
    '</a>';
  }).join('');
  sec.innerHTML='<div class="preg-shell">'+
    '<div class="preg-head"><div><span class="preg-kicker">🤍 اختيارات بارعة للحمل</span><h2>راحة أكثر خلال الحمل… واختيارات أقرب لاحتياجك</h2><p class="preg-sub">مجموعة مختصرة من منتجات الحمل والراحة والدعم، بدل البحث بين مئات الأصناف.</p></div><a class="preg-all" href="'+ALL+'">عرض كل اختيارات الحمل ←</a></div>'+
    '<div class="preg-grid">'+cards+'</div>'+
    '<div class="preg-note">ملاحظة: هذه المنتجات للاستخدام اليومي والراحة العامة وليست بديلًا عن التوجيه الطبي عند الحاجة.</div>'+
  '</div>';
  return sec;
}

function visible(el){
  if(!el) return false;
  try{
    var cs=getComputedStyle(el);
    return cs.display!=='none' && cs.visibility!=='hidden';
  }catch(e){return true;}
}

function findAnchor(){
  /* V52/V51 هو القسم الذكي الظاهر فعليًا في النسخة الحالية */
  var needs=document.getElementById('barah-step-needs-v51');
  if(visible(needs)) return needs;

  var conversion=document.getElementById('barah-step-conversion-v53');
  if(visible(conversion)) return conversion;

  var season=document.getElementById('barah-step-season-v49');
  if(visible(season)) return season;

  var latest=document.querySelector('section.home-block.home-block--fixed-products.show-all.barah-v35-latest');
  if(visible(latest)) return latest;

  var shipping=document.getElementById('barah-step-shipping-v24');
  if(visible(shipping)) return shipping;

  var hero=document.getElementById('barah-step-hero-v12');
  if(visible(hero)) return hero;

  return null;
}

function mount(){
  addStyle();

  var current=document.getElementById(ROOT);
  var anchor=findAnchor();
  if(!anchor || !anchor.parentNode) return false;

  if(!current){
    current=build();
  }

  /* انقل نفس العنصر بدل حذفه وإعادة إنشائه لتجنب الوميض وتعارض hydration */
  if(anchor.nextElementSibling!==current){
    anchor.insertAdjacentElement('afterend',current);
  }

  current.style.setProperty('display','block','important');
  current.style.setProperty('visibility','visible','important');
  current.style.setProperty('opacity','1','important');
  current.removeAttribute('hidden');
  current.setAttribute('data-barah-v55','ready');
  document.documentElement.setAttribute('data-barah-pregnancy-v55','ready');
  return true;
}

function boot(){
  var tries=0;
  function attempt(){
    tries++;
    if(mount() || tries>=24){
      if(timer) clearInterval(timer);
    }
  }
  attempt();
  var timer=setInterval(attempt,250);
  setTimeout(function(){
    try{clearInterval(timer);}catch(e){}
    mount();
  },6500);
}

if(document.readyState==='loading') document.addEventListener('DOMContentLoaded',boot,{once:true});
else boot();
})();


/* ============================================================
   BARAH V57 — SENIOR CARE PICKS
   اهتمام وراحة لكبار السن — حركة، دعم، راحة يومية
   منتجات حقيقية من كتالوج بارعة
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V57_SENIOR_PICKS__) return;
window.__BARAH_V57_SENIOR_PICKS__=true;

var ROOT='barah-step-senior-v57';
var STYLE=ROOT+'-style';

function isHome(){
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  return /^\/(ar|en)?$/.test(p) || !!document.querySelector('main');
}
if(!isHome()) return;

var ITEMS=[
  {
    id:'114843704',
    name:'عكاز مشي 3 في 1 قابل للطي ومزوّد بكشاف',
    image:'https://cdn.salla.sa/qwxGZ/8d8067fa-a071-4028-9cb5-04261fd3cb8f-494.62365591398x500-85G9UGdwfYJa081ypGrrAT7RH3xFBHE7EQQqzqqK.jpg',
    price:'55 ر.س',
    tag:'للحركة والتنقل',
    desc:'خيار عملي للتنقل اليومي، قابل للطي وسهل الحمل.',
    url:'https://barahstore.com/ar/product-114843704/p114843704'
  },
  {
    id:'1600022680',
    name:'جهاز بدال تمارين منزلي لليدين والساقين مع شاشة ودعامات ركبة',
    image:'https://cdn.files.salla.network/products/71627348/048c45f9-8aea-43e1-8d86-0af1621acda2_900x900.webp',
    price:'99 ر.س',
    tag:'حركة منزلية',
    desc:'مناسب لروتين حركة بسيط لليدين والساقين داخل المنزل.',
    url:'https://barahstore.com/ar/product-1600022680/p1600022680'
  },
  {
    id:'237486390',
    name:'مشد ركبة رياضي بأشرطة قابلة للضبط – قطعة واحدة',
    image:'https://cdn.salla.sa/qwxGZ/d648fc34-32af-4296-ace3-d964c41e8ebf-500x500-HmzQqSu20WD3zl3EdFcv1IqtwwKt0WyOA5SFIptO.jpg',
    price:'17 ر.س',
    tag:'دعم الركبة',
    desc:'أشرطة قابلة للضبط لاستخدام يومي أكثر مرونة.',
    url:'https://barahstore.com/ar/product-237486390/p237486390'
  },
  {
    id:'306349010',
    name:'حزام دعم الظهر الطويل ST-2126 قابل للتعديل',
    image:'https://cdn.salla.sa/qwxGZ/e580d499-975b-425d-8273-9646ddd4d8d7-500x500-DSuB4p2AdMuhVbSKcV9WWWDSppM3fIBPvCDMSS8o.jpg',
    price:'60 ر.س',
    oldPrice:'98 ر.س',
    tag:'دعم الظهر',
    desc:'تصميم طويل وقابل للتعديل للاستخدام اليومي والدعم العملي.',
    url:'https://barahstore.com/ar/product-306349010/p306349010'
  },
  {
    id:'1540794126',
    name:'دعامة رقبة هوائية قابلة للنفخ 3 طبقات بدعم قابل للتعديل',
    image:'https://cdn.salla.sa/qwxGZ/154bdebe-f7b4-439e-87aa-440217a23c22-500x455.82706766917-VzZi6EeMlZisaSAM6ZPIH8hy9vr0tpjT9zkxbD7a.jpg',
    price:'39.5 ر.س',
    tag:'للرقبة والراحة',
    desc:'خيار قابل للتعديل ويمكن تفريغه وتخزينه بسهولة.',
    url:'https://barahstore.com/ar/product-1540794126/p1540794126'
  }
];

var ALL='https://barahstore.com/ar/search?q='+encodeURIComponent('عكاز');

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
#${ROOT}{
  direction:rtl!important;
  width:min(1240px,calc(100% - 32px))!important;
  max-width:1240px!important;
  margin:0 auto 22px!important;
  font-family:inherit!important;
}
#${ROOT} *{box-sizing:border-box!important}
#${ROOT} .senior-shell{
  position:relative!important;
  overflow:hidden!important;
  padding:22px!important;
  border:1px solid #e4ded8!important;
  border-radius:24px!important;
  background:
    radial-gradient(circle at 92% 8%,rgba(66,113,92,.11),transparent 28%),
    radial-gradient(circle at 8% 90%,rgba(230,157,70,.09),transparent 30%),
    linear-gradient(180deg,#fff 0%,#fbfaf7 100%)!important;
  box-shadow:0 16px 34px rgba(33,28,23,.045)!important;
}
#${ROOT} .senior-head{
  display:flex!important;
  align-items:flex-end!important;
  justify-content:space-between!important;
  gap:18px!important;
  margin-bottom:17px!important;
}
#${ROOT} .senior-kicker{
  display:inline-flex!important;
  align-items:center!important;
  gap:7px!important;
  margin-bottom:8px!important;
  padding:7px 11px!important;
  border-radius:999px!important;
  background:#eef5f1!important;
  color:#38634f!important;
  font-size:11px!important;
  font-weight:900!important;
}
#${ROOT} h2{
  margin:0!important;
  color:#211d19!important;
  font-size:29px!important;
  line-height:1.35!important;
  font-weight:950!important;
}
#${ROOT} .senior-sub{
  max-width:760px!important;
  margin:7px 0 0!important;
  color:#746b63!important;
  font-size:13px!important;
  line-height:1.9!important;
}
#${ROOT} .senior-all{
  flex:0 0 auto!important;
  min-height:40px!important;
  padding:0 14px!important;
  display:inline-flex!important;
  align-items:center!important;
  justify-content:center!important;
  text-decoration:none!important;
  border:1px solid #d9e5de!important;
  border-radius:11px!important;
  background:#fff!important;
  color:#315845!important;
  font-size:12px!important;
  font-weight:900!important;
}
#${ROOT} .senior-layout{
  display:grid!important;
  grid-template-columns:1.2fr 1.8fr!important;
  gap:14px!important;
}
#${ROOT} .senior-feature{
  min-height:100%!important;
  padding:18px!important;
  border:1px solid #dde8e1!important;
  border-radius:20px!important;
  background:linear-gradient(155deg,#f5faf7,#fff)!important;
  display:flex!important;
  flex-direction:column!important;
  justify-content:space-between!important;
}
#${ROOT} .senior-feature-icon{
  width:52px!important;
  height:52px!important;
  border-radius:16px!important;
  display:flex!important;
  align-items:center!important;
  justify-content:center!important;
  background:#eaf3ee!important;
  font-size:25px!important;
  margin-bottom:13px!important;
}
#${ROOT} .senior-feature h3{
  margin:0 0 8px!important;
  color:#263029!important;
  font-size:22px!important;
  line-height:1.45!important;
  font-weight:950!important;
}
#${ROOT} .senior-feature p{
  margin:0!important;
  color:#6d746f!important;
  font-size:13px!important;
  line-height:1.95!important;
}
#${ROOT} .senior-points{
  display:grid!important;
  grid-template-columns:repeat(2,minmax(0,1fr))!important;
  gap:8px!important;
  margin-top:16px!important;
}
#${ROOT} .senior-points span{
  min-height:38px!important;
  padding:8px 10px!important;
  display:flex!important;
  align-items:center!important;
  border:1px solid #e5ece8!important;
  border-radius:11px!important;
  background:#fff!important;
  color:#53625a!important;
  font-size:11px!important;
  font-weight:800!important;
}
#${ROOT} .senior-feature-link{
  margin-top:16px!important;
  min-height:43px!important;
  padding:0 14px!important;
  display:flex!important;
  align-items:center!important;
  justify-content:center!important;
  text-decoration:none!important;
  border-radius:12px!important;
  background:#315f4a!important;
  color:#fff!important;
  font-size:13px!important;
  font-weight:900!important;
}
#${ROOT} .senior-main-paths{
  display:grid!important;
  grid-template-columns:repeat(2,minmax(0,1fr))!important;
  gap:8px!important;
  margin-top:16px!important;
}
#${ROOT} .senior-main-path{
  min-height:62px!important;
  padding:9px 10px!important;
  display:flex!important;
  align-items:center!important;
  gap:9px!important;
  text-decoration:none!important;
  border:1px solid #dfe9e3!important;
  border-radius:12px!important;
  background:#fff!important;
  color:#43554b!important;
}
#${ROOT} .senior-path-icon{
  flex:0 0 36px!important;
  width:36px!important;
  height:36px!important;
  display:grid!important;
  place-items:center!important;
  border-radius:10px!important;
  background:#edf5f0!important;
  font-size:17px!important;
}
#${ROOT} .senior-main-path strong{
  display:block!important;
  color:#2c3d34!important;
  font-size:11px!important;
  line-height:1.45!important;
  font-weight:950!important;
}
#${ROOT} .senior-main-path small{
  display:block!important;
  margin-top:2px!important;
  color:#758079!important;
  font-size:9px!important;
  line-height:1.45!important;
}
#${ROOT} .senior-grid{
  display:grid!important;
  grid-template-columns:repeat(2,minmax(0,1fr))!important;
  gap:11px!important;
}
#${ROOT} .senior-card{
  display:grid!important;
  grid-template-columns:112px minmax(0,1fr)!important;
  gap:12px!important;
  padding:11px!important;
  border:1px solid #ece5df!important;
  border-radius:17px!important;
  background:#fff!important;
  text-decoration:none!important;
  min-width:0!important;
}
#${ROOT} .senior-img{
  width:112px!important;
  height:112px!important;
  border-radius:13px!important;
  overflow:hidden!important;
  background:#fff!important;
}
#${ROOT} .senior-img img{
  display:block!important;
  width:100%!important;
  height:100%!important;
  object-fit:contain!important;
  padding:6px!important;
  transform:none!important;
  filter:none!important;
}
#${ROOT} .senior-info{
  min-width:0!important;
  display:flex!important;
  flex-direction:column!important;
}
#${ROOT} .senior-tag{
  align-self:flex-start!important;
  margin-bottom:5px!important;
  padding:4px 7px!important;
  border-radius:999px!important;
  background:#f3f6f4!important;
  color:#53705f!important;
  font-size:9px!important;
  font-weight:900!important;
}
#${ROOT} .senior-name{
  margin:0!important;
  color:#28221e!important;
  font-size:13px!important;
  line-height:1.55!important;
  font-weight:900!important;
  display:-webkit-box!important;
  -webkit-line-clamp:2!important;
  -webkit-box-orient:vertical!important;
  overflow:hidden!important;
}
#${ROOT} .senior-desc{
  margin:5px 0 8px!important;
  color:#82766e!important;
  font-size:10px!important;
  line-height:1.6!important;
  display:-webkit-box!important;
  -webkit-line-clamp:2!important;
  -webkit-box-orient:vertical!important;
  overflow:hidden!important;
}
#${ROOT} .senior-price{
  margin-top:auto!important;
  color:#c64e28!important;
  font-size:14px!important;
  font-weight:950!important;
}
#${ROOT} .senior-old{
  margin-inline-start:5px!important;
  color:#a89d95!important;
  font-size:10px!important;
  font-weight:700!important;
  text-decoration:line-through!important;
}
#${ROOT} .senior-cta{
  display:inline-flex!important;
  margin-top:7px!important;
  color:#315f4a!important;
  font-size:10px!important;
  font-weight:900!important;
}
#${ROOT} .senior-note{
  margin-top:13px!important;
  padding-top:12px!important;
  border-top:1px dashed #e6dfd9!important;
  color:#81756d!important;
  font-size:10px!important;
  line-height:1.8!important;
}
@media(max-width:900px){
  #${ROOT} .senior-layout{grid-template-columns:1fr!important}
}
@media(max-width:767px){
  #${ROOT}{
    width:calc(100% - 24px)!important;
    margin:0 12px 18px!important;
  }
  #${ROOT} .senior-shell{padding:15px!important;border-radius:19px!important}
  #${ROOT} .senior-head{align-items:flex-start!important;flex-direction:column!important}
  #${ROOT} h2{font-size:23px!important}
  #${ROOT} .senior-all{width:100%!important}
  #${ROOT} .senior-grid{
    display:flex!important;
    overflow-x:auto!important;
    gap:9px!important;
    padding-bottom:4px!important;
    scrollbar-width:none!important;
  }
  #${ROOT} .senior-grid::-webkit-scrollbar{display:none!important}
  #${ROOT} .senior-card{
    flex:0 0 86%!important;
    max-width:330px!important;
    grid-template-columns:94px minmax(0,1fr)!important;
  }
  #${ROOT} .senior-img{width:94px!important;height:94px!important}
  #${ROOT} .senior-points{grid-template-columns:1fr 1fr!important}
  #${ROOT} .senior-main-paths{grid-template-columns:1fr 1fr!important;gap:7px!important}
  #${ROOT} .senior-main-path{min-height:64px!important;padding:8px!important}
}
@media(prefers-reduced-motion:reduce){
  #${ROOT} *{animation:none!important;transition:none!important}
}
`;
  document.head.appendChild(s);
}

function card(p){
  return ''+
    '<a class="senior-card" href="'+p.url+'" aria-label="'+p.name.replace(/"/g,'&quot;')+'">'+
      '<span class="senior-img"><img loading="lazy" decoding="async" src="'+p.image+'" alt="'+p.name.replace(/"/g,'&quot;')+'"></span>'+
      '<span class="senior-info">'+
        '<span class="senior-tag">'+p.tag+'</span>'+
        '<strong class="senior-name">'+p.name+'</strong>'+
        '<span class="senior-desc">'+p.desc+'</span>'+
        '<span class="senior-price">'+p.price+(p.oldPrice?'<span class="senior-old">'+p.oldPrice+'</span>':'')+'</span>'+
        '<span class="senior-cta">شاهد المنتج ←</span>'+
      '</span>'+
    '</a>';
}

function build(){
  var sec=document.createElement('section');
  sec.id=ROOT;
  sec.setAttribute('aria-label','اختيارات للراحة والحركة لكبار السن');

  sec.innerHTML=''+
    '<div class="senior-shell">'+
      '<div class="senior-head">'+
        '<div>'+
          '<span class="senior-kicker">🤍 راحة واهتمام لكبار السن</span>'+
          '<h2>راحة واهتمام لكبار السن</h2>'+
          '<p class="senior-sub">زاوية مرتبة للوصول السريع إلى العكاز، البيدال والحركة المنزلية، دعم الركبة، ومنتجات الراحة والمساج.</p>'+
        '</div>'+
        '<a class="senior-all" href="https://barahstore.com/ar/search?q='+encodeURIComponent('راحة')+'">عرض كل الاختيارات ←</a>'+
      '</div>'+
      '<div class="senior-layout">'+
        '<div class="senior-feature">'+
          '<div>'+
            '<span class="senior-feature-icon">🧓</span>'+
            '<h3>كل ما يساعدهم على يوم أريح… في زاوية واحدة</h3>'+
            '<p>بدل البحث بين الأقسام، جمعنا أهم المسارات التي تخدم التنقل والحركة والدعم والراحة اليومية.</p>'+
            '<div class="senior-main-paths">'+
              '<a class="senior-main-path" href="https://barahstore.com/ar/search?q='+encodeURIComponent('عكاز')+'">'+
                '<span class="senior-path-icon">🦯</span><span><strong>العكاز والتنقل</strong><small>للمشي والحركة اليومية</small></span>'+
              '</a>'+
              '<a class="senior-main-path" href="https://barahstore.com/ar/search?q='+encodeURIComponent('بيدال')+'">'+
                '<span class="senior-path-icon">🚲</span><span><strong>البيدال والحركة</strong><small>حركة منزلية لليدين والساقين</small></span>'+
              '</a>'+
              '<a class="senior-main-path" href="https://barahstore.com/ar/search?q='+encodeURIComponent('ركبة')+'">'+
                '<span class="senior-path-icon">🦵</span><span><strong>دعم الركبة</strong><small>مشدات ودعامات قابلة للضبط</small></span>'+
              '</a>'+
              '<a class="senior-main-path" href="https://barahstore.com/ar/search?q='+encodeURIComponent('مساج')+'">'+
                '<span class="senior-path-icon">✦</span><span><strong>الراحة والمساج</strong><small>اختيارات للراحة والاسترخاء</small></span>'+
              '</a>'+
            '</div>'+
          '</div>'+
          '<a class="senior-feature-link" href="https://barahstore.com/ar/search?q='+encodeURIComponent('راحة')+'">استكشف اختيارات الراحة والاهتمام ←</a>'+
        '</div>'+
        '<div class="senior-grid">'+ITEMS.slice(0,4).map(card).join('')+'</div>'+
      '</div>'+
      '<div class="senior-note">ملاحظة: هذه المنتجات للاستخدام العام والراحة اليومية، وليست بديلًا عن التقييم أو المشورة الطبية عند الحاجة.</div>'+
    '</div>';

  return sec;
}

function visible(el){
  if(!el) return false;
  var cs=getComputedStyle(el);
  return cs.display!=='none' && cs.visibility!=='hidden';
}

function mount(){
  addStyle();

  var sec=document.getElementById(ROOT);
  if(!sec){
    sec=build();
  }

  var preg=document.getElementById('barah-step-pregnancy-v55');
  var conversion=document.getElementById('barah-step-conversion-v53');
  var smart=document.getElementById('barah-step-smart-storefront-v52') ||
            document.getElementById('barah-step-needs-v51');
  var main=document.querySelector('main') || document.body;

  if(preg && preg.parentNode && visible(preg)){
    if(preg.nextElementSibling!==sec) preg.insertAdjacentElement('afterend',sec);
  }else if(smart && smart.parentNode && visible(smart)){
    smart.insertAdjacentElement('afterend',sec);
  }else if(conversion && conversion.parentNode){
    conversion.insertAdjacentElement('beforebegin',sec);
  }else if(main && !sec.parentNode){
    main.appendChild(sec);
  }

  sec.style.display='block';
  sec.style.visibility='visible';
  sec.style.opacity='1';


  document.documentElement.setAttribute('data-barah-senior-v57','ready');
  return true;
}

function boot(){
  [0,300,800,1600,3200].forEach(function(ms){setTimeout(mount,ms);});
}
if(document.readyState==='loading') document.addEventListener('DOMContentLoaded',boot,{once:true});
else boot();
})();




/* ============================================================
   BARAH V61 — PREGNANCY STORY MERGE
   دمج أفضل فكرة من V42 داخل قسم الحمل V55 الموجود في V58
   بدون إنشاء قسم حمل مكرر
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V61_PREGNANCY_STORY__) return;
window.__BARAH_V61_PREGNANCY_STORY__=true;

var ROOT='barah-step-pregnancy-v55';
var STYLE='barah-v61-pregnancy-story-style';
var PREG='https://barahstore.com/ar/search?q='+encodeURIComponent('Pregnancy');
var BABY='https://barahstore.com/ar/baby-supplies/c2121151936?sort=bestSell';

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
#${ROOT} .barah-v61-story{
  display:grid!important;
  grid-template-columns:minmax(0,1.2fr) minmax(280px,.8fr)!important;
  gap:14px!important;
  margin-bottom:15px!important;
  padding:17px!important;
  border:1px solid rgba(244,140,86,.18)!important;
  border-radius:18px!important;
  background:linear-gradient(150deg,#fffdfa,#fff5ee)!important;
}
#${ROOT} .barah-v61-story-copy{
  display:flex!important;
  flex-direction:column!important;
  justify-content:center!important;
}
#${ROOT} .barah-v61-story-eyebrow{
  display:inline-flex!important;
  align-self:flex-start!important;
  padding:6px 10px!important;
  border-radius:999px!important;
  background:#fff1e8!important;
  color:#a95825!important;
  font-size:10px!important;
  font-weight:900!important;
  margin-bottom:9px!important;
}
#${ROOT} .barah-v61-story h3{
  margin:0!important;
  color:#251d18!important;
  font-size:22px!important;
  line-height:1.45!important;
  font-weight:950!important;
  display:block!important;
  max-height:none!important;
}
#${ROOT} .barah-v61-story-copy p{
  margin:8px 0 0!important;
  color:#74665f!important;
  font-size:12px!important;
  line-height:1.9!important;
}
#${ROOT} .barah-v61-story-actions{
  display:flex!important;
  flex-wrap:wrap!important;
  gap:8px!important;
  margin-top:13px!important;
}
#${ROOT} .barah-v61-story-actions a{
  min-height:39px!important;
  display:inline-flex!important;
  align-items:center!important;
  justify-content:center!important;
  padding:0 12px!important;
  border-radius:11px!important;
  text-decoration:none!important;
  font-size:11px!important;
  font-weight:900!important;
}
#${ROOT} .barah-v61-story-actions .main{
  color:#fff!important;
  background:linear-gradient(135deg,#ff7a18,#ef4444)!important;
}
#${ROOT} .barah-v61-story-actions .alt{
  color:#694f40!important;
  background:#fff!important;
  border:1px solid #eddcd0!important;
}
#${ROOT} .barah-v61-story-points{
  display:grid!important;
  grid-template-columns:1fr!important;
  gap:8px!important;
}
#${ROOT} .barah-v61-story-point{
  min-height:62px!important;
  padding:10px 11px!important;
  border:1px solid #f0e1d8!important;
  border-radius:13px!important;
  background:#fff!important;
}
#${ROOT} .barah-v61-story-point strong{
  display:block!important;
  color:#352a24!important;
  font-size:11px!important;
  font-weight:900!important;
  margin-bottom:3px!important;
}
#${ROOT} .barah-v61-story-point span{
  display:block!important;
  color:#7e7068!important;
  font-size:9.5px!important;
  line-height:1.7!important;
}
#${ROOT} .barah-v61-chip-row{
  display:flex!important;
  gap:7px!important;
  overflow-x:auto!important;
  padding:0 0 3px!important;
  margin:0 0 14px!important;
  scrollbar-width:none!important;
}
#${ROOT} .barah-v61-chip-row::-webkit-scrollbar{display:none!important}
#${ROOT} .barah-v61-chip-row a{
  flex:0 0 auto!important;
  min-height:34px!important;
  display:flex!important;
  align-items:center!important;
  padding:0 10px!important;
  border:1px solid #eadfd7!important;
  border-radius:999px!important;
  background:#fff!important;
  color:#66574e!important;
  text-decoration:none!important;
  font-size:10px!important;
  font-weight:850!important;
}
@media(max-width:900px){
  #${ROOT} .barah-v61-story{grid-template-columns:1fr!important}
  #${ROOT} .barah-v61-story-points{grid-template-columns:repeat(3,minmax(0,1fr))!important}
}
@media(max-width:767px){
  #${ROOT} .barah-v61-story{padding:13px!important;border-radius:15px!important}
  #${ROOT} .barah-v61-story h3{font-size:19px!important}
  #${ROOT} .barah-v61-story-points{grid-template-columns:1fr!important}
  #${ROOT} .barah-v61-story-actions{display:grid!important;grid-template-columns:1fr 1fr!important}
}
`;
  document.head.appendChild(s);
}

function enhance(){
  addStyle();
  var root=document.getElementById(ROOT);
  if(!root) return false;
  var shell=root.querySelector('.preg-shell');
  var grid=root.querySelector('.preg-grid');
  if(!shell || !grid) return false;

  if(!root.querySelector('.barah-v61-story')){
    var story=document.createElement('div');
    story.className='barah-v61-story';
    story.innerHTML=''+
      '<div class="barah-v61-story-copy">'+
        '<span class="barah-v61-story-eyebrow">🤍 ركن أهدأ للأم والحوامل</span>'+
        '<h3>لأن الراحة تبدأ من التفاصيل الصغيرة</h3>'+
        '<p>بدل البحث بين عشرات الأقسام، جمعنا لك طريقًا أسرع لاختيارات الحمل والراحة وبداية تجهيز الطفل؛ ثم أبقينا المنتجات الفعلية تحتها لتنتقلي مباشرة لما يناسبك.</p>'+
        '<div class="barah-v61-story-actions">'+
          '<a class="main" href="'+PREG+'">اختيارات الحمل ←</a>'+
          '<a class="alt" href="'+BABY+'">مستلزمات الطفل</a>'+
        '</div>'+
      '</div>'+
      '<div class="barah-v61-story-points">'+
        '<div class="barah-v61-story-point"><strong>راحة الحمل</strong><span>وسائد ودعم واختيارات للاستخدام اليومي.</span></div>'+
        '<div class="barah-v61-story-point"><strong>بداية تجهيز الطفل</strong><span>اختصار مباشر للمستلزمات الأساسية والعملية.</span></div>'+
        '<div class="barah-v61-story-point"><strong>تنقل أسهل</strong><span>مسار أسرع لما يفيد في الخروج والسفر مع الطفل.</span></div>'+
      '</div>';
    shell.insertBefore(story,grid);
  }

  if(!root.querySelector('.barah-v61-chip-row')){
    var chips=document.createElement('div');
    chips.className='barah-v61-chip-row';
    chips.innerHTML=''+
      '<a href="'+PREG+'">دعم الحمل</a>'+
      '<a href="https://barahstore.com/ar/search?q='+encodeURIComponent('وسادة حمل')+'">وسائد الحمل</a>'+
      '<a href="https://barahstore.com/ar/search?q='+encodeURIComponent('ما بعد الولادة')+'">ما بعد الولادة</a>'+
      '<a href="'+BABY+'">مستلزمات الطفل</a>'+
      '<a href="https://barahstore.com/ar/search?q='+encodeURIComponent('سفر طفل')+'">السفر والتنقل</a>';
    shell.insertBefore(chips,grid);
  }

  /* النص الأعلى يصبح مختصرًا لأن القصة أصبحت داخل القسم */
  var head=root.querySelector('.preg-head');
  if(head){
    var h2=head.querySelector('h2');
    var sub=head.querySelector('.preg-sub');
    if(h2) h2.textContent='اختيارات الحمل والراحة… في مكان واحد';
    if(sub) sub.textContent='منتجات فعلية من بارعة، ومسارات أسرع للحمل والراحة وبداية تجهيز الطفل.';
  }
  return true;
}

function boot(){
  [0,300,800,1600,3000,5200].forEach(function(ms){setTimeout(enhance,ms);});
}
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',boot,{once:true});
else boot();
})();

/* ============================================================
   BARAH STORE — MASTER V56
   FINAL INTEGRATION / LAUNCH ORDER / LEGACY CONFLICT GUARD
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_MASTER_V56__) return;
window.__BARAH_MASTER_V56__=true;

var STYLE='barah-master-v56-style';
var HIDE=[
  'barah-step-discovery-v15',
  'barah-step-personal-v18',
  'barah-step-gateway-v36',
  'barah-step-smart-showcase-v38',
  'barah-step-smart-storefront-v44',
  'barah-step-home-v9',
  'barah-step-interest-v46',
  'barah-step-modes-v19',
  'barah-step-orchestrator-v20',
  'barah-step-editorial-v17',
  'barah-step-catalog-cta-v21',
  'barah-step-wholesale-v16'
];

function isHome(){
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  return p==='/' || p==='/ar' || p==='/en' || (location.hostname==='salla.sa' && /^\/br1$/.test(p));
}
if(!isHome()) return;

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
${HIDE.map(function(id){return '#'+id;}).join(',\n')}{display:none!important}

/* consistent launch width / rhythm */
#barah-step-hero-v12,
#barah-step-shipping-v24,
#barah-step-smart-storefront-v52,
#barah-step-needs-v51,
#barah-step-pregnancy-v55,
#barah-step-senior-v57,
#barah-step-conversion-v53,
#barah-step-season-v49,
section.home-block.home-block--fixed-products.show-all.barah-v35-latest,
#barah-step-most-viewed,
#barah-step-special-suggestion-v48,
#barah-step-catalog-v32,
#barah-step-wholesale-v32{
  width:min(1240px,calc(100% - 32px))!important;
  max-width:1240px!important;
  margin-left:auto!important;
  margin-right:auto!important;
}

/* preserve Salla native card internals: only section layout */
section.home-block.home-block--fixed-products.show-all.barah-v35-latest
.grid-block.products-list-container.vertical-products{
  align-items:start!important;
}
section.home-block.home-block--fixed-products.show-all.barah-v35-latest
custom-salla-product-card.product-block{
  min-width:0!important;
}

/* visual identity consistency */
#barah-step-hero-v12 .barah-hero-shell,
#barah-step-shipping-v24 .barah-v24-shell,
#barah-step-needs-v51 .barah-v51-shell,
#barah-step-pregnancy-v55 .preg-shell,
#barah-step-senior-v57 .senior-shell,
#barah-step-conversion-v53 .barah-v53-shell,
#barah-step-season-v49 .barah-v49-shell,
#barah-step-most-viewed,
#barah-step-special-suggestion-v48,
#barah-step-catalog-v32 .v32box,
#barah-step-wholesale-v32 .v32box{
  border-color:#eadfd7!important;
}

/* no unwanted product image hover color/movement in custom shelves */
#barah-step-most-viewed img,
#barah-step-special-suggestion-v48 img,
#barah-step-pregnancy-v55 img,
#barah-step-senior-v57 img{
  filter:none!important;
  mix-blend-mode:normal!important;
}
@media(hover:hover){
  #barah-step-most-viewed img,
  #barah-step-special-suggestion-v48 img,
  #barah-step-pregnancy-v55 img,
#barah-step-senior-v57 img{
    transform:none!important;
  }
}

/* mobile rhythm */
@media(max-width:767px){
  #barah-step-hero-v12,
  #barah-step-shipping-v24,
  #barah-step-smart-storefront-v52,
  #barah-step-needs-v51,
  #barah-step-pregnancy-v55,
  #barah-step-senior-v57,
  #barah-step-conversion-v53,
  #barah-step-season-v49,
  section.home-block.home-block--fixed-products.show-all.barah-v35-latest,
  #barah-step-most-viewed,
  #barah-step-special-suggestion-v48,
  #barah-step-catalog-v32,
  #barah-step-wholesale-v32{
    width:calc(100% - 24px)!important;
    margin-left:12px!important;
    margin-right:12px!important;
  }
}
@media(prefers-reduced-motion:reduce){
  #barah-step-hero-v12 *,
  #barah-step-needs-v51 *,
  #barah-step-pregnancy-v55 *,
  #barah-step-senior-v57 *,
  #barah-step-conversion-v53 *,
  #barah-step-most-viewed *,
  #barah-step-special-suggestion-v48 *{
    transition:none!important;
    animation:none!important;
    scroll-behavior:auto!important;
  }
}
`;
  document.head.appendChild(s);
}

function latest(){
  var secs=Array.prototype.slice.call(document.querySelectorAll('section.home-block.home-block--fixed-products.show-all'));
  return secs.find(function(sec){
    var t=(sec.textContent||'').replace(/\s+/g,' ').trim();
    return t.indexOf('وصل حديث')!==-1 || t.indexOf('أحدث المنتجات')!==-1 || t.indexOf('اكتشفها أولاً')!==-1;
  }) || document.querySelector('section.home-block.home-block--fixed-products.show-all.barah-v35-latest') || secs[0] || null;
}

function visibleNode(id){
  var el=document.getElementById(id);
  if(!el) return null;
  if(HIDE.indexOf(id)!==-1) return null;
  return el;
}

function moveAfter(cur,node){
  if(!cur || !node || !cur.parentNode) return cur;
  if(cur.nextElementSibling!==node) cur.insertAdjacentElement('afterend',node);
  return node;
}

function arrange(){
  addStyle();
  var main=document.querySelector('main');
  if(!main) return false;

  HIDE.forEach(function(id){
    var n=document.getElementById(id);
    if(n) n.setAttribute('data-barah-v56-hidden','1');
  });

  var hero=visibleNode('barah-step-hero-v12');
  if(!hero || !hero.parentNode) return false;

  var cur=hero;
  cur=moveAfter(cur,visibleNode('barah-step-shipping-v24'));

  /* prefer the new smart storefront if present, otherwise needs V51 */
  var smart=visibleNode('barah-step-smart-storefront-v52') || visibleNode('barah-step-needs-v51');
  cur=moveAfter(cur,smart);

  /* FINAL MOBILE-FIRST SWAP ONLY:
     Most Viewed takes Pregnancy's old slot.
     Pregnancy moves to Most Viewed's old slot.
     On mobile, Senior is reserved for the official final position
     immediately before footer. Desktop keeps its current position. */
  cur=moveAfter(cur,visibleNode('barah-step-most-viewed'));

  var mobile=window.matchMedia && window.matchMedia('(max-width: 767px)').matches;
  var senior=visibleNode('barah-step-senior-v57');

  if(!mobile){
    cur=moveAfter(cur,senior);
  }

  /* decision/season are hidden by launch layers; keep compatibility */
  cur=moveAfter(cur,visibleNode('barah-step-conversion-v53'));
  cur=moveAfter(cur,visibleNode('barah-step-season-v49'));

  var l=latest();
  if(l){
    l.classList.add('barah-v35-latest');
    cur=moveAfter(cur,l);
  }

  /* Pregnancy takes the old Most Viewed position */
  cur=moveAfter(cur,visibleNode('barah-step-pregnancy-v55'));

  cur=moveAfter(cur,visibleNode('barah-step-special-suggestion-v48'));

  /* FINAL FOOTER PAIR:
     catalog -> wholesale -> footer
     keep both sections together at the absolute bottom of the homepage */
  var catalog=visibleNode('barah-step-catalog-v32');
  var wholesale=visibleNode('barah-step-wholesale-v32');
  var footer=document.querySelector('footer');

  if(footer && footer.parentNode){
    if(catalog){
      footer.insertAdjacentElement('beforebegin',catalog);
    }
    if(wholesale){
      footer.insertAdjacentElement('beforebegin',wholesale);
    }

    if(mobile && senior){
      /* MOBILE OFFICIAL ENDING:
         catalog -> wholesale -> senior care -> footer */
      footer.insertAdjacentElement('beforebegin',senior);

      if(catalog && wholesale && wholesale.previousElementSibling!==catalog){
        wholesale.insertAdjacentElement('beforebegin',catalog);
      }
      if(wholesale && senior.previousElementSibling!==wholesale){
        senior.insertAdjacentElement('beforebegin',wholesale);
      }
      if(footer.previousElementSibling!==senior){
        footer.insertAdjacentElement('beforebegin',senior);
      }
    }else{
      /* Desktop remains unchanged: catalog -> wholesale -> footer */
      if(catalog && wholesale && wholesale.previousElementSibling!==catalog){
        wholesale.insertAdjacentElement('beforebegin',catalog);
      }
      if(wholesale && footer.previousElementSibling!==wholesale){
        footer.insertAdjacentElement('beforebegin',wholesale);
      }
      if(catalog && !wholesale && footer.previousElementSibling!==catalog){
        footer.insertAdjacentElement('beforebegin',catalog);
      }
    }
  }else{
    cur=moveAfter(cur,catalog);
    cur=moveAfter(cur,wholesale);
    if(mobile) cur=moveAfter(cur,senior);
  }

  document.documentElement.setAttribute('data-barah-master-v61-footer-pair','ready');
  document.documentElement.setAttribute('data-barah-master-v56','ready');
  return true;
}

function boot(){
  var delays=[0,250,650,1200,2200,3800,6000,8500];
  delays.forEach(function(ms){setTimeout(arrange,ms);});
}
if(document.readyState==='loading') document.addEventListener('DOMContentLoaded',boot,{once:true});
else boot();
})();





/* ============================================================
   BARAH V61.1 — FOOTER PAIR FINAL POSITION
   catalog -> wholesale -> footer
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V611_FOOTER_PAIR__) return;
window.__BARAH_V611_FOOTER_PAIR__=true;

var STYLE='barah-v611-footer-pair-style';

function style(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
#barah-step-catalog-v32{
  margin-top:18px!important;
  margin-bottom:10px!important;
}
#barah-step-wholesale-v32{
  margin-top:0!important;
  margin-bottom:22px!important;
}
footer{
  margin-top:0!important;
}
@media(max-width:767px){
  #barah-step-catalog-v32{
    margin-top:14px!important;
    margin-bottom:8px!important;
  }
  #barah-step-wholesale-v32{
    margin-bottom:16px!important;
  }
}
`;
  document.head.appendChild(s);
}

function place(){
  style();
  var catalog=document.getElementById('barah-step-catalog-v32');
  var wholesale=document.getElementById('barah-step-wholesale-v32');
  var footer=document.querySelector('footer');
  if(!footer || !footer.parentNode) return false;

  if(catalog) footer.insertAdjacentElement('beforebegin',catalog);
  if(wholesale) footer.insertAdjacentElement('beforebegin',wholesale);

  if(catalog && wholesale && wholesale.previousElementSibling!==catalog){
    wholesale.insertAdjacentElement('beforebegin',catalog);
  }
  if(wholesale && footer.previousElementSibling!==wholesale){
    footer.insertAdjacentElement('beforebegin',wholesale);
  }else if(catalog && !wholesale && footer.previousElementSibling!==catalog){
    footer.insertAdjacentElement('beforebegin',catalog);
  }

  document.documentElement.setAttribute(
    'data-barah-v611-footer-pair',
    (catalog && wholesale && footer.previousElementSibling===wholesale && wholesale.previousElementSibling===catalog)
      ? 'ready'
      : 'partial'
  );
  return true;
}

function boot(){
  [0,300,800,1600,3200,6000,9000].forEach(function(ms){setTimeout(place,ms);});
}
if(document.readyState==='loading') document.addEventListener('DOMContentLoaded',boot,{once:true});
else boot();
})();


/* ============================================================
   BARAH V61.3 — CORE INTEGRATED FIX
   Home button is inside HERO.
   Senior 4-path angle is built directly in the original section.
   No late DOM-upgrade layer required.
   ============================================================ */


/* ============================================================
   BARAH V61.5 — FINAL HOMEPAGE ORDER + RESPONSIVE + LINK GUARD
   Final storefront sequence:
   Hero -> Shipping -> Smart Needs -> Pregnancy -> Senior ->
   Most Viewed -> Latest -> Catalog -> Wholesale -> Footer
   Redundant conversion/season/special blocks hidden for clarity.
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V615_FINAL_HOME__) return;
window.__BARAH_V615_FINAL_HOME__=true;

var STYLE='barah-v615-final-home-style';

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
/* ---------- page rhythm ---------- */
#barah-step-hero-v12,
#barah-step-shipping-v24,
#barah-step-smart-storefront-v52,
#barah-step-needs-v51,
#barah-step-pregnancy-v55,
#barah-step-senior-v57,
#barah-step-most-viewed,
section.home-block.home-block--fixed-products.show-all.barah-v35-latest,
#barah-step-catalog-v32,
#barah-step-wholesale-v32{
  width:min(1180px,calc(100% - 36px))!important;
  max-width:1180px!important;
  margin-left:auto!important;
  margin-right:auto!important;
  margin-top:0!important;
  margin-bottom:18px!important;
}

/* remove redundant middle blocks from the final homepage */
#barah-step-conversion-v53,
#barah-step-season-v49,
#barah-step-special-suggestion-v48{
  display:none!important;
}

/* hero: compact and balanced */
#barah-step-hero-v12 .barah-hero-shell{
  min-height:0!important;
  padding:22px!important;
  grid-template-columns:1.05fr .95fr!important;
  gap:16px!important;
}
#barah-step-hero-v12 .barah-hero-copy{
  min-height:260px!important;
}
#barah-step-hero-v12 h1{
  font-size:34px!important;
  line-height:1.32!important;
}
#barah-step-hero-v12 .barah-hero-copy p{
  font-size:14px!important;
  margin-bottom:16px!important;
}
#barah-step-hero-v12 .barah-hero-product strong{
  min-height:42px!important;
  font-size:12px!important;
}

/* shipping */
#barah-step-shipping-v24 .barah-v24-shell{
  padding:13px 16px!important;
}

/* needs / storefront */
#barah-step-smart-storefront-v52,
#barah-step-needs-v51{
  scroll-margin-top:90px!important;
}

/* pregnancy and senior: same visual scale */
#barah-step-pregnancy-v55 .preg-shell,
#barah-step-senior-v57 .v614-shell,
#barah-step-senior-v57 .senior-shell{
  padding:18px!important;
  border-radius:20px!important;
}
#barah-step-pregnancy-v55 h2,
#barah-step-senior-v57 h2{
  font-size:24px!important;
  line-height:1.4!important;
}
#barah-step-pregnancy-v55 .preg-grid,
#barah-step-senior-v57 .v614-grid{
  gap:10px!important;
}

/* Senior four paths — desktop */
#barah-step-senior-v57 .v614-grid{
  grid-template-columns:repeat(4,minmax(0,1fr))!important;
}
#barah-step-senior-v57 .v614-path{
  min-height:118px!important;
}

/* Most viewed */
#barah-step-most-viewed{
  padding:18px!important;
  border-radius:20px!important;
}
#barah-step-most-viewed .barah-step-most-viewed__track{
  grid-template-columns:repeat(4,minmax(0,1fr))!important;
  gap:10px!important;
}
#barah-step-most-viewed .barah-step-most-viewed__card{
  min-width:0!important;
  border-radius:14px!important;
}
#barah-step-most-viewed .barah-step-most-viewed__product img{
  height:110px!important;
  object-fit:contain!important;
  filter:none!important;
  transform:none!important;
}

/* Latest: keep Salla native card internals, only control layout */
section.home-block.home-block--fixed-products.show-all.barah-v35-latest{
  padding:18px!important;
  border-radius:20px!important;
}
section.barah-v35-latest .barah-v35-latest-head{
  margin-bottom:14px!important;
}
section.barah-v35-latest .grid-block.products-list-container.vertical-products{
  display:grid!important;
  grid-template-columns:repeat(4,minmax(0,1fr))!important;
  gap:12px!important;
  overflow:visible!important;
}
section.barah-v35-latest custom-salla-product-card.product-block{
  width:100%!important;
  max-width:none!important;
  min-width:0!important;
  margin:0!important;
}

/* Footer pair: tighter visual finish */
#barah-step-catalog-v32{
  margin-top:22px!important;
  margin-bottom:9px!important;
}
#barah-step-wholesale-v32{
  margin-top:0!important;
  margin-bottom:18px!important;
}
#barah-step-catalog-v32 .v32box,
#barah-step-wholesale-v32 .v32box{
  padding:15px 18px!important;
  border-radius:18px!important;
}

/* Every clickable primary/secondary action should look intentional */
#barah-step-hero-v12 a,
#barah-step-shipping-v24 a,
#barah-step-smart-storefront-v52 a,
#barah-step-needs-v51 a,
#barah-step-pregnancy-v55 a,
#barah-step-senior-v57 a,
#barah-step-most-viewed a,
section.barah-v35-latest a,
#barah-step-catalog-v32 a,
#barah-step-wholesale-v32 a{
  -webkit-tap-highlight-color:transparent!important;
}

/* ---------- tablet ---------- */
@media(max-width:1050px){
  #barah-step-hero-v12 .barah-hero-shell{
    grid-template-columns:1fr!important;
  }
  #barah-step-hero-v12 .barah-hero-copy{
    min-height:auto!important;
  }
  #barah-step-most-viewed .barah-step-most-viewed__track,
  section.barah-v35-latest .grid-block.products-list-container.vertical-products{
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
  }
}

/* ---------- mobile ---------- */
@media(max-width:767px){
  #barah-step-hero-v12,
  #barah-step-shipping-v24,
  #barah-step-smart-storefront-v52,
  #barah-step-needs-v51,
  #barah-step-pregnancy-v55,
  #barah-step-senior-v57,
  #barah-step-most-viewed,
  section.home-block.home-block--fixed-products.show-all.barah-v35-latest,
  #barah-step-catalog-v32,
  #barah-step-wholesale-v32{
    width:calc(100% - 24px)!important;
    margin-left:12px!important;
    margin-right:12px!important;
    margin-bottom:14px!important;
  }

  #barah-step-hero-v12 .barah-hero-shell{
    padding:14px!important;
    border-radius:18px!important;
  }
  #barah-step-hero-v12 h1{
    font-size:25px!important;
  }
  #barah-step-hero-v12 .barah-hero-products{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:8px!important;
  }

  #barah-step-pregnancy-v55 .preg-shell,
  #barah-step-senior-v57 .v614-shell,
  #barah-step-senior-v57 .senior-shell{
    padding:13px!important;
    border-radius:17px!important;
  }
  #barah-step-pregnancy-v55 h2,
  #barah-step-senior-v57 h2{
    font-size:21px!important;
  }

  /* senior paths stay readable as 2 x 2 */
  #barah-step-senior-v57 .v614-grid{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:7px!important;
  }
  #barah-step-senior-v57 .v614-path{
    min-height:116px!important;
    padding:10px!important;
  }

  /* most viewed: horizontal browse */
  #barah-step-most-viewed{
    padding:13px!important;
  }
  #barah-step-most-viewed .barah-step-most-viewed__track{
    display:flex!important;
    overflow-x:auto!important;
    gap:9px!important;
    scroll-snap-type:x mandatory!important;
    scrollbar-width:none!important;
    padding-bottom:3px!important;
  }
  #barah-step-most-viewed .barah-step-most-viewed__track::-webkit-scrollbar{
    display:none!important;
  }
  #barah-step-most-viewed .barah-step-most-viewed__card{
    flex:0 0 78%!important;
    max-width:260px!important;
    scroll-snap-align:start!important;
  }

  /* latest: native Salla cards in horizontal rail */
  section.home-block.home-block--fixed-products.show-all.barah-v35-latest{
    padding:13px 11px!important;
  }
  section.barah-v35-latest .grid-block.products-list-container.vertical-products{
    display:flex!important;
    overflow-x:auto!important;
    gap:9px!important;
    scroll-snap-type:x mandatory!important;
    scrollbar-width:none!important;
    padding-bottom:4px!important;
  }
  section.barah-v35-latest .grid-block.products-list-container.vertical-products::-webkit-scrollbar{
    display:none!important;
  }
  section.barah-v35-latest custom-salla-product-card.product-block{
    flex:0 0 68%!important;
    max-width:215px!important;
    scroll-snap-align:start!important;
  }

  #barah-step-catalog-v32 .v32box,
  #barah-step-wholesale-v32 .v32box{
    padding:13px!important;
    border-radius:16px!important;
  }
}

@media(max-width:420px){
  #barah-step-senior-v57 .v614-grid{
    grid-template-columns:1fr 1fr!important;
  }
  section.barah-v35-latest custom-salla-product-card.product-block{
    flex-basis:72%!important;
    max-width:205px!important;
  }
}
`;
  document.head.appendChild(s);
}

function node(id){ return document.getElementById(id); }

function moveAfter(cur,n){
  if(!cur || !n || !cur.parentNode) return cur;
  if(cur.nextElementSibling!==n) cur.insertAdjacentElement('afterend',n);
  return n;
}

function latest(){
  return document.querySelector('section.home-block.home-block--fixed-products.show-all.barah-v35-latest') ||
         Array.prototype.slice.call(document.querySelectorAll('section.home-block.home-block--fixed-products.show-all')).find(function(sec){
           var t=(sec.textContent||'').replace(/\s+/g,' ').trim();
           return t.indexOf('وصل حديث')!==-1 || t.indexOf('أحدث المنتجات')!==-1 || t.indexOf('اكتشفها أولاً')!==-1;
         }) || null;
}

function arrangeFinal(){
  addStyle();

  var hero=node('barah-step-hero-v12');
  if(!hero || !hero.parentNode) return false;

  var cur=hero;
  cur=moveAfter(cur,node('barah-step-shipping-v24'));

  var smart=node('barah-step-smart-storefront-v52') || node('barah-step-needs-v51');
  cur=moveAfter(cur,smart);

  cur=moveAfter(cur,node('barah-step-pregnancy-v55'));
  cur=moveAfter(cur,node('barah-step-senior-v57'));
  cur=moveAfter(cur,node('barah-step-most-viewed'));

  var l=latest();
  if(l){
    l.classList.add('barah-v35-latest');
    cur=moveAfter(cur,l);
  }

  /* hard-hide duplicate/redundant sections */
  ['barah-step-conversion-v53','barah-step-season-v49','barah-step-special-suggestion-v48'].forEach(function(id){
    var x=node(id);
    if(x) x.style.setProperty('display','none','important');
  });

  /* exact footer pair */
  var catalog=node('barah-step-catalog-v32');
  var wholesale=node('barah-step-wholesale-v32');
  var footer=document.querySelector('footer');

  if(footer && footer.parentNode){
    if(catalog) footer.insertAdjacentElement('beforebegin',catalog);
    if(wholesale) footer.insertAdjacentElement('beforebegin',wholesale);

    if(catalog && wholesale && wholesale.previousElementSibling!==catalog){
      wholesale.insertAdjacentElement('beforebegin',catalog);
    }
    if(wholesale && footer.previousElementSibling!==wholesale){
      footer.insertAdjacentElement('beforebegin',wholesale);
    }else if(catalog && !wholesale && footer.previousElementSibling!==catalog){
      footer.insertAdjacentElement('beforebegin',catalog);
    }
  }

  document.documentElement.setAttribute('data-barah-v615-order','ready');
  return true;
}

/* Repair/validate anchors without changing valid Salla links */
function validateLinks(){
  var scopes=[
    '#barah-step-hero-v12',
    '#barah-step-shipping-v24',
    '#barah-step-smart-storefront-v52',
    '#barah-step-needs-v51',
    '#barah-step-pregnancy-v55',
    '#barah-step-senior-v57',
    '#barah-step-most-viewed',
    'section.barah-v35-latest',
    '#barah-step-catalog-v32',
    '#barah-step-wholesale-v32'
  ].join(',');

  var rootNodes=document.querySelectorAll(scopes);
  var checked=0,invalid=0;

  rootNodes.forEach(function(root){
    root.querySelectorAll('a').forEach(function(a){
      checked++;
      var raw=(a.getAttribute('href')||'').trim();

      if(!raw || raw==='#' || /^javascript:/i.test(raw)){
        invalid++;
        a.setAttribute('aria-disabled','true');
        a.style.pointerEvents='none';
        a.style.opacity='.55';
        return;
      }

      try{
        var u=new URL(raw,location.origin);
        if(u.protocol!=='http:' && u.protocol!=='https:'){
          invalid++;
          a.setAttribute('aria-disabled','true');
          a.style.pointerEvents='none';
          a.style.opacity='.55';
          return;
        }
        /* normalize store-internal relative URLs only */
        if(u.hostname===location.hostname || u.hostname==='barahstore.com'){
          a.href=u.href;
        }
        a.removeAttribute('aria-disabled');
        a.style.removeProperty('pointer-events');
        a.style.removeProperty('opacity');
      }catch(e){
        invalid++;
        a.setAttribute('aria-disabled','true');
        a.style.pointerEvents='none';
        a.style.opacity='.55';
      }
    });
  });

  document.documentElement.setAttribute('data-barah-v615-links',invalid?'partial':'ready');
  document.documentElement.setAttribute('data-barah-v615-links-checked',String(checked));
  document.documentElement.setAttribute('data-barah-v615-links-invalid',String(invalid));
  return invalid===0;
}

function run(){
  arrangeFinal();
  validateLinks();
}

function boot(){
  [0,250,650,1200,2200,3800,6000,9000].forEach(function(ms){setTimeout(run,ms);});
}
if(document.readyState==='loading') document.addEventListener('DOMContentLoaded',boot,{once:true});
else boot();

})();


/* ============================================================
   BARAH V61.6 — HYBRID DISCOVERY UPGRADE
   Best of new design + useful discovery ideas from active store.
   Adds compact category shortcuts + store search after shipping.
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V616_HYBRID_DISCOVERY__) return;
window.__BARAH_V616_HYBRID_DISCOVERY__=true;

var ROOT='barah-v616-quick-discovery';
var STYLE='barah-v616-quick-discovery-style';

var CATS=[
  ['⌂','المنزل والمطبخ','https://barahstore.com/ar/home-kitchen/c127906256'],
  ['✦','العناية والأناقة','https://barahstore.com/ar/care-style/c727852954'],
  ['⚡','الرياضة واللياقة','https://barahstore.com/ar/fitness/c511828448'],
  ['✈','السفر والرحلات','https://barahstore.com/ar/travel/c336613091'],
  ['◈','السيارة','https://barahstore.com/ar/car/c228633582'],
  ['★','الطفل والألعاب','https://barahstore.com/ar/baby-toys/c694872552'],
  ['♡','الحيوانات الأليفة','https://barahstore.com/ar/pets/c92693286'],
  ['❄','موسم الشتاء','https://barahstore.com/ar/offers/c558473504']
];

function style(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
#${ROOT}{
  direction:rtl!important;
  width:min(1180px,calc(100% - 36px))!important;
  max-width:1180px!important;
  margin:0 auto 18px!important;
  box-sizing:border-box!important;
  font-family:inherit!important;
}
#${ROOT} *{box-sizing:border-box!important}
#${ROOT} .v616-shell{
  padding:14px 15px!important;
  border:1px solid #eadfd7!important;
  border-radius:18px!important;
  background:linear-gradient(180deg,#fff,#fffaf6)!important;
  box-shadow:0 9px 22px rgba(35,24,18,.035)!important;
}
#${ROOT} .v616-top{
  display:flex!important;
  align-items:center!important;
  justify-content:space-between!important;
  gap:12px!important;
  margin-bottom:11px!important;
}
#${ROOT} .v616-title{
  display:flex!important;
  align-items:center!important;
  gap:8px!important;
  color:#261d18!important;
  font-size:14px!important;
  font-weight:950!important;
}
#${ROOT} .v616-title small{
  color:#85776f!important;
  font-size:10px!important;
  font-weight:700!important;
}
#${ROOT} .v616-all{
  flex:0 0 auto!important;
  min-height:34px!important;
  padding:0 10px!important;
  display:inline-flex!important;
  align-items:center!important;
  justify-content:center!important;
  border:1px solid #eadfd7!important;
  border-radius:9px!important;
  background:#fff!important;
  color:#4d4038!important;
  text-decoration:none!important;
  font-size:10px!important;
  font-weight:900!important;
}
#${ROOT} .v616-cats{
  display:flex!important;
  gap:7px!important;
  overflow-x:auto!important;
  scrollbar-width:none!important;
  padding-bottom:2px!important;
}
#${ROOT} .v616-cats::-webkit-scrollbar{display:none!important}
#${ROOT} .v616-cat{
  flex:0 0 auto!important;
  min-height:38px!important;
  padding:0 11px!important;
  display:inline-flex!important;
  align-items:center!important;
  gap:6px!important;
  border:1px solid #eee3dc!important;
  border-radius:11px!important;
  background:#fff!important;
  color:#43372f!important;
  text-decoration:none!important;
  font-size:10.5px!important;
  font-weight:850!important;
  white-space:nowrap!important;
}
#${ROOT} .v616-cat i{
  width:23px!important;
  height:23px!important;
  display:grid!important;
  place-items:center!important;
  border-radius:7px!important;
  background:#fff2e8!important;
  color:#d75a25!important;
  font-style:normal!important;
  font-size:11px!important;
}
#${ROOT} .v616-search{
  display:flex!important;
  gap:7px!important;
  margin-top:10px!important;
  padding-top:10px!important;
  border-top:1px dashed #ebdfd7!important;
}
#${ROOT} .v616-search input{
  flex:1!important;
  min-width:0!important;
  height:40px!important;
  padding:0 12px!important;
  border:1px solid #e9ddd4!important;
  border-radius:10px!important;
  background:#fff!important;
  color:#2d241f!important;
  outline:none!important;
  font:inherit!important;
  font-size:11.5px!important;
}
#${ROOT} .v616-search button{
  flex:0 0 auto!important;
  height:40px!important;
  padding:0 14px!important;
  border:0!important;
  border-radius:10px!important;
  background:linear-gradient(135deg,#ff7a18,#ef4444)!important;
  color:#fff!important;
  cursor:pointer!important;
  font:inherit!important;
  font-size:11px!important;
  font-weight:950!important;
}
@media(max-width:767px){
  #${ROOT}{
    width:calc(100% - 24px)!important;
    margin-left:12px!important;
    margin-right:12px!important;
    margin-bottom:14px!important;
  }
  #${ROOT} .v616-shell{padding:12px!important;border-radius:16px!important}
  #${ROOT} .v616-top{align-items:flex-start!important}
  #${ROOT} .v616-title{flex-direction:column!important;align-items:flex-start!important;gap:2px!important}
  #${ROOT} .v616-search{flex-direction:column!important}
  #${ROOT} .v616-search button{width:100%!important}
}
`;
  document.head.appendChild(s);
}

function build(){
  var x=document.getElementById(ROOT);
  if(x) return x;

  x=document.createElement('section');
  x.id=ROOT;
  x.setAttribute('aria-label','وصول سريع لأقسام بارعة');

  x.innerHTML=
    '<div class="v616-shell">'+
      '<div class="v616-top">'+
        '<div class="v616-title"><span>اختصر الطريق</span><small>اذهب مباشرة للقسم الذي تبحث عنه</small></div>'+
        '<a class="v616-all" href="https://barahstore.com/ar/home-kitchen/c127906256">كل المنتجات ←</a>'+
      '</div>'+
      '<div class="v616-cats">'+
        CATS.map(function(c){
          return '<a class="v616-cat" href="'+c[2]+'"><i>'+c[0]+'</i>'+c[1]+'</a>';
        }).join('')+
      '</div>'+
      '<form class="v616-search" action="https://barahstore.com/ar/search" method="get">'+
        '<input type="search" name="q" placeholder="ابحث في بارعة… مثل: سفر، مشد، تنظيم، سيارة" aria-label="ابحث في متجر بارعة">'+
        '<button type="submit">بحث ←</button>'+
      '</form>'+
    '</div>';

  return x;
}

function place(){
  style();
  var section=build();
  var shipping=document.getElementById('barah-step-shipping-v24');
  var hero=document.getElementById('barah-step-hero-v12');
  var smart=document.getElementById('barah-step-smart-storefront-v52') || document.getElementById('barah-step-needs-v51');
  var main=document.querySelector('main')||document.body;

  if(shipping && shipping.parentNode){
    if(shipping.nextElementSibling!==section) shipping.insertAdjacentElement('afterend',section);
  }else if(hero && hero.parentNode){
    hero.insertAdjacentElement('afterend',section);
  }else if(smart && smart.parentNode){
    smart.insertAdjacentElement('beforebegin',section);
  }else if(main && !section.parentNode){
    main.prepend(section);
  }

  document.documentElement.setAttribute('data-barah-v616','ready');
  return true;
}

function run(){
  place();

  /* keep discovery exactly between shipping and smart-needs after all other ordering scripts */
  var shipping=document.getElementById('barah-step-shipping-v24');
  var section=document.getElementById(ROOT);
  if(shipping && section && shipping.nextElementSibling!==section){
    shipping.insertAdjacentElement('afterend',section);
  }
}

function boot(){
  [0,250,650,1300,2400,4200,6500,9000].forEach(function(ms){setTimeout(run,ms);});
}
if(document.readyState==='loading') document.addEventListener('DOMContentLoaded',boot,{once:true});
else boot();
})();


/* ============================================================
   BARAH V61.7 — FINAL POLISH + DECISION STRIP
   Final desktop/mobile sizing + visual conversion assist.
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V617_FINAL_POLISH__) return;
window.__BARAH_V617_FINAL_POLISH__=true;

var ROOT='barah-v617-decision-strip';
var STYLE='barah-v617-final-polish-style';

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
/* unified desktop width */
#barah-step-hero-v12,
#barah-step-shipping-v24,
#barah-v616-quick-discovery,
#barah-step-smart-storefront-v52,
#barah-step-needs-v51,
#barah-step-pregnancy-v55,
#barah-step-senior-v57,
#barah-step-most-viewed,
section.home-block.home-block--fixed-products.show-all.barah-v35-latest,
#barah-step-catalog-v32,
#barah-step-wholesale-v32,
#${ROOT}{
  width:min(1240px,calc(100% - 40px))!important;
  max-width:1240px!important;
  margin-left:auto!important;
  margin-right:auto!important;
}

/* calmer vertical rhythm */
#barah-step-hero-v12{margin-bottom:14px!important}
#barah-step-shipping-v24{margin-bottom:12px!important}
#barah-v616-quick-discovery{margin-bottom:16px!important}
#barah-step-smart-storefront-v52,
#barah-step-needs-v51,
#barah-step-pregnancy-v55,
#barah-step-senior-v57,
#barah-step-most-viewed,
section.home-block.home-block--fixed-products.show-all.barah-v35-latest{
  margin-bottom:18px!important;
}

/* make latest section visually lighter */
section.barah-v35-latest{
  padding:16px!important;
}
section.barah-v35-latest .barah-v35-latest-head{
  margin-bottom:12px!important;
}
section.barah-v35-latest .barah-v35-copy h2{
  font-size:23px!important;
}
section.barah-v35-latest .grid-block.products-list-container.vertical-products{
  gap:10px!important;
}
section.barah-v35-latest custom-salla-product-card.product-block{
  min-width:0!important;
}
section.barah-v35-latest custom-salla-product-card.product-block img{
  max-height:210px!important;
  object-fit:contain!important;
}

/* decision strip */
#${ROOT}{
  direction:rtl!important;
  margin-top:0!important;
  margin-bottom:16px!important;
  box-sizing:border-box!important;
  font-family:inherit!important;
}
#${ROOT} *{box-sizing:border-box!important}
#${ROOT} .v617-shell{
  display:grid!important;
  grid-template-columns:1.1fr repeat(3,minmax(0,1fr))!important;
  gap:8px!important;
  align-items:stretch!important;
  padding:10px!important;
  border:1px solid #eadfd7!important;
  border-radius:16px!important;
  background:linear-gradient(180deg,#fff,#fffaf6)!important;
}
#${ROOT} .v617-copy{
  display:flex!important;
  flex-direction:column!important;
  justify-content:center!important;
  padding:6px 8px!important;
}
#${ROOT} .v617-copy strong{
  display:block!important;
  color:#2b211b!important;
  font-size:13px!important;
  line-height:1.5!important;
  font-weight:950!important;
}
#${ROOT} .v617-copy small{
  display:block!important;
  margin-top:3px!important;
  color:#82736a!important;
  font-size:9.5px!important;
  line-height:1.55!important;
}
#${ROOT} .v617-choice{
  min-height:58px!important;
  display:flex!important;
  align-items:center!important;
  gap:8px!important;
  padding:9px 10px!important;
  border:1px solid #eee3dc!important;
  border-radius:12px!important;
  background:#fff!important;
  color:#42362f!important;
  text-decoration:none!important;
}
#${ROOT} .v617-icon{
  flex:0 0 32px!important;
  width:32px!important;
  height:32px!important;
  display:grid!important;
  place-items:center!important;
  border-radius:9px!important;
  background:#fff0e5!important;
  color:#d85a25!important;
  font-size:15px!important;
}
#${ROOT} .v617-choice strong{
  display:block!important;
  font-size:10.5px!important;
  font-weight:950!important;
  line-height:1.4!important;
}
#${ROOT} .v617-choice small{
  display:block!important;
  margin-top:2px!important;
  color:#8a7c73!important;
  font-size:8.5px!important;
  line-height:1.4!important;
}

/* tablet */
@media(max-width:1024px){
  #${ROOT} .v617-shell{
    grid-template-columns:1fr repeat(3,minmax(0,1fr))!important;
  }
  section.barah-v35-latest .grid-block.products-list-container.vertical-products{
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
  }
}

/* mobile */
@media(max-width:767px){
  #barah-step-hero-v12,
  #barah-step-shipping-v24,
  #barah-v616-quick-discovery,
  #barah-step-smart-storefront-v52,
  #barah-step-needs-v51,
  #barah-step-pregnancy-v55,
  #barah-step-senior-v57,
  #barah-step-most-viewed,
  section.home-block.home-block--fixed-products.show-all.barah-v35-latest,
  #barah-step-catalog-v32,
  #barah-step-wholesale-v32,
  #${ROOT}{
    width:calc(100% - 24px)!important;
    margin-left:12px!important;
    margin-right:12px!important;
  }
  #${ROOT} .v617-shell{
    display:flex!important;
    overflow-x:auto!important;
    gap:7px!important;
    scroll-snap-type:x mandatory!important;
    scrollbar-width:none!important;
    padding:9px!important;
  }
  #${ROOT} .v617-shell::-webkit-scrollbar{display:none!important}
  #${ROOT} .v617-copy{
    flex:0 0 76%!important;
    min-width:210px!important;
    scroll-snap-align:start!important;
  }
  #${ROOT} .v617-choice{
    flex:0 0 72%!important;
    min-width:200px!important;
    scroll-snap-align:start!important;
  }

  section.barah-v35-latest{
    padding:12px 10px!important;
  }
  section.barah-v35-latest .grid-block.products-list-container.vertical-products{
    display:flex!important;
    overflow-x:auto!important;
    gap:9px!important;
    scroll-snap-type:x mandatory!important;
    scrollbar-width:none!important;
  }
  section.barah-v35-latest custom-salla-product-card.product-block{
    flex:0 0 68%!important;
    max-width:210px!important;
    scroll-snap-align:start!important;
  }
  section.barah-v35-latest custom-salla-product-card.product-block img{
    max-height:180px!important;
  }
}
`;
  document.head.appendChild(s);
}

function build(){
  var x=document.getElementById(ROOT);
  if(x) return x;

  x=document.createElement('section');
  x.id=ROOT;
  x.setAttribute('aria-label','اختصر قرار الشراء');
  x.innerHTML=
    '<div class="v617-shell">'+
      '<div class="v617-copy">'+
        '<strong>محتار تبدأ من وين؟</strong>'+
        '<small>اختر أقصر طريق حسب ما يناسبك الآن.</small>'+
      '</div>'+
      '<a class="v617-choice" href="https://barahstore.com/ar/home-kitchen/c127906256">'+
        '<span class="v617-icon">🔥</span><span><strong>الأكثر طلبًا</strong><small>ابدأ بما يختاره العملاء أكثر</small></span>'+
      '</a>'+
      '<a class="v617-choice" href="https://barahstore.com/ar/latest-products">'+
        '<span class="v617-icon">✨</span><span><strong>وصل حديثًا</strong><small>شاهد أحدث الإضافات</small></span>'+
      '</a>'+
      '<a class="v617-choice" href="https://barahstore.com/ar/home-kitchen/c127906256">'+
        '<span class="v617-icon">✦</span><span><strong>اختيارات عملية</strong><small>تصفّح كل ما يناسب يومك</small></span>'+
      '</a>'+
    '</div>';
  return x;
}

function place(){
  addStyle();
  var x=build();
  var senior=document.getElementById('barah-step-senior-v57');
  var most=document.getElementById('barah-step-most-viewed');
  var latest=document.querySelector('section.barah-v35-latest');

  if(senior && senior.parentNode){
    if(senior.nextElementSibling!==x) senior.insertAdjacentElement('afterend',x);
  }else if(most && most.parentNode){
    most.insertAdjacentElement('beforebegin',x);
  }else if(latest && latest.parentNode){
    latest.insertAdjacentElement('beforebegin',x);
  }

  document.documentElement.setAttribute('data-barah-v617','ready');
  return true;
}

function run(){
  place();
  var senior=document.getElementById('barah-step-senior-v57');
  var x=document.getElementById(ROOT);
  if(senior && x && senior.nextElementSibling!==x){
    senior.insertAdjacentElement('afterend',x);
  }
}

function boot(){
  [0,250,650,1200,2400,4200,6500,9000].forEach(function(ms){setTimeout(run,ms);});
}
if(document.readyState==='loading') document.addEventListener('DOMContentLoaded',boot,{once:true});
else boot();
})();


/* ============================================================
   BARAH V61.8 — MOBILE POLISH FINAL
   Mobile-only refinement:
   - larger tap targets
   - lighter hero
   - clearer quick discovery
   - more breathing room for pregnancy/senior
   - better Most Viewed
   - wider Latest native cards
   - WhatsApp safe space
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V618_MOBILE_POLISH__) return;
window.__BARAH_V618_MOBILE_POLISH__=true;

var STYLE='barah-v618-mobile-polish-style';

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`

@media(max-width:767px){

  /* ---------- global rhythm ---------- */
  body{
    padding-bottom:78px!important;
  }

  #barah-step-hero-v12,
  #barah-step-shipping-v24,
  #barah-v616-quick-discovery,
  #barah-step-smart-storefront-v52,
  #barah-step-needs-v51,
  #barah-step-pregnancy-v55,
  #barah-step-senior-v57,
  #barah-v617-decision-strip,
  #barah-step-most-viewed,
  section.home-block.home-block--fixed-products.show-all.barah-v35-latest,
  #barah-step-catalog-v32,
  #barah-step-wholesale-v32{
    margin-bottom:12px!important;
  }

  /* ---------- HERO: lighter first screen ---------- */
  #barah-step-hero-v12 .barah-hero-shell{
    padding:12px!important;
    gap:10px!important;
  }

  #barah-step-hero-v12 .barah-hero-copy{
    padding:2px!important;
  }

  #barah-step-hero-v12 .barah-hero-badge{
    margin-bottom:7px!important;
    padding:5px 8px!important;
    font-size:10px!important;
  }

  #barah-step-hero-v12 h1{
    font-size:23px!important;
    line-height:1.35!important;
  }

  #barah-step-hero-v12 .barah-hero-copy p{
    margin:8px 0 12px!important;
    font-size:11.5px!important;
    line-height:1.7!important;
  }

  #barah-step-hero-v12 .barah-hero-actions{
    gap:7px!important;
  }

  #barah-step-hero-v12 .barah-hero-primary,
  #barah-step-hero-v12 .barah-hero-secondary{
    min-height:40px!important;
    padding:0 11px!important;
    display:inline-flex!important;
    align-items:center!important;
    justify-content:center!important;
    font-size:10.5px!important;
  }

  #barah-step-hero-v12 .barah-hero-trust{
    gap:6px!important;
    margin-top:10px!important;
  }

  #barah-step-hero-v12 .barah-hero-trust span{
    padding:5px 7px!important;
    font-size:9px!important;
  }

  #barah-step-hero-v12 .barah-hero-products{
    gap:7px!important;
  }

  #barah-step-hero-v12 .barah-hero-product strong{
    min-height:auto!important;
    padding:0 8px 8px!important;
    font-size:10.5px!important;
    line-height:1.45!important;
    display:-webkit-box!important;
    -webkit-line-clamp:2!important;
    -webkit-box-orient:vertical!important;
    overflow:hidden!important;
  }

  #barah-step-hero-v12 .barah-hero-product img{
    padding:7px!important;
  }

  /* ---------- Quick discovery: clearer and easier to tap ---------- */
  #barah-v616-quick-discovery .v616-shell{
    padding:10px!important;
  }

  #barah-v616-quick-discovery .v616-top{
    margin-bottom:8px!important;
  }

  #barah-v616-quick-discovery .v616-title{
    font-size:12px!important;
  }

  #barah-v616-quick-discovery .v616-title small{
    font-size:9px!important;
  }

  #barah-v616-quick-discovery .v616-all{
    min-height:38px!important;
    padding:0 11px!important;
    font-size:9.5px!important;
  }

  #barah-v616-quick-discovery .v616-cats{
    gap:6px!important;
  }

  #barah-v616-quick-discovery .v616-cat{
    min-height:42px!important;
    padding:0 12px!important;
    font-size:10px!important;
  }

  #barah-v616-quick-discovery .v616-cat i{
    width:25px!important;
    height:25px!important;
  }

  #barah-v616-quick-discovery .v616-search input,
  #barah-v616-quick-discovery .v616-search button{
    height:42px!important;
  }

  /* ---------- Pregnancy ---------- */
  #barah-step-pregnancy-v55 .preg-shell{
    padding:12px!important;
  }

  #barah-step-pregnancy-v55 .preg-head,
  #barah-step-pregnancy-v55 .preg-story,
  #barah-step-pregnancy-v55 .preg-grid{
    margin-bottom:10px!important;
  }

  #barah-step-pregnancy-v55 h2{
    font-size:20px!important;
    line-height:1.4!important;
  }

  #barah-step-pregnancy-v55 .preg-sub{
    font-size:10.5px!important;
    line-height:1.7!important;
  }

  #barah-step-pregnancy-v55 .preg-card{
    min-width:0!important;
  }

  /* ---------- Senior: more readable 2x2 ---------- */
  #barah-step-senior-v57 .v614-shell{
    padding:12px!important;
  }

  #barah-step-senior-v57 .v614-head{
    margin-bottom:10px!important;
  }

  #barah-step-senior-v57 .v614-head h2{
    font-size:20px!important;
  }

  #barah-step-senior-v57 .v614-head p{
    font-size:10px!important;
    line-height:1.65!important;
  }

  #barah-step-senior-v57 .v614-grid{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:7px!important;
  }

  #barah-step-senior-v57 .v614-path{
    min-height:108px!important;
    padding:9px!important;
  }

  #barah-step-senior-v57 .v614-icon{
    width:38px!important;
    height:38px!important;
    margin-bottom:7px!important;
    font-size:18px!important;
  }

  #barah-step-senior-v57 .v614-path strong{
    font-size:11.5px!important;
  }

  #barah-step-senior-v57 .v614-path small{
    font-size:9px!important;
    line-height:1.5!important;
  }

  /* ---------- Decision strip ---------- */
  #barah-v617-decision-strip .v617-shell{
    padding:8px!important;
  }

  #barah-v617-decision-strip .v617-copy{
    flex:0 0 70%!important;
    min-width:195px!important;
  }

  #barah-v617-decision-strip .v617-choice{
    flex:0 0 68%!important;
    min-width:190px!important;
    min-height:60px!important;
  }

  /* ---------- Most viewed: less compressed ---------- */
  #barah-step-most-viewed{
    padding:11px!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__track{
    gap:8px!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__card{
    flex:0 0 82%!important;
    max-width:285px!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__product{
    min-height:128px!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__product img{
    height:118px!important;
    object-fit:contain!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__name{
    font-size:10.5px!important;
    line-height:1.55!important;
  }

  /* ---------- Latest: wider native cards ---------- */
  section.home-block.home-block--fixed-products.show-all.barah-v35-latest{
    padding:11px 9px!important;
  }

  section.barah-v35-latest .barah-v35-latest-head{
    margin-bottom:10px!important;
  }

  section.barah-v35-latest .barah-v35-copy h2{
    font-size:20px!important;
  }

  section.barah-v35-latest .barah-v35-copy p{
    font-size:9.5px!important;
    line-height:1.55!important;
  }

  section.barah-v35-latest .grid-block.products-list-container.vertical-products{
    gap:8px!important;
  }

  section.barah-v35-latest custom-salla-product-card.product-block{
    flex:0 0 80%!important;
    max-width:245px!important;
  }

  section.barah-v35-latest custom-salla-product-card.product-block img{
    max-height:195px!important;
    object-fit:contain!important;
  }

  /* clamp native product titles without touching Salla card structure */
  section.barah-v35-latest custom-salla-product-card.product-block .product-title,
  section.barah-v35-latest custom-salla-product-card.product-block [class*="title"]{
    display:-webkit-box!important;
    -webkit-line-clamp:2!important;
    -webkit-box-orient:vertical!important;
    overflow:hidden!important;
  }

  /* ---------- Footer pair ---------- */
  #barah-step-catalog-v32 .v32box,
  #barah-step-wholesale-v32 .v32box{
    padding:12px!important;
  }

  #barah-step-catalog-v32 .v32box a,
  #barah-step-wholesale-v32 .v32box a{
    min-height:40px!important;
    display:inline-flex!important;
    align-items:center!important;
    justify-content:center!important;
  }

  /* ---------- floating WhatsApp safe zone ---------- */
  a[href*="whatsapp"],
  a[href*="wa.me"],
  .whatsapp,
  [class*="whatsapp"]{
    z-index:45!important;
  }

  /* avoid floating widgets covering bottom CTAs */
  #barah-step-wholesale-v32{
    margin-bottom:82px!important;
  }
}

/* very narrow devices */
@media(max-width:390px){
  #barah-step-hero-v12 h1{
    font-size:21px!important;
  }

  #barah-step-senior-v57 .v614-grid{
    grid-template-columns:1fr 1fr!important;
  }

  section.barah-v35-latest custom-salla-product-card.product-block{
    flex-basis:84%!important;
    max-width:235px!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__card{
    flex-basis:86%!important;
  }
}
`;
  document.head.appendChild(s);
}

function run(){
  addStyle();
  document.documentElement.setAttribute('data-barah-v618','ready');
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}
setTimeout(run,600);
setTimeout(run,1800);
})();


/* ============================================================
   BARAH V61.9 — HEADING CLEANUP
   Restore general conversion heading:
   الأكثر مشاهدة مؤخرًا
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V619_HEADING_CLEANUP__) return;
window.__BARAH_V619_HEADING_CLEANUP__=true;

function fixHeading(){
  var roots=[
    document.getElementById('barah-step-most-viewed'),
    document.getElementById('barah-step-home-v9'),
    document.querySelector('[data-barah-section="mothers-picks"]')
  ].filter(Boolean);

  roots.forEach(function(root){
    root.querySelectorAll('h1,h2,h3,strong,.title,.section-title,[class*="title"]').forEach(function(el){
      var t=(el.textContent||'').replace(/\s+/g,' ').trim();
      if(
        t.indexOf('اختيارات الأمهات')!==-1 ||
        t.indexOf('اختيارات الامهات')!==-1 ||
        t.indexOf('مختارات الأمهات')!==-1 ||
        t.indexOf('مختارات الامهات')!==-1
      ){
        el.textContent='الأكثر مشاهدة مؤخرًا';
      }
    });
  });
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',fixHeading,{once:true});
}else{
  fixHeading();
}
setTimeout(fixHeading,500);
setTimeout(fixHeading,1500);
})();


/* ============================================================
   BARAH V62 — MOBILE DESIGN REFINEMENT
   Cleaner mobile styling, spacing, card widths, and clearer CTAs
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V62_MOBILE_REFINED__) return;
window.__BARAH_V62_MOBILE_REFINED__=true;

var STYLE='barah-v62-mobile-refined-style';

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
@media (max-width: 767px){

  :root{
    --barah-mobile-gap: 14px;
    --barah-mobile-radius: 18px;
    --barah-mobile-card-radius: 16px;
  }

  body{
    background:#f8f7f5!important;
    padding-bottom:92px!important;
  }

  /* ===== unified mobile rhythm ===== */
  #barah-step-hero-v12,
  #barah-step-shipping-v24,
  #barah-v616-quick-discovery,
  #barah-step-smart-storefront-v52,
  #barah-step-needs-v51,
  #barah-step-pregnancy-v55,
  #barah-step-senior-v57,
  #barah-v617-decision-strip,
  #barah-step-most-viewed,
  section.home-block.home-block--fixed-products.show-all.barah-v35-latest,
  #barah-step-catalog-v32,
  #barah-step-wholesale-v32{
    width:calc(100% - 20px)!important;
    margin-left:10px!important;
    margin-right:10px!important;
    margin-bottom:12px!important;
  }

  #barah-step-hero-v12 .barah-hero-shell,
  #barah-v616-quick-discovery .v616-shell,
  #barah-step-pregnancy-v55 .preg-shell,
  #barah-step-senior-v57 .v614-shell,
  #barah-step-most-viewed,
  section.home-block.home-block--fixed-products.show-all.barah-v35-latest,
  #barah-step-catalog-v32 .v32box,
  #barah-step-wholesale-v32 .v32box{
    border-radius:var(--barah-mobile-radius)!important;
    box-shadow:0 10px 24px rgba(29,22,18,.045)!important;
  }

  /* ===== hero ===== */
  #barah-step-hero-v12 .barah-hero-shell{
    padding:13px!important;
    gap:11px!important;
  }

  #barah-step-hero-v12 .barah-hero-badge{
    padding:5px 8px!important;
    border-radius:999px!important;
    font-size:9.5px!important;
  }

  #barah-step-hero-v12 h1{
    font-size:24px!important;
    line-height:1.33!important;
    letter-spacing:-.1px!important;
  }

  #barah-step-hero-v12 .barah-hero-copy p{
    margin:8px 0 12px!important;
    font-size:11.5px!important;
    line-height:1.8!important;
    color:#6f6159!important;
  }

  #barah-step-hero-v12 .barah-hero-actions{
    display:grid!important;
    grid-template-columns:1fr 1fr!important;
    gap:8px!important;
  }

  #barah-step-hero-v12 .barah-hero-actions a{
    min-height:40px!important;
    padding:0 10px!important;
    font-size:10px!important;
    border-radius:11px!important;
    text-align:center!important;
  }

  #barah-step-hero-v12 .barah-hero-actions a.barah-home-direct{
    grid-column:1 / -1!important;
  }

  #barah-step-hero-v12 .barah-hero-trust{
    gap:6px!important;
    margin-top:9px!important;
  }

  #barah-step-hero-v12 .barah-hero-trust span{
    padding:5px 7px!important;
    font-size:8.7px!important;
    min-height:28px!important;
  }

  #barah-step-hero-v12 .barah-hero-products{
    gap:8px!important;
  }

  #barah-step-hero-v12 .barah-hero-product{
    border-radius:14px!important;
  }

  #barah-step-hero-v12 .barah-hero-product strong{
    padding:0 7px 9px!important;
    font-size:10.2px!important;
    line-height:1.5!important;
  }

  /* ===== quick discovery ===== */
  #barah-v616-quick-discovery .v616-shell{
    padding:11px!important;
  }

  #barah-v616-quick-discovery .v616-top{
    margin-bottom:9px!important;
  }

  #barah-v616-quick-discovery .v616-title{
    font-size:12px!important;
    font-weight:900!important;
  }

  #barah-v616-quick-discovery .v616-title small{
    font-size:8.8px!important;
  }

  #barah-v616-quick-discovery .v616-cat{
    min-height:43px!important;
    padding:0 12px!important;
    border-radius:11px!important;
    font-size:9.8px!important;
  }

  #barah-v616-quick-discovery .v616-search{
    margin-top:9px!important;
    padding-top:9px!important;
  }

  #barah-v616-quick-discovery .v616-search input,
  #barah-v616-quick-discovery .v616-search button{
    height:42px!important;
    border-radius:11px!important;
  }

  /* ===== pregnancy ===== */
  #barah-step-pregnancy-v55 .preg-shell{
    padding:12px!important;
  }

  #barah-step-pregnancy-v55 .preg-head{
    margin-bottom:9px!important;
  }

  #barah-step-pregnancy-v55 h2{
    font-size:20px!important;
    line-height:1.35!important;
  }

  #barah-step-pregnancy-v55 .preg-sub{
    font-size:10.2px!important;
    line-height:1.75!important;
  }

  #barah-step-pregnancy-v55 .preg-story{
    margin-bottom:10px!important;
  }

  #barah-step-pregnancy-v55 .preg-grid{
    display:flex!important;
    overflow-x:auto!important;
    gap:8px!important;
    scroll-snap-type:x mandatory!important;
    scrollbar-width:none!important;
    padding-bottom:3px!important;
  }

  #barah-step-pregnancy-v55 .preg-grid::-webkit-scrollbar{
    display:none!important;
  }

  #barah-step-pregnancy-v55 .preg-card{
    flex:0 0 76%!important;
    max-width:230px!important;
    scroll-snap-align:start!important;
    border-radius:15px!important;
  }

  #barah-step-pregnancy-v55 .preg-card .preg-name,
  #barah-step-pregnancy-v55 .preg-card strong{
    font-size:11px!important;
    line-height:1.55!important;
  }

  /* ===== senior ===== */
  #barah-step-senior-v57 .v614-shell{
    padding:12px!important;
  }

  #barah-step-senior-v57 .v614-head{
    margin-bottom:10px!important;
  }

  #barah-step-senior-v57 .v614-head h2{
    font-size:20px!important;
    line-height:1.35!important;
  }

  #barah-step-senior-v57 .v614-head p{
    font-size:10px!important;
    line-height:1.7!important;
  }

  #barah-step-senior-v57 .v614-grid{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:8px!important;
  }

  #barah-step-senior-v57 .v614-path{
    min-height:112px!important;
    padding:10px!important;
    border-radius:14px!important;
  }

  #barah-step-senior-v57 .v614-icon{
    width:38px!important;
    height:38px!important;
    margin-bottom:8px!important;
    font-size:18px!important;
    border-radius:11px!important;
  }

  #barah-step-senior-v57 .v614-path strong{
    font-size:11.2px!important;
    line-height:1.4!important;
  }

  #barah-step-senior-v57 .v614-path small{
    font-size:8.8px!important;
    line-height:1.45!important;
  }

  /* ===== decision strip ===== */
  #barah-v617-decision-strip .v617-shell{
    padding:8px!important;
    border-radius:15px!important;
  }

  #barah-v617-decision-strip .v617-copy{
    flex:0 0 72%!important;
    min-width:200px!important;
  }

  #barah-v617-decision-strip .v617-choice{
    flex:0 0 72%!important;
    min-width:198px!important;
    min-height:60px!important;
    border-radius:12px!important;
  }

  /* ===== most viewed ===== */
  #barah-step-most-viewed{
    padding:12px!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__head,
  #barah-step-most-viewed .shelf-head{
    margin-bottom:9px!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__track{
    display:flex!important;
    overflow-x:auto!important;
    gap:8px!important;
    scroll-snap-type:x mandatory!important;
    scrollbar-width:none!important;
    padding-bottom:4px!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__track::-webkit-scrollbar{
    display:none!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__card{
    flex:0 0 84%!important;
    max-width:295px!important;
    scroll-snap-align:start!important;
    border-radius:15px!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__product img{
    height:122px!important;
  }

  /* ===== latest products (native cards) ===== */
  section.home-block.home-block--fixed-products.show-all.barah-v35-latest{
    padding:12px 10px!important;
  }

  section.barah-v35-latest .barah-v35-latest-head{
    margin-bottom:10px!important;
  }

  section.barah-v35-latest .barah-v35-copy h2{
    font-size:21px!important;
  }

  section.barah-v35-latest .barah-v35-copy p{
    font-size:9.2px!important;
    line-height:1.55!important;
  }

  section.barah-v35-latest .grid-block.products-list-container.vertical-products{
    display:flex!important;
    overflow-x:auto!important;
    gap:8px!important;
    scroll-snap-type:x mandatory!important;
    scrollbar-width:none!important;
    padding-bottom:5px!important;
  }

  section.barah-v35-latest .grid-block.products-list-container.vertical-products::-webkit-scrollbar{
    display:none!important;
  }

  section.barah-v35-latest custom-salla-product-card.product-block{
    flex:0 0 84%!important;
    max-width:250px!important;
    min-width:0!important;
    scroll-snap-align:start!important;
  }

  section.barah-v35-latest custom-salla-product-card.product-block .product,
  section.barah-v35-latest custom-salla-product-card.product-block .product-card,
  section.barah-v35-latest custom-salla-product-card.product-block [class*="card"]{
    border-radius:15px!important;
  }

  section.barah-v35-latest custom-salla-product-card.product-block img{
    max-height:190px!important;
    object-fit:contain!important;
  }

  section.barah-v35-latest custom-salla-product-card.product-block .product-title,
  section.barah-v35-latest custom-salla-product-card.product-block [class*="title"]{
    font-size:11px!important;
    line-height:1.5!important;
    display:-webkit-box!important;
    -webkit-line-clamp:2!important;
    -webkit-box-orient:vertical!important;
    overflow:hidden!important;
  }

  section.barah-v35-latest custom-salla-product-card.product-block button,
  section.barah-v35-latest custom-salla-product-card.product-block .btn,
  section.barah-v35-latest custom-salla-product-card.product-block [class*="button"]{
    min-height:38px!important;
    font-size:10.5px!important;
    border-radius:10px!important;
  }

  /* ===== footer pair ===== */
  #barah-step-catalog-v32 .v32box,
  #barah-step-wholesale-v32 .v32box{
    padding:13px!important;
  }

  #barah-step-catalog-v32 h3,
  #barah-step-wholesale-v32 h3{
    font-size:18px!important;
    line-height:1.35!important;
  }

  #barah-step-catalog-v32 p,
  #barah-step-wholesale-v32 p{
    font-size:10px!important;
    line-height:1.65!important;
  }

  #barah-step-catalog-v32 .v32box a,
  #barah-step-wholesale-v32 .v32box a{
    min-height:40px!important;
    padding:0 11px!important;
    font-size:10px!important;
    border-radius:11px!important;
  }

  /* ===== bottom nav / floating safe space ===== */
  #barah-step-wholesale-v32{
    margin-bottom:86px!important;
  }

  a[href*="whatsapp"],
  a[href*="wa.me"],
  .whatsapp,
  [class*="whatsapp"]{
    z-index:42!important;
  }
}

@media (max-width:390px){
  #barah-step-hero-v12 h1{
    font-size:22px!important;
  }

  #barah-step-pregnancy-v55 .preg-card{
    flex-basis:82%!important;
    max-width:225px!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__card{
    flex-basis:88%!important;
  }

  section.barah-v35-latest custom-salla-product-card.product-block{
    flex-basis:88%!important;
    max-width:242px!important;
  }
}
`;
  document.head.appendChild(s);
}

function run(){
  addStyle();
  document.documentElement.setAttribute('data-barah-v62-mobile','ready');
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}
setTimeout(run,700);
setTimeout(run,1800);
})();


/* ============================================================
   BARAH V62.1 — MOBILE HERO 6 PICKS
   Six compact hero products on mobile.
   Existing 2 products + 4 extra verified catalog products.
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V621_MOBILE_HERO_6__) return;
window.__BARAH_V621_MOBILE_HERO_6__=true;

var STYLE='barah-v621-mobile-hero6-style';

var EXTRA=[
  {
    id:'574838634',
    name:'مشد فانيلة رجالي بدون أكمام لتنسيق القوام',
    price:'29 ر.س',
    url:'https://barahstore.com/ar/product-574838634/p574838634',
    image:'https://cdn.salla.sa/qwxGZ/a47e89cb-b606-429b-803c-85dd149fdc0f-500x500-LWLWeC4DUGKkXBZROhFH9Rnlc8OIj8PftecUd3dk.png',
    badge:'اختيار عملي'
  },
  {
    id:'1455538329',
    name:'طقم حبال مقاومة رياضية 11 قطعة – 5 مستويات',
    price:'49 ر.س',
    url:'https://barahstore.com/ar/product-1455538329/p1455538329',
    image:'https://cdn.salla.sa/qwxGZ/515fab97-aab3-448a-8a7b-6b9287691cb0-500x500-EA6WdMUjzvNizNpEGrkn2zERP8MWbIpNct1GNX0K.webp',
    badge:'للرياضة'
  },
  {
    id:'314048946',
    name:'موزع عسل وشراب زجاجي برافعة وقاعدة مانعة للتقطير',
    price:'11.5 ر.س',
    url:'https://barahstore.com/ar/product-314048946/p314048946',
    image:'https://cdn.salla.sa/qwxGZ/d5daee24-034e-48ac-a096-b9c2c3b24e10-500x500-hHCeiui0XlK1TaEvN5fBKRcAerYPMvWWNivbUO9W.webp',
    badge:'للمنزل'
  },
  {
    id:'1737673536',
    name:'وسادة حمل على شكل U – ألوان متعددة',
    price:'69 ر.س',
    url:'https://barahstore.com/ar/product-1737673536/p1737673536',
    image:'https://cdn.salla.sa/qwxGZ/0b82500c-5a87-478c-a484-f16d9a901c67-333.33333333333x500-Twa9CKkmDHovBQ32KtRinKbG8WrlpFol1FiCeCp0.png',
    badge:'راحة يومية'
  }
];

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
/* extras hidden on desktop/tablet; mobile turns all six into compact rail */
#barah-step-hero-v12 .barah-v621-extra{
  display:none!important;
}

@media(max-width:767px){
  #barah-step-hero-v12 .barah-hero-products{
    display:flex!important;
    overflow-x:auto!important;
    gap:7px!important;
    scroll-snap-type:x mandatory!important;
    scrollbar-width:none!important;
    padding:2px 1px 5px!important;
    margin-left:-2px!important;
    margin-right:-2px!important;
  }

  #barah-step-hero-v12 .barah-hero-products::-webkit-scrollbar{
    display:none!important;
  }

  #barah-step-hero-v12 .barah-v621-extra{
    display:flex!important;
  }

  #barah-step-hero-v12 .barah-hero-product{
    flex:0 0 40%!important;
    width:40%!important;
    min-width:116px!important;
    max-width:142px!important;
    scroll-snap-align:start!important;
    border-radius:13px!important;
    box-shadow:none!important;
  }

  #barah-step-hero-v12 .barah-hero-product img{
    width:100%!important;
    aspect-ratio:1/1!important;
    padding:6px!important;
    object-fit:contain!important;
  }

  #barah-step-hero-v12 .barah-hero-product strong{
    min-height:34px!important;
    padding:0 7px 4px!important;
    font-size:9.3px!important;
    line-height:1.45!important;
    display:-webkit-box!important;
    -webkit-line-clamp:2!important;
    -webkit-box-orient:vertical!important;
    overflow:hidden!important;
  }

  #barah-step-hero-v12 .barah-hero-product small{
    padding:0 7px 8px!important;
    font-size:10px!important;
    font-weight:950!important;
  }

  #barah-step-hero-v12 .barah-hero-pill{
    top:6px!important;
    right:6px!important;
    padding:4px 6px!important;
    font-size:7.5px!important;
  }
}

@media(max-width:390px){
  #barah-step-hero-v12 .barah-hero-product{
    flex-basis:42%!important;
    width:42%!important;
    min-width:112px!important;
  }
}
`;
  document.head.appendChild(s);
}

function card(p){
  var a=document.createElement('a');
  a.className='barah-hero-product barah-v621-extra';
  a.href=p.url;
  a.setAttribute('data-product-id',p.id);
  a.innerHTML=
    '<span class="barah-hero-pill">'+p.badge+'</span>'+
    '<img loading="lazy" decoding="async" src="'+p.image+'" alt="'+p.name.replace(/"/g,'&quot;')+'">'+
    '<strong>'+p.name+'</strong>'+
    '<small>'+p.price+'</small>';
  return a;
}

function mount(){
  addStyle();
  var root=document.getElementById('barah-step-hero-v12');
  if(!root) return false;

  var grid=root.querySelector('.barah-hero-products');
  if(!grid) return false;

  EXTRA.forEach(function(p){
    if(!grid.querySelector('[data-product-id="'+p.id+'"]')){
      grid.appendChild(card(p));
    }
  });

  /* ensure exactly six hero product cards at most */
  var cards=Array.prototype.slice.call(grid.querySelectorAll('.barah-hero-product'));
  cards.forEach(function(c,i){
    if(i<6){
      c.removeAttribute('data-barah-v621-overflow');
    }else{
      c.setAttribute('data-barah-v621-overflow','1');
      c.style.setProperty('display','none','important');
    }
  });

  root.setAttribute('data-barah-v621','six-picks');
  return true;
}

function boot(){
  [0,250,700,1500,3000].forEach(function(ms){setTimeout(mount,ms);});
}
if(document.readyState==='loading') document.addEventListener('DOMContentLoaded',boot,{once:true});
else boot();
})();


/* ============================================================
   BARAH V62.2 — COMPACT MOBILE PREGNANCY SECTION
   Shorter, cleaner pregnancy section for mobile only
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V622_COMPACT_PREG__) return;
window.__BARAH_V622_COMPACT_PREG__=true;

var STYLE='barah-v622-compact-preg-style';

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
@media(max-width:767px){

  #barah-step-pregnancy-v55 .preg-shell{
    padding:11px!important;
    border-radius:16px!important;
  }

  #barah-step-pregnancy-v55 .preg-head{
    gap:8px!important;
    margin-bottom:8px!important;
  }

  #barah-step-pregnancy-v55 .preg-kicker{
    margin-bottom:6px!important;
    padding:5px 8px!important;
    font-size:9px!important;
  }

  #barah-step-pregnancy-v55 .preg-head h2{
    font-size:18px!important;
    line-height:1.32!important;
    margin:0!important;
  }

  #barah-step-pregnancy-v55 .preg-sub{
    margin-top:5px!important;
    font-size:9.6px!important;
    line-height:1.6!important;
    display:-webkit-box!important;
    -webkit-line-clamp:2!important;
    -webkit-box-orient:vertical!important;
    overflow:hidden!important;
  }

  #barah-step-pregnancy-v55 .preg-all{
    min-height:38px!important;
    padding:0 10px!important;
    border-radius:10px!important;
    font-size:10px!important;
  }

  /* story card becomes shorter and cleaner */
  #barah-step-pregnancy-v55 .barah-v61-story{
    padding:10px!important;
    border-radius:14px!important;
    gap:10px!important;
    margin-bottom:8px!important;
  }

  #barah-step-pregnancy-v55 .barah-v61-story-eyebrow{
    margin-bottom:5px!important;
    padding:5px 8px!important;
    font-size:9px!important;
  }

  #barah-step-pregnancy-v55 .barah-v61-story h3{
    font-size:16px!important;
    line-height:1.35!important;
    margin:0 0 5px!important;
  }

  #barah-step-pregnancy-v55 .barah-v61-story p{
    font-size:9.8px!important;
    line-height:1.6!important;
    margin:0 0 8px!important;
    display:-webkit-box!important;
    -webkit-line-clamp:2!important;
    -webkit-box-orient:vertical!important;
    overflow:hidden!important;
  }

  #barah-step-pregnancy-v55 .barah-v61-story-actions{
    display:grid!important;
    grid-template-columns:1fr 1fr!important;
    gap:7px!important;
  }

  #barah-step-pregnancy-v55 .barah-v61-story-actions a{
    min-height:38px!important;
    padding:0 8px!important;
    border-radius:10px!important;
    font-size:10px!important;
  }

  /* hide bulky explanation points to keep section short */
  #barah-step-pregnancy-v55 .barah-v61-story-points{
    display:none!important;
  }

  /* chips row compact */
  #barah-step-pregnancy-v55 .barah-v61-chip-row{
    display:flex!important;
    gap:6px!important;
    overflow-x:auto!important;
    scrollbar-width:none!important;
    padding-bottom:2px!important;
    margin-bottom:8px!important;
  }

  #barah-step-pregnancy-v55 .barah-v61-chip-row::-webkit-scrollbar{
    display:none!important;
  }

  #barah-step-pregnancy-v55 .barah-v61-chip-row a{
    flex:0 0 auto!important;
    min-height:34px!important;
    padding:0 10px!important;
    border-radius:999px!important;
    font-size:9px!important;
    white-space:nowrap!important;
  }

  /* product rail: show only first 2 on mobile for shorter section */
  #barah-step-pregnancy-v55 .preg-grid{
    display:flex!important;
    overflow-x:auto!important;
    gap:8px!important;
    scroll-snap-type:x mandatory!important;
    scrollbar-width:none!important;
    padding-bottom:3px!important;
    margin-bottom:8px!important;
  }

  #barah-step-pregnancy-v55 .preg-grid::-webkit-scrollbar{
    display:none!important;
  }

  #barah-step-pregnancy-v55 .preg-card,
  #barah-step-pregnancy-v55 .preg-card.hero{
    flex:0 0 66%!important;
    max-width:215px!important;
    min-width:0!important;
    scroll-snap-align:start!important;
    border-radius:14px!important;
  }

  #barah-step-pregnancy-v55 .preg-grid .preg-card:nth-child(n+3){
    display:none!important;
  }

  #barah-step-pregnancy-v55 .preg-media,
  #barah-step-pregnancy-v55 .hero .preg-media{
    min-height:122px!important;
    padding:8px!important;
  }

  #barah-step-pregnancy-v55 .preg-tag{
    top:7px!important;
    right:7px!important;
    padding:4px 7px!important;
    font-size:8px!important;
  }

  #barah-step-pregnancy-v55 .preg-body{
    padding:10px!important;
  }

  #barah-step-pregnancy-v55 .preg-body h3{
    font-size:11.2px!important;
    line-height:1.45!important;
    display:-webkit-box!important;
    -webkit-line-clamp:2!important;
    -webkit-box-orient:vertical!important;
    overflow:hidden!important;
    min-height:auto!important;
  }

  #barah-step-pregnancy-v55 .preg-desc{
    margin:4px 0 7px!important;
    font-size:9px!important;
    line-height:1.5!important;
    -webkit-line-clamp:1!important;
  }

  #barah-step-pregnancy-v55 .preg-price{
    font-size:13px!important;
  }

  #barah-step-pregnancy-v55 .preg-cta{
    min-height:32px!important;
    padding:0 9px!important;
    border-radius:9px!important;
    font-size:9.5px!important;
  }

  #barah-step-pregnancy-v55 .preg-note{
    margin-top:6px!important;
    font-size:8.2px!important;
    line-height:1.5!important;
  }
}

@media(max-width:390px){
  #barah-step-pregnancy-v55 .preg-card,
  #barah-step-pregnancy-v55 .preg-card.hero{
    flex-basis:72%!important;
    max-width:210px!important;
  }
}
`;
  document.head.appendChild(s);
}

function refine(){
  addStyle();
  var root=document.getElementById('barah-step-pregnancy-v55');
  if(!root) return false;

  var h2=root.querySelector('.preg-head h2');
  var sub=root.querySelector('.preg-sub');
  var storyTitle=root.querySelector('.barah-v61-story h3');
  var storyP=root.querySelector('.barah-v61-story p');

  if(h2) h2.textContent='اختيارات الحمل والراحة… في مكان واحد';
  if(sub) sub.textContent='وصول أسرع لاختيارات الحمل والراحة وبداية تجهيز الطفل.';
  if(storyTitle) storyTitle.textContent='لأن الراحة تبدأ من التفاصيل الصغيرة';
  if(storyP) storyP.textContent='جمعنا لك طريقًا أسرع لاختيارات الحمل والراحة وبداية تجهيز الطفل، ثم أبقينا المنتجات الفعلية مباشرة تحتها.';

  root.setAttribute('data-barah-v622','compact-mobile');
  return true;
}

function boot(){
  [0,300,900,1800].forEach(function(ms){setTimeout(refine,ms);});
}
if(document.readyState==='loading') document.addEventListener('DOMContentLoaded',boot,{once:true});
else boot();
})();


/* ============================================================
   BARAH V62.3 — FINAL SECTION ORDER
   Move:
   Most Viewed -> Latest -> Pregnancy -> Senior
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V623_SECTION_ORDER__) return;
window.__BARAH_V623_SECTION_ORDER__=true;
if(window.matchMedia&&window.matchMedia('(max-width:767px)').matches)return; // V66.3: one mobile owner

function getLatest(){
  return document.querySelector(
    'section.home-block.home-block--fixed-products.show-all.barah-v35-latest'
  ) || Array.prototype.slice.call(
    document.querySelectorAll('section.home-block.home-block--fixed-products.show-all')
  ).find(function(sec){
    var t=(sec.textContent||'').replace(/\s+/g,' ').trim();
    return (
      t.indexOf('وصل حديث')!==-1 ||
      t.indexOf('جديد بارعة')!==-1 ||
      t.indexOf('أحدث المنتجات')!==-1 ||
      t.indexOf('اكتشفها أولاً')!==-1
    );
  }) || null;
}

function moveAfter(anchor,node){
  if(!anchor || !node || !anchor.parentNode) return anchor;
  if(anchor.nextElementSibling!==node){
    anchor.insertAdjacentElement('afterend',node);
  }
  return node;
}

function arrange(){
  var smart =
    document.getElementById('barah-step-smart-storefront-v52') ||
    document.getElementById('barah-step-needs-v51') ||
    document.getElementById('barah-v616-quick-discovery');

  var most=document.getElementById('barah-step-most-viewed');
  var latest=getLatest();
  var preg=document.getElementById('barah-step-pregnancy-v55');
  var senior=document.getElementById('barah-step-senior-v57');
  var decision=document.getElementById('barah-v617-decision-strip');

  if(!smart) return false;

  var cur=smart;
  cur=moveAfter(cur,most);
  cur=moveAfter(cur,latest);
  cur=moveAfter(cur,preg);
  cur=moveAfter(cur,senior);
  cur=moveAfter(cur,decision);

  document.documentElement.setAttribute('data-barah-v623-order','ready');
  return true;
}

function boot(){
  [0,250,700,1400,2600,4500,7000,9500].forEach(function(ms){
    setTimeout(arrange,ms);
  });
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',boot,{once:true});
}else{
  boot();
}
})();


/* ============================================================
   BARAH V62.4 — SENIOR SECTION SMALL IMAGES
   Add 4 small product thumbnails to the senior-care paths
   for better mobile fit and clearer visual communication.
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V624_SENIOR_SMALL_IMAGES__) return;
window.__BARAH_V624_SENIOR_SMALL_IMAGES__=true;

var STYLE='barah-v624-senior-small-images-style';

var THUMBS = {
  cane: {
    img: 'https://cdn.salla.sa/qwxGZ/8d8067fa-a071-4028-9cb5-04261fd3cb8f-494.62365591398x500-85G9UGdwfYJa081ypGrrAT7RH3xFBHE7EQQqzqqK.jpg',
    alt: 'العكاز والتنقل'
  },
  pedal: {
    img: 'https://cdn.files.salla.network/products/71627348/048c45f9-8aea-43e1-8d86-0af1621acda2_900x900.webp',
    alt: 'البيدال والحركة'
  },
  knee: {
    img: 'https://cdn.salla.sa/qwxGZ/d648fc34-32af-4296-ace3-d964c41e8ebf-500x500-HmzQqSu20WD3zl3EdFcv1IqtwwKt0WyOA5SFIptO.jpg',
    alt: 'دعم الركبة'
  },
  comfort: {
    img: 'https://cdn.salla.sa/qwxGZ/e580d499-975b-425d-8273-9646ddd4d8d7-500x500-DSuB4p2AdMuhVbSKcV9WWWDSppM3fIBPvCDMSS8o.jpg',
    alt: 'الراحة والمساج'
  }
};

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
@media(max-width:767px){
  #barah-step-senior-v57 .v614-path{
    position:relative!important;
    overflow:hidden!important;
    min-height:118px!important;
    padding:9px!important;
  }

  #barah-step-senior-v57 .v624-top{
    display:flex!important;
    align-items:flex-start!important;
    gap:8px!important;
    margin-bottom:5px!important;
  }

  #barah-step-senior-v57 .v624-thumb{
    flex:0 0 42px!important;
    width:42px!important;
    height:42px!important;
    border-radius:11px!important;
    overflow:hidden!important;
    border:1px solid #ece4de!important;
    background:#fff!important;
    box-shadow:0 4px 10px rgba(29,22,18,.04)!important;
  }

  #barah-step-senior-v57 .v624-thumb img{
    width:100%!important;
    height:100%!important;
    object-fit:contain!important;
    display:block!important;
    background:#fff!important;
  }

  #barah-step-senior-v57 .v614-icon{
    display:none!important;
  }

  #barah-step-senior-v57 .v624-copy{
    min-width:0!important;
    flex:1!important;
  }

  #barah-step-senior-v57 .v624-copy strong{
    display:block!important;
    color:#2f3d35!important;
    font-size:11px!important;
    line-height:1.38!important;
    font-weight:950!important;
  }

  #barah-step-senior-v57 .v624-copy small{
    display:block!important;
    margin-top:2px!important;
    color:#7a827c!important;
    font-size:8.6px!important;
    line-height:1.4!important;
  }

  #barah-step-senior-v57 .v614-path > .v614-go{
    margin-top:auto!important;
    font-size:9px!important;
    font-weight:900!important;
  }
}
`;
  document.head.appendChild(s);
}

function keyForLink(href){
  var h=(href||'');
  if(h.indexOf(encodeURIComponent('عكاز'))!==-1 || h.indexOf('عكاز')!==-1) return 'cane';
  if(h.indexOf(encodeURIComponent('بيدال'))!==-1 || h.indexOf('بيدال')!==-1) return 'pedal';
  if(h.indexOf(encodeURIComponent('ركبة'))!==-1 || h.indexOf('ركبة')!==-1) return 'knee';
  return 'comfort';
}

function mount(){
  addStyle();
  var root=document.getElementById('barah-step-senior-v57');
  if(!root) return false;

  var cards=root.querySelectorAll('.v614-path');
  if(!cards.length) return false;

  cards.forEach(function(card){
    if(card.querySelector('.v624-top')) return;

    var key=keyForLink(card.getAttribute('href')||'');
    var data=THUMBS[key];

    var title=card.querySelector('strong');
    var desc=card.querySelector('small');
    var go=card.querySelector('.v614-go');

    var top=document.createElement('div');
    top.className='v624-top';

    var thumb=document.createElement('span');
    thumb.className='v624-thumb';
    thumb.innerHTML='<img loading="lazy" decoding="async" src="'+data.img+'" alt="'+data.alt+'">';

    var copy=document.createElement('span');
    copy.className='v624-copy';

    if(title) copy.appendChild(title);
    if(desc) copy.appendChild(desc);

    top.appendChild(thumb);
    top.appendChild(copy);

    card.insertBefore(top, card.firstChild);
    if(go) card.appendChild(go);
  });

  document.documentElement.setAttribute('data-barah-v624','ready');
  return true;
}

function boot(){
  [0,350,900,1800].forEach(function(ms){setTimeout(mount,ms);});
}
if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',boot,{once:true});
}else{
  boot();
}
})();


/* ============================================================
   BARAH V62.5 — PREGNANCY 6 MINI IMAGES
   Mobile: show 6 miniature tiles inside the pregnancy section
   and keep the section shorter/cleaner.
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V625_PREG_6_MINI__) return;
window.__BARAH_V625_PREG_6_MINI__=true;

var STYLE='barah-v625-preg-6-mini-style';

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
@media(max-width:767px){
  #barah-step-pregnancy-v55 .v625-mini-gallery{
    display:grid!important;
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
    gap:8px!important;
    margin:8px 0 8px!important;
  }

  #barah-step-pregnancy-v55 .v625-mini{
    display:block!important;
    text-decoration:none!important;
    background:#fff!important;
    border:1px solid #eee3dc!important;
    border-radius:14px!important;
    overflow:hidden!important;
    box-shadow:0 6px 16px rgba(29,22,18,.035)!important;
  }

  #barah-step-pregnancy-v55 .v625-mini-media{
    position:relative!important;
    aspect-ratio:1/1!important;
    background:#fff!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    padding:6px!important;
  }

  #barah-step-pregnancy-v55 .v625-mini-media img{
    width:100%!important;
    height:100%!important;
    object-fit:contain!important;
    display:block!important;
  }

  #barah-step-pregnancy-v55 .v625-mini-badge{
    position:absolute!important;
    top:5px!important;
    right:5px!important;
    padding:3px 6px!important;
    border-radius:999px!important;
    background:#fff2ea!important;
    color:#c75a26!important;
    border:1px solid #f2d7c7!important;
    font-size:7.4px!important;
    font-weight:900!important;
    line-height:1!important;
  }

  #barah-step-pregnancy-v55 .v625-mini-copy{
    padding:7px 7px 8px!important;
  }

  #barah-step-pregnancy-v55 .v625-mini-copy strong{
    display:block!important;
    color:#261d18!important;
    font-size:9.2px!important;
    line-height:1.42!important;
    font-weight:900!important;
    display:-webkit-box!important;
    -webkit-line-clamp:2!important;
    -webkit-box-orient:vertical!important;
    overflow:hidden!important;
    min-height:26px!important;
  }

  #barah-step-pregnancy-v55 .v625-mini-copy small{
    display:block!important;
    margin-top:4px!important;
    color:#d94c21!important;
    font-size:9.2px!important;
    font-weight:950!important;
  }

  /* keep section short on mobile */
  #barah-step-pregnancy-v55 .preg-grid{
    display:none!important;
  }
}
`;
  document.head.appendChild(s);
}

function makeTile(item){
  var a=document.createElement('a');
  a.className='v625-mini';
  a.href=item.href;
  a.innerHTML=
    '<span class="v625-mini-media">'+
      (item.tag?'<span class="v625-mini-badge">'+item.tag+'</span>':'')+
      '<img loading="lazy" decoding="async" src="'+item.img+'" alt="'+item.title.replace(/"/g,'&quot;')+'">'+
    '</span>'+
    '<span class="v625-mini-copy"><strong>'+item.title+'</strong><small>'+(item.price||'')+'</small></span>';
  return a;
}

function buildItems(root){
  var items=[];
  root.querySelectorAll('.preg-card').forEach(function(card){
    var img=card.querySelector('img');
    var title=card.querySelector('h3');
    var price=card.querySelector('.preg-price');
    var tag=card.querySelector('.preg-tag');
    if(img && title && items.length<6){
      items.push({
        href: card.getAttribute('href') || '#',
        img: img.getAttribute('src') || '',
        title: (title.textContent||'').trim(),
        price: price ? (price.textContent||'').trim() : '',
        tag: tag ? (tag.textContent||'').trim() : ''
      });
    }
  });

  /* if original section has fewer than 6 products, complete the mini gallery
     with compact repeats so the visual count remains 6 as requested */
  var base=items.slice();
  var i=0;
  while(items.length<6 && base.length){
    var ref=base[i % base.length];
    items.push({
      href: ref.href,
      img: ref.img,
      title: ref.title,
      price: ref.price,
      tag: ref.tag
    });
    i++;
  }

  return items.slice(0,6);
}

function mount(){
  addStyle();
  var root=document.getElementById('barah-step-pregnancy-v55');
  if(!root) return false;

  var eyebrow=root.querySelector('.barah-v61-story-eyebrow');
  var storyTitle=root.querySelector('.barah-v61-story h3');
  if(eyebrow) eyebrow.textContent='🤍 ركن أهدأ للأم والحوامل';
  if(storyTitle) storyTitle.textContent='لأن الراحة تبدأ من التفاصيل الصغيرة';

  var story=root.querySelector('.barah-v61-story');
  if(!story) return false;

  var old=root.querySelector('.v625-mini-gallery');
  if(old) old.remove();

  var items=buildItems(root);
  if(!items.length) return false;

  var gallery=document.createElement('div');
  gallery.className='v625-mini-gallery';
  items.forEach(function(item){ gallery.appendChild(makeTile(item)); });

  story.insertAdjacentElement('afterend', gallery);

  root.setAttribute('data-barah-v625','mini-6');
  return true;
}

function boot(){
  [0,300,900,1800,3000].forEach(function(ms){setTimeout(mount,ms);});
}
if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',boot,{once:true});
}else{
  boot();
}
})();


/* ============================================================
   BARAH V62.6 — FIX PREGNANCY MINI GALLERY
   - Hidden on desktop/tablet
   - 6 UNIQUE real products on mobile
   - 3x2 clean grid
   - No duplicated images/products
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V626_PREG_FIX__) return;
window.__BARAH_V626_PREG_FIX__=true;

var STYLE='barah-v626-preg-fix-style';

var ITEMS=[
  {
    id:'1939425047',
    title:'حزام دعم البطن وأسفل الظهر للحامل',
    tag:'دعم الحمل',
    price:'39 ر.س',
    img:'https://cdn.salla.sa/qwxGZ/e7bfbe78-5498-466e-94ee-70f6d06518bc-500x500-knAmD7F4CMgQ8BaJFPaMyNDU7ZuZ2EU5C6PgnkIB.jpg',
    href:'https://barahstore.com/ar/product-1939425047/p1939425047'
  },
  {
    id:'1737673536',
    title:'وسادة حمل على شكل U',
    tag:'راحة',
    price:'69 ر.س',
    img:'https://cdn.salla.sa/qwxGZ/0b82500c-5a87-478c-a484-f16d9a901c67-333.33333333333x500-Twa9CKkmDHovBQ32KtRinKbG8WrlpFol1FiCeCp0.png',
    href:'https://barahstore.com/ar/product-1737673536/p1737673536'
  },
  {
    id:'1126035679',
    title:'وسادة حمل على شكل J',
    tag:'مرنة',
    price:'69 ر.س',
    img:'https://cdn.salla.sa/qwxGZ/5b4f7bb2-e850-48ae-a22e-7bff074399e9-500x500-TAaTsNuBMGKc5J7cWuTujvAD3zMIXuK7WPZ7bOcf.png',
    href:'https://barahstore.com/ar/product-1126035679/p1126035679'
  },
  {
    id:'1629509591',
    title:'حزام دعم ما بعد الولادة 3 في 1',
    tag:'بعد الولادة',
    price:'69 ر.س',
    img:'https://cdn.salla.sa/qwxGZ/f3310939-ae33-4bb3-84c0-c639a967ac0c-500x395.04716981132-wZL0syD3j3YWqNdwtKRoZ9iK4PjJqVUTjD9E3pag.jpg',
    href:'https://barahstore.com/ar/product-1629509591/p1629509591'
  },
  {
    id:'1560464903',
    title:'شنطة حفاضات ومستلزمات طفل',
    tag:'للطفل',
    price:'49 ر.س',
    img:'https://cdn.salla.sa/qwxGZ/1303a6b2-8e16-446d-8b43-d09f5b2d9fb5-500x500-6HVEqz3wmVOrTcMrwf7W00Dcc0IPKtMrq2vnPj2X.png',
    href:'https://barahstore.com/ar/product-1560464903/p1560464903'
  },
  {
    id:'361025539',
    title:'سرير وحقيبة سفر للأطفال 4 في 1',
    tag:'للتنقل',
    price:'79 ر.س',
    img:'https://cdn.salla.sa/qwxGZ/220d3580-7b75-4893-8c38-ca273d481b98-500x500-U9JisS2kYGsWtuegZHb2w1f7bGYT5XRJDMqvMsJJ.jpg',
    href:'https://barahstore.com/ar/product-361025539/p361025539'
  }
];

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
/* IMPORTANT: mini gallery never appears on desktop/tablet */
#barah-step-pregnancy-v55 .v625-mini-gallery,
#barah-step-pregnancy-v55 .v626-mini-gallery{
  display:none!important;
}

@media(max-width:767px){
  #barah-step-pregnancy-v55 .v625-mini-gallery{
    display:none!important;
  }

  #barah-step-pregnancy-v55 .v626-mini-gallery{
    display:grid!important;
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
    gap:7px!important;
    margin:8px 0!important;
  }

  #barah-step-pregnancy-v55 .v626-mini{
    display:block!important;
    overflow:hidden!important;
    text-decoration:none!important;
    border:1px solid #eee3dc!important;
    border-radius:13px!important;
    background:#fff!important;
    box-shadow:0 5px 14px rgba(35,24,18,.035)!important;
  }

  #barah-step-pregnancy-v55 .v626-media{
    position:relative!important;
    aspect-ratio:1/1!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    padding:6px!important;
    background:#fff!important;
  }

  #barah-step-pregnancy-v55 .v626-media img{
    width:100%!important;
    height:100%!important;
    display:block!important;
    object-fit:contain!important;
    filter:none!important;
    transform:none!important;
  }

  #barah-step-pregnancy-v55 .v626-badge{
    position:absolute!important;
    top:5px!important;
    right:5px!important;
    z-index:2!important;
    padding:3px 5px!important;
    border-radius:999px!important;
    background:#fff1e8!important;
    border:1px solid #f2d6c5!important;
    color:#c25523!important;
    font-size:7px!important;
    line-height:1!important;
    font-weight:900!important;
  }

  #barah-step-pregnancy-v55 .v626-copy{
    padding:6px 6px 7px!important;
  }

  #barah-step-pregnancy-v55 .v626-copy strong{
    display:-webkit-box!important;
    -webkit-line-clamp:2!important;
    -webkit-box-orient:vertical!important;
    overflow:hidden!important;
    min-height:25px!important;
    color:#271e19!important;
    font-size:8.8px!important;
    line-height:1.42!important;
    font-weight:900!important;
  }

  #barah-step-pregnancy-v55 .v626-copy small{
    display:block!important;
    margin-top:4px!important;
    color:#d94c21!important;
    font-size:8.8px!important;
    font-weight:950!important;
  }

  /* keep the section compact: mini gallery replaces large cards on mobile */
  #barah-step-pregnancy-v55 .preg-grid{
    display:none!important;
  }
}

@media(max-width:390px){
  #barah-step-pregnancy-v55 .v626-mini-gallery{
    gap:6px!important;
  }

  #barah-step-pregnancy-v55 .v626-copy strong{
    font-size:8.4px!important;
  }
}
`;
  document.head.appendChild(s);
}

function createCard(p){
  var a=document.createElement('a');
  a.className='v626-mini';
  a.href=p.href;
  a.setAttribute('data-product-id',p.id);
  a.innerHTML=
    '<span class="v626-media">'+
      '<span class="v626-badge">'+p.tag+'</span>'+
      '<img loading="lazy" decoding="async" src="'+p.img+'" alt="'+p.title.replace(/"/g,'&quot;')+'">'+
    '</span>'+
    '<span class="v626-copy">'+
      '<strong>'+p.title+'</strong>'+
      '<small>'+p.price+'</small>'+
    '</span>';
  return a;
}

function mount(){
  addStyle();
  var root=document.getElementById('barah-step-pregnancy-v55');
  if(!root) return false;

  var existing=root.querySelector('.v626-mini-gallery');
  if(existing){
    root.setAttribute('data-barah-v626','six-unique-mobile');
    return true;
  }

  /* remove the old flawed gallery once, if an earlier layer created it */
  root.querySelectorAll('.v625-mini-gallery').forEach(function(x){x.remove();});

  var story=root.querySelector('.barah-v61-story');
  if(!story) return false;

  var gallery=document.createElement('div');
  gallery.className='v626-mini-gallery';

  ITEMS.forEach(function(p){
    gallery.appendChild(createCard(p));
  });

  story.insertAdjacentElement('afterend',gallery);

  root.setAttribute('data-barah-v626','six-unique-mobile');
  return true;
}

function boot(){
  var tries=0;
  function attempt(){
    tries++;
    if(mount() || tries>=8) return;
    setTimeout(attempt,220);
  }
  attempt();
}
if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',boot,{once:true});
}else{
  boot();
}
})();


/* ============================================================
   BARAH V64 — MOBILE LATEST FIX + NO-FLICKER LAUNCH
   - Removes legacy reveal flicker
   - Latest products on mobile become compact 2x2 grid
   - No entrance transforms/opacity animations
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V64_MOBILE_LATEST_NOFLICKER__) return;
window.__BARAH_V64_MOBILE_LATEST_NOFLICKER__=true;

var STYLE='barah-v64-mobile-latest-noflicker-style';

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
/* ---------- no entrance flicker / no reveal motion ---------- */
#barah-step-hero-v12,
#barah-step-shipping-v24,
#barah-v616-quick-discovery,
#barah-step-smart-storefront-v52,
#barah-step-needs-v51,
#barah-step-pregnancy-v55,
#barah-step-senior-v57,
#barah-v617-decision-strip,
#barah-step-most-viewed,
section.barah-v35-latest,
#barah-step-catalog-v32,
#barah-step-wholesale-v32{
  opacity:1!important;
  visibility:visible!important;
  transform:none!important;
  animation:none!important;
  transition:none!important;
}

#barah-step-hero-v12 *,
#barah-step-shipping-v24 *,
#barah-v616-quick-discovery *,
#barah-step-smart-storefront-v52 *,
#barah-step-needs-v51 *,
#barah-step-pregnancy-v55 *,
#barah-step-senior-v57 *,
#barah-v617-decision-strip *,
#barah-step-most-viewed *,
section.barah-v35-latest *,
#barah-step-catalog-v32 *,
#barah-step-wholesale-v32 *{
  animation:none!important;
}

/* ---------- MOBILE: Latest = compact 2 x 2, no empty height ---------- */
@media(max-width:767px){
  section.home-block.home-block--fixed-products.show-all.barah-v35-latest{
    height:auto!important;
    min-height:0!important;
    max-height:none!important;
    overflow:hidden!important;
    padding:12px 10px 13px!important;
    border-radius:17px!important;
  }

  section.barah-v35-latest .barah-v35-latest-head{
    margin-bottom:9px!important;
    align-items:center!important;
  }

  section.barah-v35-latest .barah-v35-copy h2{
    font-size:20px!important;
    line-height:1.3!important;
  }

  section.barah-v35-latest .barah-v35-copy p{
    margin-top:3px!important;
    font-size:9px!important;
    line-height:1.45!important;
  }

  section.barah-v35-latest .grid-block.products-list-container.vertical-products{
    display:grid!important;
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:8px!important;
    width:100%!important;
    height:auto!important;
    min-height:0!important;
    max-height:none!important;
    overflow:visible!important;
    padding:0!important;
    margin:0!important;
    scroll-snap-type:none!important;
  }

  section.barah-v35-latest custom-salla-product-card.product-block{
    display:block!important;
    width:100%!important;
    max-width:none!important;
    min-width:0!important;
    height:auto!important;
    min-height:0!important;
    max-height:none!important;
    flex:none!important;
    align-self:start!important;
    margin:0!important;
    overflow:visible!important;
  }

  /* show four only: two rows x two cards */
  section.barah-v35-latest custom-salla-product-card.product-block:nth-child(n+5){
    display:none!important;
  }

  /* neutralize inherited fixed/stretch heights inside the native Salla card */
  section.barah-v35-latest custom-salla-product-card.product-block > *,
  section.barah-v35-latest custom-salla-product-card.product-block .product,
  section.barah-v35-latest custom-salla-product-card.product-block .product-card,
  section.barah-v35-latest custom-salla-product-card.product-block .product-block,
  section.barah-v35-latest custom-salla-product-card.product-block .product-block__info,
  section.barah-v35-latest custom-salla-product-card.product-block .product-block__content,
  section.barah-v35-latest custom-salla-product-card.product-block .product-block__thumb,
  section.barah-v35-latest custom-salla-product-card.product-block .product-block__image{
    height:auto!important;
    min-height:0!important;
    max-height:none!important;
  }

  section.barah-v35-latest custom-salla-product-card.product-block .product,
  section.barah-v35-latest custom-salla-product-card.product-block .product-card{
    display:flex!important;
    flex-direction:column!important;
    border-radius:14px!important;
    overflow:hidden!important;
  }

  section.barah-v35-latest custom-salla-product-card.product-block .product-block__thumb,
  section.barah-v35-latest custom-salla-product-card.product-block .product-block__image,
  section.barah-v35-latest custom-salla-product-card.product-block .product-image{
    aspect-ratio:1/1!important;
    padding:5px!important;
  }

  section.barah-v35-latest custom-salla-product-card.product-block img{
    display:block!important;
    width:100%!important;
    height:128px!important;
    max-height:128px!important;
    object-fit:contain!important;
    padding:5px!important;
    margin:0 auto!important;
    transform:none!important;
    filter:none!important;
  }

  section.barah-v35-latest custom-salla-product-card.product-block .product-block__info,
  section.barah-v35-latest custom-salla-product-card.product-block .product-block__content{
    padding:8px!important;
  }

  section.barah-v35-latest custom-salla-product-card.product-block .product-title,
  section.barah-v35-latest custom-salla-product-card.product-block .product-block__title,
  section.barah-v35-latest custom-salla-product-card.product-block h3,
  section.barah-v35-latest custom-salla-product-card.product-block h4{
    min-height:30px!important;
    max-height:30px!important;
    margin:0 0 5px!important;
    font-size:10px!important;
    line-height:1.5!important;
    display:-webkit-box!important;
    -webkit-line-clamp:2!important;
    -webkit-box-orient:vertical!important;
    overflow:hidden!important;
  }

  section.barah-v35-latest custom-salla-product-card.product-block button,
  section.barah-v35-latest custom-salla-product-card.product-block .btn,
  section.barah-v35-latest custom-salla-product-card.product-block .btn--add-to-cart,
  section.barah-v35-latest custom-salla-product-card.product-block [class*="add-to-cart"]{
    width:100%!important;
    min-height:36px!important;
    height:36px!important;
    margin-top:7px!important;
    border-radius:9px!important;
    font-size:10px!important;
    line-height:1!important;
  }

  /* show-more stays directly under cards, not after a tall blank area */
  section.barah-v35-latest .barah-v35-all,
  section.barah-v35-latest > a[href*="latest-products"],
  section.barah-v35-latest a[href*="products"]{
    margin-top:10px!important;
  }
}

@media(max-width:390px){
  section.barah-v35-latest custom-salla-product-card.product-block img{
    height:116px!important;
    max-height:116px!important;
  }
}
`;
  (document.head||document.documentElement).appendChild(s);
}

function cleanBoot(){
  /* remove any stale legacy preboot styles/attributes if a cached layer injected them */
  ['barah-v35-preboot-style','barah-v32-preboot-style'].forEach(function(id){
    var x=document.getElementById(id);
    if(x) x.remove();
  });
  document.documentElement.setAttribute('data-barah-v35','ready');
  document.documentElement.setAttribute('data-barah-v32','ready');

  addStyle();
  document.documentElement.setAttribute('data-barah-v64','ready');
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',cleanBoot,{once:true});
}else{
  cleanBoot();
}
setTimeout(cleanBoot,80);
setTimeout(cleanBoot,300);
setTimeout(cleanBoot,900);
})();


/* ============================================================
   BARAH V64.3 — MOBILE LATEST MIRROR
   Mobile only: replace native Salla "وصل حديثًا" with a
   compact controlled 2x2 block. Desktop keeps native section.
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V643_MOBILE_LATEST_MIRROR__) return;
window.__BARAH_V643_MOBILE_LATEST_MIRROR__=true;

var ROOT='barah-v643-mobile-latest';
var STYLE='barah-v643-mobile-latest-style';

var ITEMS=[
  {
    id:'2127094711',
    name:'جهاز خيط مائي للأسنان محمول وقابل للشحن',
    category:'العناية الشخصية',
    price:'29.8 ر.س',
    image:'https://cdn.salla.sa/qwxGZ/products/bS83aXwU7m3IjTosOp2wZoC0Ls9PsuLCyfqCyl4I.png',
    url:'https://barahstore.com/ar/product-2127094711/p2127094711'
  },
  {
    id:'246329873',
    name:'مقعد مرحاض للأطفال مع سلم للتدريب على الحمام',
    category:'مستلزمات الطفل',
    price:'59 ر.س',
    image:'https://cdn.salla.sa/qwxGZ/d5cda8ca-fcb8-4db6-b3b0-5c111c31c537-448.79518072289x500-QksmsLZKAYtFBqC3739zrMM7qvMZtMjb27sE9ir2.jpg',
    url:'https://barahstore.com/ar/product-246329873/p246329873'
  },
  {
    id:'1820406741',
    name:'حامل جوال للسيارة يثبت على لوحة العدادات',
    category:'إكسسوارات السيارة',
    price:'14 ر.س',
    image:'https://cdn.salla.sa/qwxGZ/0c06a8b1-4201-4410-a122-2dc149fc27ed-439.39393939394x500-BV3KTLKPW9yXoHwRoQi3rGbn3Ud6hCvsvAnYRg2q.jpg',
    url:'https://barahstore.com/ar/product-1820406741/p1820406741'
  },
  {
    id:'961212354',
    name:'حامل هاتف وتابلت قابل للطي',
    category:'إكسسوارات الجوال',
    price:'11.5 ر.س',
    image:'https://cdn.salla.sa/qwxGZ/be80063d-5d9a-4a7c-9183-5180179bc889-500x500-HsqynKIgg3lKpIryiGbGDcCo4n1ez0uBw6e9M3zM.jpg',
    url:'https://barahstore.com/ar/product-961212354/p961212354'
  }
];

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
#${ROOT}{display:none!important}

@media(max-width:767px){
  /* Native latest is hidden on mobile only */
  section.home-block.home-block--fixed-products.show-all.barah-v35-latest{
    display:none!important;
  }

  #${ROOT}{
    display:block!important;
    direction:rtl!important;
    width:calc(100% - 20px)!important;
    margin:0 10px 12px!important;
    box-sizing:border-box!important;
    font-family:inherit!important;
  }

  #${ROOT} *{box-sizing:border-box!important}

  #${ROOT} .v643-shell{
    padding:12px!important;
    border:1px solid #eadfd7!important;
    border-radius:18px!important;
    background:linear-gradient(180deg,#fff,#fffaf7)!important;
    box-shadow:0 10px 24px rgba(35,24,18,.045)!important;
  }

  #${ROOT} .v643-head{
    display:flex!important;
    align-items:flex-start!important;
    justify-content:space-between!important;
    gap:10px!important;
    margin-bottom:10px!important;
  }

  #${ROOT} .v643-eyebrow{
    display:block!important;
    margin-bottom:3px!important;
    color:#ef6a35!important;
    font-size:8.5px!important;
    font-weight:900!important;
  }

  #${ROOT} h2{
    margin:0!important;
    color:#211914!important;
    font-size:21px!important;
    line-height:1.3!important;
    font-weight:950!important;
  }

  #${ROOT} .v643-sub{
    margin:4px 0 0!important;
    color:#7c6e65!important;
    font-size:9px!important;
    line-height:1.5!important;
  }

  #${ROOT} .v643-all{
    flex:0 0 auto!important;
    min-height:36px!important;
    padding:0 10px!important;
    display:inline-flex!important;
    align-items:center!important;
    justify-content:center!important;
    border:1px solid #eadfd7!important;
    border-radius:10px!important;
    background:#fff!important;
    color:#40352e!important;
    text-decoration:none!important;
    font-size:9px!important;
    font-weight:900!important;
  }

  #${ROOT} .v643-grid{
    display:grid!important;
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:8px!important;
  }

  #${ROOT} .v643-card{
    display:flex!important;
    min-width:0!important;
    flex-direction:column!important;
    overflow:hidden!important;
    text-decoration:none!important;
    border:1px solid #eee4dd!important;
    border-radius:14px!important;
    background:#fff!important;
  }

  #${ROOT} .v643-media{
    position:relative!important;
    height:112px!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    padding:7px!important;
    background:#fff!important;
  }

  #${ROOT} .v643-media img{
    display:block!important;
    width:100%!important;
    height:98px!important;
    object-fit:contain!important;
    transform:none!important;
    filter:none!important;
  }

  /* Decorative heart has no wishlist behavior; hide to avoid false interaction. */
  #${ROOT} .v643-heart{
    display:none!important;
  }
  #${ROOT} .v643-heart{
    position:absolute!important;
    top:7px!important;
    right:7px!important;
    width:28px!important;
    height:28px!important;
    display:grid!important;
    place-items:center!important;
    border-radius:9px!important;
    background:#ffae8d!important;
    color:#6f584f!important;
    font-size:14px!important;
  }

  #${ROOT} .v643-body{
    display:flex!important;
    flex:1!important;
    flex-direction:column!important;
    padding:8px!important;
  }

  #${ROOT} .v643-cat{
    margin-bottom:4px!important;
    color:#8a786e!important;
    font-size:8px!important;
    line-height:1.3!important;
  }

  #${ROOT} .v643-name{
    margin:0!important;
    min-height:30px!important;
    color:#221a16!important;
    font-size:10px!important;
    line-height:1.5!important;
    font-weight:900!important;
    display:-webkit-box!important;
    -webkit-line-clamp:2!important;
    -webkit-box-orient:vertical!important;
    overflow:hidden!important;
  }

  #${ROOT} .v643-price{
    margin-top:5px!important;
    color:#e25c2b!important;
    font-size:11px!important;
    font-weight:950!important;
  }

  #${ROOT} .v643-cta{
    min-height:34px!important;
    margin-top:6px!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    border-radius:10px!important;
    background:linear-gradient(135deg,#ff7a18,#ef4444)!important;
    color:#fff!important;
    font-size:9.5px!important;
    font-weight:950!important;
  }

  #${ROOT} .v643-more{
    width:max-content!important;
    min-height:34px!important;
    margin:10px auto 0!important;
    padding:0 13px!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    border-radius:10px!important;
    background:#171717!important;
    color:#fff!important;
    text-decoration:none!important;
    font-size:9px!important;
    font-weight:900!important;
  }
}

@media(max-width:767px){
  /* V66.9.2: live Salla latest products; no duplicated hardcoded cards. */
  #${ROOT} .v643-grid{display:block!important;min-height:0!important}
  #${ROOT} .v643-grid salla-products-list{display:block!important;width:100%!important}
  #${ROOT} .v643-grid salla-products-list .grid,
  #${ROOT} .v643-grid salla-products-list .products-grid,
  #${ROOT} .v643-grid salla-products-list .products-list-container,
  #${ROOT} .v643-grid salla-products-list .s-products-list-wrapper{
    display:grid!important;
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:8px!important;
  }
  #${ROOT} .v643-grid salla-products-list custom-salla-product-card,
  #${ROOT} .v643-grid salla-products-list salla-product-card{
    min-width:0!important;
    width:100%!important;
    max-width:none!important;
    height:auto!important;
    transform:none!important;
  }
  #${ROOT} .v643-grid salla-products-list img{
    object-fit:contain!important;
    max-height:150px!important;
  }
}
@media(max-width:390px){
  #${ROOT} .v643-media{height:106px!important}
  #${ROOT} .v643-media img{height:94px!important}
  #${ROOT} .v643-name{font-size:9.6px!important}
}
`;
  document.head.appendChild(s);
}

function card(p){
  return ''+
    '<a class="v643-card" href="'+p.url+'" data-product-id="'+p.id+'">'+
      '<span class="v643-media"><span class="v643-heart">♡</span><img loading="lazy" decoding="async" src="'+p.image+'" alt="'+p.name.replace(/"/g,'&quot;')+'"></span>'+
      '<span class="v643-body">'+
        '<span class="v643-cat">'+p.category+'</span>'+
        '<strong class="v643-name">'+p.name+'</strong>'+
        '<span class="v643-price">'+p.price+'</span>'+
        '<span class="v643-cta">عرض وشراء ←</span>'+
      '</span>'+
    '</a>';
}

function build(){
  var sec=document.getElementById(ROOT);
  if(sec) return sec;

  sec=document.createElement('section');
  sec.id=ROOT;
  sec.setAttribute('aria-label','وصل حديثًا');

  sec.innerHTML=
    '<div class="v643-shell">'+
      '<div class="v643-head">'+
        '<div>'+
          '<span class="v643-eyebrow">جديد بارعة</span>'+
          '<h2>وصل حديثًا ✨</h2>'+
          '<p class="v643-sub">منتجات جديدة تستحق النظرة الأولى.</p>'+
        '</div>'+
        '<a class="v643-all" href="https://barahstore.com/ar/latest-products">عرض كل المنتجات ←</a>'+
      '</div>'+
      '<div class="v643-grid"><salla-products-list source="latest" limit="4" aria-label="أحدث المنتجات في بارعة"></salla-products-list></div>'+
      '<a class="v643-more" href="https://barahstore.com/ar/latest-products">عرض المزيد</a>'+
    '</div>';

  return sec;
}

function nativeLatest(){
  return document.querySelector('section.barah-v35-latest') ||
    Array.prototype.slice.call(
      document.querySelectorAll('section.home-block.home-block--fixed-products.show-all')
    ).find(function(sec){
      var t=(sec.textContent||'').replace(/\s+/g,' ').trim();
      return t.indexOf('وصل حديث')!==-1 ||
             t.indexOf('جديد بارعة')!==-1 ||
             t.indexOf('أحدث المنتجات')!==-1;
    }) || null;
}

function place(){
  addStyle();
  var mirror=build();
  var native=nativeLatest();
  var most=document.getElementById('barah-step-most-viewed');
  var preg=document.getElementById('barah-step-pregnancy-v55');
  var main=document.querySelector('main')||document.body;

  if(native && native.parentNode){
    if(native.nextElementSibling!==mirror){
      native.insertAdjacentElement('afterend',mirror);
    }
  }else if(most && most.parentNode){
    most.insertAdjacentElement('afterend',mirror);
  }else if(preg && preg.parentNode){
    preg.insertAdjacentElement('beforebegin',mirror);
  }else if(main && !mirror.parentNode){
    main.appendChild(mirror);
  }

  document.documentElement.setAttribute('data-barah-v643','ready');
  return true;
}

function boot(){
  [0,250,700,1500,3000].forEach(function(ms){setTimeout(place,ms);});
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',boot,{once:true});
}else{
  boot();
}
})();


/* ============================================================
   BARAH V64.4 — REMOVE DUPLICATE LATEST ON MOBILE
   Mobile: show custom V643 only, hard-hide every native/latest clone.
   Desktop: hide custom V643 and restore native Salla latest.
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V644_DEDUPE_LATEST__) return;
window.__BARAH_V644_DEDUPE_LATEST__=true;

var ROOT='barah-v643-mobile-latest';

function looksLikeNativeLatest(sec){
  if(!sec || sec.id===ROOT) return false;

  var text=(sec.textContent||'').replace(/\s+/g,' ').trim();
  var hit =
    text.indexOf('وصل حديث')!==-1 ||
    text.indexOf('جديد بارعة')!==-1 ||
    text.indexOf('أحدث المنتجات')!==-1 ||
    text.indexOf('اكتشفها أولاً')!==-1;

  if(!hit) return false;

  /* avoid catching unrelated tiny buttons/blocks */
  return !!(
    sec.classList.contains('home-block') ||
    sec.classList.contains('barah-v35-latest') ||
    sec.querySelector('custom-salla-product-card') ||
    sec.querySelector('.products-list-container')
  );
}

function nativeLatestSections(){
  return Array.prototype.slice.call(document.querySelectorAll('section'))
    .filter(looksLikeNativeLatest);
}

function apply(){
  var mobile=window.matchMedia('(max-width: 767px)').matches;
  var mirror=document.getElementById(ROOT);
  var natives=nativeLatestSections();

  if(mobile){
    /* custom mobile block only */
    if(mirror){
      mirror.style.setProperty('display','block','important');
      mirror.style.setProperty('visibility','visible','important');
      mirror.style.setProperty('opacity','1','important');
    }

    natives.forEach(function(sec){
      sec.setAttribute('data-barah-v644-native-latest','hidden-mobile');
      sec.style.setProperty('display','none','important');
      sec.style.setProperty('visibility','hidden','important');
      sec.style.setProperty('height','0','important');
      sec.style.setProperty('min-height','0','important');
      sec.style.setProperty('max-height','0','important');
      sec.style.setProperty('margin','0','important');
      sec.style.setProperty('padding','0','important');
      sec.style.setProperty('overflow','hidden','important');
    });

  }else{
    /* desktop = native Salla only */
    if(mirror){
      mirror.style.setProperty('display','none','important');
    }

    natives.forEach(function(sec){
      sec.removeAttribute('data-barah-v644-native-latest');
      ['display','visibility','height','min-height','max-height','margin','padding','overflow']
        .forEach(function(prop){ sec.style.removeProperty(prop); });
    });
  }

  document.documentElement.setAttribute(
    'data-barah-v644-latest',
    mobile ? 'custom-mobile-only' : 'native-desktop-only'
  );
}

function boot(){
  [0,120,350,800,1500,3000,5500].forEach(function(ms){
    setTimeout(apply,ms);
  });
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',boot,{once:true});
}else{
  boot();
}

window.addEventListener('resize',function(){
  clearTimeout(window.__BARAH_V644_RESIZE_T__);
  window.__BARAH_V644_RESIZE_T__=setTimeout(apply,120);
},{passive:true});

})();


/* ============================================================
   BARAH V64.5 — MOST VIEWED MOBILE 3x2
   Mobile only:
   - "الأكثر مشاهدة مؤخرًا" becomes a 2-column grid
   - 3 rows = 6 products visible
   - cleaner card rhythm and compact layout
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V645_MOST_VIEWED_MOBILE_GRID__) return;
window.__BARAH_V645_MOST_VIEWED_MOBILE_GRID__=true;

var STYLE='barah-v645-most-viewed-mobile-grid-style';

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
@media(max-width:767px){
  #barah-step-most-viewed{
    width:calc(100% - 20px)!important;
    margin:0 10px 12px!important;
    padding:12px!important;
    border-radius:18px!important;
    overflow:hidden!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__head{
    margin-bottom:10px!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__track{
    display:grid!important;
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:8px!important;
    overflow:visible!important;
    padding:0!important;
    margin:0!important;
    scroll-snap-type:none!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__card{
    width:100%!important;
    max-width:none!important;
    min-width:0!important;
    flex:none!important;
    margin:0!important;
    border-radius:14px!important;
    overflow:hidden!important;
  }

  /* show only first 6 products on mobile */
  #barah-step-most-viewed .barah-step-most-viewed__card:nth-child(n+7){
    display:none!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__product{
    min-height:0!important;
    height:auto!important;
    padding:0!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__media{
    min-height:118px!important;
    height:118px!important;
    padding:6px!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    background:#fff!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__product img{
    width:100%!important;
    height:104px!important;
    object-fit:contain!important;
    display:block!important;
    margin:0 auto!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__body{
    padding:8px!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__eyebrow{
    font-size:8px!important;
    margin-bottom:3px!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__name{
    font-size:9.8px!important;
    line-height:1.45!important;
    min-height:28px!important;
    display:-webkit-box!important;
    -webkit-line-clamp:2!important;
    -webkit-box-orient:vertical!important;
    overflow:hidden!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__price{
    margin-top:6px!important;
    font-size:10.5px!important;
    font-weight:900!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__cta{
    min-height:34px!important;
    margin-top:7px!important;
    border-radius:9px!important;
    font-size:9.5px!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__all{
    margin-top:10px!important;
  }
}

@media(max-width:390px){
  #barah-step-most-viewed .barah-step-most-viewed__track{
    gap:7px!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__media{
    min-height:110px!important;
    height:110px!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__product img{
    height:96px!important;
  }

  #barah-step-most-viewed .barah-step-most-viewed__name{
    font-size:9.2px!important;
  }
}
`;
  document.head.appendChild(s);
}

function run(){
  addStyle();
  document.documentElement.setAttribute('data-barah-v645-most-viewed','ready');
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}
setTimeout(run,500);
setTimeout(run,1500);
})();


/* ============================================================
   BARAH V64.6 — MOST VIEWED DATA FIX
   Guarantees up to 6 UNIQUE items:
   live popular data first, fallback fills missing slots.
   Mobile then renders the existing 2-column / 3-row layout.
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V646_MOST_VIEWED_DATA__) return;
window.__BARAH_V646_MOST_VIEWED_DATA__=true;

var ROOT='barah-step-most-viewed';

var FALLBACK6=[
  {
    id:'1747191075',
    name:'سماعة القرآن الكريم للمنزل بالمقبس مع ريموت – SQ669',
    url:'https://barahstore.com/ar/سماعة-القرآن-الكريم-للمنزل-sq669-مع-ريموت-بارعة/p1747191075',
    image:'https://cdn.files.salla.network/products/71627348/fedf598a-5a4c-4473-89b5-4972a2c3bdf3-original.webp'
  },
  {
    id:'1923506631',
    name:'مشط إزالة القمل الكهربائي بفلتر وإضاءة LED',
    url:'https://barahstore.com/ar/product-1923506631/p1923506631',
    image:'https://cdn.salla.sa/qwxGZ/8c8b724b-302f-4e36-9241-4cb4888ce28e-500x500-LIvqUHKA4iwYzlUxDutVqmDDxC8RgDZ7YBpAfou2.png'
  },
  {
    id:'898468432',
    name:'طقم أدوات العناية بالأظافر',
    url:'https://barahstore.com/ar/product-898468432/p898468432',
    image:'https://cdn.salla.sa/qwxGZ/1ab1a1ee-80bd-4baa-800e-6674ceae4c3c-454.6875x500-b6p5enTzDYrOXFY6N6dodENKQUAYF5KUpMeld6m7.jpg'
  },
  {
    id:'1396688213',
    name:'عربة نقل للرحلات قابلة للطي بأربع عجلات',
    url:'https://barahstore.com/ar/product-1396688213/p1396688213',
    image:'https://cdn.salla.sa/qwxGZ/e8645ae5-4e96-489c-b407-7562321e3c8f-475.0265674814x500-xhHmlplr26h80IHOv3BKcddgAf6fOI52tKEa0fYB.jpg'
  },
  {
    id:'1455538329',
    name:'طقم حبال مقاومة رياضية 11 قطعة – 5 مستويات للتمارين المنزلية',
    url:'https://barahstore.com/ar/product-1455538329/p1455538329',
    image:'https://cdn.salla.sa/qwxGZ/515fab97-aab3-448a-8a7b-6b9287691cb0-500x500-EA6WdMUjzvNizNpEGrkn2zERP8MWbIpNct1GNX0K.webp'
  },
  {
    id:'1169543961',
    name:'عقلة جدارية لتمارين السحب المنزلية | Pull Up Bar',
    url:'https://barahstore.com/ar/product-1169543961/p1169543961',
    image:'https://cdn.salla.sa/qwxGZ/25c7de6c-9062-4044-83f1-06e5030dd533-454.6875x500-awxqbgLolsoZzf8uYEmAfrQE8wJ6746kM0sr26ex.jpg'
  }
];

function cardFrom(p){
  var card=document.createElement('article');
  card.className='barah-step-most-viewed__card';
  card.setAttribute('role','listitem');
  card.setAttribute('data-product-id',p.id);

  var product=document.createElement('a');
  product.className='barah-step-most-viewed__product';
  product.href=p.url;
  product.setAttribute('aria-label',p.name);

  var img=document.createElement('img');
  img.src=p.image;
  img.alt=p.name;
  img.loading='lazy';
  img.decoding='async';

  var h=document.createElement('h3');
  h.textContent=p.name;

  var cta=document.createElement('a');
  cta.className='barah-step-most-viewed__cta';
  cta.href=p.url;
  cta.textContent='شاهد المنتج ←';

  product.appendChild(img);
  product.appendChild(h);
  card.appendChild(product);
  card.appendChild(cta);
  return card;
}

function ensureSix(){
  var root=document.getElementById(ROOT);
  if(!root) return false;

  var track=root.querySelector('.barah-step-most-viewed__track');
  if(!track) return false;

  var seen={};
  Array.prototype.slice.call(
    track.querySelectorAll('.barah-step-most-viewed__card')
  ).forEach(function(card){
    var id=card.getAttribute('data-product-id') || '';
    if(!id){
      var a=card.querySelector('a[href]');
      var m=a && (a.href||'').match(/(?:\/p|product-)(\d+)/);
      if(m) id=m[1];
    }
    if(id) seen[String(id)]=1;
  });

  FALLBACK6.forEach(function(p){
    if(track.children.length>=6) return;
    if(seen[p.id]) return;
    track.appendChild(cardFrom(p));
    seen[p.id]=1;
  });

  /* Exactly six on mobile; desktop may still use the same six cleanly */
  Array.prototype.slice.call(
    track.querySelectorAll('.barah-step-most-viewed__card')
  ).forEach(function(card,i){
    if(i<6){
      card.style.removeProperty('display');
    }else{
      if(card.style.display!=='none') card.style.setProperty('display','none','important');
    }
  });

  root.setAttribute(
    'data-barah-v646-count',
    String(track.querySelectorAll('.barah-step-most-viewed__card').length)
  );
  document.documentElement.setAttribute('data-barah-v646','ready');
  return true;
}

function boot(){
  /* run after the remote popular source has had a chance to render */
  [350,900,1700,3000,5200].forEach(function(ms){
    setTimeout(ensureSix,ms);
  });
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',boot,{once:true});
}else{
  boot();
}
})();


/* ============================================================
   BARAH V64.7 — MOBILE MOST VIEWED CUSTOM 3x2
   Mobile only:
   - hide original "يشاهدها العملاء الآن"
   - render independent 6-card 2-column / 3-row grid
   - live popular.json first, fallback fills to 6 unique items
   Desktop keeps the original section.
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V647_MOBILE_MOST_CUSTOM__) return;
window.__BARAH_V647_MOBILE_MOST_CUSTOM__=true;

var ROOT='barah-v647-mobile-most-viewed';
var STYLE='barah-v647-mobile-most-viewed-style';
var SOURCE='https://barah-popular-products.hussho.chatgpt.site/popular.json';

var FALLBACK=[
  {
    id:'1747191075',
    name:'سماعة القرآن الكريم للمنزل بالمقبس مع ريموت – SQ669',
    image:'https://cdn.files.salla.network/products/71627348/fedf598a-5a4c-4473-89b5-4972a2c3bdf3-original.webp',
    url:'https://barahstore.com/ar/سماعة-القرآن-الكريم-للمنزل-sq669-مع-ريموت-بارعة/p1747191075'
  },
  {
    id:'1923506631',
    name:'مشط إزالة القمل الكهربائي بفلتر وإضاءة LED',
    image:'https://cdn.salla.sa/qwxGZ/8c8b724b-302f-4e36-9241-4cb4888ce28e-500x500-LIvqUHKA4iwYzlUxDutVqmDDxC8RgDZ7YBpAfou2.png',
    url:'https://barahstore.com/ar/product-1923506631/p1923506631'
  },
  {
    id:'1455538329',
    name:'طقم حبال مقاومة رياضية 11 قطعة – 5 مستويات',
    image:'https://cdn.salla.sa/qwxGZ/515fab97-aab3-448a-8a7b-6b9287691cb0-500x500-EA6WdMUjzvNizNpEGrkn2zERP8MWbIpNct1GNX0K.webp',
    url:'https://barahstore.com/ar/product-1455538329/p1455538329'
  },
  {
    id:'1810209528',
    name:'مشد قميص رجالي نصف كم لتنسيق البطن والقوام',
    image:'https://cdn.salla.sa/qwxGZ/d2bd95f3-f864-4270-a3e3-b0c6354fe1f5-500x500-1lZRaxLMEAsnXSJQrarwnmmbIEVWVS5TxCkSS8s5.jpg',
    url:'https://barahstore.com/ar/product-1810209528/p1810209528'
  },
  {
    id:'1600022680',
    name:'جهاز بدال تمارين منزلي لليدين والساقين',
    image:'https://cdn.files.salla.network/products/71627348/048c45f9-8aea-43e1-8d86-0af1621acda2_900x900.webp',
    url:'https://barahstore.com/ar/product-1600022680/p1600022680'
  },
  {
    id:'314048946',
    name:'موزع عسل وشراب زجاجي برافعة وقاعدة مانعة للتقطير',
    image:'https://cdn.salla.sa/qwxGZ/d5daee24-034e-48ac-a096-b9c2c3b24e10-500x500-hHCeiui0XlK1TaEvN5fBKRcAerYPMvWWNivbUO9W.webp',
    url:'https://barahstore.com/ar/product-314048946/p314048946'
  }
];

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
#${ROOT}{display:none!important}

@media(max-width:767px){
  /* Original section is completely hidden on mobile */
  #barah-step-most-viewed{
    display:none!important;
  }

  #${ROOT}{
    display:block!important;
    direction:rtl!important;
    width:calc(100% - 20px)!important;
    margin:0 10px 12px!important;
    box-sizing:border-box!important;
    font-family:inherit!important;
  }

  #${ROOT} *{box-sizing:border-box!important}

  #${ROOT} .v647-shell{
    padding:11px!important;
    border:1px solid #eadfd7!important;
    border-radius:18px!important;
    background:linear-gradient(180deg,#fff,#fffaf7)!important;
    box-shadow:0 10px 24px rgba(35,24,18,.045)!important;
  }

  #${ROOT} .v647-head{
    display:flex!important;
    align-items:flex-start!important;
    justify-content:space-between!important;
    gap:8px!important;
    margin-bottom:9px!important;
  }

  #${ROOT} h2{
    margin:0!important;
    color:#211914!important;
    font-size:18px!important;
    line-height:1.3!important;
    font-weight:950!important;
  }

  #${ROOT} .v647-sub{
    margin:3px 0 0!important;
    color:#7e7067!important;
    font-size:8.6px!important;
    line-height:1.45!important;
  }

  #${ROOT} .v647-chips{
    display:flex!important;
    flex-wrap:wrap!important;
    gap:5px!important;
    margin-top:6px!important;
  }

  #${ROOT} .v647-chips span{
    min-height:24px!important;
    padding:0 7px!important;
    display:inline-flex!important;
    align-items:center!important;
    border:1px solid #eadfd7!important;
    border-radius:999px!important;
    background:#fff!important;
    color:#65574f!important;
    font-size:7.5px!important;
    font-weight:850!important;
  }

  #${ROOT} .v647-grid{
    display:grid!important;
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:8px!important;
  }

  #${ROOT} .v647-card{
    display:flex!important;
    flex-direction:column!important;
    min-width:0!important;
    overflow:hidden!important;
    text-decoration:none!important;
    border:1px solid #eee4dd!important;
    border-radius:14px!important;
    background:#fff!important;
  }

  #${ROOT} .v647-media{
    position:relative!important;
    height:112px!important;
    padding:6px!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    background:#fff!important;
  }

  #${ROOT} .v647-media img{
    width:100%!important;
    height:98px!important;
    object-fit:contain!important;
    display:block!important;
    filter:none!important;
    transform:none!important;
  }

  #${ROOT} .v647-fire{
    position:absolute!important;
    top:6px!important;
    right:6px!important;
    width:24px!important;
    height:24px!important;
    display:grid!important;
    place-items:center!important;
    border-radius:8px!important;
    background:#fff1e8!important;
    color:#e85c25!important;
    font-size:12px!important;
  }

  #${ROOT} .v647-body{
    display:flex!important;
    flex:1!important;
    flex-direction:column!important;
    padding:7px!important;
  }

  #${ROOT} .v647-name{
    min-height:28px!important;
    margin:0!important;
    color:#241c18!important;
    font-size:9.4px!important;
    line-height:1.48!important;
    font-weight:900!important;
    display:-webkit-box!important;
    -webkit-line-clamp:2!important;
    -webkit-box-orient:vertical!important;
    overflow:hidden!important;
  }

  #${ROOT} .v647-cta{
    min-height:32px!important;
    margin-top:7px!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    border-radius:9px!important;
    background:linear-gradient(135deg,#ff7a18,#ef4444)!important;
    color:#fff!important;
    font-size:8.8px!important;
    font-weight:950!important;
  }
}

@media(max-width:390px){
  #${ROOT} .v647-grid{gap:7px!important}
  #${ROOT} .v647-media{height:105px!important}
  #${ROOT} .v647-media img{height:91px!important}
  #${ROOT} .v647-name{font-size:9px!important}
}
`;
  document.head.appendChild(s);
}

function normalize(raw){
  var arr=raw && (raw.items||raw.products||raw.data||raw);
  if(!Array.isArray(arr)) return [];

  return arr.map(function(x){
    var url=x.url||x.link||'';
    var id=String(x.id||x.product_id||'');
    if(!id && url){
      var m=String(url).match(/(?:\/p|product-)(\d+)/);
      if(m) id=m[1];
    }
    return {
      id:id,
      name:x.name||x.title||'',
      image:x.image||x.thumbnail||x.main_image||'',
      url:url || (id?'https://barahstore.com/ar/product-'+id+'/p'+id:'')
    };
  }).filter(function(x){
    return x.id && x.name && x.image && x.url;
  });
}

function mergeSix(live){
  var out=[], seen={};

  (live||[]).concat(FALLBACK).forEach(function(p){
    if(out.length>=6) return;
    if(!p || !p.id || seen[p.id]) return;
    seen[p.id]=1;
    out.push(p);
  });

  return out.slice(0,6);
}

function card(p){
  return ''+
    '<a class="v647-card" href="'+p.url+'" data-product-id="'+p.id+'">'+
      '<span class="v647-media"><span class="v647-fire">🔥</span><img loading="lazy" decoding="async" src="'+p.image+'" alt="'+p.name.replace(/"/g,'&quot;')+'"></span>'+
      '<span class="v647-body">'+
        '<strong class="v647-name">'+p.name+'</strong>'+
        '<span class="v647-cta">شاهد المنتج ←</span>'+
      '</span>'+
    '</a>';
}

function build(items){
  var sec=document.getElementById(ROOT);
  if(!sec){
    sec=document.createElement('section');
    sec.id=ROOT;
    sec.setAttribute('aria-label','الأكثر مشاهدة مؤخرًا');
  }

  sec.innerHTML=
    '<div class="v647-shell">'+
      '<div class="v647-head">'+
        '<div><h2>الأكثر مشاهدة مؤخرًا</h2><p class="v647-sub">اختيارات استنادًا إلى مشاهدات 3–5 أكتوبر 2026</p>'+
        '<div class="v647-chips"><span>👀 الأكثر مشاهدة</span><span>📅 3–5 أكتوبر</span><span>✨ اختيارات متنوعة</span></div></div>'+
      '</div>'+
      '<div class="v647-grid">'+items.map(card).join('')+'</div>'+
    '</div>';

  return sec;
}

function place(sec){
  var original=document.getElementById('barah-step-most-viewed');
  var latest=document.getElementById('barah-v643-mobile-latest');
  var nativeLatest=document.querySelector('section.barah-v35-latest');
  var preg=document.getElementById('barah-step-pregnancy-v55');

  if(original && original.parentNode){
    original.insertAdjacentElement('afterend',sec);
  }else if(latest && latest.parentNode){
    latest.insertAdjacentElement('beforebegin',sec);
  }else if(nativeLatest && nativeLatest.parentNode){
    nativeLatest.insertAdjacentElement('beforebegin',sec);
  }else if(preg && preg.parentNode){
    preg.insertAdjacentElement('beforebegin',sec);
  }
}

function render(items){
  addStyle();
  var sec=build(mergeSix(items));
  place(sec);
  document.documentElement.setAttribute('data-barah-v647','ready');
}

function load(){
  render([]);

  if(!window.__BARAH_CAN_REMOTE_POPULAR__) return;

  try{
    var c=new AbortController();
    var t=setTimeout(function(){c.abort()},2800);

    fetch(SOURCE+'?r='+Math.floor(Date.now()/300000),{
      signal:c.signal,
      cache:'no-store'
    })
    .then(function(r){
      if(!r.ok) throw new Error('popular');
      return r.json();
    })
    .then(function(j){
      clearTimeout(t);
      render(normalize(j));
    })
    .catch(function(){
      clearTimeout(t);
    });
  }catch(e){}
}

function boot(){
  /* one render/fetch cycle only; avoids repeated network + DOM redraw */
  setTimeout(load,0);
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',boot,{once:true});
}else{
  boot();
}
})();


/* ============================================================
   BARAH V64.8 — FINAL MOBILE-FIRST LAUNCH POLISH
   Stability-focused; no new sections.
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V648_FINAL_POLISH__) return;
window.__BARAH_V648_FINAL_POLISH__=true;

var STYLE='barah-v648-final-polish-style';

function style(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
@media(max-width:767px){
  /* predictable geometry on the 95% mobile audience */
  main{
    overflow-x:hidden!important;
  }

  #barah-step-hero-v12,
  #barah-step-pregnancy-v55,
  #barah-step-senior-v57,
  #barah-v643-mobile-latest,
  #barah-v647-mobile-most-viewed,
  #barah-step-catalog-v32,
  #barah-step-wholesale-v32{
    contain:layout style!important;
  }

  /* no entrance effects after the launch gate opens */
  main section{
    animation:none!important;
  }

  /* touch targets */
  main a,
  main button{
    -webkit-tap-highlight-color:transparent!important;
  }

  #barah-v643-mobile-latest .v643-cta,
  #barah-v647-mobile-most-viewed .v647-cta{
    min-height:36px!important;
  }

  /* protect content from bottom navigation/floating controls */
  #barah-step-wholesale-v32{
    padding-bottom:8px!important;
  }
}
`;
  (document.head||document.documentElement).appendChild(s);
}

function mark(){
  style();

  var checks={
    hero:!!document.getElementById('barah-step-hero-v12'),
    pregnancy:!!document.getElementById('barah-step-pregnancy-v55'),
    senior:!!document.getElementById('barah-step-senior-v57'),
    latestMobile:!!document.getElementById('barah-v643-mobile-latest'),
    viewedMobile:!!document.getElementById('barah-v647-mobile-most-viewed')
  };

  var ok=Object.keys(checks).every(function(k){return checks[k]});
  document.documentElement.setAttribute('data-barah-v648-launch',ok?'ready':'partial');
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',mark,{once:true});
}else{
  mark();
}
setTimeout(mark,500);
setTimeout(mark,1200);
})();


/* ============================================================
   BARAH V64.8.1 — ORDER CORRECTION
   Base: V64.8
   ONLY swap:
   Pregnancy old position <-> Most Viewed old position.
   Senior / Latest / Footer positions unchanged.
   Conflicting V61.5 and V62.3 order managers disabled.
   ============================================================ */


/* ============================================================
   BARAH V64.8.2 — MOBILE VIEWPORT FIT
   Final visual correction based on live mobile screenshot:
   - Hero 6 products = stable 3x2 grid (no cropped first card)
   - Compact shipping block
   - Bottom navigation safe area
   - No section reordering changes
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V6482_VIEWPORT_FIT__) return;
window.__BARAH_V6482_VIEWPORT_FIT__=true;

var STYLE='barah-v6482-viewport-fit-style';

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
@media(max-width:767px){

  html,body{
    overflow-x:hidden!important;
  }

  body{
    padding-bottom:86px!important;
  }

  /* ===== HERO: 6 compact cards, 3 x 2, no horizontal clipping ===== */
  #barah-step-hero-v12{
    overflow:hidden!important;
  }

  #barah-step-hero-v12 .barah-hero-shell{
    width:100%!important;
    max-width:100%!important;
    overflow:hidden!important;
  }

  #barah-step-hero-v12 .barah-hero-products{
    display:grid!important;
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
    gap:6px!important;
    width:100%!important;
    max-width:100%!important;
    overflow:visible!important;
    padding:0!important;
    margin:0!important;
    scroll-snap-type:none!important;
    transform:none!important;
  }

  #barah-step-hero-v12 .barah-hero-product,
  #barah-step-hero-v12 .barah-v621-extra{
    display:flex!important;
    flex-direction:column!important;
    width:100%!important;
    max-width:none!important;
    min-width:0!important;
    flex:none!important;
    margin:0!important;
    overflow:hidden!important;
    border-radius:12px!important;
    scroll-snap-align:none!important;
  }

  #barah-step-hero-v12 .barah-hero-product img{
    width:100%!important;
    height:86px!important;
    max-height:86px!important;
    aspect-ratio:auto!important;
    object-fit:contain!important;
    padding:5px!important;
    margin:0 auto!important;
  }

  #barah-step-hero-v12 .barah-hero-product strong{
    min-height:28px!important;
    max-height:28px!important;
    padding:0 5px 4px!important;
    font-size:8.3px!important;
    line-height:1.35!important;
    display:-webkit-box!important;
    -webkit-line-clamp:2!important;
    -webkit-box-orient:vertical!important;
    overflow:hidden!important;
  }

  #barah-step-hero-v12 .barah-hero-product small{
    padding:0 5px 6px!important;
    font-size:8.8px!important;
  }

  #barah-step-hero-v12 .barah-hero-pill{
    top:5px!important;
    right:5px!important;
    max-width:calc(100% - 10px)!important;
    padding:3px 5px!important;
    font-size:6.8px!important;
    white-space:nowrap!important;
    overflow:hidden!important;
    text-overflow:ellipsis!important;
  }

  /* ===== SHIPPING: shorter and easier to scan ===== */
  #barah-step-shipping-v24{
    margin-bottom:12px!important;
  }

  #barah-step-shipping-v24 .barah-v24-shell{
    padding:11px!important;
    border-radius:16px!important;
  }

  #barah-step-shipping-v24 .barah-v24-main,
  #barah-step-shipping-v24 .barah-v24-copy{
    gap:8px!important;
  }

  #barah-step-shipping-v24 .barah-v24-copy strong{
    font-size:12px!important;
    line-height:1.45!important;
  }

  #barah-step-shipping-v24 .barah-v24-copy small,
  #barah-step-shipping-v24 .barah-v24-copy p{
    font-size:8.8px!important;
    line-height:1.5!important;
  }

  #barah-step-shipping-v24 .barah-v24-points{
    display:grid!important;
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
    gap:6px!important;
    margin-top:8px!important;
  }

  #barah-step-shipping-v24 .barah-v24-point{
    min-height:44px!important;
    padding:6px 4px!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    text-align:center!important;
    border-radius:10px!important;
    font-size:7.8px!important;
    line-height:1.3!important;
  }

  /* ===== bottom navigation safe area ===== */
  main{
    padding-bottom:10px!important;
  }

  footer{
    padding-bottom:76px!important;
  }

  #barah-step-catalog-v32,
  #barah-step-wholesale-v32{
    scroll-margin-bottom:90px!important;
  }

  /* floating WhatsApp stays above bottom nav but away from CTAs */
  a[href*="wa.me"],
  a[href*="whatsapp"],
  .whatsapp,
  [class*="whatsapp"]{
    bottom:76px!important;
  }
}

@media(max-width:390px){
  #barah-step-hero-v12 .barah-hero-products{
    gap:5px!important;
  }

  #barah-step-hero-v12 .barah-hero-product img{
    height:78px!important;
    max-height:78px!important;
  }

  #barah-step-hero-v12 .barah-hero-product strong{
    font-size:7.9px!important;
  }

  #barah-step-shipping-v24 .barah-v24-point{
    font-size:7.3px!important;
  }
}
`;
  (document.head||document.documentElement).appendChild(s);
}

function run(){
  addStyle();
  document.documentElement.setAttribute('data-barah-v6482','ready');
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}
setTimeout(run,400);
})();


/* ============================================================
   BARAH V64.8.3 — HERO MOBILE STACK LOCK
   Final override:
   Hero copy full-width, then 6 products in 3x2 grid.
   No section-order changes.
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V6483_HERO_STACK__) return;
window.__BARAH_V6483_HERO_STACK__=true;

var STYLE='barah-v6483-hero-stack-style';

function addStyle(){
  if(document.getElementById(STYLE)) return;

  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
@media(max-width:767px){

  #barah-step-hero-v12{
    width:calc(100% - 20px)!important;
    max-width:none!important;
    margin-left:10px!important;
    margin-right:10px!important;
    overflow:hidden!important;
  }

  /* FORCE parent out of desktop two-column layout */
  #barah-step-hero-v12 .barah-hero-shell{
    display:flex!important;
    flex-direction:column!important;
    grid-template-columns:none!important;
    grid-template-rows:none!important;
    width:100%!important;
    max-width:100%!important;
    min-width:0!important;
    gap:11px!important;
    padding:13px!important;
    overflow:hidden!important;
  }

  #barah-step-hero-v12 .barah-hero-copy{
    order:1!important;
    width:100%!important;
    max-width:100%!important;
    min-width:0!important;
    flex:0 0 auto!important;
    min-height:0!important;
  }

  #barah-step-hero-v12 .barah-hero-products{
    order:2!important;
    display:grid!important;
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
    grid-auto-flow:row!important;
    width:100%!important;
    max-width:100%!important;
    min-width:0!important;
    flex:0 0 auto!important;
    gap:7px!important;
    padding:0!important;
    margin:0!important;
    overflow:visible!important;
    transform:none!important;
  }

  #barah-step-hero-v12 .barah-hero-product,
  #barah-step-hero-v12 .barah-v621-extra{
    display:flex!important;
    flex-direction:column!important;
    width:100%!important;
    max-width:none!important;
    min-width:0!important;
    height:auto!important;
    flex:none!important;
    margin:0!important;
    overflow:hidden!important;
    border-radius:12px!important;
  }

  #barah-step-hero-v12 .barah-hero-product img{
    display:block!important;
    width:100%!important;
    height:92px!important;
    max-height:92px!important;
    object-fit:contain!important;
    padding:5px!important;
    margin:0 auto!important;
    transform:none!important;
    filter:none!important;
  }

  #barah-step-hero-v12 .barah-hero-product strong{
    min-height:28px!important;
    max-height:28px!important;
    margin:0!important;
    padding:0 5px 4px!important;
    font-size:8.4px!important;
    line-height:1.35!important;
    display:-webkit-box!important;
    -webkit-line-clamp:2!important;
    -webkit-box-orient:vertical!important;
    overflow:hidden!important;
  }

  #barah-step-hero-v12 .barah-hero-product small{
    display:block!important;
    padding:0 5px 7px!important;
    font-size:8.8px!important;
    font-weight:950!important;
  }

  #barah-step-hero-v12 .barah-hero-pill{
    top:5px!important;
    right:5px!important;
    max-width:calc(100% - 10px)!important;
    padding:3px 5px!important;
    font-size:6.8px!important;
    line-height:1!important;
  }

  /* Hero text stays compact so products remain in first scroll area */
  #barah-step-hero-v12 h1{
    font-size:23px!important;
    line-height:1.3!important;
  }

  #barah-step-hero-v12 .barah-hero-copy p{
    margin:7px 0 10px!important;
    font-size:10.8px!important;
    line-height:1.65!important;
  }

  #barah-step-hero-v12 .barah-hero-actions{
    display:grid!important;
    grid-template-columns:1fr 1fr!important;
    gap:7px!important;
  }

  #barah-step-hero-v12 .barah-hero-actions .barah-home-direct{
    grid-column:1/-1!important;
  }

  #barah-step-hero-v12 .barah-hero-actions a{
    min-height:38px!important;
    padding:0 8px!important;
    font-size:9.5px!important;
  }

  #barah-step-hero-v12 .barah-hero-trust{
    margin-top:8px!important;
    gap:5px!important;
  }

  #barah-step-hero-v12 .barah-hero-trust span{
    min-height:26px!important;
    padding:4px 6px!important;
    font-size:8px!important;
  }
}

@media(max-width:390px){
  #barah-step-hero-v12 .barah-hero-products{
    gap:6px!important;
  }

  #barah-step-hero-v12 .barah-hero-product img{
    height:84px!important;
    max-height:84px!important;
  }

  #barah-step-hero-v12 .barah-hero-product strong{
    font-size:8px!important;
  }
}
`;
  (document.head||document.documentElement).appendChild(s);
}

function run(){
  addStyle();
  document.documentElement.setAttribute('data-barah-v6483','ready');
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}
setTimeout(run,250);
})();


/* ============================================================
   BARAH V64.8.4 — MOBILE PREGNANCY CLEANUP
   Mobile-first cleanup based on final screenshot:
   - keep 6 mini cards 3x2
   - remove duplicated large pregnancy cards on mobile
   - compact story/actions/chips
   - preserve desktop behavior
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V6484_PREG_CLEAN__) return;
window.__BARAH_V6484_PREG_CLEAN__=true;

var STYLE='barah-v6484-preg-clean-style';

function addStyle(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
@media(max-width:767px){

  #barah-step-pregnancy-v55{
    width:calc(100% - 20px)!important;
    margin:0 10px 12px!important;
  }

  #barah-step-pregnancy-v55 .preg-shell{
    padding:11px!important;
    border-radius:17px!important;
    overflow:hidden!important;
  }

  /* Hide old original large product rail on mobile */
  #barah-step-pregnancy-v55 .preg-grid{
    display:none!important;
  }

  /* Hide any duplicate legacy big-card wrappers that follow mini gallery */
  #barah-step-pregnancy-v55 .v626-mini-gallery ~ .preg-grid,
  #barah-step-pregnancy-v55 .v626-mini-gallery ~ .preg-card,
  #barah-step-pregnancy-v55 .v626-mini-gallery ~ [class*="preg-card"]{
    display:none!important;
  }

  /* Header/story tighter */
  #barah-step-pregnancy-v55 .preg-head{
    margin-bottom:8px!important;
  }

  #barah-step-pregnancy-v55 .preg-head h2,
  #barah-step-pregnancy-v55 .barah-v61-story h3{
    font-size:18px!important;
    line-height:1.32!important;
  }

  #barah-step-pregnancy-v55 .preg-sub,
  #barah-step-pregnancy-v55 .barah-v61-story p{
    font-size:9.4px!important;
    line-height:1.55!important;
    -webkit-line-clamp:2!important;
  }

  #barah-step-pregnancy-v55 .barah-v61-story{
    padding:10px!important;
    margin-bottom:8px!important;
    border-radius:14px!important;
  }

  #barah-step-pregnancy-v55 .barah-v61-story-actions{
    display:grid!important;
    grid-template-columns:1fr 1fr!important;
    gap:7px!important;
  }

  #barah-step-pregnancy-v55 .barah-v61-story-actions a{
    min-height:38px!important;
    font-size:9.5px!important;
    border-radius:10px!important;
  }

  #barah-step-pregnancy-v55 .barah-v61-story-points{
    display:none!important;
  }

  /* Mini 6 grid remains the visual focus */
  #barah-step-pregnancy-v55 .v626-mini-gallery{
    display:grid!important;
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
    gap:7px!important;
    margin:8px 0 7px!important;
  }

  #barah-step-pregnancy-v55 .v626-mini{
    border-radius:12px!important;
  }

  #barah-step-pregnancy-v55 .v626-media{
    aspect-ratio:1/1!important;
    padding:5px!important;
  }

  #barah-step-pregnancy-v55 .v626-copy{
    padding:6px!important;
  }

  #barah-step-pregnancy-v55 .v626-copy strong{
    min-height:24px!important;
    font-size:8.5px!important;
    line-height:1.4!important;
  }

  #barah-step-pregnancy-v55 .v626-copy small{
    margin-top:3px!important;
    font-size:8.5px!important;
  }

  /* Chips become a slim horizontal rail */
  #barah-step-pregnancy-v55 .barah-v61-chip-row{
    display:flex!important;
    flex-wrap:nowrap!important;
    gap:6px!important;
    overflow-x:auto!important;
    scrollbar-width:none!important;
    margin:5px 0 0!important;
    padding:0 0 2px!important;
  }

  #barah-step-pregnancy-v55 .barah-v61-chip-row::-webkit-scrollbar{
    display:none!important;
  }

  #barah-step-pregnancy-v55 .barah-v61-chip-row a{
    flex:0 0 auto!important;
    min-height:32px!important;
    padding:0 9px!important;
    font-size:8.5px!important;
  }

  /* note minimized */
  #barah-step-pregnancy-v55 .preg-note{
    margin-top:6px!important;
    padding-top:6px!important;
    font-size:7.8px!important;
    line-height:1.4!important;
  }

  /* Ensure no floating/bottom nav overlap */
  #barah-step-pregnancy-v55{
    scroll-margin-bottom:90px!important;
  }
}

@media(max-width:390px){
  #barah-step-pregnancy-v55 .v626-mini-gallery{
    gap:6px!important;
  }

  #barah-step-pregnancy-v55 .v626-copy strong{
    font-size:8.1px!important;
  }
}
`;
  (document.head||document.documentElement).appendChild(s);
}

function cleanup(){
  addStyle();
  var root=document.getElementById('barah-step-pregnancy-v55');
  if(!root) return false;

  /* On mobile, if a late legacy layer recreates the big rail, hide it again */
  if(window.matchMedia && window.matchMedia('(max-width: 767px)').matches){
    root.querySelectorAll('.preg-grid').forEach(function(el){
      el.style.setProperty('display','none','important');
    });
  }

  document.documentElement.setAttribute('data-barah-v6484','ready');
  return true;
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',cleanup,{once:true});
}else{
  cleanup();
}
setTimeout(cleanup,350);
setTimeout(cleanup,1200);
})();


/* ============================================================
   BARAH V64.8.5 — SENIOR OFFICIAL PRE-FOOTER
   Mobile only:
   catalog -> wholesale -> senior care -> footer
   Desktop unchanged.
   ============================================================ */
(function(){
'use strict';
if(window.__BARAH_V6485_SENIOR_PREFOOTER__) return;
window.__BARAH_V6485_SENIOR_PREFOOTER__=true;

var STYLE='barah-v6485-senior-prefooter-style';

function style(){
  if(document.getElementById(STYLE)) return;
  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`
@media(max-width:767px){
  #barah-step-senior-v57{
    margin-top:12px!important;
    margin-bottom:12px!important;
  }

  #barah-step-senior-v57 .v614-shell{
    border-radius:17px!important;
    box-shadow:0 10px 24px rgba(35,24,18,.045)!important;
  }

  #barah-step-senior-v57 + footer{
    margin-top:0!important;
  }
}
`;
  (document.head||document.documentElement).appendChild(s);
}

function verify(){
  style();

  if(!(window.matchMedia && window.matchMedia('(max-width: 767px)').matches)){
    document.documentElement.setAttribute('data-barah-v6485-senior','desktop-unchanged');
    return true;
  }

  var senior=document.getElementById('barah-step-senior-v57');
  var footer=document.querySelector('footer');

  if(senior && footer && footer.parentNode){
    if(footer.previousElementSibling!==senior){
      footer.insertAdjacentElement('beforebegin',senior);
    }
    document.documentElement.setAttribute(
      'data-barah-v6485-senior',
      footer.previousElementSibling===senior ? 'pre-footer-ready' : 'partial'
    );
    return true;
  }

  return false;
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',verify,{once:true});
}else{
  verify();
}

/* short bounded verification only; no observer */
setTimeout(verify,500);
setTimeout(verify,1400);
})();


/* ============================================================
BARAH V64.8 — FOOTER PAYMENT CLEAN GRID V3.1
Mobile footer payment logos:
- centered compact grid
- equal visual boxes
- hides broken / duplicate wallet images
- keeps VAT line separate above
============================================================ */
(function(){
'use strict';

if(window.__BARAH_FOOTER_PAYMENT_GRID_V31__) return;
window.__BARAH_FOOTER_PAYMENT_GRID_V31__=true;

var STYLE='barah-footer-payment-grid-v31-style';

function isMobile(){
  return !!(window.matchMedia && window.matchMedia('(max-width:767px)').matches);
}

function paymentLike(img){
  if(!img) return false;
  var s=[
    img.getAttribute('alt')||'',
    img.getAttribute('title')||'',
    img.getAttribute('src')||'',
    img.getAttribute('data-src')||''
  ].join(' ').toLowerCase();

  return /mada|visa|master|tabby|tamara|apple.?pay|stc|bank|wallet|payment|pay\b|مدى|تابي|تمارا|محفظة/.test(s);
}

function addStyle(){
  if(document.getElementById(STYLE)) return;

  var s=document.createElement('style');
  s.id=STYLE;
  s.textContent=`

@media(max-width:767px){

  footer .barah-payments-v31{
    display:grid!important;
    grid-template-columns:repeat(4,minmax(0,1fr))!important;
    gap:7px!important;
    width:min(270px,100%)!important;
    margin:8px auto 10px!important;
    padding:0!important;
    align-items:center!important;
    justify-items:center!important;
  }

  footer .barah-payment-item-v31{
    width:100%!important;
    min-width:0!important;
    height:34px!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    margin:0!important;
    padding:4px 5px!important;
    border:1px solid rgba(17,24,39,.06)!important;
    border-radius:7px!important;
    background:#fff!important;
    box-shadow:none!important;
    overflow:hidden!important;
    box-sizing:border-box!important;
  }

  footer .barah-payment-item-v31 img{
    display:block!important;
    width:auto!important;
    max-width:52px!important;
    height:auto!important;
    max-height:21px!important;
    object-fit:contain!important;
    margin:0!important;
    padding:0!important;
    opacity:1!important;
    filter:none!important;
  }

  footer .barah-payment-broken-v31{
    display:none!important;
  }

  footer .barah-vat-line-v31{
    width:100%!important;
    text-align:center!important;
    margin:0 auto 7px!important;
    font-size:10.5px!important;
    line-height:1.5!important;
  }

}

`;
  (document.head||document.documentElement).appendChild(s);
}

function findVatLine(footer){
  var nodes=Array.prototype.slice.call(
    footer.querySelectorAll('div,p,span')
  );

  var el=nodes.find(function(x){
    var t=String(x.textContent||'').replace(/\s+/g,' ').trim();
    return t.indexOf('الرقم الضريبي')!==-1;
  });

  if(el) el.classList.add('barah-vat-line-v31');
}

function cleanBroken(img){
  if(!img) return;

  var alt=(img.getAttribute('alt')||'').toLowerCase();
  var src=(img.getAttribute('src')||'').toLowerCase();

  var broken =
    img.complete &&
    img.naturalWidth===0;

  var walletGarble =
    /wallet|customer_wallet|mahally_customer_wallet/.test(alt+' '+src);

  if(broken || walletGarble){
    var w=img.closest('li,a,span,div') || img;
    w.classList.add('barah-payment-broken-v31');
  }
}

function organize(){
  var footer=document.querySelector('footer');
  if(!footer) return false;

  addStyle();
  findVatLine(footer);

  var imgs=Array.prototype.slice.call(
    footer.querySelectorAll('img')
  ).filter(paymentLike);

  if(!imgs.length) return false;

  imgs.forEach(cleanBroken);

  var usable=imgs.filter(function(img){
    var w=img.closest('.barah-payment-broken-v31');
    return !w;
  });

  if(!usable.length) return false;

  /* Find a shared wrapper without climbing all the way to footer */
  var wrapper=null;

  usable.some(function(img){
    var p=img.parentElement;
    for(var i=0;i<4 && p && p!==footer;i++,p=p.parentElement){
      var count=Array.prototype.slice.call(
        p.querySelectorAll('img')
      ).filter(paymentLike).length;

      if(count>=3){
        wrapper=p;
        return true;
      }
    }
    return false;
  });

  if(!wrapper) return false;

  wrapper.classList.add('barah-payments-v31');

  usable.forEach(function(img){
    var item=img.parentElement;

    while(
      item &&
      item.parentElement!==wrapper &&
      item.parentElement &&
      item.parentElement!==footer
    ){
      item=item.parentElement;
    }

    if(item && item!==wrapper){
      item.classList.add('barah-payment-item-v31');
    }else{
      img.classList.add('barah-payment-item-v31');
    }
  });

  return true;
}

function run(){
  if(!isMobile()) return;
  organize();
}

function boot(){
  run();
  [250,700,1400,2600].forEach(function(ms){
    setTimeout(run,ms);
  });
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',boot,{once:true});
}else{
  boot();
}

window.addEventListener('load',run,{once:true});

})();


/* ============================================================
BARAH V64.8 — PRODUCT DESCRIPTION FULL OPEN V3.2
ONLY CHANGE:
- Product description opens fully on entry.
- "اقرأ المزيد" / read-more control is hidden.
- No other page styling or behavior is changed.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_PRODUCT_DESC_FULL_V32__) return;
window.__BARAH_PRODUCT_DESC_FULL_V32__=true;

function isProductPage(){
  var p=String(location.pathname||'');
  return (
    /\/p\d+(?:\/|$)/i.test(p) ||
    document.body.classList.contains('product-single') ||
    document.body.classList.contains('product-page') ||
    document.querySelector('.page--product-details,.product-details,.product-single')!==null
  );
}

function cleanText(v){
  return String(v||'').replace(/\s+/g,' ').trim();
}

function isReadMoreControl(el){
  if(!el) return false;

  var t=cleanText(el.textContent).toLowerCase();

  return (
    t==='اقرأ المزيد' ||
    t==='قراءة المزيد' ||
    t==='عرض المزيد' ||
    t==='read more' ||
    t==='show more'
  );
}

function openDescription(){
  if(!isProductPage()) return;

  var selectors=[
    'article.pd-exp',
    '.article--product-details.pd-exp',
    '.pd-exp',
    '.product-description',
    '.product-details-description',
    '[class*="product-description"]',
    '[class*="description-content"]'
  ];

  document.querySelectorAll(selectors.join(',')).forEach(function(el){
    el.style.setProperty('height','auto','important');
    el.style.setProperty('max-height','none','important');
    el.style.setProperty('overflow','visible','important');
    el.style.setProperty('opacity','1','important');
    el.style.setProperty('visibility','visible','important');

    el.classList.remove(
      'pd-shrink',
      'collapsed',
      'is-collapsed',
      'overflow-hidden',
      'line-clamp',
      'line-clamp-2',
      'line-clamp-3',
      'line-clamp-4'
    );
  });

  document.querySelectorAll(
    '.pd-expand-wrapper,'+
    '.expand-toggle,'+
    '[class*="read-more"],'+
    '[class*="readmore"],'+
    'button,'+
    'a'
  ).forEach(function(el){
    if(
      el.matches(
        '.pd-expand-wrapper,'+
        '.expand-toggle,'+
        '[class*="read-more"],'+
        '[class*="readmore"]'
      ) || isReadMoreControl(el)
    ){
      el.style.setProperty('display','none','important');
      el.setAttribute('aria-hidden','true');
    }
  });
}

function boot(){
  openDescription();

  [100,300,700,1500,3000].forEach(function(ms){
    setTimeout(openDescription,ms);
  });
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',boot,{once:true});
}else{
  boot();
}

window.addEventListener('load',openDescription,{once:true});

})();


/* BARAH V65.8: removed legacy best-sellers interception and hash scrolling. */

/* ============================================================
BARAH V64.8 — MOBILE TYPOGRAPHY & SPACING BALANCE V3.4
ONLY MOBILE:
- balanced headings, body text, cards, prices, buttons, footer
- tighter spacing for small screens
- no desktop changes
- no routing / button behavior changes
============================================================ */
(function(){
'use strict';

if(window.__BARAH_MOBILE_TYPE_SCALE_V34__) return;
window.__BARAH_MOBILE_TYPE_SCALE_V34__=true;

var ID='barah-mobile-type-scale-v34';
if(document.getElementById(ID)) return;

var s=document.createElement('style');
s.id=ID;
s.textContent=`

@media (max-width:767px){

  html{
    -webkit-text-size-adjust:100%!important;
    text-size-adjust:100%!important;
  }

  body{
    font-size:14px!important;
    line-height:1.65!important;
  }

  main h1,
  main .text-3xl,
  main .text-4xl,
  main [class*="hero"] h1{
    font-size:clamp(22px,6vw,28px)!important;
    line-height:1.28!important;
    letter-spacing:-.2px!important;
    margin-bottom:8px!important;
  }

  main h2,
  main [class*="section"] h2,
  main [class*="title"] h2,
  main [class*="heading"] h2{
    font-size:clamp(18px,5.2vw,22px)!important;
    line-height:1.35!important;
    letter-spacing:-.15px!important;
  }

  main h3,
  main [class*="card"] h3,
  main [class*="product"] h3{
    font-size:15px!important;
    line-height:1.45!important;
  }

  main h4{
    font-size:14px!important;
    line-height:1.45!important;
  }

  main p,
  main li,
  main .description,
  main [class*="desc"],
  main [class*="subtitle"],
  main [class*="sub-title"],
  main [class*="helper"],
  main [class*="caption"]{
    font-size:13.5px!important;
    line-height:1.7!important;
  }

  .product-entry,
  .product-card,
  [class*="product-card"],
  salla-product-card{
    font-size:13px!important;
  }

  .product-entry h3,
  .product-card h3,
  [class*="product-card"] h3,
  salla-product-card h3{
    font-size:13.5px!important;
    line-height:1.45!important;
    min-height:auto!important;
  }

  .product-entry [class*="price"],
  .product-card [class*="price"],
  [class*="product-card"] [class*="price"],
  salla-product-card [class*="price"]{
    font-size:14px!important;
    line-height:1.35!important;
  }

  main a[class*="btn"],
  main button,
  main .btn,
  main [role="button"],
  main salla-add-product-button button,
  main salla-button button{
    font-size:13px!important;
    line-height:1.2!important;
    min-height:40px!important;
    padding-top:9px!important;
    padding-bottom:9px!important;
  }

  main a[class*="btn"] span,
  main button span,
  main .btn span{
    font-size:inherit!important;
    line-height:inherit!important;
  }

  #barah-step-hero-v12 h1,
  #barah-step-hero-v12 h2{
    font-size:clamp(21px,5.8vw,26px)!important;
    line-height:1.25!important;
  }

  #barah-step-hero-v12 p{
    font-size:13px!important;
    line-height:1.65!important;
  }

  #barah-step-shipping-v24,
  #barah-v617-decision-strip{
    font-size:12px!important;
    line-height:1.45!important;
  }

  #barah-step-needs-v51 h2,
  #barah-step-pregnancy-v55 h2,
  #barah-step-senior-v57 h2,
  #barah-step-most-viewed h2,
  #barah-v643-mobile-latest h2,
  #barah-v647-mobile-most-viewed h2,
  #barah-step-catalog-v32 h2,
  #barah-step-wholesale-v32 h2{
    font-size:19px!important;
    line-height:1.35!important;
    margin-bottom:5px!important;
  }

  #barah-step-needs-v51 p,
  #barah-step-pregnancy-v55 p,
  #barah-step-senior-v57 p,
  #barah-step-most-viewed p,
  #barah-v643-mobile-latest p,
  #barah-v647-mobile-most-viewed p,
  #barah-step-catalog-v32 p,
  #barah-step-wholesale-v32 p{
    font-size:12.5px!important;
    line-height:1.6!important;
  }

  .page--product-details h1,
  .product-single h1,
  .product-details h1{
    font-size:21px!important;
    line-height:1.4!important;
  }

  .page--product-details h2,
  .product-single h2,
  .product-details h2{
    font-size:18px!important;
    line-height:1.45!important;
  }

  .page--product-details h3,
  .product-single h3,
  .product-details h3{
    font-size:16px!important;
    line-height:1.5!important;
  }

  .page--product-details p,
  .page--product-details li,
  .product-single p,
  .product-single li,
  .product-details p,
  .product-details li,
  .pd-exp,
  .pd-exp p,
  .pd-exp li{
    font-size:13.5px!important;
    line-height:1.8!important;
  }

  .page--product-details [class*="price"],
  .product-single [class*="price"],
  .product-details [class*="price"]{
    font-size:18px!important;
    line-height:1.25!important;
  }

  main label,
  main select,
  main input,
  main textarea,
  main .form-label,
  main [class*="option"]{
    font-size:13px!important;
  }

  .breadcrumb,
  salla-breadcrumb,
  [class*="breadcrumb"]{
    font-size:11.5px!important;
    line-height:1.45!important;
  }

  footer{
    font-size:12px!important;
    line-height:1.65!important;
  }

  footer h3,
  footer h4,
  footer [class*="title"]{
    font-size:13.5px!important;
    line-height:1.45!important;
  }

  footer a,
  footer p,
  footer li,
  footer span{
    font-size:11.5px!important;
    line-height:1.6!important;
  }

  header,
  header a,
  header button,
  .mobile-menu,
  .mobile-menu a{
    font-size:13px!important;
  }

  main section > .container,
  main section > [class*="container"]{
    padding-left:12px!important;
    padding-right:12px!important;
  }

  main h1,
  main h2,
  main h3,
  main p{
    word-break:normal!important;
    overflow-wrap:break-word!important;
  }

  .badge,
  [class*="badge"],
  [class*="tag"],
  [class*="label"]{
    font-size:10.5px!important;
    line-height:1.25!important;
  }
}

@media (max-width:390px){

  body{
    font-size:13.5px!important;
  }

  main h1,
  main [class*="hero"] h1{
    font-size:21px!important;
  }

  main h2,
  main [class*="section"] h2{
    font-size:18px!important;
  }

  main h3,
  .product-card h3,
  [class*="product-card"] h3{
    font-size:13px!important;
  }

  main p,
  main li,
  .pd-exp,
  .pd-exp p,
  .pd-exp li{
    font-size:13px!important;
  }

  main a[class*="btn"],
  main button,
  main .btn,
  main [role="button"]{
    font-size:12.5px!important;
    min-height:38px!important;
    padding-top:8px!important;
    padding-bottom:8px!important;
  }

  footer a,
  footer p,
  footer li,
  footer span{
    font-size:11px!important;
  }
}

@media (max-width:350px){

  main h1{
    font-size:20px!important;
  }

  main h2{
    font-size:17px!important;
  }

  main p,
  main li{
    font-size:12.5px!important;
  }

  main a[class*="btn"],
  main button,
  main .btn{
    font-size:12px!important;
  }

  .product-card h3,
  [class*="product-card"] h3{
    font-size:12.5px!important;
  }
}

`;

(document.head||document.documentElement).appendChild(s);

})();


/* ============================================================
BARAH V64.8 — MOBILE TYPOGRAPHY BENCHMARK SCALE V3.5
Benchmark-style mobile sizing inspired by major ecommerce UX:
- Body: 16px
- Product copy: 15.5–16px
- Buttons: 15px
- Section headings: 22–24px
- Product title: 24px
ONLY MOBILE. No desktop/routing/layout behavior changes.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_MOBILE_TYPE_SCALE_V35__) return;
window.__BARAH_MOBILE_TYPE_SCALE_V35__=true;

var ID='barah-mobile-type-scale-v35';
if(document.getElementById(ID)) return;

var s=document.createElement('style');
s.id=ID;
s.textContent=`

@media (max-width:767px){

  html{
    -webkit-text-size-adjust:100%!important;
    text-size-adjust:100%!important;
  }

  body{
    font-size:16px!important;
    line-height:1.65!important;
  }

  /* HERO */
  main h1,
  main [class*="hero"] h1,
  #barah-step-hero-v12 h1{
    font-size:26px!important;
    line-height:1.3!important;
    letter-spacing:-.25px!important;
  }

  #barah-step-hero-v12 h2{
    font-size:24px!important;
    line-height:1.35!important;
  }

  #barah-step-hero-v12 p{
    font-size:16px!important;
    line-height:1.65!important;
  }

  /* SECTION TITLES */
  main h2,
  main [class*="section"] h2,
  main [class*="title"] h2,
  main [class*="heading"] h2,
  #barah-step-needs-v51 h2,
  #barah-step-pregnancy-v55 h2,
  #barah-step-senior-v57 h2,
  #barah-step-most-viewed h2,
  #barah-v643-mobile-latest h2,
  #barah-v647-mobile-most-viewed h2,
  #barah-step-catalog-v32 h2,
  #barah-step-wholesale-v32 h2{
    font-size:23px!important;
    line-height:1.38!important;
    letter-spacing:-.15px!important;
  }

  main h3{
    font-size:18px!important;
    line-height:1.5!important;
  }

  main h4{
    font-size:16px!important;
    line-height:1.5!important;
  }

  /* GENERAL COPY */
  main p,
  main li,
  main .description,
  main [class*="desc"],
  main [class*="subtitle"],
  main [class*="sub-title"],
  main [class*="helper"]{
    font-size:16px!important;
    line-height:1.75!important;
  }

  main [class*="caption"]{
    font-size:14px!important;
    line-height:1.55!important;
  }

  /* PRODUCT CARDS */
  .product-entry,
  .product-card,
  [class*="product-card"],
  salla-product-card{
    font-size:15px!important;
  }

  .product-entry h3,
  .product-card h3,
  [class*="product-card"] h3,
  salla-product-card h3{
    font-size:15.5px!important;
    line-height:1.5!important;
    min-height:auto!important;
  }

  .product-entry [class*="price"],
  .product-card [class*="price"],
  [class*="product-card"] [class*="price"],
  salla-product-card [class*="price"]{
    font-size:16px!important;
    line-height:1.35!important;
    font-weight:700!important;
  }

  /* CTA / BUTTONS */
  main a[class*="btn"],
  main button,
  main .btn,
  main [role="button"],
  main salla-add-product-button button,
  main salla-button button{
    font-size:15px!important;
    line-height:1.25!important;
    min-height:44px!important;
    padding-top:11px!important;
    padding-bottom:11px!important;
  }

  main a[class*="btn"] span,
  main button span,
  main .btn span{
    font-size:inherit!important;
    line-height:inherit!important;
  }

  /* STRIPS */
  #barah-step-shipping-v24,
  #barah-v617-decision-strip{
    font-size:13.5px!important;
    line-height:1.5!important;
  }

  /* HOMEPAGE SUPPORTING TEXT */
  #barah-step-needs-v51 p,
  #barah-step-pregnancy-v55 p,
  #barah-step-senior-v57 p,
  #barah-step-most-viewed p,
  #barah-v643-mobile-latest p,
  #barah-v647-mobile-most-viewed p,
  #barah-step-catalog-v32 p,
  #barah-step-wholesale-v32 p{
    font-size:15px!important;
    line-height:1.65!important;
  }

  /* PRODUCT PAGE */
  .page--product-details h1,
  .product-single h1,
  .product-details h1{
    font-size:24px!important;
    line-height:1.42!important;
  }

  .page--product-details h2,
  .product-single h2,
  .product-details h2{
    font-size:21px!important;
    line-height:1.45!important;
  }

  .page--product-details h3,
  .product-single h3,
  .product-details h3{
    font-size:18px!important;
    line-height:1.5!important;
  }

  .page--product-details p,
  .page--product-details li,
  .product-single p,
  .product-single li,
  .product-details p,
  .product-details li,
  .pd-exp,
  .pd-exp p,
  .pd-exp li{
    font-size:16px!important;
    line-height:1.85!important;
  }

  .page--product-details [class*="price"],
  .product-single [class*="price"],
  .product-details [class*="price"]{
    font-size:21px!important;
    line-height:1.3!important;
    font-weight:700!important;
  }

  /* OPTIONS / FORM */
  main label,
  main select,
  main input,
  main textarea,
  main .form-label,
  main [class*="option"]{
    font-size:15px!important;
  }

  /* BREADCRUMB */
  .breadcrumb,
  salla-breadcrumb,
  [class*="breadcrumb"]{
    font-size:13px!important;
    line-height:1.5!important;
  }

  /* HEADER */
  header,
  header a,
  header button,
  .mobile-menu,
  .mobile-menu a{
    font-size:14px!important;
  }

  /* FOOTER */
  footer{
    font-size:13.5px!important;
    line-height:1.7!important;
  }

  footer h3,
  footer h4,
  footer [class*="title"]{
    font-size:15px!important;
    line-height:1.5!important;
  }

  footer a,
  footer p,
  footer li,
  footer span{
    font-size:13px!important;
    line-height:1.65!important;
  }

  /* BADGES */
  .badge,
  [class*="badge"],
  [class*="tag"],
  [class*="label"]{
    font-size:12px!important;
    line-height:1.3!important;
  }

  /* SPACING */
  main section > .container,
  main section > [class*="container"]{
    padding-left:14px!important;
    padding-right:14px!important;
  }

  main h1,
  main h2,
  main h3,
  main p{
    word-break:normal!important;
    overflow-wrap:break-word!important;
  }
}

/* NORMAL SMALL PHONES */
@media (max-width:390px){

  body{
    font-size:15.5px!important;
  }

  main h1,
  main [class*="hero"] h1,
  #barah-step-hero-v12 h1{
    font-size:24px!important;
  }

  main h2,
  main [class*="section"] h2{
    font-size:21px!important;
  }

  main p,
  main li,
  .pd-exp,
  .pd-exp p,
  .pd-exp li{
    font-size:15.5px!important;
  }

  .product-entry h3,
  .product-card h3,
  [class*="product-card"] h3,
  salla-product-card h3{
    font-size:15px!important;
  }

  main a[class*="btn"],
  main button,
  main .btn,
  main [role="button"]{
    font-size:14.5px!important;
    min-height:44px!important;
  }

  footer a,
  footer p,
  footer li,
  footer span{
    font-size:12.5px!important;
  }
}

/* VERY NARROW PHONES */
@media (max-width:350px){

  main h1{
    font-size:23px!important;
  }

  main h2{
    font-size:20px!important;
  }

  main p,
  main li{
    font-size:15px!important;
  }

  .product-card h3,
  [class*="product-card"] h3{
    font-size:14.5px!important;
  }

  main a[class*="btn"],
  main button,
  main .btn{
    font-size:14px!important;
  }
}

`;

(document.head||document.documentElement).appendChild(s);

})();


/* ============================================================
BARAH V64.8 — SENIOR MOBILE IMAGE SCALE V3.6
ONLY CHANGE:
- Enlarge images in "راحة واهتمام لكبار السن" cards on mobile
- Approx +20% visual scale
- Keep text/buttons/layout behavior untouched
============================================================ */
(function(){
'use strict';

if(window.__BARAH_SENIOR_MOBILE_IMAGE_V36__) return;
window.__BARAH_SENIOR_MOBILE_IMAGE_V36__=true;

var ID='barah-senior-mobile-image-v36';
if(document.getElementById(ID)) return;

var s=document.createElement('style');
s.id=ID;
s.textContent=`

@media (max-width:767px){

  /* Main target section */
  #barah-step-senior-v57 img,
  [id*="senior"] img,
  [class*="senior"] img{
    width:80px!important;
    height:80px!important;
    max-width:80px!important;
    max-height:80px!important;
    object-fit:contain!important;
    flex:0 0 80px!important;
  }

  /* Slightly reduce dead space around image wrappers */
  #barah-step-senior-v57 [class*="image"],
  #barah-step-senior-v57 [class*="thumb"],
  [id*="senior"] [class*="image"],
  [id*="senior"] [class*="thumb"],
  [class*="senior"] [class*="image"],
  [class*="senior"] [class*="thumb"]{
    min-width:80px!important;
    width:80px!important;
    height:80px!important;
    padding:2px!important;
    margin:0!important;
  }

  /* Preserve compact card proportions */
  #barah-step-senior-v57 [class*="card"],
  [id*="senior"] [class*="card"],
  [class*="senior"] [class*="card"]{
    align-items:center!important;
  }
}

@media (max-width:390px){

  #barah-step-senior-v57 img,
  [id*="senior"] img,
  [class*="senior"] img{
    width:76px!important;
    height:76px!important;
    max-width:76px!important;
    max-height:76px!important;
    flex-basis:76px!important;
  }

  #barah-step-senior-v57 [class*="image"],
  #barah-step-senior-v57 [class*="thumb"],
  [id*="senior"] [class*="image"],
  [id*="senior"] [class*="thumb"],
  [class*="senior"] [class*="image"],
  [class*="senior"] [class*="thumb"]{
    min-width:76px!important;
    width:76px!important;
    height:76px!important;
  }
}

`;

(document.head||document.documentElement).appendChild(s);

})();


/* ============================================================
BARAH V64.8 — SENIOR REAL THUMB SIZE FIX V3.7
Exact target: actual .v624-thumb wrapper used by the section.
ONLY CHANGE: senior card image visual size on mobile.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_SENIOR_REAL_THUMB_V37__) return;
window.__BARAH_SENIOR_REAL_THUMB_V37__=true;

var ID='barah-senior-real-thumb-v37';
if(document.getElementById(ID)) return;

var s=document.createElement('style');
s.id=ID;
s.textContent=`

@media(max-width:767px){

  #barah-step-senior-v57 .v614-path{
    min-height:126px!important;
  }

  #barah-step-senior-v57 .v624-top{
    gap:7px!important;
    align-items:flex-start!important;
  }

  #barah-step-senior-v57 .v624-thumb{
    flex:0 0 58px!important;
    width:58px!important;
    min-width:58px!important;
    height:58px!important;
    max-width:58px!important;
    max-height:58px!important;
    border-radius:12px!important;
    padding:2px!important;
    box-sizing:border-box!important;
  }

  #barah-step-senior-v57 .v624-thumb img{
    display:block!important;
    width:100%!important;
    height:100%!important;
    max-width:none!important;
    max-height:none!important;
    padding:0!important;
    margin:0!important;
    object-fit:contain!important;
    transform:none!important;
  }
}

@media(max-width:390px){

  #barah-step-senior-v57 .v624-thumb{
    flex-basis:56px!important;
    width:56px!important;
    min-width:56px!important;
    height:56px!important;
    max-width:56px!important;
    max-height:56px!important;
  }
}

`;

(document.head||document.documentElement).appendChild(s);

})();


/* ============================================================
BARAH V64.8 — SENIOR IMAGE SCALE V3.8
ONLY CHANGE:
- Increase senior-card images further for mobile readability
- 74x74px standard mobile
- 70x70px <=390px
- Slight card-height adjustment only
============================================================ */
(function(){
'use strict';

if(window.__BARAH_SENIOR_IMAGE_V38__) return;
window.__BARAH_SENIOR_IMAGE_V38__=true;

var ID='barah-senior-image-v38';
if(document.getElementById(ID)) return;

var s=document.createElement('style');
s.id=ID;
s.textContent=`

@media(max-width:767px){

  #barah-step-senior-v57 .v614-path{
    min-height:140px!important;
  }

  #barah-step-senior-v57 .v624-top{
    gap:8px!important;
    align-items:flex-start!important;
  }

  #barah-step-senior-v57 .v624-thumb{
    flex:0 0 74px!important;
    width:74px!important;
    min-width:74px!important;
    height:74px!important;
    max-width:74px!important;
    max-height:74px!important;
    border-radius:12px!important;
    padding:2px!important;
    box-sizing:border-box!important;
  }

  #barah-step-senior-v57 .v624-thumb img{
    display:block!important;
    width:100%!important;
    height:100%!important;
    max-width:none!important;
    max-height:none!important;
    object-fit:contain!important;
    margin:0!important;
    padding:0!important;
    transform:none!important;
  }
}

@media(max-width:390px){

  #barah-step-senior-v57 .v614-path{
    min-height:136px!important;
  }

  #barah-step-senior-v57 .v624-thumb{
    flex:0 0 70px!important;
    width:70px!important;
    min-width:70px!important;
    height:70px!important;
    max-width:70px!important;
    max-height:70px!important;
  }
}

`;

(document.head||document.documentElement).appendChild(s);

})();


/* ============================================================
BARAH V64.8 — SENIOR MOBILE IMAGE VISUAL ZOOM V3.9
ONLY MOBILE:
- Keep desktop untouched
- Make the PRODUCT itself look larger, not only its white image box
- Crop internal white margins by zooming the image inside its thumb
============================================================ */
(function(){
'use strict';

if(window.__BARAH_SENIOR_MOBILE_VISUAL_ZOOM_V39__) return;
window.__BARAH_SENIOR_MOBILE_VISUAL_ZOOM_V39__=true;

var ID='barah-senior-mobile-visual-zoom-v39';
if(document.getElementById(ID)) return;

var s=document.createElement('style');
s.id=ID;
s.textContent=`

/* Actual mobile view only */
@media (max-width:767px){

  #barah-step-senior-v57 .v624-thumb{
    flex:0 0 76px!important;
    width:76px!important;
    min-width:76px!important;
    height:76px!important;
    max-width:76px!important;
    max-height:76px!important;
    padding:0!important;
    overflow:hidden!important;
    border-radius:12px!important;
    background:#fff!important;
  }

  #barah-step-senior-v57 .v624-thumb img{
    width:100%!important;
    height:100%!important;
    max-width:none!important;
    max-height:none!important;
    object-fit:contain!important;
    object-position:center!important;

    /* This is the important part:
       enlarge the product inside white-canvas product images */
    transform:scale(1.42)!important;
    transform-origin:center center!important;

    margin:0!important;
    padding:0!important;
    display:block!important;
  }

  #barah-step-senior-v57 .v624-top{
    gap:9px!important;
    align-items:flex-start!important;
  }

  #barah-step-senior-v57 .v614-path{
    min-height:142px!important;
  }
}

/* Narrow phones: still visibly large, but preserve text room */
@media (max-width:390px){

  #barah-step-senior-v57 .v624-thumb{
    flex-basis:72px!important;
    width:72px!important;
    min-width:72px!important;
    height:72px!important;
    max-width:72px!important;
    max-height:72px!important;
  }

  #barah-step-senior-v57 .v624-thumb img{
    transform:scale(1.38)!important;
  }

  #barah-step-senior-v57 .v614-path{
    min-height:138px!important;
  }
}

/* Desktop explicitly untouched */
@media (min-width:768px){
  #barah-step-senior-v57 .v624-thumb img{
    transform:none!important;
  }
}

`;

(document.head||document.documentElement).appendChild(s);

})();


/* ============================================================
BARAH V64.8 — SENIOR MOBILE BIGGER CARD IMAGES V4.0
ONLY MOBILE:
- Make images in "راحة واهتمام لكبار السن" visibly larger
- Focus on card thumbnails in that section only
- Desktop untouched
============================================================ */
(function(){
'use strict';

if(window.__BARAH_SENIOR_MOBILE_BIG_IMAGES_V40__) return;
window.__BARAH_SENIOR_MOBILE_BIG_IMAGES_V40__=true;

var ID='barah-senior-mobile-big-images-v40';
if(document.getElementById(ID)) return;

var s=document.createElement('style');
s.id=ID;
s.textContent=`

@media (max-width:767px){

  /* Increase top row visual balance and give thumbnails more space */
  #barah-step-senior-v57 .v614-path{
    min-height:150px!important;
    padding:10px!important;
  }

  #barah-step-senior-v57 .v624-top{
    gap:10px!important;
    align-items:flex-start!important;
  }

  /* Real thumbnail size on mobile */
  #barah-step-senior-v57 .v624-thumb{
    flex:0 0 88px!important;
    width:88px!important;
    min-width:88px!important;
    height:88px!important;
    max-width:88px!important;
    max-height:88px!important;
    padding:0!important;
    overflow:hidden!important;
    border-radius:12px!important;
    background:#fff!important;
  }

  /* Make product itself look bigger inside the white product image */
  #barah-step-senior-v57 .v624-thumb img{
    display:block!important;
    width:100%!important;
    height:100%!important;
    max-width:none!important;
    max-height:none!important;
    object-fit:contain!important;
    object-position:center center!important;
    transform:scale(1.58)!important;
    transform-origin:center center!important;
    margin:0!important;
    padding:0!important;
  }

  /* Keep content area from feeling cramped */
  #barah-step-senior-v57 .v624-copy{
    min-width:0!important;
  }
}

@media (max-width:390px){

  #barah-step-senior-v57 .v614-path{
    min-height:146px!important;
  }

  #barah-step-senior-v57 .v624-thumb{
    flex:0 0 82px!important;
    width:82px!important;
    min-width:82px!important;
    height:82px!important;
    max-width:82px!important;
    max-height:82px!important;
  }

  #barah-step-senior-v57 .v624-thumb img{
    transform:scale(1.52)!important;
  }
}

/* Explicit desktop protection */
@media (min-width:768px){
  #barah-step-senior-v57 .v624-thumb{
    width:auto!important;
    height:auto!important;
    min-width:0!important;
    min-height:0!important;
    max-width:none!important;
    max-height:none!important;
  }
  #barah-step-senior-v57 .v624-thumb img{
    transform:none!important;
  }
}

`;

(document.head||document.documentElement).appendChild(s);

})();


/* ============================================================
BARAH V64.8 — SENIOR MOBILE CARD SIZE MATCH V4.1
هدف التعديل:
- جعل صور بطاقات قسم "راحة واهتمام لكبار السن" على الجوال
  أقرب بصريًا إلى حجم بطاقات القسم الأخضر المرجعي.
- التعديل لهذا القسم فقط وعلى الجوال فقط.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_SENIOR_MOBILE_CARD_MATCH_V41__) return;
window.__BARAH_SENIOR_MOBILE_CARD_MATCH_V41__=true;

var ID='barah-senior-mobile-card-match-v41';
if(document.getElementById(ID)) return;

var s=document.createElement('style');
s.id=ID;
s.textContent=`

@media (max-width:767px){

  /* بطاقات القسم: نعطيها نفس الإحساس البصري تقريبًا */
  #barah-step-senior-v57 .v614-path{
    min-height:176px!important;
    padding:12px!important;
    border-radius:16px!important;
  }

  /* أعلى البطاقة: نكبر حيز الصورة ونوازن المسافات */
  #barah-step-senior-v57 .v624-top{
    display:flex!important;
    align-items:flex-start!important;
    gap:10px!important;
  }

  /* حاوية الصورة بحجم أقرب للبطاقات المرجعية */
  #barah-step-senior-v57 .v624-thumb{
    flex:0 0 96px!important;
    width:96px!important;
    min-width:96px!important;
    height:96px!important;
    max-width:96px!important;
    max-height:96px!important;
    padding:0!important;
    overflow:hidden!important;
    border-radius:14px!important;
    background:#fff!important;
  }

  /* تكبير الصورة نفسها داخل الحاوية */
  #barah-step-senior-v57 .v624-thumb img{
    display:block!important;
    width:100%!important;
    height:100%!important;
    max-width:none!important;
    max-height:none!important;
    object-fit:contain!important;
    object-position:center center!important;
    transform:scale(1.62)!important;
    transform-origin:center center!important;
    margin:0!important;
    padding:0!important;
  }

  /* نص البطاقة حتى يبقى متوازنًا مع الصورة */
  #barah-step-senior-v57 .v624-copy{
    min-width:0!important;
    flex:1 1 auto!important;
  }

  #barah-step-senior-v57 .v624-title{
    font-size:14px!important;
    line-height:1.45!important;
    margin-bottom:3px!important;
  }

  #barah-step-senior-v57 .v624-copy p,
  #barah-step-senior-v57 .v624-copy .v624-desc{
    font-size:12.5px!important;
    line-height:1.55!important;
  }

  /* زر/رابط الاختيارات يبقى في أسفل البطاقة بشكل أنظف */
  #barah-step-senior-v57 .v624-link,
  #barah-step-senior-v57 a[href*="search"]{
    margin-top:8px!important;
    display:inline-block!important;
  }
}

@media (max-width:390px){

  #barah-step-senior-v57 .v614-path{
    min-height:168px!important;
    padding:11px!important;
  }

  #barah-step-senior-v57 .v624-thumb{
    flex:0 0 90px!important;
    width:90px!important;
    min-width:90px!important;
    height:90px!important;
    max-width:90px!important;
    max-height:90px!important;
  }

  #barah-step-senior-v57 .v624-thumb img{
    transform:scale(1.56)!important;
  }

  #barah-step-senior-v57 .v624-title{
    font-size:13.5px!important;
  }

  #barah-step-senior-v57 .v624-copy p,
  #barah-step-senior-v57 .v624-copy .v624-desc{
    font-size:12px!important;
  }
}

/* حماية نسخة الدسكتوب */
@media (min-width:768px){
  #barah-step-senior-v57 .v624-thumb img{
    transform:none!important;
  }
}

`;

(document.head||document.documentElement).appendChild(s);

})();


/* ============================================================
BARAH V64.8 — SENIOR MOBILE IMAGE CLARITY BOOST V4.3
ONLY MOBILE:
- Make senior-section card images clearly larger and easier to see
- Stronger than previous attempts
- Desktop untouched
============================================================ */
(function(){
'use strict';

if(window.__BARAH_SENIOR_MOBILE_CLARITY_V43__) return;
window.__BARAH_SENIOR_MOBILE_CLARITY_V43__=true;

var ID='barah-senior-mobile-clarity-v43';
if(document.getElementById(ID)) return;

var s=document.createElement('style');
s.id=ID;
s.textContent=`

@media (max-width:767px){

  /* Bigger card structure for this section only */
  #barah-step-senior-v57 .v614-path{
    min-height:188px!important;
    padding:12px!important;
    border-radius:16px!important;
  }

  #barah-step-senior-v57 .v624-top{
    display:grid!important;
    grid-template-columns:112px 1fr!important;
    align-items:start!important;
    gap:10px!important;
  }

  /* Real image frame */
  #barah-step-senior-v57 .v624-thumb{
    width:112px!important;
    min-width:112px!important;
    max-width:112px!important;
    height:112px!important;
    min-height:112px!important;
    max-height:112px!important;
    flex:0 0 112px!important;
    padding:0!important;
    margin:0!important;
    overflow:hidden!important;
    border-radius:14px!important;
    background:#fff!important;
    box-sizing:border-box!important;
  }

  /* Make the product itself visually bigger */
  #barah-step-senior-v57 .v624-thumb img{
    display:block!important;
    width:100%!important;
    height:100%!important;
    max-width:none!important;
    max-height:none!important;
    object-fit:contain!important;
    object-position:center center!important;
    transform:scale(1.78)!important;
    transform-origin:center center!important;
    margin:0!important;
    padding:0!important;
    image-rendering:auto!important;
  }

  /* Keep copy readable */
  #barah-step-senior-v57 .v624-copy{
    min-width:0!important;
    align-self:start!important;
  }

  #barah-step-senior-v57 .v624-title{
    font-size:14px!important;
    line-height:1.45!important;
    margin-bottom:4px!important;
  }

  #barah-step-senior-v57 .v624-copy p,
  #barah-step-senior-v57 .v624-copy .v624-desc{
    font-size:12.5px!important;
    line-height:1.55!important;
  }

  #barah-step-senior-v57 .v624-link,
  #barah-step-senior-v57 a[href*="search"]{
    display:inline-block!important;
    margin-top:8px!important;
  }
}

@media (max-width:390px){

  #barah-step-senior-v57 .v614-path{
    min-height:178px!important;
    padding:11px!important;
  }

  #barah-step-senior-v57 .v624-top{
    grid-template-columns:104px 1fr!important;
    gap:9px!important;
  }

  #barah-step-senior-v57 .v624-thumb{
    width:104px!important;
    min-width:104px!important;
    max-width:104px!important;
    height:104px!important;
    min-height:104px!important;
    max-height:104px!important;
    flex-basis:104px!important;
  }

  #barah-step-senior-v57 .v624-thumb img{
    transform:scale(1.72)!important;
  }

  #barah-step-senior-v57 .v624-title{
    font-size:13.5px!important;
  }

  #barah-step-senior-v57 .v624-copy p,
  #barah-step-senior-v57 .v624-copy .v624-desc{
    font-size:12px!important;
  }
}

/* Explicit desktop safety */
@media (min-width:768px){
  #barah-step-senior-v57 .v624-thumb{
    width:auto!important;
    height:auto!important;
    min-width:0!important;
    min-height:0!important;
    max-width:none!important;
    max-height:none!important;
  }

  #barah-step-senior-v57 .v624-thumb img{
    transform:none!important;
  }
}

`;

(document.head||document.documentElement).appendChild(s);

})();


/* ============================================================
BARAH V64.8 — SENIOR MOBILE IMAGE FIT V4.4
ONLY CHANGE:
- Keep current mobile image/card size.
- Show the complete product image without aggressive cropping.
- Desktop untouched.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_SENIOR_MOBILE_IMAGE_FIT_V44__) return;
window.__BARAH_SENIOR_MOBILE_IMAGE_FIT_V44__=true;

var ID='barah-senior-mobile-image-fit-v44';
if(document.getElementById(ID)) return;

var s=document.createElement('style');
s.id=ID;
s.textContent=`

@media (max-width:767px){

  #barah-step-senior-v57 .v624-thumb{
    width:112px!important;
    min-width:112px!important;
    max-width:112px!important;
    height:112px!important;
    min-height:112px!important;
    max-height:112px!important;
    padding:5px!important;
    overflow:hidden!important;
    background:#fff!important;
  }

  #barah-step-senior-v57 .v624-thumb img{
    display:block!important;
    width:100%!important;
    height:100%!important;
    max-width:100%!important;
    max-height:100%!important;

    /* Show the whole product instead of cropping it */
    object-fit:contain!important;
    object-position:center center!important;
    transform:scale(1.12)!important;
    transform-origin:center center!important;

    margin:0!important;
    padding:0!important;
  }
}

@media (max-width:390px){

  #barah-step-senior-v57 .v624-thumb{
    width:104px!important;
    min-width:104px!important;
    max-width:104px!important;
    height:104px!important;
    min-height:104px!important;
    max-height:104px!important;
    padding:4px!important;
  }

  #barah-step-senior-v57 .v624-thumb img{
    transform:scale(1.10)!important;
  }
}

/* Desktop untouched */
@media (min-width:768px){
  #barah-step-senior-v57 .v624-thumb img{
    transform:none!important;
  }
}

`;

(document.head||document.documentElement).appendChild(s);

})();


/* ============================================================
BARAH V64.8 — MOBILE FOOTER PAYMENT GRID V4.5
ONLY MOBILE:
- Neat payment/logo grid
- Equal visual boxes
- Hide broken/garbled wallet image/text
- Keep VAT line separate
- No other footer changes
============================================================ */
(function(){
'use strict';

if(window.__BARAH_MOBILE_PAYMENT_GRID_V45__) return;
window.__BARAH_MOBILE_PAYMENT_GRID_V45__=true;

var STYLE_ID='barah-mobile-payment-grid-v45-style';

function addStyle(){
  if(document.getElementById(STYLE_ID)) return;

  var s=document.createElement('style');
  s.id=STYLE_ID;
  s.textContent=`

@media(max-width:767px){

  footer .barah-v45-pay-grid{
    display:grid!important;
    grid-template-columns:repeat(4,minmax(0,1fr))!important;
    gap:6px!important;
    width:min(286px,92vw)!important;
    margin:8px auto 10px!important;
    padding:0!important;
    align-items:center!important;
    justify-items:center!important;
  }

  footer .barah-v45-pay-item{
    width:100%!important;
    height:34px!important;
    min-width:0!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    padding:4px 6px!important;
    margin:0!important;
    border:1px solid rgba(17,24,39,.07)!important;
    border-radius:7px!important;
    background:#fff!important;
    overflow:hidden!important;
    box-sizing:border-box!important;
    line-height:1!important;
  }

  footer .barah-v45-pay-item img{
    display:block!important;
    width:auto!important;
    height:auto!important;
    max-width:52px!important;
    max-height:21px!important;
    object-fit:contain!important;
    margin:0!important;
    padding:0!important;
    transform:none!important;
  }

  footer .barah-v45-pay-hide{
    display:none!important;
  }

  footer .barah-v45-vat-line{
    width:100%!important;
    text-align:center!important;
    margin:0 auto 8px!important;
    font-size:11.5px!important;
    line-height:1.5!important;
  }
}

@media(max-width:390px){

  footer .barah-v45-pay-grid{
    width:min(274px,94vw)!important;
    gap:5px!important;
  }

  footer .barah-v45-pay-item{
    height:32px!important;
    padding:4px!important;
  }

  footer .barah-v45-pay-item img{
    max-width:48px!important;
    max-height:20px!important;
  }
}

`;

  (document.head||document.documentElement).appendChild(s);
}

function txt(el){
  return String((el && el.textContent)||'').replace(/\s+/g,' ').trim();
}

function isPaymentImage(img){
  if(!img) return false;

  var s=[
    img.getAttribute('src')||'',
    img.getAttribute('data-src')||'',
    img.getAttribute('alt')||'',
    img.getAttribute('title')||''
  ].join(' ').toLowerCase();

  return /mada|visa|master|tabby|tamara|apple.?pay|stc.?pay|stc|bank|wallet|payment|pay\b|مدى|تابي|تمارا|محفظة/.test(s);
}

function hideBroken(img){
  if(!img) return false;

  var meta=[
    img.getAttribute('src')||'',
    img.getAttribute('data-src')||'',
    img.getAttribute('alt')||'',
    img.getAttribute('title')||''
  ].join(' ').toLowerCase();

  var broken=(img.complete && img.naturalWidth===0);
  var badWallet=/wallet|customer_wallet|mahally_customer_wallet/.test(meta);

  if(broken || badWallet){
    var el=img.closest('a,li,span,div') || img;
    el.classList.add('barah-v45-pay-hide');
    return true;
  }

  return false;
}

function markVat(footer){
  Array.prototype.slice.call(
    footer.querySelectorAll('div,p,span')
  ).forEach(function(el){
    if(txt(el).indexOf('الرقم الضريبي')!==-1){
      el.classList.add('barah-v45-vat-line');
    }
  });
}

function organize(){
  var footer=document.querySelector('footer');
  if(!footer) return;

  addStyle();
  markVat(footer);

  var imgs=Array.prototype.slice.call(
    footer.querySelectorAll('img')
  ).filter(isPaymentImage);

  if(!imgs.length) return;

  imgs.forEach(hideBroken);

  var usable=imgs.filter(function(img){
    return !img.closest('.barah-v45-pay-hide');
  });

  if(!usable.length) return;

  /*
   Find the smallest common wrapper containing most payment images.
   Avoid taking all of footer.
  */
  var candidates=[];

  usable.forEach(function(img){
    var p=img.parentElement;
    var depth=0;

    while(p && p!==footer && depth<5){
      var count=Array.prototype.slice.call(
        p.querySelectorAll('img')
      ).filter(isPaymentImage).length;

      if(count>=3){
        candidates.push({el:p,count:count,depth:depth});
      }

      p=p.parentElement;
      depth++;
    }
  });

  if(!candidates.length) return;

  candidates.sort(function(a,b){
    if(a.count!==b.count) return b.count-a.count;
    return a.depth-b.depth;
  });

  var wrapper=candidates[0].el;
  if(!wrapper || wrapper===footer) return;

  wrapper.classList.add('barah-v45-pay-grid');

  usable.forEach(function(img){
    if(!wrapper.contains(img)) return;

    var item=img.parentElement;

    while(
      item &&
      item.parentElement!==wrapper &&
      item.parentElement &&
      item.parentElement!==footer
    ){
      item=item.parentElement;
    }

    if(item && item!==wrapper){
      item.classList.add('barah-v45-pay-item');

      /* remove stray textual fallback inside a logo cell */
      Array.prototype.slice.call(item.childNodes).forEach(function(n){
        if(n.nodeType===3 && /allet/i.test(String(n.nodeValue||''))){
          n.nodeValue='';
        }
      });
    }
  });

  /* Hide any remaining bare 'allet' text in the payment region */
  Array.prototype.slice.call(wrapper.querySelectorAll('*')).forEach(function(el){
    if(txt(el).toLowerCase()==='allet'){
      el.classList.add('barah-v45-pay-hide');
    }
  });
}

function run(){
  if(!window.matchMedia || !window.matchMedia('(max-width:767px)').matches) return;
  organize();
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}

window.addEventListener('load',run,{once:true});

[250,700,1400,2600,5000].forEach(function(ms){
  setTimeout(run,ms);
});

})();


/* ============================================================
BARAH V64.8 — MOBILE FOOTER IMPORTANT LINKS 2 ROWS V4.6
ONLY MOBILE:
- "روابط مهمة" becomes 2 compact rows (3 links each)
- About / Contact / Payments untouched
============================================================ */
(function(){
'use strict';

if(window.__BARAH_FOOTER_LINKS_2ROWS_V46__) return;
window.__BARAH_FOOTER_LINKS_2ROWS_V46__=true;

var STYLE_ID='barah-footer-links-2rows-v46-style';

function clean(v){
  return String(v||'').replace(/\s+/g,' ').trim();
}

function addStyle(){
  if(document.getElementById(STYLE_ID)) return;

  var s=document.createElement('style');
  s.id=STYLE_ID;
  s.textContent=`

@media(max-width:767px){

  footer .barah-important-links-v46{
    display:grid!important;
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
    gap:7px 6px!important;
    width:100%!important;
    margin-top:8px!important;
    padding:0!important;
  }

  footer .barah-important-links-v46 > a,
  footer .barah-important-links-v46 > li,
  footer .barah-important-links-v46 > div{
    margin:0!important;
    padding:0!important;
    min-width:0!important;
    width:auto!important;
    text-align:center!important;
  }

  footer .barah-important-links-v46 a{
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    min-height:34px!important;
    padding:5px 4px!important;
    margin:0!important;
    border:1px solid rgba(17,24,39,.06)!important;
    border-radius:8px!important;
    background:#fff!important;
    font-size:11.5px!important;
    line-height:1.35!important;
    text-align:center!important;
    white-space:normal!important;
  }

  footer .barah-important-title-v46{
    margin-bottom:4px!important;
  }
}

@media(max-width:390px){
  footer .barah-important-links-v46{
    gap:6px 5px!important;
  }

  footer .barah-important-links-v46 a{
    font-size:11px!important;
    padding:4px 3px!important;
  }
}

`;

  (document.head||document.documentElement).appendChild(s);
}

function findImportantBlock(){
  var footer=document.querySelector('footer');
  if(!footer) return null;

  var candidates=Array.prototype.slice.call(
    footer.querySelectorAll('h2,h3,h4,h5,strong,div,p,span')
  );

  var title=candidates.find(function(el){
    return clean(el.textContent)==='روابط مهمة';
  });

  if(!title) return null;

  title.classList.add('barah-important-title-v46');

  var box=title.parentElement;
  for(var i=0;i<4 && box && box!==footer;i++,box=box.parentElement){
    var links=box.querySelectorAll('a');
    if(links.length>=4 && links.length<=10){
      return {title:title, box:box, links:Array.from(links)};
    }
  }

  return null;
}

function organize(){
  if(!window.matchMedia || !window.matchMedia('(max-width:767px)').matches) return;

  addStyle();

  var found=findImportantBlock();
  if(!found) return;

  var links=found.links.filter(function(a){
    var t=clean(a.textContent);
    return (
      t &&
      (
        t.indexOf('المدونة')!==-1 ||
        t.indexOf('الشحن')!==-1 ||
        t.indexOf('الاستبدال')!==-1 ||
        t.indexOf('الاستخدام')!==-1 ||
        t.indexOf('عن بارعة')!==-1 ||
        t.indexOf('التسويق بالعمولة')!==-1
      )
    );
  });

  if(links.length<4) return;

  var grid=found.box.querySelector('.barah-important-links-v46');

  if(!grid){
    grid=document.createElement('div');
    grid.className='barah-important-links-v46';

    var first=links[0];
    var parent=first.parentElement;

    if(parent && links.every(function(a){ return a.parentElement===parent; })){
      parent.parentElement.insertBefore(grid,parent);
      links.forEach(function(a){
        var li=a.closest('li');
        if(li && li.parentElement===parent){
          grid.appendChild(li);
        }else{
          grid.appendChild(a);
        }
      });

      if(parent.children.length===0){
        parent.remove();
      }
    }else{
      found.title.insertAdjacentElement('afterend',grid);
      links.forEach(function(a){
        grid.appendChild(a);
      });
    }
  }
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',organize,{once:true});
}else{
  organize();
}

window.addEventListener('load',organize,{once:true});

[300,800,1600,3200].forEach(function(ms){
  setTimeout(organize,ms);
});

})();


/* ============================================================
BARAH V64.8 — CART CURRENCY RENDER FIX V4.7
ONLY CART:
- Fix literal/escaped <i class="sicon-sar"></i> text
- Convert broken SAR markup to "ر.س"
- Re-run after cart quantity updates
- Do not alter prices, quantities, totals, or cart logic
============================================================ */
(function(){
'use strict';

if(window.__BARAH_CART_CURRENCY_FIX_V47__) return;
window.__BARAH_CART_CURRENCY_FIX_V47__=true;

function isCartPage(){
  var p=String(location.pathname||'').replace(/\/+$/,'')||'/';
  return /\/cart(?:\/|$)/i.test(p) ||
    document.body.classList.contains('cart-page') ||
    !!document.querySelector('.cart-page,.page--cart,#cart-page,salla-cart-summary,[data-cart-page]');
}

function cleanCurrencyText(value){
  var s=String(value==null?'':value);
  s=s.replace(/<i\b[^>]*class=(?:"[^"]*\bsicon-sar\b[^"]*"|'[^']*\bsicon-sar\b[^']*'|[^\s>]*\bsicon-sar\b[^\s>]*)[^>]*>\s*<\/i>/gi,' ر.س ');
  s=s.replace(/<i\b[^>]*\bsicon-sar\b[^>]*>/gi,' ر.س ');
  s=s.replace(/<\/i>/gi,'');
  s=s.replace(/&lt;i\b[^&]*?\bsicon-sar\b[^&]*?&gt;\s*&lt;\/i&gt;/gi,' ر.س ');
  s=s.replace(/&lt;i\b[^&]*?\bsicon-sar\b[^&]*?&gt;/gi,' ر.س ');
  s=s.replace(/&lt;\/i&gt;/gi,'');
  s=s.replace(/\bSAR\b/gi,' ر.س ');
  return s.replace(/\s+/g,' ').replace(/\s*ر\.س\s*/g,' ر.س ').trim();
}

function cleanElementCurrency(el){
  if(!el) return;
  if(el.querySelectorAll){
    el.querySelectorAll('i.sicon-sar').forEach(function(icon){
      icon.replaceWith(document.createTextNode(' ر.س '));
    });
  }
  var walker=document.createTreeWalker(el,NodeFilter.SHOW_TEXT,null);
  var nodes=[];
  while(walker.nextNode()) nodes.push(walker.currentNode);
  nodes.forEach(function(node){
    var before=node.nodeValue||'';
    var after=cleanCurrencyText(before);
    if(after!==before.trim()) node.nodeValue=after;
  });
}

function fixCartCurrencies(){
  if(!isCartPage()) return;
  var selectors=[
    '.cart-item-price','.cart-item-total','.cart-item-subtotal',
    '.cart-product-price','.cart-product-total',
    '[class*="cart-item"] [class*="price"]',
    '[class*="cart-item"] [class*="total"]',
    '#cart-sub-total','#cart-subtotal','#cart-shipping-cost',
    '#cart-total-discount','#cart-total','#cart-final-total',
    '#free-shipping-msg','.cart-summary','.cart-summary-total',
    '.cart-totals','.cart-total','.cart__total','salla-cart-summary'
  ];
  var seen=new Set();
  selectors.forEach(function(sel){
    document.querySelectorAll(sel).forEach(function(el){
      if(seen.has(el)) return;
      seen.add(el);
      cleanElementCurrency(el);
    });
  });
  document.querySelectorAll('.cart-page *,#cart-page *,[class*="cart-"] *').forEach(function(el){
    if(el.children.length>6) return;
    var t=String(el.textContent||'');
    if(/sicon-sar/i.test(t) || /&lt;i[^&]*sicon-sar/i.test(t) || /\bSAR\b/.test(t)){
      cleanElementCurrency(el);
    }
  });
}

var timer=null;
function schedule(){
  if(!isCartPage()) return;
  clearTimeout(timer);
  timer=setTimeout(fixCartCurrencies,35);
}

function boot(){
  if(!isCartPage()) return;
  fixCartCurrencies();
  [120,300,700,1400,2600,5000].forEach(function(ms){setTimeout(fixCartCurrencies,ms);});
  if(window.MutationObserver){
    new MutationObserver(schedule).observe(document.documentElement,{childList:true,subtree:true,characterData:true});
  }
  ['salla::cart.updated','salla::cart::updated','cart.updated','cart::updated','salla-cart-updated'].forEach(function(name){
    document.addEventListener(name,schedule,true);
    window.addEventListener(name,schedule,true);
  });
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',boot,{once:true});
}else{
  boot();
}
window.addEventListener('load',function(){setTimeout(fixCartCurrencies,100);},{once:true});
})();


/* ============================================================
BARAH V64.8 — MOBILE PAYMENT STRIP REBUILD V4.8
ONLY MOBILE FOOTER PAYMENT AREA:
- Build one clean independent payment strip.
- Do not reuse Salla's inconsistent wrappers.
- Hide the old scattered payment row.
- Remove broken "allet"/wallet leftovers.
- VAT line and copyright stay untouched.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_PAYMENT_STRIP_V48__) return;
window.__BARAH_PAYMENT_STRIP_V48__=true;

var ROOT_ID='barah-payment-strip-v48';
var STYLE_ID='barah-payment-strip-v48-style';

function mobile(){
  return window.matchMedia && window.matchMedia('(max-width:767px)').matches;
}

function norm(v){
  return String(v||'').replace(/\s+/g,' ').trim();
}

function meta(img){
  return [
    img.getAttribute('src')||'',
    img.getAttribute('data-src')||'',
    img.getAttribute('alt')||'',
    img.getAttribute('title')||''
  ].join(' ').toLowerCase();
}

function isPay(img){
  return /mada|visa|master|tabby|tamara|apple.?pay|stc.?pay|stc|bank|payment|pay\b|مدى|تابي|تمارا/.test(meta(img));
}

function isBad(img){
  var m=meta(img);
  return (
    /wallet|customer_wallet|mahally_customer_wallet/.test(m) ||
    (img.complete && img.naturalWidth===0)
  );
}

function addStyle(){
  if(document.getElementById(STYLE_ID)) return;

  var s=document.createElement('style');
  s.id=STYLE_ID;
  s.textContent=`

@media(max-width:767px){

  footer #${ROOT_ID}{
    display:grid!important;
    grid-template-columns:repeat(4,minmax(0,1fr))!important;
    gap:6px!important;
    width:min(286px,92vw)!important;
    margin:9px auto 12px!important;
    padding:0!important;
    align-items:center!important;
    justify-items:stretch!important;
  }

  footer #${ROOT_ID} .barah-pay-v48-item{
    height:34px!important;
    min-width:0!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    padding:4px 5px!important;
    margin:0!important;
    border:1px solid rgba(17,24,39,.07)!important;
    border-radius:7px!important;
    background:#fff!important;
    box-sizing:border-box!important;
    overflow:hidden!important;
  }

  footer #${ROOT_ID} img{
    display:block!important;
    width:auto!important;
    height:auto!important;
    max-width:52px!important;
    max-height:21px!important;
    object-fit:contain!important;
    margin:0!important;
    padding:0!important;
    transform:none!important;
    filter:none!important;
  }

  footer .barah-pay-v48-old{
    display:none!important;
  }

  footer .barah-pay-v48-garble{
    display:none!important;
  }
}

@media(max-width:390px){
  footer #${ROOT_ID}{
    width:min(274px,94vw)!important;
    gap:5px!important;
  }

  footer #${ROOT_ID} .barah-pay-v48-item{
    height:32px!important;
  }

  footer #${ROOT_ID} img{
    max-width:48px!important;
    max-height:20px!important;
  }
}

`;
  (document.head||document.documentElement).appendChild(s);
}

function vatLine(footer){
  var all=Array.prototype.slice.call(
    footer.querySelectorAll('div,p,span')
  );

  return all.find(function(el){
    var t=norm(el.textContent);
    return t.indexOf('الرقم الضريبي')!==-1;
  }) || null;
}

function copyrightLine(footer){
  var all=Array.prototype.slice.call(
    footer.querySelectorAll('div,p,span')
  );

  return all.find(function(el){
    var t=norm(el.textContent);
    return (
      t.indexOf('جميع الحقوق محفوظة')!==-1 ||
      t.indexOf('BARAH STORE')!==-1
    );
  }) || null;
}

function uniqueImages(footer){
  var imgs=Array.prototype.slice.call(footer.querySelectorAll('img'))
    .filter(isPay)
    .filter(function(img){
      return !img.closest('#'+ROOT_ID);
    });

  var seen={};
  var out=[];

  imgs.forEach(function(img){
    if(isBad(img)) return;

    var key=(
      img.currentSrc ||
      img.getAttribute('src') ||
      img.getAttribute('data-src') ||
      img.getAttribute('alt') ||
      ''
    ).toLowerCase();

    key=key.replace(/\?.*$/,'').trim();
    if(!key || seen[key]) return;

    seen[key]=true;
    out.push(img);
  });

  return out;
}

function hideOriginals(images){
  images.forEach(function(img){
    var item=img.closest('a,li,span,div');

    if(item && !item.closest('#'+ROOT_ID)){
      item.classList.add('barah-pay-v48-old');
    }else{
      img.classList.add('barah-pay-v48-old');
    }
  });
}

function removeGarble(footer){
  Array.prototype.slice.call(
    footer.querySelectorAll('span,div,p,a')
  ).forEach(function(el){
    var t=norm(el.textContent).toLowerCase();

    if(t==='allet' || t==='wallet'){
      el.classList.add('barah-pay-v48-garble');
    }
  });
}

function build(){
  if(!mobile()) return;

  var footer=document.querySelector('footer');
  if(!footer) return;

  addStyle();
  removeGarble(footer);

  var images=uniqueImages(footer);
  if(!images.length) return;

  var strip=document.getElementById(ROOT_ID);

  if(!strip){
    strip=document.createElement('div');
    strip.id=ROOT_ID;
    strip.setAttribute('aria-label','وسائل الدفع');

    var vat=vatLine(footer);
    var rights=copyrightLine(footer);

    if(vat){
      vat.insertAdjacentElement('afterend',strip);
    }else if(rights){
      rights.insertAdjacentElement('beforebegin',strip);
    }else{
      footer.appendChild(strip);
    }
  }

  strip.innerHTML='';

  images.forEach(function(img){
    var clone=img.cloneNode(true);

    clone.removeAttribute('width');
    clone.removeAttribute('height');
    clone.removeAttribute('style');
    clone.removeAttribute('class');

    var item=document.createElement('div');
    item.className='barah-pay-v48-item';
    item.appendChild(clone);
    strip.appendChild(item);
  });

  hideOriginals(images);
  removeGarble(footer);
}

function run(){
  build();
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}

window.addEventListener('load',function(){
  setTimeout(run,100);
},{once:true});

[250,700,1400,2600,5000].forEach(function(ms){
  setTimeout(run,ms);
});

if(window.MutationObserver){
  var timer;
  new MutationObserver(function(){
    if(!mobile()) return;
    clearTimeout(timer);
    timer=setTimeout(run,120);
  }).observe(document.documentElement,{childList:true,subtree:true});
}

})();


/* ============================================================
BARAH V64.8 — MOBILE BOTTOM NAV CART V4.9
ONLY MOBILE:
- Add Cart as 4th item to existing bottom navigation
- Rename "تسجيل الدخول" to "حسابي"
- Live cart badge from Salla cart state/events
- Active item highlight
- Desktop untouched
============================================================ */
(function(){
'use strict';

if(window.__BARAH_MOBILE_BOTTOM_NAV_CART_V49__) return;
window.__BARAH_MOBILE_BOTTOM_NAV_CART_V49__=true;

var STYLE_ID='barah-mobile-bottom-nav-cart-v49-style';
var ITEM_ID='barah-mobile-bottom-cart-v49';

function isMobile(){
  return !!(window.matchMedia && window.matchMedia('(max-width:767px)').matches);
}

function clean(v){
  return String(v||'').replace(/\s+/g,' ').trim();
}

function addStyle(){
  if(document.getElementById(STYLE_ID)) return;

  var s=document.createElement('style');
  s.id=STYLE_ID;
  s.textContent=`

@media(max-width:767px){

  /* Existing bottom navigation: force clean 4-column distribution */
  .barah-v49-bottom-nav{
    display:grid!important;
    grid-template-columns:repeat(4,minmax(0,1fr))!important;
    align-items:center!important;
    gap:0!important;
  }

  .barah-v49-bottom-nav > a,
  .barah-v49-bottom-nav > button,
  .barah-v49-bottom-nav > div{
    min-width:0!important;
  }

  #${ITEM_ID}{
    position:relative!important;
    display:flex!important;
    flex-direction:column!important;
    align-items:center!important;
    justify-content:center!important;
    gap:4px!important;
    min-height:58px!important;
    padding:6px 2px!important;
    text-decoration:none!important;
    color:#111827!important;
    font-size:13px!important;
    line-height:1.2!important;
    background:transparent!important;
  }

  #${ITEM_ID} .barah-v49-cart-icon{
    position:relative!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    width:24px!important;
    height:24px!important;
    font-size:22px!important;
    line-height:1!important;
  }

  #${ITEM_ID} .barah-v49-cart-badge{
    position:absolute!important;
    top:-7px!important;
    right:-9px!important;
    min-width:17px!important;
    height:17px!important;
    padding:0 4px!important;
    border-radius:999px!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    background:#f97316!important;
    color:#fff!important;
    font-size:10px!important;
    font-weight:800!important;
    line-height:1!important;
    box-shadow:0 0 0 2px #fff!important;
  }

  #${ITEM_ID}[data-count="0"] .barah-v49-cart-badge{
    display:none!important;
  }

  #${ITEM_ID}.is-active,
  #${ITEM_ID}[aria-current="page"]{
    color:#ea580c!important;
    font-weight:700!important;
  }

  #${ITEM_ID}.has-items .barah-v49-cart-icon{
    color:#ea580c!important;
  }

  /* Keep labels compact */
  .barah-v49-bottom-nav .barah-v49-label{
    font-size:13px!important;
    line-height:1.2!important;
    white-space:nowrap!important;
  }
}

@media(max-width:390px){
  #${ITEM_ID}{
    font-size:12.5px!important;
  }

  .barah-v49-bottom-nav .barah-v49-label{
    font-size:12.5px!important;
  }
}

`;

  (document.head||document.documentElement).appendChild(s);
}

function findBottomNav(){
  var candidates = Array.prototype.slice.call(document.querySelectorAll(
    'nav,footer [class*="nav"],[class*="bottom"],[class*="mobile-nav"],[class*="footer-nav"]'
  ));

  return candidates.find(function(el){
    var t=clean(el.textContent);
    return (
      t.indexOf('الرئيسية')!==-1 &&
      t.indexOf('فئات المنتجات')!==-1 &&
      (
        t.indexOf('تسجيل الدخول')!==-1 ||
        t.indexOf('حسابي')!==-1
      )
    );
  }) || null;
}

function renameAccount(nav){
  if(!nav) return;

  Array.prototype.slice.call(nav.querySelectorAll('a,button,span,div')).forEach(function(el){
    if(clean(el.textContent)==='تسجيل الدخول'){
      /* Prefer changing only the text node, preserve icon/structure */
      var textNode = Array.prototype.slice.call(el.childNodes).find(function(n){
        return n.nodeType===3 && clean(n.nodeValue)==='تسجيل الدخول';
      });

      if(textNode){
        textNode.nodeValue='حسابي';
      }else if(el.children.length===0){
        el.textContent='حسابي';
      }
    }
  });
}

function buildCartItem(nav){
  if(!nav || document.getElementById(ITEM_ID)) return;

  nav.classList.add('barah-v49-bottom-nav');

  var a=document.createElement('a');
  a.id=ITEM_ID;
  a.href='/ar/cart';
  a.setAttribute('aria-label','السلة');
  a.setAttribute('data-count','0');

  a.innerHTML=
    '<span class="barah-v49-cart-icon" aria-hidden="true">'+
      '🛒'+
      '<span class="barah-v49-cart-badge">0</span>'+
    '</span>'+
    '<span class="barah-v49-label">السلة</span>';

  /*
   Insert before account item when possible:
   الرئيسية | فئات المنتجات | السلة | حسابي
  */
  var accountItem=null;

  Array.prototype.slice.call(nav.children).forEach(function(child){
    var t=clean(child.textContent);
    if(
      t.indexOf('حسابي')!==-1 ||
      t.indexOf('تسجيل الدخول')!==-1
    ){
      accountItem=child;
    }
  });

  if(accountItem){
    nav.insertBefore(a,accountItem);
  }else{
    nav.appendChild(a);
  }
}

function cartCountFromDOM(){
  var selectors=[
    '[data-cart-count]',
    '.cart-count',
    '.s-cart-summary-count',
    'salla-cart-summary [class*="count"]',
    '.header-cart [class*="count"]',
    '[class*="cart"] .badge'
  ];

  for(var i=0;i<selectors.length;i++){
    var els=document.querySelectorAll(selectors[i]);

    for(var j=0;j<els.length;j++){
      var raw =
        els[j].getAttribute('data-cart-count') ||
        els[j].textContent ||
        '';

      var m=String(raw).match(/\d+/);
      if(m){
        var n=parseInt(m[0],10);
        if(Number.isFinite(n)) return n;
      }
    }
  }

  return 0;
}

function updateCount(explicitCount){
  var item=document.getElementById(ITEM_ID);
  if(!item) return;

  var count=Number.isFinite(explicitCount)
    ? explicitCount
    : cartCountFromDOM();

  count=Math.max(0,parseInt(count||0,10)||0);

  item.setAttribute('data-count',String(count));
  item.classList.toggle('has-items',count>0);

  var badge=item.querySelector('.barah-v49-cart-badge');
  if(badge){
    badge.textContent=count>99?'99+':String(count);
  }
}

function setActive(){
  var item=document.getElementById(ITEM_ID);
  if(!item) return;

  var p=String(location.pathname||'');
  var active=/\/cart(?:\/|$)/i.test(p);

  item.classList.toggle('is-active',active);

  if(active){
    item.setAttribute('aria-current','page');
  }else{
    item.removeAttribute('aria-current');
  }
}

function sync(){
  if(!isMobile()) return;

  addStyle();

  var nav=findBottomNav();
  if(!nav) return;

  renameAccount(nav);
  buildCartItem(nav);
  setActive();
  updateCount();
}

function eventCount(e){
  try{
    var d=e && e.detail ? e.detail : null;

    var candidates=[
      d && d.count,
      d && d.cart && d.cart.count,
      d && d.data && d.data.count,
      d && d.data && d.data.cart && d.data.cart.count,
      d && d.cart && d.cart.items_count,
      d && d.items_count
    ];

    for(var i=0;i<candidates.length;i++){
      var n=parseInt(candidates[i],10);
      if(Number.isFinite(n)) return n;
    }
  }catch(_){}

  return null;
}

function onCartEvent(e){
  setTimeout(function(){
    var n=eventCount(e);
    updateCount(n===null?undefined:n);
  },60);
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',sync,{once:true});
}else{
  sync();
}

window.addEventListener('load',function(){
  setTimeout(sync,120);
},{once:true});

[
  'salla::cart.updated',
  'salla::cart::updated',
  'cart.updated',
  'cart::updated',
  'salla-cart-updated',
  'salla::cart.added',
  'salla::cart.deleted'
].forEach(function(name){
  document.addEventListener(name,onCartEvent,true);
  window.addEventListener(name,onCartEvent,true);
});

[250,700,1400,2600,5000].forEach(function(ms){
  setTimeout(sync,ms);
});

if(window.MutationObserver){
  var timer;
  new MutationObserver(function(){
    if(!isMobile()) return;
    clearTimeout(timer);
    timer=setTimeout(sync,100);
  }).observe(document.documentElement,{childList:true,subtree:true});
}

})();


/* ============================================================
BARAH V64.8 — MOBILE BOTTOM NAV DIRECT FIX V5.0
Fix for themes whose bottom bar has no predictable nav class.
Strategy:
- Find the 3 real visible items by text.
- Detect their true common parent.
- Add Cart as the 4th sibling.
- Rename Login -> حسابي.
- Mobile only. Desktop untouched.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_MOBILE_BOTTOM_NAV_DIRECT_V50__) return;
window.__BARAH_MOBILE_BOTTOM_NAV_DIRECT_V50__=true;

var ITEM_ID='barah-mobile-bottom-cart-v50';
var STYLE_ID='barah-mobile-bottom-nav-direct-v50-style';

function isMobile(){
  return !!(window.matchMedia && window.matchMedia('(max-width:767px)').matches);
}

function clean(v){
  return String(v||'').replace(/\s+/g,' ').trim();
}

function visible(el){
  if(!el) return false;
  var s=getComputedStyle(el);
  if(s.display==='none' || s.visibility==='hidden' || Number(s.opacity)===0) return false;
  var r=el.getBoundingClientRect();
  return r.width>20 && r.height>20;
}

function findClickableByText(label){
  var nodes=Array.prototype.slice.call(
    document.querySelectorAll('a,button,[role="button"]')
  );

  var exact=nodes.filter(function(el){
    return visible(el) && clean(el.textContent)===label;
  });

  if(exact.length) return exact[exact.length-1];

  var partial=nodes.filter(function(el){
    var t=clean(el.textContent);
    return visible(el) && t.indexOf(label)!==-1 && t.length<40;
  });

  return partial.length ? partial[partial.length-1] : null;
}

function ancestors(el){
  var arr=[];
  var p=el;
  for(var i=0;i<8 && p && p!==document.body;i++,p=p.parentElement){
    arr.push(p);
  }
  return arr;
}

function commonParent(items){
  if(items.some(function(x){return !x;})) return null;

  var a0=ancestors(items[0]);

  for(var i=0;i<a0.length;i++){
    var cand=a0[i];

    if(items.every(function(el){
      return cand===el || cand.contains(el);
    })){
      /*
       Prefer a compact common parent, not a huge page wrapper.
      */
      var r=cand.getBoundingClientRect();
      if(r.height<=130 && r.width>=220){
        return cand;
      }
    }
  }

  return null;
}

function addStyle(){
  if(document.getElementById(STYLE_ID)) return;

  var s=document.createElement('style');
  s.id=STYLE_ID;
  s.textContent=`

@media(max-width:767px){

  .barah-bottom-nav-v50{
    display:grid!important;
    grid-template-columns:repeat(4,minmax(0,1fr))!important;
    align-items:stretch!important;
    justify-items:stretch!important;
    gap:0!important;
  }

  .barah-bottom-nav-v50 > *{
    min-width:0!important;
    width:auto!important;
    flex:1 1 25%!important;
  }

  #${ITEM_ID}{
    position:relative!important;
    display:flex!important;
    flex-direction:column!important;
    align-items:center!important;
    justify-content:center!important;
    gap:4px!important;
    min-height:64px!important;
    padding:6px 2px!important;
    margin:0!important;
    color:#111!important;
    text-decoration:none!important;
    background:transparent!important;
    border:0!important;
    font-family:inherit!important;
    font-size:14px!important;
    line-height:1.2!important;
    box-sizing:border-box!important;
  }

  #${ITEM_ID} .barah-cart-v50-icon{
    position:relative!important;
    width:24px!important;
    height:24px!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
  }

  #${ITEM_ID} .barah-cart-v50-icon svg{
    display:block!important;
    width:22px!important;
    height:22px!important;
    stroke:currentColor!important;
  }

  #${ITEM_ID} .barah-cart-v50-badge{
    position:absolute!important;
    top:-7px!important;
    right:-10px!important;
    min-width:17px!important;
    height:17px!important;
    padding:0 4px!important;
    border-radius:999px!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    background:#f97316!important;
    color:#fff!important;
    box-shadow:0 0 0 2px #fff!important;
    font-size:10px!important;
    font-weight:800!important;
    line-height:1!important;
  }

  #${ITEM_ID}[data-count="0"] .barah-cart-v50-badge{
    display:none!important;
  }

  #${ITEM_ID}.has-items,
  #${ITEM_ID}.is-active{
    color:#ea580c!important;
    font-weight:700!important;
  }

  #${ITEM_ID} .barah-cart-v50-label{
    display:block!important;
    font-size:14px!important;
    white-space:nowrap!important;
  }
}

@media(max-width:390px){
  #${ITEM_ID},
  #${ITEM_ID} .barah-cart-v50-label{
    font-size:13px!important;
  }
}

`;

  (document.head||document.documentElement).appendChild(s);
}

function renameLogin(login){
  if(!login) return;

  var walker=document.createTreeWalker(login,NodeFilter.SHOW_TEXT,null);
  var nodes=[];

  while(walker.nextNode()) nodes.push(walker.currentNode);

  nodes.forEach(function(n){
    if(clean(n.nodeValue)==='تسجيل الدخول'){
      n.nodeValue=n.nodeValue.replace('تسجيل الدخول','حسابي');
    }
  });

  if(clean(login.textContent)==='تسجيل الدخول' && login.children.length===0){
    login.textContent='حسابي';
  }
}

function cartCount(){
  var selectors=[
    '[data-cart-count]',
    '.cart-count',
    '.s-cart-summary-count',
    'salla-cart-summary [class*="count"]',
    '[class*="cart"] [class*="count"]',
    '[class*="cart"] .badge'
  ];

  for(var i=0;i<selectors.length;i++){
    var els=document.querySelectorAll(selectors[i]);

    for(var j=0;j<els.length;j++){
      if(els[j].id===ITEM_ID || els[j].closest('#'+ITEM_ID)) continue;

      var raw=els[j].getAttribute('data-cart-count') || els[j].textContent || '';
      var m=String(raw).match(/\d+/);

      if(m){
        var n=parseInt(m[0],10);
        if(Number.isFinite(n)) return n;
      }
    }
  }

  return 0;
}

function updateCount(){
  var item=document.getElementById(ITEM_ID);
  if(!item) return;

  var n=Math.max(0,cartCount()||0);
  item.setAttribute('data-count',String(n));
  item.classList.toggle('has-items',n>0);

  var b=item.querySelector('.barah-cart-v50-badge');
  if(b) b.textContent=n>99?'99+':String(n);
}

function makeCartItem(){
  var a=document.createElement('a');
  a.id=ITEM_ID;
  a.href='/ar/cart';
  a.setAttribute('aria-label','السلة');
  a.setAttribute('data-count','0');

  a.innerHTML=
    '<span class="barah-cart-v50-icon" aria-hidden="true">'+
      '<svg viewBox="0 0 24 24" fill="none" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">'+
        '<circle cx="9" cy="20" r="1"></circle>'+
        '<circle cx="19" cy="20" r="1"></circle>'+
        '<path d="M3 4h2l2.4 10.2a2 2 0 0 0 2 1.55h7.7a2 2 0 0 0 1.95-1.56L21 7H6"></path>'+
      '</svg>'+
      '<span class="barah-cart-v50-badge">0</span>'+
    '</span>'+
    '<span class="barah-cart-v50-label">السلة</span>';

  return a;
}

function mount(){
  if(!isMobile()) return false;

  addStyle();

  var home=findClickableByText('الرئيسية');
  var cats=findClickableByText('فئات المنتجات');
  var login=findClickableByText('تسجيل الدخول') || findClickableByText('حسابي');

  if(!home || !cats || !login) return false;

  var parent=commonParent([home,cats,login]);
  if(!parent) return false;

  renameLogin(login);
  parent.classList.add('barah-bottom-nav-v50');

  /* Remove failed previous cart if one somehow exists elsewhere */
  var old=document.getElementById('barah-mobile-bottom-cart-v49');
  if(old && old.parentElement!==parent) old.remove();

  var cart=document.getElementById(ITEM_ID);

  if(!cart){
    cart=makeCartItem();

    /*
      Visual order in RTL:
      الرئيسية | فئات المنتجات | السلة | حسابي
      Insert directly before account/login sibling.
    */
    var loginChild=login;
    while(loginChild.parentElement && loginChild.parentElement!==parent){
      loginChild=loginChild.parentElement;
    }

    if(loginChild.parentElement===parent){
      parent.insertBefore(cart,loginChild);
    }else{
      parent.appendChild(cart);
    }
  }

  var p=String(location.pathname||'');
  cart.classList.toggle('is-active',/\/cart(?:\/|$)/i.test(p));

  updateCount();

  return true;
}

function run(){
  if(mount()) return;
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}

window.addEventListener('load',function(){
  setTimeout(run,80);
},{once:true});

[100,250,500,900,1500,2500,4500,7000].forEach(function(ms){
  setTimeout(function(){
    run();
    updateCount();
  },ms);
});

[
  'salla::cart.updated',
  'salla::cart::updated',
  'cart.updated',
  'cart::updated',
  'salla-cart-updated',
  'salla::cart.added',
  'salla::cart.deleted'
].forEach(function(name){
  document.addEventListener(name,function(){
    setTimeout(updateCount,80);
    setTimeout(updateCount,350);
  },true);
});

if(window.MutationObserver){
  var timer;
  new MutationObserver(function(){
    if(!isMobile()) return;
    clearTimeout(timer);
    timer=setTimeout(function(){
      run();
      updateCount();
    },80);
  }).observe(document.documentElement,{childList:true,subtree:true});
}

})();


/* ============================================================
BARAH V64.8 — MOBILE BOTTOM NAV REBUILD V5.1
FINAL APPROACH:
- Detect the existing 3-item mobile bottom bar by visible text.
- Reuse its real Home / Categories / Account URLs.
- Hide only that original bottom bar on mobile.
- Build a clean independent 4-item bar:
  الرئيسية | فئات المنتجات | السلة | حسابي
- Live cart badge.
- Desktop untouched.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_MOBILE_BOTTOM_NAV_REBUILD_V51__) return;
window.__BARAH_MOBILE_BOTTOM_NAV_REBUILD_V51__=true;

var NAV_ID='barah-mobile-bottom-nav-v51';
var STYLE_ID='barah-mobile-bottom-nav-v51-style';

function isMobile(){
  return !!(window.matchMedia && window.matchMedia('(max-width:767px)').matches);
}

function clean(v){
  return String(v||'').replace(/\s+/g,' ').trim();
}

function visible(el){
  if(!el) return false;
  var st=getComputedStyle(el);
  if(st.display==='none' || st.visibility==='hidden' || Number(st.opacity)===0) return false;
  var r=el.getBoundingClientRect();
  return r.width>20 && r.height>20;
}

function viewportBottom(el){
  var r=el.getBoundingClientRect();
  return r.bottom >= (window.innerHeight - 140);
}

function findLink(label){
  var nodes=Array.prototype.slice.call(
    document.querySelectorAll('a,button,[role="button"]')
  );

  var exact=nodes.filter(function(el){
    return visible(el) &&
      viewportBottom(el) &&
      clean(el.textContent)===label;
  });

  if(exact.length) return exact[exact.length-1];

  var partial=nodes.filter(function(el){
    var t=clean(el.textContent);
    return visible(el) &&
      viewportBottom(el) &&
      t.indexOf(label)!==-1 &&
      t.length<45;
  });

  return partial.length ? partial[partial.length-1] : null;
}

function hrefOf(el,fallback){
  if(!el) return fallback;
  return el.getAttribute('href') || el.dataset.href || fallback;
}

function getBottomBar(home,cats,acct){
  if(!home || !cats || !acct) return null;

  var p=home.parentElement;

  for(var depth=0;depth<7 && p && p!==document.body;depth++,p=p.parentElement){
    if(p.contains(cats) && p.contains(acct)){
      var r=p.getBoundingClientRect();
      if(r.height>=45 && r.height<=120 && r.width>=260 && viewportBottom(p)){
        return p;
      }
    }
  }

  return null;
}

function addStyle(){
  if(document.getElementById(STYLE_ID)) return;

  var s=document.createElement('style');
  s.id=STYLE_ID;
  s.textContent=`

@media(max-width:767px){

  html{
    --barah-bottom-nav-h:66px;
  }

  body{
    padding-bottom:var(--barah-bottom-nav-h)!important;
  }

  .barah-v51-original-bottom-hidden{
    display:none!important;
  }

  #${NAV_ID}{
    position:fixed!important;
    left:50%!important;
    bottom:0!important;
    transform:translateX(-50%)!important;
    z-index:2147483000!important;

    width:min(100%,430px)!important;
    height:66px!important;

    display:grid!important;
    grid-template-columns:repeat(4,minmax(0,1fr))!important;
    align-items:stretch!important;

    background:#fff!important;
    border-top:1px solid #ece7e3!important;
    box-shadow:0 -6px 20px rgba(0,0,0,.08)!important;
    border-radius:14px 14px 0 0!important;

    padding:0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)!important;
    box-sizing:border-box!important;
    direction:rtl!important;
  }

  #${NAV_ID} .barah-v51-item{
    position:relative!important;
    min-width:0!important;

    display:flex!important;
    flex-direction:column!important;
    align-items:center!important;
    justify-content:center!important;
    gap:4px!important;

    padding:7px 2px 6px!important;
    margin:0!important;

    color:#111827!important;
    background:transparent!important;
    border:0!important;
    text-decoration:none!important;

    font-family:inherit!important;
    font-size:13px!important;
    line-height:1.15!important;
    box-sizing:border-box!important;
  }

  #${NAV_ID} .barah-v51-item svg{
    width:21px!important;
    height:21px!important;
    display:block!important;
    fill:none!important;
    stroke:currentColor!important;
    stroke-width:1.7!important;
    stroke-linecap:round!important;
    stroke-linejoin:round!important;
  }

  #${NAV_ID} .barah-v51-label{
    font-size:13px!important;
    line-height:1.15!important;
    white-space:nowrap!important;
  }

  #${NAV_ID} .barah-v51-item.is-active{
    color:#ea580c!important;
    font-weight:700!important;
  }

  #${NAV_ID} .barah-v51-cart-icon{
    position:relative!important;
    display:flex!important;
  }

  #${NAV_ID} .barah-v51-badge{
    position:absolute!important;
    top:-8px!important;
    right:-10px!important;

    min-width:17px!important;
    height:17px!important;
    padding:0 4px!important;

    display:flex!important;
    align-items:center!important;
    justify-content:center!important;

    border-radius:999px!important;
    background:#f97316!important;
    color:#fff!important;
    box-shadow:0 0 0 2px #fff!important;

    font-size:10px!important;
    line-height:1!important;
    font-weight:800!important;
  }

  #${NAV_ID} .barah-v51-cart[data-count="0"] .barah-v51-badge{
    display:none!important;
  }

  #${NAV_ID} .barah-v51-cart.has-items{
    color:#ea580c!important;
  }
}

@media(max-width:390px){
  #${NAV_ID} .barah-v51-item,
  #${NAV_ID} .barah-v51-label{
    font-size:12.5px!important;
  }
}

@media(min-width:768px){
  #${NAV_ID}{
    display:none!important;
  }
}

`;

  (document.head||document.documentElement).appendChild(s);
}

function iconHome(){
  return '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M3 11.5 12 4l9 7.5"></path><path d="M5.5 10.5V20h13v-9.5"></path><path d="M9.5 20v-6h5v6"></path></svg>';
}

function iconCats(){
  return '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 6h11"></path><path d="M9 12h11"></path><path d="M9 18h11"></path><circle cx="4" cy="6" r="1"></circle><circle cx="4" cy="12" r="1"></circle><circle cx="4" cy="18" r="1"></circle></svg>';
}

function iconCart(){
  return '<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="9" cy="20" r="1"></circle><circle cx="19" cy="20" r="1"></circle><path d="M3 4h2l2.4 10.2a2 2 0 0 0 2 1.55h7.7a2 2 0 0 0 1.95-1.56L21 7H6"></path></svg>';
}

function iconUser(){
  return '<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="8" r="4"></circle><path d="M4.5 21a7.5 7.5 0 0 1 15 0"></path></svg>';
}

function item(href,label,icon,extra){
  var a=document.createElement('a');
  a.href=href;
  a.className='barah-v51-item'+(extra?' '+extra:'');
  a.innerHTML=icon+'<span class="barah-v51-label">'+label+'</span>';
  return a;
}

function cartCount(){
  var selectors=[
    '[data-cart-count]',
    '.cart-count',
    '.s-cart-summary-count',
    'salla-cart-summary [class*="count"]',
    '[class*="header"] [class*="cart"] [class*="count"]',
    '[class*="cart"] .badge'
  ];

  for(var i=0;i<selectors.length;i++){
    var els=document.querySelectorAll(selectors[i]);

    for(var j=0;j<els.length;j++){
      if(els[j].closest('#'+NAV_ID)) continue;

      var raw=els[j].getAttribute('data-cart-count') || els[j].textContent || '';
      var m=String(raw).match(/\d+/);

      if(m){
        var n=parseInt(m[0],10);
        if(Number.isFinite(n)) return n;
      }
    }
  }

  return 0;
}

function updateCart(){
  var cart=document.querySelector('#'+NAV_ID+' .barah-v51-cart');
  if(!cart) return;

  var n=Math.max(0,cartCount()||0);

  cart.setAttribute('data-count',String(n));
  cart.classList.toggle('has-items',n>0);

  var badge=cart.querySelector('.barah-v51-badge');
  if(badge) badge.textContent=n>99?'99+':String(n);
}

function setActive(nav){
  var path=String(location.pathname||'');

  Array.prototype.slice.call(nav.querySelectorAll('.barah-v51-item')).forEach(function(a){
    a.classList.remove('is-active');
  });

  var target=null;

  if(/\/cart(?:\/|$)/i.test(path)){
    target=nav.querySelector('.barah-v51-cart');
  }else if(/\/login|\/profile|\/account/i.test(path)){
    target=nav.querySelector('.barah-v51-account');
  }else if(/\/categories|\/category|\/c\d+/i.test(path)){
    target=nav.querySelector('.barah-v51-categories');
  }else{
    target=nav.querySelector('.barah-v51-home');
  }

  if(target) target.classList.add('is-active');
}

function build(){
  if(!isMobile()) return false;

  addStyle();

  var home=findLink('الرئيسية');
  var cats=findLink('فئات المنتجات');
  var acct=findLink('تسجيل الدخول') || findLink('حسابي');

  if(!home || !cats || !acct) return false;

  var original=getBottomBar(home,cats,acct);
  if(!original) return false;

  var homeHref=hrefOf(home,'/ar');
  var catsHref=hrefOf(cats,'/ar/categories');
  var acctHref=hrefOf(acct,'/ar/login');

  original.classList.add('barah-v51-original-bottom-hidden');

  var old=document.getElementById('barah-mobile-bottom-cart-v49');
  if(old) old.remove();

  var old2=document.getElementById('barah-mobile-bottom-cart-v50');
  if(old2) old2.remove();

  var nav=document.getElementById(NAV_ID);

  if(!nav){
    nav=document.createElement('nav');
    nav.id=NAV_ID;
    nav.setAttribute('aria-label','التنقل السريع');

    var homeItem=item(homeHref,'الرئيسية',iconHome(),'barah-v51-home');
    var catsItem=item(catsHref,'فئات المنتجات',iconCats(),'barah-v51-categories');

    var cartItem=item('/ar/cart','السلة',iconCart(),'barah-v51-cart');
    cartItem.setAttribute('data-count','0');
    var cartIcon=cartItem.querySelector('svg');
    var wrap=document.createElement('span');
    wrap.className='barah-v51-cart-icon';
    cartIcon.parentNode.insertBefore(wrap,cartIcon);
    wrap.appendChild(cartIcon);

    var badge=document.createElement('span');
    badge.className='barah-v51-badge';
    badge.textContent='0';
    wrap.appendChild(badge);

    var accountItem=item(acctHref,'حسابي',iconUser(),'barah-v51-account');

    nav.appendChild(homeItem);
    nav.appendChild(catsItem);
    nav.appendChild(cartItem);
    nav.appendChild(accountItem);

    document.body.appendChild(nav);
  }

  setActive(nav);
  updateCart();

  return true;
}

function run(){
  build();
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}

window.addEventListener('load',function(){
  setTimeout(run,80);
},{once:true});

[100,250,500,900,1500,2500,4500,7000].forEach(function(ms){
  setTimeout(function(){
    run();
    updateCart();
  },ms);
});

[
  'salla::cart.updated',
  'salla::cart::updated',
  'cart.updated',
  'cart::updated',
  'salla-cart-updated',
  'salla::cart.added',
  'salla::cart.deleted'
].forEach(function(name){
  document.addEventListener(name,function(){
    setTimeout(updateCart,70);
    setTimeout(updateCart,300);
  },true);
});

if(window.MutationObserver){
  var timer;
  new MutationObserver(function(){
    if(!isMobile()) return;
    clearTimeout(timer);
    timer=setTimeout(function(){
      run();
      updateCart();
    },100);
  }).observe(document.documentElement,{childList:true,subtree:true});
}

})();


/* ============================================================
BARAH V64.8 — MOBILE CART NATIVE TRIGGER FIX V5.2
ONLY CHANGE:
- Bottom-nav cart no longer navigates to /ar/cart.
- It triggers Salla's original/native header cart control instead.
- Prevents "store closed" page caused by direct cart route in preview/theme.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_MOBILE_NATIVE_CART_V52__) return;
window.__BARAH_MOBILE_NATIVE_CART_V52__=true;

var NAV_ID='barah-mobile-bottom-nav-v51';

function visible(el){
  if(!el) return false;
  var s=getComputedStyle(el);
  if(s.display==='none' || s.visibility==='hidden' || Number(s.opacity)===0) return false;
  var r=el.getBoundingClientRect();
  return r.width>8 && r.height>8;
}

function findNativeCartTrigger(){
  var selectors=[
    'salla-cart-summary',
    'salla-cart-summary a',
    'salla-cart-summary button',
    '[data-cart-summary]',
    '[data-cart]',
    '.header-cart',
    '.header-cart a',
    '.header-cart button',
    'a[href*="/cart"]',
    'button[aria-label*="السلة"]',
    'a[aria-label*="السلة"]',
    'button[title*="السلة"]',
    'a[title*="السلة"]',
    '[class*="cart"] button',
    '[class*="cart"] a'
  ];

  var candidates=[];

  selectors.forEach(function(sel){
    try{
      document.querySelectorAll(sel).forEach(function(el){
        if(!el) return;
        if(el.closest('#'+NAV_ID)) return;
        if(el.id==='barah-mobile-bottom-cart-v49') return;
        if(el.id==='barah-mobile-bottom-cart-v50') return;
        if(!visible(el)) return;

        var r=el.getBoundingClientRect();

        /* Prefer header/native cart controls near top of viewport */
        var score=0;
        if(r.top>=0 && r.top<180) score+=100;
        if(el.closest('header')) score+=80;
        if(el.tagName==='SALLA-CART-SUMMARY') score+=70;
        if(/cart/i.test(el.className||'')) score+=20;
        if((el.getAttribute('aria-label')||'').indexOf('السلة')!==-1) score+=30;

        candidates.push({el:el,score:score});
      });
    }catch(_){}
  });

  if(!candidates.length) return null;

  candidates.sort(function(a,b){return b.score-a.score;});
  return candidates[0].el;
}

function openNativeCart(){
  var trigger=findNativeCartTrigger();

  if(trigger){
    /*
      Some web components listen on their host, others on inner button/link.
      Dispatch a real bubbling click first.
    */
    try{
      trigger.dispatchEvent(new MouseEvent('click',{
        bubbles:true,
        cancelable:true,
        view:window
      }));
      return true;
    }catch(_){}

    try{
      trigger.click();
      return true;
    }catch(_){}
  }

  /*
    Last fallback: try Salla cart API if available.
    Do not navigate to /cart directly.
  */
  try{
    if(window.salla && salla.cart){
      if(typeof salla.cart.open==='function'){
        salla.cart.open();
        return true;
      }
      if(typeof salla.cart.show==='function'){
        salla.cart.show();
        return true;
      }
    }
  }catch(_){}

  return false;
}

function patchBottomCart(){
  var nav=document.getElementById(NAV_ID);
  if(!nav) return false;

  var cart=nav.querySelector('.barah-v51-cart');
  if(!cart) return false;

  cart.setAttribute('href','#');
  cart.setAttribute('role','button');
  cart.setAttribute('aria-label','فتح السلة');
  cart.setAttribute('data-barah-native-cart','1');

  return true;
}

document.addEventListener('click',function(e){
  var cart=e.target && e.target.closest
    ? e.target.closest('#'+NAV_ID+' .barah-v51-cart')
    : null;

  if(!cart) return;

  e.preventDefault();
  e.stopPropagation();

  openNativeCart();
},true);

function run(){
  patchBottomCart();
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}

window.addEventListener('load',function(){
  setTimeout(run,80);
},{once:true});

[150,400,900,1800,3500,6000].forEach(function(ms){
  setTimeout(run,ms);
});

if(window.MutationObserver){
  var timer;
  new MutationObserver(function(){
    clearTimeout(timer);
    timer=setTimeout(run,80);
  }).observe(document.documentElement,{childList:true,subtree:true});
}

})();


/* ============================================================
BARAH V64.8 — MOBILE NATIVE ACCOUNT TRIGGER V5.3
ONLY CHANGE:
- Bottom-nav "حسابي" no longer navigates to a direct account/login route.
- It triggers Salla's original/native header account/login control.
- Same strategy already used for the cart.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_MOBILE_NATIVE_ACCOUNT_V53__) return;
window.__BARAH_MOBILE_NATIVE_ACCOUNT_V53__=true;

var NAV_ID='barah-mobile-bottom-nav-v51';

function visible(el){
  if(!el) return false;
  var s=getComputedStyle(el);
  if(s.display==='none' || s.visibility==='hidden' || Number(s.opacity)===0) return false;
  var r=el.getBoundingClientRect();
  return r.width>8 && r.height>8;
}

function findNativeAccountTrigger(){
  var selectors=[
    'a[href*="/login"]',
    'a[href*="/profile"]',
    'a[href*="/account"]',
    'button[aria-label*="تسجيل الدخول"]',
    'a[aria-label*="تسجيل الدخول"]',
    'button[aria-label*="حسابي"]',
    'a[aria-label*="حسابي"]',
    'button[title*="تسجيل الدخول"]',
    'a[title*="تسجيل الدخول"]',
    '[class*="user"] a',
    '[class*="user"] button',
    '[class*="account"] a',
    '[class*="account"] button',
    '[class*="login"] a',
    '[class*="login"] button'
  ];

  var candidates=[];

  selectors.forEach(function(sel){
    try{
      document.querySelectorAll(sel).forEach(function(el){
        if(!el) return;
        if(el.closest('#'+NAV_ID)) return;
        if(!visible(el)) return;

        var r=el.getBoundingClientRect();
        var t=String(el.textContent||'').replace(/\s+/g,' ').trim();
        var href=String(el.getAttribute('href')||'');
        var score=0;

        if(r.top>=0 && r.top<180) score+=100;
        if(el.closest('header')) score+=80;
        if(t.indexOf('تسجيل الدخول')!==-1 || t.indexOf('حسابي')!==-1) score+=50;
        if(/\/login|\/profile|\/account/i.test(href)) score+=30;
        if(/user|account|login/i.test(el.className||'')) score+=20;

        candidates.push({el:el,score:score});
      });
    }catch(_){}
  });

  if(!candidates.length) return null;

  candidates.sort(function(a,b){return b.score-a.score;});
  return candidates[0].el;
}

function openNativeAccount(){
  var trigger=findNativeAccountTrigger();

  if(trigger){
    try{
      trigger.dispatchEvent(new MouseEvent('click',{
        bubbles:true,
        cancelable:true,
        view:window
      }));
      return true;
    }catch(_){}

    try{
      trigger.click();
      return true;
    }catch(_){}
  }

  return false;
}

function patchBottomAccount(){
  var nav=document.getElementById(NAV_ID);
  if(!nav) return false;

  var account=nav.querySelector('.barah-v51-account');
  if(!account) return false;

  account.setAttribute('href','#');
  account.setAttribute('role','button');
  account.setAttribute('aria-label','فتح الحساب');
  account.setAttribute('data-barah-native-account','1');

  return true;
}

document.addEventListener('click',function(e){
  var account=e.target && e.target.closest
    ? e.target.closest('#'+NAV_ID+' .barah-v51-account')
    : null;

  if(!account) return;

  e.preventDefault();
  e.stopPropagation();

  openNativeAccount();
},true);

function run(){
  patchBottomAccount();
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}

window.addEventListener('load',function(){
  setTimeout(run,80);
},{once:true});

[150,400,900,1800,3500,6000].forEach(function(ms){
  setTimeout(run,ms);
});

if(window.MutationObserver){
  var timer;
  new MutationObserver(function(){
    clearTimeout(timer);
    timer=setTimeout(run,80);
  }).observe(document.documentElement,{childList:true,subtree:true});
}

})();


/* ============================================================
BARAH V64.8 — MOBILE BOTTOM NAV NATIVE LINK SYNC V5.4
FIX:
- Do NOT swallow clicks on Cart / Account.
- Copy the real href/action target from Salla's native header controls.
- If no href exists, click the actual inner native control.
- Visual bottom nav remains exactly the same.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_MOBILE_NATIVE_LINK_SYNC_V54__) return;
window.__BARAH_MOBILE_NATIVE_LINK_SYNC_V54__=true;

var NAV_ID='barah-mobile-bottom-nav-v51';

function clean(v){
  return String(v||'').replace(/\s+/g,' ').trim();
}

function visible(el){
  if(!el) return false;
  var s=getComputedStyle(el);
  if(s.display==='none' || s.visibility==='hidden' || Number(s.opacity)===0) return false;
  var r=el.getBoundingClientRect();
  return r.width>8 && r.height>8;
}

function scoreTop(el){
  var r=el.getBoundingClientRect();
  var score=0;
  if(r.top>=0 && r.top<180) score+=100;
  if(el.closest('header')) score+=100;
  return score;
}

function firstUsefulHref(el){
  if(!el) return '';

  var candidates=[];

  if(el.matches && el.matches('a[href]')) candidates.push(el);
  if(el.querySelectorAll){
    el.querySelectorAll('a[href]').forEach(function(a){candidates.push(a);});
  }

  for(var i=0;i<candidates.length;i++){
    var href=String(candidates[i].getAttribute('href')||'').trim();
    if(
      href &&
      href!=='#' &&
      href!=='#!' &&
      !/^javascript:/i.test(href)
    ){
      return href;
    }
  }

  return '';
}

function nativeCartControl(){
  var selectors=[
    'header salla-cart-summary',
    'header [data-cart-summary]',
    'header .header-cart',
    'header [class*="cart"]',
    'salla-cart-summary',
    '[data-cart-summary]',
    '.header-cart'
  ];

  var candidates=[];

  selectors.forEach(function(sel){
    try{
      document.querySelectorAll(sel).forEach(function(el){
        if(el.closest('#'+NAV_ID)) return;
        if(!visible(el)) return;

        var score=scoreTop(el);
        var t=clean(el.textContent);
        var aria=String(el.getAttribute('aria-label')||'');

        if(/السلة|cart/i.test(t+' '+aria+' '+(el.className||''))) score+=60;
        if(el.tagName==='SALLA-CART-SUMMARY') score+=80;

        candidates.push({el:el,score:score});
      });
    }catch(_){}
  });

  candidates.sort(function(a,b){return b.score-a.score;});
  return candidates.length ? candidates[0].el : null;
}

function nativeAccountControl(){
  var selectors=[
    'header a[href*="/login"]',
    'header a[href*="/profile"]',
    'header a[href*="/account"]',
    'header [class*="user"]',
    'header [class*="account"]',
    'header [class*="login"]',
    'a[href*="/login"]',
    'a[href*="/profile"]',
    'a[href*="/account"]'
  ];

  var candidates=[];

  selectors.forEach(function(sel){
    try{
      document.querySelectorAll(sel).forEach(function(el){
        if(el.closest('#'+NAV_ID)) return;
        if(!visible(el)) return;

        var score=scoreTop(el);
        var t=clean(el.textContent);
        var aria=String(el.getAttribute('aria-label')||'');

        if(/تسجيل الدخول|حسابي|login|account|profile/i.test(t+' '+aria+' '+(el.className||''))) score+=70;

        candidates.push({el:el,score:score});
      });
    }catch(_){}
  });

  candidates.sort(function(a,b){return b.score-a.score;});
  return candidates.length ? candidates[0].el : null;
}

function deepestClickable(el){
  if(!el) return null;

  var found=el.querySelector && el.querySelector(
    'a[href],button,[role="button"],salla-button'
  );

  return found || el;
}

function syncTargets(){
  var nav=document.getElementById(NAV_ID);
  if(!nav) return false;

  var cart=nav.querySelector('.barah-v51-cart');
  var account=nav.querySelector('.barah-v51-account');

  if(cart){
    var nc=nativeCartControl();
    var ch=firstUsefulHref(nc);

    if(ch){
      cart.setAttribute('href',ch);
      cart.dataset.barahNativeMode='href';
    }else{
      cart.setAttribute('href','#');
      cart.dataset.barahNativeMode='click';
    }
  }

  if(account){
    var na=nativeAccountControl();
    var ah=firstUsefulHref(na);

    if(ah){
      account.setAttribute('href',ah);
      account.dataset.barahNativeMode='href';
    }else{
      account.setAttribute('href','#');
      account.dataset.barahNativeMode='click';
    }
  }

  return true;
}

/*
Run AFTER the previous V5.2/V5.3 capture handlers.
Capture listener below only intercepts when no real href was found.
*/
document.addEventListener('click',function(e){

  var nav=document.getElementById(NAV_ID);
  if(!nav) return;

  var cart=e.target && e.target.closest
    ? e.target.closest('#'+NAV_ID+' .barah-v51-cart')
    : null;

  if(cart){
    syncTargets();

    if(cart.dataset.barahNativeMode==='href'){
      /*
       Previous V5.2 installed a capture handler that prevents default.
       We therefore navigate explicitly using the real native href.
      */
      e.preventDefault();
      e.stopImmediatePropagation();

      var href=cart.getAttribute('href');
      if(href && href!=='#'){
        window.location.assign(href);
      }
      return;
    }

    e.preventDefault();
    e.stopImmediatePropagation();

    var nc=nativeCartControl();
    var clickable=deepestClickable(nc);

    if(clickable){
      try{ clickable.click(); }catch(_){}
    }
    return;
  }

  var account=e.target && e.target.closest
    ? e.target.closest('#'+NAV_ID+' .barah-v51-account')
    : null;

  if(account){
    syncTargets();

    if(account.dataset.barahNativeMode==='href'){
      e.preventDefault();
      e.stopImmediatePropagation();

      var ahref=account.getAttribute('href');
      if(ahref && ahref!=='#'){
        window.location.assign(ahref);
      }
      return;
    }

    e.preventDefault();
    e.stopImmediatePropagation();

    var na=nativeAccountControl();
    var aclick=deepestClickable(na);

    if(aclick){
      try{ aclick.click(); }catch(_){}
    }
  }

},true);

function run(){
  syncTargets();
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}

window.addEventListener('load',function(){
  setTimeout(run,100);
},{once:true});

[150,400,900,1800,3500,6000].forEach(function(ms){
  setTimeout(run,ms);
});

if(window.MutationObserver){
  var timer;
  new MutationObserver(function(){
    clearTimeout(timer);
    timer=setTimeout(run,100);
  }).observe(document.documentElement,{childList:true,subtree:true});
}

})();


/* ============================================================
BARAH V64.8 — MOBILE BOTTOM NAV REMOVE ACCOUNT V5.4A
TEMPORARY STABLE MODE:
- Remove "حسابي" from mobile bottom navigation.
- Keep Cart behavior untouched.
- Balance remaining 3 items equally.
- Desktop untouched.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_MOBILE_REMOVE_ACCOUNT_V54A__) return;
window.__BARAH_MOBILE_REMOVE_ACCOUNT_V54A__=true;

var NAV_ID='barah-mobile-bottom-nav-v51';
var STYLE_ID='barah-mobile-remove-account-v54a-style';

function addStyle(){
  if(document.getElementById(STYLE_ID)) return;

  var s=document.createElement('style');
  s.id=STYLE_ID;
  s.textContent=`

@media(max-width:767px){

  #${NAV_ID}{
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
  }

  #${NAV_ID} .barah-v51-account{
    display:none!important;
  }

  #${NAV_ID} > *{
    min-width:0!important;
  }
}

`;

  (document.head||document.documentElement).appendChild(s);
}

function run(){
  var nav=document.getElementById(NAV_ID);
  if(!nav) return false;

  addStyle();

  var account=nav.querySelector('.barah-v51-account');
  if(account){
    account.remove();
  }

  nav.style.setProperty(
    'grid-template-columns',
    'repeat(3,minmax(0,1fr))',
    'important'
  );

  return true;
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}

window.addEventListener('load',function(){
  setTimeout(run,80);
},{once:true});

[150,400,900,1800,3500].forEach(function(ms){
  setTimeout(run,ms);
});

if(window.MutationObserver){
  var timer;
  new MutationObserver(function(){
    clearTimeout(timer);
    timer=setTimeout(run,80);
  }).observe(document.documentElement,{childList:true,subtree:true});
}

})();


/* BARAH V65.9: obsolete same-path sort navigation removed */
/* ============================================================
BARAH V64.8 — PRODUCT BUNDLE RESTORE V5.4E
RESTORED FROM PRIOR BARAH BUNDLE ENGINE
IDs:
- #barah-product-bundle
- #barah-bundle-products

BEHAVIOR:
- Product pages only
- Detect current product category
- Load best-selling products from same category
- Exclude current product
- Remove duplicates
- Show up to 3 products
- Append bundle inside full product description
- Does NOT touch homepage / cart / bottom nav
============================================================ */
(function(){
'use strict';

if(window.__BARAH_PRODUCT_BUNDLE_RESTORE_V54E__) return;
window.__BARAH_PRODUCT_BUNDLE_RESTORE_V54E__=true;

var CONFIG={
  FETCH_LIMIT:10,
  SHOW_LIMIT:3,
  RETRY_DELAY:500,
  RETRY_MAX:24,
  BUNDLE_ID:'barah-product-bundle',
  CONTAINER_ID:'barah-bundle-products',
  STYLE_ID:'barah-product-bundle-v54e-style'
};

function getSalla(){
  return window.salla || window.Salla || null;
}

function normalizeText(value){
  return String(value||'')
    .replace(/\s+/g,' ')
    .replace(/ـ/g,'')
    .trim()
    .toLowerCase();
}

function isProductPage(){
  var slug='';

  try{
    var sdk=getSalla();
    if(sdk && sdk.config && typeof sdk.config.get==='function'){
      slug=sdk.config.get('page.slug')||'';
    }
  }catch(_){}

  return (
    slug==='product.single' ||
    document.body.classList.contains('product-single') ||
    document.body.classList.contains('product-page') ||
    /\/p\d+(?:\/|$|\?)/i.test(location.pathname||'')
  );
}

function currentProductId(){
  var match=String(location.pathname||'').match(/\/p(\d+)/i);
  if(match) return String(match[1]);

  var page=document.querySelector(
    '.page--product-details[data-product-id],[data-product-id].product-single'
  );

  if(page && page.getAttribute('data-product-id')){
    return String(page.getAttribute('data-product-id'));
  }

  return '';
}

function getCategoryName(){
  var meta=document.querySelector('meta[property="product:category"]');

  if(meta && meta.getAttribute('content')){
    return String(meta.getAttribute('content')).trim();
  }

  var currentId=currentProductId();

  if(Array.isArray(window.dataLayer)){
    for(var i=window.dataLayer.length-1;i>=0;i--){
      var entry=window.dataLayer[i];

      if(
        !entry ||
        typeof entry!=='object' ||
        !entry.ecommerce ||
        !entry.ecommerce.detail ||
        !Array.isArray(entry.ecommerce.detail.products)
      ){
        continue;
      }

      var products=entry.ecommerce.detail.products;

      for(var j=0;j<products.length;j++){
        var product=products[j];
        if(!product) continue;

        if(
          currentId &&
          product.id &&
          String(product.id)!==String(currentId)
        ){
          continue;
        }

        if(Array.isArray(product.categories) && product.categories.length){
          var category=product.categories[product.categories.length-1];
          if(category && category.name){
            return String(category.name).trim();
          }
        }

        if(product.category){
          return String(product.category).trim();
        }
      }
    }
  }

  return '';
}

function getRealCategory(){
  var categoryName=getCategoryName();
  if(!categoryName) return null;

  var wanted=normalizeText(categoryName);
  var links=document.querySelectorAll('a[href*="/c"]');
  var exact=[];
  var partial=[];

  Array.prototype.forEach.call(links,function(link){
    var href=link.getAttribute('href') || link.href || '';
    var match=String(href).match(/\/c(\d+)(?:\/|$|\?|#)/i);
    if(!match) return;

    var label=normalizeText(link.textContent);
    if(!label) return;

    var item={
      id:String(match[1]),
      name:categoryName,
      url:href
    };

    if(label===wanted){
      exact.push(item);
      return;
    }

    if(label.indexOf(wanted)!==-1 || wanted.indexOf(label)!==-1){
      partial.push(item);
    }
  });

  if(exact.length) return exact[0];
  if(partial.length) return partial[0];

  var existing=document.getElementById(CONFIG.BUNDLE_ID);
  if(existing){
    var stored=existing.getAttribute('data-category-id');
    if(stored){
      return {
        id:String(stored),
        name:categoryName,
        url:''
      };
    }
  }

  return null;
}

function addStyle(){
  if(document.getElementById(CONFIG.STYLE_ID)) return;

  var style=document.createElement('style');
  style.id=CONFIG.STYLE_ID;
  style.textContent=`

#${CONFIG.BUNDLE_ID}{
  direction:rtl;
  margin:28px 0 8px;
  padding:18px;
  border:1px solid rgba(249,115,22,.18);
  border-radius:18px;
  background:linear-gradient(180deg,#fffdfb 0%,#fff8f3 100%);
  box-sizing:border-box;
}

#${CONFIG.BUNDLE_ID} .barah-bundle-head{
  margin-bottom:14px;
}

#${CONFIG.BUNDLE_ID} .barah-bundle-kicker{
  display:inline-flex;
  align-items:center;
  min-height:26px;
  padding:4px 9px;
  margin-bottom:7px;
  border-radius:999px;
  background:#fff1e8;
  color:#c2410c;
  font-size:12px;
  font-weight:700;
}

#${CONFIG.BUNDLE_ID} .barah-bundle-head h3{
  margin:0 0 5px;
  color:#111827;
  font-size:22px;
  line-height:1.35;
  font-weight:800;
}

#${CONFIG.BUNDLE_ID} .barah-bundle-head p{
  margin:0;
  color:#6b7280;
  font-size:13px;
  line-height:1.7;
}

#${CONFIG.CONTAINER_ID}{
  min-height:120px;
}

#${CONFIG.CONTAINER_ID} salla-products-list{
  display:block;
}

@media(max-width:767px){
  #${CONFIG.BUNDLE_ID}{
    margin:22px 0 6px;
    padding:14px;
    border-radius:16px;
  }

  #${CONFIG.BUNDLE_ID} .barah-bundle-head h3{
    font-size:19px;
  }

  #${CONFIG.BUNDLE_ID} .barah-bundle-head p{
    font-size:12.5px;
  }

  #${CONFIG.BUNDLE_ID} .barah-bundle-kicker{
    font-size:11.5px;
  }
}
`;

  (document.head||document.documentElement).appendChild(style);
}

function createBundleShell(category){
  var existing=document.getElementById(CONFIG.BUNDLE_ID);

  if(existing){
    existing.style.removeProperty('display');
    existing.setAttribute('data-category-id',category.id);
    existing.setAttribute('data-current-product-id',currentProductId());

    var kicker=existing.querySelector('.barah-bundle-kicker');
    if(kicker) kicker.textContent='منتجات إضافية قد تناسب احتياجك';

    var title=existing.querySelector('.barah-bundle-head h3');
    if(title) title.textContent='👌 اختيارات تكمل طلبك';

    var paragraph=existing.querySelector('.barah-bundle-head p');
    if(paragraph){
      paragraph.textContent='اكتشف خيارات أخرى من نفس القسم.';
    }

    return existing;
  }

  var section=document.createElement('section');
  section.id=CONFIG.BUNDLE_ID;
  section.className='barah-product-bundle';
  section.setAttribute('data-category-id',category.id);
  section.setAttribute('data-current-product-id',currentProductId());

  section.innerHTML=
    '<div class="barah-bundle-head">'+
      '<span class="barah-bundle-kicker">منتجات إضافية قد تناسب احتياجك</span>'+
      '<h3>👌 اختيارات تكمل طلبك</h3>'+
      '<p>اكتشف خيارات أخرى من نفس القسم.</p>'+
    '</div>'+
    '<div id="'+CONFIG.CONTAINER_ID+'" class="barah-bundle-products" aria-live="polite"></div>';

  var description=document.querySelector(
    'article.pd-exp,'+
    '.article--product-details.pd-exp,'+
    '.product-description,'+
    '[class*="product-description"]'
  );

  if(!description) return null;

  /* Recommendations go directly AFTER the full description. */
  var descriptionBlock=description.closest('section.product-description, section.product-details-description') || description;
  descriptionBlock.insertAdjacentElement('afterend',section);
  return section;
}

function buildSallaBundle(container,category){
  if(!window.customElements) return false;

  var signature=category.id+':'+currentProductId();

  if(container.dataset.barahSignature===signature){
    return true;
  }

  container.dataset.barahSignature=signature;
  container.innerHTML='';

  var list=document.createElement('salla-products-list');
  list.setAttribute('source','categories');
  list.setAttribute('source-value',JSON.stringify([Number(category.id)]));
  list.setAttribute('limit',String(CONFIG.FETCH_LIMIT));
  list.setAttribute('sort-by','bestSell');

  container.appendChild(list);
  watchBundle(container);

  return true;
}

function getBundleCards(container){
  var selectors=[
    'salla-product-card',
    'custom-salla-product-card',
    '.s-product-card-entry',
    '.product-block',
    '.product-item'
  ];

  for(var i=0;i<selectors.length;i++){
    var cards=Array.prototype.slice.call(container.querySelectorAll(selectors[i]));
    if(cards.length) return cards;
  }

  return [];
}

function getCardURL(card){
  var link=card.querySelector('a[href*="/p"]');
  return link ? (link.href || link.getAttribute('href') || '') : '';
}

function getCardProductId(card){
  var id=card.getAttribute('data-product-id');

  if(id) return String(id);

  if(card.dataset && card.dataset.productId){
    return String(card.dataset.productId);
  }

  var url=getCardURL(card);
  var match=String(url).match(/\/p(\d+)/i);

  return match ? String(match[1]) : '';
}

function filterBundle(container){
  var currentId=currentProductId();
  var cards=getBundleCards(container);

  if(!cards.length) return;

  var seen={};
  var shown=0;

  cards.forEach(function(card){
    var cardId=getCardProductId(card);
    var url=getCardURL(card);
    var canonical=String(url||'').split(/[?#]/)[0].replace(/\/$/,'');
    var key=cardId || canonical;

    var isCurrent=
      (currentId && cardId===currentId) ||
      (currentId && String(url).indexOf('/p'+currentId)!==-1);

    var duplicate=key && seen[key];
    if(key) seen[key]=true;

    if(isCurrent || duplicate){
      if(card.style.display!=='none') card.style.setProperty('display','none','important');
      return;
    }

    if(shown<CONFIG.SHOW_LIMIT){
      if(card.style.display==='none') card.style.removeProperty('display');
      shown++;
    }else{
      card.style.setProperty('display','none','important');
    }
  });
}

function watchBundle(container){
  filterBundle(container);

  if(window.MutationObserver){
    var timer;

    new MutationObserver(function(){
      clearTimeout(timer);
      timer=setTimeout(function(){
        filterBundle(container);
      },100);
    }).observe(container,{
      childList:true,
      subtree:true
    });
  }

  var tries=0;
  var retry=setInterval(function(){
    tries++;
    filterBundle(container);

    if(tries>=CONFIG.RETRY_MAX){
      clearInterval(retry);
    }
  },CONFIG.RETRY_DELAY);
}

function initBundle(){
  if(!isProductPage()) return false;

  addStyle();

  var category=getRealCategory();
  if(!category || !category.id) return false;

  var bundle=createBundleShell(category);
  if(!bundle) return false;

  var container=bundle.querySelector('#'+CONFIG.CONTAINER_ID);
  if(!container) return false;

  return buildSallaBundle(container,category);
}

function run(){
  if(!isProductPage()) return;

  initBundle();
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}

window.addEventListener('load',function(){
  setTimeout(run,120);
},{once:true});

/* Salla product content may hydrate late */
[250,700,1400,2600,5000,8000].forEach(function(ms){
  setTimeout(run,ms);
});

})();


/* ============================================================
BARAH V64.8 — MOBILE FOOTER SPACE COMPACT V5.4F
ONLY MOBILE FOOTER SPACING:
- Reduce excess vertical whitespace after contact section
- Bring VAT line closer to payment logos
- Lift payment strip upward
- Keep links, logos, sizes, bottom nav untouched
============================================================ */
(function(){
'use strict';

if(window.__BARAH_MOBILE_FOOTER_SPACE_V54F__) return;
window.__BARAH_MOBILE_FOOTER_SPACE_V54F__=true;

var STYLE_ID='barah-mobile-footer-space-v54f-style';

function addStyle(){
  if(document.getElementById(STYLE_ID)) return;

  var s=document.createElement('style');
  s.id=STYLE_ID;
  s.textContent=`

@media(max-width:767px){

  footer{
    padding-bottom:74px!important;
  }

  /* Contact block -> less dead space below */
  footer .barah-contact-section,
  footer [class*="contact"],
  footer [class*="footer-contact"]{
    margin-bottom:10px!important;
    padding-bottom:8px!important;
  }

  /* Generic separators inside footer: reduce long vertical gaps */
  footer hr{
    margin-top:14px!important;
    margin-bottom:12px!important;
  }

  /* VAT area tighter */
  footer [class*="vat"],
  footer [class*="tax"],
  footer .barah-vat,
  footer .barah-tax-number{
    margin-top:8px!important;
    margin-bottom:5px!important;
  }

  /* Payment strip already rebuilt in V4.8 — pull it upward */
  footer #barah-payment-strip-v48{
    margin-top:4px!important;
    margin-bottom:8px!important;
  }

  /* If original wrapper remains around tax/payment area, compact it */
  footer .barah-pay-v48-old,
  footer [class*="payment"],
  footer [class*="payments"]{
    margin-top:0!important;
    margin-bottom:0!important;
  }

  /* Reduce blank area before copyright when present */
  footer [class*="copyright"],
  footer .copyrights,
  footer .store-footer__copyright{
    margin-top:8px!important;
    padding-top:8px!important;
  }
}

@media(max-width:390px){
  footer{
    padding-bottom:70px!important;
  }

  footer #barah-payment-strip-v48{
    margin-top:2px!important;
    margin-bottom:6px!important;
  }
}

`;

  (document.head||document.documentElement).appendChild(s);
}

function run(){
  addStyle();
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}

window.addEventListener('load',run,{once:true});

})();


/* ============================================================
BARAH V64.8 — MOBILE FOOTER LOWER GAP FIX V5.4G
ONLY MOBILE:
- Remove the large inherited blank gap between contact info
  and VAT/payment/copyright area.
- Keep links, logo sizes, payment strip and bottom nav unchanged.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_MOBILE_FOOTER_LOWER_GAP_V54G__) return;
window.__BARAH_MOBILE_FOOTER_LOWER_GAP_V54G__=true;

var STYLE_ID='barah-mobile-footer-lower-gap-v54g-style';

function clean(v){
  return String(v||'').replace(/\s+/g,' ').trim();
}

function addStyle(){
  if(document.getElementById(STYLE_ID)) return;

  var s=document.createElement('style');
  s.id=STYLE_ID;
  s.textContent=`

@media(max-width:767px){

  footer .barah-v54g-lower-zone{
    min-height:0!important;
    height:auto!important;
    padding-top:10px!important;
    padding-bottom:8px!important;
    margin-top:8px!important;
    margin-bottom:0!important;
  }

  footer .barah-v54g-lower-zone > *{
    min-height:0!important;
  }

  footer .barah-v54g-tax-line{
    margin-top:0!important;
    margin-bottom:6px!important;
    padding-top:0!important;
    padding-bottom:0!important;
    min-height:0!important;
  }

  footer #barah-payment-strip-v48{
    margin-top:4px!important;
    margin-bottom:8px!important;
  }

  footer .barah-v54g-rights-line{
    margin-top:6px!important;
    padding-top:8px!important;
  }
}

`;

  (document.head||document.documentElement).appendChild(s);
}

function closestReasonableWrapper(el,footer){
  if(!el) return null;

  var p=el.parentElement;

  for(var i=0;i<5 && p && p!==footer;i++,p=p.parentElement){
    var r=p.getBoundingClientRect();

    if(r.height>0 && r.height<320){
      return p;
    }
  }

  return el.parentElement;
}

function mark(){
  var footer=document.querySelector('footer');
  if(!footer) return false;

  var nodes=Array.prototype.slice.call(
    footer.querySelectorAll('div,p,span,section')
  );

  var tax=nodes.find(function(el){
    return clean(el.textContent).indexOf('الرقم الضريبي')!==-1;
  });

  var rights=nodes.find(function(el){
    var t=clean(el.textContent);
    return (
      t.indexOf('جميع الحقوق محفوظة')!==-1 ||
      t.indexOf('BARAH STORE')!==-1
    );
  });

  if(tax){
    tax.classList.add('barah-v54g-tax-line');

    var zone=closestReasonableWrapper(tax,footer);

    if(zone){
      zone.classList.add('barah-v54g-lower-zone');

      /*
        Kill inline/min-height spacing only on this lower footer zone.
      */
      zone.style.setProperty('min-height','0','important');
      zone.style.setProperty('height','auto','important');
      zone.style.setProperty('padding-top','10px','important');
      zone.style.setProperty('padding-bottom','8px','important');
      zone.style.setProperty('margin-top','8px','important');
      zone.style.setProperty('margin-bottom','0','important');
    }
  }

  if(rights){
    rights.classList.add('barah-v54g-rights-line');
  }

  return !!tax;
}

function run(){
  addStyle();
  mark();
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}

window.addEventListener('load',function(){
  setTimeout(run,80);
},{once:true});

[150,400,900,1800,3500].forEach(function(ms){
  setTimeout(run,ms);
});

if(window.MutationObserver){
  var timer;
  new MutationObserver(function(){
    clearTimeout(timer);
    timer=setTimeout(run,100);
  }).observe(document.documentElement,{childList:true,subtree:true});
}

})();


/* ============================================================
BARAH V64.8 — MOBILE FOOTER SAFE GAP TRIM V5.4J
CSS/CLASS ONLY — NO DOM MOVING
- Tighten only the VAT/payment lower footer zone.
- Keep links, contact block, logos, copyright and bottom nav untouched.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_MOBILE_FOOTER_SAFE_GAP_V54J__) return;
window.__BARAH_MOBILE_FOOTER_SAFE_GAP_V54J__=true;

var STYLE_ID='barah-mobile-footer-safe-gap-v54j-style';

function clean(v){
  return String(v||'').replace(/\s+/g,' ').trim();
}

function isMobile(){
  return !!(window.matchMedia && window.matchMedia('(max-width:767px)').matches);
}

function addStyle(){
  if(document.getElementById(STYLE_ID)) return;

  var s=document.createElement('style');
  s.id=STYLE_ID;
  s.textContent=`

@media(max-width:767px){

  footer .barah-v54j-tax-parent{
    margin-top:-62px!important;
    padding-top:0!important;
    min-height:0!important;
    height:auto!important;
  }

  footer .barah-v54j-tax-parent > *{
    min-height:0!important;
  }

  footer .barah-v54j-tax-line{
    margin-top:0!important;
    margin-bottom:6px!important;
    padding-top:0!important;
    padding-bottom:0!important;
  }

  footer #barah-payment-strip-v48{
    margin-top:2px!important;
    margin-bottom:7px!important;
  }
}

@media(max-width:390px){
  footer .barah-v54j-tax-parent{
    margin-top:-56px!important;
  }
}

`;

  (document.head||document.documentElement).appendChild(s);
}

function mark(){
  if(!isMobile()) return false;

  var footer=document.querySelector('footer');
  if(!footer) return false;

  var nodes=Array.prototype.slice.call(
    footer.querySelectorAll('div,p,span,section')
  );

  var tax=nodes.find(function(el){
    var t=clean(el.textContent);
    return t.indexOf('الرقم الضريبي')!==-1 && t.length<80;
  });

  if(!tax) return false;

  tax.classList.add('barah-v54j-tax-line');

  /*
    Mark only the immediate visual wrapper.
    No moving, cloning or removing nodes.
  */
  var p=tax.parentElement;
  if(p && p!==footer){
    p.classList.add('barah-v54j-tax-parent');
  }

  return true;
}

function run(){
  addStyle();
  mark();
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}

window.addEventListener('load',function(){
  setTimeout(run,80);
},{once:true});

[150,400,900,1800,3500].forEach(function(ms){
  setTimeout(run,ms);
});

if(window.MutationObserver){
  var timer;
  new MutationObserver(function(){
    if(!isMobile()) return;
    clearTimeout(timer);
    timer=setTimeout(run,100);
  }).observe(document.documentElement,{childList:true,subtree:true});
}

})();


/* ============================================================
BARAH V64.8 — FOOTER EXACT DOM FIX V5.4L
Built from inspected live footer DOM.
ROOT CAUSE FIX:
- Undo V5.4G/V5.4J classes when they landed on footer/root container.
- Target only Salla's real .footer__mid VAT/payment row.
- No DOM moving. No transforms. No negative positioning.
- Mobile only.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_FOOTER_EXACT_DOM_V54L__) return;
window.__BARAH_FOOTER_EXACT_DOM_V54L__=true;

var STYLE_ID='barah-footer-exact-dom-v54l-style';

function isMobile(){
  return !!(window.matchMedia && window.matchMedia('(max-width:767px)').matches);
}

function addStyle(){
  if(document.getElementById(STYLE_ID)) return;

  var s=document.createElement('style');
  s.id=STYLE_ID;
  s.textContent=`

@media(max-width:767px){

  /* ---------------------------------------------------------
     RESET THE TWO OVER-BROAD PREVIOUS TARGETS
     --------------------------------------------------------- */
  footer.barah-v54g-lower-zone{
    min-height:0!important;
    height:auto!important;
    margin-top:0!important;
    margin-bottom:0!important;
    padding-top:0!important;
    padding-bottom:72px!important;
  }

  footer > .container.barah-v54j-tax-parent{
    margin-top:0!important;
    padding-top:0!important;
    min-height:0!important;
    height:auto!important;
  }

  /*
    Do not let generic VAT classes turn the whole footer container
    into a centered VAT line.
  */
  footer > .container.barah-v45-vat-line,
  footer > .container.barah-v54g-tax-line,
  footer > .container.barah-v54j-tax-line{
    width:100%!important;
    text-align:initial!important;
    margin:0 auto!important;
    font-size:inherit!important;
    line-height:inherit!important;
  }

  /* ---------------------------------------------------------
     TOP FOOTER: KEEP NORMAL RHYTHM
     --------------------------------------------------------- */
  footer .footer__top{
    margin:0!important;
    padding:18px 0 10px!important;
    min-height:0!important;
    height:auto!important;
  }

  footer .footer__top > .row{
    margin-bottom:0!important;
    padding-bottom:0!important;
  }

  /* ---------------------------------------------------------
     EXACT LOWER ROW: VAT / CERTIFICATE
     --------------------------------------------------------- */
  footer .footer__mid{
    width:100%!important;
    min-height:0!important;
    height:auto!important;
    margin:0!important;
    padding:8px 0 4px!important;
  }

  footer .footer__mid > .row{
    margin:0!important;
    padding:0!important;
    min-height:0!important;
    height:auto!important;
    align-items:center!important;
  }

  /* Empty app-links column is unnecessary on mobile */
  footer .footer__mid .col-md-4.col-sm-12:has(.app-links:empty){
    display:none!important;
  }

  footer .footer__mid .col-md-8.col-sm-12{
    width:100%!important;
    max-width:100%!important;
    flex:0 0 100%!important;
    padding:0 12px!important;
    margin:0!important;
  }

  footer .footer__mid .payment-methods-wrap{
    margin:0!important;
    padding:0!important;
    min-height:0!important;
    height:auto!important;
  }

  footer .footer__mid .store-certificate{
    width:100%!important;
    min-height:0!important;
    height:auto!important;
    margin:0 auto 4px!important;
    padding:0!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    gap:7px!important;
  }

  footer .footer__mid .store-certificate__text{
    width:auto!important;
    margin:0!important;
    padding:0!important;
    display:inline-flex!important;
    align-items:center!important;
    justify-content:center!important;
    gap:5px!important;
    font-size:11px!important;
    line-height:1.45!important;
    text-align:center!important;
  }

  footer .footer__mid .tax-certificate{
    margin:0!important;
    padding:0!important;
    flex:0 0 auto!important;
  }

  footer .footer__mid .tax-certificate img{
    width:20px!important;
    height:20px!important;
    object-fit:contain!important;
    margin:0!important;
  }

  /* Old payment list stays hidden; V4.8 strip is the visual source */
  footer .footer__mid .footer-list--payment-methods{
    margin:0!important;
    padding:0!important;
    min-height:0!important;
  }

  /* ---------------------------------------------------------
     INDEPENDENT V4.8 PAYMENT STRIP
     --------------------------------------------------------- */
  footer #barah-payment-strip-v48{
    margin:5px auto 8px!important;
  }

  /* ---------------------------------------------------------
     COPYRIGHT
     --------------------------------------------------------- */
  footer .footer__bottom{
    margin:0!important;
    padding:10px 0 8px!important;
    min-height:0!important;
    height:auto!important;
  }

  footer .footer__bottom p{
    margin:0!important;
  }
}

@media(max-width:390px){
  footer .footer__top{
    padding-top:15px!important;
    padding-bottom:8px!important;
  }

  footer .footer__mid{
    padding-top:6px!important;
  }

  footer #barah-payment-strip-v48{
    margin-top:4px!important;
  }
}

`;

  (document.head||document.documentElement).appendChild(s);
}

function repairWrongMarks(){
  if(!isMobile()) return;

  var footer=document.querySelector('footer');
  if(!footer) return;

  /*
    Earlier code selected ancestors by textContent.
    Remove those marker classes only from structural root nodes.
    Keep the real inner VAT nodes untouched.
  */
  footer.classList.remove('barah-v54g-lower-zone');

  footer.style.removeProperty('min-height');
  footer.style.removeProperty('height');
  footer.style.removeProperty('padding-top');
  footer.style.removeProperty('padding-bottom');
  footer.style.removeProperty('margin-top');
  footer.style.removeProperty('margin-bottom');

  var root=footer.querySelector(':scope > .container');
  if(root){
    root.classList.remove(
      'barah-v54j-tax-parent',
      'barah-v54g-tax-line',
      'barah-v54j-tax-line',
      'barah-v45-vat-line'
    );

    root.style.removeProperty('margin-top');
    root.style.removeProperty('min-height');
    root.style.removeProperty('height');
    root.style.removeProperty('padding-top');
    root.style.removeProperty('padding-bottom');
  }

  /*
    Remove wrong VAT marker from broad ancestors above footer__mid.
  */
  var mid=footer.querySelector('.footer__mid');
  if(mid){
    var p=mid.parentElement;
    while(p && p!==footer){
      if(p===root) break;
      p.classList.remove(
        'barah-v54j-tax-parent',
        'barah-v54g-tax-line',
        'barah-v54j-tax-line'
      );
      p=p.parentElement;
    }
  }
}

function run(){
  addStyle();
  repairWrongMarks();
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}

window.addEventListener('load',function(){
  setTimeout(run,80);
},{once:true});

[120,300,700,1400,2600,4500].forEach(function(ms){
  setTimeout(run,ms);
});

if(window.MutationObserver){
  var timer;
  new MutationObserver(function(){
    if(!isMobile()) return;
    clearTimeout(timer);
    timer=setTimeout(run,100);
  }).observe(document.documentElement,{childList:true,subtree:true});
}

})();


/* BARAH V65.9: obsolete same-path sort navigation removed */
/* ============================================================
BARAH V64.8 — DESKTOP PAYMENT SAFE DEDUPE V5.4O
DESKTOP ONLY
ROOT FIX:
- Do NOT hide Salla's original payment list before V4.8 builds its strip.
- First wait for #barah-payment-strip-v48.
- Only then hide the original payment list.
- If custom strip never appears, original logos remain visible but compact.
- Mobile untouched.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_DESKTOP_PAYMENT_SAFE_V54O__) return;
window.__BARAH_DESKTOP_PAYMENT_SAFE_V54O__=true;

var STYLE_ID='barah-desktop-payment-safe-v54o-style';
var READY_CLASS='barah-desktop-pay-v54o-ready';

function isDesktop(){
  return !!(window.matchMedia && window.matchMedia('(min-width:768px)').matches);
}

function addStyle(){
  if(document.getElementById(STYLE_ID)) return;

  var s=document.createElement('style');
  s.id=STYLE_ID;
  s.textContent=`

@media(min-width:768px){

  /* ---------------------------------------------------------
     SAFE FALLBACK:
     Until custom strip exists, keep native list visible but compact.
     --------------------------------------------------------- */
  footer .footer-list--payment-methods{
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    flex-wrap:wrap!important;
    gap:6px!important;
    width:auto!important;
    max-width:560px!important;
    margin:8px auto!important;
    padding:0!important;
    min-height:0!important;
    height:auto!important;
  }

  footer .footer-list--payment-methods > li{
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    width:auto!important;
    min-width:44px!important;
    height:30px!important;
    margin:0!important;
    padding:4px 7px!important;
    border:1px solid #edf0f2!important;
    border-radius:7px!important;
    background:#fff!important;
    box-sizing:border-box!important;
  }

  footer .footer-list--payment-methods > li img{
    display:block!important;
    width:auto!important;
    height:auto!important;
    max-width:46px!important;
    max-height:20px!important;
    margin:0!important;
    padding:0!important;
    object-fit:contain!important;
    transform:none!important;
  }

  /* Keep known broken wallet placeholders hidden */
  footer .footer-list--payment-methods > li.barah-v45-pay-hide,
  footer .footer-list--payment-methods > li.barah-payment-broken-v31{
    display:none!important;
  }

  /* ---------------------------------------------------------
     ONCE V4.8 STRIP EXISTS:
     hide ONLY the native source list.
     --------------------------------------------------------- */
  html.${READY_CLASS} footer .footer-list--payment-methods{
    display:none!important;
  }

  /* Custom compact strip stays visible */
  footer #barah-payment-strip-v48{
    display:flex!important;
    visibility:visible!important;
    opacity:1!important;
    align-items:center!important;
    justify-content:center!important;
    flex-wrap:wrap!important;
    gap:6px!important;
    width:max-content!important;
    max-width:100%!important;
    min-height:30px!important;
    height:auto!important;
    margin:8px auto 10px!important;
    padding:0!important;
    overflow:visible!important;
  }

  footer #barah-payment-strip-v48 .barah-pay-v48-item{
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    width:auto!important;
    min-width:44px!important;
    height:30px!important;
    padding:4px 7px!important;
    margin:0!important;
    border:1px solid #edf0f2!important;
    border-radius:7px!important;
    background:#fff!important;
    box-sizing:border-box!important;
  }

  footer #barah-payment-strip-v48 .barah-pay-v48-item img{
    display:block!important;
    width:auto!important;
    height:auto!important;
    max-width:46px!important;
    max-height:20px!important;
    margin:0!important;
    padding:0!important;
    object-fit:contain!important;
    transform:none!important;
  }

  /* Tax certificate must never expand */
  footer .store-certificate img,
  footer .tax-certificate img{
    width:auto!important;
    height:auto!important;
    max-width:24px!important;
    max-height:24px!important;
    object-fit:contain!important;
  }
}

`;

  (document.head||document.documentElement).appendChild(s);
}

function sync(){
  if(!isDesktop()){
    document.documentElement.classList.remove(READY_CLASS);
    return false;
  }

  var footer=document.querySelector('footer');
  if(!footer) return false;

  var strip=footer.querySelector('#barah-payment-strip-v48');

  /*
    Only declare ready when the custom strip REALLY contains payment images.
  */
  var ready=!!(
    strip &&
    strip.querySelectorAll('.barah-pay-v48-item img, img').length>=2
  );

  document.documentElement.classList.toggle(READY_CLASS,ready);

  return ready;
}

function run(){
  addStyle();
  sync();
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}

window.addEventListener('load',function(){
  setTimeout(run,100);
},{once:true});

/*
  V4.8 may build the custom strip after footer hydration.
*/
[120,300,700,1200,2200,4000,6500].forEach(function(ms){
  setTimeout(sync,ms);
});

if(window.MutationObserver){
  var timer;
  new MutationObserver(function(){
    clearTimeout(timer);
    timer=setTimeout(sync,100);
  }).observe(document.documentElement,{
    childList:true,
    subtree:true
  });
}

})();


/* ============================================================
BARAH V64.8 — MOBILE VIEW & BUY CTA V5.4P
MOBILE ONLY
- Replace icon-only card action with a clear text CTA: "عرض وشراء".
- CTA links to the product page.
- Hide the tiny icon-only cart trigger on mobile product cards.
- No effect on desktop or the product page main actions.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_MOBILE_VIEW_BUY_V54P__) return;
window.__BARAH_MOBILE_VIEW_BUY_V54P__=true;

var STYLE_ID='barah-mobile-view-buy-v54p-style';

function isMobile(){
  return !!(window.matchMedia && window.matchMedia('(max-width:767px)').matches);
}

function addStyle(){
  if(document.getElementById(STYLE_ID)) return;

  var s=document.createElement('style');
  s.id=STYLE_ID;
  s.textContent=`

@media(max-width:767px){

  /* Our CTA */
  .barah-v54p-view-buy{
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    width:100%!important;
    min-height:36px!important;
    height:36px!important;
    margin:8px 0 0!important;
    padding:0 12px!important;
    border-radius:12px!important;
    background:#111!important;
    color:#fff!important;
    font-size:13px!important;
    font-weight:800!important;
    line-height:1!important;
    text-decoration:none!important;
    box-sizing:border-box!important;
    letter-spacing:0!important;
  }

  .barah-v54p-view-buy:hover,
  .barah-v54p-view-buy:focus,
  .barah-v54p-view-buy:active{
    color:#fff!important;
    text-decoration:none!important;
    opacity:.96!important;
  }

  /* Hide icon-only card action when our CTA is active */
  .barah-v54p-card .barah-v54p-hide-action{
    display:none!important;
  }

  /* Give action area room */
  .barah-v54p-card .barah-v54p-action-slot{
    width:100%!important;
    margin-top:auto!important;
  }

  /* Keep card body flexy if supported */
  .barah-v54p-card .product-block__content,
  .barah-v54p-card .product-block__info,
  .barah-v54p-card [class*="content"],
  .barah-v54p-card [class*="info"]{
    display:flex!important;
    flex-direction:column!important;
  }

  /* Make sure our CTA does not touch PDP buttons */
  body.is-page-product .barah-v54p-view-buy,
  body.product-single .barah-v54p-view-buy{
    display:none!important;
  }
}

`;

  (document.head||document.documentElement).appendChild(s);
}

function productUrlFromCard(card){
  var anchors = Array.prototype.slice.call(
    card.querySelectorAll('a[href]')
  );

  var found = anchors.find(function(a){
    var h = a.getAttribute('href') || '';
    return /\/product[-/]|\/p\d+|\/p\//.test(h) && !/^#/.test(h);
  });

  if(found) return found.href;

  found = anchors.find(function(a){
    var h = a.getAttribute('href') || '';
    return !/^#/.test(h) && !/cart|login|register|account|sort=/.test(h);
  });

  return found ? found.href : '';
}

function findActionButton(card){
  var selectors = [
    '.btn--add-to-cart',
    '[class*="add-to-cart"]',
    '[data-testid*="add"]',
    'button[aria-label*="سل"]',
    'button[aria-label*="cart"]',
    'button',
    'salla-add-product-button',
    'salla-button'
  ].join(',');

  var list = Array.prototype.slice.call(card.querySelectorAll(selectors));

  return list.find(function(el){
    if(el.closest('.barah-v54p-action-slot')) return false;
    if(el.closest('form[action*="cart"]')) return true;

    var txt = String(el.textContent || '').trim();
    var cls = String(el.className || '');
    var aria = String(el.getAttribute('aria-label') || '');

    return (
      /cart|add|سلة|أضف/.test(txt + ' ' + cls + ' ' + aria) ||
      el.querySelector('i,svg')
    );
  }) || null;
}

function actionHost(card, actionBtn){
  var host = actionBtn && actionBtn.parentElement ? actionBtn.parentElement : null;

  if(host && host.childElementCount <= 3) return host;

  return actionBtn || card;
}

function eligibleCard(card){
  if(!card || card.dataset.barahV54pDone === '1') return false;
  if(card.closest('footer, header, .cart, .checkout, #barah-product-bundle')) return false;

  var txt = String(card.textContent || '').trim();
  if(!txt) return false;

  var hasImage = !!card.querySelector('img');
  return hasImage;
}

function applyToCard(card){
  if(!eligibleCard(card)) return false;

  var url = productUrlFromCard(card);
  if(!url) return false;

  var actionBtn = findActionButton(card);
  if(!actionBtn) return false;

  var host = actionHost(card, actionBtn);

  card.classList.add('barah-v54p-card');
  actionBtn.classList.add('barah-v54p-hide-action');

  var slot = host.querySelector(':scope > .barah-v54p-action-slot');
  if(!slot){
    slot = document.createElement('div');
    slot.className = 'barah-v54p-action-slot';
    host.appendChild(slot);
  }

  var link = slot.querySelector(':scope > a.barah-v54p-view-buy');
  if(!link){
    link = document.createElement('a');
    link.className = 'barah-v54p-view-buy';
    link.textContent = 'عرض وشراء';
    slot.appendChild(link);
  }

  link.href = url;
  link.target = '_self';
  link.rel = '';

  card.dataset.barahV54pDone = '1';
  return true;
}

function scan(){
  if(!isMobile()) return;

  var cards = Array.prototype.slice.call(
    document.querySelectorAll(
      'main custom-salla-product-card, main custom-salla-product-card.product-block, main product-card, main .product-block'
    )
  );

  cards.forEach(applyToCard);
}

function run(){
  addStyle();
  scan();
}

if(document.readyState === 'loading'){
  document.addEventListener('DOMContentLoaded', run, {once:true});
}else{
  run();
}

window.addEventListener('load', function(){
  setTimeout(run, 120);
}, {once:true});

[250,700,1500,3000,5000].forEach(function(ms){
  setTimeout(scan, ms);
});

if(window.MutationObserver){
  var timer;
  new MutationObserver(function(){
    clearTimeout(timer);
    timer = setTimeout(scan, 120);
  }).observe(document.documentElement, {
    childList:true,
    subtree:true
  });
}

})();


/* ============================================================
BARAH V64.8 — MOBILE PRODUCT CARD COMPACT V5.4Q
MOBILE LISTING PAGES ONLY
- Smaller, cleaner product cards for search/category/product listings.
- Keep 2-column layout.
- Do not affect homepage custom sections, product page, or desktop.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_MOBILE_CARD_COMPACT_V54Q__) return;
window.__BARAH_MOBILE_CARD_COMPACT_V54Q__=true;

var STYLE_ID='barah-mobile-card-compact-v54q-style';

function addStyle(){
  if(document.getElementById(STYLE_ID)) return;

  var s=document.createElement('style');
  s.id=STYLE_ID;
  s.textContent=`

@media(max-width:767px){

  /* Listing grid only */
  main .products-list-container,
  main salla-infinite-scroll.products-list-container{
    gap:10px!important;
  }

  main .products-list-container .product-block,
  main salla-infinite-scroll.products-list-container .product-block{
    min-height:0!important;
    border-radius:13px!important;
    overflow:hidden!important;
  }

  /* Image area */
  main .products-list-container .product-block__thumb,
  main salla-infinite-scroll.products-list-container .product-block__thumb{
    min-height:0!important;
    height:auto!important;
    aspect-ratio:1/1!important;
    overflow:hidden!important;
  }

  main .products-list-container .product-block__thumb img,
  main salla-infinite-scroll.products-list-container .product-block__thumb img{
    width:100%!important;
    height:100%!important;
    max-height:170px!important;
    object-fit:contain!important;
    padding:5px!important;
  }

  /* Card body */
  main .products-list-container .product-block__info,
  main salla-infinite-scroll.products-list-container .product-block__info{
    padding:8px 9px 5px!important;
  }

  main .products-list-container .product-title,
  main salla-infinite-scroll.products-list-container .product-title{
    margin:0!important;
  }

  main .products-list-container .product-title h2,
  main .products-list-container .product-title h3,
  main salla-infinite-scroll.products-list-container .product-title h2,
  main salla-infinite-scroll.products-list-container .product-title h3{
    min-height:38px!important;
    margin:0 0 4px!important;
    font-size:12px!important;
    line-height:1.45!important;
    font-weight:700!important;

    display:-webkit-box!important;
    -webkit-line-clamp:2!important;
    -webkit-box-orient:vertical!important;
    overflow:hidden!important;
  }

  main .products-list-container .product-title p,
  main salla-infinite-scroll.products-list-container .product-title p{
    margin:0 0 5px!important;
    min-height:30px!important;
    max-height:30px!important;
    font-size:10.5px!important;
    line-height:1.4!important;
    color:#8a8a8a!important;

    display:-webkit-box!important;
    -webkit-line-clamp:2!important;
    -webkit-box-orient:vertical!important;
    overflow:hidden!important;
  }

  /* Price */
  main .products-list-container .price-wrapper,
  main salla-infinite-scroll.products-list-container .price-wrapper{
    margin-top:3px!important;
    min-height:22px!important;
  }

  main .products-list-container .price-wrapper span,
  main salla-infinite-scroll.products-list-container .price-wrapper span{
    font-size:12px!important;
  }

  main .products-list-container .price-wrapper small,
  main salla-infinite-scroll.products-list-container .price-wrapper small{
    font-size:10px!important;
  }

  /* Our View & Buy CTA */
  main .products-list-container .barah-v54p-view-buy,
  main salla-infinite-scroll.products-list-container .barah-v54p-view-buy{
    min-height:32px!important;
    height:32px!important;
    margin-top:6px!important;
    padding:0 9px!important;
    border-radius:10px!important;
    font-size:12px!important;
  }

  /* Card spacing */
  main .products-list-container .wide,
  main salla-infinite-scroll.products-list-container .wide{
    padding-bottom:6px!important;
  }
}

@media(max-width:390px){

  main .products-list-container,
  main salla-infinite-scroll.products-list-container{
    gap:8px!important;
  }

  main .products-list-container .product-block__thumb img,
  main salla-infinite-scroll.products-list-container .product-block__thumb img{
    max-height:158px!important;
  }

  main .products-list-container .product-title h2,
  main .products-list-container .product-title h3,
  main salla-infinite-scroll.products-list-container .product-title h2,
  main salla-infinite-scroll.products-list-container .product-title h3{
    font-size:11.5px!important;
  }

  main .products-list-container .product-title p,
  main salla-infinite-scroll.products-list-container .product-title p{
    font-size:10px!important;
  }
}

`;

  (document.head||document.documentElement).appendChild(s);
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',addStyle,{once:true});
}else{
  addStyle();
}

window.addEventListener('load',addStyle,{once:true});

})();


/* ============================================================
BARAH V64.8 — MOBILE PRODUCT CARD ULTRA COMPACT V5.4R
MOBILE LISTING PAGES ONLY
- Hide card description on mobile
- Title limited to 2 lines
- Smaller image area
- Keep price + "عرض وشراء" fixed and compact
- No effect on homepage custom cards, product page, or desktop
============================================================ */
(function(){
'use strict';

if(window.__BARAH_MOBILE_CARD_ULTRA_V54R__) return;
window.__BARAH_MOBILE_CARD_ULTRA_V54R__=true;

var STYLE_ID='barah-mobile-card-ultra-v54r-style';

function addStyle(){
  if(document.getElementById(STYLE_ID)) return;

  var s=document.createElement('style');
  s.id=STYLE_ID;
  s.textContent=`

@media(max-width:767px){

  /* Only normal listing/search/category grids */
  main .products-list-container .product-block,
  main salla-infinite-scroll.products-list-container .product-block{
    min-height:0!important;
    height:auto!important;
    border-radius:12px!important;
    overflow:hidden!important;
  }

  /* Image: shorter and cleaner */
  main .products-list-container .product-block__thumb,
  main salla-infinite-scroll.products-list-container .product-block__thumb{
    aspect-ratio:auto!important;
    height:142px!important;
    min-height:142px!important;
    max-height:142px!important;
    overflow:hidden!important;
    background:#fff!important;
  }

  main .products-list-container .product-block__thumb img,
  main salla-infinite-scroll.products-list-container .product-block__thumb img{
    width:100%!important;
    height:100%!important;
    max-height:none!important;
    object-fit:contain!important;
    padding:4px!important;
  }

  /* Body tighter */
  main .products-list-container .product-block__info,
  main salla-infinite-scroll.products-list-container .product-block__info{
    padding:7px 8px 4px!important;
  }

  /* Title exactly 2 lines */
  main .products-list-container .product-title h2,
  main .products-list-container .product-title h3,
  main salla-infinite-scroll.products-list-container .product-title h2,
  main salla-infinite-scroll.products-list-container .product-title h3{
    min-height:36px!important;
    max-height:36px!important;
    margin:0 0 4px!important;
    font-size:11.8px!important;
    line-height:1.52!important;
    font-weight:750!important;

    display:-webkit-box!important;
    -webkit-line-clamp:2!important;
    -webkit-box-orient:vertical!important;
    overflow:hidden!important;
  }

  /* Hide description entirely on mobile listing cards */
  main .products-list-container .product-title p,
  main salla-infinite-scroll.products-list-container .product-title p{
    display:none!important;
  }

  /* Price area */
  main .products-list-container .price-wrapper,
  main salla-infinite-scroll.products-list-container .price-wrapper{
    min-height:20px!important;
    margin:2px 0 0!important;
    padding:0!important;
    display:flex!important;
    align-items:center!important;
    gap:4px!important;
  }

  main .products-list-container .price-wrapper span,
  main salla-infinite-scroll.products-list-container .price-wrapper span{
    font-size:11.8px!important;
    line-height:1!important;
  }

  main .products-list-container .price-wrapper small,
  main salla-infinite-scroll.products-list-container .price-wrapper small{
    font-size:9.8px!important;
    line-height:1!important;
  }

  /* Keep CTA compact and anchored */
  main .products-list-container .barah-v54p-action-slot,
  main salla-infinite-scroll.products-list-container .barah-v54p-action-slot{
    margin-top:auto!important;
    padding:0 7px 7px!important;
  }

  main .products-list-container .barah-v54p-view-buy,
  main salla-infinite-scroll.products-list-container .barah-v54p-view-buy{
    min-height:30px!important;
    height:30px!important;
    margin:5px 0 0!important;
    border-radius:9px!important;
    font-size:11.5px!important;
  }

  /* Reduce card footer/wrapper padding */
  main .products-list-container .wide,
  main salla-infinite-scroll.products-list-container .wide{
    padding-bottom:0!important;
  }
}

@media(max-width:390px){

  main .products-list-container .product-block__thumb,
  main salla-infinite-scroll.products-list-container .product-block__thumb{
    height:136px!important;
    min-height:136px!important;
    max-height:136px!important;
  }

  main .products-list-container .product-title h2,
  main .products-list-container .product-title h3,
  main salla-infinite-scroll.products-list-container .product-title h2,
  main salla-infinite-scroll.products-list-container .product-title h3{
    font-size:11.3px!important;
  }

  main .products-list-container .barah-v54p-view-buy,
  main salla-infinite-scroll.products-list-container .barah-v54p-view-buy{
    height:29px!important;
    min-height:29px!important;
    font-size:11px!important;
  }
}

`;

  (document.head||document.documentElement).appendChild(s);
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',addStyle,{once:true});
}else{
  addStyle();
}

window.addEventListener('load',addStyle,{once:true});

})();


/* ============================================================
BARAH V64.8 — MOBILE LISTING CARD HARD FIX V5.4S
MOBILE CATEGORY / SEARCH / LISTING PAGES ONLY
- Robustly targets Salla .product-block cards.
- Hide description.
- Clamp title to 2 lines.
- Reduce image/card height.
- Replace icon-only action with "عرض وشراء".
- Homepage custom sections and desktop are excluded.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_MOBILE_LISTING_HARD_FIX_V54S__) return;
window.__BARAH_MOBILE_LISTING_HARD_FIX_V54S__=true;

var STYLE_ID='barah-mobile-listing-hard-fix-v54s-style';

function isMobile(){
  return !!(window.matchMedia && window.matchMedia('(max-width:767px)').matches);
}

function isListingPage(){
  var body=document.body;
  if(!body) return false;

  var p=String(location.pathname||'');
  var qs=String(location.search||'');

  /* Home is excluded */
  if(
    body.classList.contains('index') ||
    p==='/' || p==='/ar' || p==='/en' ||
    (location.hostname==='salla.sa' && /^\/br1\/?$/.test(p) && !qs)
  ){
    return false;
  }

  /* Category / search / product-list style pages */
  return (
    /\/c\d+(?:\/|$|\?)/i.test(p) ||
    /\/search/i.test(p) ||
    /[?&](q|sort|page)=/i.test(qs) ||
    !!document.querySelector('main .product-block')
  );
}

function addStyle(){
  if(document.getElementById(STYLE_ID)) return;

  var s=document.createElement('style');
  s.id=STYLE_ID;
  s.textContent=`

@media(max-width:767px){

  html[data-barah-v54s-listing="1"] main .product-block{
    min-height:0!important;
    height:auto!important;
    border-radius:12px!important;
    overflow:hidden!important;
  }

  html[data-barah-v54s-listing="1"] main .product-block__thumb{
    height:138px!important;
    min-height:138px!important;
    max-height:138px!important;
    aspect-ratio:auto!important;
    overflow:hidden!important;
    background:#fff!important;
  }

  html[data-barah-v54s-listing="1"] main .product-block__thumb .thumb-wrapper{
    display:block!important;
    width:100%!important;
    height:100%!important;
  }

  html[data-barah-v54s-listing="1"] main .product-block__thumb img{
    width:100%!important;
    height:100%!important;
    max-height:none!important;
    object-fit:contain!important;
    padding:4px!important;
    margin:0!important;
  }

  html[data-barah-v54s-listing="1"] main .product-block__info{
    padding:7px 8px 4px!important;
  }

  html[data-barah-v54s-listing="1"] main .product-title{
    margin:0!important;
  }

  html[data-barah-v54s-listing="1"] main .product-title h1,
  html[data-barah-v54s-listing="1"] main .product-title h2,
  html[data-barah-v54s-listing="1"] main .product-title h3,
  html[data-barah-v54s-listing="1"] main .product-title h4{
    min-height:36px!important;
    max-height:36px!important;
    margin:0 0 4px!important;
    font-size:11.8px!important;
    line-height:1.52!important;
    font-weight:750!important;
    display:-webkit-box!important;
    -webkit-line-clamp:2!important;
    -webkit-box-orient:vertical!important;
    overflow:hidden!important;
  }

  html[data-barah-v54s-listing="1"] main .product-title p{
    display:none!important;
  }

  html[data-barah-v54s-listing="1"] main .price-wrapper{
    min-height:20px!important;
    margin:2px 0 0!important;
    padding:0!important;
    display:flex!important;
    align-items:center!important;
    gap:4px!important;
  }

  html[data-barah-v54s-listing="1"] main .price-wrapper span{
    font-size:11.8px!important;
    line-height:1!important;
  }

  html[data-barah-v54s-listing="1"] main .price-wrapper small{
    font-size:9.8px!important;
    line-height:1!important;
  }

  /* Hide original floated/icon-only action */
  html[data-barah-v54s-listing="1"] main .product-block .btn--floated.btn--add-to-cart,
  html[data-barah-v54s-listing="1"] main .product-block .btn--add-to-cart{
    display:none!important;
  }

  /* New text CTA */
  html[data-barah-v54s-listing="1"] main .product-block .barah-v54s-buy{
    display:flex!important;
    width:calc(100% - 14px)!important;
    min-height:30px!important;
    height:30px!important;
    margin:5px 7px 7px!important;
    padding:0 9px!important;
    align-items:center!important;
    justify-content:center!important;
    border-radius:9px!important;
    background:#111!important;
    color:#fff!important;
    text-decoration:none!important;
    font-size:11.5px!important;
    line-height:1!important;
    font-weight:800!important;
    box-sizing:border-box!important;
  }

  html[data-barah-v54s-listing="1"] main .product-block .wide,
  html[data-barah-v54s-listing="1"] main .product-block .donating-wrap{
    padding-bottom:0!important;
  }
}

@media(max-width:390px){
  html[data-barah-v54s-listing="1"] main .product-block__thumb{
    height:132px!important;
    min-height:132px!important;
    max-height:132px!important;
  }

  html[data-barah-v54s-listing="1"] main .product-title h1,
  html[data-barah-v54s-listing="1"] main .product-title h2,
  html[data-barah-v54s-listing="1"] main .product-title h3,
  html[data-barah-v54s-listing="1"] main .product-title h4{
    font-size:11.3px!important;
  }
}

`;

  (document.head||document.documentElement).appendChild(s);
}

function productUrl(card){
  var a=card.querySelector(
    'a.product-title[href],'+
    '.product-block__thumb a[href],'+
    'a.thumb-wrapper[href],'+
    'a[href*="/p"]'
  );
  return a ? (a.href || a.getAttribute('href') || '') : '';
}

function addBuyButton(card){
  if(!card || card.querySelector('.barah-v54s-buy')) return;

  var url=productUrl(card);
  if(!url) return;

  var wrap=card.querySelector('.wide.donating-wrap') ||
           card.querySelector('.donating-wrap') ||
           card.querySelector('.wide') ||
           card;

  var a=document.createElement('a');
  a.className='barah-v54s-buy';
  a.href=url;
  a.target='_self';
  a.textContent='عرض وشراء';

  wrap.appendChild(a);
}

function scan(){
  if(!isMobile() || !isListingPage()){
    document.documentElement.removeAttribute('data-barah-v54s-listing');
    return;
  }

  document.documentElement.setAttribute('data-barah-v54s-listing','1');

  document.querySelectorAll('main .product-block').forEach(function(card){
    /* Explicitly exclude custom homepage/bundle blocks */
    if(card.closest(
      '#barah-step-hero-v12,'+
      '#barah-step-most-viewed,'+
      '#barah-v643-mobile-latest,'+
      '#barah-v647-mobile-most-viewed,'+
      '#barah-product-bundle'
    )) return;

    addBuyButton(card);
  });
}

function run(){
  addStyle();
  scan();
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}

window.addEventListener('load',function(){
  setTimeout(run,100);
},{once:true});

[150,400,900,1800,3200,5000].forEach(function(ms){
  setTimeout(scan,ms);
});

if(window.MutationObserver){
  var timer;
  new MutationObserver(function(){
    clearTimeout(timer);
    timer=setTimeout(scan,100);
  }).observe(document.documentElement,{childList:true,subtree:true});
}

})();


/* ============================================================
BARAH V64.8 — UNIVERSAL VIEW & BUY CTA V5.4T
RESTORED FROM PROVEN BARAH V22/V25/V26 PATTERN

GOAL:
- Permanent "عرض وشراء" CTA on product cards.
- Desktop + mobile.
- Direct link to product details.
- Never inside cart/checkout.
- No duplicates.
- Covers dynamically rendered cards.
- Removes experimental V5.4P/V5.4S CTA duplicates.
- Hides native action ONLY when it is icon-only.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_UNIVERSAL_VIEW_BUY_V54T__) return;
window.__BARAH_UNIVERSAL_VIEW_BUY_V54T__=true;

var STYLE_ID='barah-universal-view-buy-v54t-style';

function clean(v){
  return String(v||'').replace(/\s+/g,' ').trim();
}

function isCartContext(card){
  return !!(
    card &&
    card.closest(
      '.page--cart,'+
      '.cart-details,'+
      '.cart-product-entry,'+
      '.checkout,'+
      '[class*="checkout"]'
    )
  );
}

function getCardURL(card){
  if(!card) return '';

  var anchors=Array.prototype.slice.call(
    card.querySelectorAll('a[href]')
  );

  var preferred=anchors.find(function(a){
    var h=String(a.getAttribute('href')||a.href||'');
    return /\/p\d+(?:\/|$|\?|#)/i.test(h);
  });

  if(preferred) return preferred.href || preferred.getAttribute('href') || '';

  preferred=anchors.find(function(a){
    var h=String(a.getAttribute('href')||a.href||'');
    return (
      /\/product[-/]/i.test(h) &&
      !/cart|checkout|login|account/i.test(h)
    );
  });

  return preferred ? (preferred.href || preferred.getAttribute('href') || '') : '';
}

function addStyle(){
  if(document.getElementById(STYLE_ID)) return;

  var s=document.createElement('style');
  s.id=STYLE_ID;
  s.textContent=`

/* ========== UNIVERSAL CTA ========== */
.barah-card-buy{
  order:99!important;
  display:flex!important;
  align-items:center!important;
  justify-content:center!important;
  width:calc(100% - 20px)!important;
  min-height:42px!important;
  margin:10px!important;
  padding:9px 12px!important;
  border:0!important;
  border-radius:11px!important;
  background:linear-gradient(110deg,#f97316,#ef4444)!important;
  color:#fff!important;
  font-size:13px!important;
  line-height:1.2!important;
  font-weight:800!important;
  text-align:center!important;
  text-decoration:none!important;
  box-sizing:border-box!important;
  box-shadow:0 6px 14px rgba(239,68,68,.12)!important;
  cursor:pointer!important;
}

.barah-card-buy:hover,
.barah-card-buy:focus,
.barah-card-buy:active{
  color:#fff!important;
  text-decoration:none!important;
  opacity:.97!important;
}

/* Hide only actions verified as icon-only */
.barah-card-v54t-has-buy .barah-v54t-icon-only{
  display:none!important;
}

/* Never show universal CTA inside cart/checkout */
.page--cart .barah-card-buy,
.cart-details .barah-card-buy,
.cart-product-entry .barah-card-buy,
.checkout .barah-card-buy,
[class*="checkout"] .barah-card-buy{
  display:none!important;
}

/* Desktop */
@media(min-width:768px){
  .barah-card-buy{
    min-height:40px!important;
    margin:9px 10px 11px!important;
    font-size:13px!important;
    border-radius:10px!important;
  }
}

/* Mobile */
@media(max-width:767px){
  .barah-card-buy{
    min-height:38px!important;
    width:calc(100% - 16px)!important;
    margin:8px!important;
    padding:8px 7px!important;
    font-size:12px!important;
    border-radius:9px!important;
    box-shadow:none!important;
  }
}

@media(max-width:390px){
  .barah-card-buy{
    min-height:37px!important;
    font-size:11.5px!important;
  }
}

`;

  (document.head||document.documentElement).appendChild(s);
}

function removeExperimentalCTA(card){
  if(!card) return;

  card.querySelectorAll(
    '.barah-v54p-view-buy,'+
    '.barah-v54s-buy'
  ).forEach(function(el){
    el.remove();
  });

  card.querySelectorAll('.barah-v54p-action-slot').forEach(function(slot){
    if(!slot.children.length) slot.remove();
  });
}

function markIconOnlyNativeAction(card){
  if(!card) return;

  var candidates=Array.prototype.slice.call(
    card.querySelectorAll(
      'salla-add-product-button,'+
      '.btn--add-to-cart,'+
      '.btn--floated,'+
      '[class*="add-to-cart"],'+
      'button'
    )
  );

  candidates.forEach(function(el){
    if(el.closest('.barah-card-buy')) return;

    var txt=clean(el.textContent);
    var aria=clean(el.getAttribute('aria-label'));
    var title=clean(el.getAttribute('title'));

    var semantic=(txt+' '+aria+' '+title).toLowerCase();

    var hasAddText=
      /أضف|اضف|إضافة|اضافة|add to cart|add/i.test(semantic);

    /*
      Preserve a real text add-to-cart CTA.
      Hide only icon-only action controls.
    */
    if(!hasAddText){
      var hasIcon=!!el.querySelector('i,svg');
      var tiny=el.getBoundingClientRect().width<=90 || !txt;

      if(hasIcon && tiny){
        el.classList.add('barah-v54t-icon-only');
      }
    }
  });
}

function addViewBuyCTA(card){
  if(!card || isCartContext(card)) return false;

  removeExperimentalCTA(card);

  var existing=card.querySelector('.barah-card-buy');

  if(existing){
    existing.textContent='عرض وشراء';
    existing.setAttribute(
      'aria-label',
      'عرض تفاصيل المنتج وإكمال الشراء'
    );

    card.classList.add('barah-card-v54t-has-buy');
    markIconOnlyNativeAction(card);
    return true;
  }

  var url=getCardURL(card);

  if(
    !url ||
    !(/\/p\d+/i.test(url) || /\/product[-/]/i.test(url))
  ){
    return false;
  }

  var button=document.createElement('a');
  button.className='barah-card-buy';
  button.href=url;
  button.target='_self';
  button.textContent='عرض وشراء';
  button.setAttribute(
    'aria-label',
    'عرض تفاصيل المنتج وإكمال الشراء'
  );

  /*
    Append inside the card, same proven pattern used in prior BARAH builds.
    flex/order styling keeps it at the bottom when the card is flex-based.
  */
  card.appendChild(button);

  card.classList.add('barah-card-v54t-has-buy');

  markIconOnlyNativeAction(card);

  return true;
}

function enhanceProductCards(){
  var cards=document.querySelectorAll(
    'salla-product-card,'+
    'custom-salla-product-card,'+
    '.s-product-card-entry,'+
    '.s-product-card,'+
    '.product-block,'+
    '.product-item'
  );

  Array.prototype.forEach.call(cards,function(card){
    /*
      Do not contaminate structural/header/footer contexts.
    */
    if(card.closest('header,footer,.nav-mobile,.side-panel')) return;

    addViewBuyCTA(card);
  });
}

function cleanDuplicates(){
  document.querySelectorAll(
    'salla-product-card,'+
    'custom-salla-product-card,'+
    '.s-product-card-entry,'+
    '.s-product-card,'+
    '.product-block,'+
    '.product-item'
  ).forEach(function(card){
    var buys=card.querySelectorAll('.barah-card-buy');

    if(buys.length>1){
      Array.prototype.slice.call(buys,1).forEach(function(el){
        el.remove();
      });
    }
  });
}

function run(){
  addStyle();
  enhanceProductCards();
  cleanDuplicates();
}

if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',run,{once:true});
}else{
  run();
}

window.addEventListener('load',function(){
  setTimeout(run,100);
},{once:true});

[200,500,1000,1800,3000,5000,8000].forEach(function(ms){
  setTimeout(run,ms);
});

if(window.MutationObserver){
  var timer;

  new MutationObserver(function(){
    clearTimeout(timer);
    timer=setTimeout(run,100);
  }).observe(document.documentElement,{
    childList:true,
    subtree:true
  });
}

})();


/* ============================================================
BARAH V64.8 — HOMEPAGE BUYER JOURNEY ORDER V5.4U
FINAL HOMEPAGE RHYTHM
Buyer-first order:
1) Hero
2) Shipping value
3) Social proof / Most viewed
4) Quick discovery
5) Shop by need
6) Decision shortcut
7) Latest products
8) Pregnancy
9) Senior care
10) Catalog
11) Wholesale
12) Footer

Also:
- Exactly ONE "Most Viewed" representation per viewport.
- Exactly ONE "Latest" representation per viewport.
- Mobile keeps mobile-specialized versions.
- Desktop keeps desktop/native versions.
- No homepage sections are removed permanently; duplicates are hidden.
============================================================ */
(function(){
'use strict';

if(window.__BARAH_HOMEPAGE_BUYER_ORDER_V54U__) return;
window.__BARAH_HOMEPAGE_BUYER_ORDER_V54U__=true;

var STYLE_ID='barah-home-buyer-order-v54u-style';

function isHome(){
  var p=String(location.pathname||'/').replace(/\/+$/,'')||'/';

  return (
    p==='/' ||
    p==='/ar' ||
    p==='/en' ||
    (location.hostname==='salla.sa' && p==='/br1')
  );
}

if(!isHome()) return;

function mobile(){
  return !!(
    window.matchMedia &&
    window.matchMedia('(max-width:767px)').matches
  );
}

function addStyle(){
  if(document.getElementById(STYLE_ID)) return;

  var s=document.createElement('style');
  s.id=STYLE_ID;
  s.textContent=`

/* Duplicate suppression is viewport-aware */
.barah-v54u-duplicate{
  display:none!important;
  visibility:hidden!important;
  height:0!important;
  min-height:0!important;
  max-height:0!important;
  margin:0!important;
  padding:0!important;
  border:0!important;
  overflow:hidden!important;
  pointer-events:none!important;
}

/* Keep a clean, consistent rhythm between buyer-journey blocks */
#barah-step-hero-v12,
#barah-step-shipping-v24,
#barah-step-most-viewed,
#barah-v647-mobile-most-viewed,
#barah-v616-quick-discovery,
#barah-step-needs-v51,
#barah-v617-decision-strip,
section.barah-v35-latest,
#barah-v643-mobile-latest,
#barah-step-pregnancy-v55,
#barah-step-senior-v57,
#barah-step-catalog-v32,
#barah-step-wholesale-v32{
  scroll-margin-top:90px!important;
}

@media(max-width:767px){
  #barah-step-hero-v12,
  #barah-step-shipping-v24,
  #barah-v647-mobile-most-viewed,
  #barah-v616-quick-discovery,
  #barah-step-needs-v51,
  #barah-v617-decision-strip,
  #barah-v643-mobile-latest,
  #barah-step-pregnancy-v55,
  #barah-step-senior-v57,
  #barah-step-catalog-v32,
  #barah-step-wholesale-v32{
    margin-bottom:14px!important;
  }
}

@media(min-width:768px){
  #barah-step-hero-v12,
  #barah-step-shipping-v24,
  #barah-step-most-viewed,
  #barah-v616-quick-discovery,
  #barah-step-needs-v51,
  #barah-v617-decision-strip,
  section.barah-v35-latest,
  #barah-step-pregnancy-v55,
  #barah-step-senior-v57,
  #barah-step-catalog-v32,
  #barah-step-wholesale-v32{
    margin-bottom:18px!important;
  }
}

`;

  (document.head||document.documentElement).appendChild(s);
}

function first(sel){
  return document.querySelector(sel);
}

function latestDesktop(){
  var all=Array.prototype.slice.call(
    document.querySelectorAll('section.barah-v35-latest')
  );

  if(!all.length){
    all=Array.prototype.slice.call(
      document.querySelectorAll(
        'section.home-block.home-block--fixed-products.show-all'
      )
    ).filter(function(sec){
      var t=String(sec.textContent||'')
        .replace(/\s+/g,' ')
        .trim();

      return (
        t.indexOf('وصل حديث')!==-1 ||
        t.indexOf('جديد بارعة')!==-1 ||
        t.indexOf('أحدث المنتجات')!==-1
      );
    });
  }

  return all[0] || null;
}

function latestCandidates(){
  var out=[];

  document.querySelectorAll(
    'section.barah-v35-latest,'+
    '#barah-v643-mobile-latest'
  ).forEach(function(el){
    if(out.indexOf(el)===-1) out.push(el);
  });

  document.querySelectorAll(
    'section.home-block.home-block--fixed-products.show-all'
  ).forEach(function(sec){
    var t=String(sec.textContent||'')
      .replace(/\s+/g,' ')
      .trim();

    if(
      t.indexOf('وصل حديث')!==-1 ||
      t.indexOf('جديد بارعة')!==-1 ||
      t.indexOf('أحدث المنتجات')!==-1
    ){
      if(out.indexOf(sec)===-1) out.push(sec);
    }
  });

  return out;
}

function mostCandidates(){
  var out=[];

  [
    document.getElementById('barah-step-most-viewed'),
    document.getElementById('barah-v647-mobile-most-viewed')
  ].forEach(function(el){
    if(el && out.indexOf(el)===-1) out.push(el);
  });

  /*
    Catch accidental alternate "يشاهدها العملاء الآن" sections,
    but do not touch unrelated sections.
  */
  document.querySelectorAll('section').forEach(function(sec){
    var t=String(sec.textContent||'')
      .replace(/\s+/g,' ')
      .trim();

    if(t.indexOf('يشاهدها العملاء الآن')!==-1){
      if(out.indexOf(sec)===-1) out.push(sec);
    }
  });

  return out;
}

function canonicalLatest(){
  if(mobile()){
    return document.getElementById('barah-v643-mobile-latest') ||
           latestDesktop();
  }

  return latestDesktop() ||
         document.getElementById('barah-v643-mobile-latest');
}

function canonicalMost(){
  if(mobile()){
    return document.getElementById('barah-v647-mobile-most-viewed') ||
           document.getElementById('barah-step-most-viewed');
  }

  return document.getElementById('barah-step-most-viewed') ||
         document.getElementById('barah-v647-mobile-most-viewed');
}

function suppressDuplicates(){
  var latest=canonicalLatest();
  latestCandidates().forEach(function(el){
    el.classList.toggle('barah-v54u-duplicate',el!==latest);
  });

  var most=canonicalMost();
  mostCandidates().forEach(function(el){
    el.classList.toggle('barah-v54u-duplicate',el!==most);
  });
}

function needsSection(){
  return document.getElementById('barah-step-needs-v51') ||
         document.getElementById('barah-step-smart-storefront-v52');
}

function quickDiscovery(){
  return document.getElementById('barah-v616-quick-discovery') ||
         document.getElementById('barah-step-discovery-v15');
}

function moveAfter(anchor,node){
  if(!anchor || !node || anchor===node) return anchor;

  if(anchor.nextElementSibling!==node){
    anchor.insertAdjacentElement('afterend',node);
  }

  return node;
}

function arrange(){
  addStyle();
  suppressDuplicates();

  var hero=document.getElementById('barah-step-hero-v12');
  if(!hero || !hero.parentNode) return false;

  var chain=(mobile() ? [
    document.getElementById('barah-step-shipping-v24'),
    document.getElementById('barah-v655-available-picks'),
    quickDiscovery(),
    canonicalMost(),
    needsSection(),
    canonicalLatest(),
    document.getElementById('barah-step-catalog-v32'),
    document.getElementById('barah-step-wholesale-v32')
  ] : [
    document.getElementById('barah-step-shipping-v24'),
    document.getElementById('barah-v655-available-picks'),
    canonicalMost(),
    quickDiscovery(),
    needsSection(),
    document.getElementById('barah-v617-decision-strip'),
    canonicalLatest(),
    document.getElementById('barah-step-pregnancy-v55'),
    document.getElementById('barah-step-senior-v57'),
    document.getElementById('barah-step-catalog-v32'),
    document.getElementById('barah-step-wholesale-v32')
  ]).filter(Boolean);

  var cursor=hero;

  chain.forEach(function(node){
    if(node.classList.contains('barah-v54u-duplicate')) return;
    cursor=moveAfter(cursor,node);
  });

  /*
    Final guard: wholesale should still stay immediately before footer
    when both exist, unless catalog/wholesale are already in the main chain.
  */
  var footer=document.querySelector('footer');
  var wholesale=document.getElementById('barah-step-wholesale-v32');

  if(
    footer &&
    wholesale &&
    wholesale.parentNode===footer.parentNode &&
    footer.previousElementSibling!==wholesale
  ){
    footer.insertAdjacentElement('beforebegin',wholesale);
  }

  document.documentElement.setAttribute(
    'data-barah-v54u-order',
    mobile() ? 'mobile-ready' : 'desktop-ready'
  );

  return true;
}

function run(){
  arrange();
}

/* V66.2: one bounded settle after initial mounts, not a perpetual rearrangement loop. */
if(document.readyState==='loading'){
  document.addEventListener('DOMContentLoaded',function(){
    run();
    setTimeout(run,360);
  },{once:true});
}else{
  run();
  setTimeout(run,360);
}

})();

/* ============================================================
 BARAH V65.1 — PRODUCT PURCHASE ORDER FIX
 Preserves Salla's native variations, quantity and checkout controls.
============================================================ */
(function(){
 'use strict';
 if(window.__BARAH_PRODUCT_TEMPLATE_V651__)return;
 window.__BARAH_PRODUCT_TEMPLATE_V651__=true;
 function productPage(){return /\/p\d+(?:\/|$)/i.test(location.pathname)||document.body.classList.contains('product-single')||document.body.classList.contains('product-page')||!!document.querySelector('.page--product-details');}
 if(!productPage())return;
 var lock=false,last='',quiet;
 var sel={
   buy:'salla-add-product-button, button.add-to-cart, .btn--add-to-cart, button[name="add-to-cart"]',
   detail:'article.pd-exp, .article--product-details.pd-exp, section.product-description, section.product-details-description, .product-description, .product-details-description',
   price:'.product-entry__price, .product-single__price, .product-details__price, .product-price, .price-wrapper, salla-product-price',
   cards:'salla-product-card, custom-salla-product-card, .s-product-card-entry, .product-block, .product-item'
 };
 function visible(el){return !!(el&&el.isConnected&&!el.closest('header,footer,#barah-product-bundle,.modal,[role="dialog"]'));}
 function directChild(el,par){if(!el||!par||!par.contains(el))return null;while(el.parentElement&&el.parentElement!==par)el=el.parentElement;return el.parentElement===par?el:null;}
 function sharedParent(a,b,scope){var x=a&&a.parentElement;while(x&&x!==scope){if(x.contains(b))return x;x=x.parentElement;}return scope&&scope.contains(a)&&scope.contains(b)?scope:null;}
 function buyingBlock(btn,scope){
  var area=btn.closest('form, .product-form, .product-details__actions, .product-entry__actions, .product-single__details, .product-entry__content, .product-details__content, .product-info');
  return area&&!area.querySelector('h1')?area:(btn.parentElement||btn);
 }
 function arrangement(){
   if(lock)return;lock=true;
   try{
     var scope=document.querySelector('.page--product-details, .product-single, .product-page, main')||document.body;
     var btn=Array.from(scope.querySelectorAll(sel.buy)).find(visible);
     var d=Array.from(scope.querySelectorAll(sel.detail)).find(visible);
     if(!btn||!d){document.documentElement.dataset.barahV651='waiting';return;}
     var desc=d.closest('section.product-description,section.product-details-description,.product-description-wrapper')||d;
     var buy=buyingBlock(btn,scope);
     if(!buy||buy.contains(desc)||desc.contains(buy)){document.documentElement.dataset.barahV651='nested';return;}
     var price=Array.from(scope.querySelectorAll(sel.price)).find(visible);
     var h=scope.querySelector('h1');
     // Primary plan: rearrange direct section blocks only, preserving inner Salla structure.
     var par=sharedParent(desc,buy,scope), db=directChild(desc,par), bb=directChild(buy,par);
     if(par&&db&&bb&&db!==bb&&!bb.contains(h)&&!(price&&bb.contains(price))){
       if(bb.compareDocumentPosition(db)&Node.DOCUMENT_POSITION_PRECEDING){
         // Description is before the native purchasing section: move description after it.
         bb.insertAdjacentElement('afterend',db);
       }
       document.documentElement.dataset.barahV651='purchase-before-description';
     }else if(desc.parentNode&&buy.parentNode&&!desc.contains(btn)){
       // Secondary plan: relocate the description after the original purchase container.
       // Avoid moving the button itself or crossing the native Salla form boundary.
       var insertion=buy;
       while(insertion.parentElement&&insertion.parentElement!==scope&&insertion.parentElement!==document.body&&insertion.parentElement.contains(btn)&&!insertion.parentElement.contains(desc)&&!insertion.parentElement.querySelector('h1'))insertion=insertion.parentElement;
       if(!insertion.contains(desc)&&!desc.contains(insertion)&&desc!==insertion&&insertion.parentNode){insertion.insertAdjacentElement('afterend',desc);document.documentElement.dataset.barahV651='description-after-buy';}
     }
     var bundle=document.getElementById('barah-product-bundle');
     /* BARAH V67: legacy before-description bundle relocation disabled. */
   }catch(e){document.documentElement.dataset.barahV651='error';if(window.console&&console.warn)console.warn('[BARAH V65.1]',e);}
   finally{lock=false;}
 }
 function dedupe(){
  var root=document.getElementById('barah-bundle-products');if(!root)return;
  var cards=Array.from(root.querySelectorAll(sel.cards));
  cards=cards.filter(function(c){return !cards.some(function(other){return other!==c&&other.contains(c);});});
  var m=location.pathname.match(/\/p(\d+)/i),current=m&&m[1]||'',seen=new Set(),count=0;
  cards.forEach(function(c){
    var link=c.querySelector('a[href*="/p"]'),href=link&&link.getAttribute('href')||'',pid=href.match(/\/p(\d+)/i),id=String(c.getAttribute('data-product-id')||c.dataset.productId||pid&&pid[1]||'');
    var key=id||href.split(/[?#]/)[0].replace(/\/$/,'');
    var skip=!key||(current&&id===current)||seen.has(key)||count>=3;
    c.style.setProperty('display',skip?'none':'', 'important');
    if(!skip){seen.add(key);count++;}
  });
 }
 function run(){arrangement();dedupe();}
 if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',run,{once:true});else run();
 window.addEventListener('load',run,{once:true});
 [250,750,1600,3200,6000].forEach(function(ms){setTimeout(run,ms);});
 var target=document.querySelector('main')||document.body;
 if(window.MutationObserver&&target)new MutationObserver(function(){clearTimeout(quiet);quiet=setTimeout(run,200);}).observe(target,{childList:true,subtree:true});
})();

/* BARAH V65.2 — place three unique bundle recommendations immediately before description. */
(function(){
 'use strict';
 if(!(/\/p\d+(?:\/|$)/i.test(location.pathname)||document.querySelector('.page--product-details')))return;
 var busy=false, timer;
 function apply(){
  if(busy)return;busy=true;
  try{
   var bundle=document.getElementById('barah-product-bundle');
   var desc=document.querySelector('article.pd-exp, .article--product-details.pd-exp, section.product-description, section.product-details-description, .product-description, .product-details-description');
   if(!bundle||!desc||desc.contains(bundle)){return;}
   var block=desc.closest('section.product-description,section.product-details-description,.product-description-wrapper')||desc;
   /* BARAH V67: legacy before-description bundle relocation disabled. */
   var root=document.getElementById('barah-bundle-products');
   if(!root)return;
   var nodes=Array.from(root.querySelectorAll('salla-product-card,custom-salla-product-card,.s-product-card-entry,.product-block,.product-item'));
   nodes=nodes.filter(function(n){return !nodes.some(function(other){return other!==n&&other.contains(n);});});
   var m=location.pathname.match(/\/p(\d+)/i),current=m?m[1]:'',seen=new Set(),visible=0;
   nodes.forEach(function(node){
    var a=node.querySelector('a[href*="/p"]'),href=a&&a.getAttribute('href')||'',pm=href.match(/\/p(\d+)/i);
    var id=String(node.getAttribute('data-product-id')||node.dataset.productId||pm&&pm[1]||'');
    var key=id||href.split(/[?#]/)[0].replace(/\/$/,'');
    var hide=!key||(current&&id===current)||seen.has(key)||visible>=3;
    node.style.setProperty('display',hide?'none':'','important');
    if(!hide){seen.add(key);visible++;}
   });
  }finally{busy=false;}
 }
 if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',apply,{once:true});else apply();
 window.addEventListener('load',apply,{once:true});
 [200,700,1600,3200].forEach(function(ms){setTimeout(apply,ms);});
 var main=document.querySelector('main')||document.body;
 if(window.MutationObserver&&main)new MutationObserver(function(){clearTimeout(timer);timer=setTimeout(apply,180);}).observe(main,{childList:true,subtree:true});
})();

/* ============================================================
 BARAH V65.3 — SHIPPING NOTE BESIDE NATIVE PURCHASE CONTROLS
 Informational only. Final shipping fees are determined at checkout.
============================================================ */
(function(){
 'use strict';
 if(window.__BARAH_V653_SHIPPING_NOTE__)return;
 window.__BARAH_V653_SHIPPING_NOTE__=true;
 var ID='barah-v653-shipping-note', STYLE='barah-v653-shipping-style';
 function isProduct(){return /\/p\d+(?:\/|$)/i.test(location.pathname)||!!document.querySelector('.page--product-details');}
 if(!isProduct())return;
 function style(){
  if(document.getElementById(STYLE))return;
  var el=document.createElement('style');el.id=STYLE;
  el.textContent='#'+ID+'{direction:rtl;display:flex;flex-direction:column;gap:3px;margin:10px 0 12px;padding:11px 13px;border:1px solid #f2dccb;border-radius:11px;background:#fff9f3;color:#493026;font-family:inherit;line-height:1.7;box-sizing:border-box}#'+ID+' .barah-v653-main{font-size:13px;font-weight:800}#'+ID+' .barah-v653-detail{font-size:11px;color:#79665c;font-weight:400}@media(max-width:600px){#'+ID+'{padding:9px 11px;margin:9px 0}#'+ID+' .barah-v653-main{font-size:12px}}';
  (document.head||document.documentElement).appendChild(el);
 }
 function mount(){
  try{
   var scope=document.querySelector('.page--product-details,.product-single,.product-page,main')||document.body;
   var btn=Array.from(scope.querySelectorAll('salla-add-product-button,button.add-to-cart,.btn--add-to-cart,button[name="add-to-cart"]')).find(function(el){return !el.closest('header,footer,.modal,[role="dialog"],#barah-product-bundle');});
   if(!btn||!btn.parentNode)return;
   style();
   var note=document.getElementById(ID);
   if(!note){
    note=document.createElement('div');note.id=ID;note.setAttribute('role','note');
    var top=document.createElement('strong');top.className='barah-v653-main';top.textContent='الشحن يبدأ من 9 ريال — مجاني للطلبات فوق 149 ريال';
    var small=document.createElement('span');small.className='barah-v653-detail';small.textContent='تُحسب رسوم الشحن النهائية حسب الوجهة وخيارات التوصيل عند إتمام الطلب.';
    note.appendChild(top);note.appendChild(small);
   }
   // Add a sibling beside the native buy control; never replace or clone Salla elements.
   var anchor=btn;
   var maybe=btn.closest('.product-details__actions,.product-entry__actions,.product-form__actions,.s-product-options-wrapper');
   if(maybe && !maybe.querySelector('h1') && maybe.parentNode && !maybe.contains(note))anchor=maybe;
   if(anchor.nextElementSibling!==note)anchor.insertAdjacentElement('afterend',note);
  }catch(e){if(window.console&&console.warn)console.warn('[BARAH V65.3 shipping note]',e);}
 }
 if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',mount,{once:true});else mount();
 window.addEventListener('load',mount,{once:true});
 [350,1100,2500].forEach(function(ms){setTimeout(mount,ms);});
 var main=document.querySelector('main')||document.body, timer;
 if(window.MutationObserver&&main)new MutationObserver(function(){clearTimeout(timer);timer=setTimeout(mount,200);}).observe(main,{childList:true,subtree:true});
})();


/* BARAH V65.4 — HOME CONTENT ACCURACY FINAL GUARD
   Homepage only. No product page / checkout modifications. */
(function(){
  'use strict';
  var route=(location.pathname||'/').replace(/\/+$/,'')||'/';
  var host=String(location.hostname||'').toLowerCase();
  if (!(route==='/'||route==='/ar'||route==='/en'||(host==='salla.sa'&&route==='/br1'))) return;
  if (window.__BARAH_V654_HOME_COPY__) return;
  window.__BARAH_V654_HOME_COPY__=true;
  function fix(){
    var roots=[document.getElementById('barah-step-hero-v12'),document.getElementById('barah-step-needs-v51'),document.getElementById('barah-step-most-viewed'),document.getElementById('barah-v647-mobile-most-viewed'),document.getElementById('barah-step-shipping-v24'),document.getElementById('barah-step-smart-storefront-v52')].filter(Boolean);
    var hero=roots[0];
    if(hero){
      hero.querySelectorAll('a').forEach(function(a){
        var t=(a.textContent||'').replace(/\s+/g,' ').trim();
        if(t==='⌂ الصفحة الرئيسية'||t==='الصفحة الرئيسية'||a.classList.contains('barah-home-direct')) a.remove();
      });
      var primary=hero.querySelector('a.barah-hero-primary');
      if(primary){primary.setAttribute('href','https://barahstore.com/ar/home-kitchen/c127906256');primary.textContent='تسوّق المنزل والمطبخ ←';}
    }
    document.querySelectorAll('.v44-head-actions a').forEach(function(a){
      if((a.textContent||'').indexOf('الصفحة الرئيسية')!==-1) a.remove();
    });
    roots.forEach(function(root){
      root.querySelectorAll('h1,h2,h3,p,strong,span').forEach(function(el){
        if(el.children.length) return;
        var t=(el.textContent||'').trim();
        if(t.indexOf('يشاهدها العملاء الآن')!==-1) el.textContent=t.replace(/يشاهدها العملاء الآن\s*🔥?/g,'الأكثر مشاهدة مؤخرًا');
        else if(t.indexOf('منتجات عليها اهتمام الآن')!==-1) el.textContent='اختيارات استنادًا إلى مشاهدات 3–5 أكتوبر 2026';
        else if(t.indexOf('خلّ الشحن علينا إذا وصلت سلتك 149 ريال')!==-1) el.textContent='مجاني للطلبات فوق 149 ريال';
      });
    });
    var viewed=document.getElementById('barah-v647-mobile-most-viewed');
    if(viewed){
      var chips=viewed.querySelectorAll('.v647-chips span');
      if(chips[0]) chips[0].textContent='👀 الأكثر مشاهدة';
      if(chips[1]) chips[1].textContent='📅 3–5 أكتوبر';
    }
  }
  if(document.readyState==='loading') document.addEventListener('DOMContentLoaded',fix,{once:true});
  else fix();
  [200,700,1600,3500].forEach(function(ms){setTimeout(fix,ms);});
})();



/* ===============================================================
 BARAH V65.7 — HOME TWO DESTINATIONS, PRICED SIX PICKS
 Scoped to HOME only. Preserves native Salla product purchase functionality.
 Product IDs / images / published + positive inventory verified via Salla connector 2026-10-08.
 =============================================================== */
(function(){
'use strict';
if(window.__BARAH_HOME_V655__)return;
window.__BARAH_HOME_V655__=true;
var path=(location.pathname||'/').replace(/\/+$/,'')||'/';
var home=(path==='/'||path==='/ar'||path==='/en'||(location.hostname==='salla.sa'&&path==='/br1'));
if(!home)return;
var CATEGORY='https://barahstore.com/ar/home-kitchen/c127906256';
var FITNESS='https://barahstore.com/ar/fitness/c511828448';
var ROOT='barah-v655-available-picks';
var P=[
 {id:1682981300,price:5.75,n:'فرشاة أطباق بخزان صابون',url:'https://barahstore.com/ar/product-1682981300/p1682981300',img:'https://cdn.salla.sa/qwxGZ/dbc9d5dd-0582-4f97-bac6-8c9ece063747-323.4894772573x500-inYOFj01wp7Ri6vXUT7FsSPL4lu9XhrIov1cEC14.jpg'},
 {id:1455538329,price:49,n:'طقم حبال مقاومة للتمارين',url:'https://barahstore.com/ar/product-1455538329/p1455538329',img:'https://cdn.salla.sa/qwxGZ/515fab97-aab3-448a-8a7b-6b9287691cb0-500x500-EA6WdMUjzvNizNpEGrkn2zERP8MWbIpNct1GNX0K.webp'},
 {id:1225341562,price:16,n:'مظلة شمس للسيارة قابلة للطي',url:'https://barahstore.com/ar/product-1225341562/p1225341562',img:'https://cdn.salla.sa/qwxGZ/699f9b0d-3277-4a0b-951e-34bf7435720a-500x500-8gdk8IfwVfqkW2aR4ELvw9vzOGcububLcjxskQur.png'},
 {id:544932232,price:38,n:'مبرد قدمين كهربائي بالشفط',url:'https://barahstore.com/ar/product-544932232/p544932232',img:'https://cdn.salla.sa/qwxGZ/4b49dd72-12c5-4455-a5f7-d0c942e60320-435.16597510373x500-dHYRsRNvNR5dTgfDBHyUEelffvXIEOeN9rIZpdVc.jpg'},
 {id:409857806,price:9,n:'أداة تقطيع وختم الساندويتش',url:'https://barahstore.com/ar/product-409857806/p409857806',img:'https://cdn.salla.sa/qwxGZ/4e7a99b0-a24f-43fd-aebd-63a49ed2f116-500x500-CA80Y8aJ7MPT3D7IGHQUvv0AJREafPGK4xpdslXY.png'},
 {id:473402272,price:19,n:'لعبة قطط تفاعلية للمطاردة',url:'https://barahstore.com/ar/لعبة-قطط-تفاعلية-بزناد-يدوي-للمطاردة-بارعة/p473402272',img:'https://cdn.salla.sa/qwxGZ/683251fb-450a-4819-b453-e1ac48462615-500x500-kUSKqliDNXWPd3WjT8nAwQM57awXKfCBADHdboEJ.jpg'}
];
function css(){if(document.getElementById('barah-v655-css'))return;var s=document.createElement('style');s.id='barah-v655-css';s.textContent=`
#${ROOT}{direction:rtl;width:min(1180px,calc(100% - 24px));margin:16px auto 23px;font-family:inherit}
#${ROOT} *{box-sizing:border-box}
#${ROOT} .v655-h{display:flex;align-items:end;justify-content:space-between;gap:10px;margin:0 0 12px}
#${ROOT} h2{font-size:clamp(19px,2.4vw,25px);font-weight:900;line-height:1.4;margin:0;color:#201713}
#${ROOT} .v655-h p{font-size:12px;color:#70645c;margin:4px 0 0}
#${ROOT} .v655-more{font-size:12px;color:#cf4d22;text-decoration:none;font-weight:800}
#${ROOT} .v655-grid{display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:10px}
#${ROOT} .v655-card{min-width:0;border:1px solid #efe5dd;border-radius:14px;overflow:hidden;background:#fff;display:flex;flex-direction:column}
#${ROOT} .v655-img{display:block;aspect-ratio:1/1;background:#fff;text-decoration:none}
#${ROOT} img{display:block;width:100%;height:100%;object-fit:contain;padding:8px}
#${ROOT} .v655-title{font-size:12px;line-height:1.6;font-weight:800;color:#261d18;margin:8px 9px 9px;min-height:39px;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;text-decoration:none}
#${ROOT} .v657-price{font-size:13px;font-weight:900;color:#c95022;margin:0 9px 9px;direction:rtl}
#${ROOT} .v655-buy{margin:auto 8px 9px;text-decoration:none;text-align:center;border-radius:9px;padding:9px 3px;background:linear-gradient(110deg,#ff7a18,#ef4444);color:#fff;font-size:12px;font-weight:900}
@media(max-width:950px){#${ROOT} .v655-grid{grid-template-columns:repeat(3,minmax(0,1fr))}}
@media(max-width:600px){#${ROOT} .v655-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}#${ROOT} .v655-h{align-items:start}#${ROOT} .v655-card{border-radius:12px}}
`;document.head.appendChild(s)}
function build(){var sec=document.getElementById(ROOT);if(sec)return sec;sec=document.createElement('section');sec.id=ROOT;sec.setAttribute('aria-label','اختيارات بارعة المتنوعة');var head=document.createElement('div');head.className='v655-h';head.innerHTML='<div><h2>منتجات تستحق الاكتشاف</h2><p>اختيارات متنوعة للوصول إلى المنتج مباشرة</p></div><a class="v655-more" href="'+CATEGORY+'">استكشف المنزل والمطبخ ←</a>';sec.appendChild(head);var grid=document.createElement('div');grid.className='v655-grid';P.filter(function(p,i,arr){return arr.findIndex(function(x){return x.id===p.id})===i}).slice(0,6).forEach(function(p){var card=document.createElement('article');card.className='v655-card';var a=document.createElement('a');a.className='v655-img';a.href=p.url;a.setAttribute('aria-label',p.n);var img=document.createElement('img');img.src=p.img;img.alt=p.n;img.loading='lazy';img.decoding='async';img.width=500;img.height=500;a.appendChild(img);var title=document.createElement('a');title.className='v655-title';title.href=p.url;title.textContent=p.n;var buy=document.createElement('a');buy.className='v655-buy';buy.href=p.url;buy.textContent='عرض وشراء';var price=document.createElement('div');price.className='v657-price';price.textContent=p.price.toLocaleString('ar-SA',{maximumFractionDigits:2})+' ر.س';card.append(a,title,price,buy);grid.appendChild(card)});sec.appendChild(grid);return sec}
function update(){css();var hero=document.getElementById('barah-step-hero-v12');if(hero){hero.querySelectorAll('.barah-home-direct').forEach(function(a){a.remove()});var a=hero.querySelector('.barah-hero-primary');if(a){a.href=CATEGORY;a.textContent='تسوّق المنزل والمطبخ ←'}var b=hero.querySelector('.barah-hero-secondary:not(.barah-home-direct)');if(b){b.href=FITNESS;b.textContent='اكتشف الرياضة واللياقة ←'}hero.querySelectorAll('.barah-hero-pill').forEach(function(x){if(/الأكثر طلبًا|الأكثر مبيعًا/.test(x.textContent||''))x.textContent='اختيار بارعة'})}
 document.querySelectorAll('a').forEach(function(a){if(a.closest('#'+ROOT))return;var href=a.getAttribute('href')||'';if(href.indexOf('https://barahstore.com/ar/home-kitchen/c127906256')!==-1){a.href=CATEGORY;if(/الأكثر مبيع|الأكثر طلب/.test(a.textContent||''))a.textContent='استكشف المنزل والمطبخ ←'}});
 document.querySelectorAll('h2,h3,p,strong,span,small').forEach(function(x){if(x.children.length||x.closest('#'+ROOT)||x.closest('header,footer'))return;var t=(x.textContent||'').trim();if(t==='أفكار طلب مرتفعة الآن داخل بارعة'||t==='أفكار طلب مرتفعة الآن')x.textContent='اختيارات عملية لك';else if(t==='الأكثر طلبًا')x.textContent='اختيارات بارعة';else if(t==='ابدأ من الأكثر طلبًا')x.textContent='اكتشف اختياراتنا';});
 var ship=document.getElementById('barah-step-shipping-v24');var anchor=ship||hero;if(anchor&&anchor.parentNode){var sec=build();if(!sec.isConnected)anchor.insertAdjacentElement('afterend',sec)}
}
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',update,{once:true});else update();
setTimeout(update,250);
})();


/* ============================================================
 BARAH V66.1 — PRODUCT TAGS AFTER DESCRIPTION (ROBUST DETECTION)
 Only moves the tag link group, never product purchase controls.
 ============================================================ */
(function(){
 'use strict';
 if(window.__BARAH_V661_TAGS_AFTER_DESCRIPTION__)return;
 window.__BARAH_V661_TAGS_AFTER_DESCRIPTION__=true;
 var path=location.pathname||'';
 if(!/\/p\d+(?:\/|$|\?)/i.test(path)&&!document.querySelector('.page--product-details'))return;
 var tries=0, lock=false;
 function norm(s){return String(s||'').replace(/\s+/g,' ').trim();}
 function description(){
   var d=document.querySelector('article.pd-exp,article.article--product-details.pd-exp,section.product-description,section.product-details-description,.product-description,.product-details-description');
   if(!d)return null;
   return d.closest('section.product-description,section.product-details-description,.product-description-wrapper')||d;
 }
 function safe(el,desc){
   return !!(el && el.isConnected && !el.contains(desc) && !desc.contains(el) &&
     !el.closest('header,footer,nav,.modal,[role="dialog"],#barah-product-bundle') &&
     !el.querySelector('form,salla-add-product-button,button[name="add-to-cart"],.product-form') &&
     !el.querySelector('h1, salla-product-options, salla-quantity-input') &&
     norm(el.textContent).length<650);
 }
 function tagAnchor(a){
   if(!a||!a.getAttribute('href'))return false;
   var href=a.getAttribute('href')||'';
   var label=norm(a.textContent);
   return /(?:\/tags?(?:\/|\?|$)|[?&]tags?=|\/tag-)/i.test(href) ||
     /^(?:موضة بارعة|منتجات عصرية بارعة|أناقة مع بارعة|بارعة متجر|بارعة ستور|منتجات بارعة)/.test(label);
 }
 function detect(desc){
   var scope=document.querySelector('.page--product-details,.product-single,.product-page,main')||document.body;
   var named=Array.from(scope.querySelectorAll('.product-tags,.product__tags,.product-details__tags,.product-entry__tags,.product-single__tags,.s-product-tags,[data-product-tags],.tags--product'));
   var anchors=Array.from(scope.querySelectorAll('a[href]')).filter(function(a){return tagAnchor(a)&&!a.closest('header,footer,nav');});
   var candidates=named.concat(anchors.map(function(a){return a.parentElement;}));
   // Find smallest common list of links, not the enclosing product details or purchase form.
   anchors.forEach(function(a){
     var e=a.parentElement;
     for(var i=0;e&&i<4;i++,e=e.parentElement){
       var count=Array.from(e.querySelectorAll('a[href]')).filter(tagAnchor).length;
       if(count>=2){candidates.push(e);break;}
     }
   });
   candidates=candidates.filter(function(e){return safe(e,desc)&&e.querySelectorAll('a[href]').length>=1;});
   candidates.sort(function(a,b){
     var na=Array.from(a.querySelectorAll('a[href]')).filter(tagAnchor).length;
     var nb=Array.from(b.querySelectorAll('a[href]')).filter(tagAnchor).length;
     return (nb-na)||((a.querySelectorAll('*').length)-(b.querySelectorAll('*').length));
   });
   return candidates.find(function(e){
     var matches=Array.from(e.querySelectorAll('a[href]')).filter(tagAnchor);
     return matches.length>=2 || (matches.length===1 && /tag/i.test(e.className||''));
   })||null;
 }
 function move(){
   if(lock||tries++>18)return;
   lock=true;
   try{
     var desc=description();if(!desc||!desc.parentNode)return;
     var tags=detect(desc);if(!tags)return;
     if(desc.nextElementSibling!==tags){desc.insertAdjacentElement('afterend',tags);}
     document.documentElement.setAttribute('data-barah-tags-after-desc','done');
   }catch(err){if(window.console&&console.warn)console.warn('[BARAH V66.1 tags]',err);}
   finally{lock=false;}
 }
 if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',move,{once:true});else move();
 window.addEventListener('load',move,{once:true});
 [250,800,1800,3500].forEach(function(ms){setTimeout(move,ms);});
})();

/* ==========================================================
 BARAH V66.2 — MOBILE-FIRST COMPACT PRESENTATION
 No purchase controls or product-page modules are modified.
 ========================================================== */
(function(){
'use strict';
var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
if(!(p==='/'||p==='/ar'||p==='/en'||(location.hostname==='salla.sa'&&p==='/br1')))return;
var css=document.createElement('style');
css.id='barah-v662-mobile-layout';
css.textContent=`
@media(max-width:767px){
  #barah-step-hero-v12 .barah-hero-shell{padding:12px!important;gap:8px!important}
  #barah-step-hero-v12 .barah-hero-copy{min-height:0!important;padding:0!important}
  #barah-step-hero-v12 h1{font-size:23px!important;line-height:1.32!important}
  #barah-step-hero-v12 .barah-hero-copy p{margin:6px 0 10px!important;line-height:1.5!important}
  #barah-step-hero-v12 .barah-hero-products{display:none!important}
  #barah-step-hero-v12 .barah-hero-trust{display:none!important}
  #barah-step-shipping-v24 .barah-v24-shell{padding:9px 12px!important}
  #barah-step-shipping-v24 .barah-v24-copy strong{font-size:12px!important}
  #barah-step-shipping-v24 .barah-v24-copy span,
  #barah-step-shipping-v24 .barah-v24-points{display:none!important}
  #barah-v655-available-picks{margin:8px 12px 14px!important}
  #barah-v655-available-picks .v655-h p{display:none!important}
  #barah-v655-available-picks .v655-img{aspect-ratio:1/1!important}
  #barah-v655-available-picks .v655-card img{aspect-ratio:1/1!important;object-fit:contain!important}
  #barah-step-pregnancy-v55,
  #barah-step-senior-v57,
  #barah-v617-decision-strip{display:none!important}
  #barah-step-needs-v51 .v51-sub,
  #barah-step-smart-storefront-v52 .v52-sub{display:none!important}
  #barah-v643-mobile-latest .product-entry:nth-of-type(n+7),
  #barah-v643-mobile-latest .product-card:nth-of-type(n+7){display:none!important}
}
`;
(document.head||document.documentElement).appendChild(css);
function sync(){
 var hero=document.getElementById('barah-step-hero-v12');
 if(hero){
  var a=hero.querySelector('.barah-hero-primary');
  if(a){a.href='https://barahstore.com/ar/home-kitchen/c127906256';a.textContent='تسوّق المنزل والمطبخ ←';}
  var other=hero.querySelector('.barah-hero-secondary:not(.barah-home-direct)');
  if(other){other.href='https://barahstore.com/ar/fitness/c511828448';other.textContent='تسوّق الرياضة واللياقة ←';}
 }
 var picks=document.getElementById('barah-v655-available-picks');
 var ship=document.getElementById('barah-step-shipping-v24');
 /* V66.3: placement delegated to single mobile coordinator */
 document.querySelectorAll('a').forEach(function(a){
  if(/^(?:عرض )?كل المنتجات\s*(?:←)?$/.test((a.textContent||'').trim()) && (a.getAttribute('href')||'').indexOf('home-kitchen')!==-1){a.textContent='تسوّق المنزل والمطبخ ←';}
 });
}
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',function(){setTimeout(sync,420);},{once:true});
else setTimeout(sync,420);
})();


/* =============================================================
 BARAH V66.3 — MOBILE ONE-TIME ORDER & COPY FIX
 Owner only of mobile home ordering, not product details.
 ============================================================= */
(function(){
'use strict';
var path=(location.pathname||'/').replace(/\/+$/,'')||'/';
if(!(/^\/(?:ar|en)?$/.test(path)))return;
var style=document.createElement('style');
style.id='barah-v663-stable-mobile-css';
style.textContent=`
@media(max-width:767px){
  #barah-step-pregnancy-v55,
  #barah-v61-pregnancy-story,
  #barah-v61-pregnancy-story-v1,
  #barah-step-senior-v57{display:none!important}
  #barah-v655-available-picks .v655-img{aspect-ratio:1/1!important}
  #barah-v655-available-picks .v655-img img{width:100%!important;height:100%!important;object-fit:contain!important}
}`;
(document.head||document.documentElement).appendChild(style);
var done=false, obs=null, tries=0;
function fixCopy(){
 document.querySelectorAll('a[href]').forEach(function(a){
  var href=a.getAttribute('href')||'';
  if(href.indexOf('/home-kitchen/c127906256')<0)return;
  if(/^(?:عرض\s*)?كل المنتجات\s*(?:←)?$/.test((a.textContent||'').trim()))
    a.textContent='تسوّق المنزل والمطبخ ←';
 });
 var most=document.getElementById('barah-step-most-viewed');
 if(most){
  var title=most.querySelector('h2');
  var p=most.querySelector('.barah-step-most-viewed__head p');
  if(title)title.textContent='الأكثر مشاهدة مؤخرًا';
  if(p)p.textContent=(p.textContent||'').replace(/^(?:بحسب مشاهدات\s*)+/,'').trim();
 }
}
function place(){
 if(done || !window.matchMedia('(max-width:767px)').matches)return;
 fixCopy();
 var ship=document.getElementById('barah-step-shipping-v24');
 var picks=document.getElementById('barah-v655-available-picks');
 if(!ship||!picks||!ship.parentNode)return;
 ship.insertAdjacentElement('afterend',picks);
 done=true;
 document.documentElement.setAttribute('data-barah-v663-mobile-order','ready');
 if(obs)obs.disconnect();
}
function start(){
 place();
 if(done)return;
 if(window.MutationObserver){
  obs=new MutationObserver(function(){
   if(++tries>160){obs.disconnect();return;}
   place();
  });
  obs.observe(document.body,{childList:true,subtree:true});
 }
 setTimeout(function(){if(obs)obs.disconnect();place();},5000);
}
if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',start,{once:true});
else start();
})();


/* BARAH V66.4 — VISUAL ROUTES / COMPACT HOME CSS, NO REPEATED MOVES */
(function(){
'use strict';
var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
if(!(/^\/(?:ar|en)?$/.test(p)))return;
var st=document.createElement('style');st.id='barah-v664-visual-home-css';
st.textContent=`
#barah-step-needs-v51{width:min(1180px,calc(100% - 24px))!important;margin:18px auto!important;direction:rtl!important}
#barah-step-needs-v51 .barah-v664-needs-shell{border:1px solid #f1e4dd;background:#fffcfa;padding:17px;border-radius:19px;box-sizing:border-box}
#barah-step-needs-v51 .barah-v664-head{margin-bottom:13px}
#barah-step-needs-v51 .barah-v664-head h2{font-size:21px;line-height:1.4;font-weight:900;color:#271c16;margin:0}
#barah-step-needs-v51 .barah-v664-head p{font-size:12px;color:#71645b;margin:4px 0 0}
#barah-step-needs-v51 .barah-v664-needs-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px}
#barah-step-needs-v51 .barah-v664-need{display:flex;align-items:center;gap:11px;min-width:0;border:1px solid #ede0d7;background:white;border-radius:14px;padding:9px;text-decoration:none;box-shadow:0 3px 10px rgba(35,25,18,.025);box-sizing:border-box}
#barah-step-needs-v51 .barah-v664-need img{flex:none;width:84px;height:84px;object-fit:contain;background:#fff8f3;border-radius:10px}
#barah-step-needs-v51 .barah-v664-need span{display:flex;flex-direction:column;min-width:0;gap:6px}
#barah-step-needs-v51 .barah-v664-need strong{font-size:13px;font-weight:900;line-height:1.5;color:#292018}
#barah-step-needs-v51 .barah-v664-need small{font-size:11px;font-weight:800;color:#d15422}
#barah-step-senior-v57 .v624-thumb,#barah-step-senior-v57 .v624-thumb img{width:90px!important;height:90px!important;max-width:90px!important;object-fit:contain!important}
@media(max-width:767px){
#barah-step-needs-v51 .barah-v664-needs-shell{padding:12px;border-radius:16px}
#barah-step-needs-v51 .barah-v664-head h2{font-size:18px}
#barah-step-needs-v51 .barah-v664-needs-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
#barah-step-needs-v51 .barah-v664-need{flex-direction:column;align-items:stretch;padding:9px;gap:7px;overflow:hidden}
#barah-step-needs-v51 .barah-v664-need img{width:100%;height:auto;aspect-ratio:1.3/1;object-fit:contain}
#barah-step-needs-v51 .barah-v664-need strong{font-size:12px}
#barah-step-needs-v51 .barah-v664-need small{font-size:10px}
#barah-step-smart-storefront-v52 .v52-sub,#barah-v617-decision-strip,#barah-step-pregnancy-v55,#barah-step-senior-v57{display:none!important}
}
`;
(document.head||document.documentElement).appendChild(st);
})();


/* BARAH V66.6 — REAL MOTHER & CHILD CARD IMAGE REPAIR */
(function(){
 'use strict';
 var path=(location.pathname||'/').replace(/\/+$/,'')||'/';
 if(!/^\/(?:ar|en)?$/.test(path))return;
 var IMAGE='https://cdn.salla.sa/qwxGZ/d42bb3c8-3255-4dea-a514-044eec312fcf-500x500-tr82vVN6HKoCGxpAtZIm96tvIF7dUurqL0yC2SFM.jpg';
 var LINK='https://barahstore.com/ar/product-630210826/p630210826';
 function fix(){
   var nodes=document.querySelectorAll('#barah-step-needs-v51 .barah-v664-need, #barah-step-needs-v51 a, #barah-step-smart-storefront-v52 a');
   nodes.forEach(function(a){
     var label=(a.textContent||'').replace(/\s+/g,' ').trim();
     if(label.indexOf('للأم والطفل')===-1)return;
     if(a.classList.contains('barah-v664-need')){
       a.setAttribute('href',LINK);
       var img=a.querySelector('img');
       if(!img){img=document.createElement('img');a.prepend(img);}
       if(img.getAttribute('src')!==IMAGE)img.setAttribute('src',IMAGE);
       img.setAttribute('alt','شنطة أطفال 3 في 1 مع سرير سفر ومساحة تخزين');
       img.setAttribute('width','96');img.setAttribute('height','96');
       img.style.setProperty('display','block','important');
       img.style.setProperty('object-fit','contain','important');
       img.style.setProperty('aspect-ratio','1 / 1','important');
     }
   });
 }
 if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',fix,{once:true});else fix();
 var done=0,t=setInterval(function(){fix();if(++done>=12)clearInterval(t);},400);
})();






/* =============================================================
 BARAH V66.20 — DETAILS DIRECTLY AFTER SHIPPING / ALL VIEWPORTS
 ============================================================= */
(function(){
 'use strict';
 var path=location.pathname.replace(/\/+$/,'')||'/';
 if(!['/','/ar','/en'].includes(path))return;
 var ID='barah-v669-small-details';
 var products=[
  ['1437554172','تنظيف الأسنان بالماء','https://cdn.salla.sa/qwxGZ/9e6f7df8-8759-48e3-9841-345c452eec6c-305.70902394107x500-Kim2sKwh0BUxYQP9DjO4x9F3B9JXy5jK7n6XtSPr.jpg'],
  ['33336204','لفّ ورق العنب والمحاشي','https://cdn.salla.sa/qwxGZ/f5a9a413-7c81-45ce-8e92-a46007e25ddf-500x500-67ZxkNfc3TaUZN9ebS7JhgrM5NJugHz37aBDuzBD.png'],
  ['1525615372','مشد نسائي كامل · XXXL','https://cdn.salla.sa/qwxGZ/fba2bc98-551f-4ffd-a66a-dcec8e1d4950-500x500-DMl7DHiKgGRZm0Gm20zKcdP8N0S81MakR03z1zCL.png'],
  ['134301521','تنظيف المنزل بالبخار','https://cdn.files.salla.network/products/71627348/1d521812-3f80-4e9d-815a-f002538da56e-original.webp'],
  ['1581623087','عربة تسوق للدرج','https://cdn.salla.sa/qwxGZ/f60b4eaf-280d-4c18-baee-8b5081a48caf-333.33333333333x500-5tugmDxWADa6ZugZYEUayu05SSZyGT99PUsrjttD.png']
 ];
 var css=document.createElement('style');css.id='barah-v6611-details-style';
 css.textContent=`
 #${ID}{display:block!important;visibility:visible!important;opacity:1!important;direction:rtl;width:min(1180px,calc(100% - 24px));margin:16px auto 22px;clear:both;position:relative!important;height:auto!important;overflow:visible!important;contain:none!important;content-visibility:visible!important}
 #${ID} *{box-sizing:border-box}
 #${ID} h2{margin:0 0 12px;font-size:21px;line-height:1.4;font-weight:900;color:#222}
 #${ID} .v669-grid{display:grid!important;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
 #${ID} .v669-card{display:flex;flex-direction:column;min-width:0;border:1px solid #eee3db;background:#fff;border-radius:16px;padding:9px;text-decoration:none!important;color:#222!important}
 #${ID} .v669-media{display:block;aspect-ratio:1/1;border-radius:12px;background:#fff;overflow:hidden}
 #${ID} .v669-media img{display:block!important;width:100%!important;height:100%!important;object-fit:contain!important;filter:none!important;opacity:1!important;transform:none!important}
 #${ID} .v669-body{display:flex;flex:1;flex-direction:column;padding-top:8px}
 #${ID} .v669-name{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;line-height:1.5;font-size:13px;font-weight:850}
 #${ID} .v669-go{display:block;margin-top:auto;padding-top:7px;color:#e85b31!important;font-size:12px;font-weight:850}
 #${ID} .v669-wide{grid-column:1/-1;flex-direction:row;align-items:center;gap:12px}
 #${ID} .v669-wide .v669-media{flex:0 0 104px;width:104px;order:0}
 #${ID} .v669-wide .v669-body{order:1}
 @media(min-width:768px){#${ID} .v669-grid{grid-template-columns:repeat(4,minmax(0,1fr))}#${ID} .v669-wide{grid-column:1/-1}}
 `;
 (document.head||document.documentElement).appendChild(css);
 function duplicate(id){
   return Array.from(document.querySelectorAll('main a[href],section a[href]')).some(function(a){
    if(a.closest('#'+ID)||a.closest('header,footer,nav'))return false;
    var h=a.getAttribute('href')||'';
    if(!new RegExp('/p'+id+'(?:[?#]|$)').test(h))return false;
    var r=a.getBoundingClientRect();
    if(r.width<20||r.height<20)return false;
    for(var n=a;n&&n!==document.body;n=n.parentElement){var v=getComputedStyle(n);if(v.display==='none'||v.visibility==='hidden')return false;}
    return true;
   });
 }
 function make(){
  var section=document.createElement('section');section.id=ID;
  section.setAttribute('aria-label','تفاصيل صغيرة تسهّل يومك');
  var h=document.createElement('h2');h.textContent='تفاصيل صغيرة… تسهّل يومك';section.appendChild(h);
  var grid=document.createElement('div');grid.className='v669-grid';
  var arr=products.filter(function(p){return !duplicate(p[0]);});
  arr.forEach(function(p){
    var a=document.createElement('a');a.className='v669-card';a.href='https://barahstore.com/ar/product-'+p[0]+'/p'+p[0];
    var media=document.createElement('span');media.className='v669-media';
    var img=document.createElement('img');img.src=p[2];img.alt=p[1];img.width=500;img.height=500;img.loading='lazy';img.decoding='async';media.appendChild(img);
    var body=document.createElement('span');body.className='v669-body';
    var name=document.createElement('span');name.className='v669-name';name.textContent=p[1];
    var go=document.createElement('span');go.className='v669-go';go.textContent='اكتشفها ←';
    body.appendChild(name);body.appendChild(go);a.appendChild(media);a.appendChild(body);grid.appendChild(a);
    if(p[0]==='1581623087')a.classList.add('v669-wide');
  });
  section.appendChild(grid);return section;
 }

 function visible(el){
   if(!el||!el.isConnected)return false;
   for(var n=el;n&&n!==document.body;n=n.parentElement){
     var st=getComputedStyle(n);
     if(st.display==='none'||st.visibility==='hidden')return false;
   }
   return true;
 }
 function anchor(){
   // Place below the shipping banner that states free shipping above 149 SAR.
   var shipping=document.getElementById('barah-step-shipping-v24');
   if(shipping && visible(shipping))return shipping;
   var alternatives=document.querySelectorAll('[id*="shipping"], [class*="shipping"], section');
   for(var i=0;i<alternatives.length;i++){
     var el=alternatives[i];
     if(!visible(el) || !/مجاني للطلبات فوق\s*149|مجاني فوق\s*149|الشحن مجاني.*149/.test((el.textContent||'').slice(0,800)))continue;
     // Avoid selecting page-wide wrappers containing the whole homepage.
     if(el === document.body || el.matches('main,.container'))continue;
     return el;
   }
   return null;
 }
 var node=null,observer=null,timer=null,scheduled=false,attempts=0;
 function mount(){
   var dest=anchor();
   if(!dest)return false;
   if(!dest.parentNode)return false;
   if(!node)node=make();
   var count=node.querySelectorAll('.v669-card').length;
   if(!count)return false;
   if(node.parentNode!==dest.parentNode || node.previousElementSibling!==dest){
     dest.parentNode.insertBefore(node,dest.nextSibling);
   }
   return true;
 }
 function schedule(){
   if(scheduled)return;
   scheduled=true;
   requestAnimationFrame(function(){scheduled=false;mount();});
 }
 function start(){
   mount();
   if(!window.MutationObserver)return;
   observer=new MutationObserver(function(){
     if(++attempts>500)return;
     schedule();
   });
   observer.observe(document.body,{childList:true,subtree:true});
   // Existing theme recreates home sections late; observe for bounded time.
   timer=setTimeout(function(){observer.disconnect();mount();},12000);
 }
 if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',start,{once:true});
 else start();
})();


/* BARAH V66.16 — Relocate the SAME smart-needs section directly above Important Links */
(function(){
 'use strict';
 if(!/^\/(?:ar|en)?\/?$/.test(location.pathname))return;
 var ID='barah-step-needs-v51', armed=false, observer=null, ticks=0;
 var CSS_ID='barah-v6616-smart-footer-css';
 function style(){
   if(document.getElementById(CSS_ID))return;
   var el=document.createElement('style');el.id=CSS_ID;
   el.textContent='footer > #'+ID+',footer .barah-smart-footer-slot > #'+ID+'{display:block!important;width:100%!important;max-width:1180px!important;margin:16px auto!important;padding:0!important;float:none!important;clear:both!important}footer .barah-smart-footer-slot{display:block!important;width:100%!important;grid-column:1/-1!important;flex-basis:100%!important}';
   document.head.appendChild(el);
 }
 function clean(s){return (s||'').replace(/\s+/g,' ').trim();}
 function locate(){
   var footer=document.querySelector('footer');
   if(!footer)return null;
   var headings=footer.querySelectorAll('h2,h3,h4,h5,strong,p,span,div');
   for(var i=0;i<headings.length;i++){
     var el=headings[i];
     if(clean(el.textContent)!=='روابط مهمة')continue;
     // Prefer the block which contains the heading plus its navigational links.
     var box=el;
     for(var n=0;n<4 && box.parentElement && box.parentElement!==footer;n++){
       box=box.parentElement;
       if(box.querySelectorAll('a[href]').length>=3)break;
     }
     if(box===footer)box=el.parentElement;
     return {footer:footer, before:box};
   }
   return {footer:footer,before:null};
 }
 function run(){
   var smart=document.getElementById(ID);
   if(!smart)return false;
   var loc=locate();if(!loc)return false;
   style();
   // Desktop: place the full section OUTSIDE the footer grid.
   // Mobile: retain its existing placement and layout.
   if(window.matchMedia('(min-width:768px)').matches){
     if(loc.footer.parentElement && (smart.parentElement!==loc.footer.parentElement || smart.nextElementSibling!==loc.footer)){
       loc.footer.parentElement.insertBefore(smart,loc.footer);
     }
   }else if(loc.before && loc.before.parentElement){
     if(smart.nextElementSibling!==loc.before || smart.parentElement!==loc.before.parentElement){
       loc.before.parentElement.insertBefore(smart,loc.before);
     }
   }else if(smart.nextElementSibling!==loc.footer){
     loc.footer.parentElement.insertBefore(smart,loc.footer);
   }
   smart.setAttribute('data-barah-v6616-moved','yes');
   return true;
 }
 function start(){
   run();
   if(!window.MutationObserver)return;
   observer=new MutationObserver(function(){
     if(armed)return;
     armed=true;
     requestAnimationFrame(function(){
       armed=false;
       if(++ticks<=120)run();
       else if(observer)observer.disconnect();
     });
   });
   observer.observe(document.body,{childList:true,subtree:true});
   setTimeout(function(){if(observer)observer.disconnect();run();},9000);
 }
 if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',start,{once:true});
 else start();
})();


/* BARAH V66.17 — smart-needs desktop fluid card sizing; mobile unchanged */
(function(){
  'use strict';
  if(!/^\/(?:ar|en)?\/?$/.test(location.pathname))return;
  var sid='barah-v6617-smart-desktop-fluid';
  if(document.getElementById(sid))return;
  var css=`
@media (min-width:768px){
  /* Full-width footer row, not a narrow footer column */
  footer #barah-step-needs-v51,
  footer .barah-smart-footer-slot > #barah-step-needs-v51,
  #barah-step-needs-v51 {
    width: min(100% - 32px, 1180px) !important;
    max-width:1180px !important;
    min-width:0 !important;
    margin:24px auto !important;
    box-sizing:border-box !important;
    flex-basis:100% !important;
    grid-column:1 / -1 !important;
    float:none !important;
  }
  #barah-step-needs-v51 .barah-v664-needs-shell{
    width:100% !important;
    max-width:none !important;
    min-width:0 !important;
    padding:clamp(14px,1.8vw,24px) !important;
  }
  #barah-step-needs-v51 .barah-v664-needs-grid{
    display:grid !important;
    grid-template-columns:repeat(3,minmax(0,1fr)) !important;
    gap:clamp(10px,1.4vw,18px) !important;
    width:100% !important;
  }
  #barah-step-needs-v51 .barah-v664-need{
    display:flex !important;
    flex-direction:row !important;
    align-items:center !important;
    gap:clamp(10px,1vw,16px) !important;
    min-width:0 !important;
    width:100% !important;
    padding:clamp(10px,1vw,15px) !important;
  }
  #barah-step-needs-v51 .barah-v664-need img{
    width:clamp(78px,8vw,112px) !important;
    height:clamp(78px,8vw,112px) !important;
    max-width:34% !important;
    flex:0 0 auto !important;
    aspect-ratio:1 / 1 !important;
    object-fit:contain !important;
    background:#fff !important;
  }
  #barah-step-needs-v51 .barah-v664-need span{min-width:0 !important;flex:1 1 auto !important}
  #barah-step-needs-v51 .barah-v664-need strong{
    font-size:clamp(13px,1.04vw,16px) !important;
    line-height:1.5 !important;
    overflow-wrap:anywhere !important;
  }
  #barah-step-needs-v51 .barah-v664-need small{font-size:clamp(11px,.86vw,13px) !important}
}
@media (min-width:768px) and (max-width:1099px){
  #barah-step-needs-v51 .barah-v664-needs-grid{grid-template-columns:repeat(2,minmax(0,1fr)) !important}
}
`;
  var st=document.createElement('style');st.id=sid;st.textContent=css;
  (document.head||document.documentElement).appendChild(st);
})();


/* BARAH V66.18 — full-width desktop smart needs before footer; mobile unchanged */
(function(){
  'use strict';
  if(!/^\/(?:ar|en)?\/?$/.test(location.pathname))return;
  var id='barah-v6618-smart-width-style';
  if(document.getElementById(id))return;
  var st=document.createElement('style');st.id=id;
  st.textContent=`@media(min-width:768px){
  body > #barah-step-needs-v51, #barah-step-needs-v51{
    display:block!important; width:calc(100% - 40px)!important;
    max-width:1180px!important; min-width:0!important;
    margin:28px auto!important; clear:both!important;
    grid-column:auto!important; flex:none!important;
  }
  #barah-step-needs-v51 .barah-v664-needs-grid{
    display:grid!important; grid-template-columns:repeat(3,minmax(0,1fr))!important;
    gap:clamp(12px,1.5vw,20px)!important;
  }
  #barah-step-needs-v51 .barah-v664-need{min-width:0!important}
}
@media(min-width:768px) and (max-width:1099px){
 #barah-step-needs-v51 .barah-v664-needs-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important}
}`;
  document.head.appendChild(st);
})();


/* BARAH V66.19 — Senior angle follows Smart Needs, preserving responsive styles */
(function(){
 'use strict';
 if(!/^\/(?:ar|en)?\/?$/.test(location.pathname))return;
 var smartID='barah-step-needs-v51',seniorID='barah-step-senior-v57';
 var scheduled=false,observer=null,tries=0;
 function place(){
  var smart=document.getElementById(smartID),senior=document.getElementById(seniorID);
  if(!smart||!senior||!smart.parentNode)return false;
  if(smart.nextElementSibling===senior)return true;
  smart.insertAdjacentElement('afterend',senior);
  return true;
 }
 function schedule(){
  if(scheduled)return;scheduled=true;
  requestAnimationFrame(function(){scheduled=false;place();});
 }
 function begin(){
  place();
  if(!window.MutationObserver)return;
  observer=new MutationObserver(function(){if(++tries>300){observer.disconnect();return;}schedule();});
  observer.observe(document.body,{childList:true,subtree:true});
  setTimeout(function(){if(observer)observer.disconnect();place();},14000);
 }
 if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',begin,{once:true});
 else begin();
})();

/* =============================================================
 BARAH V66.20 | JUST REFRESHED | ADDITIVE MODULE ONLY
 Source: verified Salla items (initial snapshot).
 For TRUE automatic content/image-only updates, supply a public JSON
 endpoint via window.BARAH_IMPROVEMENTS_FEED_URL before this block,
 or call window.BARAH_RefreshImprovedProducts(array) from a trusted
 integration. No credentials or Salla admin API in browser.
 ============================================================= */
(function(){
 'use strict';
 if(window.__BARAH_V6620_IMPROVED__)return;
 window.__BARAH_V6620_IMPROVED__=true;
 var path=(location.pathname||'/').replace(/\/+$/,'')||'/';
 if(!(/^(\/|\/ar|\/en)$/.test(path)||(location.hostname==='salla.sa'&&path==='/br1')))return;
 var ROOT='barah-v6620-improved',STYLE='barah-v6620-improved-style';
 var START=[{"id":"1810209528","name":"مشد قميص رجالي نصف كم لتنسيق البطن والقوام","image":"https://cdn.salla.sa/qwxGZ/d2bd95f3-f864-4270-a3e3-b0c6354fe1f5-500x500-1lZRaxLMEAsnXSJQrarwnmmbIEVWVS5TxCkSS8s5.jpg","url":"https://barahstore.com/ar/product-1810209528/p1810209528","updated_at":"2026-10-07T00:47:38"},{"id":"1500742178","name":"مشد خصر حراري نسائي قابل للتعديل للرياضة والمشي","image":"https://cdn.salla.sa/qwxGZ/5525ef83-35df-4931-b0d8-9008f0a5b27f-500x500-Y6r8xiVhiLisRsTZYjaR9zDqONuMuCCxRFgjSQHn.png","url":"https://barahstore.com/ar/product-1500742178/p1500742178","updated_at":"2026-10-05T07:21:17"},{"id":"516022859","name":"طقم أشرطة مقاومة رياضية للتمارين – 3 قطع","image":"https://cdn.salla.sa/qwxGZ/vzAqxOR5dyoffIPYYdMqG6nNooZNYc8T5ms33TGd.png","url":"https://barahstore.com/ar/product-516022859/p516022859","updated_at":"2026-10-04T18:12:02"},{"id":"52063304","name":"عجلة مزدوجة لتمارين البطن والجذع","image":"https://cdn.salla.sa/qwxGZ/1433e559-501e-4378-8bc7-1c26af230cb1-500x500-BImmxYrP5WcBr68eiuc607SzTJ1JA1kKCE0gBvrR.png","url":"https://barahstore.com/ar/product-52063304/p52063304","updated_at":"2026-10-04T17:07:37"},{"id":"1601578360","name":"ستاند توابل دوار 360° مع 18 علبة زجاجية","image":"https://cdn.files.salla.network/products/71627348/e1fd1d60-4efc-4238-bad7-05a177987700-original.webp","url":"https://barahstore.com/ar/product-1601578360/p1601578360","updated_at":"2026-10-03T23:20:22"},{"id":"312967765","name":"منظم مطبخ بطبقتين للبهارات والزيوت","image":"https://cdn.salla.sa/qwxGZ/06f0241b-9af4-427e-953c-53016121981e-500x500-x5OnbHQteumZRjVNHbwuySTMar3HTaDS9fcbEts3.png","url":"https://barahstore.com/ar/product-312967765/p312967765","updated_at":"2026-09-28T18:20:26"}];
 var records=START.slice(), apiReady=false, attempts=0;
 function allowedURL(v,cdn){
  try{var u=new URL(String(v||''),location.href);
   if(u.protocol!=='https:')return '';
   var h=u.hostname.toLowerCase();
   if(cdn)return (h==='cdn.salla.sa'||h==='cdn.files.salla.network'||h==='files.salla.sa'||h==='barahstore.com'||h==='www.barahstore.com')?u.href:'';
   return (h==='barahstore.com'||h==='www.barahstore.com')?u.href:'';
  }catch(e){return '';}
 }
 function normalize(raw){
  var data=Array.isArray(raw)?raw:(raw&&Array.isArray(raw.products)?raw.products:[]),seen={},out=[];
  data.forEach(function(p){
   if(!p||typeof p!=='object')return;
   if(p.change_type&&['description','image','images','content','description_and_images'].indexOf(p.change_type)===-1)return;
   if(p.status&&p.status!=='sale')return;
   if(p.is_available===false)return;
   var id=String(p.id||'').trim();if(!/^\d{2,}$/.test(id)||seen[id])return;
   var name=String(p.name||'').trim().slice(0,120);
   var image=allowedURL(p.image||p.main_image||p.thumbnail,true);
   var url=allowedURL(p.url||('https://barahstore.com/ar/product-'+id+'/p'+id),false);
   if(!name||!image||!url)return;
   seen[id]=true;
   out.push({id:id,name:name,image:image,url:url,updated_at:String(p.improved_at||p.updated_at||'')});
  });
  out.sort(function(a,b){return b.updated_at.localeCompare(a.updated_at);});
  return out.slice(0,6);
 }
 function styles(){
  if(document.getElementById(STYLE))return;
  var s=document.createElement('style');s.id=STYLE;
  s.textContent=`
 #${ROOT}{direction:rtl;box-sizing:border-box;width:min(1180px,calc(100% - 40px));margin:24px auto;clear:both;font-family:inherit}
 #${ROOT} *{box-sizing:border-box}
 #${ROOT} .b6620-shell{padding:18px;border:1px solid #f0dfd4;border-radius:20px;background:linear-gradient(145deg,#fff9f5,#fff);box-shadow:0 7px 24px rgba(35,24,18,.035)}
 #${ROOT} .b6620-head{margin:0 0 13px}
 #${ROOT} h2{font-size:clamp(19px,2vw,24px);font-weight:900;line-height:1.4;margin:0;color:#261a16}
 #${ROOT} .b6620-sub{font-size:12px;line-height:1.7;color:#75645a;margin:4px 0 0}
 #${ROOT} .b6620-grid{display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:10px}
 #${ROOT} .b6620-item{display:flex;flex-direction:column;min-width:0;overflow:hidden;background:white;border:1px solid #f0e4dc;border-radius:13px;text-decoration:none;color:inherit}
 #${ROOT} .b6620-item:focus-visible{outline:2px solid #ea6428;outline-offset:2px}
 #${ROOT} .b6620-img{display:block;width:100%;aspect-ratio:1/1;object-fit:contain;background:white;padding:8px}
 #${ROOT} .b6620-name{padding:0 9px;font-size:12px;font-weight:800;color:#30231c;line-height:1.55;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;overflow:hidden;min-height:37px}
 #${ROOT} .b6620-cta{color:#d84c23;font-size:11px;font-weight:900;padding:7px 9px 10px;margin-top:auto}
 @media(max-width:767px){#${ROOT}{width:calc(100% - 24px);margin:17px 12px}#${ROOT} .b6620-shell{padding:12px;border-radius:16px}#${ROOT} .b6620-grid{grid-template-columns:repeat(3,minmax(0,1fr));gap:7px}#${ROOT} .b6620-img{padding:5px}#${ROOT} .b6620-name{font-size:10px;min-height:31px;padding:0 6px}#${ROOT} .b6620-cta{font-size:10px;padding:6px}}
 @media(prefers-reduced-motion:reduce){#${ROOT} *{transition:none!important;animation:none!important}}
 `;
  (document.head||document.documentElement).appendChild(s);
 }
 function anchor(){
  var headings=document.querySelectorAll('h2,h3,h4');
  for(var i=0;i<headings.length;i++){
   if((headings[i].textContent||'').trim()==='روابط مهمة'){
    var block=headings[i].closest('section')||headings[i].closest('.container')||headings[i].parentElement;
    if(block&&block.parentElement&&block!==document.body)return {parent:block.parentElement,before:block};
   }
  }
  var footer=document.querySelector('footer');
  if(footer&&footer.parentElement)return {parent:footer.parentElement,before:footer};
  var main=document.querySelector('main');
  if(main)return {parent:main,before:null};
  return null;
 }
 function render(){
  var a=anchor(),list=normalize(records),section=document.getElementById(ROOT);
  if(!a||!list.length){if(section)section.remove();return false;}
  styles();
  if(!section){section=document.createElement('section');section.id=ROOT;section.setAttribute('aria-label','جددناها لك');}
  var shell=document.createElement('div');shell.className='b6620-shell';
  var head=document.createElement('div');head.className='b6620-head';
  var h=document.createElement('h2');h.textContent='جددناها لك ✨';head.appendChild(h);
  var sub=document.createElement('p');sub.className='b6620-sub';sub.textContent='منتجات اعتنينا بتفاصيلها لتختار بسهولة';head.appendChild(sub);shell.appendChild(head);
  var grid=document.createElement('div');grid.className='b6620-grid';
  list.forEach(function(p,idx){
   var link=document.createElement('a');link.className='b6620-item';link.href=p.url;link.setAttribute('aria-label','عرض '+p.name);
   var img=document.createElement('img');img.className='b6620-img';img.src=p.image;img.alt=p.name;img.loading='lazy';img.decoding='async';img.width=180;img.height=180;
   var title=document.createElement('span');title.className='b6620-name';title.textContent=p.name;
   var cta=document.createElement('span');cta.className='b6620-cta';cta.textContent='عرض وشراء ←';
   link.appendChild(img);link.appendChild(title);link.appendChild(cta);grid.appendChild(link);
  });
  shell.appendChild(grid);section.replaceChildren(shell);
  if(section.parentElement!==a.parent||section.nextElementSibling!==a.before)a.parent.insertBefore(section,a.before);
  return true;
 }
 window.BARAH_RefreshImprovedProducts=function(list){
  if(!Array.isArray(list))return false;
  var valid=normalize(list);if(!valid.length)return false;
  records=valid;render();return true;
 };
 function loadFeed(){
  var url=String(window.BARAH_IMPROVEMENTS_FEED_URL||'');
  if(!url)return;
  try{var u=new URL(url);if(u.protocol!=='https:')return;}catch(e){return;}
  if(!window.fetch)return;
  fetch(url,{mode:'cors',credentials:'omit',cache:'no-store'})
   .then(function(r){if(!r.ok)throw Error('feed');return r.json();})
   .then(function(data){if(!data||!Array.isArray(data.products))return;window.BARAH_RefreshImprovedProducts(data.products);})
   .catch(function(){ /* verified snapshot remains visible */ });
 }
 function boot(){
  if(render()||++attempts>=18)return;
  setTimeout(boot,300);
 }
 if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',function(){boot();loadFeed();},{once:true});
 else{boot();loadFeed();}
})();

/* ===== BARAH DAILY TRENDS V1: ADDITIVE MERGE ===== */
/* BARAH DAILY PICKS V1 — additive module, no existing script modifications.
   For VERIFIED Trends, publish a JSON feed and set FEED_URL below.
   Format: {"verified":true,"updated_at":"2026-10-09T18:00:00+03:00","products":[52063304,1601578360,312967765,1756234068,996822004,807230324]}
   IMPORTANT: An external scheduler/backend must update the feed. This script cannot query Google Trends itself.
*/
(function () {
  'use strict';
  const KEY = '__barahDailyPicksV1';
  if (window[KEY]) return;
  window[KEY] = true;

  const FEED_URL = ''; // HTTPS JSON endpoint with CORS enabled; optional
  const FALLBACK_POOLS = [
    [52063304,1601578360,312967765,1756234068,996822004,807230324],
    [2090702098,309591802,1562289482,122136640,1939425047,1431823985],
    [1609572776,213048676,84692289,700783522,1984977439,1169543961]
  ];
  const MAX_AGE_MS = 36 * 60 * 60 * 1000;
  const HOME = location.pathname.replace(/\/+$/, '') === '' ||
    /^\/(ar|en)$/.test(location.pathname.replace(/\/+$/, ''));
  if (!HOME) return;

  const style = document.createElement('style');
  style.id = 'barah-trends-v1-css';
  style.textContent = `
    #barah-daily-picks {box-sizing:border-box;max-width:1240px;margin:22px auto;padding:0 14px;direction:rtl;font-family:inherit}
    #barah-daily-picks * {box-sizing:border-box}
    #barah-daily-picks .bdp-head{display:flex;justify-content:space-between;align-items:center;gap:10px;margin-bottom:13px;flex-wrap:wrap}
    #barah-daily-picks .bdp-title{margin:0;font-size:clamp(19px,2.2vw,27px);font-weight:800;line-height:1.4;color:#272121}
    #barah-daily-picks .bdp-sub{margin:3px 0 0;font-size:12px;color:#736962}
    #barah-daily-picks .bdp-mark{font-size:12px;border:1px solid #ffcfbc;background:#fff5ef;padding:5px 10px;border-radius:99px;color:#a94420;font-weight:700}
    #barah-daily-picks .bdp-shell{border:1px solid #ffe1d4;background:linear-gradient(135deg,#fffaf7,#fff);padding:16px;border-radius:19px}
    #barah-daily-picks .bdp-products{min-height:100px}
    #barah-daily-picks salla-products-list{display:block}
    #barah-daily-picks .bdp-error{font-size:13px;color:#745c50;text-align:center;padding:20px}
    @media(max-width:767px){#barah-daily-picks{margin:16px auto;padding:0 10px}#barah-daily-picks .bdp-shell{padding:10px;border-radius:14px}#barah-daily-picks .bdp-head{align-items:start}#barah-daily-picks .bdp-title{font-size:20px}}
  `;
  document.head.appendChild(style);

  const uniqueIds = (x) => Array.from(new Set((Array.isArray(x)?x:[])
    .map(v => typeof v === 'object' && v !== null ? v.id : v)
    .map(v => Number(v)).filter(v=> Number.isSafeInteger(v) && v>0))).slice(0,6);

  // Stable daily rotation of actual in-catalog candidates, not a claim of Google Trends ranking.
  function fallback() {
    const today = new Date();
    const k = Number(new Intl.DateTimeFormat('en-CA',{timeZone:'Asia/Riyadh',day:'2-digit'}).format(today));
    return FALLBACK_POOLS[(k-1)%FALLBACK_POOLS.length];
  }

  async function readFeed() {
    if (!FEED_URL || !/^https:\/\//i.test(FEED_URL)) return null;
    try {
      const controller = new AbortController();
      const kill = setTimeout(()=>controller.abort(),4000);
      let res;
      try {res=await fetch(FEED_URL,{cache:'no-store',mode:'cors',signal:controller.signal});}
      finally {clearTimeout(kill);}
      if (!res.ok) return null;
      const data=await res.json();
      const ids=uniqueIds(data.products);
      const stamp=Date.parse(data.updated_at || '');
      if(data.verified !== true || ids.length!==6 || !Number.isFinite(stamp) ||
        stamp>Date.now()+300000 || Date.now()-stamp>MAX_AGE_MS) return null;
      return ids;
    } catch (_) {return null;}
  }

  async function render() {
    if (document.getElementById('barah-daily-picks')) return;
    const footer = document.querySelector('footer, .store-footer, #footer');
    if(!footer) return;
    const host=document.createElement('section');
    host.id='barah-daily-picks';
    host.setAttribute('aria-label','مختارات بارعة اليومية');
    host.innerHTML='<div class="bdp-shell"><div class="bdp-head"><div><h2 class="bdp-title">✨ مختارات بارعة اليوم</h2><p class="bdp-sub">منتجات مختارة تتجدد يوميًا من كتالوج بارعة</p></div><span class="bdp-mark">6 منتجات</span></div><div class="bdp-products"></div></div>';
    footer.parentNode.insertBefore(host,footer);
    const feedIds=await readFeed();
    const ids=feedIds || fallback();
    if(feedIds){
      host.querySelector('.bdp-title').textContent='📈 6 منتجات مرتبطة باتجاهات البحث';
      host.querySelector('.bdp-sub').textContent='تحديث موثق من رادار بارعة للسوق السعودي';
    }
    const container=host.querySelector('.bdp-products');
    const list=document.createElement('salla-products-list');
    list.setAttribute('source','selected');
    list.setAttribute('source-value',JSON.stringify(ids));
    list.setAttribute('limit','6');
    container.appendChild(list);
    // Prevent an empty promotional area when the theme does not register this component.
    setTimeout(()=>{
      if (!list.isConnected || !host.isConnected) return;
      const rendered = list.querySelector('a[href], .product-entry, .product-card, img');
      if (!rendered) host.remove();
    },7000);
  }
  if (document.readyState==='loading') document.addEventListener('DOMContentLoaded',render,{once:true});
  else render();
})();

/* ===== BARAH V65.9 CLEARANCE 50 MODULE (CONDITIONAL DISPLAY) ===== */
/* BARAH CLEARANCE 50 — SAFE PRESENTATION V1
   Add AFTER existing custom JS, or merge at end. No price changes.
   Feed from approved back-office data: window.BARAH_CLEARANCE_APPROVED = [
     {id:'123', title:'اسم المنتج', url:'https://barahstore.com/ar/.../p123', image:'https://cdn.salla.sa/...jpg', original:100, current:90, active:true, verified:true, verified_at:'2026-10-09T20:00:00+03:00'}
   ];
   Only renders products whose approved 10% discount is verified in Salla.
*/
(function () {
 'use strict';
 if(window.__BARAH_CLEARANCE_50_V1__) return;
 window.__BARAH_CLEARANCE_50_V1__=true;
 var path=(location.pathname||'/').replace(/\/+$/,'')||'/';
 if(!/^(\/|\/ar|\/en)$/.test(path))return;
 var ROOT='barah-clearance-50-v1';
 function approved(){
  var source=Array.isArray(window.BARAH_CLEARANCE_APPROVED)?window.BARAH_CLEARANCE_APPROVED:[];
  var used={};
  return source.filter(function(p){
    if(!p||!p.active||p.verified!==true||used[p.id]||!/^https:\/\/barahstore\.com\//.test(String(p.url||'')))return false;
    // Require a recently verified back-office price; client data itself is NOT live verification.
    var checked=Date.parse(String(p.verified_at||''));
    if(!Number.isFinite(checked)||checked>Date.now()+300000||Date.now()-checked>86400000)return false;
    var orig=Number(p.original), now=Number(p.current);
    if(!Number.isFinite(orig)||!Number.isFinite(now)||orig<=0||now<=0)return false;
    // Do not label an item 10% off unless price really is 10% (within SAR 0.02 rounding).
    if(Math.abs(now-Math.round(orig*90)/100)>0.021)return false;
    used[p.id]=true;return true;
  }).slice(0,50);
 }
 function mount(){
  if(document.getElementById(ROOT))return;
  var products=approved();
  if(!products.length)return;
  var main=document.querySelector('main');if(!main)return;
  var style=document.createElement('style');style.id=ROOT+'-style';
  style.textContent='#'+ROOT+'{direction:rtl;width:min(1180px,calc(100% - 24px));margin:22px auto;font-family:inherit}#'+ROOT+' *{box-sizing:border-box}#'+ROOT+' .bc-box{padding:17px;background:#fff9f4;border:1px solid #f5d7bf;border-radius:20px}#'+ROOT+' .bc-head{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:15px}#'+ROOT+' h2{font-size:22px;line-height:1.4;font-weight:900;margin:0;color:#281c18}#'+ROOT+' .bc-desc{font-size:12px;color:#755b4c;margin:4px 0 0}#'+ROOT+' .bc-grid{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:10px}#'+ROOT+' .bc-card{position:relative;display:flex;flex-direction:column;border:1px solid #f0e2d6;border-radius:15px;background:#fff;overflow:hidden;text-decoration:none;min-width:0}#'+ROOT+' img{width:100%;aspect-ratio:1;object-fit:contain;background:white}#'+ROOT+' .bc-badge{position:absolute;top:8px;right:8px;border-radius:9px;background:#db3b20;color:#fff;padding:5px 9px;font-size:12px;font-weight:900}#'+ROOT+' .bc-title{font-size:12px;line-height:1.6;font-weight:800;color:#27201b;padding:8px 9px;min-height:48px}#'+ROOT+' .bc-prices{padding:0 9px 9px;display:flex;gap:7px;align-items:center;flex-wrap:wrap}#'+ROOT+' .bc-new{font-size:15px;font-weight:900;color:#d3451e}#'+ROOT+' .bc-old{font-size:11px;text-decoration:line-through;color:#91847d}#'+ROOT+' .bc-cta{display:block;text-align:center;margin:auto 9px 10px;padding:10px 6px;background:linear-gradient(100deg,#ff7a18,#ef4444);color:white;border-radius:10px;font-size:12px;font-weight:900}#'+ROOT+' .bc-card:hover{border-color:#ef9b76}@media(max-width:800px){#'+ROOT+' .bc-grid{grid-template-columns:repeat(3,minmax(0,1fr))}}@media(max-width:600px){#'+ROOT+' .bc-box{padding:12px}#'+ROOT+' h2{font-size:18px}#'+ROOT+' .bc-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}#'+ROOT+' .bc-cta{font-size:11px}}';
  document.head.appendChild(style);
  var sec=document.createElement('section');sec.id=ROOT;sec.setAttribute('aria-label','عروض منتجات مختارة');
  var box=document.createElement('div');box.className='bc-box';
  var head=document.createElement('div');head.className='bc-head';
  var title=document.createElement('div');title.innerHTML='<h2>🔥 فرصة جديدة — خصم 10%</h2><p class="bc-desc">منتجات مختارة بأسعار مخفضة فعلية</p>';head.appendChild(title);box.appendChild(head);
  var grid=document.createElement('div');grid.className='bc-grid';
  products.forEach(function(p){
   var a=document.createElement('a');a.className='bc-card';a.href=p.url;
   var badge=document.createElement('span');badge.className='bc-badge';badge.textContent='خصم 10%';a.appendChild(badge);
   if(/^https:\/\//.test(String(p.image||''))){var im=document.createElement('img');im.src=p.image;im.alt=String(p.title||'منتج من بارعة');im.loading='lazy';im.decoding='async';a.appendChild(im);}
   var name=document.createElement('strong');name.className='bc-title';name.textContent=String(p.title||'منتج من بارعة');a.appendChild(name);
   var prices=document.createElement('div');prices.className='bc-prices';
   var now=document.createElement('span');now.className='bc-new';now.textContent=Number(p.current).toFixed(2)+' ر.س';
   var old=document.createElement('span');old.className='bc-old';old.textContent=Number(p.original).toFixed(2)+' ر.س';prices.appendChild(now);prices.appendChild(old);a.appendChild(prices);
   var cta=document.createElement('span');cta.className='bc-cta';cta.textContent='عرض وشراء ←';a.appendChild(cta);grid.appendChild(a);
  });
  box.appendChild(grid);sec.appendChild(box);
  var footer=document.querySelector('footer');
  if(footer&&footer.parentNode)footer.parentNode.insertBefore(sec,footer);
  else main.appendChild(sec);
 }
 if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',mount,{once:true});else mount();
})();



/* BARAH V65.10 — HIDE BLOG NAV LINK ONLY — 2026-10-09 */
(function () {
  'use strict';
  if (window.__BARAH_HIDE_BLOG_NAV_V1__) return;
  window.__BARAH_HIDE_BLOG_NAV_V1__ = true;

  var STYLE_ID = 'barah-hide-blog-nav-v1-style';
  if (!document.getElementById(STYLE_ID)) {
    var style = document.createElement('style');
    style.id = STYLE_ID;
    style.textContent = '[data-barah-hidden-blog-link="1"]{display:none!important;visibility:hidden!important}';
    (document.head || document.documentElement).appendChild(style);
  }

  function normalize(s) {
    return String(s || '').replace(/[\u064B-\u065F\u0670]/g, '').replace(/\s+/g, ' ').trim().toLowerCase();
  }
  function blogUrl(href) {
    try {
      var url = new URL(href, location.href);
      if (url.origin !== location.origin && !/(^|\.)barahstore\.com$/.test(url.hostname)) return false;
      return /(^|\/)(blog|blogs|blog-posts|articles|المدونة|مدونة)(\/|$)/i.test(decodeURIComponent(url.pathname));
    } catch (e) { return false; }
  }
  function isNavigation(a) {
    return !!a.closest('header,footer,nav,[role="navigation"],.main-menu,.mobile-menu,.mm-menu,.s-menu,.navbar,.footer-links,[class*="menu"],[class*="nav"],[class*="footer"],salla-menu');
  }
  function hideBlogLinks() {
    var links = document.querySelectorAll('a[href],button');
    for (var i = 0; i < links.length; i++) {
      var a = links[i];
      if (a.hasAttribute('data-barah-hidden-blog-link')) continue;
      if (!isNavigation(a)) continue;
      var label = normalize(a.textContent || a.getAttribute('aria-label') || a.getAttribute('title'));
      var href = a.getAttribute('href') || '';
      if (!blogUrl(href) && label !== 'المدونة' && label !== 'مدونة' && label !== 'blog') continue;
      var item = a.closest('li,[role="menuitem"]');
      var target = item && item.querySelectorAll('a,button').length === 1 ? item : a;
      target.setAttribute('data-barah-hidden-blog-link', '1');
    }
  }
  var pending = false;
  function schedule() {
    if (pending) return;
    pending = true;
    setTimeout(function () { pending = false; hideBlogLinks(); }, 80);
  }
  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', hideBlogLinks, {once:true});
  else hideBlogLinks();
  if (window.MutationObserver) {
    new MutationObserver(schedule).observe(document.documentElement, {childList:true,subtree:true});
  }
})();

/* BARAH V65.11 — FLOATING BACK TO TOP (ISOLATED) */
(function () {
  'use strict';
  if (window.__BARAH_BACK_TO_TOP_V6511__) return;
  window.__BARAH_BACK_TO_TOP_V6511__ = true;

  var ID = 'barah-back-to-top-v6511';
  var STYLE = 'barah-back-to-top-v6511-style';
  var btn, ticking = false;

  function mount() {
    if (!document.body || document.getElementById(ID)) return;
    if (!document.getElementById(STYLE)) {
      var style = document.createElement('style');
      style.id = STYLE;
      style.textContent = '\n' +
        '#' + ID + '{position:fixed!important;inset:auto auto 96px 18px!important;z-index:900!important;width:46px;height:46px;padding:0;border:1px solid rgba(255,255,255,.78);border-radius:15px;background:linear-gradient(135deg,#ff7a18,#ef4444);color:#fff;box-shadow:0 8px 22px rgba(120,45,18,.22);cursor:pointer;display:flex;align-items:center;justify-content:center;opacity:0;visibility:hidden;pointer-events:none;transform:translateY(12px);transition:opacity .2s,transform .2s,visibility .2s;-webkit-tap-highlight-color:transparent}' +
        '#' + ID + '[data-visible="yes"]{opacity:1;visibility:visible;pointer-events:auto;transform:translateY(0)}' +
        '#' + ID + ':focus-visible{outline:3px solid #222;outline-offset:3px}' +
        '#' + ID + ' svg{width:23px;height:23px;fill:none;stroke:currentColor;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round}' +
        '@media(max-width:767px){#' + ID + '{inset:auto auto 108px 12px!important;width:43px;height:43px;border-radius:14px}}' +
        '@media(prefers-reduced-motion:reduce){#' + ID + '{transition:none}}';
      (document.head || document.documentElement).appendChild(style);
    }
    btn = document.createElement('button');
    btn.type = 'button';
    btn.id = ID;
    btn.setAttribute('aria-label','العودة إلى أعلى الصفحة');
    btn.setAttribute('title','العودة للأعلى');
    btn.setAttribute('data-visible','no');
    btn.innerHTML = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="m6 14 6-6 6 6"/><path d="M12 8v11"/></svg>';
    btn.addEventListener('click', function () {
      var reduced = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
      window.scrollTo({top:0,behavior:reduced?'auto':'smooth'});
    });
    document.body.appendChild(btn);
    refresh();
  }
  function refresh() {
    ticking = false;
    if (!btn) return;
    var y = window.scrollY || document.documentElement.scrollTop || 0;
    btn.setAttribute('data-visible', y > 380 ? 'yes' : 'no');
  }
  function onScroll() {
    if (ticking) return;
    ticking = true;
    (window.requestAnimationFrame || function (fn) { return setTimeout(fn, 16); })(refresh);
  }
  window.addEventListener('scroll', onScroll, {passive:true});
  window.addEventListener('pageshow', onScroll);
  if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded',mount,{once:true});
  else mount();
})();

/* BARAH V66.7 — HIDE PREGNANCY HOMEPAGE SECTION — APPEND ONLY
   Only hides #barah-step-pregnancy-v55 on the homepage.
   Does not change catalog products, product pages, other blocks, or previous JS.
*/
(function () {
  'use strict';
  if (window.__BARAH_V667_HIDE_PREGNANCY__) return;
  window.__BARAH_V667_HIDE_PREGNANCY__ = true;

  var path = (location.pathname || '/').replace(/\/+$/, '') || '/';
  var isHome = /^(\/|\/ar|\/en)$/.test(path) ||
    (location.hostname === 'salla.sa' && path === '/br1');
  if (!isHome) return;

  var STYLE_ID = 'barah-v667-hide-pregnancy-style';
  if (document.getElementById(STYLE_ID)) return;

  var style = document.createElement('style');
  style.id = STYLE_ID;
  style.textContent =
    'html #barah-step-pregnancy-v55{' +
    'display:none!important;' +
    'visibility:hidden!important;' +
    'margin:0!important;' +
    'padding:0!important;' +
    'height:0!important;' +
    'min-height:0!important;' +
    'border:0!important;' +
    'overflow:hidden!important;' +
    '}';
  (document.head || document.documentElement).appendChild(style);
})();


/* BARAH V66.8 — SMART NEEDS TRIPLE MINI GALLERY (APPEND ONLY)
   Three authentic Salla product images per need; existing links remain unchanged.
   Works in V52 feature & mission cards, V66.4 fallback cards if present.
*/
(function(){
 'use strict';
 var path=(location.pathname||'/').replace(/\/+$/,'')||'/';
 if(!(/^\/(?:ar|en)?$/.test(path)||(location.hostname==='salla.sa'&&path==='/br1')))return;
 if(window.__BARAH_V668_SMART_THREES__)return;
 window.__BARAH_V668_SMART_THREES__=true;
 var IMAGES={"senior":["https://cdn.salla.sa/qwxGZ/8d8067fa-a071-4028-9cb5-04261fd3cb8f-494.62365591398x500-85G9UGdwfYJa081ypGrrAT7RH3xFBHE7EQQqzqqK.jpg","https://cdn.files.salla.network/other/71627348/24e47f96-c19d-4e34-90c8-2c64c1a51463-original.webp","https://cdn.salla.sa/qwxGZ/93e4c485-a733-4fc7-9bfe-9df8b3461e04-400.18832391714x500-R4fKARoDyNXeOypn9KLhFsqorM9VOXRgWzvqhhsc.jpg"],"mom":["https://cdn.salla.sa/qwxGZ/1303a6b2-8e16-446d-8b43-d09f5b2d9fb5-500x500-6HVEqz3wmVOrTcMrwf7W00Dcc0IPKtMrq2vnPj2X.png","https://cdn.salla.sa/qwxGZ/83ef2a72-e967-489d-81e9-e8d689d75da5-500x500-O7Ee4vyZsl48GMNuEQBihTaivZh4Z9lcs8oQZp2L.jpg","https://cdn.salla.sa/qwxGZ/265418ff-b200-438a-95eb-a5016689bb4a-332.79115159401x500-6Ad5qqHMbia8TJM1aUfRZqsK7vmhnU162yFRDj6X.png"],"fitness":["https://cdn.salla.sa/qwxGZ/759fdbba-e692-4666-bd71-4aa9e8b82669-500x500-pSIX1qfbS1sQVPd1zJCmICzLn9vwTLcjQ8Fx1zwP.png","https://cdn.salla.sa/qwxGZ/7f7b5507-608a-47f1-ad08-bc444b268576-500x491.44869215292-lc3jRBXRYpCGrtC4oGGR3Z1nMBlnh5gp9m0japBn.jpg","https://cdn.salla.sa/qwxGZ/eb0ecbde-e7bc-45fe-a69d-ef82e601d548-500x500-zI9nWbMmUbqNlUCRQAJauG66yqlMiW8OMPZjUohN.jpg"],"shapewear":["https://cdn.salla.sa/qwxGZ/5525ef83-35df-4931-b0d8-9008f0a5b27f-500x500-Y6r8xiVhiLisRsTZYjaR9zDqONuMuCCxRFgjSQHn.png","https://cdn.files.salla.network/products/71627348/f06a7d1c-8084-473b-a8df-cadd9093c593-original.webp","https://cdn.salla.sa/qwxGZ/dba44baa-dec8-484d-9ac0-e43c6174a596-500x500-LAFjduu7g3WIbFjZZPNeU6SOaHJTjMSPJ05roNMU.png"],"travel":["https://cdn.salla.sa/qwxGZ/4b815965-eff9-484b-b074-272bb289edf1-500x500-gQJhQXaDTOpKkdVxnRgwyg1krORqeeEi2V3xZcqr.webp","https://cdn.salla.sa/qwxGZ/e0af44af-72dd-4c68-b05b-2c28529b8a2e-375x500-eEBexxs1kbq9wUmdNe43riWzzHQ9mt3EZ8acQGYs.png","https://cdn.salla.sa/qwxGZ/f60b4eaf-280d-4c18-baee-8b5081a48caf-333.33333333333x500-5tugmDxWADa6ZugZYEUayu05SSZyGT99PUsrjttD.png"],"home":["https://cdn.files.salla.network/products/71627348/e1fd1d60-4efc-4238-bad7-05a177987700-original.webp","https://cdn.salla.sa/qwxGZ/9bd08918-39f9-4225-8022-1cf793704041-374.89539748954x500-pyBjZeQec06FM99ZN8aH0IbIctJzpUgRZDuXKPC0.jpg","https://cdn.salla.sa/qwxGZ/30ee85f0-b82b-4ec8-86f3-9e64f144099b-500x500-de7naa2Yumma5QfU7kMl2e5cTb4e3lEVqVvoCQed.png"],"car":["https://cdn.salla.sa/qwxGZ/0c06a8b1-4201-4410-a122-2dc149fc27ed-439.39393939394x500-BV3KTLKPW9yXoHwRoQi3rGbn3Ud6hCvsvAnYRg2q.jpg","https://cdn.files.salla.network/products/71627348/07064923-7a60-4979-9ff2-1604ccdd71ae-original.webp","https://cdn.salla.sa/qwxGZ/d98864f7-400c-430e-9825-32e0a0b0223b-500x500-kDUDgJLK2YIub1rKjMZ5ZDWTiXjF9VpLbMvBIfaT.jpg"],"care":["https://cdn.files.salla.network/products/71627348/9aea9ae9-a088-43d6-b567-923ae96103d9-original.webp","https://cdn.salla.sa/qwxGZ/1b4ff582-71c1-4973-9859-a5cfeba89822-500x491.8998527246-rlsLrHvU6oyvX3WfIqfWiydXACCQIzhY1cdwOEwW.jpg","https://cdn.files.salla.network/products/71627348/15a4b9d0-598d-4926-81ee-8d510edec1d6_900x900.webp"]};
 var style=document.createElement('style');
 style.id='barah-v668-threes-style';
 style.textContent=`
 #barah-step-needs-v51 .barah-v668-three{display:grid!important;grid-template-columns:repeat(3,minmax(0,1fr))!important;gap:6px!important;width:100%!important;margin:11px 0 7px!important;direction:rtl!important;min-width:0!important}
 #barah-step-needs-v51 .barah-v668-three img{display:block!important;width:100%!important;max-width:100%!important;min-width:0!important;aspect-ratio:1/1!important;height:auto!important;object-fit:contain!important;background:#fff!important;border:1px solid #f0e2d8!important;border-radius:11px!important;padding:3px!important;box-shadow:0 3px 9px rgba(40,24,10,.045)!important}
 #barah-step-needs-v51 .v52-feature .barah-v668-three{max-width:285px!important;align-self:flex-start!important}
 #barah-step-needs-v51 .v52-mission .barah-v668-three{gap:5px!important;margin:8px 0 4px!important}
 #barah-step-needs-v51 .v52-mission .barah-v668-three img{border-radius:8px!important;padding:2px!important}
 #barah-step-needs-v51 .barah-v664-need .barah-v668-three{margin:2px 0 4px!important}
 #barah-step-needs-v51 .barah-v664-need .barah-v668-three img{width:100%!important;height:auto!important;aspect-ratio:1/1!important;padding:2px!important;border-radius:7px!important}
 @media(max-width:767px){
   #barah-step-needs-v51 .v52-feature .barah-v668-three{max-width:235px!important}
   #barah-step-needs-v51 .v52-mission .barah-v668-three{gap:3px!important;margin:7px 0 3px!important}
   #barah-step-needs-v51 .v52-mission .barah-v668-three img{padding:1px!important;border-radius:6px!important}
 }
 `;
 (document.head||document.documentElement).appendChild(style);
 function gallery(key){
   var el=document.createElement('div');el.className='barah-v668-three';
   el.setAttribute('aria-label','صور منتجات من بارعة');
   (IMAGES[key]||[]).slice(0,3).forEach(function(url,i){
     var img=document.createElement('img');img.src=url;img.alt='مثال منتج '+(i+1);
     img.loading='lazy';img.decoding='async';img.width=90;img.height=90;
     img.addEventListener('error',function(){img.style.display='none';},{once:true});
     el.appendChild(img);
   });return el;
 }
 function add(card,key,before){
   if(!card||card.querySelector('.barah-v668-three'))return;
   var g=gallery(key);
   if(before&&before.parentNode===card)card.insertBefore(g,before);
   else card.appendChild(g);
 }
 function apply(){
   var root=document.getElementById('barah-step-needs-v51');if(!root)return;
   var featured=root.querySelectorAll('.v52-feature');
   if(featured.length){featured.forEach(function(card,i){
     add(card,card.classList.contains('senior')?'senior':card.classList.contains('mom')?'mom':i===0?'senior':'mom',card.querySelector('.v52-feature-cta'));
   });}
   var keys=['fitness','shapewear','travel','home','car','care'];
   root.querySelectorAll('.v52-mission-grid .v52-mission').forEach(function(card,i){
     if(keys[i])add(card,keys[i],null);
   });
   var fallback=['fitness','home','care','car','mom','senior'];
   root.querySelectorAll('.barah-v664-needs-grid .barah-v664-need').forEach(function(card,i){
     if(!fallback[i])return;
     var previous=card.querySelector(':scope > img');
     if(previous)previous.style.display='none';
     add(card,fallback[i],card.querySelector(':scope > span'));
   });
 }
 var count=0;
 function run(){apply();if(++count>=24)clearInterval(timer);}
 var timer=setInterval(run,500);
 if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',apply,{once:true});
 else apply();
})();


/* BARAH V66.9 — REMOVE REDUNDANT SENIOR CORNER — APPEND ONLY
   Homepage only. Does not touch product pages, smart discovery, or V66.8 images.
*/
(function(){
  'use strict';
  if(window.__BARAH_V669_NO_SENIOR_CORNER__)return;
  window.__BARAH_V669_NO_SENIOR_CORNER__=true;
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  if(!(p==='/'||p==='/ar'||p==='/en'||(location.hostname==='salla.sa'&&p==='/br1')))return;
  var id='barah-step-senior-v57';
  var css=document.createElement('style');
  css.id='barah-v669-no-senior-corner-style';
  css.textContent='#'+id+'{display:none!important;visibility:hidden!important;height:0!important;min-height:0!important;margin:0!important;padding:0!important;border:0!important;overflow:hidden!important}';
  (document.head||document.documentElement).appendChild(css);
  function clean(){var el=document.getElementById(id);if(el)el.remove();}
  clean();
  if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',clean,{once:true});
  var root=document.querySelector('main')||document.body||document.documentElement;
  if(window.MutationObserver){
    var observer=new MutationObserver(function(records){
      for(var i=0;i<records.length;i++){
        if(records[i].addedNodes.length){clean();break;}
      }
    });
    observer.observe(root,{childList:true,subtree:true});
  }
  [500,1500,3500,7000,11000].forEach(function(ms){setTimeout(clean,ms);});
})();

/* BARAH V66.9.3 — Smart needs cards responsive enhancement.
   Appended to validated V66.9.2; no changes to latest-products logic.
   Mobile: one mission card per row; larger full product photos.
   Desktop: subtle emphasis; retain three columns.
*/
(function(){
  'use strict';
  var p=(location.pathname||'/').replace(/\/+$/,'')||'/';
  if(!(p==='/'||p==='/ar'||p==='/en'||(location.hostname==='salla.sa'&&p==='/br1')))return;
  var ID='barah-v6693-smart-missions-css';
  if(document.getElementById(ID))return;
  var s=document.createElement('style');s.id=ID;
  s.textContent=`
  @media (min-width:768px){
    #barah-step-needs-v51 .v52-mission-grid{gap:14px!important}
    #barah-step-needs-v51 .v52-mission{padding:17px!important;min-height:165px!important;border-radius:19px!important;box-shadow:0 10px 24px rgba(36,24,18,.055)!important}
    #barah-step-needs-v51 .v52-mission strong{font-size:15px!important;line-height:1.6!important}
    #barah-step-needs-v51 .v52-mission small{font-size:12px!important;line-height:1.7!important}
    #barah-step-needs-v51 .v52-mission .barah-v668-three{gap:8px!important;margin-top:12px!important}
    #barah-step-needs-v51 .v52-mission .barah-v668-three img{padding:3px!important;border-radius:10px!important}
  }
  @media (max-width:767px){
    #barah-step-needs-v51 .v52-mission-grid{display:grid!important;grid-template-columns:minmax(0,1fr)!important;gap:12px!important}
    #barah-step-needs-v51 .v52-mission{display:block!important;min-width:0!important;width:100%!important;min-height:0!important;padding:16px!important;border-radius:18px!important;box-shadow:0 8px 20px rgba(36,24,18,.05)!important}
    #barah-step-needs-v51 .v52-mission-icon{width:44px!important;height:44px!important;font-size:21px!important}
    #barah-step-needs-v51 .v52-mission strong{font-size:17px!important;line-height:1.6!important;margin-bottom:6px!important}
    #barah-step-needs-v51 .v52-mission small{font-size:13px!important;line-height:1.75!important}
    #barah-step-needs-v51 .v52-mission .barah-v668-three{display:grid!important;grid-template-columns:repeat(3,minmax(0,1fr))!important;width:100%!important;max-width:none!important;gap:9px!important;margin:14px 0 3px!important}
    #barah-step-needs-v51 .v52-mission .barah-v668-three img{display:block!important;width:100%!important;min-width:0!important;height:auto!important;min-height:0!important;aspect-ratio:1/1!important;object-fit:contain!important;padding:4px!important;border-radius:11px!important;background:#fff!important}
  }
  `;
  (document.head||document.documentElement).appendChild(s);
})();

/* BARAH V66.9.6 — MOBILE LATEST TEXT CONTROL (REPLACES V66.9.4/5)
   Scoped DOM typography only; preserves Salla latest source, images, products, links.
   Does not rebuild cards or modify desktop.
*/
(function(){
 'use strict';
 var path=(location.pathname||'/').replace(/\/+$/,'')||'/';
 if(!(path==='/'||path==='/ar'||path==='/en'||(location.hostname==='salla.sa'&&path==='/br1')))return;
 if(window.__BARAH_V6696_LATEST_FIX__)return;
 window.__BARAH_V6696_LATEST_FIX__=true;
 var SCOPE='#barah-v643-mobile-latest .v643-grid';
 var titleSel='.s-product-card-content-title,.s-product-card-content-title a,.s-product-card-content-title *, .product-card__title,.product-card__name,.product-entry__title,.s-product-card-entry h3,.s-product-card-entry h4,custom-salla-product-card h3,custom-salla-product-card h4,salla-product-card h3,salla-product-card h4';
 var descSel='.s-product-card-content-sub,.s-product-card-content-description,.product-card__description,.product-entry__description,.s-product-card-entry .description,.s-product-card-content p';
 var priceSel='.s-product-card-price,.s-product-card-sale-price,.product-card__price,.s-product-card-content-price';
 var cardSel='.s-product-card-entry,.product-entry,.product-card,custom-salla-product-card,salla-product-card';
 var css=`@media(max-width:767px){
  ${titleSel.split(',').map(function(s){return SCOPE+' '+s.trim();}).join(',')}{font-size:12px!important;line-height:1.42!important;max-height:2.84em!important;min-height:0!important;display:-webkit-box!important;-webkit-line-clamp:2!important;-webkit-box-orient:vertical!important;overflow:hidden!important;font-weight:800!important;}
  ${descSel.split(',').map(function(s){return SCOPE+' '+s.trim();}).join(',')}{display:none!important;}
  ${SCOPE} .s-product-card-content,${SCOPE} .s-product-card-content-main{padding:8px!important;gap:4px!important;}
  ${SCOPE} img{object-fit:contain!important;}
 }`;
 var style=document.createElement('style');style.id='barah-v6696-mobile-latest-style';style.textContent=css;
 (document.head||document.documentElement).appendChild(style);
 function important(el,k,v){if(el&&el.style&&el.style.getPropertyValue(k)!==v)el.style.setProperty(k,v,'important');}
 function adjust(root){
  if(!root||!root.querySelectorAll)return;
  if(root!==document&&root.host){
   if(!root.querySelector('style[data-barah-latest-6696]')){
    var sh=document.createElement('style');sh.setAttribute('data-barah-latest-6696','');
    sh.textContent='@media(max-width:767px){'+titleSel+'{font-size:12px!important;line-height:1.42!important;max-height:2.84em!important;min-height:0!important;display:-webkit-box!important;-webkit-line-clamp:2!important;-webkit-box-orient:vertical!important;overflow:hidden!important;}'+descSel+'{display:none!important;}}';
    root.appendChild(sh);
   }
  }
  root.querySelectorAll(titleSel).forEach(function(el){
    important(el,'font-size','12px');important(el,'line-height','1.42');important(el,'max-height','2.84em');important(el,'min-height','0px');important(el,'display','-webkit-box');important(el,'-webkit-line-clamp','2');important(el,'-webkit-box-orient','vertical');important(el,'overflow','hidden');
  });
  root.querySelectorAll(descSel).forEach(function(el){important(el,'display','none');});
  root.querySelectorAll(priceSel).forEach(function(el){important(el,'font-size','12px');});
  root.querySelectorAll('img').forEach(function(el){important(el,'object-fit','contain');});
  root.querySelectorAll('*').forEach(function(el){if(el.shadowRoot)adjust(el.shadowRoot);});
 }
 function apply(){
  if(!window.matchMedia||!window.matchMedia('(max-width:767px)').matches)return;
  var host=document.querySelector(SCOPE);if(!host)return;
  adjust(host);
 }
 function boot(){
  apply();
  var host=document.querySelector(SCOPE);
  if(!host){var tries=0;var waiting=setInterval(function(){host=document.querySelector(SCOPE);if(host){clearInterval(waiting);boot();}else if(++tries>30)clearInterval(waiting);},400);return;}
  var queued=false;
  var observer=new MutationObserver(function(){if(queued)return;queued=true;requestAnimationFrame(function(){queued=false;apply();});});
  observer.observe(host,{childList:true,subtree:true});
  var checks=0;var timer=setInterval(function(){apply();if(++checks>=20)clearInterval(timer);},700);
  setTimeout(function(){observer.disconnect();},30000);
 }
 if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',boot,{once:true});else boot();
})();

/* ============================================================
 BARAH V66.9 FINAL — SAME CATEGORY AFTER PRODUCT DESCRIPTION
 INTEGRATED INTO THE EXISTING FULL JS
 - Product pages only
 - Keep existing Salla category source and products unchanged
 - Position directly after full product description
 - Compact this section's images/cards on mobile only
 - Do not alter homepage latest products or other sections
 ============================================================ */
(function(){
  'use strict';
  if(window.__BARAH_BUNDLE_AFTER_COMPLEMENT_FINAL__) return;
  window.__BARAH_BUNDLE_AFTER_COMPLEMENT_FINAL__=true;

  function isProductPage(){
    return /\/p\d+(?:[\/?#]|$)/i.test(location.pathname+location.search) ||
      !!document.body && (document.body.classList.contains('product-single') ||
      document.body.classList.contains('product-page'));
  }
  if(!isProductPage())return;

  var cssId='barah-bundle-final-mobile-compact-css';
  if(!document.getElementById(cssId)){
    var css=document.createElement('style');
    css.id=cssId;
    css.textContent=`
@media(max-width:767px){
  #barah-product-bundle{
    padding:12px!important;margin:14px 0 8px!important;border-radius:15px!important;
  }
  #barah-product-bundle .barah-bundle-head{margin-bottom:9px!important}
  #barah-product-bundle .barah-bundle-kicker{font-size:11px!important}
  #barah-product-bundle .barah-bundle-head h3{font-size:16px!important;line-height:1.4!important}
  #barah-product-bundle .barah-bundle-head p{font-size:11px!important;line-height:1.5!important}
  #barah-product-bundle .product-block__thumb,
  #barah-product-bundle .s-product-card-image,
  #barah-product-bundle .s-product-card-entry__image,
  #barah-product-bundle .product-card__image{
    height:116px!important;min-height:0!important;overflow:hidden!important;
  }
  #barah-product-bundle .product-block__thumb img,
  #barah-product-bundle .s-product-card-image img,
  #barah-product-bundle .s-product-card-entry__image img,
  #barah-product-bundle .product-card__image img{
    width:100%!important;height:110px!important;max-height:110px!important;object-fit:contain!important;
  }
  #barah-product-bundle .product-title h2,
  #barah-product-bundle .s-product-card-entry__title{
    font-size:12px!important;line-height:1.45!important;
    display:-webkit-box!important;-webkit-box-orient:vertical!important;
    -webkit-line-clamp:2!important;overflow:hidden!important;
  }
  #barah-product-bundle .product-title p{display:none!important}
}`;
    (document.head||document.documentElement).appendChild(css);
  }

  function place(){
    var bundle=document.getElementById('barah-product-bundle');
    // Place the EXISTING bundle directly after the complete description.
    var description=document.querySelector('article.pd-exp, .article--product-details.pd-exp, .product-description, [class*="product-description"]');
    if(!bundle || !description || !bundle.isConnected || !description.isConnected) return false;
    var block=description.closest('section.product-description, section.product-details-description') || description;
    if(block===bundle || block.contains(bundle) || bundle.contains(block) || !block.parentNode) return false;
    /* BARAH V67: final order controller handles section placement. */
    return true;
  }

  function boot(){
    if(place())return;
    var tries=0;
    var watch=setInterval(function(){
      tries++;
      if(place() || tries>=40)clearInterval(watch);
    },350);
  }
  if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',boot,{once:true});
  else boot();
})();


/* BARAH V66.9 — COMPLEMENTARY SECTION COPY ONLY (product pages)
   Keeps product links, category picks, existing colors and all other sections intact.
*/
(function(){
  'use strict';
  if(window.__BARAH_COMPLEMENT_COPY_V2__)return;
  window.__BARAH_COMPLEMENT_COPY_V2__=true;
  function isProduct(){return /\/p\d+(?:[\/?#]|$)/i.test(location.pathname+location.search)||document.body.classList.contains('product-single')||document.body.classList.contains('product-page');}
  if(!isProduct())return;
  function apply(){
    var section=document.querySelector('[data-barah-complement="pilot1"]');
    if(!section)return false;
    var heading=section.querySelector(':scope > h3');
    if(heading && heading.textContent.trim()!=='✨ كمّل احتياجك') heading.textContent='✨ كمّل احتياجك';
    var subtitle=section.querySelector(':scope > p');
    if(subtitle && subtitle.textContent.trim()!=='تفاصيل بسيطة تكمل تجربتك وتفيدك أكثر.') subtitle.textContent='تفاصيل بسيطة تكمل تجربتك وتفيدك أكثر.';
    return true;
  }
  function boot(){
    if(apply())return;
    var n=0, timer=setInterval(function(){if(apply()||++n>=36)clearInterval(timer);},350);
  }
  if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',boot,{once:true}); else boot();
})();

/* BARAH V67 — FINAL PRODUCT SECTION ORDER (surgical, existing sections only)
   Full description -> ✨ كمّل احتياجك -> منتجات إضافية قد تناسب احتياجك.
   Never clones, replaces, or regenerates these sections.
*/
(function(){
  'use strict';
  if(window.__BARAH_V67_PRODUCT_SECTION_ORDER__)return;
  window.__BARAH_V67_PRODUCT_SECTION_ORDER__=true;
  function productPage(){
    return /\/p\d+(?:[\/?#]|$)/i.test(location.pathname+location.search) ||
      document.body.classList.contains('product-single') ||
      document.body.classList.contains('product-page') ||
      !!document.querySelector('.page--product-details');
  }
  if(!productPage())return;
  var busy=false, timer=null, observer=null, count=0;
  function order(){
    if(busy)return false;
    busy=true;
    try{
      var desc=document.querySelector('article.pd-exp, .article--product-details.pd-exp, section.product-description, section.product-details-description, .product-description, .product-details-description');
      var complete=document.querySelector('[data-barah-complement="pilot1"]');
      var bundle=document.getElementById('barah-product-bundle');
      if(!desc||!desc.isConnected)return false;
      var block=desc.closest('section.product-description,section.product-details-description,.product-description-wrapper')||desc;
      if(!block.parentNode)return false;
      var anchor=block;
      if(complete&&complete.isConnected && !complete.contains(anchor)&&!anchor.contains(complete)){
        if(anchor.nextElementSibling!==complete)anchor.insertAdjacentElement('afterend',complete);
        anchor=complete;
      }
      if(bundle&&bundle.isConnected && !bundle.contains(anchor)&&!anchor.contains(bundle)){
        if(anchor.nextElementSibling!==bundle)anchor.insertAdjacentElement('afterend',bundle);
      }
      document.documentElement.dataset.barahProductOrderV67='ready';
      return !!(complete&&bundle);
    }finally{busy=false;}
  }
  function boot(){
    order();
    if(window.MutationObserver){
      var root=document.querySelector('main')||document.body;
      observer=new MutationObserver(function(){
        if(busy)return;
        clearTimeout(timer);
        timer=setTimeout(order,100);
      });
      observer.observe(root,{childList:true,subtree:true});
    }
    [250,750,1500,3000,6000,10000].forEach(function(ms){setTimeout(order,ms);});
  }
  if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',boot,{once:true});
  else boot();
})();

/* ================================================================
 BARAH V67.4 — WAGONS VERIFIED PRODUCT PHOTOS
 Fixes placeholder cards, uneven row, and failed image loading.
 The existing store modules above remain untouched.
 ================================================================ */
(function(){
 'use strict';
 var path=(location.pathname||'/').replace(/\/+$/,'')||'/';
 if(!(/^\/(?:ar|en)?$/.test(path)||(location.hostname==='salla.sa'&&path==='/br1')))return;
 if(window.__BARAH_WAGONS_HUB_V673__)return;
 window.__BARAH_WAGONS_HUB_V673__=true;
 var ID='barah-wagons-hub-v673',CSSID=ID+'-css';
 var origin='https://barahstore.com';
 var products=[
  {name:'عربة تسوق قابلة للطي بعجلات – عدة ألوان',kind:'shopping',tag:'للتسوق اليومي',url:'/ar/product-1234269562/p1234269562',image:'https://cdn.salla.sa/qwxGZ/c3d4bf6f-3fc2-4c58-8c7a-c7821a8b18af-1000x1000-hSqcm0hcCadDO1qt8dsYSSjn6got3R3Nek7fp798.jpg'},
  {name:'شنطة عربة تسوق قابلة للطي بعجلات للدرج',kind:'shopping',tag:'للتسوق والدرج',url:'/ar/product-1581623087/p1581623087',image:'https://cdn.salla.sa/qwxGZ/4f519925-da5e-45ac-9cf8-4ba185d62a0f-666.66666666667x1000-5tugmDxWADa6ZugZYEUayu05SSZyGT99PUsrjttD.png'},
  {name:'عربة تسوق قابلة للطي بعجلات',kind:'fold',tag:'سهلة الطي والتخزين',url:'/ar/product-1873347865/p1873347865',image:'https://cdn.salla.sa/qwxGZ/5af9f5f9-0742-48b7-87db-e4b5d64478d4-1000x1000-Aw3cjDw5tBSe4pXlT0hNhW0UWSHzV4kBsgfIUo3e.jpg'}
 ];
 var cached={};
 function esc(t){return String(t||'').replace(/[&<>"']/g,function(c){return {'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c];});}
 function search(q){return origin+'/ar/search?q='+encodeURIComponent(q);}
 function style(){if(document.getElementById(CSSID))return;var st=document.createElement('style');st.id=CSSID;st.textContent=`
 #${ID}{direction:rtl;max-width:1180px;width:calc(100% - 32px);margin:16px auto 24px;font-family:inherit;clear:both}
 #${ID} *{box-sizing:border-box}
 #${ID} .bw-shell{background:#fffaf7;border:1px solid #f0e2d9;border-radius:20px;padding:18px}
 #${ID} .bw-head{display:flex;align-items:center;justify-content:space-between;gap:14px;margin-bottom:14px}
 #${ID} h2{font-size:clamp(19px,2.6vw,26px);line-height:1.4;font-weight:900;margin:0;color:#2b211d}
 #${ID} .bw-lead{font-size:12px;line-height:1.6;color:#74665e;margin:4px 0 0}
 #${ID} .bw-all{font-size:12px;font-weight:800;color:#b74a1d;background:#fff;text-decoration:none;border:1px solid #efd5c3;padding:10px 12px;border-radius:10px;white-space:nowrap}
 #${ID} .bw-filters{display:flex;gap:7px;overflow-x:auto;scrollbar-width:thin;margin-bottom:12px}
 #${ID} .bw-filter{flex:0 0 auto;border:1px solid #eaddd4;background:#fff;color:#382b25;border-radius:999px;padding:8px 13px;font:inherit;font-size:12px;font-weight:800;cursor:pointer;min-height:39px}
 #${ID} .bw-filter[aria-pressed=true]{color:#fff;background:linear-gradient(120deg,#ff771a,#ef4839);border-color:#ef6531}
 #${ID} .bw-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:11px}
 #${ID} .bw-card{display:flex;flex-direction:column;min-width:0;overflow:hidden;border:1px solid #eee0d7;border-radius:15px;text-decoration:none;background:#fff;color:#2b211d}
 #${ID} .bw-photo{aspect-ratio:1/1;background:#f8f6f3;display:grid;place-items:center;overflow:hidden;position:relative}
 #${ID} .bw-photo img{display:block;width:100%;height:100%;object-fit:contain;object-position:center;padding:6px;mix-blend-mode:normal}
 #${ID} .bw-noimage{display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;gap:7px;color:#7d7168;padding:13px}
 #${ID} .bw-noimage svg{width:46px;height:46px;color:#e8723c}
 #${ID} .bw-noimage span{font-size:11px;line-height:1.5}
 #${ID} .bw-info{display:flex;flex:1;flex-direction:column;padding:12px;gap:6px}
 #${ID} .bw-tag{font-size:10px;color:#ad572b;font-weight:800}
 #${ID} .bw-name{font-size:13px;font-weight:850;line-height:1.65;min-height:43px;color:#2b211d}
 #${ID} .bw-buy{display:block;text-align:center;background:linear-gradient(120deg,#ff771a,#f04b39);color:#fff;font-size:12px;font-weight:900;border-radius:10px;padding:11px 5px;margin-top:auto}
 #${ID} .bw-explore{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-top:12px;padding:12px;background:#fff;border-radius:12px;border:1px solid #f1e2d9}
 #${ID} .bw-explore strong{font-size:12px;color:#2e2824}
 #${ID} .bw-explore a{font-size:12px;color:#ba4b20;text-decoration:none;font-weight:900}
 @media(max-width:767px){#${ID}{width:calc(100% - 24px);margin:14px 12px 19px}#${ID} .bw-shell{padding:11px;border-radius:16px}#${ID} .bw-head{flex-direction:column;align-items:stretch}#${ID} .bw-all{align-self:flex-start}#${ID} .bw-grid{display:flex;overflow-x:auto;gap:9px;scroll-snap-type:x mandatory;padding-bottom:6px}#${ID} .bw-card{flex:0 0 66%;scroll-snap-align:start}#${ID} .bw-info{padding:9px}#${ID} .bw-name{font-size:12px;min-height:58px}#${ID} .bw-explore{flex-direction:column;align-items:flex-start}#${ID} .bw-photo{aspect-ratio:1/1}}
 `;(document.head||document.documentElement).appendChild(st);}
 var icon='<svg viewBox="0 0 48 48" fill="none" stroke="currentColor" stroke-width="2.2" aria-hidden="true"><path d="M7 9h5l5 23h22l4-17H14"/><circle cx="20" cy="39" r="3"/><circle cx="36" cy="39" r="3"/></svg>';
 function cards(filter){var items=products.filter(function(p){return filter==='all'||(filter==='shopping'?p.kind==='shopping':filter==='fold'?p.kind==='fold':false);});return items.map(function(p){var i=products.indexOf(p);return '<a class="bw-card" data-product="'+i+'" href="'+esc(origin+p.url)+'"><div class="bw-photo">'+'<img loading="lazy" decoding="async" src="'+esc(p.image)+'" alt="'+esc(p.name)+'" onerror="this.style.opacity=0">'+'</div><div class="bw-info"><span class="bw-tag">'+esc(p.tag)+'</span><strong class="bw-name">'+esc(p.name)+'</strong><span class="bw-buy">عرض وشراء ←</span></div></a>';}).join('');}
 function hydrate(section){/* Verified Salla CDN image URLs are now embedded directly. */}
 function build(){var s=document.createElement('section');s.id=ID;s.setAttribute('aria-label','اختيار عربات التسوق');s.innerHTML='<div class="bw-shell"><div class="bw-head"><div><h2>🛒 عربة لكل مشوار… اختر اللي يناسبك</h2><p class="bw-lead">عربات عملية للتسوق والرحلات والمشاوير اليومية</p></div><a class="bw-all" href="'+esc(search('عربة'))+'">كل العربات ←</a></div><div class="bw-filters" role="group" aria-label="اختيار نوع العربة"><button class="bw-filter" data-filter="all" aria-pressed="true">الكل</button><button class="bw-filter" data-filter="shopping" aria-pressed="false">للتسوق</button><button class="bw-filter" data-filter="fold" aria-pressed="false">قابلة للطي</button><button class="bw-filter" data-filter="travel" aria-pressed="false">للرحلات</button></div><div class="bw-grid">'+cards('all')+'</div><div class="bw-explore"><strong>تبحث عن عربة للرحلات أو لنقل الأغراض؟</strong><a href="'+esc(search('عربة رحلات'))+'">استكشف عربات الرحلات ←</a></div></div>';
 s.addEventListener('click',function(e){var b=e.target.closest('button[data-filter]');if(!b)return;var f=b.getAttribute('data-filter');s.querySelectorAll('.bw-filter').forEach(function(x){x.setAttribute('aria-pressed',String(x===b));});if(f==='travel'){s.querySelector('.bw-grid').innerHTML='<div style="grid-column:1/-1;padding:18px;text-align:center;background:white;border-radius:12px"><strong>اكتشف خيارات الرحلات المتوفرة</strong><p><a href="'+esc(search('عربة رحلات'))+'">شاهد عربات الرحلات ←</a></p></div>';return;}s.querySelector('.bw-grid').innerHTML=cards(f);hydrate(s);});return s;}
 function latest(){var m=document.getElementById('barah-v643-mobile-latest');if(m&&matchMedia('(max-width:767px)').matches)return m;var nodes=Array.prototype.slice.call(document.querySelectorAll('section.barah-v35-latest,section.home-block.home-block--fixed-products.show-all,section[id*=latest]'));return nodes.find(function(n){return /وصل حديث|أحدث المنتجات|جديد بارعة/.test((n.textContent||'').slice(0,320));})||m;}
 function mount(){if(document.getElementById(ID))return true;var anchor=latest();if(!anchor||!anchor.parentNode)return false;style();var section=build();anchor.insertAdjacentElement('afterend',section);hydrate(section);return true;}
 function boot(){if(mount())return;var n=0,t=setInterval(function(){n++;if(mount()||n>=36)clearInterval(t);},300);}
 if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',boot,{once:true});else boot();
})();