/* =============================================================
 * Ambersea — Mobile layout overrides (child theme)
 * Breakpoint: ≤768px
 * ============================================================= */

/*
 * Явно показываем Accordion на десктопе — страховка от граничных случаев
 * при ресайзе окна, когда оба меню могут оказаться скрытыми.
 */
/*
 * Breakpoint: 1024px
 * ≤1024px → ambersea-category-menu (мобильное меню), accordion скрыт
 * >1024px → accordion (достаточно ширины для sidebar), мобильное меню скрыто
 * 768px был слишком мал: accordion начинал ломаться уже при ~900px.
 */

/* =============================================================
 * HEADER CONTACT BLOCK — телефон и адрес между логотипом и меню
 * ============================================================= */

/* ── Dropdown menu ── */
.ambersea-header-contact__phone,
.ambersea-header-contact__address {
    position: relative;   /* anchor for dropdown */
}

.ambersea-header-contact {
    position: relative;   /* contains absolute dropdown */
}

.ambersea-contact-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 9999;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    min-width: 210px;
    overflow: hidden;
    animation: ambersea-menu-in 0.12s ease;
}

@keyframes ambersea-menu-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.ambersea-contact-menu__header {
    padding: 10px 14px 8px;
    font-size: 12px;
    color: #333;
    font-weight: 500;
    line-height: 1.4;
    border-bottom: 1px solid #f0f0f0;
    max-width: 260px;
    word-break: break-word;
}

.ambersea-contact-menu__item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    color: #222;
    text-decoration: none;
    cursor: pointer;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    transition: background 0.1s;
    box-sizing: border-box;
}

.ambersea-contact-menu__item:hover,
.ambersea-contact-menu__item:focus {
    background: #f5f5f5;
    color: #000;
    outline: none;
}

.ambersea-contact-menu__item svg {
    flex-shrink: 0;
    opacity: 0.6;
}

/* ── Contact block ── */
.ambersea-header-contact {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex-shrink: 1;        /* сжимается при нехватке места */
    min-width: 0;
    padding-left: clamp(12px, 1.5vw, 24px);
    border-left: 1px solid #e4e4e4;
}

.ambersea-header-contact__phone,
.ambersea-header-contact__address {
    display: flex;
    align-items: center;
    gap: clamp(4px, 0.4vw, 7px);
    text-decoration: none;
    line-height: 1.2;
    color: #222;
    transition: color 0.15s;
    white-space: nowrap;   /* не переносить при сжатии */
}

.ambersea-header-contact__phone {
    /* clamp: 14px при 1300px → плавно → 19px при 1700px+ */
    font-size: clamp(14px, 1.2vw, 19px);
    font-weight: 700;
}

.ambersea-header-contact__address {
    /* clamp: 12px при 1300px → плавно → 15px при 1700px+ */
    font-size: clamp(12px, 0.95vw, 15px);
    color: #666;
    font-weight: 400;
}

.ambersea-header-contact__phone:hover {
    color: #000;
}

.ambersea-header-contact__address:hover {
    color: #333;
    text-decoration: underline;
}

.ambersea-header-contact__icon {
    flex-shrink: 0;
    opacity: 0.65;
    /* масштабируем иконку вместе с текстом */
    width: clamp(12px, 1vw, 16px);
    height: clamp(12px, 1vw, 16px);
}

/* Контакт всегда справа от логотипа — nav убран при ≤1280px,
   справа достаточно места в любом случае (топбар или hamburger). */
@media (max-width: 1280px) {
    .ambersea-header-contact__phone { font-size: 15px; }
    .ambersea-header-contact__address { font-size: 13px; }
    .ambersea-header-contact__icon { width: 13px; height: 13px; }
}

/* =============================================================
 * LOGOUT — desktop nav button
 * ============================================================= */

.ambersea-nav-logout-item {
    display: flex;
    align-items: center;
}

.ambersea-nav-logout-item button.ambersea-logout-trigger {
    display: flex;
    align-items: center;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    color: #888;
    font-family: inherit;
    transition: color 0.15s, background 0.15s;
    line-height: 1;
}

.ambersea-nav-logout-item button.ambersea-logout-trigger:hover {
    color: #c0392b;
    background: rgba(192, 57, 43, 0.06);
}

/* Mobile topbar logout button */
.ambersea-mobile-nav__user-link--logout {
    color: #c0392b !important;
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: inherit;
    width: 100%;
    text-align: left;
}

.ambersea-mobile-nav__user-link--logout:hover {
    background: rgba(192, 57, 43, 0.06) !important;
}

/* =============================================================
 * LOGOUT CONFIRMATION MODAL
 * ============================================================= */

.ambersea-logout-modal {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.22s ease;
}

.ambersea-logout-modal.is-open {
    opacity: 1;
    pointer-events: auto;
}

.ambersea-logout-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.ambersea-logout-modal__box {
    position: relative;
    background: #fff;
    border-radius: 14px;
    padding: 2rem 2rem 1.75rem;
    max-width: 360px;
    width: calc(100% - 2rem);
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    transform: translateY(6px);
    transition: transform 0.22s ease;
}

.ambersea-logout-modal.is-open .ambersea-logout-modal__box {
    transform: translateY(0);
}

.ambersea-logout-modal__icon {
    width: 56px;
    height: 56px;
    background: #fff5f5;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    color: #c0392b;
}

.ambersea-logout-modal__title {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0 0 0.5rem;
}

.ambersea-logout-modal__text {
    font-size: 14px;
    color: #666;
    line-height: 1.55;
    margin: 0 0 1.5rem;
}

.ambersea-logout-modal__btns {
    display: flex;
    gap: 0.75rem;
}

.ambersea-logout-modal__btn {
    flex: 1;
    padding: 11px 0;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    border: none;
    text-decoration: none !important;
    text-align: center;
    transition: background 0.15s;
}

.ambersea-logout-modal__btn--confirm {
    background: #c0392b;
    color: #fff !important;
}

.ambersea-logout-modal__btn--confirm:hover {
    background: #a93226;
}

.ambersea-logout-modal__btn--cancel {
    background: #f0f0f0;
    color: #333 !important;
}

.ambersea-logout-modal__btn--cancel:hover {
    background: #e4e4e4;
}

/* =============================================================
 * HEADER NAV — responsive collapse на не-топбар страницах
 * ============================================================= */

/* Всегда добавляем gap между лого+контакт и навигацией */
body:not(.ambersea-has-topbar) .wc-blocks-header-pattern.wp-block-group {
    gap: clamp(16px, 2vw, 40px) !important;
}

/* ≥1281px (не-топбар): hamburger скрыт, стандартный nav видим */
@media (min-width: 1281px) {
    body:not(.ambersea-has-topbar) .wc-blocks-header-pattern
        .wp-block-navigation__responsive-container-open {
        display: none !important;
    }
}

/* ≤1280px (не-топбар): nav скрыт, hamburger — compact dropdown.
 * Контейнер не имеет класса hidden-by-default — таргетируем напрямую. */
@media (max-width: 1280px) {
    body:not(.ambersea-has-topbar) .wc-blocks-header-pattern
        .wp-block-navigation .wp-block-navigation__responsive-container:not(.is-menu-open) {
        display: none !important;
    }
    body:not(.ambersea-has-topbar) .wc-blocks-header-pattern
        .wp-block-navigation__responsive-container-open {
        display: flex !important;
        color: currentColor;
    }
    /* Logout item: не скрываем отдельно — контейнер и так скрыт
       через :not(.is-menu-open), а в открытом dropdown logout должен быть виден */
}

/* ── Compact dropdown (весь диапазон, где hamburger активен) ── */

/* Anchor для absolute-позиционирования */
body:not(.ambersea-has-topbar) .wc-blocks-header-pattern .wp-block-navigation {
    position: relative !important;
}

/* Overlay → компактный dropdown */
body:not(.ambersea-has-topbar) .wc-blocks-header-pattern
    .wp-block-navigation__responsive-container.is-menu-open {
    position: absolute !important;
    top: calc(100% + 8px) !important;
    right: 0 !important;
    bottom: auto !important;
    left: auto !important;
    width: auto !important;
    min-width: 200px !important;
    height: auto !important;
    max-height: 75vh !important;
    overflow-y: auto !important;
    border-radius: 12px !important;
    border: 1px solid #e4e4e4 !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.13) !important;
    padding: 0.4rem 0.5rem !important;
    background: #fff !important;
    overflow: hidden !important;
    color: #222 !important;
    z-index: 9999 !important;
    animation: ambersea-dropdown-in 0.15s ease !important;
}

@keyframes ambersea-dropdown-in {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Контент: вертикальный список, правое выравнивание */
body:not(.ambersea-has-topbar) .wc-blocks-header-pattern
    .wp-block-navigation__responsive-container.is-menu-open
    .wp-block-navigation__responsive-container-content {
    padding-top: 0 !important;
    flex-direction: column !important;
    align-items: flex-end !important;
    flex-wrap: nowrap !important;
}

/* Пункты меню: правый край, отступ */
body:not(.ambersea-has-topbar) .wc-blocks-header-pattern
    .wp-block-navigation__responsive-container.is-menu-open
    .wp-block-navigation-item__content {
    padding: 0.55rem 1.25rem 0.55rem 2rem !important;
    font-size: 15px !important;
    font-weight: 600 !important;
    white-space: nowrap !important;
    text-align: right !important;
    justify-content: flex-end !important;
}

body:not(.ambersea-has-topbar) .wc-blocks-header-pattern
    .wp-block-navigation__responsive-container.is-menu-open
    .wp-block-navigation-item {
    width: 100% !important;
}

body:not(.ambersea-has-topbar) .wc-blocks-header-pattern
    .wp-block-navigation__responsive-container.is-menu-open
    .wp-block-navigation-item:hover {
    background: #f5f5f5 !important;
}

/* Скрыть кнопку закрытия × — меню закрывается повторным кликом на hamburger или Esc */
body:not(.ambersea-has-topbar) .wc-blocks-header-pattern
    .wp-block-navigation__responsive-container-close {
    display: none !important;
}

/* Снять блокировку скролла страницы при открытом дропдауне */
html.has-modal-open:has(body:not(.ambersea-has-topbar)) {
    overflow: auto !important;
}

/* Убираем "Showing X–Y of Z results" — неактуально при Load More / infinite scroll */
.woocommerce-result-count { display: none !important; }

/*
 * Минимальная ширина карточки товара — 230px (глобально, все breakpoints).
 * repeat(auto-fill, minmax(230px, 1fr)) сокращает колонки автоматически:
 *   ~480px → 2 кол. | ~700px → 3 кол. | ~960px → 4 кол. | ~1200px → 5 кол.
 * На десктопе с sidebar (products ≈ 70% viewport):
 *   1281px → 3-4 кол. | 1440px → 4 кол. | 1920px → 5-6 кол.
 * Предотвращает сжатие controls (−/input/+/Add) до нечитаемых размеров.
 */
.wc-block-product-template {
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)) !important;
}

/*
 * Brands page layout: flex вместо grid — надёжнее чем FSE grid placement.
 * Desktop (>1280px): sidebar 30% + content 70% рядом.
 * Mobile (≤1280px): sidebar скрыт, карточки на всю ширину.
 */
@media (min-width: 1281px) {
    body.page-template-page-brands main.is-layout-grid {
        display: flex !important;
        flex-direction: row !important;
        align-items: flex-start !important;
        flex-wrap: nowrap !important;
        gap: 0 !important;
        max-width: none !important;  /* убрать ограничения ширины main */
        width: 100% !important;
        box-sizing: border-box !important;
    }

    body.page-template-page-brands main.is-layout-grid > :first-child {
        flex: 0 0 30% !important;
        width: 30% !important;
        max-width: 30% !important;
    }

    body.page-template-page-brands main.is-layout-grid > :last-child {
        flex: 1 1 auto !important;
        min-width: 0 !important;
        max-width: none !important;
        width: auto !important;
        padding-left: 16px !important;
        box-sizing: border-box !important;
    }

    /* brands-grid напрямую — обходит любые is-layout-constrained ограничения */
    body.page-template-page-brands .ambersea-brands-grid {
        max-width: none !important;
        width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        box-sizing: border-box !important;
    }

    /* Heading выравниваем тоже */
    body.page-template-page-brands main.is-layout-grid > :last-child .wp-block-heading {
        max-width: none !important;
    }
}

/*
 * АРХИТЕКТУРНАЯ ЗАМЕТКА:
 * WordPress FSE не выводит className из блочного шаблона для tagName:main
 * и вложенных wp-block-group элементов без явных идентификаторов.
 * Используем структурные CSS-селекторы:
 *   main.is-layout-grid > :first-child  = sidebar (6 колонок)
 *   main.is-layout-grid > :last-child   = products (14 колонок)
 */

@media (min-width: 1281px) {
    /* Sidebar всегда видим на десктопе */
    main.wp-block-group.is-layout-grid > :first-child {
        display: block !important;
        visibility: visible !important;
    }

    /* Sticky accordion реализован через JS (sidebar.js):
     * CSS position:sticky не работает — предок с overflow на стеке
     * WordPress/WooCommerce. Диагноз: TODO при следующей сессии. */
}

@media (max-width: 1280px) {

    /* Скрыть стандартное меню и поиск в хедере ТОЛЬКО на страницах с топбаром
       (shop, category, brand, search) — там функции меню перехватывает топбар.
       На остальных страницах (my-account, checkout, register и др.) меню остаётся. */
    .ambersea-has-topbar .wc-blocks-header-pattern .wp-block-navigation {
        display: none !important;
    }

    .ambersea-has-topbar .wc-blocks-header-pattern .wp-block-search,
    .ambersea-has-topbar .wc-blocks-header-pattern form[role="search"] {
        display: none !important;
    }

    /* Скрыть sidebar:
     * - shop/category: main.is-layout-grid — первый child
     * - search: div.is-layout-grid — первый child (body.search-results) */
    main.wp-block-group.is-layout-grid > :first-child,
    body.search-results .wp-block-group.is-layout-grid > :first-child,
    .wpb_the_category_accordion,
    .wpb_category_n_menu_accordion_list {
        display: none !important;
        visibility: hidden !important;
    }

    /* Products занимает всю ширину (shop + search) */
    main.wp-block-group.is-layout-grid > :last-child,
    body.search-results .wp-block-group.is-layout-grid > :last-child {
        grid-column: 1 / -1 !important;
        width: 100% !important;
        padding-left: var(--wp--style--root--padding-left, var(--wp--style--root--padding-right, 1.5rem)) !important;
    }

    /* minmax moved to global scope below — applies at all breakpoints */

    html, body {
        overflow-x: clip !important;
    }
}
