<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="csrf-token" content="{{ csrf_token() }}">

        <title>{{ config('app.name', 'Laravel') }}</title>

        <!-- Fonts -->
        <link rel="preconnect" href="https://fonts.bunny.net">
        <link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />

        <!-- Font Awesome -->
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" />

        <!-- Alpine.js -->
        <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>

        <!-- Scripts -->
        @vite(['resources/css/app.css', 'resources/js/app.js'])
    </head>
    <body class="font-sans antialiased">
        <div class="flex h-screen bg-gray-50 dark:bg-gray-900 overflow-hidden">
            <!-- Sidebar -->
            @include('layouts.sidebar')

            <!-- Main Content Area -->
            <div class="flex-1 flex flex-col overflow-hidden">
                <!-- Top Header -->
                @include('layouts.header')

                <!-- Impersonation Banner -->
            @if(session('impersonator_id'))
                <div class="bg-gradient-to-r from-purple-600 to-pink-600 text-white shadow-lg">
                    <div class="max-w-7xl mx-auto py-3 px-4 sm:px-6 lg:px-8">
                        <div class="flex items-center justify-between flex-wrap">
                            <div class="flex items-center">
                                <i class="fas fa-user-secret text-2xl mr-3"></i>
                                <div>
                                    <p class="font-semibold">🎭 Mod Impersonare Activ</p>
                                    <p class="text-sm text-purple-100">Ești autentificat ca: <strong>{{ Auth::user()->name }} ({{ Auth::user()->email }})</strong></p>
                                </div>
                            </div>
                            <form method="POST" action="{{ route('admin.users.leave-impersonation') }}" class="mt-2 sm:mt-0">
                                @csrf
                                <button type="submit" class="bg-white text-purple-600 hover:bg-purple-50 font-bold py-2 px-4 rounded-lg transition shadow-md">
                                    <i class="fas fa-sign-out-alt mr-2"></i>
                                    Revenire la Admin
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            @endif

            <!-- Flash Messages Toast -->
            @if (session('success') || session('error') || session('info') || session('warning'))
                <div id="alert-toast" class="fixed z-[9999] animate-slideIn" style="top: 5rem; right: 1rem;">
                    <div class="bg-white dark:bg-gray-800 rounded-lg shadow-lg border {{ session('success') ? 'border-green-200 dark:border-green-800' : (session('error') ? 'border-red-200 dark:border-red-800' : (session('warning') ? 'border-yellow-200 dark:border-yellow-800' : 'border-blue-200 dark:border-blue-800')) }} w-96">
                        <div class="p-4">
                            <div class="flex items-start">
                                <!-- Icon -->
                                <div class="flex-shrink-0">
                                    @if (session('success'))
                                        <div class="flex items-center justify-center h-10 w-10 rounded-full bg-green-100 dark:bg-green-900/30">
                                            <i class="fas fa-check text-green-600 dark:text-green-400"></i>
                                        </div>
                                    @elseif (session('error'))
                                        <div class="flex items-center justify-center h-10 w-10 rounded-full bg-red-100 dark:bg-red-900/30">
                                            <i class="fas fa-times text-red-600 dark:text-red-400"></i>
                                        </div>
                                    @elseif (session('warning'))
                                        <div class="flex items-center justify-center h-10 w-10 rounded-full bg-yellow-100 dark:bg-yellow-900/30">
                                            <i class="fas fa-exclamation-triangle text-yellow-600 dark:text-yellow-400"></i>
                                        </div>
                                    @elseif (session('info'))
                                        <div class="flex items-center justify-center h-10 w-10 rounded-full bg-blue-100 dark:bg-blue-900/30">
                                            <i class="fas fa-info text-blue-600 dark:text-blue-400"></i>
                                        </div>
                                    @endif
                                </div>

                                <!-- Content -->
                                <div class="ml-3 flex-1">
                                    <p class="text-sm font-medium text-gray-900 dark:text-gray-100">
                                        @if (session('success'))
                                            Succes
                                        @elseif (session('error'))
                                            Eroare
                                        @elseif (session('warning'))
                                            Atenționare
                                        @elseif (session('info'))
                                            Informație
                                        @endif
                                    </p>
                                    <p class="mt-1 text-sm text-gray-600 dark:text-gray-300">
                                        {{ session('success') ?? session('error') ?? session('warning') ?? session('info') }}
                                    </p>
                                </div>

                                <!-- Close button -->
                                <button onclick="closeToast()" class="ml-4 flex-shrink-0 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300">
                                    <i class="fas fa-times text-sm"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>

                <style>
                    @keyframes slideIn {
                        from {
                            transform: translateX(100%);
                            opacity: 0;
                        }
                        to {
                            transform: translateX(0);
                            opacity: 1;
                        }
                    }
                    @keyframes slideOut {
                        from {
                            transform: translateX(0);
                            opacity: 1;
                        }
                        to {
                            transform: translateX(100%);
                            opacity: 0;
                        }
                    }
                    .animate-slideIn {
                        animation: slideIn 0.3s ease-out;
                    }
                    .animate-slideOut {
                        animation: slideOut 0.3s ease-in;
                    }
                </style>

                <script>
                    function closeToast() {
                        const toast = document.getElementById('alert-toast');
                        if (toast) {
                            toast.classList.remove('animate-slideIn');
                            toast.classList.add('animate-slideOut');
                            setTimeout(() => {
                                toast.style.display = 'none';
                            }, 300);
                        }
                    }

                    // Auto-close după 4 secunde
                    setTimeout(() => {
                        closeToast();
                    }, 4000);
                </script>
            @endif

                <!-- Page Heading -->
                @isset($header)
                    <header class="bg-white dark:bg-gray-800 shadow-sm border-b border-gray-200 dark:border-gray-700">
                        <div class="px-4 sm:px-6 lg:px-8 py-4">
                            {{ $header }}
                        </div>
                    </header>
                @endisset

                <!-- Page Content -->
                <main class="flex-1 overflow-x-hidden overflow-y-auto bg-gray-50 dark:bg-gray-900 flex flex-col">
                    <div class="flex-1 container mx-auto px-4 sm:px-6 lg:px-8 py-6">
                        {{ $slot }}
                    </div>

                    <!-- Footer - Sticky Bottom -->
                    @include('layouts.footer')
                </main>
            </div>
        </div>

        <!-- Mobile Bottom Navigation -->
        @include('layouts.mobile-nav')

        <!-- Page Scripts -->
        @stack('scripts')
    </body>
</html>
