{{-- Bloque: Cuadrícula de Productos --}}
<section class="py-12 px-4 max-w-7xl mx-auto">
    @if($title)
        <h2 class="font-display text-3xl md:text-4xl text-olive text-center mb-10">{{ $title }}</h2>
    @endif

    @php
        $gridCols = [2 => 'sm:grid-cols-2', 3 => 'sm:grid-cols-2 lg:grid-cols-3', 4 => 'sm:grid-cols-2 lg:grid-cols-4'][$columns] ?? 'sm:grid-cols-2 lg:grid-cols-4';
    @endphp

    @if($products->isEmpty())
        <p class="text-center text-gray-500">No hay productos que coincidan con este filtro.</p>
    @else
        <div class="grid grid-cols-1 {{ $gridCols }} gap-6">
            @foreach($products as $product)
                <article class="group bg-white rounded-xl overflow-hidden shadow-sm hover:shadow-md transition">
                    <a href="{{ route('store.product', $product->slug) }}" class="block relative">
                        <img src="{{ $product->image_url ?: 'https://placehold.co/400x400/F7F3EE/4A5D4D?text=Producto' }}"
                             alt="{{ $product->name }}"
                             class="w-full aspect-square object-cover group-hover:scale-105 transition">
                        @if($product->is_on_sale && $product->discount_percent > 0)
                            <span class="absolute top-3 left-3 bg-olive text-beige text-xs font-semibold px-2 py-1 rounded">
                                -{{ $product->discount_percent }}%
                            </span>
                        @endif
                    </a>
                    <div class="p-4">
                        <p class="text-xs uppercase tracking-wide text-gray-400">{{ $product->brand->name ?? '' }}</p>
                        <h3 class="font-display text-lg text-olive leading-tight">{{ $product->name }}</h3>
                        <div class="mt-2 flex items-baseline gap-2">
                            <span class="text-olive font-semibold">S/ {{ number_format($product->active_price, 2) }}</span>
                            @if($product->is_on_sale && $product->sale_price)
                                <span class="text-sm text-gray-400 line-through">S/ {{ number_format($product->price, 2) }}</span>
                            @endif
                        </div>
                        <form method="POST" action="{{ route('cart.add') }}" class="mt-3">
                            @csrf
                            <input type="hidden" name="product_id" value="{{ $product->id }}">
                            <input type="hidden" name="quantity" value="1">
                            <button class="w-full bg-olive text-beige py-2 rounded-lg text-sm hover:bg-olive/90 transition">
                                Añadir al carrito
                            </button>
                        </form>
                    </div>
                </article>
            @endforeach
        </div>
    @endif
</section>
