/* Responsive navbar.
 *
 * Scoped entirely to .navbar-custom — the header above it and the rest of the
 * page are untouched. The 1200px-and-up appearance is unchanged; everything
 * here only takes effect below that.
 *
 * Three problems this fixes:
 *   1. 1200-1399px  the six links wrapped onto a second row (nav grew to 79px)
 *   2. 992-1199px   the links overflowed the viewport horizontally
 *   3. below 992px  the collapsed menu inherited Bootstrap's .row negative
 *                   margins, so MANUFACTURERS hung off the left edge, and the
 *                   absolutely-positioned mega menu was unusable
 */

/* --- 1. Large screens: keep six links on one row ----------------------- */

@media (max-width: 1399.98px) {
    .navbar-custom .nav-link {
        padding: 18px 1.6rem !important;
    }
}

@media (min-width: 992px) and (max-width: 1199.98px) {
    .navbar-custom .navbar-nav {
        flex-wrap: nowrap;
        justify-content: space-between;
    }

    .navbar-custom .nav-link {
        padding: 18px 0.7rem !important;
        font-size: 0.78rem;
        white-space: nowrap;
    }

    .navbar-custom .manufactureDiv {
        font-size: 0.95rem;
    }
}

/* --- 2. Below 992px: the collapsed menu -------------------------------- */

@media (max-width: 991.98px) {

    /* Sticky offset is tuned for the tall desktop header; on a stacked mobile
       header it would float over the page, so the bar scrolls normally. */
    .navbar-custom {
        position: static !important;
        top: auto;
        margin-top: 0;
    }

    .navbar-custom>.container {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .navbar-custom .navbar-toggler {
        align-self: flex-start;
        margin: 8px 12px;
    }

    .navbar-custom .navbar-toggler:focus {
        box-shadow: none;
    }

    /* Bootstrap's .row negative gutters are what pushed MANUFACTURERS off the
       left edge once the collapse became a block. */
    .navbar-custom .navbar-collapse .row {
        --bs-gutter-x: 0;
        margin-left: 0;
        margin-right: 0;
        width: 100%;
    }

    .navbar-custom .navbar-collapse [class*="col-"] {
        width: 100%;
        max-width: 100%;
        flex: 0 0 100%;
        padding-left: 0;
        padding-right: 0;
    }

    /* A long category tree should scroll inside the menu, not stretch the page. */
    .navbar-custom .navbar-collapse.show,
    .navbar-custom .navbar-collapse.collapsing {
        max-height: 75vh;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .navbar-custom .manufactureDiv {
        width: 100%;
        padding: 14px 16px;
        justify-content: flex-start;
        font-size: 1rem;
    }

    .navbar-custom .navbar-nav {
        width: 100%;
    }

    .navbar-custom .nav-item {
        width: 100%;
    }

    .navbar-custom .nav-link {
        padding: 14px 16px !important;
        font-size: 0.9rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.12) !important;
    }

    .navbar-custom .nav-link.dropdownMenu {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    /* The mega menu is absolutely positioned on desktop; inside the collapse it
       has to sit in the flow as a plain panel. */
    .navbar-custom .mega-menu {
        position: static;
        padding: 0;
        border-top: none;
        box-shadow: none;
        background: transparent;
    }

    .navbar-custom .mega-menu-content {
        grid-template-columns: 1fr;
        gap: 0;
        padding: 0;
    }

    .navbar-custom .mega-menu-category {
        background: #fff;
        padding: 14px 16px;
        border-bottom: 1px solid #ececec;
    }

    .navbar-custom .mega-menu-category-title {
        margin-bottom: 8px;
        font-size: 0.9rem;
    }

    .navbar-custom .mega-menu-item {
        font-size: 0.82rem;
        padding: 5px 0;
    }

    .navbar-custom .mega-menu-subitem {
        font-size: 0.78rem;
        padding: 4px 0 4px 12px;
    }
}

/* --- 3. Small screens --------------------------------------------------- */

@media (max-width: 575.98px) {
    .navbar-custom .manufactureDiv {
        padding: 12px 14px;
        font-size: 0.92rem;
    }

    .navbar-custom .nav-link {
        padding: 13px 14px !important;
        font-size: 0.85rem;
    }

    .navbar-custom .mega-menu-category {
        padding: 12px 14px;
    }
}
