/**
 * CATEGORY GRID - FRONTEND STYLES
 * Ottimizzato per performance e design moderno
 */

/* ===============================
   CONTAINER PRINCIPALE
   =============================== */

.category-grid-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
}

.category-grid-container {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
    margin: 0 auto;
    position: relative;
}

/* ===============================
   CONTENITORI CATEGORIA - DIMENSIONI FISSE
   =============================== */

.category-container {
    width: 300px;
    height: 220px;
    position: relative;
    overflow: hidden;
    border-radius: 12px;
    cursor: pointer;
    text-decoration: none;
    display: block;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    transform: translateZ(0); /* Hardware acceleration */
    backface-visibility: hidden;
    will-change: transform;
}

/* ===============================
   IMMAGINE DI SFONDO
   =============================== */

.category-image {
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    position: relative;
    transition: all 0.4s ease;
}

/* ===============================
   OVERLAY E TITOLO - CENTRATO
   =============================== */

.category-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        180deg,
        rgba(0, 0, 0, 0.1) 0%,
        rgba(0, 0, 0, 0.3) 40%,
        rgba(0, 0, 0, 0.7) 100%
    );
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 2;
    text-align: center;
}

.category-title {
    color: #ffffff;
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    line-height: 1.2;
    letter-spacing: -0.3px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    text-decoration: none;
    text-align: center;
    width: 100%;
}

/* ===============================
   EFFETTO ZOOM HOVER - SOLO DESKTOP
   =============================== */

@media (min-width: 769px) {
    .zoom-hover:hover {
        transform: scale(1.05) translateY(-5px);
        box-shadow: 0 15px 35px rgba(20, 141, 70, 0.2);
        z-index: 10;
    }
    
    .zoom-hover:hover .category-image {
        transform: scale(1.08);
    }
    
    .zoom-hover:hover .category-overlay {
        background: linear-gradient(
            180deg,
            rgba(0, 0, 0, 0.15) 0%,
            rgba(0, 0, 0, 0.4) 40%,
            rgba(0, 0, 0, 0.8) 100%
        );
    }
    
    .zoom-hover:hover .category-title {
        transform: translateY(-2px);
        text-shadow: 0 3px 12px rgba(0, 0, 0, 0.6);
    }
}

/* ===============================
   STATI INTERATTIVI
   =============================== */

.category-container:focus {
    outline: 3px solid #148d46;
    outline-offset: 2px;
}

.category-container:active {
    transform: scale(0.98);
}

/* ===============================
   RESPONSIVE - MANTENIMENTO PROPORZIONI
   =============================== */

/* Desktop: mantieni dimensioni fisse sempre */
@media (min-width: 1201px) {
    .category-grid-wrapper {
        overflow-x: auto;
        padding-left: 20px;
        padding-right: 20px;
    }
}

/* Tablet grande */
@media (max-width: 1200px) and (min-width: 993px) {
    .category-container {
        width: 280px;
        height: 206px;
    }
    
    .category-title {
        font-size: 1.4rem;
    }
    
    .category-overlay {
        padding: 20px;
    }
}

/* Tablet */
@media (max-width: 992px) and (min-width: 769px) {
    .category-container {
        width: 250px;
        height: 184px;
    }
    
    .category-title {
        font-size: 1.3rem;
    }
    
    .category-overlay {
        padding: 18px;
    }
}

/* Mobile - Disabilita zoom e adatta dimensioni */
@media (max-width: 768px) {
    .category-grid-wrapper {
        padding-left: 15px;
        padding-right: 15px;
    }
    
    .category-grid-container {
        flex-wrap: wrap;
        justify-content: center;
        gap: 15px !important;
    }
    
    .category-container {
        width: 160px;
        height: 118px;
        /* Disabilita effetti hover su mobile */
        transform: none !important;
        transition: none !important;
    }
    
    .category-container:hover {
        transform: none !important;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1) !important;
    }
    
    .category-container:hover .category-image {
        transform: none !important;
    }
    
    .category-title {
        font-size: 1rem;
        line-height: 1.1;
    }
    
    .category-overlay {
        padding: 12px;
    }
}

/* Mobile piccolo */
@media (max-width: 480px) {
    .category-grid-wrapper {
        padding-left: 10px;
        padding-right: 10px;
    }
    
    .category-container {
        width: 140px;
        height: 103px;
    }
    
    .category-title {
        font-size: 0.9rem;
    }
    
    .category-overlay {
        padding: 10px;
    }
}

/* ===============================
   CENTRATURA DINAMICA GRIGLIA
   =============================== */

/* 1 contenitore */
.category-grid-container[data-count="1"] {
    max-width: 300px;
}

/* 2 contenitori */
.category-grid-container[data-count="2"] {
    max-width: calc(600px + var(--spacing, 15px));
}

/* 3 contenitori */
.category-grid-container[data-count="3"] {
    max-width: calc(900px + calc(var(--spacing, 15px) * 2));
}

/* 4 contenitori */
.category-grid-container[data-count="4"] {
    max-width: calc(1200px + calc(var(--spacing, 15px) * 3));
}

/* ===============================
   PLACEHOLDER STATO VUOTO
   =============================== */

.category-grid-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 220px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border: 2px dashed #148d46;
    border-radius: 12px;
    color: #148d46;
    font-weight: 600;
    font-size: 1.1rem;
    margin: 20px;
    text-align: center;
    padding: 40px 20px;
}

.category-grid-placeholder::before {
    content: '📁';
    font-size: 2rem;
    display: block;
    margin-bottom: 12px;
}

/* ===============================
   PERFORMANCE OPTIMIZATIONS
   =============================== */

.category-container {
    contain: layout style paint;
    content-visibility: auto;
}

.category-image {
    contain: strict;
    backface-visibility: hidden;
}

/* Preload immagini vicine */
.category-container:hover + .category-container .category-image {
    content-visibility: visible;
}

/* ===============================
   ACCESSIBILITÀ
   =============================== */

@media (prefers-reduced-motion: reduce) {
    .category-container,
    .category-image,
    .category-title {
        transition: none !important;
        animation: none !important;
    }
    
    .zoom-hover:hover {
        transform: none !important;
    }
}

/* Navigazione keyboard */
.category-container:focus-visible {
    outline: 3px solid #148d46;
    outline-offset: 3px;
    border-radius: 15px;
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .category-overlay {
        background: linear-gradient(
            180deg,
            rgba(0, 0, 0, 0.3) 0%,
            rgba(0, 0, 0, 0.6) 40%,
            rgba(0, 0, 0, 0.9) 100%
        );
    }
    
    .category-title {
        text-shadow: 0 2px 4px rgba(0, 0, 0, 1);
        font-weight: 800;
    }
}

/* ===============================
   ANIMAZIONI DI INGRESSO
   =============================== */

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.category-container {
    animation: fadeInUp 0.6s ease forwards;
}

.category-container:nth-child(1) { animation-delay: 0ms; }
.category-container:nth-child(2) { animation-delay: 150ms; }
.category-container:nth-child(3) { animation-delay: 300ms; }
.category-container:nth-child(4) { animation-delay: 450ms; }

/* ===============================
   UTILITY CLASSES
   =============================== */

/* Forza centratura */
.category-grid-center {
    justify-content: center !important;
}

/* Varianti spaziatura */
.category-grid-tight {
    gap: 10px !important;
}

.category-grid-loose {
    gap: 25px !important;
}