<!DOCTYPE html>
<html lang="en" class="h-full bg-slate-50">
<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', 'Dashboard') - Humanity Welfare Society CMS</title>
    
    <!-- Fonts & Icons -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
    <script src="https://unpkg.com/@lucide/web@latest"></script>
    
    <!-- Tailwind CSS & Alpine.js -->
    <script src="https://cdn.tailwindcss.com"></script>
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    fontFamily: {
                        sans: ['"Plus Jakarta Sans"', 'sans-serif'],
                    },
                    colors: {
                        emerald: {
                            50: '#ecfdf5',
                            100: '#d1fae5',
                            500: '#10b981',
                            600: '#059669',
                            700: '#047857',
                            800: '#065f46',
                            900: '#064e3b',
                        }
                    }
                }
            }
        }
    </script>
    <script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
    
    <style>
        [x-cloak] { display: none !important; }
    </style>
</head>
<body class="h-full font-sans text-slate-800 antialiased bg-slate-50" x-data="{ sidebarOpen: true }">

    <div class="min-h-screen flex">
        
        <!-- Sidebar Navigation -->
        <aside class="fixed inset-y-0 left-0 z-40 bg-slate-900 text-slate-300 w-64 transition-transform duration-300 flex flex-col shadow-2xl"
               :class="sidebarOpen ? 'translate-x-0' : '-translate-x-full lg:translate-x-0 lg:w-20'">
            
            <!-- Sidebar Header -->
            <div class="h-20 flex items-center justify-between px-6 bg-slate-950/60 border-b border-slate-800/80">
                <a href="{{ route('admin.dashboard') }}" class="flex items-center gap-3 overflow-hidden">
                    <div class="w-10 h-10 rounded-xl bg-gradient-to-tr from-emerald-600 to-teal-400 flex items-center justify-center text-white font-extrabold text-xl shadow-lg shadow-emerald-600/30 flex-shrink-0">
                        HWS
                    </div>
                    <div class="flex flex-col" x-show="sidebarOpen">
                        <span class="font-bold text-white tracking-wide text-sm leading-tight">Humanity Welfare</span>
                        <span class="text-xs text-emerald-400 font-medium">Certificate System</span>
                    </div>
                </a>
            </div>

            <!-- Nav Links -->
            <nav class="flex-1 px-4 py-6 space-y-1.5 overflow-y-auto">
                <a href="{{ route('admin.dashboard') }}" 
                   class="flex items-center gap-3.5 px-4 py-3 rounded-xl text-sm font-semibold transition-all duration-200 {{ request()->routeIs('admin.dashboard') ? 'bg-emerald-600 text-white shadow-lg shadow-emerald-600/30' : 'hover:bg-slate-800/80 hover:text-white text-slate-400' }}">
                    <i data-lucide="layout-dashboard" class="w-5 h-5 flex-shrink-0"></i>
                    <span x-show="sidebarOpen">Dashboard</span>
                </a>

                <a href="{{ route('admin.certificates.index') }}" 
                   class="flex items-center gap-3.5 px-4 py-3 rounded-xl text-sm font-semibold transition-all duration-200 {{ request()->routeIs('admin.certificates.*') ? 'bg-emerald-600 text-white shadow-lg shadow-emerald-600/30' : 'hover:bg-slate-800/80 hover:text-white text-slate-400' }}">
                    <i data-lucide="award" class="w-5 h-5 flex-shrink-0"></i>
                    <span x-show="sidebarOpen">Certificates</span>
                </a>

                <a href="{{ route('admin.students.index') }}" 
                   class="flex items-center gap-3.5 px-4 py-3 rounded-xl text-sm font-semibold transition-all duration-200 {{ request()->routeIs('admin.students.*') ? 'bg-emerald-600 text-white shadow-lg shadow-emerald-600/30' : 'hover:bg-slate-800/80 hover:text-white text-slate-400' }}">
                    <i data-lucide="users" class="w-5 h-5 flex-shrink-0"></i>
                    <span x-show="sidebarOpen">Students / Interns</span>
                </a>

                <a href="{{ route('admin.colleges.index') }}" 
                   class="flex items-center gap-3.5 px-4 py-3 rounded-xl text-sm font-semibold transition-all duration-200 {{ request()->routeIs('admin.colleges.*') ? 'bg-emerald-600 text-white shadow-lg shadow-emerald-600/30' : 'hover:bg-slate-800/80 hover:text-white text-slate-400' }}">
                    <i data-lucide="building-2" class="w-5 h-5 flex-shrink-0"></i>
                    <span x-show="sidebarOpen">Colleges</span>
                </a>

                <a href="{{ route('admin.courses.index') }}" 
                   class="flex items-center gap-3.5 px-4 py-3 rounded-xl text-sm font-semibold transition-all duration-200 {{ request()->routeIs('admin.courses.*') ? 'bg-emerald-600 text-white shadow-lg shadow-emerald-600/30' : 'hover:bg-slate-800/80 hover:text-white text-slate-400' }}">
                    <i data-lucide="book-open" class="w-5 h-5 flex-shrink-0"></i>
                    <span x-show="sidebarOpen">Courses / Domains</span>
                </a>

                @if(Auth::user() && Auth::user()->isSuperAdmin())
                <div class="pt-4 pb-2 px-4" x-show="sidebarOpen">
                    <span class="text-[10px] font-bold tracking-wider text-slate-500 uppercase">Administration</span>
                </div>

                <a href="{{ route('admin.users.index') }}" 
                   class="flex items-center gap-3.5 px-4 py-3 rounded-xl text-sm font-semibold transition-all duration-200 {{ request()->routeIs('admin.users.*') ? 'bg-emerald-600 text-white shadow-lg shadow-emerald-600/30' : 'hover:bg-slate-800/80 hover:text-white text-slate-400' }}">
                    <i data-lucide="user-cog" class="w-5 h-5 flex-shrink-0"></i>
                    <span x-show="sidebarOpen">Staff Users</span>
                </a>

                <a href="{{ route('admin.audit_logs.index') }}" 
                   class="flex items-center gap-3.5 px-4 py-3 rounded-xl text-sm font-semibold transition-all duration-200 {{ request()->routeIs('admin.audit_logs.*') ? 'bg-emerald-600 text-white shadow-lg shadow-emerald-600/30' : 'hover:bg-slate-800/80 hover:text-white text-slate-400' }}">
                    <i data-lucide="shield-check" class="w-5 h-5 flex-shrink-0"></i>
                    <span x-show="sidebarOpen">Audit Logs</span>
                </a>
                @endif
            </nav>

            <!-- User Footer -->
            <div class="p-4 border-t border-slate-800/80 bg-slate-950/40 flex items-center justify-between">
                <div class="flex items-center gap-3 overflow-hidden">
                    <div class="w-9 h-9 rounded-full bg-slate-800 flex items-center justify-center font-bold text-white text-sm border border-slate-700 flex-shrink-0">
                        {{ strtoupper(substr(Auth::user()->name ?? 'A', 0, 1)) }}
                    </div>
                    <div class="flex flex-col min-w-0" x-show="sidebarOpen">
                        <span class="text-xs font-bold text-white truncate">{{ Auth::user()->name ?? 'User' }}</span>
                        <span class="text-[11px] text-slate-400 capitalize">{{ str_replace('_', ' ', Auth::user()->role ?? 'Staff') }}</span>
                    </div>
                </div>
                <form action="{{ route('logout') }}" method="POST">
                    @csrf
                    <button type="submit" class="p-2 text-slate-400 hover:text-rose-400 hover:bg-slate-800 rounded-lg transition-colors" title="Logout">
                        <i data-lucide="log-out" class="w-4 h-4"></i>
                    </button>
                </form>
            </div>
        </aside>

        <!-- Main Content Area -->
        <div class="flex-1 flex flex-col transition-all duration-300"
             :class="sidebarOpen ? 'lg:ml-64' : 'lg:ml-20'">
            
            <!-- Top Navbar -->
            <header class="h-20 bg-white border-b border-slate-200/80 px-6 flex items-center justify-between sticky top-0 z-30 shadow-sm">
                <div class="flex items-center gap-4">
                    <button @click="sidebarOpen = !sidebarOpen" class="p-2 text-slate-600 hover:bg-slate-100 rounded-xl transition-colors">
                        <i data-lucide="menu" class="w-6 h-6"></i>
                    </button>
                    <h1 class="text-xl font-bold text-slate-900">@yield('page_header', 'Dashboard')</h1>
                </div>

                <div class="flex items-center gap-4">
                    <a href="{{ route('admin.certificates.create') }}" class="inline-flex items-center gap-2 bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-700 hover:to-teal-700 text-white font-semibold text-sm px-4 py-2.5 rounded-xl shadow-lg shadow-emerald-600/20 transition-all duration-200 hover:scale-[1.02]">
                        <i data-lucide="plus" class="w-4 h-4"></i>
                        <span>Generate Certificate</span>
                    </a>
                </div>
            </header>

            <!-- Flash Banners -->
            <main class="flex-1 p-6 md:p-8 max-w-7xl w-full mx-auto">
                @if(session('success'))
                <div class="mb-6 bg-emerald-50 border border-emerald-200 text-emerald-800 px-5 py-4 rounded-2xl flex items-center justify-between shadow-sm">
                    <div class="flex items-center gap-3">
                        <div class="w-8 h-8 rounded-xl bg-emerald-600 text-white flex items-center justify-center flex-shrink-0">
                            <i data-lucide="check-circle" class="w-5 h-5"></i>
                        </div>
                        <span class="text-sm font-semibold">{{ session('success') }}</span>
                    </div>
                    <button onclick="this.parentElement.remove()" class="text-emerald-500 hover:text-emerald-700">
                        <i data-lucide="x" class="w-5 h-5"></i>
                    </button>
                </div>
                @endif

                @if(session('error'))
                <div class="mb-6 bg-rose-50 border border-rose-200 text-rose-800 px-5 py-4 rounded-2xl flex items-center justify-between shadow-sm">
                    <div class="flex items-center gap-3">
                        <div class="w-8 h-8 rounded-xl bg-rose-600 text-white flex items-center justify-center flex-shrink-0">
                            <i data-lucide="alert-triangle" class="w-5 h-5"></i>
                        </div>
                        <span class="text-sm font-semibold">{{ session('error') }}</span>
                    </div>
                    <button onclick="this.parentElement.remove()" class="text-rose-500 hover:text-rose-700">
                        <i data-lucide="x" class="w-5 h-5"></i>
                    </button>
                </div>
                @endif

                @yield('content')
            </main>

            <!-- Footer -->
            <footer class="bg-white border-t border-slate-200/80 py-4 px-6 text-center text-xs text-slate-500">
                &copy; {{ date('Y') }} <strong>Humanity Welfare Society (NGO)</strong>. Certificate Management & Verification System.
            </footer>
        </div>
    </div>

    <script>
        lucide.createIcons();
    </script>
    @stack('scripts')
</body>
</html>
