<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="csrf-token" content="<?= e(csrf_token()) ?>">
  <title><?= e($title ?? 'Staff Portal') ?> · AOSWARE CRM</title>
  <link rel="icon" href="<?= e(asset('img/aosware-crm-logo.jpg')) ?>">
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet">
  <link href="<?= e(asset('css/app.css')) ?>" rel="stylesheet">
  <script>
  (function () {
    try {
      var key = 'aoswareKeepScroll';
      var raw = sessionStorage.getItem(key);
      if (raw == null) return;
      sessionStorage.removeItem(key);
      var y = parseInt(raw, 10);
      if (isNaN(y) || y < 0) return;
      if ('scrollRestoration' in history) history.scrollRestoration = 'manual';
      document.documentElement.classList.add('is-keep-scroll');
      var go = function () { window.scrollTo(0, y); };
      go();
      document.addEventListener('DOMContentLoaded', go);
      window.addEventListener('load', function () {
        go();
        document.documentElement.classList.remove('is-keep-scroll');
      });
    } catch (e) {}
  })();
  </script>
</head>
<body class="app-body">
<div class="d-flex app-shell">
  <?php \App\Core\View::partial('sidebar', ['current' => $current ?? '']); ?>
  <div class="flex-grow-1 main-col">
    <?php \App\Core\View::partial('topbar', ['notifications' => $notifications ?? ['items' => [], 'count' => 0]]); ?>
    <div class="page">
      <?php if ($msg = flash('success')): ?><div class="alert alert-success"><?= e($msg) ?></div><?php endif; ?>
      <?php if ($msg = flash('error')): ?><div class="alert alert-danger"><?= e($msg) ?></div><?php endif; ?>
      <?= $content ?>
    </div>
  </div>
</div>
<?php \App\Core\View::partial('modals'); ?>
<script>window.APP_URL = <?= json_encode(url()) ?>;</script>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="<?= e(asset('js/app.js')) ?>"></script>
<?php if (!empty($scripts)) echo $scripts; ?>
</body>
</html>
