/* Общий полноэкранный просмотр картинок: зум/поворот (как в мессенджере)
   + рисование ручкой/маркером поверх. Один файл вместо N дублирующихся
   инлайн-стилей по шаблонам. */

.image-viewer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.image-viewer-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.image-viewer-stage {
  position: relative;
  max-width: 90%;
  max-height: 90%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: scale(0.9);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.image-viewer-overlay.active .image-viewer-stage {
  transform: scale(1);
}

/* Зум/поворот управляют этой обёрткой — независимо от entrance-анимации выше */
.image-viewer-transform-wrap {
  position: relative;
  display: inline-block;
  line-height: 0;
  transform-origin: center center;
  transition: transform 0.12s ease;
  touch-action: none;
}

.image-viewer-img {
  display: block;
  max-width: 90vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.image-viewer-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  touch-action: none;
}

.image-viewer-canvas.drawing {
  cursor: crosshair;
}

.image-viewer-close {
  position: absolute;
  top: 20px;
  right: 24px;
  background: none;
  border: none;
  color: #fff;
  font-size: 32px;
  font-weight: 300;
  cursor: pointer;
  line-height: 1;
  opacity: 0.8;
  transition: opacity 0.2s, transform 0.2s;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  z-index: 2;
}

.image-viewer-close:hover {
  opacity: 1;
  transform: scale(1.1);
  background: rgba(255, 255, 255, 0.1);
}

/* Зум/поворот тулбар — внизу по центру, как плавающая панель */
.image-viewer-zoom-controls {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 999px;
  padding: 6px;
  z-index: 2;
}

.image-viewer-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

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

.image-viewer-btn.active {
  background: #707dff;
}

.image-viewer-zoom {
  min-width: 48px;
  text-align: center;
  color: #fff;
  font: 600 13px 'Manrope', sans-serif;
  user-select: none;
}

/* Тулбар инструментов рисования — сверху по центру */
.image-viewer-toolbar {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 999px;
  padding: 6px;
  z-index: 2;
}

.image-viewer-tool-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.image-viewer-tool-btn img {
  width: 34px;
  height: 34px;
  pointer-events: none;
}

.image-viewer-tool-btn[data-action="clear-all"] img {
  width: 22px;
  height: 22px;
  padding-top: 1px;
}

.image-viewer-tool-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.image-viewer-tool-btn.active {
  background: #707dff;
}

.image-viewer-tool-divider {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.2);
  margin: 0 4px;
}

.image-viewer-saving-hint {
  position: absolute;
  top: 24px;
  left: 24px;
  color: rgba(255, 255, 255, 0.65);
  font: 500 13px 'Manrope', sans-serif;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.image-viewer-saving-hint.visible {
  opacity: 1;
}

@media (max-width: 640px) {
  .image-viewer-toolbar,
  .image-viewer-zoom-controls {
    padding: 4px;
    gap: 2px;
  }
  .image-viewer-tool-btn,
  .image-viewer-btn {
    width: 38px;
    height: 38px;
  }
  .image-viewer-tool-btn img {
    width: 28px;
    height: 28px;
  }
  .image-viewer-tool-btn[data-action="clear-all"] img {
    width: 18px;
    height: 18px;
  }
}

/* ===== Инлайн-разметка прямо на маленькой картинке (без открытия полноэкранного вьюера) ===== */

.annot-inline-wrap {
  position: relative;
  display: inline-block;
  vertical-align: top;
  line-height: 0;
  max-width: 100%;
}

/* Размер уже зафиксирован в px на самой обёртке (см. image-viewer.js) —
   картинке внутри остаётся просто заполнить её, не полагаясь больше на
   собственные width/max-width правила шаблона (которые могли зависеть от
   родителя и создавать циклическую зависимость внутри shrink-to-fit обёртки). */
.annot-inline-wrap img {
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  object-fit: contain;
}

.annot-inline-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  touch-action: none;
}

.annot-inline-canvas.drawing {
  pointer-events: auto;
  cursor: crosshair;
}

.annot-inline-toolbar {
  position: absolute;
  bottom: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

/* Показываем только при наведении на саму картинку — но не прячем, пока
   открыто меню инструментов (на узкой картинке курсор может уйти за
   пределы обёртки, пока список инструментов ещё раскрыт). Кнопки не
   должны ловить клики, пока невидимы (opacity сам по себе pointer-events
   не убирает). */
.annot-inline-wrap:hover .annot-inline-toolbar,
.annot-inline-wrap:has(.annot-pencil-menu-wrap.open) .annot-inline-toolbar {
  opacity: 1;
  pointer-events: auto;
}

/* Кнопки тулбара кликабельны, но не должны получать нативный синий
   focus-ring браузера (Safari/Chrome подсвечивают им кнопку по клику) —
   выглядело как "неправильный цвет ховера", хотя это не наш CSS. */
.annot-inline-toolbar button {
  outline: none !important;
}

.annot-inline-btn {
  height: 32px;
  width: 32px;
  border-radius: 9px;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 7px;
  box-sizing: border-box;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  transition: background 0.15s ease;
}

.annot-inline-btn:hover {
  background: rgba(0, 0, 0, 0.75) !important;
}

.annot-inline-btn img {
  width: 100%;
  height: 100%;
  pointer-events: none;
  object-fit: contain;
}

/* Кнопка-карандаш и раскрывающийся список инструментов — одна и та же
   плашка, которая просто становится шире, а не триггер + отдельный попап. */
.annot-pencil-menu-wrap {
  display: flex;
  align-items: center;
  height: 32px;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.55);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  transition: background 0.15s ease;
}

.annot-pencil-menu-wrap:hover {
  background: rgba(0, 0, 0, 0.75);
}

.annot-pencil-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-sizing: border-box;
}

/* Без этого глобальное button:hover (static/css/style.css) красит кнопку
   в синий #5c6de0 — у самой кнопки не было своего :hover, красился только
   фон обёртки-плашки под ней. */
.annot-pencil-btn:hover {
  background: transparent !important;
}

.annot-pencil-btn img {
  width: 100%;
  height: 100%;
  pointer-events: none;
  object-fit: contain;
}

.annot-pencil-btn.active {
  background: rgba(112, 125, 255, 0.35);
}

.annot-pencil-options {
  display: flex;
  align-items: center;
  max-width: 0;
  overflow: hidden;
  transition: max-width 0.2s ease;
}

.annot-pencil-menu-wrap.open .annot-pencil-options {
  max-width: 200px;
}

.annot-pencil-options button {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-sizing: border-box;
  transition: background 0.15s ease;
}

.annot-pencil-options button:hover {
  background: rgba(255, 255, 255, 0.15);
}

.annot-pencil-options button.active {
  background: rgba(112, 125, 255, 0.35);
}

.annot-pencil-options button img {
  width: 100%;
  height: 100%;
  pointer-events: none;
  object-fit: contain;
}

.annot-pencil-options button[data-action="clear-all"] img {
  width: 70%;
  height: 70%;
  padding-top: 1px;
}

.annot-pencil-menu-divider {
  flex-shrink: 0;
  width: 1px;
  height: 18px;
  background: rgba(255, 255, 255, 0.25);
}
