(function(){
'use strict';
var page=String(document.body&&document.body.getAttribute('data-native-sidebar-page')||'');
if(page.indexOf('diar-')!==0)return;
var sidebar=document.querySelector('[data-native-sidebar]');
var nav=sidebar&&sidebar.querySelector('[data-native-nav]');
if(!sidebar||!nav)return;
var key='diar.sidebar.scroll.'+(document.documentElement.dir==='rtl'?'rtl':'ltr');
function number(value){var n=parseInt(value,10);return Number.isFinite(n)?Math.max(0,n):0;}
function restore(){
  var saved=0;
  try{saved=number(window.sessionStorage.getItem(key));}catch(ignore){}
  nav.scrollTop=saved;
  var active=nav.querySelector('[aria-current="page"]');
  if(active){
    var nr=nav.getBoundingClientRect(),ar=active.getBoundingClientRect();
    if(ar.top<nr.top||ar.bottom>nr.bottom){active.scrollIntoView({block:'nearest',inline:'nearest'});}
  }
  document.documentElement.setAttribute('data-diar-sidebar-stability','READY');
}
function save(){try{window.sessionStorage.setItem(key,String(Math.round(nav.scrollTop)));}catch(ignore){}}
nav.addEventListener('scroll',save,{passive:true});
nav.querySelectorAll('a[href]').forEach(function(link){link.addEventListener('click',save,{passive:true});});
window.addEventListener('pagehide',save,{passive:true});
window.addEventListener('beforeunload',save,{passive:true});
if(document.readyState==='complete')requestAnimationFrame(restore);else window.addEventListener('load',function(){requestAnimationFrame(restore);},{once:true});
}());
