/* =====================================================================
   Мобильная шапка Arqelya — независимая от Bootstrap.
   Видна только на телефонах (≤ 991.98px). На десктопе скрыта полностью.
   Использует собственный JS (assets/js/mobile-header.js), никаких
   offcanvas / backdrop / data-bs-* атрибутов.
   ===================================================================== */

/* Сбрасываем — по умолчанию мобильная шапка скрыта */
.mh,
.mh-menu,
.mh-overlay {
    display: none;
}

@media (max-width: 991.98px) {
    /* ---- 1. Базовый каркас ---- */
    .mh {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        position: sticky;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        min-height: 56px;
        padding: 8px max(14px, env(safe-area-inset-left)) 8px max(14px, env(safe-area-inset-right));
        background: var(--arq-paper, #f7f4ef);
        border-bottom: 0.5px solid var(--arq-line, rgba(42, 37, 32, 0.12));
        z-index: 1030;
        /* НЕ ставим backdrop-filter — он ломает sticky в iOS Safari */
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        box-sizing: border-box;
    }

    html[data-theme="dark"] .mh {
        background: var(--arq-paper, #161311);
        border-bottom-color: var(--arq-line, rgba(229, 219, 200, 0.12));
    }

    /* ---- 2. Бренд (лого + название) ---- */
    .mh__brand {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        text-decoration: none;
        color: inherit;
        min-width: 0;
        flex: 1 1 auto;
    }

    .mh__logo {
        width: 32px;
        height: 32px;
        flex: 0 0 auto;
        object-fit: contain;
    }

    .mh__name {
        font-family: var(--font-display, "Cormorant Garamond", serif);
        font-size: 19px;
        font-weight: 500;
        letter-spacing: 0.02em;
        color: var(--arq-ink, #2a2520);
        line-height: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    html[data-theme="dark"] .mh__name {
        color: var(--arq-ink, #ede8df);
    }

    /* ---- 3. Правая группа (тема + бургер) ---- */
    .mh__actions {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        flex: 0 0 auto;
    }

    .mh__theme-toggle {
        flex-shrink: 0;
    }

    .mh__icon-btn {
        appearance: none;
        -webkit-appearance: none;
        background: transparent;
        border: 0;
        padding: 0;
        width: 40px;
        height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 999px;
        color: var(--arq-ink, #2a2520);
        cursor: pointer;
        transition: background-color 0.15s ease;
        -webkit-tap-highlight-color: transparent;
    }

    .mh__icon-btn:active,
    .mh__icon-btn:hover {
        background: rgba(42, 37, 32, 0.08);
    }

    html[data-theme="dark"] .mh__icon-btn {
        color: var(--arq-ink, #ede8df);
    }

    html[data-theme="dark"] .mh__icon-btn:active,
    html[data-theme="dark"] .mh__icon-btn:hover {
        background: rgba(237, 232, 223, 0.08);
    }

    .mh__icon-btn svg {
        width: 20px;
        height: 20px;
        display: block;
        fill: none;
        stroke: currentColor;
        stroke-width: 1.6;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    /* Бургер на 3 линии — становится крестиком когда меню открыто */
    .mh__burger {
        position: relative;
    }

    .mh__burger-line {
        position: absolute;
        left: 11px;
        right: 11px;
        height: 1.5px;
        background: currentColor;
        border-radius: 1px;
        transition: transform 0.25s ease, opacity 0.2s ease, top 0.25s ease;
    }

    .mh__burger-line:nth-child(1) { top: 13px; }
    .mh__burger-line:nth-child(2) { top: 19px; }
    .mh__burger-line:nth-child(3) { top: 25px; }

    .mh__burger[aria-expanded="true"] .mh__burger-line:nth-child(1) {
        top: 19px;
        transform: rotate(45deg);
    }

    .mh__burger[aria-expanded="true"] .mh__burger-line:nth-child(2) {
        opacity: 0;
    }

    .mh__burger[aria-expanded="true"] .mh__burger-line:nth-child(3) {
        top: 19px;
        transform: rotate(-45deg);
    }

    /* ---- 4. Выезжающее меню ---- */
    .mh-menu {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: min(86vw, 340px);
        max-width: 100vw;
        background: var(--arq-paper, #f7f4ef);
        border-left: 0.5px solid var(--arq-line, rgba(42, 37, 32, 0.14));
        box-shadow: -16px 0 50px rgba(0, 0, 0, 0.18);
        transform: translateX(100%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 2001;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    html[data-theme="dark"] .mh-menu {
        background: var(--arq-paper-2, #1f1b18);
        border-left-color: var(--arq-line, rgba(229, 219, 200, 0.12));
        box-shadow: -16px 0 50px rgba(0, 0, 0, 0.5);
    }

    .mh-menu.is-open {
        transform: translateX(0);
    }

    .mh-menu__head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        padding: 14px 18px;
        border-bottom: 0.5px solid var(--arq-line, rgba(42, 37, 32, 0.12));
    }

    .mh-menu__brand {
        display: inline-flex;
        align-items: center;
        gap: 10px;
        text-decoration: none;
        color: inherit;
        font-family: var(--font-display, "Cormorant Garamond", serif);
        font-size: 20px;
        font-weight: 500;
        letter-spacing: 0.02em;
    }

    .mh-menu__brand img {
        width: 28px;
        height: 28px;
        object-fit: contain;
    }

    .mh-menu__close {
        appearance: none;
        background: transparent;
        border: 0;
        width: 40px;
        height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 999px;
        color: inherit;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .mh-menu__close:active,
    .mh-menu__close:hover {
        background: rgba(42, 37, 32, 0.08);
    }

    .mh-menu__close svg {
        width: 20px;
        height: 20px;
        stroke: currentColor;
        stroke-width: 1.6;
        fill: none;
        stroke-linecap: round;
    }

    .mh-menu__body {
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        padding: 8px 0;
    }

    .mh-menu__nav {
        display: flex;
        flex-direction: column;
    }

    .mh-menu__link {
        display: flex;
        align-items: center;
        padding: 14px 22px;
        font-family: var(--font-body, "Manrope", system-ui, sans-serif);
        font-size: 15px;
        font-weight: 500;
        letter-spacing: 0;
        color: var(--arq-ink, #2a2520);
        text-decoration: none;
        border: 0;
        background: transparent;
        transition: background-color 0.15s ease;
        -webkit-tap-highlight-color: transparent;
        min-height: 48px;
    }

    .mh-menu__link:active,
    .mh-menu__link:hover {
        background: rgba(42, 37, 32, 0.06);
        color: var(--arq-ink, #2a2520);
    }

    .mh-menu__link.is-active {
        background: rgba(42, 37, 32, 0.08);
        font-weight: 600;
    }

    html[data-theme="dark"] .mh-menu__link {
        color: var(--arq-ink, #ede8df);
    }

    html[data-theme="dark"] .mh-menu__link:active,
    html[data-theme="dark"] .mh-menu__link:hover,
    html[data-theme="dark"] .mh-menu__link.is-active {
        background: rgba(237, 232, 223, 0.08);
        color: var(--arq-ink, #ede8df);
    }

    .mh-menu__divider {
        height: 0.5px;
        background: var(--arq-line, rgba(42, 37, 32, 0.12));
        margin: 8px 22px;
    }

    .mh-menu__foot {
        padding: 14px 22px max(20px, env(safe-area-inset-bottom));
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .mh-menu__btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 46px;
        padding: 10px 18px;
        font-family: var(--font-body, "Manrope", system-ui, sans-serif);
        font-size: 13px;
        font-weight: 600;
        letter-spacing: 0.06em;
        text-transform: uppercase;
        text-decoration: none;
        border: 0;
        border-radius: 0;
        transition: background-color 0.15s ease, color 0.15s ease;
        -webkit-tap-highlight-color: transparent;
        cursor: pointer;
    }

    .mh-menu__btn--solid {
        background: var(--arq-ink, #2a2520);
        color: var(--arq-paper, #f7f4ef);
    }

    .mh-menu__btn--solid:active {
        background: #4a423a;
        color: var(--arq-paper, #f7f4ef);
    }

    .mh-menu__btn--outline {
        background: transparent;
        color: var(--arq-ink, #2a2520);
        border: 0.5px solid var(--arq-line, rgba(42, 37, 32, 0.4));
    }

    .mh-menu__btn--outline:active {
        background: rgba(42, 37, 32, 0.06);
        color: var(--arq-ink, #2a2520);
    }

    html[data-theme="dark"] .mh-menu__btn--solid {
        background: var(--arq-accent, #e07a4f);
        color: var(--arq-accent-ink, #16110d);
    }

    html[data-theme="dark"] .mh-menu__btn--outline {
        color: var(--arq-ink, #ede8df);
        border-color: rgba(237, 232, 223, 0.32);
    }

    .mh-menu__hint {
        margin: 0;
        font-size: 12px;
        color: var(--arq-ink-soft, rgba(42, 37, 32, 0.6));
        letter-spacing: 0.04em;
    }

    /* ---- 5. Затемнение под меню ---- */
    .mh-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 18, 14, 0.45);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.24s ease;
        z-index: 2000;
    }

    .mh-overlay.is-open {
        opacity: 1;
        pointer-events: auto;
    }

    /* ---- 6. Запрет скролла фоном, пока меню открыто ---- */
    html.mh-locked,
    html.mh-locked body {
        overflow: hidden !important;
        touch-action: none;
    }

    /* ---- 7. Скрываем старую (десктопную) шапку и её offcanvas на мобильных ---- */
    .site-header.site-header--split,
    .site-nav-offcanvas {
        display: none !important;
    }
}

/* На десктопе мобильная шапка не нужна */
@media (min-width: 992px) {
    .mh,
    .mh-menu,
    .mh-overlay {
        display: none !important;
    }
}
