/* =============================================================
 * Ambersea Category Menu — styles
 * Mobile-only: shown at ≤768px, hidden on desktop.
 * ============================================================= */

/* Root: hidden on desktop (>1280px) */
#ambersea-mobile-nav-root {
    display: none;
}

@media (max-width: 1280px) {
    #ambersea-mobile-nav-root {
        display: block;
    }

    /*
     * position:fixed — вырывает элемент из потока, не зависит от overflow/transform
     * предков (в отличие от sticky, который ломается при overflow на предке).
     * padding-top к body выставляется JS-ом после замера реальной высоты бара.
     */
    .ambersea-mobile-nav {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 9999;
        width: 100%;
        background: #ffffff;
        box-sizing: border-box;
    }

    /* ── Trigger bar ── */
    .ambersea-mobile-nav__bar {
        display: flex;
        flex-direction: row;
        align-items: center;
        width: 100%;
        min-height: 48px;
        border-bottom: 2px solid #e0e0e0;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.10);
        box-sizing: border-box;
        background: #ffffff;
    }

    /* ≡ Menu toggle (left icon) */
    .ambersea-mobile-nav__menu-toggle {
        flex: 0 0 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        border-right: 1px solid #e0e0e0;
        font-size: 20px;
        color: #222;
        cursor: pointer;
        min-height: 48px;
        -webkit-tap-highlight-color: transparent;
        transition: background 0.12s;
    }

    .ambersea-mobile-nav__menu-toggle:hover,
    .ambersea-mobile-nav__menu-toggle:active {
        background: #f0f0f0;
    }

    /* [All][Category][Brand] mode selector */
    .ambersea-mobile-nav__mode-selector {
        flex: 1 1 auto;
        display: flex;
        align-items: stretch;
        min-width: 0;
    }

    .ambersea-mobile-nav__mode-btn {
        flex: 1;
        border: none;
        border-right: 1px solid #e0e0e0;
        background: transparent;
        font-size: 10px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        cursor: pointer;
        color: #777;
        padding: 0;
        font-family: inherit;
        min-height: 48px;
        transition: background 0.12s, color 0.12s;
        -webkit-tap-highlight-color: transparent;
    }

    .ambersea-mobile-nav__mode-btn:last-child {
        border-right: none;
    }

    .ambersea-mobile-nav__mode-btn:hover {
        background: #f0f0f0;
        color: #222;
    }

    .ambersea-mobile-nav__mode-btn--active {
        background: #111;
        color: #fff;
    }

    /* ▼ Expand arrow (яркая, контрастная) */
    .ambersea-mobile-nav__expand-arrow {
        flex: 0 0 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #333;
        border: none;
        border-left: none;
        color: #fff;
        font-size: 14px;
        cursor: pointer;
        min-height: 48px;
        transition: background 0.12s;
        -webkit-tap-highlight-color: transparent;
    }

    .ambersea-mobile-nav__expand-arrow:hover,
    .ambersea-mobile-nav__expand-arrow:active {
        background: #000;
    }

    /* Right section: cart + user menu */
    .ambersea-mobile-nav__right {
        flex: 0 0 auto;
        display: flex;
        align-items: stretch;
        border-left: 1px solid #e8e8e8;
        position: relative; /* для user-dropdown */
    }

    /* Общий стиль иконок-кнопок */
    .ambersea-mobile-nav__icon-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        width: 48px;
        min-height: 48px;
        background: transparent;
        border: none;
        border-left: 1px solid #e8e8e8;
        color: #333;
        cursor: pointer;
        text-decoration: none;
        -webkit-tap-highlight-color: transparent;
        font-family: inherit;
    }

    .ambersea-mobile-nav__icon-btn:first-child {
        border-left: none;
    }

    .ambersea-mobile-nav__icon-btn:active,
    .ambersea-mobile-nav__icon-btn--active {
        background: #f0f0f0;
        color: #000;
    }

    /* SVG icon size */
    .ambersea-icon {
        width: 22px;
        height: 22px;
        flex-shrink: 0;
    }

    /* Cart count badge */
    .ambersea-mobile-nav__cart-badge {
        position: absolute;
        top: 8px;
        right: 6px;
        background: #d00;
        color: #fff;
        font-size: 10px;
        font-weight: 700;
        line-height: 1;
        padding: 2px 4px;
        border-radius: 8px;
        min-width: 16px;
        text-align: center;
    }

    /* User menu dropdown (opens from right) */
    .ambersea-mobile-nav__user-dropdown {
        position: absolute;
        top: 100%;
        right: 0;
        left: auto;
        min-width: 180px;
        background: #ffffff;
        border: 1px solid #e0e0e0;
        border-top: none;
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.14);
        z-index: 9998;
    }

    .ambersea-mobile-nav__user-dropdown[hidden] {
        display: none;
    }

    .ambersea-mobile-nav__user-link {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 13px 16px;
        font-size: 14px;
        font-weight: 500;
        color: #222;
        text-decoration: none;
        border-bottom: 1px solid #f0f0f0;
    }

    .ambersea-mobile-nav__user-link:last-child {
        border-bottom: none;
    }

    .ambersea-mobile-nav__user-link:active {
        background: #f5f5f5;
    }

    .ambersea-mobile-nav__user-link .ambersea-icon {
        width: 18px;
        height: 18px;
        color: #555;
        flex-shrink: 0;
    }

    /* ── Search overlay ── */
    .ambersea-mobile-nav__search-overlay {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: #fff;
        border-top: 1px solid #e0e0e0;
        box-shadow: 0 4px 12px rgba(0,0,0,0.12);
        z-index: 9998;
        padding: 10px 12px;
    }

    .ambersea-mobile-nav__search-overlay[hidden] {
        display: none;
    }

    .ambersea-mobile-nav__search-form {
        display: flex;
        align-items: center;
        gap: 8px;
        width: 100%;
    }

    .ambersea-mobile-nav__search-input {
        flex: 1;
        height: 40px;
        border: 2px solid #e0e0e0;
        border-radius: 6px;
        padding: 0 14px;
        font-size: 16px; /* предотвращает авто-зум на iOS */
        font-family: inherit;
        color: #222;
        background: #fafafa;
        outline: none;
        transition: border-color 0.15s;
        box-sizing: border-box;
    }

    .ambersea-mobile-nav__search-input:focus {
        border-color: #111;
        background: #fff;
    }

    .ambersea-mobile-nav__search-submit {
        flex: 0 0 40px;
        width: 40px;
        height: 40px;
        background: #111;
        border: none;
        border-radius: 6px;
        color: #fff;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        -webkit-tap-highlight-color: transparent;
    }

    .ambersea-mobile-nav__search-submit:hover {
        background: #333;
    }

    .ambersea-mobile-nav__search-submit .ambersea-icon {
        width: 18px;
        height: 18px;
    }

    /* ── Shared dropdown animation ──
     * Используем opacity + transform вместо display:none/block
     * для плавного появления/исчезновения.
     * JS переключает класс .is-open (не [hidden]). */
    .ambersea-mobile-nav__panel,
    .ambersea-mobile-nav__user-dropdown,
    .ambersea-mobile-nav__search-overlay {
        opacity: 0;
        visibility: hidden;
        transform: translateY(-6px);
        transition: opacity 0.18s ease, transform 0.18s ease, visibility 0s linear 0.18s;
        pointer-events: none;
    }

    .ambersea-mobile-nav__panel.is-open,
    .ambersea-mobile-nav__user-dropdown.is-open,
    .ambersea-mobile-nav__search-overlay.is-open {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
        transition: opacity 0.18s ease, transform 0.18s ease, visibility 0s linear 0s;
        pointer-events: auto;
    }

    /* [hidden] как fallback (для элементов без JS) */
    .ambersea-mobile-nav__panel[hidden],
    .ambersea-mobile-nav__user-dropdown[hidden],
    .ambersea-mobile-nav__search-overlay[hidden] {
        display: none;
    }

    /* ── Dropdown panel ── */
    .ambersea-mobile-nav__panel {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: #ffffff;
        border-top: 1px solid #e0e0e0;
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.14);
        max-height: 65vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        z-index: 9998;
    }

    /* ── Category list ── */
    .ambersea-mobile-nav__list {
        list-style: none;
        margin: 0;
        padding: 6px 0;
    }

    .ambersea-mobile-nav__item {
        border-bottom: 1px solid #f0f0f0;
    }

    .ambersea-mobile-nav__item:last-child {
        border-bottom: none;
    }

    /* Row: link + expand toggle */
    .ambersea-mobile-nav__item-row {
        display: flex;
        align-items: stretch;
    }

    .ambersea-mobile-nav__item-link {
        flex: 1;
        display: block;
        padding: 13px 16px;
        font-size: 14px;
        font-weight: 600;
        color: #222;
        text-decoration: none;
        background: transparent;
    }

    .ambersea-mobile-nav__item-link:hover {
        background: #e8e8e8;
        box-shadow: inset 3px 0 0 #555;
        color: #000;
    }

    .ambersea-mobile-nav__item-link:active {
        background: #ddd;
    }

    .ambersea-mobile-nav__item--active > .ambersea-mobile-nav__item-link,
    .ambersea-mobile-nav__item--active > .ambersea-mobile-nav__item-row
        .ambersea-mobile-nav__item-link {
        color: #000;
        font-weight: 800;
    }

    /* Expand/collapse toggle button (top-level) */
    .ambersea-mobile-nav__item-toggle {
        flex: 0 0 56px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        border-left: 1px solid #e8e8e8;
        font-size: 18px;
        color: #444;
        cursor: pointer;
        font-family: inherit;
        -webkit-tap-highlight-color: transparent;
        min-height: 48px;
    }

    .ambersea-mobile-nav__item-toggle:hover {
        background: #e0e0e0;
        color: #111;
    }

    .ambersea-mobile-nav__item-toggle:active {
        background: #d4d4d4;
    }

    /* ── View mode фильтрация в панели ── */
    .ambersea-mobile-nav__list[data-view="categories"] .ambersea-mobile-nav__item--brands {
        display: none !important;
    }

    .ambersea-mobile-nav__list[data-view="brands"]
        .ambersea-mobile-nav__item:not(.ambersea-mobile-nav__item--all):not(.ambersea-mobile-nav__item--brands) {
        display: none !important;
    }

    /* Счётчик товаров/брендов в пунктах панели */
    .ambersea-mobile-nav__item-count,
    .ambersea-mobile-nav__subitem-count {
        flex-shrink: 0;
        margin-left: 6px;
        font-weight: 400;
        color: #999;
        font-size: 11px;
    }

    .ambersea-mobile-nav__item-link--brands .ambersea-mobile-nav__item-count {
        color: #aaa;
    }

    /* ── All Brands: контрастный пункт ── */
    .ambersea-mobile-nav__item--brands > .ambersea-mobile-nav__item-row {
        background: #222;
        border-top: 2px solid #000;
    }

    .ambersea-mobile-nav__item-link--brands {
        color: #fff !important;
        font-weight: 700 !important;
    }

    .ambersea-mobile-nav__item-link--brands:hover {
        background: #333 !important;
        box-shadow: none !important;
    }

    .ambersea-mobile-nav__item--brands .ambersea-mobile-nav__item-toggle {
        background: #222;
        color: #aaa;
        border-left-color: #444;
    }

    .ambersea-mobile-nav__item--brands .ambersea-mobile-nav__item-toggle:hover {
        background: #333;
        color: #fff;
    }

    /* ── Sublist (анимированное раскрытие) ── */
    .ambersea-mobile-nav__sublist {
        list-style: none;
        margin: 0;
        padding: 4px 0 4px 16px;
        background: #fafafa;
        border-top: 1px solid #f0f0f0;
        overflow: hidden;
        max-height: 0;
        opacity: 0;
        transition: max-height 0.3s ease, opacity 0.2s ease;
    }

    /* [hidden] override: только display:block, max-height управляется через --open */
    .ambersea-mobile-nav__sublist[hidden] {
        display: block !important;
        pointer-events: none;
        /* max-height:0 и opacity:0 берутся из базового правила выше */
    }

    /* --open должен быть ПОСЛЕ [hidden] чтобы выиграть по порядку каскада */
    .ambersea-mobile-nav__item--open > .ambersea-mobile-nav__sublist {
        max-height: 3000px;
        opacity: 1;
        pointer-events: auto;
        transition: max-height 0.35s ease, opacity 0.25s ease;
    }

    .ambersea-mobile-nav__sublist--d2 {
        background: #f2f2f2;
        padding-left: 20px;
    }

    .ambersea-mobile-nav__sublist--d3 {
        background: #ebebeb;
        padding-left: 24px;
    }

    .ambersea-mobile-nav__subitem {
        border-bottom: 1px solid #f0f0f0;
    }

    .ambersea-mobile-nav__subitem:last-child {
        border-bottom: none;
    }

    /* Row: link + toggle для подкатегорий с детьми */
    .ambersea-mobile-nav__subitem-row {
        display: flex;
        align-items: stretch;
    }

    .ambersea-mobile-nav__subitem-link {
        flex: 1;
        display: block;
        padding: 10px 14px;
        font-size: 13px;
        font-weight: 500;
        color: #444;
        text-decoration: none;
    }

    .ambersea-mobile-nav__subitem-link--all {
        font-weight: 700;
        color: #222;
        border-bottom: 1px dashed #e0e0e0;
        margin-bottom: 2px;
    }

    .ambersea-mobile-nav__subitem-link:hover {
        background: #e4e4e4;
        box-shadow: inset 3px 0 0 #777;
        color: #000;
    }

    .ambersea-mobile-nav__subitem-link:active {
        background: #ddd;
    }

    /* Toggle кнопка для подкатегорий */
    .ambersea-mobile-nav__subitem-toggle {
        flex: 0 0 52px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        border-left: 1px solid #e4e4e4;
        font-size: 16px;
        color: #444;
        cursor: pointer;
        font-family: inherit;
        -webkit-tap-highlight-color: transparent;
        min-height: 44px;
    }

    .ambersea-mobile-nav__subitem-toggle:active {
        background: #e4e4e4;
    }

    .ambersea-mobile-nav__subitem--active > .ambersea-mobile-nav__subitem-link,
    .ambersea-mobile-nav__subitem--active > .ambersea-mobile-nav__subitem-row
        .ambersea-mobile-nav__subitem-link {
        color: #000;
        font-weight: 700;
    }
}
