/*!
 * Lenso — стили
 * Вся кастомизация — через CSS-переменные ниже. Они объявлены в :where(.lenso)
 * (нулевая специфичность), поэтому любое ваше правило .lenso { --lenso-…: … }
 * переопределит их независимо от порядка подключения файлов.
 */

:where(.lenso) {
  /* Слой и шрифт */
  --lenso-z: 9999;
  --lenso-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Цвета */
  --lenso-bg: rgba(12, 13, 16, 0.94);
  --lenso-blur: 8px;
  --lenso-color: #f3f4f6;
  --lenso-muted: rgba(243, 244, 246, 0.62);
  --lenso-accent: #f39800;
  --lenso-accent-color: #111;

  /* Кнопки */
  --lenso-btn-size: 44px;
  --lenso-btn-radius: 999px;
  --lenso-btn-bg: rgba(255, 255, 255, 0.08);
  --lenso-btn-bg-hover: rgba(255, 255, 255, 0.18);
  --lenso-btn-color: var(--lenso-color);
  --lenso-icon-size: 22px;
  --lenso-nav-size: 52px;
  --lenso-nav-offset: 16px;

  /* Контент */
  --lenso-gap: 16px;                 /* отступ контента от краёв сцены */
  --lenso-radius: 6px;               /* скругление медиа */
  --lenso-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
  --lenso-media-bg: #000;            /* фон видео */
  --lenso-frame-bg: #fff;            /* фон iframe / pdf */
  --lenso-frame-width: 1100px;       /* макс. ширина iframe */
  --lenso-frame-height: 100%;        /* высота iframe */
  --lenso-pdf-width: 1000px;
  --lenso-video-width: 1280px;
  --lenso-embed-ratio: 16 / 9;

  /* Подпись */
  --lenso-caption-size: 14px;
  --lenso-caption-color: var(--lenso-muted);
  --lenso-caption-max: 900px;

  /* Миниатюры */
  --lenso-thumb-w: 76px;
  --lenso-thumb-h: 54px;
  --lenso-thumb-gap: 8px;
  --lenso-thumb-radius: 6px;
  --lenso-thumb-opacity: 0.45;
  --lenso-thumb-bg: rgba(255, 255, 255, 0.08);
  --lenso-thumb-active: var(--lenso-accent);

  /* Анимация */
  --lenso-duration: 280ms;
  --lenso-easing: cubic-bezier(0.2, 0.7, 0.2, 1);
  --lenso-shift: 80px;               /* сдвиг слайда при анимации slide */

  /* Спиннер */
  --lenso-spinner-size: 40px;
  --lenso-spinner-width: 3px;

  /* Слайд-шоу */
  --lenso-progress-height: 3px;
  --lenso-progress-color: var(--lenso-accent);

  /* Кнопка заявки */
  --lenso-cta-bg: var(--lenso-accent);
  --lenso-cta-color: var(--lenso-accent-color);
  --lenso-cta-radius: 999px;

  /* Обложка видео */
  --lenso-facade-play-size: 72px;
  --lenso-facade-play-bg: rgba(0, 0, 0, 0.6);

  /* PDF через pdf.js */
  --lenso-pdf-bg: #525659;
  --lenso-pdf-page-gap: 12px;

  /* Встроенный блок (#id) */
  --lenso-inline-width: 720px;
  --lenso-inline-bg: #fff;
  --lenso-inline-color: #1b1d22;
  --lenso-inline-padding: 28px;
}

/* ---------- Светлая тема (theme: 'light') ---------- */
.lenso--light {
  --lenso-bg: rgba(246, 247, 249, 0.96);
  --lenso-color: #15171c;
  --lenso-muted: rgba(21, 23, 28, 0.6);
  --lenso-btn-bg: rgba(0, 0, 0, 0.06);
  --lenso-btn-bg-hover: rgba(0, 0, 0, 0.12);
  --lenso-thumb-bg: rgba(0, 0, 0, 0.06);
  --lenso-shadow: 0 16px 48px rgba(0, 0, 0, 0.16);
}

/* ---------- Блокировка прокрутки страницы ---------- */
html.lenso-lock { overflow: hidden; }
html.lenso-lock body { padding-right: var(--lenso-scrollbar, 0px); }

/* ---------- Корень ---------- */
.lenso {
  position: fixed;
  inset: 0;
  z-index: var(--lenso-z);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  color: var(--lenso-color);
  font-family: var(--lenso-font);
  font-size: 14px;
  line-height: 1.4;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  opacity: 0;
  transition: opacity var(--lenso-duration) var(--lenso-easing);
}
.lenso.is-open { opacity: 1; }
.lenso.is-closing { opacity: 0; pointer-events: none; }
.lenso *, .lenso *::before, .lenso *::after { box-sizing: border-box; }
.lenso [hidden] { display: none !important; }

.lenso__backdrop {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--lenso-bg);
  -webkit-backdrop-filter: blur(var(--lenso-blur));
  backdrop-filter: blur(var(--lenso-blur));
}

/* ---------- Тулбар ---------- */
.lenso__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px 6px 18px;
  min-height: calc(var(--lenso-btn-size) + 16px);
}
.lenso__counter {
  font-variant-numeric: tabular-nums;
  color: var(--lenso-muted);
  letter-spacing: 0.02em;
}
.lenso__actions { display: flex; gap: 6px; margin-left: auto; }

/* ---------- Кнопки ---------- */
.lenso__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--lenso-btn-size);
  height: var(--lenso-btn-size);
  padding: 0;
  border: 0;
  border-radius: var(--lenso-btn-radius);
  background: var(--lenso-btn-bg);
  color: var(--lenso-btn-color);
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s, color 0.15s, opacity 0.15s, transform 0.15s;
}
.lenso__btn svg { width: var(--lenso-icon-size); height: var(--lenso-icon-size); display: block; }
.lenso__btn:hover { background: var(--lenso-btn-bg-hover); }
.lenso__btn:active { transform: scale(0.94); }
.lenso__btn:disabled { opacity: 0.3; cursor: default; transform: none; background: var(--lenso-btn-bg); }
.lenso__btn.is-active { background: var(--lenso-accent); color: var(--lenso-accent-color); }
.lenso__btn:focus-visible,
.lenso__thumb:focus-visible,
.lenso__pill:focus-visible { outline: 2px solid var(--lenso-accent); outline-offset: 2px; }

/* ---------- Сцена ---------- */
.lenso__main { position: relative; min-height: 0; }
.lenso__stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.lenso__stage.is-dragging,
.lenso__stage.is-dragging * { cursor: grabbing !important; }
.lenso__stage.is-dragging iframe { pointer-events: none; }

.lenso__nav,
.lenso__btn--prev,
.lenso__btn--next {
  position: absolute;
  top: 50%;
  z-index: 2;
  width: var(--lenso-nav-size);
  height: var(--lenso-nav-size);
  margin-top: calc(var(--lenso-nav-size) / -2);
}
.lenso__btn--prev { left: var(--lenso-nav-offset); }
.lenso__btn--next { right: var(--lenso-nav-offset); }
.lenso__btn--prev svg, .lenso__btn--next svg { width: 28px; height: 28px; }

.lenso__slide {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--lenso-gap) calc(var(--lenso-nav-size) + var(--lenso-nav-offset) * 2);
  container-type: size;
  transition: transform var(--lenso-duration) var(--lenso-easing), opacity var(--lenso-duration) var(--lenso-easing);
}
.lenso__content { position: relative; max-width: 100%; max-height: 100%; }

/* Изображение: размеры обёртки считает JS (вписывание, зум, поворот) */
.lenso__slide.lenso__slide--image { padding: 0; }
.lenso__slide--image .lenso__content {
  width: 100%;
  height: 100%;
  display: flex;
  overflow: auto;
  padding: var(--lenso-gap) calc(var(--lenso-nav-size) + var(--lenso-nav-offset) * 2);
  scrollbar-width: none;            /* без полос прокрутки — панорама перетаскиванием */
  -ms-overflow-style: none;
  overscroll-behavior: contain;
}
.lenso__slide--image .lenso__content::-webkit-scrollbar { display: none; }
.lenso__zoom {
  position: relative;
  flex: none;
  margin: auto;
}
.lenso__img {
  position: absolute;
  left: 50%;
  top: 50%;
  display: block;
  max-width: none;
  max-height: none;
  border-radius: var(--lenso-radius);
  box-shadow: var(--lenso-shadow);
  user-select: none;
  -webkit-user-drag: none;
  opacity: 0;
  transition: opacity var(--lenso-duration) var(--lenso-easing);
}
.lenso__slide.is-loaded .lenso__img { opacity: 1; }
.lenso__slide--image.is-loaded .lenso__zoom { cursor: zoom-in; }
.lenso__slide.is-zoomed .lenso__content,
.lenso__slide.is-zoomed .lenso__zoom { cursor: grab; }
.lenso__slide.is-zoomed .lenso__img { border-radius: 0; }

/* Видео-файл */
.lenso__slide--video .lenso__content { width: 100%; height: 100%; display: flex; }
.lenso__video {
  display: block;
  margin: auto;
  width: min(var(--lenso-item-width, var(--lenso-video-width)), 100%);
  max-height: 100%;
  background: var(--lenso-media-bg);
  border-radius: var(--lenso-radius);
  box-shadow: var(--lenso-shadow);
}

/* Видео-embed (YouTube / Vimeo) — вписывается в сцену с сохранением пропорций */
.lenso__slide--embed .lenso__content {
  width: min(var(--lenso-item-width, var(--lenso-video-width)), 100cqw, 100cqh * (var(--lenso-embed-ratio)));
  height: auto;
  aspect-ratio: var(--lenso-embed-ratio);
  background: var(--lenso-media-bg);
  border-radius: var(--lenso-radius);
  box-shadow: var(--lenso-shadow);
  overflow: hidden;
}

/* PDF и iframe */
.lenso__slide--pdf .lenso__content,
.lenso__slide--iframe .lenso__content {
  width: min(var(--lenso-item-width, var(--lenso-frame-width)), 100%);
  height: min(var(--lenso-item-height, var(--lenso-frame-height)), 100%);
  background: var(--lenso-frame-bg);
  border-radius: var(--lenso-radius);
  box-shadow: var(--lenso-shadow);
  overflow: hidden;
}
.lenso__slide--pdf .lenso__content { width: min(var(--lenso-item-width, var(--lenso-pdf-width)), 100%); }
.lenso__slide--fallback .lenso__content {
  width: auto;
  height: auto;
  background: none;
  box-shadow: none;
  overflow: visible;
}
.lenso__frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--lenso-frame-bg);
}
.lenso__slide--embed .lenso__frame { background: var(--lenso-media-bg); }

/* Обложка YouTube / Vimeo — плеер грузится по клику */
.lenso__facade {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: var(--lenso-media-bg);
  cursor: pointer;
}
.lenso__facade img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.lenso__facade-play {
  position: absolute;
  top: 50%;
  left: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--lenso-facade-play-size);
  height: var(--lenso-facade-play-size);
  margin: calc(var(--lenso-facade-play-size) / -2) 0 0 calc(var(--lenso-facade-play-size) / -2);
  border-radius: 50%;
  background: var(--lenso-facade-play-bg);
  color: #fff;
  transition: background-color 0.15s, transform 0.15s;
}
.lenso__facade-play svg { width: 44%; height: 44%; margin-left: 6%; }
.lenso__facade:hover .lenso__facade-play { background: var(--lenso-accent); color: var(--lenso-accent-color); transform: scale(1.06); }
.lenso__facade:focus-visible { outline: 2px solid var(--lenso-accent); outline-offset: -2px; }

/* Зоны со своей прокруткой (pdf.js, встроенный блок) */
.lenso__scroll {
  overflow: auto;
  touch-action: pan-x pan-y pinch-zoom;
  overscroll-behavior: contain;
  user-select: text;
  -webkit-user-select: text;
}

/* PDF через pdf.js */
.lenso__slide--pdfjs .lenso__content { background: var(--lenso-pdf-bg); }
.lenso__pdfjs {
  width: 100%;
  height: 100%;
  padding: var(--lenso-pdf-page-gap);
}
.lenso__pdf-page {
  position: relative;
  width: 100%;
  margin: 0 auto var(--lenso-pdf-page-gap);
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
.lenso__pdf-page canvas { display: block; width: 100%; height: 100%; }

/* Встроенный блок со страницы (#id) */
:is(.lenso__slide--inline, .lenso__slide--html, .lenso__slide--ajax) .lenso__content {
  width: min(var(--lenso-item-width, var(--lenso-inline-width)), 100%);
  height: var(--lenso-item-height, auto);
  max-height: 100%;
  padding: var(--lenso-inline-padding);
  background: var(--lenso-inline-bg);
  color: var(--lenso-inline-color);
  border-radius: var(--lenso-radius);
  box-shadow: var(--lenso-shadow);
  font-size: 15px;
  line-height: 1.55;
}

/* ---------- Состояния ---------- */
.lenso__spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--lenso-spinner-size);
  height: var(--lenso-spinner-size);
  margin: calc(var(--lenso-spinner-size) / -2) 0 0 calc(var(--lenso-spinner-size) / -2);
  border: var(--lenso-spinner-width) solid var(--lenso-btn-bg-hover);
  border-top-color: var(--lenso-accent);
  border-radius: 50%;
  animation: lenso-spin 0.8s linear infinite;
  pointer-events: none;
}
.lenso__slide.is-loading .lenso__frame { opacity: 0; }

.lenso__error,
.lenso__fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 420px;
  padding: 32px 28px;
  margin: auto;
  text-align: center;
  color: var(--lenso-color);
  background: var(--lenso-btn-bg);
  border-radius: calc(var(--lenso-radius) * 2);
}
.lenso__error svg { width: 40px; height: 40px; color: var(--lenso-muted); }
.lenso__error p,
.lenso__fallback-text { margin: 0; color: var(--lenso-muted); }
.lenso__fallback-icon svg { width: 56px; height: 56px; color: var(--lenso-accent); }
.lenso__fallback-title { font-size: 16px; font-weight: 600; word-break: break-word; }
.lenso__fallback-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 8px; }

.lenso__pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border-radius: 999px;
  background: var(--lenso-btn-bg-hover);
  color: var(--lenso-color);
  font-weight: 500;
  text-decoration: none;
}
.lenso__pill svg { width: 18px; height: 18px; }
.lenso__pill--primary { background: var(--lenso-accent); color: var(--lenso-accent-color); }

/* ---------- Подпись ---------- */
.lenso__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 16px;
  padding: 8px 20px 4px;
}
.lenso__caption {
  max-width: min(var(--lenso-caption-max), 100%);
  text-align: center;
  font-size: var(--lenso-caption-size);
  color: var(--lenso-caption-color);
}
.lenso__cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 18px;
  border-radius: var(--lenso-cta-radius);
  background: var(--lenso-cta-bg);
  color: var(--lenso-cta-color);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: filter 0.15s, transform 0.15s;
}
.lenso__cta svg { width: 18px; height: 18px; }
.lenso__cta:hover { filter: brightness(1.08); }
.lenso__cta:active { transform: scale(0.97); }
.lenso__cta:focus-visible { outline: 2px solid var(--lenso-color); outline-offset: 2px; }

/* ---------- Слайд-шоу ---------- */
.lenso__progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  height: var(--lenso-progress-height);
  opacity: 0;
  pointer-events: none;
}
.lenso__progress span {
  display: block;
  height: 100%;
  background: var(--lenso-progress-color);
  transform: scaleX(0);
  transform-origin: left;
}
.lenso.is-playing .lenso__progress { opacity: 1; }

/* ---------- Скрытый интерфейс (тап по фото на телефоне) ---------- */
.lenso__toolbar,
.lenso__footer,
.lenso__thumbs,
.lenso__btn--prev,
.lenso__btn--next { transition: opacity var(--lenso-duration) var(--lenso-easing); }
.lenso.is-ui-hidden .lenso__toolbar,
.lenso.is-ui-hidden .lenso__footer,
.lenso.is-ui-hidden .lenso__thumbs,
.lenso.is-ui-hidden .lenso__btn--prev,
.lenso.is-ui-hidden .lenso__btn--next { opacity: 0; pointer-events: none; }

/* ---------- Миниатюры ---------- */
.lenso__thumbs {
  display: flex;
  gap: var(--lenso-thumb-gap);
  padding: 10px 16px 14px;
  overflow-x: auto;
  scrollbar-width: none;
  /* центрирование, но с возможностью прокрутки при переполнении */
  justify-content: safe center;
}
.lenso__thumbs::-webkit-scrollbar { display: none; }
.lenso__thumb {
  position: relative;
  flex: 0 0 auto;
  width: var(--lenso-thumb-w);
  height: var(--lenso-thumb-h);
  padding: 0;
  border: 0;
  border-radius: var(--lenso-thumb-radius);
  background: var(--lenso-thumb-bg);
  color: var(--lenso-color);
  overflow: hidden;
  cursor: pointer;
  opacity: var(--lenso-thumb-opacity);
  transition: opacity 0.15s, box-shadow 0.15s;
}
.lenso__thumb:hover { opacity: 0.85; }
.lenso__thumb[aria-selected="true"] { opacity: 1; box-shadow: inset 0 0 0 2px var(--lenso-thumb-active); }
.lenso__thumb img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.lenso__thumb[aria-selected="true"] img { outline: 2px solid var(--lenso-thumb-active); outline-offset: -2px; border-radius: var(--lenso-thumb-radius); }
.lenso__thumb-icon,
.lenso__thumb-badge {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lenso__thumb-icon svg { width: 24px; height: 24px; }
.lenso__thumb--pdf .lenso__thumb-icon { color: var(--lenso-accent); }
.lenso__thumb-badge svg {
  width: 22px;
  height: 22px;
  padding: 3px;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 50%;
}

/* ---------- Заглушка из миниатюры, пока грузится большое фото ---------- */
.lenso__ph {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* миниатюра — обычно центральная часть фото: вписываем без дообрезки, чтобы при подмене
     на настоящее фото изображение не прыгало по масштабу */
  object-fit: contain;
  transition: opacity var(--lenso-duration) ease;
  pointer-events: none;
  user-select: none;
}
.lenso__slide.is-loaded .lenso__ph { opacity: 0; }
.lenso__slide.has-ph .lenso__spinner { opacity: 0; animation-delay: 1s; }

/* ---------- Лента: соседние слайды при свайпе ---------- */
.lenso__slide.is-peek { pointer-events: none; }
.lenso__slide--ghost { display: flex; align-items: center; justify-content: center; }
.lenso__ghost { max-width: 72%; max-height: 72%; border-radius: var(--lenso-radius); box-shadow: var(--lenso-shadow); }
.lenso__ghost-icon svg { width: 56px; height: 56px; color: var(--lenso-muted); }

/* ---------- Анимация «в миниатюру» при закрытии ---------- */
.lenso.is-morphing { pointer-events: none; }

/* ---------- Автоскрытие интерфейса (мышь без движения) ---------- */
.lenso.is-idle .lenso__toolbar,
.lenso.is-idle .lenso__footer,
.lenso.is-idle .lenso__thumbs,
.lenso.is-idle .lenso__btn--prev,
.lenso.is-idle .lenso__btn--next { opacity: 0; pointer-events: none; }
.lenso.is-idle .lenso__stage,
.lenso.is-idle .lenso__stage * { cursor: none !important; }

/* ---------- Письмо справа налево ---------- */
.lenso[dir="rtl"] .lenso__btn--prev { left: auto; right: var(--lenso-nav-offset); }
.lenso[dir="rtl"] .lenso__btn--next { right: auto; left: var(--lenso-nav-offset); }
.lenso[dir="rtl"] .lenso__btn--prev svg,
.lenso[dir="rtl"] .lenso__btn--next svg { transform: scaleX(-1); }
.lenso[dir="rtl"] .lenso__progress span { transform-origin: right; }

/* ---------- Анимации слайдов ---------- */
.lenso__slide.is-entering { animation: lenso-in var(--lenso-duration) var(--lenso-easing) both; }
.lenso__slide.is-leaving { animation: lenso-out var(--lenso-duration) var(--lenso-easing) both; pointer-events: none; }
.lenso--anim-fade { --lenso-shift: 0px; }

@keyframes lenso-in {
  from { opacity: 0; transform: translateX(calc(var(--lenso-dir, 1) * var(--lenso-shift))); }
  to { opacity: 1; transform: none; }
}
@keyframes lenso-out {
  from { opacity: 1; transform: translateX(var(--lenso-drag, 0px)); }
  to { opacity: 0; transform: translateX(calc(var(--lenso-drag, 0px) + var(--lenso-dir, 1) * var(--lenso-shift) * -1)); }
}
@keyframes lenso-spin { to { transform: rotate(360deg); } }

/* ---------- Полноэкранный режим ---------- */
.lenso.is-fullscreen .lenso__thumbs { display: none; }

/* ---------- Адаптив ---------- */
@media (max-width: 640px) {
  :where(.lenso) {
    --lenso-gap: 8px;
    --lenso-btn-size: 40px;
    --lenso-nav-size: 40px;
    --lenso-nav-offset: 6px;
    --lenso-thumb-w: 56px;
    --lenso-thumb-h: 42px;
  }
  .lenso__toolbar { padding: 6px 8px 4px 14px; }
  .lenso__slide { padding: var(--lenso-gap); }
  .lenso__slide--image .lenso__content { padding: var(--lenso-gap); }
  :where(.lenso) { --lenso-inline-padding: 18px; }
  .lenso__footer { padding: 6px 12px 2px; }
  .lenso__btn--prev, .lenso__btn--next { background: rgba(0, 0, 0, 0.35); color: #fff; }
  .lenso__btn--fullscreen { display: none; }
}

@media (hover: none) and (pointer: coarse) {
  /* на тач-устройствах навигация свайпом, стрелки можно скрыть темой */
  .lenso__btn:hover { background: var(--lenso-btn-bg); }
}

@media (prefers-reduced-motion: reduce) {
  :where(.lenso) { --lenso-duration: 1ms; --lenso-shift: 0px; }
  .lenso__spinner { animation-duration: 1.6s; }
}
