/* Travnik Gallery — preview (main + thumbs) + optional grid + lightbox (no deps)
   Variant B (mobile-first):
   - Mobile: swipe main + dots
   - Desktop: thumbs column (2 cols) on the right
*/

.tn-featured-gallery{ margin: 0; padding: 0; }

/* =================
   PREVIEW (carousel)
   ================= */

.tn-featured-gallery--preview{
  width: 100%;
  max-width: 100%;
}

/* Optional: если где-то нужно намеренно «узкое» превью (например, в сайдбаре) */
.tn-featured-gallery--preview.tn-featured-gallery--narrow{
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}

/* Dots (mobile) */
.tn-featured-gallery__dots{
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}

.tn-featured-gallery__dot{
  appearance: none;
  border: 0;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: rgba(0,0,0,0.25);
  padding: 0;
  cursor: pointer;
}

.tn-featured-gallery__dot.is-active{ background: rgba(0,0,0,0.6); }

/* Variant B toggles */
.tn-featured-gallery--variant-b .tn-featured-gallery__dots{ display: flex; }
.tn-featured-gallery--variant-b .tn-featured-gallery__thumbs{ display: none; }

@media (min-width: 783px){
  .tn-featured-gallery--variant-b .tn-featured-gallery__dots{ display: none; }
  .tn-featured-gallery--variant-b .tn-featured-gallery__thumbs{ display: grid; }
}

/* Main carousel */
.tn-featured-gallery__main{
  position: relative;
  border-radius: 16px;
  background: rgba(0,0,0,0.04);
  aspect-ratio: 1 / 1;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  touch-action: auto;
  scrollbar-width: none;
}

.tn-featured-gallery__main::-webkit-scrollbar{ display: none; }

.tn-featured-gallery__slide{
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  display: block;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  position: relative;
  cursor: zoom-in;
  user-select: none;
  -webkit-user-select: none;
}

.tn-featured-gallery__slide:focus{
  outline: 2px solid rgba(47,133,90,0.65);
  outline-offset: -2px;
}

.tn-featured-gallery__main-img{
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transform: scale(1);
  transition: transform .18s ease, filter .18s ease;
  will-change: transform;
}

.tn-featured-gallery__slide:hover .tn-featured-gallery__main-img{
  transform: scale(1.02);
  filter: saturate(1.03);
}

@supports (scroll-snap-stop: always){
  .tn-featured-gallery__slide{ scroll-snap-stop: always; }
}

/* Progressive enhancement: scroll-driven emphasis (Chrome/Edge) */
@supports (animation-timeline: view()) {
  .tn-featured-gallery__slide{
    view-timeline-name: --tn-slide;
    view-timeline-axis: inline;
  }
  .tn-featured-gallery__main-img{
    animation: tn-slide-focus 1 both;
    animation-timeline: --tn-slide;
    animation-range: entry 0% exit 100%;
  }
}

@keyframes tn-slide-focus{
  0%{ transform: scale(.97); filter: saturate(.96); }
  50%{ transform: scale(1); filter: saturate(1.03); }
  100%{ transform: scale(.97); filter: saturate(.96); }
}

/* Thumbs */
.tn-featured-gallery__thumbs{
  --tn-thumb-gap: 8px;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: var(--tn-thumb-gap);
  margin-top: 10px;
}

.tn-featured-gallery__thumb{
  appearance: none;
  border: 2px solid transparent;
  box-sizing: border-box;
  padding: 0;
  margin: 0;
  background: transparent;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 1 / 1;
  background: rgba(0,0,0,0.04);
}

.tn-featured-gallery__thumb:focus-visible{
  outline: none;
  border-color: rgba(47,133,90,.65);
  box-shadow: 0 0 0 3px rgba(47,133,90,.18);
}

.tn-featured-gallery__thumb.is-active{ border-color: rgba(47,133,90,.85); }

.tn-featured-gallery__thumb-img{
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transform: scale(1);
  transition: transform .18s ease;
}

.tn-featured-gallery__thumb:hover .tn-featured-gallery__thumb-img{ transform: scale(1.03); }

/* "+N" tile (shown when thumbnails are capped) */
.tn-featured-gallery__thumb--more{
  position: relative;
  box-sizing: border-box;
}

.tn-featured-gallery__thumb--more .tn-featured-gallery__thumb-more{
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(2px);
}

.tn-featured-gallery__thumb--more .tn-featured-gallery__thumb-more-icon{
  position: absolute;
  right: 8px;
  bottom: 6px;
  font-size: 14px;
  color: #fff;
  opacity: .9;
}

/* Thumb presets from PHP */
.tn-featured-gallery__thumbs--cols-1{ grid-template-columns: repeat(1, minmax(0, 1fr)); }
.tn-featured-gallery__thumbs--cols-2{ grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tn-featured-gallery__thumbs--cols-3{ grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tn-featured-gallery__thumbs--cols-4{ grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tn-featured-gallery__thumbs--cols-5{ grid-template-columns: repeat(5, minmax(0, 1fr)); }
.tn-featured-gallery__thumbs--cols-6{ grid-template-columns: repeat(6, minmax(0, 1fr)); }
.tn-featured-gallery__thumbs--cols-7{ grid-template-columns: repeat(7, minmax(0, 1fr)); }
.tn-featured-gallery__thumbs--cols-8{ grid-template-columns: repeat(8, minmax(0, 1fr)); }

@media (max-width: 782px){
  .tn-featured-gallery__thumbs{ grid-template-columns: repeat(6, minmax(0, 1fr)); }
}
@media (max-width: 520px){
  .tn-featured-gallery__thumbs{ grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

/* Desktop: thumbs column on the right (Variant B) */
@media (min-width: 783px){
  .tn-featured-gallery--preview.tn-featured-gallery--variant-b{
    display: grid;
    grid-template-columns: minmax(0, 1fr) 168px;
    gap: 12px;
    /* Важно: не растягиваем main по высоте — иначе при большом кол-ве миниатюр «ломается» превью */
    align-items: start;
  }

  .tn-featured-gallery--preview.tn-featured-gallery--variant-b .tn-featured-gallery__main{
    grid-column: 1;
    grid-row: 1;
  }

  .tn-featured-gallery--preview.tn-featured-gallery--variant-b .tn-featured-gallery__thumbs{
    grid-column: 2;
    grid-row: 1;
    margin-top: 0;

    /* 2 колонки миниатюр в правой колонке */
    grid-template-columns: repeat(var(--tn-thumbs-side-cols, 2), minmax(0, 1fr));
    gap: var(--tn-thumbs-side-gap, 4px);
    align-content: start;

    min-height: 0;
  }
}

/* =================
   GRID (optional)
   ================= */

.tn-featured-gallery--grid{
  --tn-cols: 3;
  --tn-gap: 10px;
  display: grid;
  grid-template-columns: repeat(var(--tn-cols), minmax(0, 1fr));
  gap: var(--tn-gap);
}

.tn-featured-gallery--cols-1{ --tn-cols: 1; }
.tn-featured-gallery--cols-2{ --tn-cols: 2; }
.tn-featured-gallery--cols-3{ --tn-cols: 3; }
.tn-featured-gallery--cols-4{ --tn-cols: 4; }
.tn-featured-gallery--cols-5{ --tn-cols: 5; }
.tn-featured-gallery--cols-6{ --tn-cols: 6; }

@media (max-width: 782px){ .tn-featured-gallery--grid{ --tn-cols: 2; } }
@media (max-width: 520px){ .tn-featured-gallery--grid{ --tn-cols: 1; } }

.tn-featured-gallery--grid .tn-featured-gallery__item{
  margin: 0;
  border-radius: 16px;
  overflow: hidden;
  background: rgba(0,0,0,0.04);
  aspect-ratio: 1 / 1;
}

.tn-featured-gallery--grid .tn-featured-gallery__link{
  display: block;
  height: 100%;
  cursor: zoom-in;
}

.tn-featured-gallery--grid .tn-featured-gallery__img{
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transform: scale(1);
  transition: transform .18s ease, filter .18s ease;
}

.tn-featured-gallery--grid .tn-featured-gallery__link:hover .tn-featured-gallery__img{
  transform: scale(1.03);
  filter: saturate(1.03);
}

/* =================
   LIGHTBOX
   ================= */

.tn-lightbox{
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: none;

  /* Safe-area aware insets (iOS notch, etc.) */
  --tn-lb-safe-top: max(16px, env(safe-area-inset-top));
  --tn-lb-safe-left: max(16px, env(safe-area-inset-left));
  --tn-lb-safe-right: max(16px, env(safe-area-inset-right));
  --tn-lb-safe-bottom: max(16px, env(safe-area-inset-bottom));
}
.tn-lightbox.is-open{ display: block; }

.tn-lightbox__backdrop{
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #000; /* solid black */
}

.tn-lightbox__ui{
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  touch-action: auto;
  padding: 0;
  scrollbar-width: none;
}

.tn-lightbox__ui::-webkit-scrollbar{ display: none; }

.tn-lightbox__slide{
  flex: 0 0 100%;
  width: 100%;
  scroll-snap-align: center;
  scroll-snap-stop: always;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Keep the image perfectly centered in the viewport */
  padding: 0;
  box-sizing: border-box;
}

.tn-lightbox__img{
  max-width: min(96vw, 1400px);
  max-height: 88vh;
  border-radius: 14px;
  box-shadow: 0 20px 80px rgba(0,0,0,.55);
  object-fit: contain;
  will-change: transform, opacity;
  cursor: zoom-in;
  transition: transform 160ms ease;

}
.tn-lightbox__img.is-zoomed{
  cursor: zoom-out;
}

.tn-lightbox.is-zoomed .tn-lightbox__scroller{
  scroll-snap-type: none;
  scroll-behavior: auto;
}


.tn-lightbox__btn{
  position: fixed;
  z-index: 3;
  top: var(--tn-lb-safe-top);
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

.tn-lightbox__btn svg{
  width: 22px;
  height: 22px;
  display: block;
}

.tn-lightbox__close svg{
  width: 20px;
  height: 20px;
}

.tn-lightbox__close{ right: var(--tn-lb-safe-right); }

/* Counter “2/23” */
.tn-lightbox__counter{
  position: absolute;
  z-index: 3;
  top: var(--tn-lb-safe-top);
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  letter-spacing: .02em;
  user-select: none;
  backdrop-filter: blur(6px);
}

.tn-lightbox__meta{
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  padding: 14px 16px 16px;
  background: linear-gradient(to top, rgba(0,0,0,.78), rgba(0,0,0,0));
  color: #fff;
  text-align: center;
}

.tn-lightbox__meta-row{
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.tn-lightbox__meta-title{
  font-weight: 600;
  font-size: 16px;
  line-height: 1.3;
  text-shadow: 0 2px 10px rgba(0,0,0,.55);
  width: min(900px, 100%);
  margin-left: auto;
  margin-right: auto;
}

.tn-lightbox__meta-desc{
  font-weight: 400;
  font-size: 14px;
  line-height: 1.35;
  opacity: .92;
  text-shadow: 0 2px 10px rgba(0,0,0,.55);
  width: min(900px, 100%);
  margin-left: auto;
  margin-right: auto;
  max-height: 6.5em;
  overflow: auto;
  padding: 0 2px;
}


.tn-lightbox__meta-caption{
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.35;
  opacity: .92;
  text-shadow: 0 2px 10px rgba(0,0,0,.55);
  max-height: 30vh;
  overflow: auto;
  overscroll-behavior: contain;
  width: min(900px, 100%);
  margin-left: auto;
  margin-right: auto;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(0,0,0,.25);
}

.tn-lightbox__prev{
  top: 50%;
  left: var(--tn-lb-safe-left);
  transform: translateY(-50%);
}

.tn-lightbox__next{
  top: 50%;
  right: var(--tn-lb-safe-right);
  transform: translateY(-50%);
}

html.tn-lightbox-open{ overflow: hidden; }
