<x-app-layout>
    <x-slot name="header">
        <div class="flex flex-col md:flex-row md:items-center justify-between gap-4">
            <div>
                <h1 class="text-3xl font-extrabold tracking-tight text-gray-900 sm:text-4xl">
                    <span class="text-gradient">Customers</span>
                </h1>
                <p class="text-gray-500 text-lg mt-1 font-medium">Manage and monitor your customer base with ease.</p>
            </div>
            <div>
                <a href="{{ route('customers.create') }}"
                   class="inline-flex items-center px-6 py-3 border border-transparent text-base font-semibold rounded-2xl shadow-sm text-white bg-gradient-to-r from-blue-600 to-indigo-700 hover:from-blue-700 hover:to-indigo-800 transition-all duration-300 transform hover:scale-[1.02] active:scale-[0.98] shadow-blue-200">
                    <svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"></path>
                    </svg>
                    New Customer
                </a>
            </div>
        </div>
    </x-slot>

    <div class="p-6">
        <div class="max-w-7xl mx-auto">
            <!-- Search Bar -->
            <div class="relative mb-10">
                <div class="absolute inset-0 bg-gradient-to-r from-blue-500/10 to-indigo-500/10 blur-3xl -z-10 rounded-3xl"></div>
                <div class="glass-card rounded-3xl p-2 border-white/40 shadow-2xl shadow-blue-900/5">
                    <form method="GET" action="{{ route('customers.index') }}" class="flex flex-col md:flex-row gap-2">
                        <div class="relative flex-1 group">
                            <div class="absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none text-gray-400 group-focus-within:text-blue-500 transition-colors">
                                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
                                </svg>
                            </div>
                            <input type="text"
                                   name="search"
                                   value="{{ $search }}"
                                   placeholder="Search customers by name, phone, or email..."
                                   class="w-full pl-12 pr-4 py-4 bg-transparent border-none focus:ring-0 text-gray-900 placeholder-gray-400 text-lg font-medium">
                        </div>
                        <div class="flex gap-2 p-1">
                            @if($search)
                                <a href="{{ route('customers.index') }}"
                                   class="px-6 py-3 text-gray-500 hover:text-gray-700 font-semibold rounded-2xl transition-all duration-200 flex items-center hover:bg-gray-100">
                                    Clear
                                </a>
                            @endif
                            <button type="submit"
                                    class="bg-gray-900 hover:bg-black text-white font-bold py-3 px-8 rounded-2xl transition-all duration-300 flex items-center shadow-lg active:scale-95">
                                Search
                            </button>
                        </div>
                    </form>
                </div>
            </div>

            <!-- Customers Grid -->
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
                @forelse($customers as $customer)
                    <div class="group relative">
                        <!-- Glow Effect Background -->
                        <div class="absolute -inset-0.5 bg-gradient-to-r from-blue-600 to-indigo-600 rounded-3xl blur opacity-0 group-hover:opacity-20 transition duration-1000 group-hover:duration-200"></div>
                        
                        <div class="relative bg-white border border-gray-100 rounded-3xl premium-shadow premium-shadow-hover transition-all duration-500 overflow-hidden flex flex-col h-full hover-glow">
                            <div class="p-8 flex-1">
                                <div class="flex items-start justify-between mb-6">
                                    <div class="flex items-center space-x-4">
                                        <div class="relative">
                                            <div class="absolute inset-0 bg-blue-500 blur-lg opacity-20 group-hover:opacity-40 transition-opacity"></div>
                                            <div class="relative w-16 h-16 bg-gradient-to-br from-blue-600 to-indigo-700 rounded-2xl flex items-center justify-center text-white font-bold text-2xl shadow-xl transform group-hover:rotate-3 transition-transform duration-500">
                                                {{ strtoupper(substr($customer->full_name, 0, 1)) }}
                                            </div>
                                        </div>
                                        <div>
                                            <h3 class="text-xl font-bold text-gray-900 group-hover:text-blue-600 transition-colors duration-300">{{ $customer->full_name }}</h3>
                                            <p class="text-sm font-semibold text-gray-400 tracking-wider uppercase mt-1">ID #{{ str_pad($customer->id, 4, '0', STR_PAD_LEFT) }}</p>
                                        </div>
                                    </div>
                                    <div class="flex flex-col items-end">
                                        <span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-bold bg-blue-50 text-blue-700 border border-blue-100">
                                            ACTIVE
                                        </span>
                                    </div>
                                </div>
                                
                                <div class="space-y-4">
                                    <div class="flex items-center group/item">
                                        <div class="w-10 h-10 rounded-xl bg-gray-50 flex items-center justify-center text-gray-400 group-hover/item:bg-blue-50 group-hover/item:text-blue-600 transition-all duration-300 mr-4">
                                            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"></path>
                                            </svg>
                                        </div>
                                        <span class="text-gray-600 font-medium group-hover/item:text-gray-900 transition-colors">{{ $customer->phone }}</span>
                                    </div>
                                    
                                    @if($customer->email)
                                        <div class="flex items-center group/item">
                                            <div class="w-10 h-10 rounded-xl bg-gray-50 flex items-center justify-center text-gray-400 group-hover/item:bg-blue-50 group-hover/item:text-blue-600 transition-all duration-300 mr-4">
                                                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 4.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path>
                                                </svg>
                                            </div>
                                            <span class="text-gray-600 font-medium group-hover/item:text-gray-900 transition-colors truncate">{{ $customer->email }}</span>
                                        </div>
                                    @endif

                                    <div class="flex items-start group/item">
                                        <div class="w-10 h-10 rounded-xl bg-gray-50 flex items-center justify-center text-gray-400 group-hover/item:bg-blue-50 group-hover/item:text-blue-600 transition-all duration-300 mr-4 flex-shrink-0">
                                            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"></path>
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"></path>
                                            </svg>
                                        </div>
                                        <span class="text-gray-600 font-medium group-hover/item:text-gray-900 transition-colors line-clamp-2 mt-2">{{ $customer->address }}</span>
                                    </div>
                                </div>
                            </div>

                            <div class="px-8 py-6 bg-gray-50/50 border-t border-gray-100 flex items-center justify-between">
                                <div class="flex -space-x-2">
                                    <div class="w-8 h-8 rounded-full bg-blue-100 border-2 border-white flex items-center justify-center text-[10px] font-bold text-blue-600">
                                        {{ $customer->orders_count ?? 0 }}
                                    </div>
                                    <span class="ml-4 text-xs font-bold text-gray-400 uppercase tracking-widest mt-2.5">Orders</span>
                                </div>
                                <div class="flex space-x-2">
                                    <a href="{{ route('customers.show', $customer) }}"
                                       class="p-2.5 text-blue-600 hover:bg-blue-600 hover:text-white rounded-xl transition-all duration-300 border border-blue-100 hover:border-blue-600">
                                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path>
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"></path>
                                        </svg>
                                    </a>
                                    <a href="{{ route('customers.edit', $customer) }}"
                                       class="p-2.5 text-indigo-600 hover:bg-indigo-600 hover:text-white rounded-xl transition-all duration-300 border border-indigo-100 hover:border-indigo-600">
                                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path>
                                        </svg>
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                @empty
                    <div class="col-span-full">
                        <div class="relative group">
                            <div class="absolute -inset-1 bg-gradient-to-r from-blue-600 to-indigo-600 rounded-[2rem] blur opacity-25 group-hover:opacity-50 transition duration-1000"></div>
                            <div class="relative glass-card rounded-[2rem] border-white/50 p-16 text-center">
                                <div class="w-32 h-32 bg-gradient-to-br from-gray-50 to-gray-100 rounded-3xl flex items-center justify-center mx-auto mb-8 shadow-inner">
                                    <svg class="w-16 h-16 text-gray-300" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"></path>
                                    </svg>
                                </div>
                                <h3 class="text-3xl font-extrabold text-gray-900 mb-4">No customers found</h3>
                                <p class="text-gray-500 text-lg mb-10 max-w-lg mx-auto font-medium">
                                    @if($search)
                                        We couldn't find any customers matching "<span class="text-blue-600 font-bold">{{ $search }}</span>". Try a different search term.
                                    @else
                                        Start building your community! Add your first customer to begin tracking orders and preferences.
                                    @endif
                                </p>
                                <a href="{{ route('customers.create') }}"
                                   class="inline-flex items-center px-10 py-4 border border-transparent text-lg font-bold rounded-2xl shadow-xl text-white bg-gray-900 hover:bg-black transition-all duration-300 transform hover:scale-105 active:scale-95">
                                    <svg class="w-6 h-6 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"></path>
                                    </svg>
                                    Add Your First Customer
                                </a>
                            </div>
                        </div>
                    </div>
                @endforelse
            </div>

            <!-- Pagination -->
            @if($customers->hasPages())
                <div class="mt-12 glass-card rounded-2xl p-4 border-white/40">
                    {{ $customers->appends(request()->query())->links() }}
                </div>
            @endif
        </div>
    </div>
</x-app-layout>
