<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>@yield('title', 'AppSuper PKLK')</title>
    
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
    <!-- DataTables CSS -->
    <link href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap5.min.css" rel="stylesheet">
    
    @stack('styles')
    
    <style>
        :root {
            --primary-color: #0d6efd;
            --secondary-color: #6c757d;
            --success-color: #198754;
            --danger-color: #dc3545;
            --warning-color: #ffc107;
            --info-color: #0dcaf0;
        }
        
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f8f9fa;
            margin: 0;
            padding: 0;
        }
        
        .navbar {
            display: flex;
            align-items: center;
            height: 60px;
            padding: 0 1.5rem !important;
            position: fixed;
            top: 0;
            left: 260px;
            right: 0;
            z-index: 1030;
            background-color: #0d6efd;
            transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            box-sizing: border-box;
        }
        
        .navbar.minimized {
            left: 70px;
        }
        
        .navbar.collapsed {
            left: 0;
        }
        
        .navbar-brand {
            font-weight: 700;
            font-size: 1.25rem;
            display: flex;
            align-items: center;
            gap: 0.5rem;
            transition: all 0.3s ease-in-out;
            margin-left: 0.5rem;
        }
        
        .navbar-nav {
            margin-right: 0.5rem;
        }
        
        .navbar-brand i {
            font-size: 1.5rem;
        }
        
        .sidebar-wrapper {
            position: fixed;
            top: 0;
            left: 0;
            bottom: 0;
            width: 260px;
            z-index: 1000;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            overflow-y: auto;
            background: linear-gradient(180deg, #0d6efd 0%, #0a58ca 100%);
        }
        
        .sidebar-wrapper.minimized {
            width: 70px;
        }
        
        .sidebar-wrapper.collapsed {
            transform: translateX(-100%);
        }
        
        .sidebar-wrapper.show {
            transform: translateX(0);
        }
        
        .sidebar {
            color: white;
            padding: 0.75rem;
            padding-top: 60px;
            transition: padding 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }
        
        .sidebar.minimized {
            padding: 0.5rem;
            padding-top: 60px;
        }
        
        .sidebar .sidebar-header {
            position: fixed;
            top: 0;
            left: 0;
            width: 260px;
            height: 60px;
            display: flex;
            align-items: center;
            padding: 0 1rem;
            gap: 1rem;
            z-index: 1025;
            background: #0d6efd;
            box-sizing: border-box;
        }
        
        .sidebar-wrapper.minimized .sidebar-header {
            width: 70px;
            padding: 0 0.75rem;
        }
        
        .sidebar > nav {
            margin-top: 0;
        }
        
        .sidebar-title {
            flex: 1;
            display: flex;
            align-items: center;
            overflow: hidden;
            transition: opacity 0.3s ease-in-out;
        }
        
        .sidebar-title-text {
            color: white;
            font-size: 1.1rem;
            font-weight: 600;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        
        .sidebar.minimized .sidebar-title {
            opacity: 0;
            width: 0;
        }
        
        .sidebar .nav {
            margin-top: 0.5rem;
        }
        
        .sidebar .nav-link {
            color: rgba(255, 255, 255, 0.85);
            padding: 0.875rem 1rem;
            margin: 0.25rem 0;
            border-radius: 0.5rem;
            transition: all 0.2s ease-in-out;
            display: flex;
            align-items: center;
            white-space: nowrap;
            position: relative;
            font-size: 0.95rem;
            text-decoration: none;
            cursor: pointer;
            user-select: none;
            -webkit-tap-highlight-color: transparent;
        }
        
        .sidebar.minimized .nav-link {
            justify-content: center;
            padding: 0.875rem 0.5rem;
        }
        
        .sidebar .nav-link:hover {
            background-color: rgba(255, 255, 255, 0.15);
            color: white;
            padding-left: 1.25rem;
            transform: translateX(2px);
        }
        
        .sidebar.minimized .nav-link:hover {
            padding-left: 0.5rem;
            transform: translateX(0) scale(1.05);
        }
        
        .sidebar .nav-link.active {
            background-color: rgba(255, 255, 255, 0.25);
            color: white;
            font-weight: 600;
            border-left: 4px solid white;
            padding-left: calc(1rem - 4px);
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
        }
        
        .sidebar.minimized .nav-link.active {
            border-left: none;
            border-radius: 0.5rem;
            padding-left: 0.5rem;
            box-shadow: 0 0 0 2px white inset;
        }
        
        .sidebar .nav-link i {
            margin-right: 0.75rem;
            width: 20px;
            text-align: center;
            font-size: 1.1rem;
            transition: all 0.3s;
        }
        
        .sidebar.minimized .nav-link i {
            margin-right: 0;
            font-size: 1.2rem;
        }
        
        .sidebar .nav-link-text {
            transition: opacity 0.3s;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        
        .sidebar.minimized .nav-link-text {
            opacity: 0;
            width: 0;
            overflow: hidden;
        }
        
        /* Tooltip for minimized sidebar */
        .sidebar.minimized .nav-link::after {
            content: attr(data-tooltip);
            position: absolute;
            left: calc(100% + 10px);
            top: 50%;
            transform: translateY(-50%);
            background-color: #212529;
            color: white;
            padding: 0.5rem 1rem;
            border-radius: 0.5rem;
            white-space: nowrap;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.2s ease-in-out, left 0.2s ease-in-out;
            margin-left: 0;
            font-size: 0.875rem;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
            z-index: 1100;
            font-weight: 500;
        }
        
        .sidebar.minimized .nav-link:hover::after {
            opacity: 1;
            left: calc(100% + 8px);
        }
        
        .sidebar.minimized .nav-link::before {
            content: '';
            position: absolute;
            left: calc(100% + 4px);
            top: 50%;
            transform: translateY(-50%);
            border: 6px solid transparent;
            border-right-color: #212529;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.2s ease-in-out;
            z-index: 1100;
        }
        
        .sidebar.minimized .nav-link:hover::before {
            opacity: 1;
        }
        
        /* Submenu Styles */
        .nav-item-with-submenu {
            position: relative;
        }
        
        .nav-item-with-submenu .nav-link {
            position: relative;
        }
        
        .submenu-arrow {
            margin-left: auto;
            font-size: 0.75rem;
            transition: transform 0.3s ease-in-out;
            opacity: 0.8;
        }
        
        .nav-item-with-submenu .nav-link:hover .submenu-arrow {
            opacity: 1;
        }
        
        .submenu {
            display: none;
            padding-left: 0;
            margin: 0.25rem 0;
            overflow: hidden;
            transition: all 0.3s ease-in-out;
            background-color: rgba(0, 0, 0, 0.1);
            border-radius: 0.375rem;
            margin-top: 0.25rem;
        }
        
        .submenu.show {
            display: block;
        }
        
        .submenu-link {
            display: flex;
            align-items: center;
            color: rgba(255, 255, 255, 0.75);
            padding: 0.75rem 1rem 0.75rem 2.75rem;
            text-decoration: none;
            transition: all 0.2s ease-in-out;
            font-size: 0.875rem;
            position: relative;
            border-radius: 0.25rem;
            margin: 0.125rem 0.5rem;
        }
        
        .submenu-link::before {
            content: '';
            position: absolute;
            left: 1.5rem;
            top: 50%;
            transform: translateY(-50%);
            width: 6px;
            height: 6px;
            border-radius: 50%;
            background-color: rgba(255, 255, 255, 0.4);
            transition: all 0.2s ease-in-out;
        }
        
        .submenu-link:hover {
            background-color: rgba(255, 255, 255, 0.12);
            color: white;
            padding-left: 3rem;
        }
        
        .submenu-link:hover::before {
            background-color: white;
            transform: translateY(-50%) scale(1.3);
        }
        
        .submenu-link.active {
            background-color: rgba(255, 255, 255, 0.2);
            color: white;
            font-weight: 600;
        }
        
        .submenu-link.active::before {
            background-color: white;
            width: 8px;
            height: 8px;
        }
        
        .submenu-link i {
            margin-right: 0.75rem;
            font-size: 0.875rem;
            width: 16px;
            text-align: center;
        }
        
        .sidebar.minimized .nav-item-with-submenu .submenu {
            display: none !important;
        }
        
        .sidebar.minimized .nav-item-with-submenu .submenu-arrow {
            display: none;
        }
        
        .main-content {
            margin-left: 260px;
            transition: margin-left 0.3s ease-in-out;
            padding: 1.5rem;
            padding-top: 1.5rem;
            margin-top: 60px;
        }
        
        .main-content.minimized {
            margin-left: 70px;
        }
        
        .main-content.expanded {
            margin-left: 0;
        }
        
        .sidebar-overlay {
            display: none;
            position: fixed;
            top: 56px;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 999;
        }
        
        .sidebar-overlay.show {
            display: block;
        }
        
        /* Hamburger Menu Button - Gemini Style */
        .btn-toggle-sidebar {
            background: transparent;
            border: 1px solid rgba(255, 255, 255, 0.3);
            color: white;
            padding: 0;
            cursor: pointer;
            transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 44px;
            height: 44px;
            border-radius: 50%;
            flex-shrink: 0;
            position: relative;
            overflow: visible;
            -webkit-tap-highlight-color: transparent;
            user-select: none;
        }
        
        .btn-toggle-sidebar::before {
            content: '';
            position: absolute;
            inset: 0;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.1);
            opacity: 0;
            transition: opacity 0.25s ease-in-out;
        }
        
        .btn-toggle-sidebar:hover {
            background-color: rgba(255, 255, 255, 0.15);
            border-color: rgba(255, 255, 255, 0.4);
        }
        
        .btn-toggle-sidebar:hover::before {
            opacity: 1;
        }
        
        .btn-toggle-sidebar:active {
            background-color: rgba(255, 255, 255, 0.25);
            transform: scale(0.96);
        }
        
        /* Hamburger Box Container - Gemini Style */
        .hamburger-box {
            width: 20px;
            height: 16px;
            display: inline-block;
            position: relative;
        }
        
        /* Hamburger Inner (3 lines) - Clean and Modern */
        .hamburger-inner,
        .hamburger-inner::before,
        .hamburger-inner::after {
            width: 20px;
            height: 2px;
            background-color: white;
            border-radius: 1px;
            position: absolute;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }
        
        .hamburger-inner {
            display: block;
            top: 50%;
            margin-top: -1px;
        }
        
        .hamburger-inner::before,
        .hamburger-inner::after {
            content: "";
            display: block;
        }
        
        .hamburger-inner::before {
            top: -6px;
        }
        
        .hamburger-inner::after {
            bottom: -6px;
        }
        
        /* Active/Minimized State - Transform to X */
        .btn-toggle-sidebar.minimized .hamburger-inner,
        .btn-toggle-sidebar.active .hamburger-inner {
            background-color: transparent;
        }
        
        .btn-toggle-sidebar.minimized .hamburger-inner::before,
        .btn-toggle-sidebar.active .hamburger-inner::before {
            top: 0;
            transform: rotate(45deg);
        }
        
        .btn-toggle-sidebar.minimized .hamburger-inner::after,
        .btn-toggle-sidebar.active .hamburger-inner::after {
            bottom: 0;
            transform: rotate(-45deg);
        }
        
        /* Hover effect on hamburger lines */
        .btn-toggle-sidebar:hover .hamburger-inner,
        .btn-toggle-sidebar:hover .hamburger-inner::before,
        .btn-toggle-sidebar:hover .hamburger-inner::after {
            background-color: #fff;
        }

        
        /* Mobile responsive */
        @media (max-width: 768px) {
            .sidebar-wrapper {
                width: 280px;
                max-width: 85vw;
                transform: translateX(-100%);
                box-shadow: 4px 0 16px rgba(0, 0, 0, 0.3);
                transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            }
            
            .sidebar-wrapper.show {
                transform: translateX(0);
            }
            
            .main-content {
                margin-left: 0;
                padding: 1rem;
            }
            
            .sidebar {
                padding: 1rem 0.75rem;
                padding-top: 1rem;
            }
            
            .sidebar .sidebar-header {
                margin-bottom: 1rem;
                min-height: auto;
                border-bottom: 1px solid rgba(255, 255, 255, 0.15);
            }
            
            .sidebar-logo {
                align-items: center !important;
            }
            
            .sidebar-logo-text {
                display: none !important;
            }
            
            .btn-toggle-sidebar {
                width: 48px;
                height: 48px;
                min-width: 48px;
                min-height: 48px;
            }
            
            .hamburger-box {
                width: 24px;
                height: 20px;
            }
            
            .hamburger-inner,
            .hamburger-inner::before,
            .hamburger-inner::after {
                width: 24px;
                height: 3px;
            }
            
            .sidebar .nav-link {
                padding: 1rem;
                margin: 0.5rem 0;
                font-size: 1rem;
                min-height: 48px;
            }
            
            .sidebar .nav-link i {
                font-size: 1.25rem;
            }
            
            .navbar-brand {
                font-size: 1rem;
            }
            
            .card {
                margin-bottom: 1rem;
            }
            
            .sidebar-overlay {
                display: none;
                position: fixed;
                top: 60px;
                left: 0;
                right: 0;
                bottom: 0;
                background-color: rgba(0, 0, 0, 0.5);
                z-index: 999;
                animation: fadeIn 0.3s ease-in-out;
            }
            
            .sidebar-overlay.show {
                display: block;
            }
        }
        
        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }
        
        @media (max-width: 576px) {
            .navbar-brand {
                font-size: 0.9rem;
            }
            
            .main-content {
                padding: 1rem;
            }
            
            .stat-card h3 {
                font-size: 1.5rem;
            }
            
            /* Hide tahun ajaran on very small screens */
            .nav-item .bg-white.bg-opacity-25 span {
                font-size: 0.85rem;
            }
        }
        
        /* Tahun Ajaran Badge Styling */
        .nav-item .bg-white.bg-opacity-25 {
            display: inline-flex;
            align-items: center;
            transition: all 0.3s ease;
        }
        
        .nav-item .bg-white.bg-opacity-25:hover {
            background-color: rgba(255, 255, 255, 0.35) !important;
        }
        
        .card {
            border: none;
            border-radius: 0.5rem;
            box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
            margin-bottom: 1.5rem;
        }
        
        .card-header {
            background-color: #f8f9fa;
            border-bottom: 2px solid #e9ecef;
            font-weight: 600;
            padding: 1rem 1.25rem;
        }
        
        .stat-card {
            border-left: 4px solid var(--primary-color);
        }
        
        .stat-card.success {
            border-left-color: var(--success-color);
        }
        
        .stat-card.warning {
            border-left-color: var(--warning-color);
        }
        
        .stat-card.danger {
            border-left-color: var(--danger-color);
        }
        
        .badge {
            padding: 0.375rem 0.75rem;
            font-weight: 600;
        }
        
        .btn {
            border-radius: 0.375rem;
            padding: 0.5rem 1rem;
            font-weight: 500;
        }
        
        .table {
            background-color: white;
        }
        
        .table thead th {
            background-color: #f8f9fa;
            border-bottom: 2px solid #dee2e6;
            font-weight: 600;
            text-transform: uppercase;
            font-size: 0.875rem;
        }
    </style>
</head>
<body>
    <!-- Navbar -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary sticky-top">
        <div class="container-fluid">
            <a class="navbar-brand" href="{{ route('dashboard') }}">
                <i class="bi bi-mortarboard-fill"></i> 
                <span class="d-none d-sm-inline">AppSuper PKLK</span>
                <span class="d-inline d-sm-none">AppSuper</span>
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav ms-auto">
                    <!-- Tahun Ajaran Aktif -->
                    <li class="nav-item d-flex align-items-center me-3">
                        <div class="bg-white bg-opacity-25 px-3 py-1 rounded-pill">
                            <i class="bi bi-calendar-event me-2"></i>
                            <span class="fw-bold">TA {{ $tahunAjaranAktif ?? '2026/2027' }}</span>
                        </div>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">
                            <i class="bi bi-person-circle"></i> 
                            <span class="d-none d-md-inline">{{ Auth::user()->name }}</span>
                            <span class="badge bg-light text-primary ms-1">{{ Auth::user()->role->name }}</span>
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end">
                            <li><a class="dropdown-item" href="#"><i class="bi bi-person"></i> Profil</a></li>
                            <li><a class="dropdown-item" href="#"><i class="bi bi-gear"></i> Pengaturan</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li>
                                <form action="{{ route('logout') }}" method="POST">
                                    @csrf
                                    <button type="submit" class="dropdown-item text-danger">
                                        <i class="bi bi-box-arrow-right"></i> Logout
                                    </button>
                                </form>
                            </li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
    
    <!-- Sidebar Overlay for Mobile -->
    <div class="sidebar-overlay" id="sidebarOverlay"></div>

    <!-- Sidebar & Main Content (for authenticated users) -->
    @auth
        @include('layouts.sidebar')
    @endauth

    <!-- For guest users (login, etc) -->
    @guest
        @yield('content')
    @endguest

    <!-- jQuery -->
    <script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
    <!-- Bootstrap 5 JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <!-- DataTables JS -->
    <script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap5.min.js"></script>
    <!-- Chart.js -->
    <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
    
    <!-- Sidebar Toggle Script -->
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const sidebarToggle = document.getElementById('sidebarToggle');
            const sidebar = document.querySelector('.sidebar-wrapper');
            const sidebarInner = document.querySelector('.sidebar');
            const sidebarOverlay = document.getElementById('sidebarOverlay');
            const mainContent = document.querySelector('.main-content');
            const navbar = document.querySelector('.navbar');
            
            if (!sidebarToggle || !sidebar) return;
            
            // AdminLTE-style toggle function
            function toggleSidebar(e) {
                e.preventDefault();
                e.stopPropagation();
                
                const isMobile = window.innerWidth < 768;
                
                if (!isMobile) {
                    // Desktop: minimize/maximize with smooth transition
                    const isMinimized = sidebar.classList.contains('minimized');
                    
                    sidebar.classList.toggle('minimized');
                    sidebarInner.classList.toggle('minimized');
                    mainContent.classList.toggle('minimized');
                    sidebarToggle.classList.toggle('minimized');
                    navbar.classList.toggle('minimized');
                    
                    // Store preference
                    localStorage.setItem('sidebarMinimized', !isMinimized);
                } else {
                    // Mobile: show/hide with overlay
                    const isVisible = sidebar.classList.contains('show');
                    
                    if (!isVisible) {
                        sidebar.classList.add('show');
                        sidebar.classList.remove('collapsed');
                        if (sidebarOverlay) sidebarOverlay.classList.add('show');
                        sidebarToggle.classList.add('active');
                        document.body.style.overflow = 'hidden';
                    } else {
                        sidebar.classList.remove('show');
                        sidebar.classList.add('collapsed');
                        if (sidebarOverlay) sidebarOverlay.classList.remove('show');
                        sidebarToggle.classList.remove('active');
                        document.body.style.overflow = '';
                    }
                }
            }
            
            // Event listener with touch support for both buttons
            sidebarToggle.addEventListener('click', toggleSidebar);
            sidebarToggle.addEventListener('touchend', function(e) {
                e.preventDefault();
                toggleSidebar(e);
            });
            
            // Close sidebar on overlay click
            if (sidebarOverlay) {
                sidebarOverlay.addEventListener('click', function(e) {
                    if (window.innerWidth < 768) {
                        sidebar.classList.remove('show');
                        sidebar.classList.add('collapsed');
                        sidebarOverlay.classList.remove('show');
                        sidebarToggle.classList.remove('active');
                        document.body.style.overflow = '';
                    }
                });
            }
            
            // Close sidebar on menu click (mobile)
            const sidebarLinks = sidebarInner.querySelectorAll('.nav-link:not([onclick])');
            sidebarLinks.forEach(link => {
                link.addEventListener('click', function() {
                    if (window.innerWidth < 768 && !this.hasAttribute('onclick')) {
                        setTimeout(() => {
                            sidebar.classList.remove('show');
                            sidebar.classList.add('collapsed');
                            if (sidebarOverlay) sidebarOverlay.classList.remove('show');
                            sidebarToggle.classList.remove('active');
                            document.body.style.overflow = '';
                        }, 200);
                    }
                });
            });
            
            // Restore state on load (desktop only)
            if (window.innerWidth >= 768) {
                const wasMinimized = localStorage.getItem('sidebarMinimized') === 'true';
                if (wasMinimized) {
                    sidebar.classList.add('minimized');
                    sidebarInner.classList.add('minimized');
                    mainContent.classList.add('minimized');
                    sidebarToggle.classList.add('minimized');
                    navbar.classList.add('minimized');
                }
            }
            
            // Handle window resize smartly
            let resizeTimer;
            window.addEventListener('resize', function() {
                clearTimeout(resizeTimer);
                resizeTimer = setTimeout(function() {
                    const isMobile = window.innerWidth < 768;
                    
                    if (!isMobile) {
                        // Desktop mode
                        sidebar.classList.remove('show', 'collapsed');
                        navbar.classList.remove('collapsed');
                        if (sidebarOverlay) sidebarOverlay.classList.remove('show');
                        mainContent.classList.remove('expanded');
                        sidebarToggle.classList.remove('active');
                        document.body.style.overflow = '';
                        
                        // Restore minimized state
                        const wasMinimized = localStorage.getItem('sidebarMinimized') === 'true';
                        if (wasMinimized) {
                            sidebar.classList.add('minimized');
                            sidebarInner.classList.add('minimized');
                            mainContent.classList.add('minimized');
                            sidebarToggle.classList.add('minimized');
                            navbar.classList.add('minimized');
                        }
                    } else {
                        // Mobile mode
                        sidebar.classList.remove('minimized');
                        sidebarInner.classList.remove('minimized');
                        mainContent.classList.remove('minimized');
                        sidebarToggle.classList.remove('minimized');
                        navbar.classList.remove('minimized');
                        
                        if (!sidebar.classList.contains('show')) {
                            sidebar.classList.add('collapsed');
                        }
                    }
                }, 100);
            });
            
            // Initialize proper state
            if (window.innerWidth < 768) {
                sidebar.classList.add('collapsed');
                navbar.classList.add('collapsed');
            }
            
            // Keyboard accessibility (ESC to close on mobile)
            document.addEventListener('keydown', function(e) {
                if (e.key === 'Escape' && window.innerWidth < 768 && sidebar.classList.contains('show')) {
                    sidebar.classList.remove('show');
                    sidebar.classList.add('collapsed');
                    if (sidebarOverlay) sidebarOverlay.classList.remove('show');
                    sidebarToggle.classList.remove('active');
                    document.body.style.overflow = '';
                }
            });
        });
    </script>
    
    <script>
    // Improved submenu toggle with better UX
    function toggleSubmenu(event, submenuId) {
        event.preventDefault();
        event.stopPropagation();
        
        const submenu = document.getElementById(submenuId);
        const parentLink = event.currentTarget;
        const arrow = parentLink.querySelector('.submenu-arrow');
        
        // Close other submenus
        document.querySelectorAll('.submenu').forEach(sm => {
            if (sm.id !== submenuId && sm.style.display === 'block') {
                sm.style.display = 'none';
                const otherArrow = sm.previousElementSibling.querySelector('.submenu-arrow');
                if (otherArrow) otherArrow.style.transform = 'rotate(0deg)';
            }
        });
        
        // Toggle current submenu with animation
        if (submenu.style.display === 'block') {
            submenu.style.display = 'none';
            if (arrow) arrow.style.transform = 'rotate(0deg)';
        } else {
            submenu.style.display = 'block';
            if (arrow) arrow.style.transform = 'rotate(180deg)';
        }
    }
    </script>
    
    @stack('scripts')
</body>
</html>