<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">
                {{ __('Trips') }}
            </h2>
            <a href="{{ route('trips.create') }}" class="bg-blue-600 text-white px-4 py-2 rounded shadow hover:bg-blue-700">Add Trip</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" 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($trips as $trip)
                    <div class="bg-white rounded-lg shadow-md p-4 border-t-4 border-blue-500">
                        <div class="flex justify-between items-start mb-2">
                            <div>
                                <span class="text-xs font-bold text-gray-400 uppercase">{{ $trip->date->format('d M Y') }}</span>
                                <h3 class="font-bold text-lg text-gray-800">{{ $trip->location }}</h3>
                            </div>
                            <span class="px-2 py-1 bg-gray-100 text-xs font-bold rounded uppercase">{{ $trip->trip_type }}</span>
                        </div>
                        
                        <div class="text-sm text-gray-600 mb-4 border-b pb-2">
                            <p><strong>Vehicle:</strong> {{ $trip->vehicle->vehicle_number ?? 'N/A' }}</p>
                            <p><strong>Driver:</strong> {{ $trip->driver->driver_name ?? 'N/A' }}</p>
                            <p><strong>Total KM:</strong> {{ $trip->total_km }} km</p>
                        </div>
                        
                        <div class="flex justify-between items-center">
                            <div>
                                <p class="text-xs text-gray-500">Rent</p>
                                <p class="font-bold text-green-600">₹{{ number_format($trip->rent_amount, 2) }}</p>
                            </div>
                            <div>
                                <p class="text-xs text-gray-500">Fuel</p>
                                <p class="font-bold text-red-500">₹{{ number_format($trip->fuel_cost, 2) }}</p>
                            </div>
                            <div class="text-right">
                                <p class="text-xs text-gray-500">Profit</p>
                                <p class="font-black text-blue-600">₹{{ number_format($trip->profit, 2) }}</p>
                            </div>
                        </div>
                        
                        <!-- Actions -->
                        <div class="flex gap-2 mt-3 pt-3 border-t">
                            <a href="{{ route('trips.edit', $trip) }}" class="flex-1 text-center text-sm font-medium px-3 py-1.5 rounded bg-blue-50 text-blue-700 hover:bg-blue-100 transition">✏️ Edit</a>
                            <form action="{{ route('trips.destroy', $trip) }}" method="POST" class="flex-1" onsubmit="return confirm('Delete this trip?')">
                                @csrf
                                @method('DELETE')
                                <button type="submit" class="w-full text-sm font-medium px-3 py-1.5 rounded bg-red-50 text-red-700 hover:bg-red-100 transition">🗑️ Delete</button>
                            </form>
                        </div>
                    </div>
                @endforeach
            </div>
            
            <div class="mt-4 px-4 sm:px-0">
                {{ $trips->links() }}
            </div>

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