/* ==========================================================
   Mega menu fit fix (Condo Control)
   - Dropdown never runs past the bottom of the screen
   - Tighter spacing on short screens so all rows fit
   - Chat widget hides while a menu is open
   Loaded after header-footer.css (see functions.php)
   ========================================================== */

/* ---------- Desktop (993px and up) ---------- */
@media (min-width: 993px) {

    /* Cap the dropdown to the visible screen, scroll inside if still too tall */
    body #mega-menu-wrap-main-menu #mega-menu-main-menu > li.mega-menu-megamenu > ul.mega-sub-menu {
        max-height: calc(100vh - 170px);
        max-height: calc(100dvh - 170px);
        overflow-y: auto;
        overflow-x: hidden;
        overscroll-behavior: contain;
        scrollbar-width: thin;
        scrollbar-color: #9cc9cc transparent;
    }
    body #mega-menu-wrap-main-menu #mega-menu-main-menu > li.mega-menu-megamenu > ul.mega-sub-menu::-webkit-scrollbar {
        width: 6px;
    }
    body #mega-menu-wrap-main-menu #mega-menu-main-menu > li.mega-menu-megamenu > ul.mega-sub-menu::-webkit-scrollbar-thumb {
        background: #9cc9cc;
        border-radius: 6px;
    }
}

/* ---------- Laptop screens (960px tall or less) ---------- */
@media (min-width: 993px) and (max-height: 960px) {

    /* white cards */
    body #mega-menu-wrap-main-menu #mega-menu-main-menu > li.mega-menu-megamenu > ul.mega-sub-menu .mega-menu-column > .mega-sub-menu {
        padding: 12px;
    }

    /* card headings (Communication, Financial ...) */
    body #mega-menu-wrap-main-menu #mega-menu-main-menu > li.mega-menu-megamenu > ul.mega-sub-menu li.mega-menu-column > ul.mega-sub-menu > li.mega-menu-item > a.mega-menu-link {
        padding-top: 5px;
        padding-bottom: 5px;
        margin-bottom: 4px;
    }

    /* links inside the cards */
    body #mega-menu-wrap-main-menu #mega-menu-main-menu > li.mega-menu-megamenu > ul.mega-sub-menu li.mega-menu-column > ul.mega-sub-menu > li.mega-menu-item li.mega-menu-item > a.mega-menu-link {
        padding-top: 4px;
        padding-bottom: 4px;
        line-height: 22px;
    }
}

/* ---------- Short screens (768px tall or less) ---------- */
@media (min-width: 993px) and (max-height: 768px) {

    body #mega-menu-wrap-main-menu #mega-menu-main-menu > li.mega-menu-megamenu > ul.mega-sub-menu .mega-menu-column > .mega-sub-menu {
        padding: 10px;
        margin-bottom: 6px;
    }

    body #mega-menu-wrap-main-menu #mega-menu-main-menu > li.mega-menu-megamenu > ul.mega-sub-menu li.mega-menu-column > ul.mega-sub-menu > li.mega-menu-item li.mega-menu-item > a.mega-menu-link {
        padding-top: 3px;
        padding-bottom: 3px;
        line-height: 20px;
    }
}

/* ---------- Mobile / tablet (992px and below) ---------- */
@media (max-width: 992px) {

    /* open mobile menu stays inside the screen and scrolls */
    body.mega-menu-main-menu-mobile-open header .navbar {
        max-height: calc(100vh - 120px);
        max-height: calc(100dvh - 120px);
        overflow-y: auto;
        overscroll-behavior: contain;
    }
}

/* ---------- Hide the Qualified chat while a menu is open ----------
   q-root sits outside <body>, so the check runs on <html>.
   The ID is needed to beat Qualified's own !important rule. */
html:has(#mega-menu-main-menu > li.mega-menu-megamenu.mega-toggle-on) #q-messenger-frame,
html:has(#mega-menu-main-menu > li.mega-menu-megamenu:hover) #q-messenger-frame,
html:has(body.mega-menu-main-menu-mobile-open) #q-messenger-frame {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}
