/* ======================== */
/* MODAL - МОДАЛЬНОЕ ОКНО */
/* ======================== */

/* Переменные для модального окна */
:root {
  --modal-z-index: 1050;
  --modal-backdrop-z-index: 1040;
  --modal-transition: var(--transition-normal);
  --modal-max-width: 500px;
  --modal-padding: 32px;
  --modal-border-radius: 12px;
  --modal-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

/* Модальное окно */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  z-index: var(--z-modal);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
}

/* Активное состояние модального окна */
.modal--active {
  opacity: 1;
  visibility: visible;
}

/* Оверлей */
.modal__overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: var(--modal-backdrop-z-index);
  backdrop-filter: blur(2px);
}

/* Контент модального окна */
.modal__content {
  position: relative !important;
  z-index: calc(var(--modal-z-index) + 1);
  background-color: #ffffff !important;
  border-radius: var(--modal-border-radius);
  box-shadow: var(--modal-shadow);
  width: 100% !important;
  max-width: var(--modal-max-width);
  max-height: calc(100vh - 32px) !important;
  overflow-y: auto;
  animation: modalSlideIn 0.3s ease;
  box-sizing: border-box !important;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Заголовок модального окна */
.modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: var(--modal-padding);
  padding-bottom: 24px;
  border-bottom: 1px solid #e9ecef;
  gap: 16px;
  box-sizing: border-box;
}

.modal__title {
  font-size: 24px;
  font-weight: 700;
  color: #0a0a0a;
  margin: 0;
  line-height: 1.3;
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
  flex: 1;
}

/* Кнопка закрытия */
.modal__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  color: #555555;
  transition: all 0.15s ease;
  background: none;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  margin-top: -4px;
}

.modal__close:hover {
  background-color: #f8f9fa;
  color: #0a0a0a;
}

.modal__close:focus-visible {
  outline: 3px solid #0696ee;
  outline-offset: 2px;
}

/* Форма модального окна */
.modal__form {
  padding: var(--modal-padding);
  display: flex;
  flex-direction: column;
  gap: 24px;
  box-sizing: border-box !important;
}

/* Поля формы */
.modal__field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal__label {
  font-size: 16px;
  font-weight: 500;
  color: #0a0a0a;
  line-height: 1.4;
}

.modal__input {
  padding: 16px;
  border: 2px solid #e9ecef;
  border-radius: 8px;
  font-size: 16px;
  color: #0a0a0a;
  background-color: #ffffff;
  transition: border-color 0.15s ease;
  width: 100% !important;
  box-sizing: border-box !important;
  line-height: 1.5;
  font-family: inherit;
}

.modal__input:focus {
  outline: none;
  border-color: #0696ee;
}

.modal__input:invalid:not(:placeholder-shown) {
  border-color: #dc3545;
}

/* Чекбокс согласия */
.modal__privacy {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  border: 2px solid transparent;
  border-radius: 8px;
  transition: border-color 0.15s ease;
  box-sizing: border-box;
}

.modal__privacy--error {
  border-color: #dc3545;
}

.modal__checkbox {
  margin-top: 2px;
  width: 18px;
  height: 18px;
  min-width: 18px;
  accent-color: #0696ee;
  flex-shrink: 0;
  cursor: pointer;
}

.modal__privacy-label {
  font-size: 14px;
  color: #555555;
  line-height: 1.5;
  cursor: pointer;
  margin: 0;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.modal__privacy-label a {
  text-decoration: underline;
}

/* Кнопка отправки */
.modal__submit {
  padding: 18px 32px;
  background-color: #0696ee;
  color: white;
  border-radius: 8px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
  width: 100% !important;
  box-sizing: border-box !important;
  line-height: 1.5;
  text-align: center;
  font-family: inherit;
  min-height: 56px;
}

.modal__submit:hover {
  background-color: #ff8c00;
  transform: translateY(-2px);
}

.modal__submit:active {
  transform: scale(0.98);
}

.modal__submit:disabled {
  background-color: #777777;
  cursor: not-allowed;
  transform: none;
  opacity: 0.6;
}

.modal__submit:focus-visible {
  outline: 3px solid #ffffff;
  outline-offset: 2px;
}

/* ======================== */
/* АДАПТИВНОСТЬ */
/* ======================== */

/* Планшеты и небольшие десктопы */
@media screen and (max-width: 1024px) {
  .modal {
    padding: 12px;
  }

  .modal__content {
    max-height: calc(100vh - 24px);
  }
}

/* Планшеты вертикальные (до 768px) */
@media screen and (max-width: 768px) {
  :root {
    --modal-padding: 24px;
  }

  .modal {
    padding: 8px !important;
    align-items: center !important;
  }

  .modal__content {
    max-height: calc(100vh - 16px) !important;
    border-radius: 12px !important;
    width: 100% !important;
  }

  .modal__header {
    padding: 24px !important;
    padding-bottom: 16px !important;
    gap: 12px !important;
  }

  .modal__title {
    font-size: 20px !important;
    line-height: 1.2 !important;
  }

  .modal__close {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
  }

  .modal__form {
    padding: 24px !important;
    gap: 20px !important;
  }

  .modal__input {
    padding: 14px !important;
    font-size: 16px !important; /* Предотвращение зума на iOS */
  }

  .modal__privacy {
    padding: 12px !important;
    gap: 10px !important;
  }

  .modal__privacy-label {
    font-size: 14px !important;
  }

  .modal__submit {
    padding: 16px 24px !important;
    font-size: 16px !important;
    min-height: 52px !important;
  }
}

/* Мобильные устройства (до 480px) */
@media screen and (max-width: 480px) {
  :root {
    --modal-padding: 16px;
  }

  .modal {
    padding: 4px !important;
  }

  .modal__content {
    max-height: calc(100vh - 8px) !important;
    border-radius: 8px !important;
    width: 100% !important;
  }

  .modal__header {
    padding: 16px !important;
    padding-bottom: 12px !important;
    gap: 8px !important;
  }

  .modal__title {
    font-size: 18px !important;
    line-height: 1.2 !important;
  }

  .modal__close {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
  }

  .modal__form {
    padding: 16px !important;
    gap: 16px !important;
  }

  .modal__field {
    gap: 6px !important;
  }

  .modal__label {
    font-size: 14px !important;
  }

  .modal__input {
    padding: 12px !important;
    font-size: 16px !important; /* Предотвращение зума на iOS */
  }

  .modal__privacy {
    padding: 10px !important;
    gap: 8px !important;
  }

  .modal__checkbox {
    width: 16px !important;
    height: 16px !important;
    min-width: 16px !important;
  }

  .modal__privacy-label {
    font-size: 13px !important;
    line-height: 1.4 !important;
  }

  .modal__submit {
    padding: 14px 20px !important;
    font-size: 16px !important;
    min-height: 50px !important;
  }
}

/* Очень маленькие экраны (до 360px) */
@media screen and (max-width: 360px) {
  .modal {
    padding: 0 !important;
  }

  .modal__content {
    max-height: 100vh !important;
    border-radius: 0 !important;
    width: 100% !important;
  }

  .modal__header {
    padding: 12px !important;
    padding-bottom: 10px !important;
  }

  .modal__title {
    font-size: 16px !important;
  }

  .modal__close {
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
  }

  .modal__form {
    padding: 12px !important;
    gap: 14px !important;
  }

  .modal__input {
    padding: 10px !important;
  }

  .modal__privacy {
    padding: 8px !important;
  }

  .modal__submit {
    padding: 12px 16px !important;
    font-size: 15px !important;
    min-height: 48px !important;
  }
}

/* Адаптивность по высоте экрана */
@media screen and (max-height: 700px) {
  .modal__content {
    max-height: calc(100vh - 20px);
  }

  .modal__header {
    padding-bottom: 12px;
  }

  .modal__form {
    gap: 16px;
  }
}

@media screen and (max-height: 600px) {
  .modal {
    align-items: flex-start;
    padding-top: 8px;
  }

  .modal__content {
    max-height: calc(100vh - 16px);
  }

  .modal__header {
    padding: 16px;
    padding-bottom: 10px;
  }

  .modal__form {
    padding: 16px;
    gap: 12px;
  }

  .modal__field {
    gap: 4px;
  }

  .modal__privacy {
    padding: 8px;
  }

  .modal__submit {
    min-height: 44px;
  }
}

/* Ландшафтная ориентация на мобильных */
@media screen and (max-width: 896px) and (orientation: landscape) and (max-height: 500px) {
  .modal {
    align-items: flex-start;
    padding: 4px;
  }

  .modal__content {
    max-height: calc(100vh - 8px);
    max-width: 90vw;
  }

  .modal__header {
    padding: 12px;
    padding-bottom: 8px;
  }

  .modal__title {
    font-size: 16px;
  }

  .modal__close {
    width: 28px;
    height: 28px;
    min-width: 28px;
  }

  .modal__form {
    padding: 12px;
    gap: 10px;
  }

  .modal__field {
    gap: 4px;
  }

  .modal__label {
    font-size: 13px;
  }

  .modal__input {
    padding: 8px;
    font-size: 14px;
  }

  .modal__privacy {
    padding: 6px;
    gap: 6px;
  }

  .modal__privacy-label {
    font-size: 12px;
  }

  .modal__submit {
    padding: 10px 16px;
    font-size: 14px;
    min-height: 40px;
  }
}

/* Улучшенная прокрутка для touch-устройств */
@media (hover: none) and (pointer: coarse) {
  .modal__content {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  
  /* Увеличенная область нажатия для мобильных */
  .modal__close {
    min-width: 44px;
    min-height: 44px;
  }
  
  .modal__checkbox {
    min-width: 20px;
    min-height: 20px;
  }
}

/* Accessibility - уменьшение анимаций */
@media (prefers-reduced-motion: reduce) {
  .modal,
  .modal__content,
  .modal__input,
  .modal__submit,
  .modal__close {
    transition: none;
    animation: none;
  }

  @keyframes modalSlideIn {
    from, to {
      opacity: 1;
      transform: none;
    }
  }
}