/* Quiz dialog — first-screen CTA popup (perf-tuned) */

body.mpqd-open {
  overflow: hidden;
}

.mpqd {
  position: fixed;
  inset: 0;
  z-index: 100050;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  box-sizing: border-box;
}

.mpqd.is-open {
  display: flex;
}

.mpqd__backdrop {
  position: absolute;
  inset: 0;
  /* Solid dim — no backdrop-filter (very expensive over hero) */
  background: rgba(15, 14, 25, 0.78);
}

.mpqd__shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: min(920px, 100%);
  max-height: min(calc(720px + 52px), calc(100dvh - 24px));
  box-sizing: border-box;
}

.mpqd__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  max-height: min(720px, calc(100dvh - 76px));
  overflow: hidden;
  border-radius: 18px;
  background: #f4f5f7;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.28);
  box-sizing: border-box;
  contain: layout paint style;
  transform: translateZ(0);
}

.mpqd__close {
  position: relative;
  top: auto;
  right: auto;
  flex-shrink: 0;
  z-index: 5;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: #fff;
  color: #171524;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(23, 21, 36, 0.1);
}

.mpqd__close:hover {
  background: #f0f1f5;
}

.mpqd__head {
  flex-shrink: 0;
  padding: 28px 28px 8px;
  overflow: hidden;
  max-height: 160px;
  opacity: 1;
  transition:
    opacity 0.28s ease,
    max-height 0.35s var(--mpq-ease, cubic-bezier(0.22, 1, 0.36, 1)),
    padding 0.35s var(--mpq-ease, cubic-bezier(0.22, 1, 0.36, 1));
}

.mpqd.is-contact-step .mpqd__head {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  pointer-events: none;
  visibility: hidden;
}

.mpqd__eyebrow {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8842e0;
}

.mpqd__title {
  margin: 0 0 8px;
  font-size: clamp(22px, 2.6vw, 30px);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: #171524;
}

.mpqd__lead {
  margin: 0;
  font-size: 15px;
  line-height: 1.45;
  color: #5b5770;
}

.mpqd__body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px 16px 16px;
  overflow: hidden;
}

.mpqd__body .mpq {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: none;
}

.mpqd__body .mpq__top {
  flex-shrink: 0;
}

/* Single scroll surface — body grows, footer stays at bottom */
.mpqd__body .mpq__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.mpqd__body .mpq__body > .mpq-panel {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.mpqd__body .mpq-choices,
.mpqd__body .mpq-choices.is-scrollable {
  flex: 1 1 auto;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow-y: auto !important;
  contain: none;
  scrollbar-gutter: auto;
}

.mpqd__body .mpq__foot {
  flex-shrink: 0;
  margin-top: auto;
}

/* Desktop popup: фиксированная высота — без прыжков между шагами */
@media (min-width: 768px) {
  .mpqd__shell {
    max-height: min(calc(720px + 52px), calc(100dvh - 24px));
  }

  .mpqd__panel {
    height: min(720px, calc(100dvh - 76px));
    max-height: min(720px, calc(100dvh - 76px));
  }

  .mpqd__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .mpqd__body .mpq {
    flex: 1 1 auto;
    min-height: 0 !important;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 16px 18px 0;
    --mpq-choices-h: 0px;
    --mpq-intro-h: 0px;
  }

  .mpqd__body .mpq__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }

  .mpqd__body .mpq__body > .mpq-panel,
  .mpqd__body .mpq__body > .mpq-result,
  .mpqd__body .mpq__body > .mpq-success {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .mpqd__body .mpq-panel__intro {
    flex-shrink: 0;
    min-height: 88px;
    margin-bottom: 10px;
  }

  .mpqd__body .mpq-choices,
  .mpqd__body .mpq-choices.is-scrollable {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    max-height: none !important;
    height: auto !important;
    overflow-y: auto !important;
    contain: none;
  }

  .mpqd__body .mpq__foot {
    flex-shrink: 0;
    margin-top: 0;
    padding: 12px 0 16px;
  }

  /* Финальный шаг — одна белая плоскость */
  .mpqd.is-contact-step .mpqd__panel {
    background: #eceef2;
  }

  .mpqd.is-contact-step .mpqd__body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 8px 24px 24px;
  }

  .mpqd.is-contact-step .mpqd__body .mpq {
    flex: 1 1 auto;
    height: 100%;
    min-height: 0 !important;
    padding: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
  }

  .mpqd.is-contact-step .mpqd__body .mpq__top {
    padding: 6px 8px 14px;
    margin-bottom: 0;
    border-bottom: 0;
  }

  .mpqd.is-contact-step .mpqd__body .mpq__step {
    font-size: 13px;
    font-weight: 600;
    color: var(--mpq-ink, #15181c);
  }

  .mpqd.is-contact-step .mpqd__body .mpq__body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    overflow-y: auto;
    padding: 12px 0 0;
  }

  .mpqd.is-contact-step .mpqd__body .mpq__body > .mpq-result {
    flex: 1 1 auto;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
  }

  .mpqd.is-contact-step .mpq-result__sheet {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 28px 32px 32px;
    border-radius: 14px;
    background: #fff;
    border: 1px solid rgba(21, 24, 28, 0.06);
  }

  .mpqd.is-contact-step .mpqd__body .mpq-result__layout {
    gap: 0;
    align-items: start;
  }

  .mpqd.is-contact-step .mpqd__body .mpq-form__submit {
    align-self: flex-start;
    margin-top: 8px;
    margin-left: 0;
    margin-right: auto;
    margin-bottom: 0;
  }
}

/* No infinite shadow pulse inside dialog */
.mpqd__body .mpq__btn--cta.is-ready {
  animation: none !important;
  box-shadow: 0 6px 16px rgba(115, 101, 238, 0.28);
}

.mpqd__body .mpq-option__img[src] {
  transition: none;
}

.mpqd__body .mpq.is-paused {
  pointer-events: none;
  opacity: 0.55;
}

@media (max-width: 767px) {
  .mpqd {
    padding: 0;
    align-items: stretch;
  }

  .mpqd__shell {
    position: relative;
    width: 100%;
    max-height: none;
    height: 100dvh;
    height: 100svh;
    gap: 0;
    padding: 0;
  }

  .mpqd__close {
    position: absolute;
    top: max(10px, env(safe-area-inset-top, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    z-index: 20;
  }

  .mpqd__panel {
    width: 100%;
    max-height: none;
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    border-radius: 0;
    box-shadow: none;
  }

  .mpqd__head {
    flex-shrink: 0;
    padding: max(16px, env(safe-area-inset-top, 0px) + 8px) 56px 8px 18px;
  }

  .mpqd__body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 8px 10px 0;
    overflow: hidden;
  }

  .mpqd__body .mpq {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    padding: 10px 10px 0;
  }

  .mpqd__body .mpq__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: auto;
    -webkit-overflow-scrolling: touch;
  }

  .mpqd__body .mpq-choices,
  .mpqd__body .mpq-choices.is-scrollable {
    flex: 0 1 auto;
    min-height: 0;
    overflow-y: visible !important;
    overscroll-behavior: auto;
  }

  .mpqd__body .mpq__foot {
    flex-shrink: 0;
    margin-top: auto;
    padding: 8px 0 calc(10px + env(safe-area-inset-bottom, 0px));
    background: #f4f5f7;
    border-top: 1px solid rgba(21, 24, 28, 0.08);
  }

  /* Финальный шаг — скролл формы, одна колонка */
  .mpqd.is-contact-step .mpqd__panel {
    background: #eceef2;
  }

  .mpqd.is-contact-step .mpqd__body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 8px 12px calc(12px + env(safe-area-inset-bottom, 0px));
    overflow: hidden;
  }

  .mpqd.is-contact-step .mpqd__body .mpq {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    padding: 0;
    display: flex;
    flex-direction: column;
    background: transparent;
    border: 0;
    box-shadow: none;
  }

  .mpqd.is-contact-step .mpqd__body .mpq__top {
    flex-shrink: 0;
    margin-bottom: 10px;
    padding-top: max(8px, env(safe-area-inset-top, 0px));
    padding-right: 52px;
  }

  .mpqd.is-contact-step .mpqd__body .mpq__value {
    margin-right: 0;
  }

  .mpqd.is-contact-step .mpqd__body .mpq__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 0;
  }

  .mpqd.is-contact-step .mpqd__body .mpq__body > .mpq-result {
    flex: 0 0 auto;
    width: 100%;
    margin: 0;
    padding: 0;
  }

  .mpqd.is-contact-step .mpq-result__sheet {
    padding: 20px 18px 22px;
    border-radius: 14px;
    background: #fff;
    border: 1px solid rgba(21, 24, 28, 0.06);
  }

  .mpqd.is-contact-step .mpq-result__layout {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .mpqd.is-contact-step .mpq-result__aside {
    padding-right: 0;
    border-right: 0;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(21, 24, 28, 0.08);
  }

  .mpqd.is-contact-step .mpq-result__form-col {
    padding-left: 0;
    padding-top: 20px;
  }

  .mpqd.is-contact-step .mpq-form__submit {
    align-self: flex-start;
    margin-left: 0;
    margin-right: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mpqd__body .mpq__body > .is-enter,
  .mpqd__body .mpq__body > .is-enter-back,
  .mpqd__body .mpq__body > .is-leave,
  .mpqd__body .mpq__body > .is-leave-back,
  .mpqd__body .mpq__body > .is-enter-fade,
  .mpqd__body .mpq__body > .is-leave-fade {
    animation: none !important;
  }

  .mpqd__head {
    transition: none;
  }
}
