/*
 * Gallery office/form CSS contract:
 * RU: Контракт CSS слоя office/form.
 * - Extension layer for edit lifecycle and form controls.
 *   RU: Слой расширения для edit lifecycle и контролов формы.
 * - Loaded only in office/form POV.
 *   RU: Загружается только в режимах office/form.
 * - Must not duplicate base vitrine layout rules.
 *   RU: Не должен дублировать базовые витринные правила.
 */

/* Точка расширения подписи для режимов office/form. */
.block--gallery .g-caption {
  color: var(--tg-theme-hint-color);
}

/*
 * Оверлей заменить/удалить на главном фото (этап 3).
 * RU: Паттерн как .image-office-overlay в office.css, только токены темы и префикс .g-viewer-*.
 */
.block--gallery .g-viewer-overlay {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: none;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  z-index: 3;
  pointer-events: auto;
}

/* До навешивания .is-editing на блок оверлей скрыт (избегаем мигания при onEnter). */
.block--gallery.is-editing .g-viewer-overlay {
  display: flex;
}

.block--gallery .g-viewer-overlay__btn {
  width: 28px;
  height: 28px;
  border-radius: 14px;
  border: 1px solid var(--tg-theme-section-separator-color);
  background: color-mix(in srgb, var(--tg-theme-secondary-bg-color) 55%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.2s ease;
  padding: 0;
}

.block--gallery .g-viewer-overlay__btn--replace {
  color: var(--status-accent, var(--tg-theme-link-color));
}

.block--gallery .g-viewer-overlay__btn--delete {
  color: var(--status-danger, #dc3545);
}

.block--gallery .g-viewer-overlay__btn:active {
  opacity: 0.7;
  transform: scale(0.92);
}

.block--gallery .g-viewer-overlay__btn svg {
  width: 14px;
  height: 14px;
}

/* Этап 3 (дальше): .g-caption__input — textarea в edit; при необходимости донастроить .g-minipic--add под ряд. */

/* Подпись в edit: textarea, рост вниз (высота дополняется JS: GalleryState.fitGalleryCaptionTextarea). */
.block--gallery.is-editing textarea.g-caption__input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin: 6px 0 0;
  padding: 6px 8px;
  font-size: var(--font-size-sm);
  font-weight: 300;
  line-height: 1.4;
  color: var(--tg-theme-text-color);
  background-color: var(--tg-theme-bg-color);
  border: 1px solid var(--tg-theme-section-separator-color);
  border-radius: var(--border-radius-sm);
  overflow-y: hidden;
  resize: none;
  min-height: calc(1.4em * 2 + 12px);
}

/*
 * Стрип в edit: ghost-reorder (gallery_atom_strip.js).
 * RU: .g-strip — position relative для маркера вставки; --drag-motion — transition на сдвиги.
 */
.block--gallery.is-editing .g-strip {
  position: relative;
}

/* Ячейка стрипа в edit (JS-render); reorder — pointer-drag (gallery_atom_strip.js). */
.block--gallery.is-editing .g-strip__cell {
  display: flex;
  flex-direction: row;
  align-items: center;
  flex: 0 0 auto;
}

.block--gallery.is-editing .g-strip--drag-motion .g-strip__cell {
  transition: transform 0.12s ease-out;
}

/*
 * Тач: горизонтальный pan скроллит .g-strip; long-press → reorder (gallery_atom_strip.js).
 * RU: Во время активного reorder класс .is-drag-reorder — touch-action none, чтобы не уводить скролл.
 */
.block--gallery.is-editing .g-strip__cell .js-g-minipic {
  touch-action: pan-x;
}

.block--gallery.is-editing .g-strip__cell .js-g-minipic.is-drag-reorder {
  touch-action: none;
}

/* Источник: место в ряду сохраняется, картинка скрыта (ghost следует за пальцем). */
.block--gallery.is-editing .js-g-minipic.is-drag-source {
  visibility: hidden;
}

/* Fallback без ghost (STRIP_DRAG_GHOST = false). */
.block--gallery.is-editing .js-g-minipic.is-dragging {
  opacity: 0.88;
  transform: scale(1.03);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--tg-theme-hint-color) 35%, transparent);
  z-index: 2;
  position: relative;
}

/* Клон минипика над интерфейсом (fixed в JS). */
.block--gallery.is-editing .g-minipic--drag-ghost {
  z-index: 4000;
  border-radius: var(--border-radius-sm);
  overflow: hidden;
  transform: scale(1.05);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--tg-theme-hint-color) 40%, transparent);
  pointer-events: none;
}

/* Вертикальная щель вставки (позиция left задаётся из JS). */
.block--gallery.is-editing .g-strip__insert-marker {
  display: none;
  position: absolute;
  top: 4px;
  bottom: 4px;
  width: 3px;
  margin-left: -1.5px;
  border-radius: 2px;
  background-color: var(--tg-theme-link-color);
  opacity: 0.85;
  pointer-events: none;
  z-index: 5;
}

@media (prefers-reduced-motion: reduce) {
  .block--gallery.is-editing .g-strip--drag-motion .g-strip__cell {
    transition: none;
  }
}

@keyframes gStripDropFlashKf {
  0% {
    opacity: 1;
  }
  40% {
    opacity: 0.92;
  }
  100% {
    opacity: 1;
  }
}

.block--gallery.is-editing .g-strip--drop-flash {
  animation: gStripDropFlashKf 0.22s ease-out 1;
}

/* Viewer edit: кадр 5:3, pan/zoom превью (gallery_viewer_edit.js). */
.block--gallery.is-editing .g-pic-frame {
  overflow: hidden;
}

.block--gallery.is-editing .js-g-active-pic {
  cursor: grab;
  user-select: none;
}

.block--gallery.is-editing .js-g-active-pic:active {
  cursor: grabbing;
}

