<x-app-layout>
    <x-slot name="header">
        <div class="flex justify-between items-center">
            <h2 class="font-semibold text-xl text-gray-800 leading-tight">
                {{ __('Drivers') }}
            </h2>
            <a href="{{ route('drivers.create') }}" class="bg-blue-600 text-white px-4 py-2 rounded shadow hover:bg-blue-700">Add Driver</a>
        </div>
    </x-slot>

    <div class="py-6">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            
            @if(session('success'))
                <div class="bg-green-100 border-l-4 border-green-500 text-green-700 p-4 mb-4 rounded shadow-sm" role="alert">
                    <p>{{ session('success') }}</p>
                </div>
            @endif

            <!-- Mobile First Card Layout -->
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 px-4 sm:px-0">
                @foreach($drivers as $driver)
                    <div class="bg-white rounded-lg shadow-md p-4 border-t-4 border-orange-500">
                        <div class="flex justify-between items-start mb-2">
                            <div>
                                <h3 class="font-black text-xl text-gray-800">{{ $driver->driver_name }}</h3>
                                <p class="text-sm text-gray-500 flex items-center">
                                    📞 {{ $driver->phone }}
                                </p>
                            </div>
                            <span class="px-2 py-1 {{ $driver->status == 'active' ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800' }} text-xs font-bold rounded uppercase">{{ $driver->status }}</span>
                        </div>
                        
                        <div class="text-sm text-gray-600 mb-4 border-b pb-2">
                            <p><strong>License:</strong> {{ $driver->license_number }}</p>
                            <p class="{{ $driver->license_expiry->isPast() ? 'text-red-600 font-bold' : '' }}">
                                <strong>Exp:</strong> {{ $driver->license_expiry->format('d M Y') }}
                            </p>
                        </div>
                        
                        <div class="flex justify-between items-center text-sm font-bold">
                            <span class="bg-gray-100 px-2 py-1 rounded text-gray-700">
                                🚗 {{ $driver->vehicle->vehicle_number ?? 'Unassigned' }}
                            </span>
                            <a href="{{ route('drivers.edit', $driver) }}" class="text-blue-600 bg-blue-50 px-3 py-1 rounded hover:bg-blue-100">Edit</a>
                        </div>
                    </div>
                @endforeach
            </div>
            
            <div class="mt-4 px-4 sm:px-0">
                {{ $drivers->links() }}
            </div>

        </div>
    </div>
</x-app-layout>
