/* Iris — редактор аннотаций изображений (editor.js). Все классы с префиксом ie-. */

.ie-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  flex-direction: column;
  background: rgba(14, 13, 11, 0.94);
  color: #f2efe8;
  font: inherit;
  -webkit-user-select: none;
  user-select: none;
  outline: none;
  overscroll-behavior: contain;
  -webkit-tap-highlight-color: transparent;
}

.ie-overlay *,
.ie-overlay *::before,
.ie-overlay *::after {
  box-sizing: border-box;
}

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

.ie-topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: rgba(14, 13, 11, 0.9);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.ie-title {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ie-actions {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.ie-divider {
  width: 1px;
  height: 24px;
  margin: 0 4px;
  background: rgba(255, 255, 255, 0.14);
}

/* ---------- Кнопки ---------- */

.ie-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 36px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.12s, color 0.12s, border-color 0.12s, opacity 0.12s;
}

.ie-btn svg {
  flex: none;
  display: block;
}

.ie-btn:focus-visible {
  outline: 2px solid var(--accent, #f0b030);
  outline-offset: 1px;
}

.ie-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.ie-btn-ghost {
  color: #e9e5dc;
}

.ie-btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.09);
}

.ie-btn-ghost:active:not(:disabled) {
  background: rgba(255, 255, 255, 0.14);
}

.ie-btn-text {
  padding: 0 14px;
  font-weight: 500;
}

.ie-btn-primary {
  background: var(--accent, #f0b030);
  color: #1a1814;
  font-weight: 600;
}

.ie-btn-primary:hover:not(:disabled) {
  background: var(--accent-hover, #e2a01f);
}

.ie-btn-danger {
  background: var(--danger, #d93f4c);
  color: #ffffff;
  font-weight: 600;
}

.ie-btn-danger:hover:not(:disabled) {
  filter: brightness(1.08);
}

/* ---------- Основная область ---------- */

.ie-main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: row;
  gap: 12px;
  padding: 12px;
}

.ie-stage {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
}

.ie-canvas {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  touch-action: none;
}

.ie-status {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.55);
  color: #e9e5dc;
  font-size: 14px;
  text-align: center;
  pointer-events: none;
}

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

.ie-status-error {
  color: #ffd5d9;
  background: rgba(217, 63, 76, 0.35);
}

/* Поле ввода текста поверх холста; шрифт совпадает с отрисовкой на canvas */
.ie-textinput {
  position: absolute;
  z-index: 2;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-weight: 700;
  font-style: normal;
  letter-spacing: normal;
  white-space: pre;
  overflow: hidden;
  resize: none;
  outline: 1.5px dashed rgba(255, 255, 255, 0.85);
  outline-offset: 4px;
  box-shadow: 0 0 0 5px rgba(0, 0, 0, 0.18);
  min-width: 8px;
  -webkit-user-select: text;
  user-select: text;
}

.ie-textinput[hidden] {
  display: none;
}

/* ---------- Палитра инструментов ---------- */

.ie-palette {
  flex: none;
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  width: 136px;
  max-height: 100%;
  padding: 10px;
  overflow-y: auto;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  background: rgba(30, 28, 25, 0.92);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  scrollbar-width: thin;
}

.ie-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.ie-sep {
  flex: none;
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
}

.ie-tool {
  padding: 0;
  width: 100%;
  height: 36px;
  color: #d9d4c8;
}

.ie-tool:hover:not(.ie-active) {
  background: rgba(255, 255, 255, 0.09);
}

.ie-tool.ie-active {
  background: var(--accent, #f0b030);
  color: #1a1814;
}

.ie-swatch {
  padding: 0;
  width: 100%;
  height: 36px;
}

.ie-swatch:hover .ie-swatch-dot {
  transform: scale(1.1);
}

.ie-swatch-dot {
  display: block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.35);
  transition: transform 0.12s;
}

.ie-swatch.ie-active .ie-swatch-dot {
  box-shadow: 0 0 0 2px rgba(30, 28, 25, 1), 0 0 0 4px var(--accent, #f0b030);
}

.ie-width {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.ie-width-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
}

.ie-width-dot {
  display: block;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.ie-range {
  width: 100%;
  min-height: 28px;
  margin: 0;
  accent-color: var(--accent, #f0b030);
  cursor: pointer;
  touch-action: pan-x;
}

/* ---------- Подтверждение закрытия ---------- */

.ie-confirm {
  position: absolute;
  left: 50%;
  top: 68px;
  transform: translateX(-50%);
  z-index: 3;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 12px;
  max-width: calc(100% - 24px);
  padding: 10px 12px 10px 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: #23211d;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  font-size: 14px;
}

.ie-confirm[hidden] {
  display: none;
}

.ie-confirm-text {
  flex: 1 1 200px;
}

/* ---------- Узкие экраны: палитра снизу ---------- */

@media (max-width: 700px) {
  .ie-title {
    display: none;
  }

  .ie-topbar {
    min-height: 52px;
    padding: 6px 8px;
    padding-top: max(6px, env(safe-area-inset-top));
  }

  .ie-actions {
    width: 100%;
    gap: 2px;
    justify-content: space-between;
  }

  .ie-btn-label,
  .ie-divider {
    display: none;
  }

  .ie-btn-ghost:not(.ie-btn-text) {
    padding: 0 8px;
  }

  .ie-btn-text {
    padding: 0 12px;
  }

  .ie-main {
    flex-direction: column-reverse;
    gap: 8px;
    padding: 8px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .ie-palette {
    align-self: stretch;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
    width: auto;
    max-height: none;
    padding: 6px;
    overflow: visible;
    border-radius: 12px;
  }

  .ie-group {
    display: flex;
    gap: 0;
  }

  .ie-tools,
  .ie-colors {
    flex: 1 1 100%;
    justify-content: space-between;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .ie-tools::-webkit-scrollbar,
  .ie-colors::-webkit-scrollbar {
    display: none;
  }

  .ie-tool,
  .ie-swatch {
    flex: 0 0 36px;
    width: 36px;
  }

  .ie-sep {
    display: none;
  }

  .ie-width {
    flex: 1 1 100%;
    flex-direction: row;
    gap: 10px;
    padding: 0 4px;
  }

  .ie-width-preview {
    flex: none;
  }

  .ie-confirm {
    top: 60px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ie-btn,
  .ie-swatch-dot {
    transition: none;
  }
}
