.custom-form-wrap,
.popup .content {
  position: relative;
}

.btl-form-loading-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.74);
  backdrop-filter: blur(2px);
  z-index: 50;
  border-radius: inherit;
}

.btl-form-is-loading .btl-form-loading-overlay {
  display: flex;
}

.btl-form-loading-box {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.14);
  font-size: 15px;
  line-height: 1.35;
  color: #00568D;
  text-align: center;
}

.btl-form-spinner {
  width: 22px;
  height: 22px;
  border: 3px solid rgba(0, 155, 217, 0.25);
  border-top-color: #009bd9;
  border-radius: 50%;
  animation: btlFormSpin 0.75s linear infinite;
  flex: 0 0 auto;
}

.btl-form-loading-text {
  font-weight: 500;
  color: #00568D;
}

form[id^="btl-custom-form-"] button[type="submit"].is-loading {
  opacity: 0.75;
  pointer-events: none;
}

.btl-form-loading-error {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fff3f3;
  color: #9b1c1c;
  font-size: 14px;
  line-height: 1.35;
}

@keyframes btlFormSpin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 767px) {
  html.btl-form-popup-open,
  body.btl-form-popup-open {
    overflow: hidden !important;
    overscroll-behavior: none;
  }

  body.btl-form-submit-loading {
    overflow: hidden;
  }

  /*
   * Глобальная белая подложка под popup.
   * Она не дает странице просвечивать снизу/сверху при глюках mobile viewport.
   */
  body.btl-form-popup-open::before {
    content: "";
    position: fixed;
    top: -120px;
    right: 0;
    bottom: -320px;
    left: 0;
    z-index: 999998;
    background: #fff;
    pointer-events: none;
  }

  body.btl-form-popup-open .cky-btn-revisit-wrapper,
  body.btl-form-popup-open .cky-revisit-bottom-left,
  body.btl-form-popup-open .cky-revisit-bottom-right,
  body.btl-form-popup-open .cookie-control,
  body.btl-form-popup-open .cookieControl,
  body.btl-form-popup-open #cookie-law-info-again,
  body.btl-form-popup-open .cli_settings_button {
    display: none !important;
  }

  /*
   * Popup всегда остается полноэкранным.
   * Нельзя уменьшать его до visualViewport.height, иначе снова появляется кусок страницы.
   */
  body .popup[id^="button-popup-"] {
    position: fixed !important;
    inset: 0 !important;

    width: 100% !important;
    max-width: none !important;

    height: 100vh !important;
    height: 100dvh !important;
    height: 100lvh !important;
    height: var(--btl-form-cover-height, 100lvh) !important;

    min-height: 100vh !important;
    min-height: 100dvh !important;
    min-height: 100lvh !important;

    max-height: none !important;

    align-items: stretch;
    justify-content: stretch;
    padding: 0;

    overflow: hidden !important;
    background: #fff !important;
    z-index: 999999 !important;
  }

  /*
   * .box тоже остается полной высоты.
   * Если нижняя панель браузера видна, JS добавляет нижний запас
   * через --btl-form-bottom-ui-gap, чтобы кнопка не уходила под панель.
   */
  body .popup[id^="button-popup-"] .box {
    position: relative;
    z-index: 1;

    width: 100% !important;
    max-width: none !important;

    height: 100vh !important;
    height: 100dvh !important;
    height: 100lvh !important;
    height: var(--btl-form-cover-height, 100lvh) !important;

    min-height: 0 !important;
    max-height: none !important;

    margin: 0;
    padding: 52px 18px calc(24px + env(safe-area-inset-bottom) + var(--btl-form-bottom-ui-gap, 0px));

    border-radius: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;

    scroll-padding-top: 80px;
    scroll-padding-bottom: calc(16px + var(--btl-form-bottom-ui-gap, 0px));

    background: #fff !important;
  }

  /*
   * При открытой клавиатуре не добавляем большой нижний запас:
   * активное поле поднимает JS, а лишняя белая область над клавиатурой не нужна.
   */
  html.btl-form-keyboard-open body .popup[id^="button-popup-"] .box {
    padding-bottom: 6px;
    scroll-padding-bottom: 6px;
  }

  body .popup[id^="button-popup-"] .content,
  body .popup[id^="button-popup-"] .custom-form-wrap,
  body .popup[id^="button-popup-"] form[id^="btl-custom-form-"] {
    width: 100%;
    max-width: 100%;
  }

  body .popup[id^="button-popup-"] .box .close {
    width: 44px !important;
    height: 44px !important;
    top: 6px !important;
    right: 6px !important;
    display: block !important;
    z-index: 20;
  }

  body .popup[id^="button-popup-"] .box .close::before,
  body .popup[id^="button-popup-"] .box .close::after {
    top: 50% !important;
    left: 50% !important;
    right: auto !important;

    width: 22px !important;
    height: 2px !important;
    margin: 0 !important;

    transform-origin: center center !important;
    background-color: #b8b8b8 !important;
  }

  body .popup[id^="button-popup-"] .box .close::before {
    transform: translate(-50%, -50%) rotate(45deg) !important;
  }

  body .popup[id^="button-popup-"] .box .close::after {
    transform: translate(-50%, -50%) rotate(135deg) !important;
  }

  body form[id^="btl-custom-form-"] .row {
    display: block;
    margin-left: 0;
    margin-right: 0;
  }

  body form[id^="btl-custom-form-"] .label-wrapper,
  body form[id^="btl-custom-form-"] .col,
  body form[id^="btl-custom-form-"] [class*="col-"] {
    width: 100%;
    max-width: 100%;
    flex: 0 0 100%;
    padding-left: 0;
    padding-right: 0;
  }

  body form[id^="btl-custom-form-"] .input {
    margin-bottom: 14px;
  }

  body form[id^="btl-custom-form-"] .input.textarea,
  body .popup[id^="button-popup-"] form[id^="btl-custom-form-"] .input:has(.select2-container) {
    margin-bottom: 16px;
  }

  body form[id^="btl-custom-form-"] label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    line-height: 1.3;
  }

 body form[id^="btl-custom-form-"] input[type="text"],
body form[id^="btl-custom-form-"] input[type="email"],
body form[id^="btl-custom-form-"] input[type="tel"],
body form[id^="btl-custom-form-"] input[type="search"],
body form[id^="btl-custom-form-"] input[type="url"],
body form[id^="btl-custom-form-"] input[type="number"],
body form[id^="btl-custom-form-"] select {
  width: 100% !important;

  height: 48px !important;
  min-height: 48px !important;
  max-height: 48px !important;

  padding-top: 0 !important;
  padding-bottom: 0 !important;

  font-size: 16px !important;
  line-height: 48px !important;

  box-sizing: border-box !important;

  scroll-margin-top: 80px;
  scroll-margin-bottom: 16px;

  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body form[id^="btl-custom-form-"] textarea {
  width: 100% !important;

  min-height: 110px !important;
  height: auto !important;
  max-height: none !important;

  padding-top: 12px !important;
  padding-bottom: 12px !important;

  font-size: 16px !important;
  line-height: 1.45 !important;

  box-sizing: border-box !important;
  resize: vertical;

  scroll-margin-top: 80px;
  scroll-margin-bottom: 16px;

  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body form[id^="btl-custom-form-"] .iti input[type="tel"] {
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  line-height: 48px !important;
}

  body form[id^="btl-custom-form-"] textarea {
    min-height: 110px;
    resize: vertical;
  }

  body form[id^="btl-custom-form-"] input::placeholder,
  body form[id^="btl-custom-form-"] textarea::placeholder {
    color: rgba(0, 86, 141, 0.42) !important;
    opacity: 1;
  }

  body form[id^="btl-custom-form-"] .btl-form-validation-hint {
    margin-top: 6px;
    color: #9b1c1c;
    font-size: 13px;
    line-height: 1.35;
  }

  body form[id^="btl-custom-form-"] .btl-form-has-validation-error input[type="text"],
  body form[id^="btl-custom-form-"] .btl-form-has-validation-error input[type="email"],
  body form[id^="btl-custom-form-"] .btl-form-has-validation-error input[type="tel"],
  body form[id^="btl-custom-form-"] .btl-form-has-validation-error input[type="search"],
  body form[id^="btl-custom-form-"] .btl-form-has-validation-error input[type="url"],
  body form[id^="btl-custom-form-"] .btl-form-has-validation-error input[type="number"],
  body form[id^="btl-custom-form-"] .btl-form-has-validation-error textarea,
  body form[id^="btl-custom-form-"] .btl-form-has-validation-error select {
    border-color: rgba(155, 28, 28, 0.55) !important;
  }

  body form[id^="btl-custom-form-"] .btl-form-has-validation-error .select2-selection--single,
  body form[id^="btl-custom-form-"] .btl-form-has-validation-error .select2-selection--multiple {
    border-color: rgba(155, 28, 28, 0.55) !important;
  }

  body form[id^="btl-custom-form-"] .relative,
  body form[id^="btl-custom-form-"] .iti {
    width: 100% !important;
    max-width: 100%;
  }

  body .popup[id^="button-popup-"] form[id^="btl-custom-form-"] .input .select2-container,
  body .popup[id^="button-popup-"] form[id^="btl-custom-form-"] .input .select2.select2-container--default,
  body .popup[id^="button-popup-"] form[id^="btl-custom-form-"] .input .select2.select2-container--effecto {
    width: 100% !important;
    height: 50px !important;
    min-height: 50px !important;
    max-height: none !important;
    display: block !important;
    overflow: visible !important;
    box-sizing: border-box !important;
  }

  body .popup[id^="button-popup-"] form[id^="btl-custom-form-"] .input .select2-container .selection {
    display: block !important;
    width: 100% !important;
    height: 50px !important;
    min-height: 50px !important;
    overflow: visible !important;
    box-sizing: border-box !important;
  }

  body .popup[id^="button-popup-"] form[id^="btl-custom-form-"] .input .select2-container .select2-selection--single,
  body .popup[id^="button-popup-"] form[id^="btl-custom-form-"] .input .select2-container .select2-selection--multiple {
    width: 100% !important;
    height: 50px !important;
    min-height: 50px !important;

    display: flex !important;
    align-items: center !important;

    overflow: visible !important;
    box-sizing: border-box !important;

    background: #fff !important;
    border: 1px solid rgba(0, 86, 141, 0.14) !important;
    border-radius: 4px !important;
  }

  body .popup[id^="button-popup-"] form[id^="btl-custom-form-"] .input .select2-container .select2-selection--single .select2-selection__rendered,
  body .popup[id^="button-popup-"] form[id^="btl-custom-form-"] .input .select2-container .select2-selection--multiple .select2-selection__rendered {
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    line-height: 1.35 !important;

    padding-top: 0 !important;
    padding-bottom: 0 !important;
    padding-left: 14px !important;
    padding-right: 40px !important;

    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    box-sizing: border-box !important;
    background: transparent !important;

    color: rgba(0, 86, 141, 0.52);
    font-size: 16px;
  }

  body form[id^="btl-custom-form-"] .select2-container .select2-selection__placeholder {
    color: rgba(0, 86, 141, 0.42) !important;
  }

  body form[id^="btl-custom-form-"] .select2-container .select2-selection__rendered i {
    color: #00568D;
  }

  body .popup[id^="button-popup-"] form[id^="btl-custom-form-"] .input .select2-container .select2-selection--single .select2-selection__arrow,
  body .popup[id^="button-popup-"] form[id^="btl-custom-form-"] .input .select2-container .select2-selection--multiple .select2-selection__arrow {
    position: absolute !important;
    top: 0 !important;
    right: 8px !important;

    width: 28px !important;
    height: 50px !important;
    min-height: 50px !important;

    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  body .popup[id^="button-popup-"] form[id^="btl-custom-form-"] .input .select2-container .select2-selection__arrow b {
    position: static !important;
    margin: 0 !important;
  }

  body form[id^="btl-custom-form-"] input[type="checkbox"] + label {
    min-height: 44px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 0;
    cursor: pointer;
  }

  body form[id^="btl-custom-form-"] input[type="checkbox"] + label i {
    flex: 0 0 auto;
  }

  body form[id^="btl-custom-form-"] .agree-text {
    display: block;
    font-size: 13px;
    line-height: 1.35;
  }

  body form[id^="btl-custom-form-"] .submit {
    width: 100%;
    margin-top: 18px;
    margin-bottom: var(--btl-form-bottom-ui-gap, 0px);
  }

  body form[id^="btl-custom-form-"] .submit .btn,
  body form[id^="btl-custom-form-"] button[type="submit"],
  body form[id^="btl-custom-form-"] input[type="submit"] {
    width: 100%;
    min-height: 48px;

    display: flex !important;
    align-items: center;
    justify-content: center;

    padding-left: 16px !important;
    padding-right: 16px !important;

    box-sizing: border-box;
    text-align: center !important;
    font-size: 16px;
  }

  .btl-form-loading-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000000;
    padding: 20px;
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: blur(2px);
    border-radius: 0;
  }

  .btl-form-is-loading .btl-form-loading-overlay {
    display: flex;
  }

  .btl-form-loading-box {
    position: fixed;
    left: 50%;
    top: 50%;
    z-index: 1000001;
    transform: translate(-50%, -50%);

    width: calc(100vw - 32px);
    max-width: 360px;
    min-width: 280px;
    padding: 18px 20px;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;

    text-align: center;
    font-size: 14px;
  }

  .btl-form-spinner {
    margin: 0 auto;
  }

  .btl-form-loading-text {
    display: block;
    width: 100%;
    text-align: center;
    color: #00568D;
    font-weight: 500;
    line-height: 1.35;
  }

    /*
   * Благодарственное окно после успешной отправки формы:
   * затемняющий overlay + компактная карточка по центру.
   * Основную форму, поля, Select2, клавиатуру и viewport-логику не затрагивает.
   */
  body .btl-form-thanks-screen {
    position: fixed !important;
    inset: 0 !important;

    width: 100% !important;
    min-height: 100vh !important;
    min-height: 100dvh !important;
    min-height: 100lvh !important;

    z-index: 1000002 !important;

    display: flex !important;
    align-items: center !important;
    justify-content: center !important;

    padding: 24px;
    box-sizing: border-box;

    background: rgba(0, 13, 49, 0.5) !important;

    cursor: pointer;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
  }

  body .btl-form-thanks-card {
    position: relative;

    width: 100%;
    max-width: 430px;
    min-height: 180px;

    padding: 56px 28px 34px;
    box-sizing: border-box;

    display: flex;
    align-items: center;
    justify-content: center;

    background: #fff !important;
    color: #00568D;
    text-align: center;

    cursor: pointer;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.18);
  }

  body .btl-form-thanks-screen__close {
    position: absolute !important;
    top: 6px !important;
    right: 6px !important;

    width: 44px !important;
    height: 44px !important;

    display: block !important;
    z-index: 3;

    padding: 0 !important;
    margin: 0 !important;

    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;

    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -webkit-tap-highlight-color: transparent;
  }

  body .btl-form-thanks-screen__close::before,
  body .btl-form-thanks-screen__close::after {
    content: "";
    position: absolute !important;

    top: 50% !important;
    left: 50% !important;

    width: 22px !important;
    height: 2px !important;

    margin: 0 !important;
    background-color: #b8b8b8 !important;

    transform-origin: center center !important;
  }

  body .btl-form-thanks-screen__close::before {
    transform: translate(-50%, -50%) rotate(45deg) !important;
  }

  body .btl-form-thanks-screen__close::after {
    transform: translate(-50%, -50%) rotate(135deg) !important;
  }

  body .btl-form-thanks-screen__content {
    width: 100%;
    max-width: 360px;
    margin: 0 auto;

    color: #00568D;
    text-align: center;
    line-height: 1.4;
  }

  body .btl-form-thanks-screen__content h1,
  body .btl-form-thanks-screen__content h2,
  body .btl-form-thanks-screen__content h3 {
    margin: 0 0 12px;
    color: #00568D;
    font-size: 24px;
    line-height: 1.25;
    font-weight: 700;
    text-align: center;
  }

  body .btl-form-thanks-screen__content p {
    margin: 0;
    color: #00568D;
    font-size: 16px;
    line-height: 1.45;
    text-align: center;
  }
  
    /*
   * На благодарственном окне отключаем белую защитную подложку формы,
   * чтобы за затемненным overlay была видна страница.
   * На саму форму это не влияет.
   */
  body.btl-form-popup-open.btl-form-thanks-open::before {
    display: none !important;
  }

  /*
   * Полупрозрачный overlay благодарственного окна.
   * Чем меньше последнее число, тем сильнее видна страница.
   */
  body .btl-form-thanks-screen {
    background: rgba(0, 13, 49, 0.42) !important;
  }
}