/* Модальная заявка.
   ---------------------------------------------------------------------------
   Открывается через showModal(): браузер сам кладёт окно в top layer,
   запирает фокус внутри и обрабатывает Esc. closedby="any" добавляет закрытие
   по клику вне окна и по жесту «назад» на телефоне — там, где поддерживается;
   в Safari это тихо деградирует до Esc и крестика, и ничего чинить не надо.

   Ошибки показываются по :user-invalid, а не по :invalid. Разница видна сразу:
   :invalid красит пустое обязательное поле, едва человек открыл форму, то есть
   ругается до того, как что-то произошло. :user-invalid ждёт, пока человек уйдёт
   из поля или нажмёт «отправить». */

.vp-modal {
  --vp-r: 16px;
  width: min(460px, calc(100vw - 24px));
  max-height: min(92dvh, 880px);
  padding: 0;
  border: 0;
  border-radius: var(--vp-r);
  background: #fff;
  color: #14171a;
  box-shadow: 0 24px 64px rgba(10, 20, 30, .28), 0 2px 8px rgba(10, 20, 30, .12);

  overflow: hidden;
}

/* Колонка с overflow:hidden — иначе max-height не обрезает содержимое и длинная
   форма уезжает за нижний край экрана вместо того, чтобы прокручиваться внутри
   окна.

   display задаётся ТОЛЬКО открытому окну. Браузер прячет закрытый <dialog>
   правилом dialog:not([open]) { display: none } из своей таблицы стилей, и
   безусловный display:flex его перебивал: форма заявки висела раскрытой на
   каждой странице. */
.vp-modal[open] {
  display: flex;
  flex-direction: column;
}

.vp-modal::backdrop {
  background: rgba(12, 18, 24, .55);
  backdrop-filter: blur(3px);
}

/* Появление. prefers-reduced-motion уважаем: анимация здесь украшение,
   а не способ что-то объяснить. */
@media (prefers-reduced-motion: no-preference) {
  .vp-modal[open] { animation: vp-pop .18s cubic-bezier(.2, .8, .3, 1); }
  .vp-modal[open]::backdrop { animation: vp-fade .18s ease-out; }
}
@keyframes vp-pop  { from { opacity: 0; transform: translateY(10px) scale(.985); } }
@keyframes vp-fade { from { opacity: 0; } }

.vp-modal__body {
  padding: 26px 24px 22px;
  min-height: 0;              /* без этого flex-элемент не сжимается и не скроллит */
  overflow-y: auto;
  overscroll-behavior: contain;
}

.vp-modal__x {
  position: absolute;
  top: 10px; right: 10px;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 0; border-radius: 999px;
  background: rgba(255, 255, 255, .9);
  color: #55606a;
  cursor: pointer;
  z-index: 2;
}
.vp-modal__x svg { width: 18px; height: 18px; }
.vp-modal__x:hover { background: #eef1f4; color: #14171a; }
.vp-modal__x:focus-visible { outline: 2px solid #1F7A4D; outline-offset: 2px; }

.vp-modal__eyebrow {
  margin: 0 0 6px;
  font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: #1F7A4D;
}
.vp-modal h2 { margin: 0 0 8px; font-size: 22px; line-height: 1.22; letter-spacing: -.01em; }
.vp-modal__hint { margin: 0 0 16px; color: #55606a; font-size: 14px; line-height: 1.5; }

.vp-modal__usp {
  margin: 0 0 18px; padding: 12px 14px;
  list-style: none;
  background: #f4f7f5; border-radius: 10px;
  font-size: 13.5px; color: #2c3540;
}
.vp-modal__usp li { position: relative; padding-left: 22px; margin: 5px 0; }
.vp-modal__usp li::before {
  content: ""; position: absolute; left: 2px; top: .45em;
  width: 10px; height: 6px;
  border-left: 2px solid #1F7A4D; border-bottom: 2px solid #1F7A4D;
  transform: rotate(-45deg);
}

/* ---------- поля ---------- */

.vp-field { margin-bottom: 13px; }

.vp-field label {
  display: block; margin-bottom: 5px;
  font-size: 13.5px; font-weight: 600; color: #2c3540;
}
.vp-field .req { color: #B91C1C; }

/* Подсказка стоит НАД полем: на телефоне всплывающая клавиатура и подсказки
   автозаполнения закрывают всё, что ниже. */
.vp-hint {
  display: block; margin: -2px 0 5px;
  font-size: 12.5px; color: #6b7680;
}

.vp-field input,
.vp-field select,
.vp-field textarea {
  width: 100%;
  box-sizing: border-box;     /* тема ставит это глобально, но форма не должна от этого зависеть */
  padding: 11px 13px;
  font: inherit; font-size: 16px;   /* 16px — иначе iOS зумит страницу при фокусе */
  color: #14171a;
  background: #fff;
  border: 1.5px solid #d6dde3;
  border-radius: 10px;
  transition: border-color .15s, box-shadow .15s;
}
.vp-field textarea { resize: vertical; min-height: 76px; }

.vp-field input:focus-visible,
.vp-field select:focus-visible,
.vp-field textarea:focus-visible {
  outline: 0;
  border-color: #1F7A4D;
  box-shadow: 0 0 0 3px rgba(31, 122, 77, .16);
}

/* Ошибка — только после того, как человек ушёл из поля или нажал «отправить».
   Цвет не единственный признак: есть рамка, фон и текст под полем. */
.vp-field input:user-invalid,
.vp-field textarea:user-invalid {
  border-color: #B91C1C;
  background: #fef4f3;
}
.vp-field input:user-valid,
.vp-field textarea:user-valid { border-color: #1F7A4D; }

.vp-err {
  display: none;
  margin-top: 5px;
  font-size: 12.5px; color: #B91C1C;
}
.vp-field input:user-invalid ~ .vp-err,
.vp-field textarea:user-invalid ~ .vp-err { display: block; }

/* ---------- согласие ---------- */

.vp-check {
  display: flex; gap: 9px; align-items: flex-start;
  margin: 14px 0 16px;
  font-size: 13px; line-height: 1.45; color: #55606a;
  cursor: pointer;
}
.vp-check input {
  flex: none; width: 18px; height: 18px; margin-top: 1px;
  accent-color: #1F7A4D;
}
.vp-check:has(input:user-invalid) span { color: #B91C1C; }

/* Ловушка для ботов. display:none некоторые боты распознают, поэтому
   поле остаётся в потоке, но уводится за пределы экрана. */
.vp-hp {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden; clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- кнопка и статус ---------- */

.vp-form .btn-block { width: 100%; }

.vp-form button[disabled] { opacity: .65; cursor: progress; }

.vp-note {
  margin: 10px 0 0;
  font-size: 13px; line-height: 1.45;
  color: #B91C1C;
  min-height: 0;
}
.vp-note:empty { display: none; }

.vp-consent {
  margin: 10px 0 0;
  font-size: 12px; color: #8a939c; text-align: center;
}

.vp-ok {
  padding: 26px 6px;
  text-align: center;
}
.vp-ok__tick {
  width: 52px; height: 52px; margin: 0 auto 14px;
  display: grid; place-items: center;
  border-radius: 999px; background: #e7f4ed;
}
.vp-ok__tick svg { width: 26px; height: 26px; color: #1F7A4D; }
.vp-ok h3 { margin: 0 0 8px; font-size: 19px; }
.vp-ok p  { margin: 0 0 6px; color: #55606a; font-size: 14px; line-height: 1.5; }

/* ---------- нижний блок ---------- */

.vp-modal__alt {
  margin-top: 18px; padding-top: 16px;
  border-top: 1px solid #e7ebee;
  text-align: center;
  font-size: 13px; color: #6b7680;
}
.vp-modal__alt .social-row { justify-content: center; margin: 10px 0; }
.vp-modal__tel {
  display: inline-block; margin-top: 4px;
  font-size: 17px; font-weight: 700; color: #14171a; text-decoration: none;
}
.vp-modal__tel:hover { color: #1F7A4D; }

/* ---------- телефон: лист снизу ----------
   На узком экране окно посередине выглядит как чужеродная плашка и
   наполовину закрывается клавиатурой. Лист снизу — то, к чему рука привыкла. */

@media (max-width: 560px) {
  .vp-modal {
    width: 100vw;
    max-width: 100vw;
    max-height: 92dvh;
    margin: 0;
    position: fixed;
    inset: auto 0 0 0;
    border-radius: var(--vp-r) var(--vp-r) 0 0;
  }
  @media (prefers-reduced-motion: no-preference) {
    .vp-modal[open] { animation: vp-sheet .22s cubic-bezier(.2, .8, .3, 1); }
  }
  @keyframes vp-sheet { from { transform: translateY(100%); } }

  .vp-modal__body { padding: 22px 16px calc(18px + env(safe-area-inset-bottom)); }
  .vp-modal h2 { font-size: 20px; }

  /* Полоска-ручка, как у системных листов: подсказывает, что можно закрыть. */
  .vp-modal__body::before {
    content: "";
    display: block;
    width: 38px; height: 4px; margin: -8px auto 14px;
    background: #d6dde3; border-radius: 999px;
  }
}

/* ---------- тёмная тема системы ---------- */

@media (prefers-color-scheme: dark) {
  .vp-modal { background: #16191c; color: #f2f4f6; }
  .vp-modal__usp { background: #1e2327; color: #d3d9de; }
  .vp-modal__hint, .vp-check, .vp-modal__alt { color: #a9b2ba; }
  .vp-field label { color: #e3e7ea; }
  .vp-field input, .vp-field select, .vp-field textarea {
    background: #1b1f23; border-color: #333b42; color: #f2f4f6;
  }
  .vp-modal__x { background: rgba(30, 35, 39, .9); color: #a9b2ba; }
  .vp-modal__x:hover { background: #262c31; color: #fff; }
  .vp-modal__alt { border-top-color: #2a3036; }
  .vp-modal__tel { color: #f2f4f6; }
  .vp-ok__tick { background: #16281f; }
}

/* ---------- принудительные цвета ОС ---------- */

@media (forced-colors: active) {
  .vp-modal { border: 1px solid CanvasText; }
  .vp-field input:user-invalid { border-style: dashed; }
}
