        </div>
      </div>
    </main>

    <!-- Footer -->
    <footer class="app-footer">
      <div class="float-end d-none d-sm-inline">Versi Demo</div>
      <strong>&copy; <?php echo date('Y'); ?> Sekolah Kita.</strong>
    </footer>

  </div>
  <!-- end app-wrapper -->

  <!-- Scripts: Bootstrap bundle (includes Popper) and AdminLTE JS -->
  <script src="<?php echo base_url(); ?>/assets/vendor/bootstrap5/js/bootstrap.bundle.min.js"></script>
  <script src="<?php echo base_url(); ?>/assets/dist/js/adminlte.min.js"></script>

  <script>
    // Persist Admin sidebar collapsed state (vanilla JS)
    (function(){
      try {
        function setCollapsed() {
          var collapsed = document.documentElement.classList.contains('sidebar-collapse') || document.body.classList.contains('sidebar-collapse');
          localStorage.setItem('adminSidebarCollapsed', collapsed ? '1' : '0');
        }
        // apply saved state on load
        if (localStorage.getItem('adminSidebarCollapsed') === '1') {
          document.documentElement.classList.add('sidebar-collapse');
          document.body.classList.add('sidebar-collapse');
        }
        // initial store
        setCollapsed();
        var obs = new MutationObserver(function(mutations){
          for (var m of mutations) {
            if (m.attributeName === 'class') { setCollapsed(); break; }
          }
        });
        obs.observe(document.documentElement, { attributes: true });
        obs.observe(document.body, { attributes: true });
      } catch(e){ console.error(e); }
    })();

    // Initialize treeview menu manually if AdminLTE doesn't auto-init
    document.addEventListener('DOMContentLoaded', function() {
      // Handle sidebar toggle (hamburger button)
      var sidebarToggle = document.querySelector('[data-lte-toggle="sidebar"]');
      if (sidebarToggle) {
        sidebarToggle.addEventListener('click', function(e) {
          e.preventDefault();
          
          // Toggle sidebar collapse
          document.documentElement.classList.toggle('sidebar-collapse');
          document.body.classList.toggle('sidebar-collapse');
          
          // Save state
          var isCollapsed = document.body.classList.contains('sidebar-collapse');
          try {
            localStorage.setItem('adminSidebarCollapsed', isCollapsed ? '1' : '0');
          } catch(err) {
            console.error('Failed to save sidebar state:', err);
          }
        });
      }
      
      // Handle treeview toggle - find all nav-items that have nav-treeview children
      var menuItems = document.querySelectorAll('.sidebar-menu .nav-item');
      console.log('Found menu items:', menuItems.length);
      
      menuItems.forEach(function(item) {
        var link = item.querySelector(':scope > .nav-link');
        var treeview = item.querySelector(':scope > .nav-treeview');
        
        if (link && treeview) {
          console.log('Adding click handler to:', link.textContent.trim());
          
          link.addEventListener('click', function(e) {
            e.preventDefault();
            e.stopPropagation();
            
            console.log('Menu clicked:', link.textContent.trim());
            console.log('Current classes:', item.className);
            
            // Toggle current menu
            item.classList.toggle('menu-open');
            
            console.log('After toggle:', item.className);
            
            // Optional: Close other open menus (accordion behavior)
            var accordion = item.closest('[data-accordion]');
            if (accordion && accordion.getAttribute('data-accordion') === 'true') {
              var allMenuItems = accordion.querySelectorAll('.nav-item.menu-open');
              allMenuItems.forEach(function(otherItem) {
                if (otherItem !== item) {
                  otherItem.classList.remove('menu-open');
                }
              });
            }
          });
        }
      });
      
      // Smooth scroll for sidebar on desktop
      if (window.innerWidth >= 992) {
        var sidebar = document.querySelector('.sidebar-wrapper');
        if (sidebar) {
          sidebar.style.overflowY = 'auto';
          sidebar.style.maxHeight = 'calc(100vh - 60px)';
        }
      }
      
      // Highlight active menu item
      var currentPage = window.location.pathname.split('/').pop();
      var navLinks = document.querySelectorAll('.sidebar-menu .nav-link');
      navLinks.forEach(function(link) {
        var href = link.getAttribute('href');
        if (href && href.indexOf(currentPage) !== -1 && currentPage !== '') {
          link.classList.add('active');
          // Open parent menu if this is a submenu item
          var parentTreeview = link.closest('.nav-treeview');
          if (parentTreeview) {
            var parentNavItem = parentTreeview.closest('.nav-item');
            if (parentNavItem) {
              parentNavItem.classList.add('menu-open');
              var parentLink = parentNavItem.querySelector(':scope > .nav-link');
              if (parentLink) {
                parentLink.classList.add('active');
              }
            }
          }
        }
      });
    });
  </script>
  </body>
  </html>
