/* ==========================================================================
   Template editor page
   ========================================================================== */

.te-body .app {
  grid-template-rows: var(--topbar-h) 1fr auto;
}

.te-workspace {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 340px;
  min-height: 0;
  background: var(--bg-0);
}

.te-sidebar,
.te-inspector {
  background: var(--bg-1);
  overflow-y: auto;
  min-height: 0;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
}

.te-sidebar {
  border-right: 1px solid var(--border);
}

.te-inspector {
  border-left: 1px solid var(--border);
}

.te-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.te-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-s);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.13s;
}

.te-list-item:hover {
  background: var(--bg-2);
}

.te-list-item.is-active {
  background: var(--accent-soft);
  border-color: rgba(224, 164, 74, 0.4);
}

.te-list-item .te-thumb {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: #08090a;
  background-image: linear-gradient(45deg, #17130f 25%, transparent 25%),
    linear-gradient(-45deg, #17130f 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #17130f 75%),
    linear-gradient(-45deg, transparent 75%, #17130f 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  flex: none;
  border: 1px solid var(--border);
}

.te-list-item .te-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

/* Шаблон в списке опознаётся по превью: подписи нет, счётчик и плюсик
   прижимаются вправо, а имя остаётся подсказкой при наведении. */
.te-list-item .te-meta {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-faint);
}

/* Плюсик у шаблона с вариантами в списке библиотеки. */
.te-list-item .te-badge {
  flex: none;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--accent);
  color: #1a1206;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.te-canvas-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

/* Цветовые сочетания шаблона: наборы, которые уедут вместе с шаблоном. */
.color-sets-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.color-set-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.color-set-apply {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-2);
  color: var(--text);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.14s, background 0.14s;
}

.color-set-apply:hover {
  border-color: var(--accent);
  background: var(--bg-3);
}

.color-set-swatches {
  display: flex;
  flex: none;
  width: 76px;
  height: 16px;
  border-radius: 3px;
  overflow: hidden;
}

.color-set-swatch {
  flex: 1;
}

.color-set-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Полоса вариантов шаблона: один элемент — несколько рисунков. */
.te-variants {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2, rgba(255, 255, 255, 0.02));
  overflow-x: auto;
  min-height: 36px;
}

.te-variant {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 4px 2px 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s, 6px);
  background: var(--bg-1);
  flex: none;
}

.te-variant.is-active {
  border-color: var(--accent);
  background: rgba(224, 164, 74, 0.12);
}

.te-variant-name {
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  padding: 3px 8px;
  cursor: pointer;
  white-space: nowrap;
  border-radius: 4px;
}

.te-variant-name:hover {
  background: rgba(255, 255, 255, 0.06);
}

.te-variant-input {
  width: 160px;
  font-size: 12px;
  padding: 3px 8px;
}

/* порядок вариантов: перетаскивание чипа или стрелки ← → */
.te-variant[draggable='true'] {
  cursor: grab;
}

.te-variant.is-dragging {
  opacity: 0.4;
}

/* куда встанет перетаскиваемый вариант: полоска у левого или правого края */
.te-variant.is-drop-before {
  box-shadow: inset 2px 0 0 var(--accent);
}

.te-variant.is-drop-after {
  box-shadow: inset -2px 0 0 var(--accent);
}

.te-variant-arrow {
  width: 18px;
  height: 20px;
  font-size: 11px;
  line-height: 1;
  background: transparent;
  border-color: transparent;
  color: var(--text-faint);
}

.te-variant-arrow:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.te-variant-arrow:disabled {
  opacity: 0.25;
  cursor: default;
}

.te-canvas-wrap {
  flex: 1;
  position: relative;
  min-height: 0;
  background: radial-gradient(120% 90% at 50% 0%, #17130e 0%, #0b0a09 70%);
  overflow: hidden;
}

.te-canvas-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.te-canvas-wrap.tool-pick canvas {
  cursor: cell;
}

/* live preview of the template on the character */
.te-skin-preview {
  position: absolute;
  right: 12px;
  top: 12px;
  z-index: 2;
  padding: 8px 8px 6px;
  border-radius: var(--radius-m);
  background: rgba(26, 22, 18, 0.82);
  border: 1px solid var(--border);
  backdrop-filter: blur(6px);
  display: grid;
  justify-items: center;
  gap: 5px;
  pointer-events: none;
}

.te-skin-preview canvas {
  position: static;
  inset: auto;
  width: 132px;
  height: 196px;
  cursor: default;
  border-radius: var(--radius-s);
}

.te-skin-preview-title {
  font-size: 9px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.te-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  padding: 30px;
  color: var(--text-dim);
  pointer-events: none;
}

.te-empty h2 {
  margin: 0 0 8px;
  font-size: 18px;
  color: var(--text);
}

.te-empty p {
  max-width: 460px;
  line-height: 1.6;
  font-size: 13px;
  margin: 0;
}

.te-hint {
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.5;
  margin-top: 8px;
}

.channel-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-2);
  margin-bottom: 6px;
  cursor: pointer;
}

.lock-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border);
}

.lock-row .te-hint {
  margin: 0;
  flex: 1;
  min-width: 140px;
}

.channel-row.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.channel-row.is-locked {
  border-color: rgba(224, 150, 74, 0.4);
  background: linear-gradient(90deg, rgba(224, 150, 74, 0.12), transparent 70%);
}

.channel-row .dot {
  width: 18px;
  height: 18px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  flex: none;
}

/* квадратик цвета канала: клик открывает выбор цвета */
.channel-row .dot-input {
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.channel-row .dot-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.channel-row .dot-input::-webkit-color-swatch {
  border: none;
  border-radius: 9px;
}

.channel-row .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.channel-row .count {
  font-size: 10px;
  color: var(--text-faint);
}

.mask-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.mask-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-dim);
}

.mask-legend i {
  width: 10px;
  height: 10px;
  border-radius: 10px;
  display: inline-block;
}

@media (max-width: 1100px) {
  .te-workspace {
    grid-template-columns: 220px minmax(0, 1fr) 300px;
  }
}

@media (max-width: 900px) {
  .te-workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(320px, 1fr) auto;
  }

  .te-sidebar,
  .te-inspector {
    max-height: 260px;
    border: none;
    border-bottom: 1px solid var(--border);
  }
}

/* Заглушка вместо редактора: он доступен только автору, модератору и админу. */
.te-denied {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px;
  text-align: center;
  min-height: 0;
}

.te-denied h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.te-denied p {
  margin: 0;
  max-width: 460px;
  color: var(--text-dim);
  line-height: 1.55;
}
