/**
 * Единая архитектура Bootstrap-модалок на мобильных: предел высоты, flex, scroll body.
 * Исключение: #imgModal (полноэкранное фото).
 */

@media (max-width: 767.98px) {
  /* Центрирование BS задаёт min-height ≈ 100% — ломает max-height под нативный хром APK */
  .modal:not(#imgModal) .modal-dialog.modal-dialog-centered {
    min-height: 0 !important;
  }

  .modal:not(#imgModal) .modal-dialog {
    box-sizing: border-box;
    max-height: var(--ds-modal-max-height-fallback);
    margin-bottom: max(var(--ds-space-4, 1rem), env(safe-area-inset-bottom, 0px));
  }

  .modal:not(#imgModal) .modal-dialog.modal-dialog-scrollable .modal-content {
    max-height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .modal:not(#imgModal) .modal-dialog.modal-dialog-scrollable .modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  /* Футер и шапка не сжимаются */
  .modal:not(#imgModal) .modal-dialog.modal-dialog-scrollable .modal-header,
  .modal:not(#imgModal) .modal-dialog.modal-dialog-scrollable .modal-footer {
    flex-shrink: 0;
  }

  /* Длинные заголовки не ломают раскладку */
  .modal:not(#imgModal) .modal-header {
    min-width: 0;
  }

  .modal:not(#imgModal) .modal-title {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .modal textarea.form-control {
    min-height: 5.5rem;
    resize: vertical;
    max-height: min(40dvh, 16rem);
    max-height: min(40vh, 16rem);
  }
}
