/* Mobile hamburger menu (rendered by each theme's mega-menu.js).
   Overrides the old card layout in the themes' core.min.css. Selectors are prefixed with
   .mega-menu-header so they outrank the theme's `.mega-menu-header button:hover` resets.
   Level 1: category rows, two CTAs, country switcher, legal links.
   Level 2+: back button + title, compact service rows. */

@media (max-width: 768px) {
    .mega-menu-header .mobile-main-menu,
    .mega-menu-header .mobile-sub-menu {
        --mm-ink: #0F1F33;
        --mm-ink-2: #44566C;
        --mm-brand: #2E8FC7;
        --mm-soft: #E3F1FA;
        --mm-muted: #6B7C90;
        --mm-faint: #8496A8;
        --mm-line: #E7EDF3;
        --mm-ground: #F4F7FA;
        --mm-chip: #F1F5F9;
        background: var(--mm-ground);
        color: var(--mm-ink);
        font-family: var(--font-primary);
        -webkit-tap-highlight-color: rgba(46, 143, 199, 0.08);
    }

    .mega-menu-header :is(.mobile-main-menu, .mobile-sub-menu) svg {
        display: block;
        flex: none;
        width: 20px;
        height: 20px;
        fill: none;
        stroke: currentColor;
        stroke-width: 1.8;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    /* ---------- header bars: close button at the start, logo centred ---------- */

    .mega-menu-header .mobile-main-menu .mobile-menu-header,
    .mega-menu-header .mobile-sub-menu .mobile-sub-header {
        position: relative;
        flex: none;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 12px;
        min-height: calc(64px + env(safe-area-inset-top, 0px));
        padding: env(safe-area-inset-top, 0px) 16px 0;
        background: #fff;
        border-bottom: 1px solid var(--mm-line);
        box-shadow: none;
    }

    .mega-menu-header .mobile-main-menu .mobile-menu-logo,
    .mega-menu-header .mobile-sub-menu .mobile-sub-logo {
        flex: none;
        width: auto;
        height: 40px;
        object-fit: contain;
    }

    /* Close sits on the left (the end side in RTL), where people expect it. */
    .mega-menu-header .mobile-main-menu .mobile-menu-close,
    .mega-menu-header .mobile-sub-menu .mobile-sub-close {
        position: absolute;
        top: calc(env(safe-area-inset-top, 0px) + 11px);
        inset-inline-start: auto;
        inset-inline-end: 16px;
        width: 42px;
        height: 42px;
        padding: 0;
        border: 0;
        border-radius: 12px;
        background: var(--mm-chip);
        color: var(--mm-ink);
        transition: transform 0.15s ease;
    }

    .mega-menu-header .mobile-main-menu .mobile-menu-close:active,
    .mega-menu-header .mobile-sub-menu .mobile-sub-close:active {
        background: var(--mm-line);
        border: 0;
        transform: scale(0.94);
    }

    /* ---------- scroll areas (bottom padding for the nav bar comes from bottom-nav.css) ---------- */

    .mega-menu-header .mobile-main-menu .mobile-menu-body,
    .mega-menu-header .mobile-sub-menu .mobile-sub-body {
        background: var(--mm-ground);
        padding-top: 16px;
        padding-inline: 16px;
        overscroll-behavior: contain;
    }

    .mega-menu-header .mobile-sub-menu .mobile-sub-body {
        padding-top: 4px;
    }

    /* ---------- shared row text ---------- */

    .mega-menu-header :is(.mobile-main-menu, .mobile-sub-menu) .mm-text {
        display: block;
        flex: 1 1 auto;
        min-width: 0;
    }

    .mega-menu-header :is(.mobile-main-menu, .mobile-sub-menu) .mm-name {
        display: block;
        color: var(--mm-ink);
        font-size: 15px;
        font-weight: 700;
        line-height: 1.35;
    }

    .mega-menu-header :is(.mobile-main-menu, .mobile-sub-menu) .mm-desc {
        display: block;
        margin-top: 3px;
        color: var(--mm-muted);
        font-size: 12.5px;
        font-weight: 400;
        line-height: 1.5;
    }

    /* ---------- level 1 ---------- */

    .mega-menu-header .mobile-main-menu .mm-l1 {
        display: grid;
        gap: 12px;
    }

    .mega-menu-header .mobile-main-menu .mm-eyebrow {
        margin: 0 4px -2px;
        color: var(--mm-faint);
        font-size: 12.5px;
        font-weight: 700;
        line-height: 1.4;
    }

    .mega-menu-header .mobile-main-menu .mobile-service-item.mm-cat {
        display: flex;
        align-items: center;
        gap: 14px;
        width: 100%;
        min-height: 76px;
        margin: 0;
        padding: 13px;
        padding-inline-end: 14px;
        background: #fff;
        border: 1px solid var(--mm-line);
        border-radius: 18px;
        box-shadow: none;
        color: inherit;
        font: inherit;
        text-align: start;
        cursor: pointer;
        transition: transform 0.15s ease;
    }

    .mega-menu-header .mobile-main-menu .mobile-service-item.mm-cat:active {
        background: #FAFCFE;
        transform: scale(0.985);
    }

    .mega-menu-header .mobile-main-menu .mm-tile {
        display: grid;
        place-items: center;
        flex: none;
        width: 48px;
        height: 48px;
        border-radius: 14px;
    }

    .mega-menu-header .mobile-main-menu .mm-tile svg {
        width: 24px;
        height: 24px;
    }

    .mega-menu-header .mobile-main-menu .mm-tone-blue { background: #E3F1FA; color: #2E8FC7; }
    .mega-menu-header .mobile-main-menu .mm-tone-indigo { background: #E8E8FB; color: #5B5BD6; }
    .mega-menu-header .mobile-main-menu .mm-tone-orange { background: #FDEBDD; color: #D9702B; }
    .mega-menu-header .mobile-main-menu .mm-tone-green { background: #E1F5EA; color: #1F8A5B; }

    .mega-menu-header .mobile-main-menu .mm-chev {
        flex: none;
        margin-inline-start: auto;
        color: #B0BCC9;
    }

    /* CTAs */
    .mega-menu-header .mobile-main-menu .mm-ctas {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        margin-top: 4px;
    }

    .mega-menu-header .mobile-main-menu .mm-cta {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        min-width: 0;
        min-height: 52px;
        padding: 0 12px;
        border-radius: 14px;
        font-size: 14.5px;
        font-weight: 700;
        line-height: 1.25;
        text-align: center;
        text-decoration: none;
        transition: transform 0.15s ease;
    }

    .mega-menu-header .mobile-main-menu .mm-cta:only-child {
        grid-column: 1 / -1;
    }

    .mega-menu-header .mobile-main-menu .mm-cta:active {
        transform: scale(0.97);
    }

    .mega-menu-header .mobile-main-menu .mm-cta--dark,
    .mega-menu-header .mobile-main-menu .mm-cta--dark:hover,
    .mega-menu-header .mobile-main-menu .mm-cta--dark:focus {
        background: var(--mm-ink);
        color: #fff;
    }

    .mega-menu-header .mobile-main-menu .mm-cta--light,
    .mega-menu-header .mobile-main-menu .mm-cta--light:hover,
    .mega-menu-header .mobile-main-menu .mm-cta--light:focus {
        background: #fff;
        color: var(--mm-ink);
        border: 1.5px solid var(--mm-ink);
    }

    /* PWA install row: hidden until the install script adds html.st-can-install */
    .mega-menu-header .mobile-main-menu .mm-install {
        display: none;
        align-items: center;
        gap: 12px;
        width: 100%;
        margin: 0;
        padding: 12px;
        background: #fff;
        border: 1px solid var(--mm-line);
        border-radius: 14px;
        color: var(--mm-ink);
        font: inherit;
        text-align: start;
        cursor: pointer;
        transition: transform 0.15s ease;
    }

    html.st-can-install .mega-menu-header .mobile-main-menu [data-st-install] {
        display: flex !important;
    }

    .mega-menu-header .mobile-main-menu .mm-install:active {
        background: #FAFCFE;
        transform: scale(0.985);
    }

    .mega-menu-header .mobile-main-menu .mm-install-ic {
        display: grid;
        place-items: center;
        flex: none;
        width: 36px;
        height: 36px;
        border-radius: 11px;
        background: var(--mm-soft);
        color: var(--mm-brand);
    }

    .mega-menu-header .mobile-main-menu .mm-install .mm-name {
        font-size: 14px;
    }

    .mega-menu-header .mobile-main-menu .mm-install .mm-desc {
        margin-top: 2px;
        font-size: 12px;
    }

    /* Country + legal */
    .mega-menu-header .mobile-main-menu .mm-foot {
        display: grid;
        gap: 10px;
        margin-top: 6px;
    }

    .mega-menu-header .mobile-main-menu .mm-country {
        background: #fff;
        border: 1px dashed #D5DEE7;
        border-radius: 16px;
    }

    .mega-menu-header .mobile-main-menu .mm-country-toggle {
        display: flex;
        align-items: center;
        gap: 10px;
        width: 100%;
        min-height: 52px;
        margin: 0;
        padding: 10px 16px;
        border: 0;
        border-radius: 16px;
        background: transparent;
        color: var(--mm-ink);
        font: inherit;
        font-size: 14px;
        font-weight: 600;
        text-align: start;
    }

    .mega-menu-header .mobile-main-menu .mm-country-sw {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        margin-inline-start: auto;
        color: var(--mm-brand);
        font-size: 13px;
        font-weight: 600;
    }

    .mega-menu-header .mobile-main-menu .mm-country-sw svg {
        width: 16px;
        height: 16px;
        transition: transform 0.2s ease;
    }

    .mega-menu-header .mobile-main-menu .mm-country-toggle[aria-expanded="true"] .mm-country-sw svg {
        transform: rotate(180deg);
    }

    .mega-menu-header .mobile-main-menu .mm-flag {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: none;
        width: 24px;
        font-size: 19px;
        line-height: 1;
    }

    .mega-menu-header .mobile-main-menu .mm-flag--icon {
        color: var(--mm-brand);
    }

    .mega-menu-header .mobile-main-menu .mm-country-list {
        margin: 0 12px;
        padding: 4px 0 8px;
        border-top: 1px dashed #D5DEE7;
        list-style: none;
    }

    .mega-menu-header .mobile-main-menu .mm-country-list[hidden] {
        display: none;
    }

    .mega-menu-header .mobile-main-menu .mm-country-link {
        display: flex;
        align-items: center;
        gap: 10px;
        min-height: 46px;
        padding: 0 4px;
        border-radius: 12px;
        color: var(--mm-ink);
        font-size: 14px;
        font-weight: 600;
        text-decoration: none;
    }

    .mega-menu-header .mobile-main-menu .mm-country-link:active {
        background: var(--mm-ground);
    }

    .mega-menu-header .mobile-main-menu .mm-go {
        margin-inline-start: auto;
        color: #B0BCC9;
    }

    .mega-menu-header .mobile-main-menu .mm-go svg {
        width: 18px;
        height: 18px;
    }

    .mega-menu-header .mobile-main-menu .mm-legal {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        gap: 0 10px;
        color: var(--mm-faint);
        font-size: 12.5px;
        line-height: 1.5;
    }

    .mega-menu-header .mobile-main-menu .mm-legal a {
        padding: 8px 2px;
        color: inherit;
        text-decoration: none;
    }

    /* ---------- level 2+: back + title ---------- */

    .mega-menu-header .mobile-sub-menu .mm-l2head {
        flex: none;
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 14px 16px 12px;
        background: var(--mm-ground);
    }

    .mega-menu-header .mobile-sub-menu .mobile-sub-back {
        flex: none;
        width: 40px;
        height: 40px;
        padding: 0;
        border: 1px solid var(--mm-line);
        border-radius: 12px;
        background: #fff;
        color: var(--mm-ink);
        transition: transform 0.15s ease;
    }

    .mega-menu-header .mobile-sub-menu .mobile-sub-back:active {
        background: #fff;
        border-color: var(--mm-line);
        transform: scale(0.94);
    }

    .mega-menu-header .mobile-sub-menu .mobile-breadcrumb {
        display: block;
        flex: 1 1 auto;
        min-width: 0;
        padding: 0;
        background: none;
        border: 0;
    }

    .mega-menu-header .mobile-sub-menu .mm-trail {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0 4px;
        margin-bottom: 1px;
    }

    .mega-menu-header .mobile-sub-menu .mobile-breadcrumb-item {
        display: inline;
        padding: 1px 0;
        border: 0;
        border-radius: 4px;
        background: none;
        color: var(--mm-brand);
        font-size: 12px;
        font-weight: 600;
        line-height: 1.5;
        text-align: start;
    }

    .mega-menu-header .mobile-sub-menu .mobile-breadcrumb-separator {
        color: #B0BCC9;
        font-size: 12px;
        font-weight: 700;
    }

    .mega-menu-header .mobile-sub-menu .mm-l2title {
        margin: 0;
        padding: 0;
        color: var(--mm-ink);
        font-family: var(--font-primary);
        font-size: 17px;
        font-weight: 700;
        line-height: 1.35;
        letter-spacing: 0;
    }

    .mega-menu-header .mobile-sub-menu .mm-l2sub {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 4px 10px;
        margin: 3px 0 0;
        color: var(--mm-muted);
        font-size: 12.5px;
        line-height: 1.5;
    }

    .mega-menu-header .mobile-sub-menu .mm-l2link {
        display: inline-flex;
        align-items: center;
        gap: 2px;
        padding: 1px 8px 1px 6px;
        border: 1px solid #CFE4F2;
        border-radius: 999px;
        background: #fff;
        color: var(--mm-brand);
        font-size: 12px;
        font-weight: 700;
        text-decoration: none;
    }

    .mega-menu-header .mobile-sub-menu .mm-l2link svg {
        width: 14px;
        height: 14px;
        stroke-width: 2.2;
    }

    /* ---------- level 2+: service rows ---------- */

    .mega-menu-header .mobile-sub-menu .mm-list {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 10px;
    }

    .mega-menu-header .mobile-sub-menu .mobile-card.mm-svc {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        min-height: 0;
        padding: 12px;
        background: #fff;
        border: 1px solid var(--mm-line);
        border-radius: 16px;
        box-shadow: none;
        cursor: pointer;
        transition: none;
    }

    .mega-menu-header .mobile-sub-menu .mobile-card.mm-svc::after {
        content: none;
        display: none;
    }

    /* No whole-card press effect: the card also contains the two buttons */
    .mega-menu-header .mobile-sub-menu .mobile-card.mm-svc:active {
        background: #fff;
        box-shadow: none;
        transform: none;
    }

    .mega-menu-header .mobile-sub-menu .mm-svc-top {
        display: flex;
        align-items: center;
        gap: 8px;
        min-width: 0;
    }

    .mega-menu-header .mobile-sub-menu .mm-svc-main {
        display: flex;
        align-items: center;
        gap: 12px;
        flex: 1 1 auto;
        min-width: 0;
        margin: 0;
        padding: 0;
        border: 0;
        border-radius: 12px;
        background: none;
        color: inherit;
        font: inherit;
        text-align: start;
        text-decoration: none;
        cursor: pointer;
    }

    .mega-menu-header .mobile-sub-menu .mm-ic {
        display: grid;
        place-items: center;
        flex: none;
        width: 42px;
        height: 42px;
        border-radius: 12px;
        background: var(--mm-soft);
        color: var(--mm-brand);
    }

    .mega-menu-header .mobile-sub-menu .mm-ic svg {
        width: 22px;
        height: 22px;
    }

    .mega-menu-header .mobile-sub-menu .mm-svc .mm-name {
        font-size: 14.5px;
    }

    .mega-menu-header .mobile-sub-menu .mm-svc .mm-desc {
        margin-top: 2px;
        font-size: 12px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mega-menu-header .mobile-sub-menu .mm-more {
        display: grid;
        place-items: center;
        flex: none;
        width: 32px;
        height: 32px;
        border-radius: 10px;
        background: var(--mm-soft);
        color: var(--mm-brand);
    }

    .mega-menu-header .mobile-sub-menu .mm-more svg {
        width: 18px;
        height: 18px;
        stroke-width: 2.2;
    }

    /* Actions: same pair as the desktop cards ("تعلم" outlined, "اطلب الخدمة" filled) */
    .mega-menu-header .mobile-sub-menu .mobile-card-actions.mm-svc-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin: 0;
    }

    .mega-menu-header .mobile-sub-menu .mobile-card-btn.mm-btn {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        flex: none;
        min-width: 0;
        height: 34px;
        padding: 0 10px;
        border: 1.5px solid var(--mm-brand);
        border-radius: 10px;
        font-size: 12.5px;
        font-weight: 700;
        line-height: 1;
        text-decoration: none;
        white-space: nowrap;
        transition: transform 0.15s ease;
    }

    /* ~44px-tall hit area without taller buttons */
    .mega-menu-header .mobile-sub-menu .mobile-card-btn.mm-btn::before {
        content: "";
        position: absolute;
        inset: -5px -4px;
    }

    .mega-menu-header .mobile-sub-menu .mobile-card-btn.mm-btn span {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mega-menu-header .mobile-sub-menu .mobile-card-btn.mm-btn svg {
        width: 16px;
        height: 16px;
        stroke-width: 2;
    }

    .mega-menu-header .mobile-sub-menu .mobile-card-btn.mm-btn--service,
    .mega-menu-header .mobile-sub-menu .mobile-card-btn.mm-btn--service:hover,
    .mega-menu-header .mobile-sub-menu .mobile-card-btn.mm-btn--service:focus {
        background: var(--mm-brand);
        color: #fff;
    }

    .mega-menu-header .mobile-sub-menu .mobile-card-btn.mm-btn--learn,
    .mega-menu-header .mobile-sub-menu .mobile-card-btn.mm-btn--learn:hover,
    .mega-menu-header .mobile-sub-menu .mobile-card-btn.mm-btn--learn:focus {
        background: #fff;
        color: var(--mm-brand);
    }

    .mega-menu-header .mobile-sub-menu .mobile-card-btn.mm-btn:active {
        transform: scale(0.97);
    }

    /* ---------- small phones (≤360px): give row text more room ---------- */

    @media (max-width: 360px) {
        .mega-menu-header .mobile-main-menu .mobile-service-item.mm-cat {
            gap: 12px;
            padding: 12px;
        }

        .mega-menu-header .mobile-main-menu .mm-tile {
            width: 44px;
            height: 44px;
        }

        .mega-menu-header .mobile-main-menu .mm-cta {
            gap: 6px;
            padding: 0 8px;
            font-size: 13.5px;
        }

        .mega-menu-header .mobile-main-menu .mm-cta svg {
            width: 18px;
            height: 18px;
        }

        .mega-menu-header .mobile-sub-menu .mobile-card.mm-svc {
            padding: 10px;
        }

        .mega-menu-header .mobile-sub-menu .mm-svc-main {
            gap: 10px;
        }

        .mega-menu-header .mobile-sub-menu .mm-ic {
            width: 38px;
            height: 38px;
            border-radius: 11px;
        }

        .mega-menu-header .mobile-sub-menu .mm-ic svg {
            width: 20px;
            height: 20px;
        }

        .mega-menu-header .mobile-sub-menu .mm-svc .mm-name {
            font-size: 14px;
        }

        .mega-menu-header .mobile-sub-menu .mobile-card-btn.mm-btn {
            gap: 5px;
            padding: 0 6px;
        }

        .mega-menu-header .mobile-sub-menu .mm-more {
            width: 30px;
            height: 30px;
        }
    }

    /* ---------- focus ---------- */

    .mega-menu-header :is(.mobile-main-menu, .mobile-sub-menu) :is(a, button):focus-visible {
        outline: 2px solid var(--mm-brand);
        outline-offset: 2px;
    }

    .mega-menu-header .mobile-main-menu .mm-country-toggle:focus-visible {
        outline-offset: -2px;
    }
}

@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
    .mega-menu-header :is(.mobile-main-menu, .mobile-sub-menu) * {
        transition: none !important;
    }
}

/* Packages list under the CTAs (sites with several package pages and no hub). */
@media (max-width: 768px) {
    .mega-menu-header .mobile-main-menu .mm-cta[data-mm-pkg] svg:last-child {
        width: 14px;
        height: 14px;
        transition: transform 0.2s ease;
    }

    .mega-menu-header .mobile-main-menu .mm-cta[data-mm-pkg][aria-expanded="true"] svg:last-child {
        transform: rotate(180deg);
    }

    .mega-menu-header .mobile-main-menu .mm-pkg-list:not([hidden]) {
        list-style: none;
        margin: 8px 0 0;
        padding: 6px;
        display: grid;
        gap: 4px;
        background: #fff;
        border: 1px solid #E7EDF3;
        border-radius: 14px;
    }

    .mega-menu-header .mobile-main-menu .mm-pkg-list a {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px;
        border-radius: 10px;
        background: #F7F9FB;
        font-size: 12.5px;
        font-weight: 600;
        color: #2B3A4D;
        text-decoration: none;
        line-height: 1.4;
    }

    .mega-menu-header .mobile-main-menu .mm-pkg-list a svg:first-child {
        width: 17px;
        height: 17px;
        color: #2E8FC7;
        flex: none;
    }

    .mega-menu-header .mobile-main-menu .mm-pkg-list a svg:last-child {
        width: 14px;
        height: 14px;
        color: #B0BCC9;
        margin-inline-start: auto;
        flex: none;
    }
}

/* Header: bigger logo and hamburger on phones (the stale core.min.css bundle
   shrinks them to 36/20, which reads as tiny next to the 80px bar). */
@media (max-width: 768px) {
    .mega-menu-header .header-main-bar {
        min-height: 76px;
        padding: 10px 16px;
        gap: 12px;
    }

    .mega-menu-header .header-logo img {
        height: 50px !important;
        width: auto !important;
    }

    .mega-menu-header .mobile-menu-btn {
        width: 52px !important;
        height: 52px !important;
        border-radius: 14px;
        margin-inline-start: -6px;
    }

    .mega-menu-header .mobile-menu-btn svg {
        width: 30px !important;
        height: 30px !important;
        flex: 0 0 auto;
        min-width: 30px;
    }

    .mega-menu-header .mobile-menu-btn svg path {
        stroke-width: 2.4 !important;
    }

    .mega-menu-header .mobile-menu-btn:active {
        background: #F1F5F9;
    }
}

@media (max-width: 360px) {
    .mega-menu-header .header-main-bar {
        min-height: 70px;
        padding-inline: 12px;
    }

    .mega-menu-header .header-logo img {
        height: 44px !important;
    }

    .mega-menu-header .mobile-menu-btn {
        width: 48px !important;
        height: 48px !important;
    }

    .mega-menu-header .mobile-menu-btn svg {
        width: 27px !important;
        height: 27px !important;
        min-width: 27px;
    }
}
