.photo-viewer {
  position: fixed;
  inset: 0;
  z-index: 200;
  touch-action: none;
  overscroll-behavior: none;
}

.photo-viewer[hidden] {
  display: none !important;
}

.photo-viewer__scrim {
  position: absolute;
  inset: 0;
  border: 0;
  margin: 0;
  padding: 0;
  background: #000;
  cursor: zoom-out;
}

.photo-viewer__stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  pointer-events: none;
  transition: transform 0.22s ease;
}

.photo-viewer__stage.is-dragging {
  transition: none; /* палец ведет сцену сам */
}

.photo-viewer__img {
  pointer-events: auto;
  max-width: 100vw;
  max-height: 100vh;
  max-height: 100dvh;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: center center;
  will-change: transform;
  touch-action: none;
}

/* SW1: видео в лайтбоксе — нативные контролы, autoplay-safe (без автовоспроизведения) */
.photo-viewer__video {
  pointer-events: auto;
  width: 100vw;
  height: 100dvh;
  max-height: 100vh;
  object-fit: contain;
  background: #000;
  touch-action: none;
}

.photo-viewer__video[hidden] {
  display: none !important;
}

.photo-viewer__img[hidden] {
  display: none !important;
}

/* SW1: спиннер на загрузке кадра (shimmer не нужен — фон чёрный) */
.photo-viewer__spin {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.photo-viewer__spin[hidden] {
  display: none;
}

.photo-viewer__spin-dot,
.file-viewer__spin-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  animation: pv-spin 0.8s linear infinite;
}

@keyframes pv-spin {
  to {
    transform: rotate(360deg);
  }
}

/* SW1: верхняя панель — Скачать / Переслать / Поделиться / Закрыть */
.photo-viewer__topbar {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 6px;
}

.photo-viewer__pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.photo-viewer__pill svg {
  display: block;
}

.photo-viewer__pill:active {
  background: rgba(255, 255, 255, 0.28);
}

.photo-viewer__pill[hidden] {
  display: none;
}

/* M07: активное скачивание — кнопка становится индикатором прогресса/отмены */
.photo-viewer__pill.is-downloading {
  background: rgba(255, 255, 255, 0.3);
  cursor: progress;
}

.file-viewer__dl.is-downloading {
  cursor: progress;
  opacity: 0.9;
}

.photo-viewer__close {
  width: 44px;
  height: 44px;
  min-width: 36px;
  padding: 0;
  line-height: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  display: grid;
  grid-template: 1fr / 1fr;
  place-items: center;
  cursor: pointer;
}

.photo-viewer__close svg {
  display: block;
}

/* SW1: счётчик «3/17» — слева, не спорит с панелью действий справа */
.photo-viewer__counter {
  position: absolute;
  top: max(16px, env(safe-area-inset-top) + 6px);
  left: max(12px, env(safe-area-inset-left));
  z-index: 30;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}

.photo-viewer__caption {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 26;
  box-sizing: border-box;
  max-width: 640px;
  margin: 0 auto;
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 14px;
  line-height: 1.35;
  text-align: center;
  pointer-events: none;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.photo-viewer__broken {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 25;
  max-width: 340px;
  padding: 18px 22px;
  border-radius: 14px;
  background: rgba(12, 14, 20, 0.88);
  color: #fff;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.photo-viewer__broken strong {
  font-size: 15px;
}

.photo-viewer__broken span {
  font-size: 13px;
  opacity: 0.75;
  line-height: 1.45;
}

/* SW1: узкие экраны — текстовые кнопки сворачиваются в иконки */
@media (max-width: 480px) {
  .photo-viewer__pill span {
    display: none;
  }
  .photo-viewer__pill {
    width: 36px;
    justify-content: center;
    padding: 0;
  }
}

/* SW1: пикер пересылки */
.pv-fwd {
  position: fixed;
  inset: 0;
  z-index: 220;
}

.pv-fwd[hidden] {
  display: none !important;
}

.pv-fwd__scrim {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  background: rgba(0, 0, 0, 0.45);
  cursor: default;
}

.pv-fwd__sheet {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(440px, 100%);
  max-height: 72dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface, #fff);
  color: var(--text, #111);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -12px 40px rgba(15, 23, 42, 0.2);
  overflow: hidden;
  z-index: 2;
}

.pv-fwd__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  flex-shrink: 0;
}

.pv-fwd__head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.pv-fwd__close {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2, #eef1f6);
  color: var(--text, #111);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.pv-fwd__list {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 8px calc(14px + env(safe-area-inset-bottom, 0px));
}

.pv-fwd__row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.pv-fwd__row:hover {
  background: var(--surface-2, #eef1f6);
}

.pv-fwd__row.is-busy {
  opacity: 0.55;
  pointer-events: none;
}

.pv-fwd__ava {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

.pv-fwd__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 600;
}

.photo-viewer__prev,
.photo-viewer__next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 30;
  width: 48px;
  height: 48px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  line-height: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  display: grid;
  grid-template: 1fr / 1fr;
  place-items: center;
  cursor: pointer;
}

.photo-viewer__prev svg,
.photo-viewer__next svg {
  display: block;
}

.photo-viewer__prev {
  left: max(10px, env(safe-area-inset-left));
}

.photo-viewer__next {
  right: max(10px, env(safe-area-inset-right));
}

.photo-viewer__prev[hidden],
.photo-viewer__next[hidden] {
  display: none;
}

html.photo-viewer-open,
html.photo-viewer-open body,
html.file-viewer-open,
html.file-viewer-open body {
  overflow: hidden;
}

[data-vy-photo] {
  cursor: zoom-in;
  -webkit-tap-highlight-color: transparent;
}

/* In-app file/PDF viewer — PWA has no browser X */
.file-viewer {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  background: #0b0d12;
  overscroll-behavior: none;
}

.file-viewer[hidden] {
  display: none !important;
}

.file-viewer__scrim {
  position: absolute;
  inset: 0;
  border: 0;
  margin: 0;
  padding: 0;
  background: #0b0d12;
  cursor: default;
}

.file-viewer__bar {
  position: relative;
  z-index: 2;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
}

.file-viewer__title {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-viewer__dl {
  flex-shrink: 0;
  min-height: 44px;
  display: grid;
  place-items: center;
  padding: 0 12px;
  border-radius: 10px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  -webkit-appearance: none;
  appearance: none;
}

.file-viewer__close {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  line-height: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  display: grid;
  grid-template: 1fr / 1fr;
  place-items: center;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.file-viewer__close svg {
  display: block;
}

.file-viewer__stage {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  min-width: 0;
}

.file-viewer__frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.file-viewer__frame[hidden] {
  display: none;
}

/* M07: спиннер загрузки PDF в файловом вьювере */
.file-viewer__spin {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 5;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.file-viewer__spin[hidden] {
  display: none;
}

.file-viewer__fs {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  line-height: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  display: grid;
  grid-template: 1fr / 1fr;
  place-items: center;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.file-viewer__fs[hidden] {
  display: none;
}

.file-viewer__fs svg {
  display: block;
}

.file-viewer__fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  color: #fff;
}

.file-viewer__fallback[hidden] {
  display: none;
}

.file-viewer__fallback-name {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.file-viewer__fallback-hint {
  margin: 0;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.7);
}

@media (display-mode: standalone) {
  .photo-viewer__close,
  .file-viewer__close {
    width: 44px;
    height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .photo-viewer,
  .file-viewer {
    transition: none;
  }
}

.photo-viewer__pill{min-width:44px;min-height:44px;height:44px}
@media(max-width:640px){.photo-viewer__topbar{left:10px;right:10px;justify-content:flex-end;gap:4px}.photo-viewer__pill{padding:0;width:44px;flex:0 0 44px}.photo-viewer__pill>span{display:none}.photo-viewer__close{width:44px;height:44px;min-width:44px;min-height:44px}}

.photo-viewer [hidden],.file-viewer [hidden]{display:none!important}
