/*
 * Новый дизайн всплывающих окон. Слой поверх прежних стилей: всё под
 * html.kb-modals-v2, разметку окон не меняем. Выключается в админке
 * («Оформление сайта → Модальные окна») — тогда этот файл не подключается.
 *
 * Размеры: S 400 — подтверждения, M 480 — формы (по умолчанию), L 640 — списки.
 * На телефоне короткие окна — шторка снизу, длинные — на весь экран.
 */

html.kb-modals-v2 {
    --kbm-ink: #051A32;
    --kbm-dim: #5D6A75;
    --kbm-line: #C9D1D6;
    --kbm-soft: #F1F3F4;
    --kbm-acc: #0DB8A5;
    --kbm-mint: #79EBDC;
    --kbm-keyboard: 0px;
    --kbm-shift: 0px;
}

/* ---------- затемнение и появление ---------- */

html.kb-modals-v2 .wide-modal {
    z-index: 100000;
    height: 100vh;
    height: 100dvh;
    padding: 24px;
    box-sizing: border-box;
}

html.kb-modals-v2 .wide-modal.modal-overlay {
    background-color: rgba(5, 26, 50, .55);
}

html.kb-modals-v2 .wide-modal.visible {
    animation: kbm-fade .18s ease-out;
}

html.kb-modals-v2 .wide-modal.visible .wide-modal__container {
    animation: kbm-pop .2s ease-out;
}

@keyframes kbm-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes kbm-pop {
    from { opacity: 0; transform: translateY(8px) scale(.98); }
    to { opacity: 1; transform: none; }
}

/* ---------- окно ---------- */

html.kb-modals-v2 .wide-modal:where(:not(.maps-modal):not(.gallery-modal)) .wide-modal__container {
    max-width: 480px;
    width: 100%;
    box-sizing: border-box;
    margin: 0;
    top: auto;
    padding: 28px 32px 32px;
    border-radius: 20px;
    box-shadow: 0 24px 64px rgba(5, 26, 50, .28);
    max-height: calc(100dvh - 48px);
    overflow: auto;
    overscroll-behavior: contain;
}

html.kb-modals-v2 .wide-modal__container:focus {
    outline: none;
}

/* S — подтверждения и короткие сообщения */
html.kb-modals-v2 .wide-modal.content-modal .wide-modal__container,
html.kb-modals-v2 .wide-modal[data-modal="check-city"] .wide-modal__container,
html.kb-modals-v2 .wide-modal[data-modal="no-delivery"] .wide-modal__container,
html.kb-modals-v2 .wide-modal[data-modal="one-store"] .wide-modal__container,
html.kb-modals-v2 .wide-modal[data-modal="unsubscribe"] .wide-modal__container {
    max-width: 400px;
}

/* L — списки с поиском и длинные формы */
html.kb-modals-v2 .wide-modal[data-modal="geolocation"] .wide-modal__container,
html.kb-modals-v2 .wide-modal[data-modal="find"] .wide-modal__container {
    max-width: 640px;
}

/* ---------- шапка: заголовок и крестик ---------- */

html.kb-modals-v2 .wide-modal .wide-modal__btn-close {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin: -8px -12px -32px auto;
    border-radius: 12px;
    background-color: var(--kbm-soft);
    opacity: 1;
}

html.kb-modals-v2 .wide-modal .wide-modal__btn-close:hover {
    background-color: #E2E6E9;
    opacity: 1;
}

html.kb-modals-v2 .wide-modal .wide-modal__btn-close:focus-visible {
    outline: 3px solid rgba(13, 184, 165, .35);
}

html.kb-modals-v2 .wide-modal .wide-modal__btn-close-icon {
    display: none;
}

html.kb-modals-v2 .wide-modal .kbm-close-icon {
    display: block;
    width: 18px;
    height: 18px;
}

html.kb-modals-v2 .wide-modal .wide-modal__title {
    margin: 0 52px 18px 0;
    font-size: 24px;
    line-height: 1.25;
    font-weight: 700;
    text-align: left;
    color: var(--kbm-ink);
}

html.kb-modals-v2 .wide-modal .wide-body {
    padding: 0;
    text-align: left;
}

/* подзаголовки и пояснения в окнах были по центру — выравниваем по заголовку */
html.kb-modals-v2 .wide-modal .wide-body p,
html.kb-modals-v2 .wide-modal .wide-body :is([class*="title"], [class*="subtitle"], [class*="__text"], [class*="__desc"]):not(.btn):not(button) {
    text-align: left;
}

/* ---------- поля и кнопки ---------- */

/* внутренние обёртки форм были ужаты до 252 px — растягиваем на всю ширину окна */
html.kb-modals-v2 .wide-modal .wide-body [class*="__container"],
html.kb-modals-v2 .wide-modal .wide-body [class*="__form"],
html.kb-modals-v2 .wide-modal .wide-body [class*="__search"],
html.kb-modals-v2 .wide-modal .wide-body .auth-tabs,
html.kb-modals-v2 .wide-modal .wide-body .forms-tabs,
html.kb-modals-v2 .wide-modal .wide-body .js-form {
    max-width: none;
    width: 100%;
}

html.kb-modals-v2 .wide-modal .field-label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 400;
    color: var(--kbm-dim);
}

html.kb-modals-v2 .wide-modal .field-input {
    width: 100%;
    height: 52px;
    box-sizing: border-box;
    padding: 0 16px;
    border: 1.5px solid var(--kbm-line);
    border-radius: 12px;
    font-size: 17px;
    color: var(--kbm-ink);
}

html.kb-modals-v2 .wide-modal textarea.field-input {
    height: auto;
    min-height: 104px;
    padding: 14px 16px;
}

html.kb-modals-v2 .wide-modal .field-input:focus {
    border-color: var(--kbm-acc);
    outline: 3px solid rgba(13, 184, 165, .16);
}

html.kb-modals-v2 .wide-modal .field-input::placeholder {
    color: #8A96A0;
}

html.kb-modals-v2 .wide-modal .btn.btn-primary {
    width: 100%;
    height: 52px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
}

html.kb-modals-v2 .wide-modal .btn.btn-primary:disabled,
html.kb-modals-v2 .wide-modal .btn.btn-primary[disabled] {
    opacity: .5;
}

/* Частное лицо / Компания — переключатель-сегмент вместо двух таблеток */
html.kb-modals-v2 .wide-modal .auth-tabs .tabs,
html.kb-modals-v2 .wide-modal .forms-tabs .tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    margin: 0 0 20px;
    padding: 4px;
    border-radius: 12px;
    background: var(--kbm-soft);
}

html.kb-modals-v2 .wide-modal .auth-tabs .tabs-primary,
html.kb-modals-v2 .wide-modal .forms-tabs .tabs-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    /* старые стили регистрации задают вкладке ширину 84,5px — «Частное лицо» переносилось */
    width: auto;
    min-width: 0;
    height: 40px;
    margin: 0;
    padding: 0 8px;
    border: 0;
    border-radius: 9px;
    white-space: nowrap;
    background: transparent;
    font-size: 15px;
    font-weight: 400;
    color: var(--kbm-dim);
}

/* выбранная вкладка — только .active: tabs-js-trigger-active сборка не снимает,
   это метка «открыть при загрузке», и с ней подсвечивались обе */
html.kb-modals-v2 .wide-modal .auth-tabs .tabs-primary.active,
html.kb-modals-v2 .wide-modal .forms-tabs .tabs-primary.active {
    background: #fff;
    color: var(--kbm-ink);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(5, 26, 50, .12);
}

/* ---------- подтверждения «Спасибо» ---------- */

html.kb-modals-v2 .wide-modal.content-modal .wide-body {
    padding: 0;
    text-align: left;
}

html.kb-modals-v2 .wide-modal.content-modal .wide-body::before {
    content: "";
    display: block;
    width: 56px;
    height: 56px;
    margin-bottom: 16px;
    border-radius: 16px;
    background: #E9FBF8 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 24 24' fill='none' stroke='%23077668' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12l5 5 9-10'/%3E%3C/svg%3E") center / 28px no-repeat;
}

html.kb-modals-v2 .wide-modal.content-modal .wide-body > div {
    max-width: none;
    margin-left: 0;
    margin-right: 0;
    text-align: left;
}

html.kb-modals-v2 .wide-modal.content-modal .wide-body p {
    margin: 0 0 6px;
    font-size: 15px;
    line-height: 1.5;
    color: var(--kbm-dim);
    text-align: left;
}

html.kb-modals-v2 .wide-modal.content-modal .wide-body p:first-child {
    font-size: 20px;
    line-height: 1.3;
    font-weight: 700;
    color: var(--kbm-ink);
}

html.kb-modals-v2 .kbm-ok {
    width: 100%;
    height: 48px;
    margin-top: 18px;
    border: 0;
    border-radius: 12px;
    background: var(--kbm-mint);
    color: #04302B;
    font: inherit;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
}

html.kb-modals-v2 .kbm-ok:hover {
    background: #63E0CF;
}

/* ---------- выбор города ---------- */

html.kb-modals-v2 .wide-modal[data-modal="geolocation"] .geolocation-container__search input {
    width: 100%;
    height: 48px;
    box-sizing: border-box;
    padding: 0 14px 0 42px;
    border: 0;
    border-radius: 12px;
    background: var(--kbm-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%235D6A75' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-3.5-3.5'/%3E%3C/svg%3E") 14px center / 18px no-repeat;
    font-size: 16px;
    color: var(--kbm-ink);
}

html.kb-modals-v2 .wide-modal[data-modal="geolocation"] .geolocation-container {
    align-items: stretch;
}

html.kb-modals-v2 .wide-modal[data-modal="geolocation"] .geolocation-container__lists {
    margin-bottom: 20px;
}

html.kb-modals-v2 .wide-modal[data-modal="geolocation"] .geolocation-container__list,
html.kb-modals-v2 .wide-modal[data-modal="geolocation"] .geolocation-container__btn {
    max-width: none;
    width: 100%;
    margin-left: 0;
    margin-right: 0;
}

/* строки выше — удобнее попадать пальцем; кружок радиокнопки едет вместе с подписью */
html.kb-modals-v2 .wide-modal[data-modal="geolocation"] .geolocation-container__list .field-radio,
html.kb-modals-v2 .kbm-main-city .field-radio {
    padding: 7px 0;
}

html.kb-modals-v2 .wide-modal[data-modal="geolocation"] .field-radio__label {
    font-size: 16px;
}

/* список был низким — на ПК видно было три города */
html.kb-modals-v2 .wide-modal[data-modal="geolocation"] .geolocation-container__lists {
    height: auto;
    max-height: min(440px, calc(100dvh - 300px));
    overflow: auto;
}

@media (max-width: 767px) {
    html.kb-modals-v2 .wide-modal[data-modal="geolocation"] .geolocation-container__lists {
        max-height: calc(100dvh - 250px);
    }
}

html.kb-modals-v2 .wide-modal[data-modal="geolocation"] [data-location-submit] {
    width: 100%;
    height: 52px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
}

html.kb-modals-v2 .kbm-group {
    margin: 14px 4px 6px;
    font-size: 13px;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--kbm-dim);
}

html.kb-modals-v2 .kbm-main-city .field-radio__label {
    font-weight: 600;
}

/* ---------- телефон ---------- */

@media (max-width: 767px) {
    html.kb-modals-v2 .wide-modal {
        padding: 0;
        align-items: flex-end;
    }

    /* короткие окна — шторка снизу. При открытой клавиатуре шторка остаётся
       у нижнего края, а содержимое поднимается отступом на высоту клавиатуры:
       так под прозрачной адресной строкой iPhone (iOS 26) и под клавиатурой
       белый фон шторки, а не страница */
    html.kb-modals-v2 .wide-modal:where(:not(.maps-modal):not(.gallery-modal)) .wide-modal__container {
        max-width: none;
        width: 100%;
        margin: 0;
        padding: 10px 20px calc(24px + env(safe-area-inset-bottom) + var(--kbm-keyboard));
        border-radius: 24px 24px 0 0;
        box-shadow: 0 -8px 32px rgba(5, 26, 50, .18);
        /* --kbm-shift — на сколько iPhone сдвинул видимую часть страницы к полю */
        max-height: calc(100dvh - 32px - var(--kbm-shift));
    }

    html.kb-modals-v2 .wide-modal.visible:where(:not(.maps-modal):not(.gallery-modal)) .wide-modal__container {
        animation: kbm-sheet .22s ease-out;
    }

    @keyframes kbm-sheet {
        from { transform: translateY(40px); opacity: .6; }
        to { transform: none; opacity: 1; }
    }

    /* ручка шторки */
    html.kb-modals-v2 .wide-modal:where(:not(.maps-modal):not(.gallery-modal)) .wide-modal__container::before {
        content: "";
        display: block;
        width: 40px;
        height: 5px;
        margin: 0 auto 12px;
        border-radius: 3px;
        background: var(--kbm-line);
    }

    html.kb-modals-v2 .wide-modal .wide-modal__btn-close {
        width: 44px;
        height: 44px;
        margin: -4px -6px -40px auto;
    }

    html.kb-modals-v2 .wide-modal .wide-modal__title {
        margin-right: 52px;
        font-size: 22px;
    }

    /* длинные формы и списки — на весь экран. Регистрация — шторкой, как вход: у частного лица
       там телефон и капча, на весь экран оставалась пустота; форма компании прокручивается в шторке */
    html.kb-modals-v2 .wide-modal[data-modal="geolocation"] .wide-modal__container,
    html.kb-modals-v2 .wide-modal[data-modal="find"] .wide-modal__container,
    html.kb-modals-v2 .wide-modal[data-modal="contact-us"] .wide-modal__container,
    html.kb-modals-v2 .wide-modal[data-modal="profile"] .wide-modal__container {
        height: 100dvh;
        max-height: none;
        border-radius: 0;
        padding-top: 16px;
        /* под клавиатурой — запас, чтобы кнопку внизу можно было докрутить */
        padding-bottom: calc(24px + env(safe-area-inset-bottom) + var(--kbm-keyboard));
        transform: none;
        animation: none;
    }

    /* кнопка чата Jivo висит поверх окна и закрывает «Войти» и капчу */
    html.kb-modals-v2.kbm-open jdiv,
    html.kb-modals-v2.kbm-open #jivo-iframe-container {
        display: none !important;
    }

    html.kb-modals-v2 .wide-modal[data-modal="geolocation"] .wide-modal__container::before,
    html.kb-modals-v2 .wide-modal[data-modal="find"] .wide-modal__container::before,
    html.kb-modals-v2 .wide-modal[data-modal="contact-us"] .wide-modal__container::before,
    html.kb-modals-v2 .wide-modal[data-modal="profile"] .wide-modal__container::before {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    html.kb-modals-v2 .wide-modal.visible,
    html.kb-modals-v2 .wide-modal.visible .wide-modal__container {
        animation: none !important;
    }
}
