{{-- BUKU TERPOPULER SECTION --}}
<section id="populer" class="py-24 bg-gray-50 relative overflow-hidden border-b border-gray-100">
    <div class="max-w-7xl mx-auto px-6 relative z-10">
        @if (!empty($bukuPopuler) && $bukuPopuler->count())
            <div>
                <div
                    class="flex flex-col md:flex-row justify-between items-start md:items-center mb-10 gap-4 text-center md:text-left">
                    <div class="w-full md:w-auto">
                        <div
                            class="inline-flex items-center gap-2 px-4 py-2 bg-blue-100 rounded-full mb-4 mx-auto md:mx-0">
                            <i class="fas fa-fire text-red-500 text-xs"></i>
                            <span class="text-xs font-semibold text-blue-800 tracking-wide">Paling Laris</span>
                        </div>
                        <h2 class="text-3xl md:text-4xl font-black text-gray-900 tracking-tight">
                            Buku <span
                                class="text-transparent bg-clip-text bg-gradient-to-r from-blue-600 to-indigo-600">Terpopuler</span>
                        </h2>
                        <p class="text-gray-500 mt-2 max-w-md mx-auto md:mx-0">
                            Koleksi buku favorit yang paling banyak dipinjam oleh para pengunjung perpustakaan kami.
                        </p>
                    </div>
                </div>

                <div class="grid grid-cols-2 lg:grid-cols-5 md:grid-cols-3 gap-6">
                    @foreach ($bukuPopuler as $item)
                        @php
                            $habis = $item->eksemplar <= 0;
                        @endphp
                        <div
                            class="group bg-white rounded-2xl shadow-sm hover:shadow-2xl border border-gray-100 overflow-hidden transition-all duration-300 transform {{ $habis ? 'grayscale opacity-75 cursor-not-allowed' : 'hover:-translate-y-1' }} flex flex-col h-full relative">

                            <!-- Peminjaman Count Badge -->
                            <div class="absolute top-2 left-2 z-20">
                                <span
                                    class="bg-blue-600/90 backdrop-blur-md text-white text-[10px] sm:text-xs font-bold px-2 py-1 rounded shadow-sm flex items-center gap-1">
                                    <i class="fas fa-book-reader"></i> {{ $item->peminjaman_count }}x
                                </span>
                            </div>

                            <!-- Book Cover -->
                            <div class="relative w-full pt-[140%] overflow-hidden bg-gray-50 flex-shrink-0">
                                @if ($item->cover ?? $item->sampul)
                                    <img src="{{ asset('storage/' . ($item->cover ?? $item->sampul)) }}"
                                        alt="{{ $item->judul }}"
                                        class="absolute inset-0 w-full h-full object-cover {{ !$habis ? 'group-hover:scale-110' : '' }} transition-transform duration-700 ease-in-out">
                                @else
                                    <div
                                        class="absolute inset-0 flex flex-col items-center justify-center text-gray-300 bg-gray-100 {{ !$habis ? 'group-hover:bg-gray-200' : '' }} transition-colors duration-300">
                                        <svg class="w-12 h-12 mb-2" fill="none" stroke="currentColor"
                                            viewBox="0 0 24 24">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"
                                                d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.747 0 3.332.477 4.5 1.253v13C19.832 18.477 18.247 18 16.5 18c-1.746 0-3.332.477-4.5 1.253">
                                            </path>
                                        </svg>
                                        <span class="text-xs font-medium">No Cover</span>
                                    </div>
                                @endif

                                @if ($habis)
                                    <!-- Overlay Dipinjam Semua -->
                                    <div
                                        class="absolute inset-0 bg-red-900/30 backdrop-blur-[1px] flex items-center justify-center z-10">
                                        <div
                                            class="bg-red-600/90 text-white font-black text-sm md:text-base px-2 py-2 border-y-2 border-white transform -rotate-12 shadow-2xl tracking-widest uppercase pointer-events-none text-center">
                                            TIDAK TERSEDIA
                                        </div>
                                    </div>
                                @endif

                                <div class="absolute top-2 right-2 flex justify-between items-start z-10">
                                    <span
                                        class="bg-white/90 backdrop-blur-md text-gray-800 text-[10px] sm:text-xs font-bold px-2 py-1 rounded shadow-sm">
                                        {{ $item->nomor_panggil ?? '-' }}
                                    </span>
                                </div>
                            </div>

                            <!-- Content -->
                            <div class="p-4 flex-grow flex flex-col">
                                <h2 class="text-xs sm:text-sm font-bold text-gray-900 mb-1 line-clamp-2 {{ !$habis ? 'group-hover:text-blue-600 transition-colors' : '' }} leading-snug"
                                    title="{{ $item->judul }}">
                                    {{ $item->judul }}
                                </h2>
                                <p class="text-blue-600 font-medium text-[10px] sm:text-xs mb-2 line-clamp-1">
                                    {{ $item->pengarang }}
                                </p>
                                <div class="mt-auto pt-3 flex flex-col gap-2 border-t border-gray-50">
                                    <div class="flex justify-between items-center text-[10px] text-gray-500">
                                        <span class="truncate pr-1">{{ $item->penerbit }}</span>
                                        <span
                                            class="font-medium bg-gray-100 px-1.5 py-0.5 rounded">{{ $item->tahun_terbit ?? '-' }}</span>
                                    </div>
                                </div>
                            </div>

                            <!-- Action Area -->
                            <div class="px-4 pb-4 pt-0 mt-auto relative z-30">
                                @if ($habis)
                                    <button disabled
                                        class="w-full text-center bg-gray-100 text-gray-500 text-xs font-semibold py-2 px-3 rounded-xl border border-gray-200 cursor-not-allowed opacity-80 backdrop-blur-sm">
                                        Habis Dipinjam
                                    </button>
                                @else
                                    <a href="{{ route('katalog.show', $item->id_buku ?? 1) }}"
                                        class="block w-full text-center bg-gray-50 hover:bg-blue-600 text-gray-700 hover:text-white text-xs font-semibold py-2 px-3 rounded-xl border border-gray-200 hover:border-transparent transition-all duration-300">
                                        Lihat Detail
                                    </a>
                                @endif
                            </div>
                        </div>
                    @endforeach
                </div>
            </div>
        @endif
    </div>
</section>
