<?php
/**
 * Early <head> script: standalone PWA without sessionStorage marker → server logout.
 * sessionStorage is tied to the web app “document”; it is usually cleared when the
 * standalone app is fully terminated, while the HTTP session cookie may survive.
 */
declare(strict_types=1);

if (!defined('BASE_PATH')) {
    return;
}
$sessionEndUrl = json_encode(BASE_PATH . '/mobile/session-end.php', JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_UNESCAPED_SLASHES);
?>
<script>
(function(){try{
  var dm=window.matchMedia;
  var pwa=dm&&(dm('(display-mode: standalone)').matches||dm('(display-mode: fullscreen)').matches);
  var ios=typeof navigator.standalone!=='undefined'&&navigator.standalone;
  if((pwa||ios)&&!sessionStorage.getItem('naz_m_pwa')){
    location.replace(<?= $sessionEndUrl ?>);
  }
}catch(e){}})();
</script>
