/* Сетка галереи, карточки генераций, их действия.
   Часть styles.css; порядок подключения в HTML = порядок каскада, менять нельзя. */

.empty-copy {
  max-width: 460px;
  width: min(460px, calc(100% - 40px));
  margin: 0 auto;
  text-align: center;
  justify-self: center;
  align-self: center;
  display: grid;
  justify-items: center;
}

.loading-copy {
  gap: 10px;
}

.generation-group {
  display: grid;
  gap: 10px;
  min-width: 0;
  /* Пропускаем лэйаут/пейнт групп вне вьюпорта (при тысячах карточек это снимает тормоза).
     contain-intrinsic-size держит высоту скипнутой группы; inline-style задаёт оценку по числу
     карточек, ключевое слово auto самокорректирует её по реальному размеру после первого рендера.
     Фолбэк-высота здесь — на случай, если inline-оценка не задана. Неподдерживающие браузеры
     (не Chromium/Safari<15.4) свойство игнорируют и рендерят всё как раньше.
     Две строки contain-intrinsic-size: первая без auto — фолбэк для браузеров, где
     content-visibility есть, а auto-ключ ещё нет (Chrome/Edge 85–97): без неё offscreen-группы
     схлопнулись бы в 0. Вторая (auto) переопределяет там, где поддержана, и самокорректируется. */
  content-visibility: auto;
  contain-intrinsic-size: 600px;
  contain-intrinsic-size: auto 600px;
}

.generation-group-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.generation-group-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.generation-group-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: 0.01em;
  min-width: 0;
}

.generation-action-button {
  width: 34px;
  min-height: 34px;
  padding: 0;
  flex: 0 0 auto;
  border-radius: 999px;
  opacity: 0.9;
}

.generation-action-button svg {
  width: 18px;
  height: 18px;
}

.generation-delete-button {
  color: #ff8d8d;
}

.generation-delete-button:hover {
  border-color: rgba(239, 102, 102, 0.5);
  background: rgba(239, 102, 102, 0.12);
}

.generation-group-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.generation-group-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(156px, 1fr));
  gap: 8px;
  min-width: 0;
}

.loading-orb {
  width: 58px;
  height: 58px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background:
    radial-gradient(circle at 35% 35%, rgba(47, 125, 255, 0.78), rgba(47, 125, 255, 0.08) 52%, transparent 56%),
    radial-gradient(circle at 65% 65%, rgba(104, 154, 255, 0.74), rgba(104, 154, 255, 0.08) 48%, transparent 54%),
    rgba(255, 255, 255, 0.03);
  box-shadow:
    0 0 0 10px rgba(255, 255, 255, 0.02),
    0 16px 40px rgba(0, 0, 0, 0.3);
  animation: pulse-glow 1.8s ease-in-out infinite;
}

.gallery-card {
  position: relative;
  display: block;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-radius: 9px;
  background: linear-gradient(180deg, rgba(19, 24, 31, 0.98), rgba(14, 18, 24, 0.98));
}

.gallery-media {
  position: relative;
  display: block;
  min-width: 0;
  overflow: hidden;
  cursor: zoom-in;
}

.gallery-card.processing .gallery-placeholder {
  background: linear-gradient(
    110deg,
    rgba(255, 255, 255, 0.02) 8%,
    rgba(255, 255, 255, 0.08) 18%,
    rgba(255, 255, 255, 0.02) 33%
  );
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

.gallery-card img {
  width: 100%;
  height: auto;
  object-fit: contain;
  object-position: center;
  display: block;
  background: rgba(255, 255, 255, 0.035);
}

.gallery-placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 4 / 5;
  height: auto;
  flex: 0 0 auto;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
}

.gallery-card-body {
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  gap: 4px;
  padding: 44px 8px 8px;
  color: #fff;
  pointer-events: none;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.72);
  background: linear-gradient(180deg, transparent 0%, rgba(3, 7, 18, 0.58) 44%, rgba(3, 7, 18, 0.88) 100%);
}

:root[data-theme="light"] .gallery-card-body {
  background: linear-gradient(180deg, transparent 0%, rgba(3, 7, 18, 0.48) 42%, rgba(3, 7, 18, 0.82) 100%);
}

.gallery-card h3,
.gallery-card p {
  margin: 0;
}

.gallery-card h3 {
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  white-space: normal;
  font-size: 0.8rem;
  line-height: 1.18;
}

.gallery-card .meta-text {
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.68rem;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-card footer {
  flex: 0 0 auto;
  padding: 0 10px 10px;
  background: rgba(17, 22, 29, 0.94);
}

:root[data-theme="light"] .gallery-card footer {
  background: #ffffff;
}

.gallery-card .gallery-meta {
  gap: 4px;
  margin-top: 2px;
}

.gallery-card .pill {
  padding: 3px 6px;
  border: 0;
  color: #fff;
  background: rgba(3, 7, 18, 0.66);
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.22);
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1.1;
}

.gallery-actions-overlay {
  position: absolute;
  z-index: 3;
  right: 6px;
  top: 6px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.gallery-card:hover .gallery-actions-overlay,
.gallery-card:focus-within .gallery-actions-overlay {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.gallery-icon-action {
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.46);
  background: rgba(3, 7, 18, 0.72);
  color: #fff;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(8px);
}

.gallery-icon-action:hover {
  border-color: rgba(134, 199, 255, 0.82);
  background: rgba(31, 111, 255, 0.82);
}

.gallery-icon-action:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.gallery-icon-action svg {
  width: 15px;
  height: 15px;
}

.generation-dialog {
  position: fixed;
  inset: 0;
  z-index: 130;
  display: none;
}

.generation-dialog.is-open {
  display: block;
}

.generation-dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 6, 10, 0.72);
  backdrop-filter: blur(8px);
}

.generation-dialog-panel {
  position: relative;
  width: min(460px, calc(100% - 28px));
  margin: min(14vh, 120px) auto 0;
  padding: 18px 18px 16px;
  border-radius: 20px;
  border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, rgba(18, 23, 30, 0.98), rgba(10, 14, 20, 0.98));
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
}

.generation-dialog-panel h3 {
  margin: 0;
  font-size: 1.28rem;
}

.generation-dialog-form {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.generation-dialog-preview {
  margin: -2px 0 0;
}

.generation-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.generation-dialog-confirm {
  width: auto;
  min-width: 118px;
}

.media-viewer {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: none;
}

.media-viewer.is-open {
  display: block;
}

.media-viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 5, 9, 0.82);
  backdrop-filter: blur(8px);
}