<x-admin-layout>
    <div class="space-y-8">
        <!-- Hero Section -->
        <div class="overflow-hidden rounded-3xl bg-gradient-to-br from-blue-600 via-blue-500 to-indigo-500 text-white shadow-xl shadow-blue-200/60 relative">
            <div class="absolute top-0 left-0 p-4 opacity-10">
                <x-icon name="LayoutDashboard" class="w-64 h-64" />
            </div>
            
            <div class="relative flex flex-col gap-6 p-6 sm:p-10 lg:flex-row lg:items-center lg:justify-between z-10">
                <div class="max-w-xl space-y-2">
                    <p class="text-sm font-semibold uppercase tracking-widest text-white/80">لوحة تحكم الإدارة</p>
                    <h2 class="text-3xl font-black leading-tight sm:text-4xl text-white">نظرة عامة على الأداء والتشغيل</h2>
                    <p class="text-white/80 text-lg">متابعة فورية للمركبات، الحجوزات، الإيرادات، وإنتاجية الفريق عبر مؤشرات واضحة وإجراءات سريعة.</p>
                </div>
                <div class="grid w-full max-w-lg grid-cols-2 gap-4 rounded-2xl bg-white/10 p-4 backdrop-blur-md sm:grid-cols-4 border border-white/20">
                    <div class="rounded-xl bg-white/10 px-4 py-3 text-center shadow-inner border border-white/10">
                        <p class="text-xs text-white/80 mb-1">مركبات</p>
                        <p class="text-2xl font-bold text-white">{{ $stats['total_vehicles'] ?? 0 }}</p>
                    </div>
                    <div class="rounded-xl bg-white/10 px-4 py-3 text-center shadow-inner border border-white/10">
                        <p class="text-xs text-white/80 mb-1">عملاء</p>
                        <p class="text-2xl font-bold text-white">{{ $stats['total_users'] ?? 0 }}</p>
                    </div>
                    <div class="rounded-xl bg-white/10 px-4 py-3 text-center shadow-inner border border-white/10">
                        <p class="text-xs text-white/80 mb-1">حجوزات</p>
                        <p class="text-2xl font-bold text-white">{{ $stats['total_bookings'] ?? 0 }}</p>
                    </div>
                    <div class="rounded-xl bg-white/10 px-4 py-3 text-center shadow-inner border border-white/10">
                        <p class="text-xs text-white/80 mb-1">إيرادات</p>
                        <p class="text-2xl font-bold text-white">{{ number_format($stats['revenue'] ?? 0) }}</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Stats Cards -->
        <div class="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-4">
            <!-- Vehicles Card -->
            <div class="group relative overflow-hidden rounded-2xl bg-gradient-to-br from-blue-50 to-white p-6 shadow-lg shadow-blue-100/60 transition-all hover:-translate-y-1 hover:shadow-xl border border-blue-50">
                <div class="flex items-center justify-between mb-4">
                    <h3 class="text-sm font-bold text-blue-900">إجمالي المركبات</h3>
                    <div class="rounded-full bg-blue-100 p-2 text-blue-600 group-hover:bg-blue-600 group-hover:text-white transition-colors">
                        <x-icon name="Car" class="h-5 w-5" />
                    </div>
                </div>
                <div class="flex items-baseline gap-2">
                    <span class="text-3xl font-bold text-slate-900">{{ $stats['total_vehicles'] ?? 0 }}</span>
                    <span class="text-xs text-blue-700/70 font-medium">مركبة مسجلة</span>
                </div>
            </div>

            <!-- Customers Card -->
            <div class="group relative overflow-hidden rounded-2xl bg-gradient-to-br from-cyan-50 to-white p-6 shadow-lg shadow-cyan-100/60 transition-all hover:-translate-y-1 hover:shadow-xl border border-cyan-50">
                <div class="flex items-center justify-between mb-4">
                    <h3 class="text-sm font-bold text-cyan-900">إجمالي العملاء</h3>
                    <div class="rounded-full bg-cyan-100 p-2 text-cyan-600 group-hover:bg-cyan-600 group-hover:text-white transition-colors">
                        <x-icon name="Users" class="h-5 w-5" />
                    </div>
                </div>
                <div class="flex items-baseline gap-2">
                    <span class="text-3xl font-bold text-slate-900">{{ $stats['total_users'] ?? 0 }}</span>
                    <span class="text-xs text-cyan-700/70 font-medium">مستخدم نشط</span>
                </div>
            </div>

            <!-- Bookings Card -->
            <div class="group relative overflow-hidden rounded-2xl bg-gradient-to-br from-indigo-50 to-white p-6 shadow-lg shadow-indigo-100/60 transition-all hover:-translate-y-1 hover:shadow-xl border border-indigo-50">
                <div class="flex items-center justify-between mb-4">
                    <h3 class="text-sm font-bold text-indigo-900">الحجوزات</h3>
                    <div class="rounded-full bg-indigo-100 p-2 text-indigo-600 group-hover:bg-indigo-600 group-hover:text-white transition-colors">
                        <x-icon name="Calendar" class="h-5 w-5" />
                    </div>
                </div>
                <div class="flex items-baseline gap-2">
                    <span class="text-3xl font-bold text-slate-900">{{ $stats['total_bookings'] ?? 0 }}</span>
                    <span class="text-xs text-indigo-700/70 font-medium">حجز كلي</span>
                </div>
            </div>

            <!-- Revenue Card -->
            <div class="group relative overflow-hidden rounded-2xl bg-gradient-to-br from-emerald-50 to-white p-6 shadow-lg shadow-emerald-100/60 transition-all hover:-translate-y-1 hover:shadow-xl border border-emerald-50">
                <div class="flex items-center justify-between mb-4">
                    <h3 class="text-sm font-bold text-emerald-900">الإيرادات</h3>
                    <div class="rounded-full bg-emerald-100 p-2 text-emerald-600 group-hover:bg-emerald-600 group-hover:text-white transition-colors">
                        <x-icon name="BarChart3" class="h-5 w-5" />
                    </div>
                </div>
                <div class="flex items-baseline gap-2">
                    <span class="text-3xl font-bold text-slate-900">{{ number_format($stats['revenue'] ?? 0) }}</span>
                    <span class="text-xs text-emerald-700/70 font-medium">ج.م</span>
                </div>
            </div>
        </div>

        <!-- Quick Actions -->
        <div>
            <div class="flex items-center justify-between mb-4">
                <div>
                    <h3 class="text-lg font-bold text-slate-900">إجراءات سريعة</h3>
                    <p class="text-sm text-slate-500">وصول مباشر لأكثر المهام استخداماً</p>
                </div>
            </div>
            <div class="grid grid-cols-2 gap-4 md:grid-cols-4 lg:grid-cols-4">
                 <a href="{{ route('admin.vehicles.create') }}" class="group flex items-center gap-4 rounded-2xl border border-slate-100 bg-white p-4 shadow-sm transition-all hover:-translate-y-1 hover:shadow-lg hover:border-blue-100">
                    <span class="flex h-12 w-12 items-center justify-center rounded-xl bg-blue-100 text-blue-600 group-hover:bg-blue-600 group-hover:text-white transition-colors">
                        <x-icon name="Car" class="h-6 w-6" />
                    </span>
                    <span class="font-bold text-slate-700 group-hover:text-blue-700">إضافة مركبة</span>
                </a>

                <a href="{{ route('admin.bookings.index') }}" class="group flex items-center gap-4 rounded-2xl border border-slate-100 bg-white p-4 shadow-sm transition-all hover:-translate-y-1 hover:shadow-lg hover:border-green-100">
                    <span class="flex h-12 w-12 items-center justify-center rounded-xl bg-green-100 text-green-600 group-hover:bg-green-600 group-hover:text-white transition-colors">
                        <x-icon name="Calendar" class="h-6 w-6" />
                    </span>
                    <span class="font-bold text-slate-700 group-hover:text-green-700">حجز جديد</span>
                </a>

                <a href="{{ route('admin.users.create') }}" class="group flex items-center gap-4 rounded-2xl border border-slate-100 bg-white p-4 shadow-sm transition-all hover:-translate-y-1 hover:shadow-lg hover:border-purple-100">
                    <span class="flex h-12 w-12 items-center justify-center rounded-xl bg-purple-100 text-purple-600 group-hover:bg-purple-600 group-hover:text-white transition-colors">
                        <x-icon name="UserPlus" class="h-6 w-6" />
                    </span>
                    <span class="font-bold text-slate-700 group-hover:text-purple-700">إضافة مستخدم</span>
                </a>

                <a href="{{ route('admin.finance.index') }}" class="group flex items-center gap-4 rounded-2xl border border-slate-100 bg-white p-4 shadow-sm transition-all hover:-translate-y-1 hover:shadow-lg hover:border-orange-100">
                    <span class="flex h-12 w-12 items-center justify-center rounded-xl bg-orange-100 text-orange-600 group-hover:bg-orange-600 group-hover:text-white transition-colors">
                        <x-icon name="CreditCard" class="h-6 w-6" />
                    </span>
                     <span class="font-bold text-slate-700 group-hover:text-orange-700">الفواتير</span>
                </a>
            </div>
        </div>

        <!-- Recent Activity -->
        <div class="grid grid-cols-1 gap-6 lg:grid-cols-2">
            <!-- Recent Bookings -->
            <div class="rounded-3xl border border-slate-100 bg-white shadow-lg shadow-blue-50/50 p-6">
                <div class="flex items-center justify-between mb-6">
                    <div>
                        <h3 class="text-lg font-bold text-slate-900">الحجوزات الأخيرة</h3>
                        <p class="text-sm text-slate-500">آخر الحجوزات المسجلة في النظام</p>
                    </div>
                    <a href="{{ route('admin.bookings.index') }}" class="text-sm font-medium text-blue-600 hover:text-blue-700 hover:bg-blue-50 px-3 py-1 rounded-lg transition-colors">عرض الكل</a>
                </div>
                
                <div class="space-y-4">
                    @forelse($recentBookings as $booking)
                        <div class="flex items-center justify-between rounded-2xl border border-slate-100 bg-slate-50/50 p-4 transition-colors hover:bg-white hover:shadow-md">
                            <div class="flex items-center gap-4">
                                <div class="hidden sm:flex h-10 w-10 items-center justify-center rounded-full bg-blue-100 text-blue-600">
                                    <x-icon name="Calendar" class="h-5 w-5" />
                                </div>
                                <div>
                                    <p class="font-bold text-slate-900">{{ $booking->customer->name ?? 'عميل غير معروف' }}</p>
                                    <p class="text-sm text-slate-500">
                                        {{ $booking->vehicle->make ?? '' }} {{ $booking->vehicle->model ?? '' }}
                                    </p>
                                </div>
                            </div>
                            <div class="text-left">
                                <span class="inline-flex items-center px-2.5 py-1 rounded-full text-xs font-bold 
                                    {{ $booking->status === 'CONFIRMED' ? 'bg-green-100 text-green-700' : 
                                       ($booking->status === 'PENDING' ? 'bg-yellow-100 text-yellow-700' : 'bg-gray-100 text-gray-700') }}">
                                    {{ $booking->status }}
                                </span>
                                <p class="text-xs text-slate-400 mt-1">{{ $booking->created_at->diffForHumans() }}</p>
                            </div>
                        </div>
                    @empty
                        <div class="text-center py-8 text-slate-500">
                            لا توجد حجوزات حديثة
                        </div>
                    @endforelse
                </div>
            </div>

            <!-- Recent Vehicles -->
            <div class="rounded-3xl border border-slate-100 bg-white shadow-lg shadow-emerald-50/50 p-6">
                 <div class="flex items-center justify-between mb-6">
                    <div>
                        <h3 class="text-lg font-bold text-slate-900">المركبات المضافة حديثاً</h3>
                        <p class="text-sm text-slate-500">آخر المركبات التي تمت إضافتها للمخزون</p>
                    </div>
                    <a href="{{ route('admin.vehicles.index') }}" class="text-sm font-medium text-emerald-600 hover:text-emerald-700 hover:bg-emerald-50 px-3 py-1 rounded-lg transition-colors">عرض الكل</a>
                </div>

                <div class="space-y-4">
                    @forelse($recentVehicles as $vehicle)
                        <div class="flex items-center justify-between rounded-2xl border border-slate-100 bg-slate-50/50 p-4 transition-colors hover:bg-white hover:shadow-md">
                             <div class="flex items-center gap-4">
                                <div class="hidden sm:flex h-10 w-10 items-center justify-center rounded-full bg-emerald-100 text-emerald-600">
                                    <x-icon name="Car" class="h-5 w-5" />
                                </div>
                                <div>
                                    <p class="font-bold text-slate-900">{{ $vehicle->make }} {{ $vehicle->model }}</p>
                                    <p class="text-sm text-slate-500">{{ $vehicle->year }}</p>
                                </div>
                            </div>
                            <div class="text-left">
                                <p class="font-bold text-slate-900">{{ number_format($vehicle->price) }} ج.م</p>
                                <span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-emerald-50 text-emerald-700 mt-1">
                                    {{ $vehicle->status }}
                                </span>
                            </div>
                        </div>
                    @empty
                        <div class="text-center py-8 text-slate-500">
                             لا توجد مركبات حديثة
                        </div>
                    @endforelse
                </div>
            </div>
        </div>
    </div>
</x-admin-layout>
