'use client';

import { useState, useMemo } from 'react';
import Link from 'next/link';
import { NavBar } from '@/components/layout/NavBar';
import { CartDrawer, CartButton } from '@/components/shop/CartDrawer';
import { useCartStore } from '@/stores/cartStore';

// ==========================================
// SVG Icons (inline, same pattern as actu)
// ==========================================

function IconStar({ size = 8 }: { size?: number }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round">
      <polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/>
    </svg>
  );
}

function IconShoppingCart({ size = 12 }: { size?: number }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="8" cy="21" r="1"/><circle cx="19" cy="21" r="1"/><path d="M2.05 2.05h2l2.66 12.42a2 2 0 0 0 2 1.58h9.78a2 2 0 0 0 1.95-1.57l1.65-7.43H5.12"/>
    </svg>
  );
}

function IconTag({ size = 12 }: { size?: number }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
      <path d="M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z"/><circle cx="7.5" cy="7.5" r=".5" fill="currentColor"/>
    </svg>
  );
}

function IconSearch({ size = 14 }: { size?: number }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/>
    </svg>
  );
}

// ==========================================
// PRODUCT CATALOG
// ==========================================

type ProductCategory = 'premium' | 'vetements' | 'accessoires' | 'goodies' | 'digital';

interface Product {
  id: string;
  name: string;
  brand: string;
  category: ProductCategory;
  price: number;
  originalPrice?: number;
  image: string;
  imageColor: string;
  colors: string[];
  sizes: string[];
  description: string;
  popular?: boolean;
  promo?: boolean;
}

const PRODUCTS: Product[] = [
  // === VETEMENTS ===
  {
    id: 'ts-mafiaz-noir',
    name: 'T-Shirt Mafiaz Classic',
    brand: 'Mafiaz.World',
    category: 'vetements',
    price: 24.99,
    image: '',
    imageColor: '#8B0000',
    colors: ['Noir', 'Blanc', 'Gris', 'Rouge'],
    sizes: ['S', 'M', 'L', 'XL', 'XXL'],
    description: 'T-shirt premium 100% coton bio avec logo Mafiaz brodé',
    popular: true,
  },
  {
    id: 'hoodie-ombres',
    name: 'Hoodie Ombres & Lumières',
    brand: 'Mafiaz.World',
    category: 'vetements',
    price: 49.99,
    originalPrice: 59.99,
    image: '',
    imageColor: '#1a1a2e',
    colors: ['Noir', 'Anthracite', 'Bordeaux'],
    sizes: ['S', 'M', 'L', 'XL', 'XXL'],
    description: 'Sweat à capuche épais — logo doré sérigraphié',
    popular: true,
    promo: true,
  },
  {
    id: 'ts-lupus',
    name: 'T-Shirt Mafia Lupus',
    brand: 'Mafiaz.World',
    category: 'vetements',
    price: 24.99,
    image: '',
    imageColor: '#2d1b4e',
    colors: ['Noir', 'Blanc', 'Violet'],
    sizes: ['S', 'M', 'L', 'XL', 'XXL'],
    description: 'T-shirt exclusif collection Mafia Lupus',
  },
  // === ACCESSOIRES ===
  {
    id: 'cap-mafiaz',
    name: 'Casquette Mafiaz',
    brand: 'Mafiaz.World',
    category: 'accessoires',
    price: 19.99,
    image: '',
    imageColor: '#333333',
    colors: ['Noir', 'Kaki', 'Bordeaux'],
    sizes: [],
    description: 'Casquette snapback brodée — ajustable',
    popular: true,
  },
  {
    id: 'phone-case',
    name: 'Coque Téléphone O&L',
    brand: 'Mafiaz.World',
    category: 'accessoires',
    price: 14.99,
    image: '',
    imageColor: '#0d0d0d',
    colors: ['Noir', 'Transparent'],
    sizes: [],
    description: 'Coque rigide compatible iPhone & Samsung — design exclusif',
  },
  // === GOODIES ===
  {
    id: 'mug-mafiaz',
    name: 'Mug Mafiaz "Don"',
    brand: 'Mafiaz.World',
    category: 'goodies',
    price: 12.99,
    image: '',
    imageColor: '#4a1010',
    colors: [],
    sizes: [],
    description: 'Mug céramique 350ml — « Le pouvoir se sert chaud »',
  },
  {
    id: 'stickers-pack',
    name: 'Pack Stickers x12',
    brand: 'Mafiaz.World',
    category: 'goodies',
    price: 7.99,
    image: '',
    imageColor: '#c41e1e',
    colors: [],
    sizes: [],
    description: '12 stickers vinyle waterproof — logos, factions, citations',
    popular: true,
  },
  {
    id: 'poster-map',
    name: 'Poster Carte du Monde',
    brand: 'Mafiaz.World',
    category: 'goodies',
    price: 16.99,
    originalPrice: 19.99,
    image: '',
    imageColor: '#1e3a5f',
    colors: [],
    sizes: [],
    description: 'Poster A2 (420×594mm) — carte détaillée du monde O&L',
    promo: true,
  },
  // === DIGITAL ===
  {
    id: 'wallpaper-pack',
    name: 'Pack Wallpapers HD',
    brand: 'Mafiaz.World',
    category: 'digital',
    price: 3.99,
    image: '',
    imageColor: '#0f0f23',
    colors: [],
    sizes: [],
    description: '10 fonds d’écran HD/4K — PC, tablette, mobile',
  },
  {
    id: 'artbook-digital',
    name: 'Artbook Digital',
    brand: 'Mafiaz.World',
    category: 'digital',
    price: 9.99,
    image: '',
    imageColor: '#2a1f3d',
    colors: [],
    sizes: [],
    description: 'PDF 80 pages — concept arts, personnages, lore exclusif',
  },
  // === O&L PREMIUM (in-game) ===
  {
    id: 'dagaz-100',
    name: '100 Dagaz',
    brand: 'O&L Premium',
    category: 'premium',
    price: 1.99,
    image: '',
    imageColor: '#c89b3c',
    colors: [],
    sizes: [],
    description: '100 Dagaz — monnaie premium convertible en Infinites',
    popular: true,
  },
  {
    id: 'dagaz-500',
    name: '500 Dagaz',
    brand: 'O&L Premium',
    category: 'premium',
    price: 7.99,
    originalPrice: 9.95,
    image: '',
    imageColor: '#c89b3c',
    colors: [],
    sizes: [],
    description: '500 Dagaz — 20% de bonus',
    popular: true,
    promo: true,
  },
  {
    id: 'dagaz-1000',
    name: '1000 Dagaz',
    brand: 'O&L Premium',
    category: 'premium',
    price: 12.99,
    originalPrice: 19.90,
    image: '',
    imageColor: '#c89b3c',
    colors: [],
    sizes: [],
    description: '1000 Dagaz — 35% de bonus',
    promo: true,
  },
  {
    id: 'pass-tiempo-bronze',
    name: 'Pass Tiempo Bronze',
    brand: 'O&L Premium',
    category: 'premium',
    price: 1.99,
    image: '',
    imageColor: '#cd7f32',
    colors: [],
    sizes: [],
    description: 'VIP 7 jours — bonus XP x1.5, missions accelerees',
  },
  {
    id: 'pass-tiempo-argent',
    name: 'Pass Tiempo Argent',
    brand: 'O&L Premium',
    category: 'premium',
    price: 4.99,
    image: '',
    imageColor: '#c0c0c0',
    colors: [],
    sizes: [],
    description: 'VIP 30 jours — bonus XP x2, coffre elargi, commissions reduites',
    popular: true,
  },
  {
    id: 'pass-tiempo-or',
    name: 'Pass Tiempo Or',
    brand: 'O&L Premium',
    category: 'premium',
    price: 11.99,
    originalPrice: 14.97,
    image: '',
    imageColor: '#ffd700',
    colors: [],
    sizes: [],
    description: 'VIP 90 jours — tous les bonus, skin exclusif, -50% commissions',
    popular: true,
    promo: true,
  },
  {
    id: 'character-slot',
    name: 'Slot Personnage',
    brand: 'O&L Premium',
    category: 'premium',
    price: 4.99,
    image: '',
    imageColor: '#8b0000',
    colors: [],
    sizes: [],
    description: 'Debloquer un emplacement de personnage supplementaire',
  },
  {
    id: 'name-change',
    name: 'Changement de Nom',
    brand: 'O&L Premium',
    category: 'premium',
    price: 2.99,
    image: '',
    imageColor: '#4a1a5e',
    colors: [],
    sizes: [],
    description: 'Changer le nom de votre personnage actif',
  },
];

const CATEGORIES: { id: ProductCategory | 'all'; label: string }[] = [
  { id: 'all', label: 'Tout' },
  { id: 'premium', label: 'O&L Premium' },
  { id: 'vetements', label: 'Vêtements' },
  { id: 'accessoires', label: 'Accessoires' },
  { id: 'goodies', label: 'Goodies' },
  { id: 'digital', label: 'Digital' },
];

const ALL_COLORS = ['Noir', 'Blanc', 'Gris', 'Rouge', 'Anthracite', 'Bordeaux', 'Violet', 'Kaki', 'Transparent'];
const ALL_SIZES = ['S', 'M', 'L', 'XL', 'XXL'];

const PRICE_RANGES = [
  { label: 'Tous', min: 0, max: 999 },
  { label: '< 10€', min: 0, max: 10 },
  { label: '10-20€', min: 10, max: 20 },
  { label: '20-40€', min: 20, max: 40 },
  { label: '> 40€', min: 40, max: 999 },
];

// ==========================================
// Product Card Component
// ==========================================

function ProductCard({ product, onAddToCart }: { product: Product; onAddToCart: (product: Product, color?: string, size?: string) => void }) {
  const [selectedColor, setSelectedColor] = useState<string | undefined>(product.colors[0] || undefined);
  const [selectedSize, setSelectedSize] = useState<string | undefined>(product.sizes[0] || undefined);

  return (
    <div
      className="rounded-xl overflow-hidden hover:scale-[1.02] transition-all cursor-pointer group relative"
      style={{ background: 'rgba(255,255,255,0.02)', border: '1px solid var(--border-dark)' }}
    >
      {product.promo && (
        <div
          className="absolute top-2 left-2 z-10 px-2 py-0.5 rounded text-[9px] font-bold"
          style={{ background: 'var(--color-red)', color: 'white' }}
        >
          PROMO
        </div>
      )}
      {product.popular && (
        <div
          className="absolute top-2 right-2 z-10 px-2 py-0.5 rounded text-[9px] font-bold flex items-center gap-1"
          style={{ background: 'var(--color-gold)', color: '#0a0a0a' }}
        >
          <IconStar size={8} /> POPULAIRE
        </div>
      )}

      {/* Image placeholder */}
      <div
        className="aspect-square flex items-center justify-center relative overflow-hidden"
        style={{ background: product.imageColor }}
      >
        <div
          className="absolute inset-0 opacity-20"
          style={{
            background: `radial-gradient(circle at 30% 40%, rgba(255,255,255,0.15), transparent 60%)`,
          }}
        />
        <span
          className="font-gothic text-xl tracking-wider opacity-40 text-center px-4"
          style={{ color: 'rgba(255,255,255,0.7)' }}
        >
          {product.name}
        </span>
      </div>

      {/* Info */}
      <div className="p-4">
        <p className="text-[10px] mb-0.5" style={{ color: 'var(--text-muted)' }}>{product.brand}</p>
        <h3 className="font-bold text-sm mb-1" style={{ color: 'var(--text-primary)' }}>{product.name}</h3>
        <p className="text-[10px] mb-2 leading-relaxed" style={{ color: 'var(--text-muted)' }}>{product.description}</p>

        {/* Color selector */}
        {product.colors.length > 0 && (
          <div className="mb-2">
            <p className="text-[9px] mb-1 uppercase tracking-wide" style={{ color: 'var(--text-muted)' }}>Coloris</p>
            <div className="flex flex-wrap gap-1">
              {product.colors.map(c => (
                <button
                  key={c}
                  onClick={() => setSelectedColor(c)}
                  className="text-[9px] px-1.5 py-0.5 rounded transition-colors"
                  style={{
                    background: selectedColor === c ? 'var(--color-gold)' : 'var(--bg-tertiary)',
                    color: selectedColor === c ? '#0a0a0a' : 'var(--text-muted)',
                    border: '1px solid var(--border-dark)',
                    fontWeight: selectedColor === c ? 700 : 400,
                  }}
                >
                  {c}
                </button>
              ))}
            </div>
          </div>
        )}

        {/* Size selector */}
        {product.sizes.length > 0 && (
          <div className="mb-3">
            <p className="text-[9px] mb-1 uppercase tracking-wide" style={{ color: 'var(--text-muted)' }}>Taille</p>
            <div className="flex flex-wrap gap-1">
              {product.sizes.map(s => (
                <button
                  key={s}
                  onClick={() => setSelectedSize(s)}
                  className="text-[9px] px-2 py-0.5 rounded transition-colors"
                  style={{
                    background: selectedSize === s ? 'var(--color-gold)' : 'var(--bg-tertiary)',
                    color: selectedSize === s ? '#0a0a0a' : 'var(--text-muted)',
                    border: '1px solid var(--border-dark)',
                    fontWeight: selectedSize === s ? 700 : 400,
                  }}
                >
                  {s}
                </button>
              ))}
            </div>
          </div>
        )}

        <div className="flex justify-between items-center mt-1">
          <div>
            <span className="text-lg font-bold" style={{ color: 'var(--color-gold)' }}>
              {product.price.toFixed(2)}€
            </span>
            {product.originalPrice && (
              <span className="text-xs line-through ml-2" style={{ color: 'var(--text-muted)' }}>
                {product.originalPrice.toFixed(2)}€
              </span>
            )}
          </div>
          <button
            onClick={() => onAddToCart(product, selectedColor, selectedSize)}
            className="px-3 py-1.5 rounded text-xs font-bold transition-all hover:scale-105 flex items-center gap-1"
            style={{
              background: 'linear-gradient(135deg, var(--color-red-dark), var(--color-red))',
              color: 'white',
            }}
          >
            <IconShoppingCart size={12} />
            Ajouter
          </button>
        </div>
      </div>
    </div>
  );
}

// ==========================================
// Page
// ==========================================

export default function ShopPage() {
  const [search, setSearch] = useState('');
  const [category, setCategory] = useState<ProductCategory | 'all'>('all');
  const [priceRange, setPriceRange] = useState(0);
  const [filterColor, setFilterColor] = useState<string | null>(null);
  const [filterSize, setFilterSize] = useState<string | null>(null);
  const [suggestions, setSuggestions] = useState<Product[]>([]);

  const showClothingFilters = category === 'vetements' || category === 'all';

  const filtered = useMemo(() => {
    let result = [...PRODUCTS];
    if (category !== 'all') result = result.filter(p => p.category === category);
    if (search.length >= 2) result = result.filter(p =>
      p.name.toLowerCase().includes(search.toLowerCase()) ||
      p.brand.toLowerCase().includes(search.toLowerCase()) ||
      p.description.toLowerCase().includes(search.toLowerCase())
    );
    const range = PRICE_RANGES[priceRange];
    result = result.filter(p => p.price >= range.min && p.price <= range.max);
    if (filterColor) result = result.filter(p => p.colors.includes(filterColor));
    if (filterSize) result = result.filter(p => p.sizes.includes(filterSize));
    return result;
  }, [category, search, priceRange, filterColor, filterSize]);

  const promoProducts = PRODUCTS.filter(p => p.promo);
  const popularProducts = PRODUCTS.filter(p => p.popular);

  const handleSearch = (val: string) => {
    setSearch(val);
    if (val.length >= 2) {
      setSuggestions(PRODUCTS.filter(p =>
        p.name.toLowerCase().includes(val.toLowerCase()) ||
        p.brand.toLowerCase().includes(val.toLowerCase())
      ).slice(0, 5));
    } else {
      setSuggestions([]);
    }
  };

  const addItem = useCartStore(s => s.addItem);

  const handleAddToCart = (product: Product, color?: string, size?: string) => {
    addItem({
      productId: product.id,
      name: product.name,
      brand: product.brand,
      price: product.price,
      image: product.imageColor,
      color,
      size,
    });
  };

  return (
    <div className="min-h-screen" style={{ background: 'var(--bg-primary)' }}>
      <NavBar />
      <CartDrawer />

      <div className="max-w-7xl mx-auto px-4 py-6">
        {/* Header */}
        <div className="flex items-center justify-between mb-2">
          <div>
            <h1 className="font-gothic text-3xl text-gold-gradient">Boutique</h1>
            <p className="font-impact text-xs mt-1 tracking-wide" style={{ color: 'var(--text-muted)' }}>
              MERCH OFFICIEL &mdash; MAFIAZ.WORLD
            </p>
          </div>
          <div className="sticky top-14 z-30">
            <CartButton />
          </div>
        </div>

        <p className="text-sm mb-6" style={{ color: 'var(--text-secondary)' }}>
          Représentez votre allégeance. Vêtements, goodies et contenus exclusifs Ombres &amp; Lumières.
        </p>

        {/* Category tabs */}
        <div className="flex gap-1.5 mb-6 overflow-x-auto pb-1">
          {CATEGORIES.map((cat) => {
            const isActive = category === cat.id;
            return (
              <button
                key={cat.id}
                onClick={() => { setCategory(cat.id as ProductCategory | 'all'); setFilterColor(null); setFilterSize(null); }}
                className="px-4 py-2 rounded-lg text-xs font-medium whitespace-nowrap transition-all"
                style={{
                  background: isActive
                    ? (cat.id === 'premium'
                      ? 'linear-gradient(135deg, #8b6914, #c89b3c)'
                      : 'linear-gradient(135deg, var(--color-red-dark), var(--color-red))')
                    : (cat.id === 'premium' ? 'rgba(200,155,60,0.08)' : 'rgba(255,255,255,0.03)'),
                  color: isActive
                    ? (cat.id === 'premium' ? '#000' : 'white')
                    : (cat.id === 'premium' ? '#c89b3c' : 'var(--text-secondary)'),
                  border: isActive ? 'none' : (cat.id === 'premium' ? '1px solid rgba(200,155,60,0.3)' : '1px solid var(--border-dark)'),
                }}
              >
                {cat.label}
              </button>
            );
          })}
        </div>

        <div className="flex gap-6">
          {/* === SIDEBAR LEFT: Filters === */}
          <aside className="w-56 shrink-0 hidden lg:block space-y-6">
            {/* Search */}
            <div className="relative">
              <h3 className="font-impact text-xs mb-2" style={{ color: 'var(--color-gold)' }}>RECHERCHE</h3>
              <div className="relative">
                <div className="absolute left-2.5 top-1/2 -translate-y-1/2" style={{ color: 'var(--text-muted)' }}>
                  <IconSearch size={14} />
                </div>
                <input
                  type="text"
                  value={search}
                  onChange={e => handleSearch(e.target.value)}
                  placeholder="2 lettres min..."
                  className="w-full pl-8 pr-3 py-2 rounded-lg text-xs outline-none"
                  style={{ background: 'var(--bg-tertiary)', color: 'var(--text-primary)', border: '1px solid var(--border-dark)' }}
                />
              </div>
              {suggestions.length > 0 && (
                <div
                  className="absolute left-0 right-0 top-full mt-1 rounded-lg z-20 overflow-hidden"
                  style={{ background: 'var(--bg-secondary)', border: '1px solid var(--border-dark)' }}
                >
                  {suggestions.map(s => (
                    <button
                      key={s.id}
                      onClick={() => { setSearch(s.name); setSuggestions([]); }}
                      className="w-full text-left px-3 py-2 text-xs hover:bg-white/5"
                      style={{ color: 'var(--text-primary)', borderBottom: '1px solid var(--border-dark)' }}
                    >
                      {s.name} <span style={{ color: 'var(--text-muted)' }}>&mdash; {s.price.toFixed(2)}€</span>
                    </button>
                  ))}
                </div>
              )}
            </div>

            {/* Price filter */}
            <div>
              <h3 className="font-impact text-xs mb-2" style={{ color: 'var(--color-gold)' }}>PRIX</h3>
              {PRICE_RANGES.map((r, i) => (
                <button
                  key={i}
                  onClick={() => setPriceRange(i)}
                  className="block w-full text-left px-3 py-1 rounded text-xs mb-0.5"
                  style={{
                    color: priceRange === i ? 'var(--color-gold)' : 'var(--text-muted)',
                    background: priceRange === i ? 'var(--bg-tertiary)' : 'transparent',
                  }}
                >
                  {r.label}
                </button>
              ))}
            </div>

            {/* Size filter (only when clothing visible) */}
            {showClothingFilters && (
              <div>
                <h3 className="font-impact text-xs mb-2" style={{ color: 'var(--color-gold)' }}>TAILLE</h3>
                <div className="flex flex-wrap gap-1">
                  {ALL_SIZES.map(s => (
                    <button
                      key={s}
                      onClick={() => setFilterSize(filterSize === s ? null : s)}
                      className="px-2 py-1 rounded text-[10px] transition-colors"
                      style={{
                        background: filterSize === s ? 'var(--color-gold)' : 'var(--bg-tertiary)',
                        color: filterSize === s ? '#0a0a0a' : 'var(--text-muted)',
                        border: '1px solid var(--border-dark)',
                      }}
                    >
                      {s}
                    </button>
                  ))}
                </div>
              </div>
            )}

            {/* Color filter */}
            {showClothingFilters && (
              <div>
                <h3 className="font-impact text-xs mb-2" style={{ color: 'var(--color-gold)' }}>COLORIS</h3>
                <div className="flex flex-wrap gap-1">
                  {ALL_COLORS.map(c => (
                    <button
                      key={c}
                      onClick={() => setFilterColor(filterColor === c ? null : c)}
                      className="px-2 py-1 rounded text-[10px] transition-colors"
                      style={{
                        background: filterColor === c ? 'var(--color-gold)' : 'var(--bg-tertiary)',
                        color: filterColor === c ? '#0a0a0a' : 'var(--text-muted)',
                        border: '1px solid var(--border-dark)',
                      }}
                    >
                      {c}
                    </button>
                  ))}
                </div>
              </div>
            )}

            {/* Promotions sidebar */}
            <div>
              <h3 className="font-impact text-xs mb-2 flex items-center gap-1" style={{ color: 'var(--color-red)' }}>
                <IconTag size={12} /> PROMOTIONS
              </h3>
              {promoProducts.length > 0 ? promoProducts.map(p => (
                <div
                  key={p.id}
                  className="rounded-lg p-3 mb-2"
                  style={{ background: 'rgba(255,255,255,0.02)', border: '1px solid var(--border-dark)' }}
                >
                  <h4 className="text-xs font-bold" style={{ color: 'var(--text-primary)' }}>{p.name}</h4>
                  <div className="flex items-center gap-2 mt-1">
                    <span className="text-sm font-bold" style={{ color: 'var(--color-red)' }}>{p.price.toFixed(2)}€</span>
                    {p.originalPrice && <span className="text-xs line-through" style={{ color: 'var(--text-muted)' }}>{p.originalPrice.toFixed(2)}€</span>}
                  </div>
                </div>
              )) : (
                <p className="text-[10px]" style={{ color: 'var(--text-muted)' }}>Aucune promo en cours</p>
              )}
            </div>
          </aside>

          {/* === MAIN: Product Grid === */}
          <main className="flex-1">
            {/* Results count */}
            <div className="flex items-center justify-between mb-4">
              <p className="text-xs" style={{ color: 'var(--text-muted)' }}>
                {filtered.length} produit{filtered.length !== 1 ? 's' : ''}
                {category !== 'all' && ` dans ${CATEGORIES.find(c => c.id === category)?.label}`}
              </p>
            </div>

            <div className="grid sm:grid-cols-2 xl:grid-cols-3 gap-4">
              {filtered.map(product => (
                <ProductCard
                  key={product.id}
                  product={product}
                  onAddToCart={handleAddToCart}
                />
              ))}
            </div>

            {filtered.length === 0 && (
              <div
                className="text-center py-16 rounded-lg"
                style={{ background: 'rgba(255,255,255,0.02)', border: '1px solid var(--border-dark)' }}
              >
                <p className="text-sm" style={{ color: 'var(--text-muted)' }}>Aucun produit trouvé</p>
                <button
                  onClick={() => { setCategory('all'); setSearch(''); setPriceRange(0); setFilterColor(null); setFilterSize(null); }}
                  className="mt-3 px-4 py-2 rounded-lg text-xs transition-all hover:scale-105"
                  style={{
                    background: 'rgba(255,255,255,0.05)',
                    color: 'var(--color-gold)',
                    border: '1px solid var(--border-dark)',
                  }}
                >
                  Réinitialiser les filtres
                </button>
              </div>
            )}

            {/* Popular section */}
            {category === 'all' && search.length < 2 && (
              <div className="mt-10">
                <h2 className="font-gothic text-xl text-gold-gradient mb-4">Populaires</h2>
                <div className="grid sm:grid-cols-2 xl:grid-cols-4 gap-3">
                  {popularProducts.map(product => (
                    <div
                      key={product.id}
                      className="rounded-lg p-3 transition-all hover:scale-[1.02] cursor-pointer"
                      style={{ background: 'rgba(255,255,255,0.02)', border: '1px solid var(--border-dark)' }}
                    >
                      <div
                        className="w-full h-20 rounded-lg mb-2 flex items-center justify-center"
                        style={{ background: product.imageColor }}
                      >
                        <span className="text-[10px] font-bold opacity-30" style={{ color: 'rgba(255,255,255,0.7)' }}>
                          {product.name}
                        </span>
                      </div>
                      <h4 className="text-xs font-bold truncate" style={{ color: 'var(--text-primary)' }}>{product.name}</h4>
                      <p className="text-[10px]" style={{ color: 'var(--text-muted)' }}>{product.brand}</p>
                      <div className="flex items-center justify-between mt-2">
                        <span className="text-sm font-bold" style={{ color: 'var(--color-gold)' }}>{product.price.toFixed(2)}€</span>
                        <button
                          onClick={() => handleAddToCart(product, product.colors[0], product.sizes[0])}
                          className="px-2 py-1 rounded text-[10px] font-bold transition-all hover:scale-105"
                          style={{
                            background: 'linear-gradient(135deg, var(--color-red-dark), var(--color-red))',
                            color: 'white',
                          }}
                        >
                          + Panier
                        </button>
                      </div>
                    </div>
                  ))}
                </div>
              </div>
            )}

            {/* Delivery banner */}
            <div
              className="mt-8 rounded-lg p-4 text-center"
              style={{
                background: 'linear-gradient(135deg, rgba(196,30,30,0.08), rgba(196,30,30,0.02))',
                border: '1px solid rgba(196,30,30,0.2)',
              }}
            >
              <p className="text-sm font-medium" style={{ color: 'var(--text-primary)' }}>
                Livraison offerte dès 50€ d&apos;achat
              </p>
              <p className="text-[10px] mt-1" style={{ color: 'var(--text-muted)' }}>
                Expédition sous 3-5 jours ouvrés &mdash; Retours gratuits sous 30 jours
              </p>
            </div>
          </main>
        </div>
      </div>

      {/* Footer */}
      <footer
        className="px-6 py-8 text-center text-xs mt-8"
        style={{ background: 'rgba(10,10,10,0.95)', borderTop: '1px solid var(--border-dark)', color: 'var(--text-muted)' }}
      >
        <div className="flex flex-wrap justify-center gap-4 mb-4">
          <Link href="/contact" className="hover:underline">Contact</Link>
          <Link href="/legal" className="hover:underline">Mentions légales</Link>
          <Link href="/privacy" className="hover:underline">Confidentialité</Link>
          <Link href="/terms" className="hover:underline">CGV</Link>
        </div>
        <p>&copy; 2026 Ombres &amp; Lumières &mdash; Mafiaz.World</p>
      </footer>
    </div>
  );
}
