/* Navigation Styles for Mastri Tartufi */

/* Navigation container with proper bounds */
nav {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    position: relative;
    z-index: 100;
    box-sizing: border-box;
}

/* Ensure navigation container and content-container allow dropdown overflow */
#navigation-container {
    overflow: visible !important;
    position: relative;
    z-index: 10000;
}

/* Only target navigation-specific containers for dropdown visibility */
nav,
nav ul,
nav ul li {
    overflow: visible !important;
}

/* Ensure dropdown parent has proper stacking context */
nav .group {
    position: relative !important;
    z-index: 10000 !important;
}

/* Navigation text styles */
.nav-link {
    font-size: clamp(1.2rem, 3vw, 1.5rem);
    font-weight: 700;
    text-align: center;
    display: flex;
    display: -webkit-box;
    display: -webkit-flex;
    justify-content: center;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    align-items: center;
    -webkit-box-align: center;
    -webkit-align-items: center;
    white-space: nowrap; /* Keep navigation text intact */
    overflow: visible; /* Allow text to be visible */
    box-sizing: border-box;
    padding: 0.5rem 0.75rem; /* Add padding for better touch targets */
}

/* Home link specific styling - centered */
.nav-link-home {
    justify-content: center !important;
    text-align: center !important;
    -webkit-box-pack: center !important;
    -webkit-justify-content: center !important;
    width: 100%;
    display: flex;
    align-items: center;
}

/* Navigation styles with underline and proper containment */
.nav-bar {
    display: flex;
    display: -webkit-box;
    display: -webkit-flex;
    justify-content: center;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    align-items: center;
    -webkit-box-align: center;
    -webkit-align-items: center;
    width: 100%;
    max-width: 100%;
    padding: 0;
    margin: 0;
    gap: 0.5rem; /* Add gap between items */
    flex-wrap: wrap; /* Allow wrapping to next line when needed */
    box-sizing: border-box;
    overflow: visible;
}

.nav-bar li {
    flex: 0 0 auto; /* Don't grow or shrink, keep natural size */
    min-width: 0;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
}

.nav-underline {
    margin-top: 0.5rem;
    height: 2px;
    background-color: #9A1B1F;
    width: 90%;
    margin-left: auto;
    margin-right: auto;
}

/* Active nav link */
.nav-link.active {
    color: #9A1B1F;
    font-weight: bold;
    position: relative;
}

.nav-link.active::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 0;
    width: 100%;
    height: 2px;
    background-color: #D4AF37;
}

/* Button styling for navigation */
.nav-link-btn,
button,
.btn,
[class*="btn-"],
input[type="submit"],
input[type="button"] {
    background-color: #9A1B1F !important;
    border-color: #9A1B1F !important;
    color: white !important;
}

.nav-link-btn:hover,
button:hover,
.btn:hover,
[class*="btn-"]:hover,
input[type="submit"]:hover,
input[type="button"]:hover {
    background-color: #7A1618 !important; /* darker wine-red */
    border-color: #7A1618 !important;
}

/* Dropdown menu styles with highest z-index */
.group {
    position: relative;
    z-index: 10000; /* Ensure parent has high z-index */
}

.group .absolute {
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    transform: none !important;
    width: auto !important;
    min-width: max-content !important;
    margin-top: 0.5rem !important;
    border-radius: 8px !important;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1) !important;
    background-color: rgba(255, 255, 255, 0.9) !important;
    z-index: 99999 !important; /* Extremely high z-index to ensure it's on top */
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.group:hover .absolute {
    opacity: 1;
    visibility: visible;
}

.group .absolute ul {
    width: auto !important;
    padding: 0.5rem 0 !important;
    display: flex !important;
    flex-direction: column !important;
    margin: 0 !important;
    list-style: none !important;
    z-index: 99999 !important;
}

.group .absolute ul li {
    width: 100% !important;
    display: block !important;
    margin: 0 !important;
}

.group .absolute ul li a {
    padding: 0.75rem 1rem !important;
    text-align: left !important;
    display: block !important;
    width: 100% !important;
    white-space: nowrap !important;
    box-sizing: border-box !important;
}

/* iOS specific navigation adjustments */
@supports (-webkit-touch-callout: none) {
    nav {
        width: 100%;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
        -webkit-box-orient: vertical;
        -webkit-flex-direction: column;
        flex-direction: column;
        -webkit-box-align: center;
        -webkit-align-items: center;
        align-items: center;
        padding: 1rem;
        box-sizing: border-box;
    }

    /* Ensure home link is centered on iOS */
    .nav-link-home {
        justify-content: center !important;
        text-align: center !important;
        -webkit-box-pack: center !important;
        -webkit-justify-content: center !important;
        width: 100%;
        margin: 0 auto;
    }

    .nav-bar {
        width: 90%;
        max-width: 90%;
        margin: 0 auto;
        margin-bottom: 0.5rem;
        flex-wrap: wrap;
    }

    .nav-underline {
        width: 90%;
    }
    
    .nav-link {
        font-weight: 700;
        -webkit-font-smoothing: antialiased;
    }
    
    .group .absolute {
        -webkit-backdrop-filter: blur(10px) !important;
        backdrop-filter: blur(10px) !important;
        z-index: 99999 !important;
    }

    .group .absolute ul li a {
        padding: 0.875rem 1rem !important; /* Slightly larger touch targets for iOS */
    }

    /* Prevent scroll issues on iOS */
    body.dropdown-open {
        position: fixed;
        width: 100%;
    }
}

/* Desktop dropdown styles */
@media (min-width: 769px) {
    .nav-bar {
        justify-content: center;
        flex-wrap: wrap;
        gap: 1rem; /* Larger gap for desktop */
    }
    
    .nav-link {
        font-size: clamp(1.1rem, 2.5vw, 1.4rem);
        padding: 0.5rem 1rem; /* Larger padding for desktop */
        white-space: nowrap;
    }

    .group .absolute {
        position: absolute !important;
        top: 100% !important;
        left: 0 !important;
        transform: none !important;
        width: auto !important;
        min-width: max-content !important;
        margin-top: 0.5rem !important;
        border-radius: 8px !important;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1) !important;
        background-color: rgba(255, 255, 255, 0.9) !important;
        z-index: 99999 !important;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }

    .group:hover .absolute {
        opacity: 1;
        visibility: visible;
    }

    .group .absolute ul {
        width: auto !important;
        padding: 0.5rem 0 !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .group .absolute ul li {
        width: 100% !important;
        display: block !important;
    }

    .group .absolute ul li a {
        padding: 0.75rem 1rem !important;
        text-align: left !important;
        display: block !important;
        width: 100% !important;
        white-space: nowrap !important;
    }
}

/* Tablet-specific styles for better navigation wrapping */
@media (min-width: 481px) and (max-width: 768px) {
    .nav-bar {
        justify-content: center;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .nav-link {
        font-size: clamp(0.9rem, 3vw, 1.1rem) !important;
        padding: 0.5rem 0.75rem !important;
        white-space: nowrap !important;
        min-width: fit-content;
    }
}

/* Mobile navigation styles */
@media (max-width: 768px) {
    nav {
        padding: 0.5rem;
        box-sizing: border-box;
        overflow: visible;
    }
    
    /* Ensure home link is centered on mobile */
    .nav-link-home {
        justify-content: center !important;
        text-align: center !important;
        width: 100%;
        margin: 0 auto;
    }
    
    .nav-link {
        font-size: clamp(1.1rem, 4vw, 1.2rem);
        padding: 0.5rem 0.25rem;
        white-space: nowrap; /* Keep navigation items intact */
    }
    
    @supports (-webkit-touch-callout: none) {
        nav {
            padding: 0.5rem;
        }

        .nav-bar {
            width: 100%;
            max-width: 100%;
            flex-wrap: wrap;
            gap: 0.25rem;
            justify-content: center; /* Center items when they wrap */
        }

        .nav-underline {
            width: 90%;
            margin-top: 0.25rem;
        }
    }
    
    /* Use flexbox instead of grid for better text wrapping behavior */
    nav ul.nav-bar {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
        gap: 0.25rem;
        width: 100%;
        padding: 0;
        margin: 0;
    }
    
    nav ul li {
        text-align: center;
        margin: 0;
        position: relative;
        display: flex;
        justify-content: center;
        align-items: center;
        flex: 0 0 auto; /* Don't grow or shrink */
        box-sizing: border-box;
    }
    
    .nav-link {
        font-size: clamp(0.85rem, 3.5vw, 1rem) !important;
        padding: 0.5rem 0.75rem !important;
        display: flex;
        justify-content: center;
        align-items: center;
        white-space: nowrap !important; /* Prevent text from breaking within words */
        overflow: visible;
        text-overflow: clip;
        position: relative;
        text-align: center;
        margin: 0;
        line-height: 1.3;
        box-sizing: border-box;
        /* Remove word-breaking properties */
        word-break: normal;
        hyphens: none;
        min-width: fit-content;
    }
    
    /* Dropdown menu mobile styles */
    .group .absolute {
        position: absolute !important;
        top: 100% !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: auto !important;
        min-width: max-content !important;
        margin-top: 0.5rem !important;
        border-radius: 8px !important;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1) !important;
        background-color: rgba(255, 255, 255, 0.9) !important;
        z-index: 99999 !important;
    }

    .group .absolute ul {
        width: auto !important;
        padding: 0.5rem 0 !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .group .absolute ul li {
        width: 100% !important;
        display: block !important;
    }

    .group .absolute ul li a {
        font-size: clamp(0.85rem, 2.5vw, 1rem) !important;
        padding: 0.75rem 1rem !important;
        text-align: center !important;
        display: block !important;
        width: 100% !important;
        white-space: nowrap !important;
    }

    /* Show dropdown on tap for touch devices */
    @media (hover: none) {
        .group:active .absolute,
        .group:focus .absolute,
        .group:focus-within .absolute {
            opacity: 1 !important;
            visibility: visible !important;
            transform: translateX(-50%) scale(1) !important;
        }
    }
}

/* Very small screens - stack vertically */
@media (max-width: 480px) {
    nav ul {
        grid-template-columns: 1fr 1fr; /* 2 columns for very small screens */
        gap: 0.25rem;
    }
    
    .nav-link {
        font-size: clamp(0.8rem, 3vw, 1rem) !important;
        padding: 0.4rem 0.2rem !important;
        line-height: 1.1;
    }
}

/* Extra small screens - ensure text doesn't overflow */
@media (max-width: 360px) {
    .nav-link {
        font-size: clamp(0.75rem, 2.8vw, 0.9rem) !important;
        padding: 0.3rem 0.1rem !important;
        line-height: 1.0;
    }
}

/* Universal dropdown z-index override - MUST be at the end to ensure highest priority */
/* Only target navigation groups to avoid affecting other page elements */
nav .group,
nav .group.relative,
#navigation-container .group {
    position: relative !important;
    z-index: 10000 !important;
}

nav .group .absolute,
nav .group .absolute.dropdown,
nav .group .absolute div,
#navigation-container .group .absolute,
ul.nav-bar .group .absolute,
li .group .absolute {
    z-index: 999999 !important;
    position: absolute !important;
    pointer-events: auto !important;
}

nav .group:hover .absolute,
nav .group:focus .absolute,
nav .group:active .absolute,
nav .group:focus-within .absolute,
#navigation-container .group:hover .absolute,
#navigation-container .group:focus .absolute,
#navigation-container .group:active .absolute,
#navigation-container .group:focus-within .absolute {
    z-index: 999999 !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
}

nav .group .absolute ul,
nav .group .absolute ul li,
nav .group .absolute ul li a,
#navigation-container .group .absolute ul,
#navigation-container .group .absolute ul li,
#navigation-container .group .absolute ul li a {
    z-index: 999999 !important;
    pointer-events: auto !important;
} 