/**
 * Минимальные стили плагина. Основная вёрстка — классы fd-gallery-* в теме gustolocal.
 */

.gl-gallery-section {
  width: 100%;
}

.gl-gallery-layout-lightbox-only .fd-gallery-container {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.gl-gallery-missing {
  padding: 0.5rem 1rem;
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 4px;
}

/* На случай, если тема не подгружает fd-food-gallery */
.gl-gallery-section .fd-gallery-grid {
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.gl-gallery-section .fd-gallery-item {
  cursor: pointer;
}

.gl-gallery-section .fd-lightbox[hidden],
body > .fd-lightbox.gl-gallery-lightbox[hidden] {
  display: none !important;
}

/* Lightbox переносится в body — селекторы без .gl-gallery-section обязательны */
body > .fd-lightbox.gl-gallery-lightbox:not([hidden]).active,
body > .fd-lightbox.gl-gallery-lightbox:not([hidden]).is-active,
.gl-gallery-section .gl-gallery-lightbox:not([hidden]).active,
.gl-gallery-lightbox:not([hidden]).active,
.gl-gallery-lightbox:not([hidden]).is-active {
  display: flex !important;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100000;
  align-items: center;
  justify-content: center;
  padding: 3.5rem 4rem;
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.95);
  overflow: visible;
}

body > .fd-lightbox.gl-gallery-lightbox.active .fd-lightbox-content,
body > .fd-lightbox.gl-gallery-lightbox.is-active .fd-lightbox-content,
.gl-gallery-section .gl-gallery-lightbox.active .fd-lightbox-content,
.gl-gallery-section .gl-gallery-lightbox.is-active .fd-lightbox-content,
.gl-gallery-lightbox.active .fd-lightbox-content,
.gl-gallery-lightbox.is-active .fd-lightbox-content {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 1 auto;
  position: relative;
  overflow: visible;
  max-width: min(100vw - 8rem, 100%);
  max-height: min(100vh - 7rem, 100%);
  width: auto;
  height: auto;
}

body > .fd-lightbox.gl-gallery-lightbox.active .fd-lightbox-content img,
body > .fd-lightbox.gl-gallery-lightbox.is-active .fd-lightbox-content img,
.gl-gallery-section .gl-gallery-lightbox.active .fd-lightbox-content img,
.gl-gallery-section .gl-gallery-lightbox.is-active .fd-lightbox-content img,
.gl-gallery-lightbox.active .fd-lightbox-content img,
.gl-gallery-lightbox.is-active .fd-lightbox-content img {
  display: block;
  flex: 0 0 auto;
  max-width: min(100vw - 8rem, 100%);
  max-height: min(100vh - 7rem, 100%);
  width: auto !important;
  height: auto !important;
  object-fit: contain !important;
  object-position: center center;
  border-radius: 8px;
}

/* Desktop: вписать фото целиком, без обрезки сверху/снизу (мобильные стили ниже не трогаем) */
@media (min-width: 641px) {
  body > .fd-lightbox.gl-gallery-lightbox:not([hidden]).active,
  body > .fd-lightbox.gl-gallery-lightbox:not([hidden]).is-active,
  .gl-gallery-section .gl-gallery-lightbox:not([hidden]).active,
  .gl-gallery-lightbox:not([hidden]).active,
  .gl-gallery-lightbox:not([hidden]).is-active {
    padding: 2.5rem 3.5rem;
    overflow: hidden;
  }

  body > .fd-lightbox.gl-gallery-lightbox.active .fd-lightbox-content,
  body > .fd-lightbox.gl-gallery-lightbox.is-active .fd-lightbox-content,
  .gl-gallery-section .gl-gallery-lightbox.active .fd-lightbox-content,
  .gl-gallery-section .gl-gallery-lightbox.is-active .fd-lightbox-content,
  .gl-gallery-lightbox.active .fd-lightbox-content,
  .gl-gallery-lightbox.is-active .fd-lightbox-content {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 1 auto;
    min-width: 0;
    min-height: 0;
    max-width: min(92vw, 1200px);
    max-height: min(85vh, calc(100vh - 120px));
    width: auto;
    height: auto;
  }

  body > .fd-lightbox.gl-gallery-lightbox.active .fd-lightbox-content img,
  body > .fd-lightbox.gl-gallery-lightbox.is-active .fd-lightbox-content img,
  .gl-gallery-section .gl-gallery-lightbox.active .fd-lightbox-content img,
  .gl-gallery-section .gl-gallery-lightbox.is-active .fd-lightbox-content img,
  .gl-gallery-lightbox.active .fd-lightbox-content img,
  .gl-gallery-lightbox.is-active .fd-lightbox-content img {
    display: block;
    flex: 0 0 auto;
    max-width: min(92vw, 1200px);
    max-height: min(85vh, calc(100vh - 120px));
    width: auto !important;
    height: auto !important;
    min-width: 0;
    min-height: 0;
    object-fit: contain !important;
    object-position: center center;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.14);
  }
}

.gl-gallery-lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: #333;
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10001;
  transition: background 0.2s ease, transform 0.2s ease;
  padding: 0;
}

.gl-gallery-lightbox-nav:hover {
  background: #fff;
  transform: translateY(-50%) scale(1.08);
}

.gl-gallery-lightbox-prev {
  left: 1rem;
}

.gl-gallery-lightbox-next {
  right: 1rem;
}

.gl-gallery-lightbox-counter {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.875rem;
  letter-spacing: 0.04em;
  z-index: 10001;
  pointer-events: none;
  user-select: none;
}

@media (max-width: 640px) {
  body > .fd-lightbox.gl-gallery-lightbox:not([hidden]).active,
  body > .fd-lightbox.gl-gallery-lightbox:not([hidden]).is-active,
  .gl-gallery-section .gl-gallery-lightbox:not([hidden]).active,
  .gl-gallery-lightbox:not([hidden]).active,
  .gl-gallery-lightbox:not([hidden]).is-active {
    padding: 3rem 0.5rem;
  }

  body > .fd-lightbox.gl-gallery-lightbox.active .fd-lightbox-content,
  body > .fd-lightbox.gl-gallery-lightbox.active .fd-lightbox-content img,
  body > .fd-lightbox.gl-gallery-lightbox.is-active .fd-lightbox-content,
  body > .fd-lightbox.gl-gallery-lightbox.is-active .fd-lightbox-content img,
  .gl-gallery-section .gl-gallery-lightbox.active .fd-lightbox-content,
  .gl-gallery-section .gl-gallery-lightbox.active .fd-lightbox-content img,
  .gl-gallery-lightbox.active .fd-lightbox-content,
  .gl-gallery-lightbox.active .fd-lightbox-content img,
  .gl-gallery-lightbox.is-active .fd-lightbox-content,
  .gl-gallery-lightbox.is-active .fd-lightbox-content img {
    max-width: min(100vw - 2rem, 100%);
    max-height: min(100vh - 5rem, 100%);
  }

  .gl-gallery-lightbox-nav {
    width: 40px;
    height: 40px;
    font-size: 1.4rem;
  }

  .gl-gallery-lightbox-prev {
    left: 0.25rem;
  }

  .gl-gallery-lightbox-next {
    right: 0.25rem;
  }

  .gl-gallery-lightbox-counter {
    bottom: 0.5rem;
    font-size: 0.8125rem;
  }
}
