<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">
                {{ __('Fuel Entries') }}
            </h2>
            <a href="{{ route('fuel.create') }}" class="bg-blue-600 text-white px-4 py-2 rounded shadow hover:bg-blue-700">Add Fuel</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($fuelEntries as $entry)
                    <div class="bg-white rounded-lg shadow-md p-4 border-t-4 border-red-500">
                        <div class="flex justify-between items-start mb-2">
                            <div>
                                <span class="text-xs font-bold text-gray-400 uppercase">{{ $entry->created_at->format('d M Y, h:i A') }}</span>
                                <h3 class="font-black text-xl text-gray-800">{{ $entry->vehicle->vehicle_number ?? 'Unknown' }}</h3>
                            </div>
                            <span class="px-2 py-1 bg-red-50 text-red-700 font-black rounded">₹{{ number_format($entry->total, 2) }}</span>
                        </div>
                        
                        <div class="text-sm text-gray-600">
                            <p><strong>Litre:</strong> {{ $entry->litre }} L</p>
                            <p><strong>Price/L:</strong> ₹{{ number_format($entry->price, 2) }}</p>
                            @if($entry->trip)
                                <p><strong>Trip:</strong> {{ $entry->trip->location }} ({{ $entry->trip->date->format('d/m/y') }})</p>
                            @endif
                        </div>
                        
                        <!-- Actions -->
                        <div class="flex gap-2 mt-3 pt-3 border-t">
                            <a href="{{ route('fuel.edit', $entry) }}" 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('fuel.destroy', $entry) }}" method="POST" class="flex-1" onsubmit="return confirm('Delete this entry?')">
                                @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">
                {{ $fuelEntries->links() }}
            </div>

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