/* Полноэкранный просмотрщик и плитки-превью в сообщениях. */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: #0c0c0b;
  color: #f2efe8;
  color-scheme: dark;
  overflow: hidden;
}

.viewer[hidden] {
  display: none;
}

/* Верхняя панель */

.viewer-bar {
  position: relative;
  z-index: 2;
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 12px) 8px calc(env(safe-area-inset-left) + 12px);
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.viewer-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 14px;
}

.viewer-count {
  flex: none;
  font-size: 13px;
  opacity: 0.8;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.viewer-tools {
  display: flex;
  gap: 6px;
}

.viewer-tools button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 18px;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.viewer-tools button[aria-pressed="true"] {
  background: #d97757;
  border-color: #d97757;
  color: #fff;
}

/* Кнопки панели и навигации */

.viewer-btn {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: opacity 0.15s, background-color 0.15s;
}

.viewer-btn:hover {
  background: rgba(255, 255, 255, 0.24);
}

.viewer-btn:active {
  background: rgba(255, 255, 255, 0.32);
}

.viewer-close {
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.22);
  font-size: 26px;
}

.viewer-close:hover {
  background: rgba(255, 255, 255, 0.34);
}

/* Сцена */

.viewer-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
}

.viewer-slide {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewer-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
  transform-origin: center;
}

.viewer-stl {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 50% 40%, #2a2d34, #14151a);
}

.viewer-status {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 1;
  transform: translate(-50%, -50%);
  padding: 8px 14px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.6);
  color: #f2efe8;
  font-size: 14px;
  pointer-events: none;
}

.viewer-status[hidden] {
  display: none;
}

/* Стрелки навигации */

.viewer-nav {
  position: absolute;
  top: 50%;
  z-index: 3;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  transition: opacity 0.15s;
}

.viewer-nav.prev {
  left: calc(env(safe-area-inset-left) + 8px);
}

.viewer-nav.next {
  right: calc(env(safe-area-inset-right) + 8px);
}

.viewer-nav[hidden] {
  display: none;
}

@media (hover: none) {
  .viewer-nav {
    opacity: 0.7;
  }
}

/* Плитки-превью в сообщениях */

.gal-row {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 8px;
  margin: 6px 0;
}

.gal-item {
  display: inline-flex;
  vertical-align: top;
  margin: 0;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--code);
  color: inherit;
  text-decoration: none;
  cursor: zoom-in;
  -webkit-tap-highlight-color: transparent;
}

.md .gal-item img {
  display: block;
  width: auto;
  height: 110px;
  min-width: 60px;
  max-width: min(200px, 60vw);
  object-fit: cover;
  margin: 0;
  border: 0;
  border-radius: 0;
}

.gal-stl,
.gal-src {
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  max-width: min(280px, 80vw);
}

.gal-stl .gal-txt,
.gal-src .gal-txt {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.gal-src {
  cursor: pointer;
}

.gal-ico {
  display: inline-flex;
  flex: none;
  line-height: 1;
  color: var(--text, inherit);
}

.gal-ico svg {
  display: block;
}

.gal-name {
  font-weight: 500;
  font-size: 13px;
  line-height: 1.3;
  color: var(--text, inherit);
  overflow-wrap: anywhere;
}

/* Заголовок источника — не больше двух строк, остальное многоточием */
.gal-src .gal-name {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.gal-meta {
  font-size: 11px;
  line-height: 1.3;
  color: var(--muted);
}

.gal-item:hover {
  border-color: var(--accent);
}

.gal-item:focus-visible,
.viewer-btn:focus-visible,
.viewer-nav:focus-visible,
.viewer-tools button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Без анимаций для пользователей с reduced motion */

@media (prefers-reduced-motion: reduce) {
  .viewer-btn,
  .viewer-nav,
  .viewer-tools button {
    transition: none;
    animation: none;
  }
}

/* Полоса кнопок: компактные круглые, без переноса текста */
.viewer-dl {
  width: 40px;
  height: 40px;
  font-size: 20px;
}

.viewer-close {
  width: 40px;
  height: 40px;
  font-size: 20px;
}

.viewer-tools button {
  white-space: nowrap;
}

/* STL-плитка в превью модалки материалов */
.materials-modal-stl { display: inline-flex; }

/* Текстовые кнопки: не круглые, ширина по содержимому (перекрывают .viewer-btn) */
.viewer-tools .viewer-btn,
.viewer-retry {
  width: auto;
  min-width: 0;
  height: 36px;
  padding: 0 14px;
  border-radius: 18px;
  font-size: 13px;
  white-space: nowrap;
}

.viewer-tools .viewer-btn {
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: transparent;
}

.viewer-tools .viewer-btn[aria-pressed="true"] {
  background: #d97757;
  border-color: #d97757;
}

/* Плашка ошибки: текст и кнопка «Повторить» в столбик, кнопка кликабельна */
.viewer-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}

.viewer-retry {
  pointer-events: auto;
  background: rgba(255, 255, 255, 0.18);
}
