/* BN-038: Кнопка «Подобрать ваш размер» + модалка с подбором + карусель альтернатив */

/* --- Кнопка-триггер над блоком «Размер:» --- */
.bn-size-picker-bar {
    margin: 14px 0 10px 0;
    display: flex;
    justify-content: center;
}
button.bn-size-picker-trigger,
.bn-size-picker-trigger {
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    padding: 10px 18px !important;
    background: #fff !important;
    border: 1px solid #1a1a1a !important;
    border-radius: 0 !important;
    font-family: inherit !important;
    font-size: 13px !important;
    line-height: 1 !important;
    color: #1a1a1a !important;
    cursor: pointer !important;
    transition: background .15s ease, color .15s ease !important;
    letter-spacing: .02em !important;
    text-decoration: none !important;
    text-transform: none !important;
    box-shadow: none !important;
    width: auto !important;
    min-width: 0 !important;
    margin: 0 !important;
    font-weight: 400 !important;
    outline: 0 !important;
    appearance: none !important;
    -webkit-appearance: none !important;
}
button.bn-size-picker-trigger:hover,
.bn-size-picker-trigger:hover {
    background: #1a1a1a !important;
    color: #fff !important;
}
button.bn-size-picker-trigger .bn-spc-icon,
.bn-size-picker-trigger .bn-spc-icon { display: inline-flex !important; align-items: center !important; }
button.bn-size-picker-trigger:hover .bn-spc-icon svg,
.bn-size-picker-trigger:hover .bn-spc-icon svg { stroke: #fff !important; }
.bn-size-picker-trigger .bn-spc-icon {
    display: inline-flex;
    align-items: center;
}
.bn-size-picker-trigger .bn-spc-text {
    white-space: nowrap;
}

/* --- Overlay с блюром --- */
.bn-spc-overlay {
    position: fixed !important;
    top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
    width: 100vw !important; height: 100vh !important;
    background: rgba(20, 20, 20, .35);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    z-index: 2147483000 !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
    pointer-events: auto !important;
}
.bn-spc-overlay.is-open { opacity: 1; }
body.bn-spc-locked { overflow: hidden; }

/* --- Окно модалки --- */
.bn-spc-modal {
    position: relative;
    background: #fff;
    width: 100%;
    max-width: 1100px;
    height: 92vh;
    max-height: calc(100vh - 24px);
    border-radius: 4px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(12px);
    transition: transform .25s ease;
}
.bn-spc-overlay.is-open .bn-spc-modal { transform: translateY(0); }
.bn-spc-header { display: none !important; }
.bn-spc-title { display: none !important; }
.bn-spc-close {
    background: transparent;
    border: 0;
    width: 36px; height: 36px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #1a1a1a;
    border-radius: 50%;
    transition: background .15s, box-shadow .15s;
}
.bn-spc-close:hover { background: #f3f3f3; }
.bn-spc-close--floating {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2147483647;
    background: rgba(255,255,255,.95);
    box-shadow: 0 2px 8px rgba(0,0,0,.12);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.bn-spc-close--floating:hover { background: #fff; box-shadow: 0 4px 12px rgba(0,0,0,.15); }

.bn-spc-body {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.bn-spc-iframe {
    width: 100%;
    border: 0;
    display: block;
    height: 85vh;
    min-height: 720px;
    background: #fff;
}

/* --- Карусель альтернатив снизу --- */
.bn-spc-alternatives {
    border-top: 1px solid #eee;
    padding: 18px 20px 22px 20px;
    background: #fafafa;
}
.bn-spc-alt-title {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #1a1a1a;
    margin: 0 0 12px 0;
    font-weight: 500;
}
.bn-spc-alt-empty {
    font-size: 14px;
    color: #777;
    padding: 12px 0;
}
.bn-spc-alt-track {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 260px;
    gap: 14px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
}
.bn-spc-alt-card {
    scroll-snap-align: start;
    background: #fff;
    border: 1px solid #ececec;
    display: flex;
    flex-direction: column;
    position: relative;
    transition: border-color .15s;
}
.bn-spc-alt-card:hover { border-color: #1a1a1a; }
.bn-spc-alt-card a.bn-spc-alt-link {
    text-decoration: none;
    color: inherit;
    display: block;
}
.bn-spc-alt-img {
    aspect-ratio: 3 / 4;
    background: #f4f4f4 center/cover no-repeat;
    display: block;
}
.bn-spc-alt-info { padding: 10px 12px 12px; }
.bn-spc-alt-brand { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #888; margin-bottom: 4px; }
.bn-spc-alt-name { font-size: 13px; color: #1a1a1a; line-height: 1.3; min-height: 34px; margin-bottom: 8px;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.bn-spc-alt-price { font-size: 14px; color: #1a1a1a; font-weight: 500; }
.bn-spc-alt-price .bn-spc-alt-old { font-size: 12px; color: #999; text-decoration: line-through; margin-left: 6px; font-weight: 400; }
.bn-spc-alt-badge {
    position: absolute;
    top: 8px; left: 8px;
    background: #1a1a1a;
    color: #fff;
    font-size: 10px;
    letter-spacing: .05em;
    padding: 3px 7px;
    text-transform: uppercase;
}
.bn-spc-alt-cta {
    width: 100%;
    margin-top: 8px;
    padding: 8px 0;
    background: #1a1a1a;
    color: #fff;
    border: 0;
    font-size: 11px;
    letter-spacing: .08em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background .15s;
}
.bn-spc-alt-cta:hover { background: #444; }

/* --- Toast / sticky info --- */
.bn-spc-result-banner {
    background: #f6f3ef;
    border-top: 1px solid #eadfd0;
    padding: 12px 20px;
    font-size: 14px;
    color: #1a1a1a;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.bn-spc-result-banner.is-ok { background: #eef7ee; border-top-color: #c2deb9; }
.bn-spc-result-banner.is-missing { background: #fdf1e6; border-top-color: #f1cfa1; }
.bn-spc-result-banner button {
    background: #1a1a1a;
    color: #fff;
    border: 0;
    padding: 8px 14px;
    font-size: 12px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: .06em;
}
.bn-spc-result-banner button:hover { background: #444; }

/* --- Подсветка нужного размера в карточке после успешного подбора --- */
.product-page .sizes .round.size.bn-spc-hinted {
    animation: bn-spc-pulse 1.6s ease-out 2;
    box-shadow: 0 0 0 2px #1a1a1a inset;
}
@keyframes bn-spc-pulse {
    0%   { box-shadow: 0 0 0 0   rgba(26,26,26,0); }
    30%  { box-shadow: 0 0 0 8px rgba(26,26,26,.18); }
    100% { box-shadow: 0 0 0 0   rgba(26,26,26,0); }
}

/* --- Мобильная адаптация --- */
@media (max-width: 720px) {
    /* Полноэкранная модалка */
    .bn-spc-overlay { padding: 0; }
    .bn-spc-modal {
        max-width: 100%;
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        overflow: hidden;
    }
    /* Внешний body модалки НЕ скроллим — иначе на iOS дрыгается между ним и iframe */
    .bn-spc-body { overflow: hidden !important; -webkit-overflow-scrolling: auto; flex: 1 1 auto; display: flex; flex-direction: column; }
    /* iframe фиксированной высоты — занимает остаток модалки, прокрутка ВНУТРИ него */
    .bn-spc-iframe { flex: 1 1 auto; height: 100%; min-height: 0; }
    /* Карусель снизу — крупнее карточки и тач-скролл */
    .bn-spc-alternatives { padding: 14px 14px 18px; }
    .bn-spc-alt-title { font-size: 12px; margin-bottom: 10px; }
    .bn-spc-alt-track { grid-auto-columns: 70vw; gap: 10px; }
    .bn-spc-alt-card { border-color: #e5e5e5; }
    .bn-spc-alt-name { font-size: 13px; min-height: auto; -webkit-line-clamp: 2; }
    .bn-spc-alt-price { font-size: 15px; }
    /* Кнопка на карточке: центр + крупнее touch-target */
    .bn-size-picker-bar { margin: 12px 0; }
    .bn-size-picker-trigger { font-size: 13px; padding: 10px 16px; min-height: 40px; }
    /* Плавающий крестик закрытия — fixed относительно viewport, всегда виден */
    .bn-spc-close--floating {
        position: fixed !important;
        top: max(10px, env(safe-area-inset-top, 10px));
        right: max(10px, env(safe-area-inset-right, 10px));
        width: 44px; height: 44px;
        background: #1a1a1a !important;
        color: #fff !important;
        box-shadow: 0 4px 12px rgba(0,0,0,.25);
        z-index: 2147483647;
    }
    .bn-spc-close--floating:hover { background: #333 !important; }
    .bn-spc-close--floating svg { stroke: #fff; }
    /* Баннер «вашего размера нет» */
    .bn-spc-result-banner { font-size: 13px; padding: 10px 14px; flex-direction: column; align-items: stretch; gap: 8px; }
}

@media (max-width: 380px) {
    .bn-spc-alt-track { grid-auto-columns: 80vw; }
    .bn-size-picker-trigger { font-size: 12px; padding: 9px 12px; }
}

/* BN-038: loading spinner пока iframe грузится */
.bn-spc-loader {
    position: absolute;
    inset: 0;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    z-index: 4;
    transition: opacity .3s ease;
}
.bn-spc-loader.is-hidden { opacity: 0; pointer-events: none; }
.bn-spc-loader-spinner {
    width: 36px; height: 36px;
    border: 3px solid #eee;
    border-top-color: #1a1a1a;
    border-radius: 50%;
    animation: bn-spc-spin .8s linear infinite;
}
.bn-spc-loader-text { font-size: 13px; color: #888; letter-spacing: .04em; }
@keyframes bn-spc-spin { to { transform: rotate(360deg); } }

/* BN-038: dialog-element — top-layer overlay, на весь экран, blur через ::backdrop */
dialog.bn-spc-overlay {
    width: 100vw !important; height: 100vh !important;
    max-width: 100vw !important; max-height: 100vh !important;
    min-width: 100vw !important; min-height: 100vh !important;
    margin: 0 !important; padding: 16px !important;
    border: 0 !important; outline: 0 !important;
    background: rgba(20,20,20,.35) !important;
    -webkit-backdrop-filter: blur(8px) !important;
    backdrop-filter: blur(8px) !important;
    color: inherit !important;
    overflow: hidden !important;
    top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
    position: fixed !important;
    inset: 0 !important;
    box-sizing: border-box !important;
}
dialog.bn-spc-overlay::backdrop {
    background: rgba(20, 20, 20, .35);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}
dialog.bn-spc-overlay[open],
dialog.bn-spc-overlay {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}
dialog.bn-spc-overlay > .bn-spc-modal {
    max-width: 1100px !important;
    width: 100% !important;
    height: 92vh !important;
    max-height: calc(100vh - 24px) !important;
}
@media (max-width: 720px) {
    dialog.bn-spc-overlay { padding: 0 !important; }
    dialog.bn-spc-overlay > .bn-spc-modal {
        max-width: 100vw !important;
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100vh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
    }
}

/* BN-038: кнопки в banner «Есть ваш размер» */
.bn-spc-result-banner button.bn-spc-action-primary {
    background: #1a1a1a !important; color: #fff !important;
    border: 0 !important; padding: 9px 16px !important;
    font-size: 12px !important; cursor: pointer !important;
    text-transform: uppercase !important; letter-spacing: .06em !important;
    border-radius: 0 !important; font-weight: 500 !important;
}
.bn-spc-result-banner button.bn-spc-action-primary:hover { background: #444 !important; }
.bn-spc-result-banner button.bn-spc-action-secondary {
    background: #fff !important; color: #1a1a1a !important;
    border: 1px solid #1a1a1a !important; padding: 8px 16px !important;
    font-size: 12px !important; cursor: pointer !important;
    text-transform: uppercase !important; letter-spacing: .06em !important;
    border-radius: 0 !important; font-weight: 500 !important;
}
.bn-spc-result-banner button.bn-spc-action-secondary:hover { background: #1a1a1a !important; color: #fff !important; }
.bn-spc-result-banner button.bn-spc-action-primary:disabled,
.bn-spc-result-banner button.bn-spc-action-secondary:disabled { opacity: .5; cursor: default; }
@media (max-width: 720px) {
    .bn-spc-result-banner { gap: 6px !important; padding: 8px 10px !important; }
    .bn-spc-result-banner > div:first-child { font-size: 12px !important; line-height: 1.2 !important; margin-bottom: 2px !important; }
    /* Контейнер кнопок — обе в строку, делят ширину пополам, не переносятся */
    .bn-spc-result-banner > div:nth-child(2) {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 6px !important;
        width: 100% !important;
    }
    .bn-spc-result-banner button.bn-spc-action-primary,
    .bn-spc-result-banner button.bn-spc-action-secondary {
        flex: 1 1 0 !important;
        min-width: 0 !important;
        font-size: 11px !important;
        padding: 10px 8px !important;
        letter-spacing: .04em !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
}

/* BN-038 mobile: sticky banner снизу модалки + скрываем чат-виджет когда открыта модалка */
body.bn-spc-locked .b24-widget-button-wrapper,
body.bn-spc-locked .bx-livechat-wrapper,
body.bn-spc-locked .jivo-iframe-container,
body.bn-spc-locked #jivo-iframe-container,
body.bn-spc-locked [class*='livechat'],
body.bn-spc-locked [class*='jivo'] { display: none !important; }

.bn-spc-modal { position: relative; }
.bn-spc-modal .bn-spc-result-banner {
    position: sticky !important;
    bottom: 0 !important;
    z-index: 10 !important;
    margin: 0 !important;
    box-shadow: 0 -4px 12px rgba(0,0,0,.08) !important;
}
@media (max-width: 720px) {
    .bn-spc-modal .bn-spc-result-banner {
        padding: 12px 12px calc(env(safe-area-inset-bottom, 0px) + 12px) !important;
        /* небольшой запас сверху, чтобы тап не попадал в gesture-зону */
        margin-bottom: env(safe-area-inset-bottom, 0px) !important;
    }
    /* Поднимем сам баннер на чуть выше нижнего края экрана */
    .bn-spc-modal {
        padding-bottom: max(20px, env(safe-area-inset-bottom, 20px)) !important;
    }
    .bn-spc-result-banner > div:first-child { font-size: 13px !important; line-height: 1.3 !important; }
    .bn-spc-result-banner button.bn-spc-action-primary,
    .bn-spc-result-banner button.bn-spc-action-secondary { padding: 11px 14px !important; font-size: 12px !important; }
}
