<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}" dir="{{ app()->getLocale() == 'ar' ? 'rtl' : 'ltr' }}">
    <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', 'مدار بلس') }}</title>

        <!-- Fonts -->
        <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=Tajawal:wght@200;300;400;500;700;800;900&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">

        <!-- Scripts -->
        @vite(['resources/css/app.css', 'resources/js/app.js'])
        
        @stack('styles')
        
        <style>
            body { font-family: 'Tajawal', sans-serif !important; }
            .scrollbar-hide::-webkit-scrollbar { display: none; }
            .scrollbar-hide { -ms-overflow-style: none; scrollbar-width: none; }
            [x-cloak] { display: none !important; }
        </style>
    </head>
    <body class="antialiased bg-[#0a0a0a] text-white" x-data="{ 
        sidebarOpen: localStorage.getItem('sidebarOpen') === 'true',
        init() {
            this.$watch('sidebarOpen', value => {
                localStorage.setItem('sidebarOpen', value);
            });
        }
    }">
        <div class="h-screen flex bg-[#d4af37] overflow-hidden">
            <!-- Sidebar -->
            <aside 
                :class="sidebarOpen ? 'w-80' : 'w-24'"
                class="fixed inset-y-0 ltr:left-0 rtl:right-0 z-50 bg-[#d4af37] transition-all duration-300 ease-in-out lg:relative flex flex-col h-full shrink-0 overflow-hidden">
                <div class="w-full h-full">
                    @include('layouts.navigation')
                </div>
            </aside>

            <!-- Main Layout Container -->
            <div class="flex-1 h-screen overflow-hidden relative bg-[#0a0a0a] transition-all duration-300 ease-in-out grid grid-rows-[auto_1fr_auto]"
                 style="{{ app()->getLocale() == 'ar' ? 'border-top-right-radius: 40px; border-bottom-right-radius: 40px;' : 'border-top-left-radius: 40px; border-bottom-left-radius: 40px;' }}">
                
                <!-- 1. Topbar -->
                <header class="h-20 bg-[#0a0a0a]/80 backdrop-blur-md border-b border-white/5 z-40">
                    <div style="width: 70%; margin: 0 auto; height: 100%; display: flex; align-items: center; justify-content: space-between;">
                        <div class="flex items-center gap-6">
                            <nav class="flex items-center text-xs font-bold text-gray-500 space-x-2 rtl:space-x-reverse uppercase tracking-widest">
                                <a href="{{ route('admin.dashboard') }}" class="hover:text-[#d4af37] transition-colors">Dashboard</a>
                                <svg class="w-4 h-4 opacity-20" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path d="M9 5l7 7-7 7" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"></path></svg>
                                <span class="text-white">{{ $header_title ?? '' }}</span>
                            </nav>
                        </div>

                        <div class="flex items-center gap-8">
                            <!-- Document Alerts Icon -->
                            <a href="{{ route('admin.dashboard') }}" class="relative p-2 bg-white/5 rounded-xl hover:bg-white/10 transition-all group">
                                <svg class="w-5 h-5 text-gray-400 group-hover:text-[#d4af37]" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"></path></svg>
                                @if(isset($total_alerts_count) && $total_alerts_count > 0)
                                    <span class="absolute -top-1 -right-1 w-4 h-4 bg-red-500 text-white text-[9px] font-bold flex items-center justify-center rounded-full border-2 border-[#0a0a0a]">
                                        {{ $total_alerts_count }}
                                    </span>
                                @endif
                            </a>

                            <div class="flex items-center gap-3 text-[11px] font-black">
                                <a href="{{ route('lang.switch', 'ar') }}" class="px-3 py-1.5 rounded-lg transition-all {{ app()->getLocale() == 'ar' ? 'bg-[#d4af37] text-black shadow-lg shadow-[#d4af37]/20' : 'text-gray-500 hover:text-white' }}">AR</a>
                                <a href="{{ route('lang.switch', 'en') }}" class="px-3 py-1.5 rounded-lg transition-all {{ app()->getLocale() == 'en' ? 'bg-[#d4af37] text-black shadow-lg shadow-[#d4af37]/20' : 'text-gray-500 hover:text-white' }}">EN</a>
                            </div>
                            <div class="h-8 w-px bg-white/10"></div>
                            <div class="flex items-center gap-4">
                                <div class="flex flex-col items-start leading-none ltr:items-end">
                                    <span class="text-sm font-black text-white uppercase tracking-tight">{{ Auth::user()->name }}</span>
                                    <span class="text-[10px] font-bold text-[#d4af37] mt-1 opacity-80">
                                        {{ Auth::user()->employee && Auth::user()->employee->jobTitle ? Auth::user()->employee->jobTitle->name : (Auth::user()->roles->first() ? Auth::user()->roles->first()->name : 'User') }}
                                    </span>
                                </div>
                                <div class="w-10 h-10 rounded-2xl bg-[#111] border border-white/5 flex items-center justify-center text-sm font-black text-[#d4af37] shadow-xl">
                                    {{ substr(Auth::user()->name, 0, 1) }}
                                </div>
                            </div>
                        </div>
                    </div>
                </header>

                <!-- 2. Content Area -->
                <div class="overflow-y-auto scrollbar-hide">
                    @isset($header)
                        <div class="bg-black/40 py-4">
                            <div style="width: 70%; margin: 0 auto;">
                                {{ $header }}
                            </div>
                        </div>
                    @endisset

                    <main class="py-8">
                        <div style="width: 70%; margin: 0 auto;">
                            @yield('content')
                            {{ $slot ?? '' }}
                        </div>
                    </main>

                    <!-- Large spacer to prevent content from hitting the bottom edge -->
                    <div class="h-40 w-full clear-both"></div>
                </div>
            </div>
                            

        </div>

        @stack('scripts')
    </body>
</html>