/* =========================================================
   NEW.MD — GALLERY VIEWER V2
   ---------------------------------------------------------
   Полностью автономный CSS.
   Не зависит от старой nm-product-gallery.
   ========================================================= */


/* ---------- ROOT ---------- */

.nm-gallery-v2 {
  --nm-gv2-accent: #6d3df5;
  --nm-gv2-accent-soft: rgba(109, 61, 245, 0.10);
  --nm-gv2-border: #e6eaf0;
  --nm-gv2-border-strong: #d8dee8;
  --nm-gv2-bg: #ffffff;
  --nm-gv2-soft: #f7f8fb;
  --nm-gv2-text: #172033;
  --nm-gv2-muted: #6f7785;

  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 14px;

  width: 100%;
  min-width: 0;
}


/* =========================================================
   THUMBNAILS
   ========================================================= */

.nm-gallery-v2__thumbs {
  display: flex;
  flex-direction: column;
  gap: 9px;

  width: 84px;
  height: clamp(440px, 38vw, 500px);
  max-height: none;

  padding: 1px 4px 1px 1px;

  overflow-x: hidden;
  overflow-y: auto;

  scrollbar-width: thin;
  scrollbar-color: #b9bec8 transparent;
}

.nm-gallery-v2__thumbs::-webkit-scrollbar {
  width: 5px;
}

.nm-gallery-v2__thumbs::-webkit-scrollbar-track {
  background: transparent;
}

.nm-gallery-v2__thumbs::-webkit-scrollbar-thumb {
  background: #b9bec8;
  border-radius: 999px;
}


/* ---------- THUMB ---------- */

.nm-gallery-v2__thumb {
  position: relative;

  flex: 0 0 auto;

  width: 76px;
  height: 76px;

  padding: 0;

  border: 1px solid var(--nm-gv2-border);
  border-radius: 13px;

  background: var(--nm-gv2-bg);

  overflow: hidden;

  cursor: pointer;

  appearance: none;
  -webkit-appearance: none;

  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.nm-gallery-v2__thumb:hover {
  border-color: #bfc7d4;
  transform: translateY(-1px);
}

.nm-gallery-v2__thumb:focus-visible {
  outline: 3px solid rgba(109, 61, 245, 0.22);
  outline-offset: 2px;
}


/* Активная миниатюра.
   JS позже будет ставить .is-active + aria-current */

.nm-gallery-v2__thumb.is-active,
.nm-gallery-v2__thumb[aria-current="true"] {
  border-color: var(--nm-gv2-accent);

  box-shadow:
    0 0 0 2px var(--nm-gv2-accent-soft),
    0 5px 15px rgba(25, 32, 50, 0.08);
}


.nm-gallery-v2__thumb img {
  display: block;

  width: 100%;
  height: 100%;

  object-fit: cover;

  user-select: none;
  -webkit-user-drag: none;
}


/* ---------- VIDEO THUMB ---------- */

.nm-gallery-v2__thumb--video::after {
  content: "";

  position: absolute;
  inset: 0;

  background:
    linear-gradient(
      to top,
      rgba(0, 0, 0, 0.22),
      rgba(0, 0, 0, 0.02) 55%
    );

  pointer-events: none;
}

.nm-gallery-v2__video-placeholder {
  display: block;

  width: 100%;
  height: 100%;

  background:
    radial-gradient(
      circle at 50% 35%,
      #eef1f6,
      #dde2ea
    );
}

.nm-gallery-v2__play {
  position: absolute;
  left: 50%;
  top: 50%;

  z-index: 2;

  display: grid;
  place-items: center;

  width: 34px;
  height: 34px;

  padding-left: 2px;

  border-radius: 50%;

  color: #ffffff;
  background: rgba(17, 24, 39, 0.78);

  font-size: 14px;
  line-height: 1;

  transform: translate(-50%, -50%);

  pointer-events: none;

  box-shadow:
    0 5px 16px rgba(0, 0, 0, 0.20);
}


/* =========================================================
   MAIN STAGE
   ========================================================= */

.nm-gallery-v2__stage {
  position: relative;

  min-width: 0;

  width: 100%;

  /*
    Стабильная зона:
    смена вертикального / горизонтального фото
    не меняет высоту всей страницы.
  */
  height: clamp(440px, 38vw, 500px);
  aspect-ratio: auto;

  max-height: none;

  display: flex;
  align-items: center;
  justify-content: center;

  overflow: hidden;

  border: 1px solid var(--nm-gv2-border);
  border-radius: 18px;

  background:
    linear-gradient(
      180deg,
      #ffffff 0%,
      #fcfcfd 100%
    );
}


/* ---------- IMAGE OPEN BUTTON ---------- */

.nm-gallery-v2__stage-open {
  position: absolute;
  inset: 0;

  z-index: 1;

  display: flex;
  align-items: center;
  justify-content: center;

  width: 100%;
  height: 100%;

  padding: 18px;

  border: 0;

  background: transparent;

  cursor: zoom-in;

  appearance: none;
  -webkit-appearance: none;
}

.nm-gallery-v2__stage-open:focus-visible {
  outline: 3px solid rgba(109, 61, 245, 0.25);
  outline-offset: -4px;
}


/* ---------- MAIN MEDIA ---------- */

.nm-gallery-v2__media {
  max-width: 100%;
  max-height: 100%;
}

.nm-gallery-v2__media--image {
  display: block;

  width: 100%;
  height: 100%;

  object-fit: contain;

  user-select: none;
  -webkit-user-drag: none;
}


/* Видео не вкладываем в zoom button */

.nm-gallery-v2__media--video {
  position: relative;

  z-index: 2;

  width: 100%;
  height: 100%;

  object-fit: contain;

  background: #000;
}


/* =========================================================
   STAGE ARROWS
   ========================================================= */

.nm-gallery-v2__arrow {
  position: absolute;
  top: 50%;

  z-index: 5;

  display: grid;
  place-items: center;

  width: 42px;
  height: 42px;

  padding: 0;

  border: 0;
  border-radius: 50%;

  color: #ffffff;
  background: rgba(47, 55, 70, 0.64);

  font-family: Arial, sans-serif;
  font-size: 31px;
  font-weight: 300;
  line-height: 1;

  cursor: pointer;

  transform: translateY(-50%);

  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);

  box-shadow:
    0 5px 18px rgba(0, 0, 0, 0.12);

  transition:
    background 160ms ease,
    transform 160ms ease,
    opacity 160ms ease;
}

.nm-gallery-v2__arrow:hover {
  background: rgba(31, 38, 50, 0.82);
}

.nm-gallery-v2__arrow:active {
  transform: translateY(-50%) scale(0.96);
}

.nm-gallery-v2__arrow:focus-visible {
  outline: 3px solid rgba(109, 61, 245, 0.35);
  outline-offset: 2px;
}

.nm-gallery-v2__arrow--prev {
  left: 12px;
}

.nm-gallery-v2__arrow--next {
  right: 12px;
}


/* =========================================================
   COUNTER
   ========================================================= */

.nm-gallery-v2__counter {
  position: absolute;
  right: 12px;
  bottom: 12px;

  z-index: 6;

  min-width: 50px;

  padding: 6px 10px;

  border-radius: 999px;

  color: #ffffff;
  background: rgba(27, 33, 43, 0.68);

  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;

  text-align: center;

  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);

  pointer-events: none;
}


/* =========================================================
   FULLSCREEN
   ========================================================= */

.nm-gallery-v2__fullscreen {
  position: fixed;
  inset: 0;

  z-index: 99999;

  display: flex;
  align-items: center;
  justify-content: center;

  width: 100vw;
  height: 100dvh;

  padding:
    max(22px, env(safe-area-inset-top))
    max(68px, env(safe-area-inset-right))
    max(22px, env(safe-area-inset-bottom))
    max(68px, env(safe-area-inset-left));

  background: rgba(10, 12, 17, 0.96);

  overflow: hidden;

  overscroll-behavior: contain;
}


/*
  HTML hidden всегда должен иметь приоритет,
  даже если fullscreen имеет display:flex.
*/
.nm-gallery-v2__fullscreen[hidden],
.nm-gallery-v2 [hidden] {
  display: none !important;
}


/* ---------- FULLSCREEN STAGE ---------- */

.nm-gallery-v2__fullscreen-stage {
  position: relative;

  display: flex;
  align-items: center;
  justify-content: center;

  width: 100%;
  height: 100%;

  min-width: 0;
  min-height: 0;
}


/* НИКАКОГО растягивания */

.nm-gallery-v2__fullscreen-image {
  display: block;

  width: auto;
  height: auto;

  max-width: 100%;
  max-height: 100%;

  object-fit: contain;

  user-select: none;
  -webkit-user-drag: none;
}

.nm-gallery-v2__fullscreen-video {
  width: auto;
  height: auto;

  max-width: 100%;
  max-height: 100%;

  object-fit: contain;

  background: #000;
}


/* ---------- CLOSE ---------- */

.nm-gallery-v2__fullscreen-close {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  right: max(20px, env(safe-area-inset-right));

  z-index: 10;

  display: grid;
  place-items: center;

  width: 46px;
  height: 46px;

  padding: 0;

  border: 0;
  border-radius: 50%;

  color: #ffffff;
  background: rgba(255, 255, 255, 0.10);

  font-family: Arial, sans-serif;
  font-size: 32px;
  font-weight: 300;
  line-height: 1;

  cursor: pointer;

  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);

  transition:
    background 160ms ease,
    transform 160ms ease;
}

.nm-gallery-v2__fullscreen-close:hover {
  background: rgba(255, 255, 255, 0.18);
}

.nm-gallery-v2__fullscreen-close:active {
  transform: scale(0.95);
}


/* ---------- FULLSCREEN ARROWS ---------- */

.nm-gallery-v2__fullscreen-arrow {
  position: absolute;
  top: 50%;

  z-index: 10;

  display: grid;
  place-items: center;

  width: 50px;
  height: 50px;

  padding: 0;

  border: 0;
  border-radius: 50%;

  color: #ffffff;
  background: rgba(255, 255, 255, 0.10);

  font-family: Arial, sans-serif;
  font-size: 38px;
  font-weight: 300;
  line-height: 1;

  cursor: pointer;

  transform: translateY(-50%);

  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);

  transition:
    background 160ms ease,
    transform 160ms ease;
}

.nm-gallery-v2__fullscreen-arrow:hover {
  background: rgba(255, 255, 255, 0.18);
}

.nm-gallery-v2__fullscreen-arrow:active {
  transform: translateY(-50%) scale(0.95);
}

.nm-gallery-v2__fullscreen-arrow--prev {
  left: max(16px, env(safe-area-inset-left));
}

.nm-gallery-v2__fullscreen-arrow--next {
  right: max(16px, env(safe-area-inset-right));
}


/* ---------- FULLSCREEN COUNTER ---------- */

.nm-gallery-v2__fullscreen-counter {
  position: absolute;

  left: 50%;
  top: max(22px, env(safe-area-inset-top));

  z-index: 10;

  padding: 7px 13px;

  border-radius: 999px;

  color: #ffffff;
  background: rgba(255, 255, 255, 0.10);

  font-size: 13px;
  font-weight: 600;

  transform: translateX(-50%);

  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);

  pointer-events: none;
}


/* =========================================================
   TABLET
   ========================================================= */

@media (max-width: 991.98px) {

  .nm-gallery-v2 {
    grid-template-columns: 74px minmax(0, 1fr);
    gap: 10px;
  }

  .nm-gallery-v2__thumbs {
    width: 74px;
    max-height: 480px;
  }

  .nm-gallery-v2__thumb {
    width: 68px;
    height: 68px;

    border-radius: 11px;
  }

  .nm-gallery-v2__stage {
    max-height: 480px;
    border-radius: 16px;
  }

}


/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 767.98px) {

  .nm-gallery-v2 {
    display: flex;
    flex-direction: column;

    gap: 10px;
  }


  /* Основное фото сначала */

  .nm-gallery-v2__stage {
    order: 1;

    width: 100%;
    height: auto;
    max-height: none;

    aspect-ratio: 1 / 1;

    border-radius: 14px;
  }


  /* Миниатюры снизу горизонтально */

  .nm-gallery-v2__thumbs {
    order: 2;

    flex-direction: row;

    width: 100%;
    height: auto;
    max-height: none;

    padding: 2px 2px 5px;

    overflow-x: auto;
    overflow-y: hidden;

    scroll-snap-type: x proximity;

    scrollbar-width: none;
  }

  .nm-gallery-v2__thumbs::-webkit-scrollbar {
    display: none;
  }

  .nm-gallery-v2__thumb {
    width: 64px;
    height: 64px;

    border-radius: 11px;

    scroll-snap-align: start;
  }


  .nm-gallery-v2__stage-open {
    padding: 10px;
  }


  .nm-gallery-v2__arrow {
    width: 38px;
    height: 38px;

    font-size: 28px;
  }

  .nm-gallery-v2__arrow--prev {
    left: 8px;
  }

  .nm-gallery-v2__arrow--next {
    right: 8px;
  }


  .nm-gallery-v2__counter {
    right: 8px;
    bottom: 8px;

    padding: 5px 9px;
  }


  /* FULLSCREEN MOBILE */

  .nm-gallery-v2__fullscreen {
    padding:
      max(58px, env(safe-area-inset-top))
      8px
      max(54px, env(safe-area-inset-bottom))
      8px;
  }

  .nm-gallery-v2__fullscreen-close {
    width: 42px;
    height: 42px;

    top: max(10px, env(safe-area-inset-top));
    right: 10px;

    font-size: 29px;
  }

  .nm-gallery-v2__fullscreen-arrow {
    width: 42px;
    height: 42px;

    font-size: 31px;

    background: rgba(20, 24, 31, 0.46);
  }

  .nm-gallery-v2__fullscreen-arrow--prev {
    left: 7px;
  }

  .nm-gallery-v2__fullscreen-arrow--next {
    right: 7px;
  }

  .nm-gallery-v2__fullscreen-counter {
    top: max(15px, env(safe-area-inset-top));
  }

}


/* =========================================================
   VERY SMALL PHONES
   ========================================================= */

@media (max-width: 390px) {

  .nm-gallery-v2__thumb {
    width: 58px;
    height: 58px;
  }

  .nm-gallery-v2__arrow {
    width: 36px;
    height: 36px;
  }

}


/* =========================================================
   REDUCED MOTION
   ========================================================= */

@media (prefers-reduced-motion: reduce) {

  .nm-gallery-v2 *,
  .nm-gallery-v2 *::before,
  .nm-gallery-v2 *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }

}


/* =========================================================
   FULLSCREEN FILMSTRIP
   ========================================================= */

.nm-gallery-v2__fullscreen-thumbs {
  position: absolute;

  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));

  z-index: 12;

  display: flex;
  align-items: center;
  gap: 8px;

  max-width: min(760px, calc(100vw - 150px));

  padding: 7px;

  overflow-x: auto;
  overflow-y: hidden;

  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;

  background: rgba(20, 23, 30, 0.72);

  transform: translateX(-50%);

  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);

  scrollbar-width: none;

  scroll-behavior: smooth;
}

.nm-gallery-v2__fullscreen-thumbs::-webkit-scrollbar {
  display: none;
}


.nm-gallery-v2__fullscreen-thumb {
  position: relative;

  flex: 0 0 auto;

  width: 58px;
  height: 58px;

  padding: 0;

  overflow: hidden;

  border: 2px solid transparent;
  border-radius: 10px;

  background: #11151c;

  opacity: 0.72;

  cursor: pointer;

  appearance: none;
  -webkit-appearance: none;

  transition:
    opacity 150ms ease,
    border-color 150ms ease,
    transform 150ms ease;
}


.nm-gallery-v2__fullscreen-thumb:hover {
  opacity: 1;
}


.nm-gallery-v2__fullscreen-thumb.is-active,
.nm-gallery-v2__fullscreen-thumb[aria-current="true"] {
  opacity: 1;

  border-color: #8b63ff;

  transform: translateY(-2px);

  box-shadow:
    0 0 0 2px rgba(139, 99, 255, 0.22);
}


.nm-gallery-v2__fullscreen-thumb img {
  display: block;

  width: 100%;
  height: 100%;

  object-fit: cover;

  user-select: none;
  -webkit-user-drag: none;
}


.nm-gallery-v2__fullscreen-thumb-play {
  position: absolute;
  left: 50%;
  top: 50%;

  z-index: 2;

  display: grid;
  place-items: center;

  width: 25px;
  height: 25px;

  padding-left: 1px;

  border-radius: 50%;

  color: #fff;
  background: rgba(10, 13, 18, 0.76);

  font-size: 10px;
  line-height: 1;

  transform: translate(-50%, -50%);

  pointer-events: none;
}


/* Оставляем место снизу под filmstrip */

.nm-gallery-v2__fullscreen {
  padding-bottom: max(100px, env(safe-area-inset-bottom));
}


/* =========================================================
   FULLSCREEN FILMSTRIP — MOBILE
   ========================================================= */

@media (max-width: 767.98px) {

  .nm-gallery-v2__fullscreen {
    padding-bottom: max(86px, env(safe-area-inset-bottom));
  }


  .nm-gallery-v2__fullscreen-thumbs {
    bottom: max(8px, env(safe-area-inset-bottom));

    gap: 6px;

    width: calc(100vw - 16px);
    max-width: none;

    padding: 6px;

    border-radius: 13px;
  }


  .nm-gallery-v2__fullscreen-thumb {
    width: 50px;
    height: 50px;

    border-radius: 9px;
  }


  .nm-gallery-v2__fullscreen-thumb-play {
    width: 22px;
    height: 22px;

    font-size: 9px;
  }

}
