/* ============================================================
   App Modal  —  на базе нативного <dialog>
   Использование:
     openModal('id-шаблона', 'Заголовок')   — открыть
     closeModal()                            — закрыть

   Для каждой страницы:
     1. Добавьте <link href="css/modal.css" rel="stylesheet">
     2. Вставьте оболочку диалога (один раз на страницу):
          <!-- скопируйте блок «Modal Shell» из любой страницы -->
     3. Добавьте контент в <template id="...">...</template>
     4. Добавьте <script src="js/modal.js"></script> перед </body>
   ============================================================ */

/* Оболочка диалога */
.app-modal {
  border: 1px solid #1a3a5c;
  border-radius: 10px;
  padding: 0;
  width: 720px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 48px);
  box-shadow: 0 12px 56px rgba(0, 0, 0, 0.30);
  overflow: hidden;
  /* центрирование в современных браузерах */
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  /* flex включается через [open] ниже */
  display: none;
}

/* Фон-подложка */
.app-modal::backdrop {
  background: rgba(0, 0, 0, 0.70);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

/* Открытый диалог */
.app-modal[open] {
  display: flex;
  flex-direction: column;
  animation: modal-in 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translate(-50%, calc(-50% - 18px));
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

/* Шапка */
.app-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #e4e4e4;
  background: #f7f7f7;
  flex-shrink: 0;
  flex-wrap: nowrap;
}

.app-modal__title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: #222;
}

/* Кнопка закрытия */
.app-modal__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  min-width: 30px;
  background: none;
  border: none;
  border-radius: 50%;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  color: #666;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.app-modal__close:hover,
.app-modal__close:focus-visible {
  background: #e0e0e0;
  color: #111;
  outline: none;
}

/* Тело диалога */
.app-modal__body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;   /* плавный скролл на iOS */
}

/* Таблицы внутри диалога — добавляем горизонтальный скролл */
.app-modal__body .table-responsive-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---- Мобильные устройства: стиль «нижний лист» (bottom sheet) ---- */
@media (max-width: 576px) {
  .app-modal {
    width: 100%;
    max-width: 100%;
    max-height: 88vh;
    border-radius: 16px 16px 0 0;
    /* прижимаем к низу экрана */
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
  }

  @keyframes modal-in {
    from {
      opacity: 0;
      transform: translateY(32px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}
