:root {
  --bg: #0a0a0c;
  --surface: #131318;
  --surface-2: #1a1a21;
  --border: #26262d;
  --border-strong: #34343d;
  --text: #e8e8ec;
  --muted: #8a8a93;
  --accent: #a78bfa;
  --accent-strong: #8b5cf6;
  --success: #4ade80;
  --error: #f87171;
  --warning: #fbbf24;
  --radius: 10px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Inter, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--accent);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 10, 12, 0.95);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.logo-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 0 12px var(--accent);
}

.tag {
  font-size: 11px;
  color: var(--muted);
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.model-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.model-tab {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}
.model-tab:hover { color: var(--text); }
.model-tab.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 0 0 var(--border);
}

.inflight-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--accent);
  background: rgba(167, 139, 250, 0.10);
  border: 1px solid var(--accent);
  padding: 5px 14px;
  border-radius: 999px;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
}
.inflight-badge #inflightCount {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 14px;
  text-align: center;
}
.inflight-badge .pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}

/* === Tabs === */
.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
  padding-bottom: 0;
}
.tab-btn {
  background: none;
  border: none;
  color: var(--muted);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.tab-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
}

/* === Library === */
.library-content {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Полноэкранный режим библиотеки: левая колонка рефов и форма скрываются,
   правая панель занимает всю ширину layout'а, плитки крупнее. */
body.library-fullscreen .refs-pane,
body.library-fullscreen .form-pane {
  display: none;
}
body.library-fullscreen .layout {
  grid-template-columns: 1fr;
  max-width: 1700px;
}
body.library-fullscreen .result-pane {
  position: static;
  max-height: none;
}
body.library-fullscreen .lib-grid {
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
body.library-fullscreen .lib-item {
  border-radius: 12px;
}
body.library-fullscreen .lib-item video {
  aspect-ratio: 16 / 9;
}
body.library-fullscreen .lib-meta {
  font-size: 11px;
  padding: 8px 10px;
}
/* В полноэкранном режиме крестик-кнопку × в карточках можно увеличить чуть-чуть,
   и копировальную в мета-строке тоже. Мелочь, но удобно. */
body.library-fullscreen .lib-prompt {
  font-size: 11px;
}
.lib-group-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.lib-group-title.collapsible {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color 0.15s;
}
.lib-group-title.collapsible:hover {
  color: var(--text);
}
.lib-group-title .caret {
  font-size: 9px;
  width: 10px;
  display: inline-block;
  text-align: center;
  color: var(--accent);
}
.lib-group-title .lib-group-count {
  opacity: 0.7;
}
/* Свёрнутая группа — прячем сетку, заголовок остаётся видимым */
.lib-group.collapsed .lib-grid {
  display: none;
}
.lib-group.collapsed .lib-group-title {
  margin-bottom: 0;
  border-bottom-color: transparent;
}
.lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}
.lib-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
  position: relative;
}
.lib-item:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.lib-item video {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  background: #000;
  /* pointer-events: auto — нужно, чтобы mouseenter/leave срабатывали на video
     для hover-play поведения (как в Сессии). Drag-to-dropzone и клик по
     плитке всё равно работают, потому что события бабблятся на родитель. */
}
.lib-item .lib-meta {
  padding: 6px 8px;
  font-size: 10px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}
.lib-item .lib-prompt {
  position: absolute;
  inset: auto 0 0 0;
  background: linear-gradient(to top, rgba(0,0,0,0.85), transparent);
  color: #fff;
  font-size: 10px;
  padding: 16px 6px 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}
.lib-item:hover .lib-prompt { opacity: 1; }

.layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 420px;
  gap: 20px;
  padding: 20px 24px 60px;
  max-width: 1700px;
  margin: 0 auto;
}

@media (max-width: 1400px) {
  .layout { grid-template-columns: 220px minmax(0, 1fr) 380px; }
}
@media (max-width: 1200px) {
  .layout { grid-template-columns: minmax(0, 1fr) 380px; }
  .refs-pane { display: none; } /* На узких экранах прячем библиотеку рефов */
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

/* === Левая колонка с библиотекой всех референсов === */
.refs-pane {
  position: sticky;
  top: 70px;
  align-self: start;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.refs-pane-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 8px;
}

/* Hint-строка под textarea с кнопкой справа */
.hint.hint-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.hint.hint-row .hint-text {
  flex: 1;
  min-width: 0;
}
.danger-btn {
  border-color: rgba(248, 113, 113, 0.45) !important;
  color: var(--error) !important;
  flex-shrink: 0;
}
.danger-btn:hover {
  background: rgba(248, 113, 113, 0.1) !important;
  border-color: var(--error) !important;
}
.refs-library {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.refs-day {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.refs-day-header {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
  user-select: none;
  transition: background 0.15s, color 0.15s;
}
.refs-day-header:hover {
  background: var(--surface-2);
  color: var(--text);
}
.refs-day-header .caret {
  font-size: 9px;
  width: 10px;
  display: inline-block;
}
.refs-day-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 6px;
  padding: 0 4px;
}
.ref-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 5px;
  overflow: hidden;
  background: #000;
  cursor: grab;
  border: 1px solid var(--border);
  transition: border-color 0.15s, transform 0.15s;
}
.ref-tile:hover {
  border-color: var(--accent);
  transform: scale(1.04);
  z-index: 2;
}
.ref-tile:active { cursor: grabbing; }
.ref-tile.dragging { opacity: 0.4; }
.ref-tile img,
.ref-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}
.ref-tile .audio-icon {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2d1b4e, #1a1a21);
  color: var(--accent);
  font-size: 18px;
}
.ref-tile .ref-tile-type-tag {
  position: absolute;
  top: 2px;
  left: 2px;
  font-size: 8px;
  padding: 1px 3px;
  border-radius: 2px;
  font-weight: 700;
  background: rgba(0,0,0,0.6);
  color: #fff;
  letter-spacing: 0.04em;
  pointer-events: none;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.card-title {
  margin: 0 0 14px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

.lbl {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 500;
}
.req { color: var(--error); }

textarea, input[type="text"], input[type="number"], select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

textarea:focus, input:focus, select:focus {
  border-color: var(--accent);
}

textarea {
  resize: vertical;
  min-height: 140px;
  line-height: 1.55;
  font-family: 'SF Mono', ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

/* === Prompt with highlight overlay === */
/* Контейнер: relative — для абсолютного позиционирования зеркала.
   Размер задаёт textarea (mirror — absolute, не влияет на layout). */
.prompt-grid {
  position: relative;
  display: block;
  background: var(--surface-2);
  border-radius: 8px;
}
.prompt-mirror,
.prompt-textarea {
  font-family: 'SF Mono', ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  width: 100%;
  box-sizing: border-box;
  white-space: pre-wrap;
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: break-word;
  letter-spacing: 0;
  tab-size: 4;
  margin: 0;
  min-height: 140px;
}
/* Зеркало — абсолютным слоем поверх textarea. Растягивается на 100%
   контейнера = размер textarea. pointer-events:none → клики проваливаются
   в textarea, кроме самих чипов с pointer-events:auto. */
.prompt-mirror {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: auto;       /* инлайн left+right = размер по контейнеру */
  height: auto;
  min-height: 0;
  z-index: 2;
  pointer-events: none;
  color: transparent !important;
  background: transparent !important;
  overflow: hidden;
  user-select: none;
}
.prompt-mirror .ref-highlight {
  pointer-events: auto;
  cursor: pointer;
}
.prompt-textarea {
  position: relative;
  z-index: 1;
  background: transparent !important;
  background-color: transparent !important;
  color: var(--text);
  border-color: var(--border);
  resize: vertical;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  /* Резервируем место под скроллбар ВСЕГДА, чтобы wrapping не менялся,
     когда контент дорастает до скролла. Зеркало получает соответствующий
     padding-right в JS, чтобы переносы строк совпадали. */
  scrollbar-gutter: stable;
}
.prompt-textarea:focus {
  border-color: var(--accent);
}
/* Поскольку textarea и mirror прозрачные, фон у самой обёртки —
   совпадает с обычным «полем ввода» */
/* Базовый чип. Важно: НИКАКИХ padding/margin/border, иначе ширина символов
   в зеркале не совпадёт с textarea и текст «поплывёт». Граница рисуется через
   outline (он вне потока и не двигает соседние символы). */
.ref-highlight {
  background: rgba(167, 139, 250, 0.22);
  border-radius: 3px;
  cursor: pointer;
  outline: 1px solid rgba(167, 139, 250, 0.6);
  outline-offset: -1px;
  transition: background 0.15s, outline-color 0.15s;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.ref-highlight:hover {
  background: rgba(167, 139, 250, 0.42);
}
.ref-highlight.ref-missing {
  background: rgba(248, 113, 113, 0.22);
  outline: 1px dashed rgba(248, 113, 113, 0.85);
  outline-offset: -1px;
}
.ref-highlight.ref-missing:hover {
  background: rgba(248, 113, 113, 0.42);
}
/* Sparse-вариант — слот существует, но именно эта ячейка стёрта.
   Визуально чуть «жирнее», чтобы отличаться от просто «не загруженного». */
.ref-highlight.ref-sparse {
  background: rgba(251, 146, 60, 0.28);
  outline: 1px dashed rgba(251, 146, 60, 0.95);
  animation: refSparsePulse 1.6s ease-in-out infinite;
}
.ref-highlight.ref-sparse:hover {
  background: rgba(251, 146, 60, 0.5);
}
@keyframes refSparsePulse {
  0%, 100% { background: rgba(251, 146, 60, 0.28); }
  50%      { background: rgba(251, 146, 60, 0.45); }
}

/* Текст чипа внутри ЗЕРКАЛА должен быть прозрачным — реальный текст
   рисует textarea сверху, иначе получим двойной overlap. */
.prompt-mirror .ref-highlight {
  color: transparent !important;
}

/* Демонстрационные чипы в подсказке (вне зеркала) — текст видим */
.ref-inline-demo {
  font-family: 'SF Mono', ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px;
  cursor: default;
  color: var(--accent);
}

/* === Hover-превью чипа с рефом === */
.ref-tooltip {
  position: fixed;
  z-index: 999;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  max-width: 240px;
  animation: tooltipFade 0.12s ease-out;
}
@keyframes tooltipFade {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.ref-tooltip img,
.ref-tooltip video {
  display: block;
  max-width: 220px;
  max-height: 160px;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
  background: #000;
}
.ref-tooltip-audio {
  width: 200px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: var(--accent);
  background: linear-gradient(135deg, #2d1b4e, #1a1a21);
  border-radius: 4px;
}
.ref-tooltip-name {
  font-size: 11px;
  color: var(--muted);
  padding: 4px 6px 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}
.ref-tooltip-empty {
  font-size: 12px;
  color: var(--error);
  padding: 8px 12px;
  white-space: nowrap;
}

/* === Автокомплит для @image / @video / @audio === */
.ref-autocomplete {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  max-height: 280px;
  overflow-y: auto;
  animation: tooltipFade 0.12s ease-out;
}
/* Каждая .card создаёт stacking context (position: relative), и соседние
   карточки в DOM рисуются ПОВЕРХ предыдущих. Внутренний z-index у
   .ref-autocomplete действует только внутри своей карточки — для соседних
   он не работает.
   Когда автокомплит открыт (нет атрибута hidden), поднимаем родительскую
   .card в общий stacking — теперь её содержимое перекрывает следующие
   карточки PARAMETERS / REFERENCES. */
.card:has(.ref-autocomplete:not([hidden])) {
  z-index: 50;
}
.ref-ac-header {
  padding: 6px 10px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  justify-content: space-between;
  position: sticky;
  top: 0;
}
.ref-ac-item {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.ref-ac-item:last-child {
  border-bottom: none;
}
.ref-ac-item:hover,
.ref-ac-item.selected {
  background: rgba(167, 139, 250, 0.12);
}
.ref-ac-thumb {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  border-radius: 4px;
  overflow: hidden;
  background: #000;
}
.ref-ac-thumb img,
.ref-ac-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ref-ac-thumb.audio-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2d1b4e, #1a1a21);
  color: var(--accent);
  font-size: 22px;
}
.ref-ac-info {
  flex: 1;
  min-width: 0;
}
.ref-ac-num {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  font-family: 'SF Mono', ui-monospace, Menlo, Consolas, monospace;
}
.ref-ac-name {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.ref-ac-hint {
  font-size: 10px;
  color: var(--muted);
}
textarea.drag-target {
  border-color: var(--accent);
  background: rgba(167, 139, 250, 0.08);
  box-shadow: 0 0 0 2px rgba(167, 139, 250, 0.2);
}

/* === Preview modal === */
.preview-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s ease-out;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.preview-modal-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.preview-modal-close {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 32px;
  height: 32px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  font-family: inherit;
}
.preview-modal-close:hover {
  background: var(--error);
  border-color: var(--error);
  color: #fff;
}
.preview-modal-media {
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-modal-media img,
.preview-modal-media video {
  max-width: 90vw;
  max-height: 80vh;
  display: block;
  border-radius: 8px;
  background: #000;
}
.preview-modal-media audio {
  width: min(500px, 80vw);
}
.preview-modal-caption {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  max-width: 90vw;
  text-align: center;
  word-break: break-all;
}

/* hint clickability for previews */
.preview-item {
  cursor: grab;          /* можно перетаскивать */
  user-select: none;
}
.preview-item:active { cursor: grabbing; }
.preview-item .remove { cursor: pointer; }
.preview-item img,
.preview-item video {
  pointer-events: none;  /* чтобы drag захватывал .preview-item, а не <img>/<video> */
}

/* Активный drag: исходный item */
.preview-item.dragging {
  opacity: 0.4;
  cursor: grabbing;
}

/* Sparse-slot режим: ячейка-цель для drag-reorder подсвечивается целиком */
.preview-item.drop-target-active {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  box-shadow: 0 0 16px -2px rgba(167, 139, 250, 0.55);
}

/* Пустая ячейка слота — placeholder с номером */
.preview-item.is-empty {
  cursor: pointer;
  background: rgba(0, 0, 0, 0.18);
  border: 1px dashed rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.32);
  transition: border-color 0.15s, background-color 0.15s, color 0.15s;
}
.preview-item.is-empty:hover {
  border-color: var(--accent);
  background: rgba(167, 139, 250, 0.08);
  color: var(--accent);
}
.preview-item.is-empty .empty-slot-num {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
  pointer-events: none;
}

/* Номер слота поверх миниатюры (1-based, стабильный) */
.preview-item .slot-num {
  position: absolute;
  top: 4px;
  left: 4px;
  z-index: 2;
  min-width: 16px;
  height: 16px;
  padding: 0 5px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  pointer-events: none;
  letter-spacing: 0.02em;
}

/* Aspect-ratio варнинг — оранжевый ⚠ в правом верхнем углу превью.
   pointer-events: auto чтобы тултип на hover показывался; size такой же
   как slot-num для визуальной симметрии. */
.preview-item .aspect-warn {
  position: absolute;
  top: 4px;
  right: 28px;          /* левее крестика «×» (он в position right:4px) */
  z-index: 3;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(245, 158, 11, 0.95);   /* amber-500 */
  color: #1a1a21;
  font-size: 12px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  cursor: help;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
.preview-item.has-aspect-warn {
  outline: 1px solid rgba(245, 158, 11, 0.5);
  outline-offset: -1px;
}
[data-theme="light"] .preview-item.is-empty {
  background: rgba(0, 0, 0, 0.04);
  border-color: var(--border);
  color: rgba(0, 0, 0, 0.4);
}
[data-theme="light"] .preview-item.is-empty:hover {
  background: rgba(167, 139, 250, 0.1);
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

.row { margin-bottom: 16px; }
.row:last-child { margin-bottom: 0; }
.row.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 700px) {
  .row.two { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; }

.slider-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Grid-based layout where slider + ticks share the same column,
   so tick positions visually align with slider values. */
.slider-block {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 0 14px;
  align-items: center;
}
.slider-block input[type="range"] {
  grid-column: 1;
  grid-row: 1;
  margin: 0;
}
.slider-block .slider-value {
  grid-column: 2;
  grid-row: 1 / span 2;
}
.slider-block .ticks {
  grid-column: 1;
  grid-row: 2;
  /* Compensate half thumb width on each side so ticks align with thumb travel */
  padding-left: 9px;
  padding-right: 9px;
}

.slider-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  min-width: 40px;
  text-align: right;
}

input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 24px;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
}
input[type="range"]::-moz-range-track {
  height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  margin-top: -7px;
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--accent);
}
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg);
}

.ticks {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  padding: 4px 4px 0;
}

.checkboxes { gap: 8px; }
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
}
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.dropzone-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.dz {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 12px;
  transition: border-color 0.15s, background 0.15s;
  display: flex;
  flex-direction: column;
  cursor: pointer;
}
.dz:hover:not(.is-full) {
  border-color: var(--accent);
  background: rgba(167, 139, 250, 0.04);
}
.dz.is-full {
  cursor: default;
}
.dz.drag-over {
  border-color: var(--accent);
  background: rgba(167, 139, 250, 0.08);
}

.dz-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.dz-title { font-size: 13px; font-weight: 500; }
.dz-meta { font-size: 11px; color: var(--muted); }
.dz-meta.full { color: var(--warning); }

.dz-area {
  text-align: center;
  padding: 16px 8px;
  font-size: 13px;
  color: var(--muted);
}
.dz-area p { margin: 4px 0; }
.lnk {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

.previews {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 6px;
  margin-top: 8px;
}
.previews:empty { margin-top: 0; }

.preview-item {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--border);
}
.preview-item img, .preview-item video {
  width: 100%; height: 100%; object-fit: cover;
}
.preview-item .audio-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: linear-gradient(135deg, #2d1b4e, #1a1a21);
  color: var(--accent);
  font-size: 20px;
}
.preview-item .file-name {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.85), transparent);
  font-size: 9px;
  padding: 8px 4px 3px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preview-item .remove {
  position: absolute;
  top: 3px; right: 3px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.preview-item .remove:hover { background: var(--error); }

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 4px;
}

.primary-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  border: none;
  padding: 12px 22px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.primary-btn:hover:not(:disabled) { transform: translateY(-1px); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.ghost-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  text-decoration: none;
  display: inline-block;
  transition: border-color 0.15s, background 0.15s;
  font-family: inherit;
}
.ghost-btn:hover { border-color: var(--accent); }

.btn-loader {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result-pane {
  position: sticky;
  top: 70px;
  align-self: start;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
}

@media (max-width: 1100px) {
  .result-pane { position: static; max-height: none; }
}

.status {
  padding: 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}
.status.idle { background: var(--surface-2); color: var(--muted); }
.status.loading { background: rgba(167, 139, 250, 0.08); border-color: var(--accent); color: var(--text); }
.status.success { background: rgba(74, 222, 128, 0.08); border-color: var(--success); color: var(--success); }
.status.error { background: rgba(248, 113, 113, 0.08); border-color: var(--error); color: var(--error); white-space: pre-wrap; word-break: break-word; }

.result-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.ghost-btn.small {
  padding: 4px 10px;
  font-size: 11px;
}

.results-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Плавающая круглая кнопка «Скролл к началу Сессии» — только стрелка вверх,
   без текста. Висит в правом нижнем углу viewport (position: fixed), чтобы
   оставаться видимой пока пользователь пролистывает Сессию. Видимостью
   управляет JS updateSessionFabs() — скрыта на самом верху списка, на
   Library, и при пустой Сессии. */
.session-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 60;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.32);
  transition: transform 0.12s ease, background 0.12s ease, opacity 0.15s ease;
}
.session-fab:hover {
  background: var(--surface-3, var(--surface-2));
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.36);
}
.session-fab:active { transform: translateY(0); }
.session-fab[hidden] { display: none; }
/* В Glass-теме фон окна автокомплита из var(--surface) почти прозрачный
   (rgba(255,255,255,0.04)), поэтому сквозь список было видно дропзоны
   снизу — нечитаемо. Прибиваем сплошной тёмно-синий фон + blur для
   стеклянного ощущения, но уже непрозрачно. */
[data-theme="glass"] .ref-autocomplete {
  background: rgba(20, 30, 60, 0.96);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-color: rgba(167, 139, 250, 0.5);
}
[data-theme="glass"] .ref-ac-header {
  background: rgba(30, 42, 78, 0.98);
  border-bottom-color: rgba(167, 139, 250, 0.25);
}
[data-theme="glass"] .ref-ac-item {
  border-bottom-color: rgba(167, 139, 250, 0.18);
}
[data-theme="glass"] .ref-ac-item:hover,
[data-theme="glass"] .ref-ac-item.selected {
  background: rgba(167, 139, 250, 0.22);
}

[data-theme="glass"] .session-fab {
  background: rgba(30, 30, 40, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-color: rgba(255, 255, 255, 0.14);
}
[data-theme="light"] .session-fab {
  background: rgba(255, 255, 255, 0.98);
  border-color: rgba(0, 0, 0, 0.1);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.16);
}

.result-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  animation: slideIn 0.25s ease-out;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-item video {
  width: 100%;
  background: #000;
  display: block;
  max-height: 320px;
}
.result-item .result-body {
  padding: 10px 12px;
}
.result-item .result-meta {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
}
.result-item .result-meta .badge {
  background: rgba(167, 139, 250, 0.12);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 4px;
}
.result-item .result-meta .model-badge {
  background: rgba(74, 222, 128, 0.12);
  color: var(--success);
  font-weight: 500;
}
.lib-model-tag {
  background: rgba(74, 222, 128, 0.18);
  color: var(--success);
  padding: 0 4px;
  border-radius: 3px;
  font-weight: 600;
  font-size: 9px;
}

/* === Бейдж «Новое» на непросмотренных генерациях === */
.new-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 3;
  padding: 3px 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-cyan, #38bdf8));
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 6px;
  box-shadow: 0 0 16px rgba(167, 139, 250, 0.45);
  pointer-events: none;
  animation: newBadgePulse 2s ease-in-out infinite;
}
@keyframes newBadgePulse {
  0%, 100% { box-shadow: 0 0 16px rgba(167, 139, 250, 0.45); }
  50% { box-shadow: 0 0 22px rgba(167, 139, 250, 0.7); }
}
/* На library-плитках бейдж чуть мельче и сдвинут под model-corner */
.new-badge-tile {
  top: 28px;
  left: 6px;
  font-size: 8px;
  padding: 2px 6px;
  letter-spacing: 0.04em;
  border-radius: 4px;
}

/* Угловой бейдж модели на превью в библиотеке */
.lib-model-corner {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 2;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  border: 1px solid;
  pointer-events: none;
  backdrop-filter: blur(4px);
}

/* Фильтр-пиллы сверху библиотеки */
.lib-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.lib-filter-pill {
  --pill-color: var(--text);
  --pill-bg: var(--surface-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 5px 10px 5px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.lib-filter-pill:hover {
  color: var(--text);
  border-color: var(--border-strong);
}
.lib-filter-pill.active {
  background: var(--pill-bg);
  border-color: var(--pill-color);
  color: var(--pill-color);
}
.lib-filter-pill .pill-count {
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  color: inherit;
  opacity: 0.85;
}
.lib-filter-pill.active .pill-count {
  background: rgba(0, 0, 0, 0.25);
  opacity: 1;
}
.lib-filter-pill.lib-filter-favorites {
  --pill-color: #fbbf24;
  --pill-bg: rgba(251, 191, 36, 0.12);
}
.lib-filter-pill.lib-filter-favorites:hover {
  border-color: rgba(251, 191, 36, 0.6);
}

/* === Иконка избранного: флажок-закладка со звездой внутри === */
/* Используется и на result-card (рядом с ×), и на lib-tile (правый верх) */
.card-fav-btn,
.lib-fav-btn {
  position: absolute;
  z-index: 4;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.75);
  transition: color 0.15s, transform 0.1s, filter 0.15s;
  /* Лёгкий drop-shadow чтобы белый флажок был читаем на любом фоне видео */
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.55));
}
/* Размер пропорционален × кнопке (32×32px, см. .card-close-btn).
 * Флажок шире чем нужно (квадратная кнопка), но SVG-флажок естественно
 * прямоугольный — он автоматически центрируется в width=32.
 * Звезда внутри теперь меньше (см. FAV_ICON_SVG) — не касается краёв. */
.card-fav-btn { top: 8px; right: 48px; width: 32px; height: 32px; }
.lib-fav-btn  { top: 4px; right: 4px;  width: 26px; height: 26px; }

.card-fav-btn svg,
.lib-fav-btn svg {
  width: 100%;
  height: 100%;
  display: block;
  /* Чтобы флажок чуть-чуть утопал внутрь кнопки, не упирался в её границы.
   * 4px padding на 32px кнопке = 8px реального зазора SVG от краёв. */
  padding: 2px;
  box-sizing: border-box;
}
.card-fav-btn:hover,
.lib-fav-btn:hover {
  color: #fbbf24;
  transform: scale(1.08);
}
.card-fav-btn:disabled,
.lib-fav-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

/* Активное состояние — флажок залит золотом, звезда внутри тёмная (вырезанная) */
.card-fav-btn.is-favorite,
.lib-fav-btn.is-favorite {
  color: #fbbf24;
  filter: drop-shadow(0 0 6px rgba(251, 191, 36, 0.55));
}
.card-fav-btn.is-favorite .fav-bookmark,
.lib-fav-btn.is-favorite .fav-bookmark {
  fill: currentColor;
}
.card-fav-btn.is-favorite .fav-star,
.lib-fav-btn.is-favorite .fav-star {
  fill: rgba(15, 23, 42, 0.7);
  stroke: rgba(15, 23, 42, 0.7);
}

/* На плитках библиотеки кнопка прячется до hover (если не активна) */
.lib-fav-btn:not(.is-favorite) {
  opacity: 0;
}
.lib-item:hover .lib-fav-btn {
  opacity: 1;
}

/* === Download-кнопка на плитке Библиотеки ===
   Слева от ★, тот же стиль и поведение (прячется до hover). */
.lib-dl-btn {
  position: absolute;
  z-index: 4;
  top: 4px;
  right: 34px;             /* 4 (right star) + 26 (star width) + 4 (gap) = 34 */
  width: 26px;
  height: 26px;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.85);
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.55));
  transition: color 0.15s, transform 0.1s;
  opacity: 0;
}
.lib-dl-btn svg {
  width: 100%;
  height: 100%;
  padding: 4px;
  box-sizing: border-box;
}
.lib-dl-btn:hover {
  color: var(--accent-cyan, #38bdf8);
  transform: scale(1.08) translateY(1px);
}
.lib-item:hover .lib-dl-btn {
  opacity: 1;
}
[data-theme="light"] .lib-dl-btn {
  color: rgba(0, 0, 0, 0.6);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.18));
}

[data-theme="light"] .card-fav-btn,
[data-theme="light"] .lib-fav-btn {
  color: rgba(0, 0, 0, 0.55);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.18));
}
[data-theme="light"] .card-fav-btn.is-favorite .fav-star,
[data-theme="light"] .lib-fav-btn.is-favorite .fav-star {
  fill: #fffbeb;
  stroke: #fffbeb;
}
.result-item .result-prompt {
  font-size: 12px;
  color: var(--text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 8px;
}
.result-item .result-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.result-item .result-actions .ghost-btn {
  padding: 5px 10px;
  font-size: 11px;
}

/* === Progress card (in-flight request) === */
.progress-card {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(167, 139, 250, 0.25), 0 0 16px rgba(167, 139, 250, 0.08);
}
.progress-card .progress-body {
  padding: 14px;
}
.progress-card .progress-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.progress-card .progress-timer {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  font-family: 'SF Mono', ui-monospace, Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}
.progress-card .progress-stage {
  display: flex;
  gap: 10px;
  align-items: center;
  background: rgba(167, 139, 250, 0.06);
  border: 1px solid rgba(167, 139, 250, 0.25);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 10px;
}
.progress-card .progress-stage .spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(167, 139, 250, 0.3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
.progress-card .stage-label {
  font-size: 13px;
  color: var(--text);
}
.progress-card .progress-prompt {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Failed progress card */
.progress-card-failed {
  border-color: var(--error);
  box-shadow: 0 0 0 1px rgba(248, 113, 113, 0.25);
}
.progress-card-failed .progress-error,
.error-card .progress-error {
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.4);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--error);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
}

/* Error-card в Сессии — без видео-плейсхолдера, тонкая красная рамка */
.error-card {
  position: relative;
  border-color: rgba(248, 113, 113, 0.4) !important;
  background:
    linear-gradient(180deg, rgba(248, 113, 113, 0.05), transparent 60%),
    var(--card, #111827);
}
.error-card .card-close-x {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  width: 24px;
  height: 24px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.4);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
}
.error-card .card-close-x:hover {
  background: rgba(248, 113, 113, 0.2);
  border-color: var(--error);
  transform: scale(1.05);
}
.error-card .error-body {
  padding: 14px 14px 12px;
}
.badge-error {
  background: rgba(248, 113, 113, 0.15);
  color: var(--error, #fca5a5);
  border: 1px solid rgba(248, 113, 113, 0.35);
}
[data-theme="light"] .error-card {
  background:
    linear-gradient(180deg, rgba(248, 113, 113, 0.06), transparent 60%),
    var(--card, #ffffff);
}
[data-theme="light"] .error-card .card-close-x {
  background: rgba(255, 255, 255, 0.7);
  border-color: var(--border);
}

.video-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
  flex-wrap: wrap;
}
.meta { font-size: 12px; color: var(--muted); }

.raw-json {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font-size: 11px;
  overflow: auto;
  max-height: 300px;
  margin-top: 10px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 500px;
  overflow-y: auto;
}
.hist-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.hist-item:hover { border-color: var(--accent); }
.hist-item .h-prompt {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 4px;
}
.hist-item .h-meta { color: var(--muted); font-size: 11px; }

/* ════════════════════════════════════════════════════════════════════════
   THEMES: data-theme на <html> переключает тему
   - glass    : стекло (по умолчанию) — frosted glass + cyan/purple glow
   - minimal  : плоский тёмный — без glassmorphism, ровная сетка серого
   - light    : светлая — белый фон, тёмный текст
   ════════════════════════════════════════════════════════════════════════ */

[data-theme="glass"] {
  --bg: #0a1226;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-2: rgba(255, 255, 255, 0.025);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f1f5fb;
  --muted: rgba(241, 245, 251, 0.55);
  --accent: #a78bfa;
  --accent-strong: #8b5cf6;
  --accent-cyan: #38bdf8;
  --accent-cyan-strong: #0ea5e9;
}

[data-theme="glass"] body {
  background:
    radial-gradient(ellipse 70% 45% at 18% -5%, rgba(56, 189, 248, 0.18) 0%, transparent 65%),
    radial-gradient(ellipse 60% 60% at 85% 100%, rgba(167, 139, 250, 0.22) 0%, transparent 65%),
    radial-gradient(ellipse 80% 60% at 50% 50%, rgba(56, 189, 248, 0.05) 0%, transparent 80%),
    linear-gradient(180deg, #0a1226 0%, #131e3c 50%, #0a1226 100%);
  background-attachment: fixed;
  min-height: 100vh;
}

[data-theme="glass"] body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
  opacity: 0.04;
  mix-blend-mode: overlay;
}

[data-theme="glass"] .topbar {
  background: rgba(10, 18, 38, 0.55);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-bottom-color: rgba(255, 255, 255, 0.06);
}

[data-theme="glass"] .card,
[data-theme="glass"] .refs-pane {
  background: rgba(255, 255, 255, 0.035);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  box-shadow:
    0 16px 40px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
[data-theme="glass"] textarea,
[data-theme="glass"] input[type="text"],
[data-theme="glass"] input[type="number"],
[data-theme="glass"] select {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(8px);
  border-radius: 12px;
}
[data-theme="glass"] textarea:focus,
[data-theme="glass"] input:focus,
[data-theme="glass"] select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.18);
}
[data-theme="glass"] .prompt-grid {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 12px;
}
[data-theme="glass"] .primary-btn {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-cyan) 100%);
  border-radius: 14px;
  padding: 13px 24px;
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow:
    0 12px 32px rgba(167, 139, 250, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.14) inset,
    0 1px 0 rgba(255, 255, 255, 0.25) inset;
  transition: transform 0.15s, box-shadow 0.2s;
}
[data-theme="glass"] .primary-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow:
    0 16px 40px rgba(167, 139, 250, 0.55),
    0 0 0 1px rgba(255, 255, 255, 0.22) inset,
    0 1px 0 rgba(255, 255, 255, 0.32) inset;
}
[data-theme="glass"] .ghost-btn {
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}
[data-theme="glass"] .ghost-btn:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(167, 139, 250, 0.5);
}
[data-theme="glass"] .dz {
  background: rgba(255, 255, 255, 0.025);
  backdrop-filter: blur(12px);
  border: 1px dashed rgba(255, 255, 255, 0.16);
  border-radius: 14px;
}
[data-theme="glass"] .dz:hover:not(.is-full) {
  border-color: var(--accent);
  background: rgba(167, 139, 250, 0.06);
}
[data-theme="glass"] .dz.drag-over {
  background: rgba(56, 189, 248, 0.08);
  border-color: var(--accent-cyan);
}
[data-theme="glass"] input[type="range"]::-webkit-slider-runnable-track {
  background: rgba(255, 255, 255, 0.1);
  height: 6px;
  border-radius: 3px;
}
[data-theme="glass"] input[type="range"]::-moz-range-track {
  background: rgba(255, 255, 255, 0.1);
  height: 6px;
  border-radius: 3px;
}
[data-theme="glass"] input[type="range"]::-webkit-slider-thumb {
  width: 20px;
  height: 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border: 2px solid rgba(255, 255, 255, 0.25);
  margin-top: -7px;
  box-shadow:
    0 0 0 4px rgba(167, 139, 250, 0.18),
    0 4px 12px rgba(167, 139, 250, 0.45);
}
[data-theme="glass"] input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border: 2px solid rgba(255, 255, 255, 0.25);
  box-shadow:
    0 0 0 4px rgba(167, 139, 250, 0.18),
    0 4px 12px rgba(167, 139, 250, 0.45);
}
[data-theme="glass"] .status {
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
}
[data-theme="glass"] .status.idle { color: var(--muted); }
[data-theme="glass"] .status.loading {
  background: rgba(56, 189, 248, 0.06);
  border-color: rgba(56, 189, 248, 0.35);
  color: var(--accent-cyan);
}
[data-theme="glass"] .status.success {
  background: rgba(74, 222, 128, 0.08);
  border-color: rgba(74, 222, 128, 0.4);
}
[data-theme="glass"] .status.error {
  background: rgba(248, 113, 113, 0.08);
  border-color: rgba(248, 113, 113, 0.4);
}
[data-theme="glass"] .result-item {
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.3);
}
[data-theme="glass"] .progress-card {
  border-color: rgba(167, 139, 250, 0.5);
  box-shadow:
    0 0 0 1px rgba(167, 139, 250, 0.3),
    0 0 32px rgba(167, 139, 250, 0.18),
    0 12px 32px rgba(0, 0, 0, 0.35);
}
[data-theme="glass"] .progress-card .progress-stage {
  background: rgba(167, 139, 250, 0.08);
  border: 1px solid rgba(167, 139, 250, 0.3);
  border-radius: 10px;
}
[data-theme="glass"] .lib-item {
  background: rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
}
[data-theme="glass"] .lib-filter-pill {
  background: rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(10px);
  border-color: rgba(255, 255, 255, 0.08);
}
[data-theme="glass"] .lib-filter-pill.active {
  box-shadow: 0 0 0 1px var(--pill-color, var(--accent)), 0 0 16px var(--pill-bg);
}
[data-theme="glass"] .tag,
[data-theme="glass"] .badge {
  background: rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
[data-theme="glass"] .inflight-badge {
  background: rgba(167, 139, 250, 0.12);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(167, 139, 250, 0.45);
  box-shadow: 0 0 24px rgba(167, 139, 250, 0.3);
}
[data-theme="glass"] .model-tabs {
  background: rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
}
[data-theme="glass"] .model-tab.active {
  background: rgba(167, 139, 250, 0.12);
  color: var(--accent);
  box-shadow: 0 0 0 1px rgba(167, 139, 250, 0.3), 0 0 16px rgba(167, 139, 250, 0.18);
}
[data-theme="glass"] .tab-btn.active {
  border-bottom-color: var(--accent);
  color: var(--accent);
}
[data-theme="glass"] .preview-modal {
  background: rgba(10, 18, 38, 0.7);
  backdrop-filter: blur(28px) saturate(180%);
}
[data-theme="glass"] .check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}
[data-theme="glass"] .preview-item {
  border-radius: 8px;
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}
[data-theme="glass"] ::-webkit-scrollbar { width: 10px; height: 10px; }
[data-theme="glass"] ::-webkit-scrollbar-track { background: transparent; }
[data-theme="glass"] ::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
[data-theme="glass"] ::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.15);
  background-clip: padding-box;
}
[data-theme="glass"] .dz-title { color: var(--text); }
[data-theme="glass"] .prompt-textarea {
  border-color: rgba(255, 255, 255, 0.08);
}
[data-theme="glass"] .prompt-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.18);
}
[data-theme="glass"] .ref-highlight {
  background: rgba(167, 139, 250, 0.18);
  outline-color: rgba(167, 139, 250, 0.55);
  box-shadow: 0 0 8px rgba(167, 139, 250, 0.25);
}
[data-theme="glass"] .ref-highlight.ref-missing {
  background: rgba(248, 113, 113, 0.22);
  outline: 1px dashed rgba(248, 113, 113, 0.85);
  box-shadow: 0 0 8px rgba(248, 113, 113, 0.25);
}
[data-theme="glass"] .ref-highlight.ref-sparse {
  background: rgba(251, 146, 60, 0.32);
  outline: 1px dashed rgba(251, 146, 60, 0.95);
  box-shadow: 0 0 8px rgba(251, 146, 60, 0.3);
}
[data-theme="glass"] .refs-pane-head .ghost-btn.small {
  padding: 5px 10px;
  font-size: 11px;
}

/* === Тема: minimal (плоская тёмная, без glassmorphism) === */
[data-theme="minimal"] {
  --bg: #0a0a0c;
  --surface: #131318;
  --surface-2: #1a1a21;
  --border: #26262d;
  --border-strong: #34343d;
  --text: #e8e8ec;
  --muted: #8a8a93;
  --accent: #a78bfa;
  --accent-strong: #8b5cf6;
}

/* === Тема: light (светлая) === */
[data-theme="light"] {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f5;
  --border: #d6dae3;
  --border-strong: #b9bfcc;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #7c3aed;
  --accent-strong: #6d28d9;
  --accent-cyan: #0ea5e9;
}
[data-theme="light"] body {
  background: linear-gradient(180deg, #eef1f7 0%, #f5f7fb 50%, #eef1f7 100%);
  background-attachment: fixed;
  color: var(--text);
}
[data-theme="light"] .card,
[data-theme="light"] .refs-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
}
[data-theme="light"] .topbar {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  border-bottom-color: var(--border);
}
[data-theme="light"] textarea,
[data-theme="light"] input[type="text"],
[data-theme="light"] input[type="number"],
[data-theme="light"] select {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
[data-theme="light"] .prompt-grid {
  background: var(--surface-2);
}
[data-theme="light"] .prompt-textarea {
  color: var(--text);
}
[data-theme="light"] .ghost-btn {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
[data-theme="light"] .ghost-btn:hover {
  background: var(--surface-2);
  border-color: var(--accent);
}
[data-theme="light"] .primary-btn {
  background: linear-gradient(135deg, var(--accent) 0%, #6366f1 100%);
  color: #fff;
}
[data-theme="light"] .dz {
  background: var(--surface-2);
  border-color: var(--border);
}
[data-theme="light"] .ref-highlight {
  background: rgba(124, 58, 237, 0.15);
  outline-color: rgba(124, 58, 237, 0.5);
  color: var(--accent);
}
[data-theme="light"] .ref-highlight.ref-missing {
  background: rgba(220, 38, 38, 0.16);
  outline: 1px dashed rgba(220, 38, 38, 0.65);
}
[data-theme="light"] .ref-highlight.ref-sparse {
  background: rgba(234, 88, 12, 0.20);
  outline: 1px dashed rgba(234, 88, 12, 0.75);
}
[data-theme="light"] .status.idle { background: var(--surface-2); }
[data-theme="light"] .preview-modal { background: rgba(15, 23, 42, 0.5); }
[data-theme="light"] code {
  background: var(--surface-2);
  color: var(--accent);
}

/* === Theme toggle: тройной рубильник в user-меню === */
.user-menu-section {
  padding: 10px 10px 8px;
}
.user-menu-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted, #94a3b8);
  margin-bottom: 6px;
  padding-left: 2px;
}
.theme-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
  padding: 3px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
}
.theme-toggle-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-muted, #94a3b8);
  cursor: pointer;
  font-family: inherit;
  font-size: 10px;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.theme-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}
.theme-toggle-btn.is-active {
  background: linear-gradient(135deg, rgba(167, 139, 250, 0.18), rgba(56, 189, 248, 0.14));
  border-color: rgba(167, 139, 250, 0.35);
  color: var(--text);
  box-shadow: 0 0 10px rgba(167, 139, 250, 0.2) inset;
}
.theme-toggle-icon {
  font-size: 14px;
  line-height: 1;
}
.theme-toggle-label {
  font-weight: 500;
  letter-spacing: 0.01em;
}
[data-theme="light"] .theme-toggle {
  background: var(--surface, #f3f4f6);
  border-color: var(--border, #e5e7eb);
}
[data-theme="light"] .theme-toggle-btn:hover {
  background: rgba(0, 0, 0, 0.04);
}
[data-theme="light"] .theme-toggle-btn.is-active {
  background: linear-gradient(135deg, rgba(167, 139, 250, 0.18), rgba(56, 189, 248, 0.18));
  border-color: rgba(167, 139, 250, 0.45);
}

/* === Quota badge в топбаре === */
.quota-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  color: var(--text);
  font-size: 11px;
  line-height: 1.3;
  white-space: nowrap;
  cursor: default;
}
.quota-badge.is-low {
  border-color: rgba(250, 204, 21, 0.4);
  background: rgba(250, 204, 21, 0.08);
}
.quota-badge.is-exhausted {
  border-color: rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.08);
  color: #fca5a5;
}
.quota-icon {
  font-size: 12px;
  filter: saturate(1.1);
}
.quota-text {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.quota-sep {
  opacity: 0.5;
}
.quota-coin-unit {
  opacity: 0.6;
  font-size: 10px;
  letter-spacing: 0.02em;
}
[data-theme="light"] .quota-badge {
  background: var(--surface);
  border-color: var(--border);
}

/* === Cost-индикатор на кнопке Сгенерировать === */
.primary-btn .btn-label {
  display: inline-block;
}
.primary-btn .btn-cost {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  vertical-align: middle;
}
.primary-btn:disabled .btn-cost {
  opacity: 0.7;
}
[data-theme="light"] .primary-btn .btn-cost {
  background: rgba(255, 255, 255, 0.28);
}

/* === User badge в топбаре === */
.user-badge {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.user-menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.user-menu-btn:hover {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.07);
}
.user-badge-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent, #a78bfa), var(--accent-cyan, #38bdf8));
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  flex-shrink: 0;
  box-shadow: 0 0 10px rgba(167, 139, 250, 0.35);
}
.user-email {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-chevron {
  opacity: 0.6;
  transition: transform 0.15s;
}
.user-menu-btn[aria-expanded="true"] .user-chevron {
  transform: rotate(180deg);
}
.user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: var(--card, #111827);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
  padding: 8px;
  z-index: 100;
  backdrop-filter: blur(14px);
}
.user-menu-info {
  padding: 8px 10px 10px;
}
.user-menu-email {
  font-size: 12px;
  color: var(--text);
  word-break: break-all;
  line-height: 1.35;
}
.user-menu-role {
  margin-top: 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted, #94a3b8);
}
.user-menu-role.is-admin {
  color: #fde68a;
}
.user-menu-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.07);
  margin: 4px 0;
}
.user-menu-item {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-family: inherit;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.12s;
}
.user-menu-item:hover {
  background: rgba(255, 255, 255, 0.06);
}
.user-menu-item:disabled {
  opacity: 0.5;
  cursor: wait;
}
[data-theme="light"] .user-menu-btn {
  background: var(--surface);
  border-color: var(--border);
}
[data-theme="light"] .user-menu-btn:hover {
  background: #f3f4f6;
}
[data-theme="light"] .user-menu {
  background: #ffffff;
  border-color: var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}
[data-theme="light"] .user-menu-divider {
  background: var(--border);
}
[data-theme="light"] .user-menu-item:hover {
  background: #f3f4f6;
}

/* === Inline-кнопка копирования промпта (рядом с label «Промпт *») === */
.prompt-label-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.prompt-label-row .lbl {
  margin-bottom: 0;
}
.prompt-copy-btn {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  padding: 0;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s, background 0.15s, transform 0.15s;
}
.prompt-copy-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(167, 139, 250, 0.1);
}
.prompt-copy-btn:active {
  transform: scale(0.92);
}
.prompt-copy-btn.copied {
  color: var(--success);
  border-color: var(--success);
  background: rgba(74, 222, 128, 0.1);
}
.prompt-copy-btn svg {
  width: 11px;
  height: 11px;
}

/* === Кнопка копирования (иконка в углу карточки) === */
.card { position: relative; }  /* для абсолютного позиционирования copy-btn */
.card-copy-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 3;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  padding: 0;
  transition: color 0.15s, border-color 0.15s, background 0.15s, transform 0.15s;
}
.card-copy-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(167, 139, 250, 0.1);
}
.card-copy-btn:active {
  transform: scale(0.94);
}
.card-copy-btn.copied {
  color: var(--success);
  border-color: var(--success);
  background: rgba(74, 222, 128, 0.1);
}
.card-copy-btn.copied svg {
  /* Анимация лёгкой отрисовки галочки */
  animation: copyPulse 0.4s ease-out;
}
@keyframes copyPulse {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.result-item {
  position: relative;
}

/* Copy-кнопка в правом крае строки мета-инфо */
.meta-copy-btn {
  margin-left: auto;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  padding: 0;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s, background 0.15s, transform 0.15s;
}
.meta-copy-btn svg {
  width: 12px;
  height: 12px;
}
.meta-copy-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(167, 139, 250, 0.1);
}
.meta-copy-btn:active {
  transform: scale(0.92);
}
.meta-copy-btn.copied {
  color: var(--success);
  border-color: var(--success);
  background: rgba(74, 222, 128, 0.1);
}

/* meta-строка должна быть flex-row, чтобы margin-left:auto толкнул кнопку вправо */
.result-item .result-meta {
  align-items: center;
}

/* Disabled-вид у поля seed когда чекбокс «Random seed» включён — поле
   серое, нередактируемое; визуальный сигнал что значение игнорируется. */
input#seed.is-disabled,
input#seed:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Кликабельный chip с seed — копирует значение в буфер обмена при клике.
   Подсказка курсором + лёгкий hover-эффект, чтобы было понятно что это кнопка. */
.result-item .result-meta .seed-chip {
  cursor: pointer;
  border-radius: 4px;
  padding: 2px 6px;
  margin: -2px -6px;
  transition: background 0.12s ease, color 0.12s ease;
  user-select: none;
}
.result-item .result-meta .seed-chip:hover {
  background: rgba(167, 139, 250, 0.15);
  color: var(--accent);
}
.result-item .result-meta .seed-chip.copied {
  background: rgba(74, 222, 128, 0.18);
  color: var(--success);
}
[data-theme="glass"] .result-item .result-meta .seed-chip:hover {
  background: rgba(167, 139, 250, 0.22);
}

/* Крестик в правом верхнем углу карточки — убирает её из Сессии */
.card-close-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  font-size: 18px;
  line-height: 1;
  padding: 0;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.15s;
}
.card-close-btn:hover {
  background: var(--error);
  border-color: var(--error);
  color: #fff;
}
.card-close-btn:active {
  transform: scale(0.94);
}

/* === Сворачиваемые секции === */
.card.collapsible > .card-title {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 4px 0;
  position: relative;
  transition: color 0.15s;
}
.card.collapsible > .card-title:hover { color: var(--text); }
.card.collapsible > .card-title::before {
  content: '▼';
  font-size: 8px;
  display: inline-block;
  transition: transform 0.2s;
  width: 10px;
  text-align: center;
  color: var(--accent);
}
.card.collapsible.collapsed > .card-title {
  margin-bottom: 0;
}
.card.collapsible.collapsed > .card-title::before {
  transform: rotate(-90deg);
}
/* Прячем всё кроме заголовка, когда свёрнуто */
.card.collapsible.collapsed > *:not(.card-title) {
  display: none !important;
}
/* В свёрнутом виде уменьшаем padding снизу */
.card.collapsible.collapsed {
  padding-bottom: 14px;
}

