{{-- REKOMENDASI / BUKU TERLARIS --}}
<section id="rekomendasi" class="py-24 bg-gray-50 relative overflow-hidden">
    <div class="absolute bottom-0 left-0 w-80 h-80 bg-primary-100/20 rounded-full blur-3xl"></div>

    <div class="max-w-7xl mx-auto px-6 relative z-10">
        <div class="flex flex-col md:flex-row justify-between items-start md:items-center mb-14 gap-4">
            <div>
                <div class="inline-flex items-center gap-2 px-4 py-2 bg-primary-50 rounded-full mb-4">
                    <i class="fas fa-star text-yellow-500 text-xs"></i>
                    <span class="text-xs font-semibold text-primary-600 tracking-wide">Paling Baru</span>
                </div>
                <h2 class="text-3xl md:text-4xl font-black text-gray-900 tracking-tight">
                    Koleksi <span class="gradient-text">Terbaru</span>
                </h2>
                <p class="text-gray-500 mt-2 max-w-md">
                    Buku-buku rilis baru dan penambahan paling anyar di perpustakaan kami.
                </p>
            </div>
            <a href="{{ route('katalog.index') }}"
                class="px-6 py-3 bg-white text-primary-600 rounded-2xl font-semibold text-sm border border-primary-200 hover:bg-primary-50 transition-colors shadow-sm inline-flex items-center gap-2">
                Lihat Semua Katalog <i class="fas fa-arrow-right text-xs"></i>
            </a>
        </div>

        @if (!empty($bukuTerbaru) && $bukuTerbaru->count())
            <div class="grid grid-cols-2 md:grid-cols-4 gap-6">
                @foreach ($bukuTerbaru 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">
                        <!-- Badge BUKU BARU (Pojok Kanan Atas Kartu) -->
                        @if (!$habis)
                            <div class="absolute top-0 right-0 z-20">
                                <div
                                    class="bg-gradient-to-r from-yellow-400 to-orange-500 text-white text-[9px] sm:text-[10px] font-extrabold px-3 py-1.5 shadow-lg rounded-bl-xl origin-top-right transform">
                                    <i class="fas fa-sparkles mr-1"></i> BUKU BARU
                                </div>
                            </div>
                        @endif

                        <!-- 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">Cover Tidak Tersedia</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-6 py-2 border-y-2 border-white transform -rotate-12 shadow-2xl tracking-widest uppercase pointer-events-none">
                                        TIDAK TERSEDIA
                                    </div>
                                </div>
                            @endif

                            <!-- Overlay Badges (Nomor Panggil) -->
                            <div class="absolute top-2 inset-x-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-sm sm:text-base 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-xs sm:text-sm 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] sm:text-xs 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-sm 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-sm 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>
        @else
            <div class="text-center py-20 bg-white rounded-3xl border border-gray-100">
                <div class="w-20 h-20 bg-gray-100 rounded-2xl flex items-center justify-center mx-auto mb-4">
                    <i class="fas fa-books text-gray-300 text-3xl"></i>
                </div>
                <p class="text-gray-400 font-medium">Belum ada koleksi buku untuk ditampilkan.</p>
                <p class="text-gray-300 text-sm mt-1">Silakan tambahkan buku melalui dashboard admin.</p>
            </div>
        @endif
    </div>
</section>
