/* ------------------------------------------------------------------
 * Фотогалерея с карточками.
 *
 * Namespace .photo-gallery намеренно свой: класс .gallery-item на сайте
 * уже занят конвенцией Magnific Popup (js/common.js), и совпадение
 * перехватило бы клики на восьми других страницах.
 * ------------------------------------------------------------------ */

.photo-gallery__grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

.photo-gallery__cell {
  position: relative;
  min-width: 0;
}

.photo-gallery__cell_hidden {
  display: none;
}

.photo-gallery__item {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: #f1f1f1;
  cursor: pointer;
  overflow: hidden;
  border-radius: 4px;
  aspect-ratio: 1 / 1;
}

/* фолбэк для браузеров без aspect-ratio */
@supports not (aspect-ratio: 1 / 1) {
  .photo-gallery__item {
    height: 0;
    padding-bottom: 100%;
    position: relative;
  }

  .photo-gallery__img {
    position: absolute;
    top: 0;
    left: 0;
  }
}

.photo-gallery__img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .35s ease;
}

/* Ховер только для мыши: на тачах он залипает после тапа */
@media (hover: hover) and (pointer: fine) {
  .photo-gallery__item:hover .photo-gallery__img {
    transform: scale(1.06);
  }
}

.photo-gallery__item:focus-visible {
  outline: 3px solid #324888;
  outline-offset: 2px;
}

.photo-gallery__actions {
  margin-top: 30px;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .photo-gallery__img,
  .pg-modal,
  .pg-modal__figure {
    transition: none !important;
  }
}

@media (max-width: 1169px) {
  .photo-gallery__grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 767px) {
  .photo-gallery__grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
  }
}

/* ------------------------------- Модалка ------------------------------- */

.pg-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  background: rgba(15, 20, 35, .92);
  opacity: 0;
  transition: opacity .25s ease;
}

.pg-modal_open {
  opacity: 1;
}

.pg-modal__body {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr);
  gap: 30px;
  align-items: center;
  width: 100%;
  max-width: 1400px;
  max-height: 100%;
}

.pg-modal__figure {
  margin: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: pan-y;
}

.pg-modal__image {
  display: block;
  max-width: 100%;
  max-height: 82vh;
  object-fit: contain;
}

.pg-modal__side {
  color: #fff;
  overflow-y: auto;
  max-height: 82vh;
}

.pg-modal__title {
  margin: 0 0 15px;
  font-size: 22px;
  line-height: 1.3;
  font-weight: bold;
}

.pg-modal__text {
  font-size: 16px;
  line-height: 1.5;
}

.pg-modal__text p {
  margin: 0 0 1em;
}

/* Ссылки в описании: синий цвет сайта (#324888) на тёмном фоне модалки
   практически не читается, поэтому здесь свой светлый вариант. */
.pg-modal__text a {
  color: #9ec5ff;
  text-decoration: underline;
}

.pg-modal__text a:hover {
  color: #fff;
}

.pg-modal__text a:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.pg-modal__counter {
  margin-top: 20px;
  font-size: 14px;
  opacity: .7;
}

.pg-modal__close,
.pg-modal__nav {
  position: absolute;
  border: 0;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  cursor: pointer;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  font-size: 24px;
  line-height: 48px;
  padding: 0;
}

.pg-modal__close:hover,
.pg-modal__nav:hover {
  background: rgba(255, 255, 255, .25);
}

.pg-modal__close:focus-visible,
.pg-modal__nav:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.pg-modal__close {
  top: 20px;
  right: 20px;
}

.pg-modal__nav_prev {
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
}

.pg-modal__nav_next {
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
}

.pg-modal__nav[hidden] {
  display: none;
}

/* Галерея без подписей: одна колонка, счётчик под фотографией */
.pg-modal_bare .pg-modal__body {
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  gap: 14px;
}

.pg-modal_bare .pg-modal__image {
  max-height: 78vh;
}

.pg-modal_bare .pg-modal__side {
  max-height: none;
  overflow: visible;
  text-align: center;
}

.pg-modal_bare .pg-modal__counter {
  margin-top: 0;
}

/* На мобильном заголовок и описание уходят под фото */
@media (max-width: 900px) {
  .pg-modal {
    padding: 60px 15px 20px;
    align-items: flex-start;
    overflow-y: auto;
  }

  .pg-modal__body {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .pg-modal__image {
    max-height: 60vh;
  }

  .pg-modal__side {
    max-height: none;
    overflow: visible;
  }

  .pg-modal__nav {
    top: auto;
    bottom: 20px;
    transform: none;
  }
}

/* Блокировка прокрутки страницы под открытой модалкой */
body.pg-modal-open {
  overflow: hidden;
}
