/* ═══════════════════════════════════════════
   LIGHTBOX — премиальный просмотр фотографий
   ═══════════════════════════════════════════ */

/* ---------- Миниатюры ---------- */
[data-lightbox] { cursor: zoom-in; }
[data-lightbox]:focus-visible {
  outline: 3px solid var(--accent, #8B6F2E);
  outline-offset: 3px;
}

/* ---------- Блокировка прокрутки фона ---------- */
html.lb-open { overflow: hidden; padding-right: var(--lb-sbw, 0px); }
body.lb-open { overflow: hidden; }
body.lb-open #calc-sticky-bar { display: none !important; }

/* ---------- Оболочка ---------- */
.lb {
  --lb-vh: 100vh;
  --lb-gold: #E2CA92;
  --lb-glass: rgba(255, 255, 255, .10);
  --lb-glass-line: rgba(255, 255, 255, .18);
  --lb-side: 40px;
  --lb-chrome: 208px;

  position: fixed;
  inset: 0;
  z-index: 900;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  box-sizing: border-box;
  padding: clamp(18px, 2.2vw, 28px) clamp(20px, 3vw, 40px) clamp(22px, 3vw, 34px);
  background: rgba(10, 16, 26, .92);
  -webkit-backdrop-filter: blur(8px) saturate(120%);
  backdrop-filter: blur(8px) saturate(120%);
  color: #fff;
  opacity: 0;
  overscroll-behavior: contain;
  -webkit-tap-highlight-color: transparent;
  transition: opacity .28s cubic-bezier(.22, .61, .36, 1);
}
.lb[hidden] { display: none; }
.lb:focus { outline: none; }
.lb.is-open { opacity: 1; }

@supports (height: 100dvh) {
  .lb { --lb-vh: 100dvh; }
}

.lb *,
.lb *::before,
.lb *::after { box-sizing: border-box; }

/* ---------- Верхняя панель ---------- */
.lb__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 44px;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity .3s ease .06s, transform .34s cubic-bezier(.22, .61, .36, 1) .06s;
}
.lb.is-open .lb__top { opacity: 1; transform: none; }

.lb__counter {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--lb-glass-line);
  background: var(--lb-glass);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .04em;
  color: rgba(255, 255, 255, .78);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  user-select: none;
}
.lb__counter[hidden] { display: none; }

.lb__close {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--lb-glass-line);
  background: var(--lb-glass);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background .2s ease, border-color .2s ease, transform .2s cubic-bezier(.22, .61, .36, 1);
}
.lb__close:hover {
  background: rgba(255, 255, 255, .2);
  border-color: rgba(255, 255, 255, .42);
  transform: scale(1.06);
}
.lb__close:active { transform: scale(.96); }

/* ---------- Сцена ---------- */
.lb__stage {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 56px;
  align-items: center;
  justify-items: center;
  gap: clamp(10px, 2vw, 24px);
  min-height: 0;
  padding-top: clamp(12px, 1.6vw, 22px);
}

.lb__nav {
  width: 48px;
  height: 48px;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--lb-glass-line);
  background: var(--lb-glass);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background .2s ease, border-color .2s ease, transform .2s cubic-bezier(.22, .61, .36, 1), opacity .2s ease;
}
.lb__nav:hover {
  background: rgba(255, 255, 255, .2);
  border-color: rgba(255, 255, 255, .42);
  transform: scale(1.07);
}
.lb__nav:active { transform: scale(.95); }
.lb__nav[hidden] { display: none; }
.lb__nav--prev { grid-column: 1; }
.lb__nav--next { grid-column: 3; }

.lb__close:focus-visible,
.lb__nav:focus-visible {
  outline: 2px solid var(--lb-gold);
  outline-offset: 3px;
}

/* ---------- Фото + подпись ---------- */
.lb__figure {
  grid-column: 2;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  max-width: 100%;
  min-height: 0;
  opacity: .55;
  transform: scale(.965) translateY(10px);
  transition: opacity .28s ease, transform .36s cubic-bezier(.22, .61, .36, 1);
}
.lb.is-open .lb__figure { opacity: 1; transform: none; }
.lb__figure.is-dragging { transition: none; }

.lb__imgwrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  max-width: 100%;
}

.lb__img {
  display: block;
  max-width: min(92vw, 100%);
  max-height: min(86vh, calc(var(--lb-vh) - var(--lb-chrome)));
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 14px;
  background: rgba(255, 255, 255, .04);
  box-shadow: 0 30px 90px rgba(0, 0, 0, .55), 0 2px 10px rgba(0, 0, 0, .35);
  opacity: 1;
  transition: opacity .26s ease;
}
.lb__imgwrap.is-loading .lb__img { opacity: 0; }

.lb__caption {
  max-width: min(680px, 100%);
  text-align: center;
  padding: 0 4px;
}
.lb__caption[hidden] { display: none; }
.lb__title {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -.01em;
  color: #fff;
}
.lb__meta {
  margin-top: 6px;
  font-size: 13.5px;
  line-height: 1.45;
  color: rgba(255, 255, 255, .6);
}
.lb__meta:empty { display: none; }

/* ---------- Индикатор загрузки ---------- */
.lb__spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 38px;
  height: 38px;
  margin: -19px 0 0 -19px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .16);
  border-top-color: var(--lb-gold);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  animation: lb-spin .8s linear infinite;
}
.lb__imgwrap.is-loading .lb__spinner { opacity: 1; }

@keyframes lb-spin { to { transform: rotate(360deg); } }
@keyframes lb-pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

/* ---------- Планшет ---------- */
@media (max-width: 1024px) {
  .lb { --lb-chrome: 196px; }
  .lb__stage { grid-template-columns: 48px minmax(0, 1fr) 48px; }
  .lb__nav { width: 44px; height: 44px; }
}

/* ---------- Мобильный: свайп вместо стрелок ---------- */
@media (max-width: 720px) {
  .lb {
    --lb-chrome: 168px;
    --lb-side: 20px;
    padding: 16px 20px 22px;
  }
  .lb__stage {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding-top: 14px;
  }
  .lb__nav { display: none; }
  .lb__figure { grid-column: 1; gap: 14px; }
  .lb__img {
    max-width: calc(100vw - (var(--lb-side) * 2));
    border-radius: 12px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, .5);
  }
  .lb__title { font-size: 15.5px; }
  .lb__meta { margin-top: 4px; font-size: 12.5px; }
  .lb__counter { height: 32px; padding: 0 12px; font-size: 12.5px; }
}

@media (max-width: 420px) {
  .lb { --lb-chrome: 158px; }
  .lb__caption { max-width: 100%; }
}

/* ---------- Низкие экраны: подпись не должна теснить фото ---------- */
@media (max-height: 560px) {
  .lb { --lb-chrome: 150px; }
  .lb__figure { gap: 12px; }
}

/* ---------- Уважение к настройкам движения ---------- */
@media (prefers-reduced-motion: reduce) {
  .lb,
  .lb__top,
  .lb__figure,
  .lb__img,
  .lb__close,
  .lb__nav {
    transition-duration: .12s;
    transition-property: opacity, background-color, border-color;
  }
  .lb__top,
  .lb__figure { transform: none; }
  .lb__close:hover,
  .lb__close:active,
  .lb__nav:hover,
  .lb__nav:active { transform: none; }
  .lb__spinner {
    animation: lb-pulse 1.2s ease-in-out infinite;
    border-color: rgba(255, 255, 255, .16);
    border-top-color: var(--lb-gold);
  }
}
