/* ==========================================================================
   Мега-меню категорий
   Десктоп: панель по центру под шапкой, первый уровень слева, второй — в колонках.
   Мобильный: полноэкранная панель с drill-down.
   ========================================================================== */

/* ---- панель ---- */
.mega {
    --mega-cols: 3;
    position: fixed;
    z-index: 400;
    display: none;
    width: min(980px, calc(100vw - 40px));
    min-height: 340px;
    background: #fff;
    border: 1px solid #e3e8ef;
    border-radius: 6px;
    box-shadow: 0 12px 32px rgba(18, 49, 90, .16);
}
.mega.is-open { display: flex }

/* ---- первый уровень ---- */
.mega-root {
    flex: 0 0 262px;
    padding: 8px 0;
    border-right: 1px solid #e3e8ef;
    overflow-y: auto;
}
.mega-root a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 16px;
    color: #1d2430;
    font-size: 14.5px;
    text-decoration: none;
}
.mega-root a span { flex: 1; min-width: 0 }
.mega-root a:after { content: "\203A"; color: #5f7186; font-size: 17px; line-height: 1 }
.mega-root a.no-sub:after { content: "" }
.mega-root a:hover,
.mega-root a.is-active { background: #f2f6fb; color: #0f5ba8 }
.mega-root a:focus-visible { outline: 2px solid #1573c4; outline-offset: -2px }

/* ---- второй уровень ---- */
.mega-sub {
    flex: 1;
    padding: 20px 24px;
    overflow-y: auto;
    column-count: var(--mega-cols);
    column-gap: 26px;
}
.mega-root,
.mega-sub {
    max-height: calc(100vh - var(--mega-top, 120px) - 5px);
}
.mega-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 0;
    color: #1d2430;
    font-size: 14.5px;
    text-decoration: none;
    break-inside: avoid;
}
.mega-item span { flex: 1; min-width: 0 }
.mega-item:hover { color: #1573c4 }
.mega-item:hover span { text-decoration: underline }

.mega-empty { color: #5f7186; font-size: 14px }

/* ---- иконки ---- */
.mega-ic { object-fit: contain }
.mega-ic-md { width: 30px; height: 30px; flex: 0 0 30px }
.mega-ic-sm { width: 30px; height: 30px; flex: 0 0 30px }

/* ---- шапка панели (только мобильный) ---- */
.mega-head { display: none }

/* ---- мобильный ---- */
@media (max-width: 900px) {
    .mega {
        position: fixed;
        inset: 0;
        transform: none;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        min-height: 0;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        flex-direction: column;
    }

    .mega-head {
        display: flex;
        align-items: center;
        gap: 4px;
        flex: 0 0 auto;
        padding: 0 4px;
        background: #124f80;
        color: #fff;
        font-weight: 600;
    }
    .mega-head .mega-title {
        flex: 1;
        min-width: 0;
        padding: 0 4px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .mega-head button {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 48px;
        height: 48px;
        flex: 0 0 48px;
        padding: 0;
        background: none;
        border: 0;
        color: #fff;
        font-size: 28px;
        line-height: 1;
        cursor: pointer;
    }
    .mega-head [data-back] { display: none }
    .mega.at-sub .mega-head [data-back] { display: flex }

    .mega-sub { display: none; padding: 0 }
    .mega.at-sub .mega-root { display: none }

    .mega-root,
    .mega.at-sub .mega-sub {
        display: block;
        flex: 1 1 auto;
        height: auto;
        min-height: 0;
        max-height: none;
        columns: auto;
        border: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .mega-root a,
    .mega-item {
        padding: 9px 16px;
        border-bottom: 1px solid #eef2f7;
    }
}
