/*
    CSS Mobile Navigation - Desktop-First Approach
    ===============================================
    1. Base styles target desktop screens (> 1024px).
    2. A single max-width media query adapts the layout for tablet and mobile.
*/

/* --- Base Styles (Desktop > 1024px) --- */

/* On desktop, the mobile navs are completely hidden and have zero impact on layout. */
.mobile-bottom-nav,
.second-mobile-nav {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    min-height: 0 !important;
    max-height: 0 !important;
    overflow: hidden !important;
    pointer-events: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
}

/* Add containment to the primary nav to improve rendering performance. */
.mobile-bottom-nav {
    contain: layout style;
}

/* On desktop, the body has no extra padding at the bottom. */
body {
    padding-bottom: 0 !important;
}

/* --- Shared Nav Styles (used in both views) --- */

.mobile-nav-container {
    display: flex;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
}

.mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 0.5rem;
    text-decoration: none !important; /* Force immediate application */
    color: var(--text-light);
    transition: all 0.2s ease;
    position: relative;
    min-height: 64px;
    /* Ensure good touch targets */
    min-width: 44px;
}

.mobile-nav-item:hover,
.mobile-nav-item:focus,
.mobile-nav-item.active {
    color: var(--primary-color);
    background: rgba(52, 96, 191, 0.05);
    text-decoration: none !important; /* Force immediate application */
}

.mobile-nav-item:active {
    transform: scale(0.95);
    background: rgba(52, 96, 191, 0.1);
}

.mobile-nav-icon {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
    line-height: 1;
    transition: all 0.2s ease;
    display: block;
}

.mobile-nav-item:hover .mobile-nav-icon,
.mobile-nav-item.active .mobile-nav-icon {
    transform: translateY(-1px);
}

.mobile-nav-label {
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.2;
    text-align: center;
    margin: 0;
    letter-spacing: 0.025em;
}

/* Active state indicator */
.mobile-nav-item.active::before {
    content: "";
    position: absolute;
    top: 0;
    left: 50%;
    width: 32px;
    height: 3px;
    background: var(--primary-color);
    border-radius: 0 0 2px 2px;
    transform: translateX(-50%);
}

.second-nav-container {
    position: relative;
    overflow: hidden;
    min-height: 48px; /* Slightly smaller than primary nav */
}

.second-nav-scroll {
    display: flex;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-behavior: smooth;
    padding: 0 0.5rem; /* Match primary nav horizontal padding */
    height: 100%;
    align-items: center;
    /* Even distribution when content doesn't overflow */
    justify-content: space-evenly;
    min-width: 100%;
}

.second-nav-scroll::-webkit-scrollbar {
    display: none;
}

/* When content overflows, change to flex-start */
.second-nav-container.scrollable .second-nav-scroll {
    justify-content: flex-start;
    padding: 0 1rem; /* More padding when scrollable */
}

.second-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none !important; /* Force immediate application */
    color: var(--text-light); /* Match primary nav color */
    font-size: 0.75rem; /* Match primary nav font size */
    font-weight: 500; /* Match primary nav font weight */
    white-space: nowrap;
    min-width: max-content;
    transition: all 0.2s ease; /* Match primary nav transition */
    border-radius: 6px;
    padding: 0.6rem 0.4rem; /* Slightly smaller than primary nav */
    margin: 0 0.1rem;
    position: relative;
    min-height: 48px; /* Match container height */
    /* Ensure good touch targets */
    min-width: 44px;
}

/* Override flex behavior when scrollable */
.second-nav-container.scrollable .second-nav-item {
    flex: none;
    margin: 0 0.2rem;
    padding: 0.6rem 0.6rem;
}

.second-nav-item:hover,
.second-nav-item:focus,
.second-nav-item.active {
    background: rgba(
        52,
        96,
        191,
        0.05
    ); /* Match primary nav hover and active */
    color: var(--primary-color); /* Match primary nav color - blue text */
    text-decoration: none !important; /* Force immediate application */
    box-shadow: 0 0 0 2px var(--primary-color-light); /* Accessibility focus ring */
}

.second-nav-item:active {
    transform: scale(0.95); /* Match primary nav active transform */
    background: rgba(
        52,
        96,
        191,
        0.1
    ); /* Match primary nav active background */
}

/* Active indicator matching primary nav style exactly */
.second-nav-item.active::before {
    content: "";
    position: absolute;
    top: 0;
    left: 50%;
    width: 32px; /* Match primary nav width */
    height: 3px;
    background: var(--primary-color); /* Blue bar, not white */
    border-radius: 0 0 2px 2px;
    transform: translateX(-50%);
}

.second-nav-icon {
    font-size: 1rem;
    margin-bottom: 0.25rem; /* Match primary nav icon margin */
    line-height: 1;
    transition: all 0.2s ease; /* Match primary nav transition */
}

/* Hover effect for icons matching primary nav */
.second-nav-item:hover .second-nav-icon,
.second-nav-item.active .second-nav-icon {
    transform: translateY(-1px);
}

/* Scroll Indicators - Enhanced to match overall design */
.second-nav-scroll-indicator {
    position: absolute;
    top: 0;
    right: 0;
    width: 24px;
    height: 100%;
    background: linear-gradient(
        to left,
        rgba(255, 255, 255, 0.95),
        rgba(255, 255, 255, 0)
    );
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 2;
}

.second-nav-scroll-indicator-left {
    position: absolute;
    top: 0;
    left: 0;
    width: 24px;
    height: 100%;
    background: linear-gradient(
        to right,
        rgba(255, 255, 255, 0.95),
        rgba(255, 255, 255, 0)
    );
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 2;
}

.second-nav-container.scrollable .second-nav-scroll-indicator {
    opacity: 1;
}

.second-nav-container.scrolled-to-end .second-nav-scroll-indicator {
    opacity: 0;
}

.second-nav-container.scrolled .second-nav-scroll-indicator-left {
    opacity: 1;
}

.second-nav-container.scrolled-to-start .second-nav-scroll-indicator-left {
    opacity: 0;
}

/* Focus states matching primary nav */
.second-nav-item:focus {
    outline: none; /* Remove default blue border */
}

/* High contrast mode support matching primary nav */
@media (prefers-contrast: high) {
    .second-mobile-nav {
        border-top: 2px solid var(--text-color);
    }

    .second-nav-item.active {
        background: var(--text-color);
        color: white;
    }
}

/* Accessibility improvements matching primary nav */
@media (prefers-reduced-motion: reduce) {
    .second-mobile-nav,
    .second-nav-item,
    .second-nav-icon,
    .mobile-bottom-nav,
    .mobile-nav-item,
    .mobile-nav-icon {
        transition: none;
    }
}

/* --- Mobile & Tablet Styles (<= 1024px) --- */
@media screen and (max-width: 1024px) {
    .mobile-bottom-nav {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--white);
        border-top: 1px solid var(--border-color);
        z-index: 1000;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        /* Emojis load instantly, always visible */
        visibility: visible !important;
        opacity: 1 !important;
        /* Restore dimensions */
        height: auto !important;
        min-height: 64px !important;
        max-height: none !important;
        overflow: visible !important;
        pointer-events: auto !important;
        transform: translateY(0) !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /*
      Show and position the secondary mobile nav.
    */
    .second-mobile-nav {
        display: block !important;
        position: fixed;
        bottom: 60px; /* Sits above the primary mobile nav */
        left: 0;
        right: 0;
        background: var(--white);
        border-top: 1px solid var(--border-color);
        z-index: 998;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        /* Restore visibility and dimensions */
        visibility: visible !important;
        opacity: 1 !important;
        height: auto !important;
        min-height: 48px !important;
        max-height: none !important;
        overflow: visible !important;
        pointer-events: auto !important;
        transform: translateY(0) !important;
    }

    /* Add padding to the body to prevent content from being hidden by the fixed nav bars. */
    body:not(.no-mobile-nav) {
        padding-bottom: 80px;
    }

    /* Add a margin to the footer to prevent it from being hidden by the fixed nav bars. */
    footer.footer {
        margin-bottom: 64px;
    }

    /* Add more padding if the second nav is also present. */
    body:not(.no-mobile-nav).has-second-nav,
    body:not(.no-mobile-nav):has(.second-mobile-nav) {
        padding-bottom: 108px; /* 60px primary + 48px second nav */
    }

    /* Add more margin to the footer if the second nav is also present. */
    body.has-second-nav footer.footer,
    body:has(.second-mobile-nav) footer.footer {
        margin-bottom: 128px; /* 80px primary + 48px second nav */
    }

    .nav-toggle {
        z-index: 999; /* Ensure it's below mobile nav */
    }

    /* Responsive adjustments for even smaller mobile screens */
    @media (max-width: 480px) {
        .mobile-nav-item {
            padding: 0.5rem 0.25rem;
            min-height: 60px;
        }

        .mobile-nav-icon {
            width: 22px;
            height: 22px;
        }

        .mobile-nav-label {
            font-size: 0.7rem;
        }

        .second-nav-item {
            font-size: 0.7rem; /* Match primary nav responsive size */
            padding: 0.5rem 0.3rem;
            min-height: 44px;
        }

        .second-nav-icon {
            font-size: 0.9rem;
        }

        .second-nav-scroll {
            padding: 0 0.4rem;
        }

        .second-nav-container.scrollable .second-nav-scroll {
            padding: 0 0.8rem;
        }

        /* Adjust body padding for smaller screens */
        body:not(.no-mobile-nav) {
            padding-bottom: 75px;
        }

        body:not(.no-mobile-nav).has-second-nav {
            padding-bottom: 119px; /* 75px primary + 44px second nav */
        }
        
        body.has-second-nav footer.footer,
        body:has(.second-mobile-nav) footer.footer {
            margin-bottom: 119px; /* 75px primary + 44px second nav */
        }
    }
}
