/* === Custom Mega Menu === */

.custom-mega-menu {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
    width: 100%;
}

/* Search bar prima del menu (desktop: a sinistra della lista) */
.custom-menu-search {
    flex-shrink: 0;
    position: relative; /* per dropdown risultati ricerca AJAX */
}
.custom-menu-search .header-search-form {
    display: flex;
    margin: 0;
    width: 100%;
}
.custom-menu-search .header-search-input {
    width: 200px;
    max-width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}
/* Desktop: search in .header-left deve essere lunga il più possibile */
.header-left .custom-menu-search.custom-desktop-search {
    flex: 1 1 auto;
    min-width: 0;
}
.header-left .custom-menu-search.custom-desktop-search .header-search-form {
    width: 100%;
}
.header-left .custom-menu-search.custom-desktop-search .header-search-input {
    width: 100%;
    min-width: 0;
}
.custom-menu-search .header-search-input:focus {
    outline: none;
    border-color: #E74338;
}

.custom-menu-list {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 30px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.custom-menu-item {
    position: relative;
    display: inline-block;
}

.custom-menu-link {
    display: block;
    padding: 10px 0;
    color: #111;
    text-decoration: none;
    font-weight: 500;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.3s ease;
    position: relative;
}

.custom-menu-link:hover,
.custom-menu-link.active {
    color: #111;
    text-decoration: none;
}

.custom-menu-link:hover::after,
.custom-menu-link.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background-color: #E74338;
    animation: underlineExpand 0.3s ease;
}

@keyframes underlineExpand {
    from {
        transform: scaleX(0);
    }
    to {
        transform: scaleX(1);
    }
}

/* Mega Menu Dropdown */
.custom-menu-item-has-mega {
    position: static;
}

.custom-mega-dropdown {
    position: fixed;
    top: 160px;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    background: #fff;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    z-index: 2;
    margin-top: 0;
    padding: 30px 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Solo la classe mega-open controlla la visibilità (gestito da JavaScript) */
.custom-menu-item-has-mega.mega-open .custom-mega-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Mega menu sempre aperto sulla pagina categorie - DISABILITATO
   Il mega menu nell'header NON deve aprirsi sulla pagina categorie */
.custom-menu-item-has-mega.mega-always-open .custom-mega-dropdown {
    /* Non aprire il mega menu nell'header sulla pagina categorie */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
}

/* Su pagina categorie, il mega menu nell'header non deve essere visibile */
body.page-template-page-categorie .custom-menu-item-has-mega .custom-mega-dropdown {
    display: none !important;
}

/* Mega menu nella pagina categorie */
.categorie-page-mega {
    position: relative;
    top: 0;
    left: 0;
    right: 0;
    bottom: auto;
    width: 100%;
    opacity: 1;
    visibility: visible;
    transform: none;
    margin-top: 0;
    padding: 0;
    overflow: visible;
}

/* Su pagina categorie, il body non deve avere overflow hidden */
body.page-template-page-categorie .custom-menu-item-has-mega.mega-always-open ~ * {
    /* Reset overflow se applicato */
}

body.page-template-page-categorie {
    overflow: visible !important;
}

.categorie-mega-menu-wrapper {
    margin-bottom: 0;
}

.categorie-page-title {
    font-size: 32px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #111;
    margin: 0 0 30px 0;
    padding: 0;
    text-align: center;
}

.categorie-page-text {
    margin-top: 40px;
}

.custom-mega-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Rimuovi max-width e padding per la pagina categorie */
.categorie-page-mega .custom-mega-inner {
    max-width: 100%;
    padding: 0;
    margin: 0;
}

/* Rimuovi padding dal container della pagina categorie */
.categorie-page-content .container {
    padding: 0 !important;
    max-width: 100%;
}

/* Rimuovi padding anche dal container principale della pagina categorie */
#categorie-main.column1.wide.clearfix .container {
    padding-left: 20px !important;
    padding-right: 20px !important;
}

/* Specifico per la pagina categorie (usa ID dedicato per evitare conflitti con #main globale) */
body.page-template-page-categorie-php #categorie-main.column1.wide.clearfix,
body.page-template-page-categorie-php #categorie-main {
    padding-top: 0 !important;
}

body.page-template-page-categorie-php .main-content {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}


/* body.page-template-page-categorie #main .container,
body.page-template-page-categorie .categorie-page-content .container {
    padding: 0 !important;
    max-width: 1440px !important;
} */

/* Rimuovi tutti i padding e margin dalla pagina categorie */
body.page-template-page-categorie .categorie-page-mega .custom-mega-columns {
    display: flex;
    flex-wrap: wrap;
    padding: 0;
    justify-content: space-between;
}

body.page-template-page-categorie .categorie-page-mega .custom-mega-column {
    padding: 0;
    margin: 0;
    flex: 0 0 auto;
    width: auto;
    min-width: fit-content;
}

body.page-template-page-categorie .categorie-page-mega .custom-mega-category {
    margin: 0;
    padding: 0;
    width: fit-content;
    min-width: 100%;
}

body.page-template-page-categorie .categorie-page-mega .custom-mega-category-title {
    padding-bottom: 0;
    margin-bottom: 0;
    white-space: nowrap;
    display: inline-block;
    width: auto;
}

body.page-template-page-categorie .categorie-page-mega .custom-mega-submenu {
    padding: 0;
    margin: 0;
    width: fit-content;
    min-width: 100%;
}

body.page-template-page-categorie .categorie-page-mega .custom-mega-subitem {
    margin: 0;
    padding: 0;
    width: fit-content;
}

body.page-template-page-categorie .categorie-page-mega .custom-mega-sublink {
    padding: 0;
    white-space: nowrap;
    display: inline-block;
}

.custom-mega-columns {
    display: flex;
    flex-wrap: wrap;
    padding: 0;
    justify-content: space-between;
    align-items: flex-start;
}

.custom-mega-column {
    flex: 0 0 auto;
    width: auto;
    min-width: fit-content;
    text-align: left;
}

.custom-mega-category {
    margin-bottom: 25px;
    width: fit-content;
    min-width: 100%;
}

.custom-mega-category:last-child {
    margin-bottom: 0;
}

.custom-mega-category-title {
    display: inline-block;
    font-weight: 700;
    font-size: 14px;
    color: #111;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    text-decoration: none;
    transition: color 0.3s ease;
    text-align: left;
    white-space: nowrap;
    width: auto;
}

.custom-mega-category-title:hover {
    color: #E74338;
    text-decoration: none;
}

.custom-mega-submenu {
    list-style: none;
    margin: 0;
    padding: 0;
    width: fit-content;
    min-width: 100%;
}

.custom-mega-subitem {
    margin-bottom: 8px;
    width: fit-content;
}

.custom-mega-subitem:last-child {
    margin-bottom: 0;
}

.custom-mega-sublink {
    display: inline-block;
    color: #666;
    font-size: 13px;
    text-decoration: none;
    padding: 4px 0;
    transition: color 0.3s ease;
    white-space: nowrap;
    width: auto;
}

.custom-mega-sublink:hover {
    color: #E74338;
    text-decoration: none;
}

/* Elementi senza prodotti */
.custom-mega-subitem.no-products .custom-mega-sublink.no-link {
    color: #ccc;
    cursor: default;
    pointer-events: none;
}

.custom-mega-subitem.no-products .custom-mega-sublink.no-link:hover {
    color: #ccc;
}

/* Parent senza prodotti */
.custom-mega-category.no-products .custom-mega-category-title.no-link {
    color: #ccc;
    cursor: default;
    pointer-events: none;
}

.custom-mega-category.no-products .custom-mega-category-title.no-link:hover {
    color: #ccc;
}

/* Mobile */
@media (max-width: 991px) {
    .custom-menu-list {
        flex-direction: column;
        gap: 0;
        width: 100%;
    }
    
    .custom-menu-item {
        width: 100%;
        border-bottom: 1px solid #eee;
    }
    
    .custom-menu-link {
        padding: 15px 20px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    /* +/- già nel testo (custom-menu-link-text) aggiornato da JS, niente ::after */
    .custom-menu-item-has-mega .custom-menu-link::after {
        content: none;
        display: none;
    }

    
    .custom-mega-dropdown {
        position: static;
        opacity: 1;
        visibility: visible;
        transform: none;
        box-shadow: none;
        padding: 0;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }
    
    .custom-menu-item-has-mega.mega-open .custom-mega-dropdown {
        max-height: 2000px;
        padding: 15px 0;
    }

    /* Nel pannello mobile l'entry CATEGORIE deve essere sempre aperta */
    .custom-mobile-menu-panel .custom-mega-dropdown {
        max-height: 2000px !important;
        padding: 15px 0 !important;
    }
    
    .custom-mega-columns {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .custom-mega-column {
        width: 100%;
    }
    
    .custom-mega-category {
        margin-bottom: 20px;
    }
}
