/* === БЛОКИРОВКА СКРОЛЛА === */
body.modal-open {
  overflow: hidden !important;
  padding-right: 0 !important;
}

/* === МОДАЛЬНОЕ ОКНО === */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100dvw;
  height: 100dvh;
  z-index: 10000;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  box-sizing: border-box;
}

.modal__overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  cursor: pointer;
}

/* Основной контейнер — flex: колонка (хедер + тело) */
.modal__content {
  width: 100%;
  max-width: min(900px, 100%);
  max-height: 95dvh;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  font-size: 18px;
  line-height: 1.6;
  color: #000;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ХЕДЕР — фиксированная часть */
.modal-header {
  flex: 0 0 auto;
  position: relative;
  padding: 16px;
  background: #fff;
  z-index: 10;
  border-radius: 16px 16px 0 0;
}

/* Кнопка закрытия */
.modal-close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  font-size: 28px;
  background: none;
  border: none;
  cursor: pointer;
  color: #333;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  padding: 0;
}

.modal-close-btn:hover {
  background: #f0f0f0;
}

/* ТЕЛО — скроллируемая область */
.modal-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 32px 32px 32px;
  box-sizing: border-box;
}

/* === КОНТЕНТ СТАТЬИ === */
.modal-article-content {
  padding: 0;
  width: 100%;
  word-break: break-word;
  overflow-wrap: break-word;
}

.modal-article-title {
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 24px 0;
  color: #000;
  line-height: 1.3;
  padding-right: 44px; /* место под кнопку × */
}

.modal-article-text {
  margin-bottom: 24px;
}

/* Защита вложенных элементов */
.modal-article-content img,
.modal-article-content table,
.modal-article-content p,
.modal-article-content h1,
.modal-article-content h2,
.modal-article-content h3,
.modal-article-content h4,
.modal-article-content h5,
.modal-article-content h6,
.modal-article-content ul,
.modal-article-content ol {
  max-width: 100% !important;
  height: auto !important;
  box-sizing: border-box !important;
}

/* === РАСКЛАДКА: ТЕКСТ + КАРТИНКИ === */
.modal-article-layout {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.modal-article-main {
  flex: 1;
  min-width: 0;
}

/* === MASONRY-ГАЛЕРЕЯ === */
.modal-article-images {
  display: block;
  width: 100%;
}

/* Masonry через column-count */
.modal-article-images.masonry {
  column-count: 2;
  column-gap: 12px;
}

.modal-article-image-item {
  break-inside: avoid;
  margin-bottom: 12px;
  width: 100%;
}

.modal-article-image-item img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
  background: #f9f9f9;
}

/* === АДАПТИВ === */

/* Мобильные */
@media (max-width: 768px) {
  .modal-article-images.masonry {
    column-count: 1;
  }

  .modal__content {
    border-radius: 12px;
    font-size: 16px;
    max-height: 95dvh;
  }

  .modal-body {
    padding: 0 16px 16px 16px;
  }

  .modal-article-title {
    font-size: 24px;
    padding-right: 40px;
  }
}

/* Десктоп: две колонки текст + картинки */
@media (min-width: 769px) {
  .modal-article-layout {
    flex-direction: row;
    gap: 32px;
  }

  .modal-article-main {
    flex: 2;
  }

  .modal-article-images {
    flex: 1;
    min-width: 200px;
    max-width: 300px;
  }

  /* На широких экранах — 3 колонки в галерее */
  @media (min-width: 1200px) {
    .modal-article-images.masonry {
      column-count: 3;
    }
  }
}

/* === СБРОС ФИКСИРОВАННОЙ ШИРИНЫ ИЗ ВНЕШНИХ СТИЛЕЙ === */
@media (max-width: 1024px) {
  body.modal-open {
    width: 100% !important;
    min-width: 0 !important;
  }
}