/* ──────────────────────────── базовая палитра ──────────────────────────── */
:root {
  --bg: #0d0d0e;
  --bg-elevated: #16161a;
  --bg-hover: #1f1f24;
  --bg-input: #0a0a0c;
  --border: #28282e;
  --border-strong: #3a3a42;
  --text: #e8e8ea;
  --text-dim: #92929a;
  --text-faint: #56565e;
  --accent: #f5d547;       /* приглушённый жёлтый */
  --accent-soft: #f5d54720;
  --success: #6ec77a;
  --error: #e87b7b;
  --warning: #e8b25a;
  --info: #7ab9e8;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ──────────────────────────── layout ──────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.main {
  padding: 32px 40px;
  max-width: 1400px;
  width: 100%;
}

/* ──────────────────────────── brand ──────────────────────────── */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 16px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 32px;
  height: 32px;
  background: var(--accent);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  border-radius: 4px;
}
.brand-name {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.05em;
}
.brand-sub {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.05em;
}

/* ──────────────────────────── навигация ──────────────────────────── */
.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.nav-section {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 16px 12px 8px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 4px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
  transition: background 0.1s, color 0.1s;
}
.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.nav-item.active {
  background: var(--bg);
  color: var(--accent);
  border-left: 2px solid var(--accent);
  padding-left: 10px;
}
.nav-icon {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 14px;
  width: 16px;
  text-align: center;
}

.warning-block {
  padding: 12px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 4px;
  font-size: 12px;
}
.warning-title {
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 4px;
  font-family: 'IBM Plex Mono', monospace;
}
.warning-block a {
  color: var(--text);
  text-decoration: none;
  font-size: 12px;
}

/* ──────────────────────────── типографика ──────────────────────────── */
h1 {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}
h2 {
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}
h3 {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}
.page-subtitle {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 4px;
}

.mono { font-family: 'IBM Plex Mono', monospace; }
.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }

/* ──────────────────────────── кнопки ──────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.1s;
}
.btn:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
}
.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover {
  filter: brightness(1.1);
  background: var(--accent);
}
.btn-primary:disabled {
  background: var(--bg-hover);
  color: var(--text-faint);
  cursor: not-allowed;
  border-color: var(--border);
}
.btn-danger {
  color: var(--error);
}
.btn-danger:hover {
  border-color: var(--error);
}
.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}
.btn-block {
  width: 100%;
  justify-content: center;
}

/* ──────────────────────────── формы ──────────────────────────── */
.field {
  margin-bottom: 16px;
}
.field-label {
  display: block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field-hint {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 4px;
}
input[type="text"],
input[type="number"],
input[type="password"],
textarea,
select {
  width: 100%;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 12px;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 13px;
  transition: border-color 0.1s;
}
textarea {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  line-height: 1.5;
  resize: vertical;
  min-height: 100px;
}
input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
}

/* ──────────────────────────── карточки запусков (галерея) ──────────────────────────── */
.runs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.run-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  transition: border-color 0.15s, transform 0.15s;
  text-decoration: none;
  color: var(--text);
  display: block;
}
.run-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
}
.run-card-thumb {
  aspect-ratio: 9/16;
  background: var(--bg);
  background-size: cover;
  background-position: center;
  position: relative;
  border-bottom: 1px solid var(--border);
  max-height: 320px;
}
.run-card-thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.1em;
}
.run-card-info {
  padding: 12px;
}
.run-card-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.run-card-character {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
  text-transform: capitalize;
}
.run-card-scene {
  font-size: 12px;
  color: var(--text-dim);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 8px;
}
.run-card-meta {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.stage-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-faint);
  letter-spacing: 0.05em;
}
.stage-badge.done {
  color: var(--success);
  border-color: var(--success);
}

/* ──────────────────────────── страница запуска ──────────────────────────── */
.run-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px 20px;
  margin-bottom: 24px;
}
.run-meta-item {
  font-size: 13px;
}
.run-meta-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 2px;
}

.stage {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 16px;
  overflow: hidden;
}
.stage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.stage-title {
  display: flex;
  align-items: center;
  gap: 12px;
}
.stage-num {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--text-dim);
}
.stage.done .stage-num {
  background: var(--success);
  color: var(--bg);
  border-color: var(--success);
}
.stage.running .stage-num {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  animation: pulse 1s ease-in-out infinite alternate;
}
@keyframes pulse {
  from { opacity: 1; }
  to { opacity: 0.5; }
}
.stage-name {
  font-weight: 600;
  font-size: 14px;
}
.stage-model {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-dim);
}
.stage-status {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.stage-status.idle { color: var(--text-faint); }
.stage-status.running { color: var(--accent); }
.stage-status.completed { color: var(--success); }
.stage-status.failed { color: var(--error); }

.stage-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}
.stage-controls {
  padding: 20px;
  border-right: 1px solid var(--border);
}
.stage-preview {
  padding: 20px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 280px;
}
.stage-preview img,
.stage-preview video {
  max-width: 100%;
  max-height: 480px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.stage-preview-empty {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  text-align: center;
}

.stage-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ──────────────────────────── логи (терминал) ──────────────────────────── */
.log-panel {
  background: #050507;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  line-height: 1.6;
  color: var(--text-dim);
  max-height: 240px;
  overflow-y: auto;
  margin-top: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.log-panel.empty {
  display: none;
}
.log-panel .ok { color: var(--success); }
.log-panel .err { color: var(--error); }

/* ──────────────────────────── таблицы ──────────────────────────── */
.table {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.table th, .table td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.table th {
  background: var(--bg);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 500;
}
.table tr:last-child td {
  border-bottom: none;
}
.table tr:hover td {
  background: var(--bg-hover);
}

/* ──────────────────────────── формы и блоки ──────────────────────────── */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 24px;
}
.card + .card {
  margin-top: 16px;
}

.error-msg {
  background: #2c1717;
  border: 1px solid var(--error);
  color: var(--error);
  padding: 10px 14px;
  border-radius: 4px;
  font-size: 13px;
  margin-bottom: 16px;
}
.success-msg {
  background: #142817;
  border: 1px solid var(--success);
  color: var(--success);
  padding: 10px 14px;
  border-radius: 4px;
  font-size: 13px;
  margin-bottom: 16px;
}

.toggle-row {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: var(--bg-input);
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  width: fit-content;
}
.toggle-btn {
  padding: 6px 14px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  border-radius: 3px;
  font-family: 'IBM Plex Sans', sans-serif;
}
.toggle-btn.active {
  background: var(--bg-hover);
  color: var(--text);
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-faint);
}
.empty-state-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 14px;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  color: var(--text-dim);
}
.empty-state-hint {
  font-size: 13px;
  margin-bottom: 16px;
}

/* ──────────────────────────── история lipsync ──────────────────────────── */
.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.history-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px;
}
.history-item video {
  width: 100%;
  border-radius: 3px;
  margin-bottom: 6px;
}
.history-model {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--accent);
}

/* ──────────────────────────── скроллбары ──────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ──────────────────────────── inline links ──────────────────────────── */
a { color: var(--info); }
a:hover { color: var(--text); }

/* ──────────────────────────── responsive ──────────────────────────── */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .stage-body { grid-template-columns: 1fr; }
  .stage-controls { border-right: none; border-bottom: 1px solid var(--border); }
}

/* ──────────────────────────── анализ аудио ──────────────────────────── */
.audio-analysis {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px;
  margin-bottom: 16px;
}
.audio-analysis-error,
.audio-analysis-warn {
  background: var(--bg);
  border: 1px solid var(--warning);
  color: var(--warning);
  padding: 10px;
  border-radius: 4px;
  font-size: 12px;
  margin-bottom: 16px;
}
.audio-analysis h3 {
  margin-bottom: 10px;
}
.audio-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 6px;
  font-size: 12px;
  margin-bottom: 10px;
}
.audio-stats .mono {
  color: var(--text);
  font-weight: 500;
}
.audio-bar {
  display: flex;
  height: 28px;
  border-radius: 3px;
  overflow: hidden;
  background: var(--bg-input);
  border: 1px solid var(--border);
  margin-top: 8px;
}
.audio-bar > div {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.1em;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 0.15s;
}
.audio-bar-silence {
  background: var(--bg-input);
  color: var(--text-faint);
}
.audio-bar-speech {
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
}
.audio-warn {
  background: #2c2317;
  border: 1px solid var(--warning);
  color: var(--warning);
  padding: 8px 10px;
  border-radius: 3px;
  font-size: 11px;
  margin-top: 8px;
}

/* ──────────────────────────── frames галерея ──────────────────────────── */
.frames-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.frame-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.frame-thumb {
  aspect-ratio: 9/16;
  background-size: cover;
  background-position: center;
  background-color: var(--bg);
  border-bottom: 1px solid var(--border);
  max-height: 320px;
}
.frame-info {
  padding: 10px;
}
.frame-name {
  font-size: 11px;
  color: var(--text);
  word-break: break-all;
  margin-bottom: 4px;
}
.frame-meta {
  font-size: 11px;
}

/* ──────────────────────────── переключатель режимов запуска ──────────────────────────── */
.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.mode-tab {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'IBM Plex Sans', sans-serif;
  color: var(--text);
}
.mode-tab:hover {
  border-color: var(--border-strong);
}
.mode-tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.mode-tab-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}
.mode-tab-sub {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-dim);
}

/* ──────────────────────────── BATCH режим ──────────────────────────── */

/* Селектор кадров (на форме создания batch) */
.batch-frames-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 8px;
}
.batch-frame-item {
  display: block;
  cursor: pointer;
  position: relative;
}
.batch-frame-checkbox {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.batch-frame-thumb {
  aspect-ratio: 9/16;
  background-size: cover;
  background-position: center;
  background-color: var(--bg);
  border: 2px solid var(--border);
  border-radius: 4px;
  position: relative;
  transition: border-color 0.1s, transform 0.1s;
}
.batch-frame-checkbox:checked + .batch-frame-thumb {
  border-color: var(--accent);
}
.batch-frame-checkbox:disabled + .batch-frame-thumb {
  opacity: 0.4;
}
.batch-frame-check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  background: var(--accent);
  color: var(--bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.15s;
}
.batch-frame-checkbox:checked + .batch-frame-thumb .batch-frame-check {
  opacity: 1;
}
.batch-frame-name {
  font-size: 10px;
  color: var(--text-faint);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Бейдж "×N" поверх превью на главной */
.run-card-batch-overlay {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--accent);
  color: var(--bg);
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 12px;
}

/* Сетка вариантов на странице batch */
.batch-variants-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.variant-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.variant-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.variant-num {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
}
.variant-status {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 3px;
  background: var(--bg-input);
  color: var(--text-faint);
}
.variant-status.idle,
.variant-status.queued { color: var(--text-faint); }
.variant-status.uploading_frame,
.variant-status.generating_video,
.variant-status.generating_lipsync {
  color: var(--accent);
  background: var(--accent-soft);
  animation: pulse 1.2s ease-in-out infinite alternate;
}
.variant-status.completed {
  color: var(--success);
  background: #142817;
}
.variant-status.failed {
  color: var(--error);
  background: #2c1717;
}
.variant-preview {
  aspect-ratio: 9/16;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  max-height: 380px;
}
.variant-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.variant-frame-preview {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  filter: grayscale(0.4) brightness(0.7);
}
.variant-info {
  padding: 10px 14px;
}
.variant-stages {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}
.variant-stage {
  flex: 1;
  text-align: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.05em;
  padding: 3px 4px;
  border-radius: 3px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-faint);
}
.variant-stage.done {
  color: var(--success);
  border-color: var(--success);
}
.variant-error {
  margin-top: 8px;
  padding: 6px 8px;
  background: #2c1717;
  border: 1px solid var(--error);
  border-radius: 3px;
  color: var(--error);
  font-size: 11px;
  word-break: break-word;
}

/* ──────────────────────────── удаление и корзина ──────────────────────────── */

.run-card-wrapper {
  position: relative;
}

/* Форма с кнопкой удаления — поверх правого нижнего угла карточки */
.run-card-delete-form {
  position: absolute;
  top: 8px;
  right: 8px;
  opacity: 0;
  transition: opacity 0.15s;
}
.run-card-wrapper:hover .run-card-delete-form {
  opacity: 1;
}
.run-card-delete-btn {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.7);
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.run-card-delete-btn:hover {
  background: var(--error);
  color: var(--bg);
  border-color: var(--error);
}

/* В корзине карточка без hover-эффекта удаления */
.trash-card {
  /* кнопки рядом, не в overlay */
}
.trash-card .run-card {
  cursor: default;
}


/* ──────────────────────────── prompt uploader (📄 кнопка рядом с textarea) ──────────────────────────── */

.prompt-upload-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  transition: border-color 0.1s, color 0.1s;
}
.prompt-upload-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.prompt-upload-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ──────────────────────────── batch v2 — карточки вариантов в форме ──────────────────────────── */

.batch-variants-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.batch-variant-form-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.batch-variant-form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.batch-variant-form-title {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
}

.batch-variant-form-num {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
}

.batch-variant-form-body {
  padding: 16px;
}

.batch-variant-mode-toggle {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  width: fit-content;
  margin-bottom: 16px;
}

.batch-variant-mode-toggle .toggle-btn {
  padding: 6px 14px;
}

.batch-variant-advanced {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.batch-variant-advanced-toggle {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.batch-variant-advanced-toggle:hover {
  color: var(--accent);
}

.batch-variant-advanced-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.batch-add-variant {
  margin-top: 16px;
  padding: 16px;
  border: 1px dashed var(--border-strong);
  border-radius: 6px;
  text-align: center;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  width: 100%;
  transition: border-color 0.1s, color 0.1s;
}
.batch-add-variant:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.batch-add-variant:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Селектор кадра (одиночный, в карточке варианта) */
.variant-frame-selector {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
  padding: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.variant-frame-option {
  display: block;
  cursor: pointer;
  position: relative;
}
.variant-frame-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.variant-frame-option-thumb {
  aspect-ratio: 9/16;
  background-size: cover;
  background-position: center;
  background-color: var(--bg);
  border: 2px solid var(--border);
  border-radius: 3px;
  position: relative;
}
.variant-frame-option input:checked + .variant-frame-option-thumb {
  border-color: var(--accent);
}
.variant-frame-option-name {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  color: var(--text-faint);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Бейджик статуса в шапке карточки варианта */
.variant-form-status-completed {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 3px 8px;
  background: #142817;
  color: var(--success);
  border-radius: 3px;
}

/* ──────────────────────────── Активные задачи в sidebar ──────────────────────────── */

.active-jobs-block {
  margin: 16px 12px 12px;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--accent);
  border-radius: 4px;
}

.active-jobs-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 8px;
}

.active-jobs-spinner {
  display: inline-block;
  animation: spin 2s linear infinite;
  font-size: 13px;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.active-jobs-count {
  margin-left: auto;
  background: var(--accent);
  color: var(--bg);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 9px;
  font-weight: 600;
}

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

.active-job-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  text-decoration: none;
  font-size: 11px;
  color: var(--text);
  font-family: 'IBM Plex Mono', monospace;
  transition: border-color 0.1s;
}

.active-job-item:hover {
  border-color: var(--accent);
}

.active-job-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-faint);
}

.active-job-status-dot.running {
  background: var(--accent);
  animation: pulse-dot 1.2s ease-in-out infinite;
}

.active-job-status-dot.queued {
  background: var(--text-dim);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.active-job-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
}

/* ──────────────────────────── Карточки персонажей ──────────────────────────── */

.characters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  max-width: 900px;
}

.character-card {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  transition: border-color 0.1s;
}

.character-card:hover {
  border-color: var(--accent);
}

.character-card-link {
  display: block;
  text-decoration: none;
  color: var(--text);
}

.character-card-photo {
  width: 100%;
  aspect-ratio: 3/4;
  background-size: cover;
  background-position: center;
  background-color: var(--bg);
}

.character-card-photo-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-faint);
  background: var(--bg);
}

.character-card-info {
  padding: 10px 12px;
}

.character-card-name {
  font-weight: 500;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.character-card-id {
  font-size: 11px;
}

.character-card-delete-form {
  position: absolute;
  top: 8px;
  right: 8px;
  opacity: 0;
  transition: opacity 0.15s;
}

.character-card:hover .character-card-delete-form {
  opacity: 1;
}

.character-card-delete-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.7);
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.character-card-delete-btn:hover {
  background: var(--error);
  color: var(--bg);
  border-color: var(--error);
}

/* ──────────────────────────── Превью персонажа на странице генерации кадров ──────────────────────────── */

.character-preview-inline {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-top: 8px;
}

.character-preview-inline-photo {
  width: 56px;
  height: 56px;
  background-size: cover;
  background-position: center;
  background-color: var(--bg);
  border-radius: 4px;
  flex-shrink: 0;
}

.character-preview-inline-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.character-preview-inline-name {
  font-weight: 500;
}

.character-preview-inline-id {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-dim);
}

/* ==================== auth и аккаунт (тёмная тема) ==================== */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  color: var(--text);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 32px;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.auth-title { font-size: 20px; margin: 0 0 4px 0; color: var(--text); }
.auth-hint { color: var(--text-dim); font-size: 13px; margin-bottom: 20px; line-height: 1.5; }
.auth-form { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.auth-alt { margin-top: 18px; font-size: 13px; text-align: center; color: var(--text-dim); }
.form-label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-dim); }
.form-input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  background: var(--bg-input);
  color: var(--text);
  width: 100%;
  box-sizing: border-box;
}
.form-input.mono { font-family: 'IBM Plex Mono', monospace; }
.form-input:focus { outline: none; border-color: var(--accent); }
.form-checkbox { font-size: 13px; color: var(--text-dim); display: flex; gap: 6px; align-items: center; }
.form-err { font-size: 12px; color: #ff6b6b; margin-top: 2px; }
.btn-wide { width: 100%; }
.btn-small { padding: 4px 10px; font-size: 12px; }
.btn-ghost { background: transparent; }
.flash { padding: 8px 12px; margin: 0 0 16px 0; border-radius: 6px; font-size: 13px; }
.flash-error { background: rgba(255, 107, 107, 0.12); color: #ffb0b0; border: 1px solid rgba(255, 107, 107, 0.4); }
.flash-success { background: rgba(165, 214, 167, 0.12); color: #a5d6a7; border: 1px solid rgba(165, 214, 167, 0.4); }

/* ==================== sidebar user block ==================== */
.user-block {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.user-email { font-size: 11px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ==================== аккаунт ==================== */
.account-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.account-grid .card-wide { grid-column: 1 / -1; }
.card-hint { font-size: 12px; color: var(--text-dim); margin-bottom: 12px; line-height: 1.5; }
.muted { color: var(--text-faint); }
.small { font-size: 11px; }
@media (max-width: 800px) {
  .account-grid { grid-template-columns: 1fr; }
}

/* ==================== download buttons ==================== */
.download-row {
  display: flex;
  gap: 6px;
  padding: 8px 0 0 0;
  justify-content: center;
}
.frame-thumb { position: relative; }
.frame-download-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  border-radius: 4px;
  text-decoration: none;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.frame-card:hover .frame-download-btn { opacity: 1; }

/* ==================== admin ==================== */
.admin-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.admin-tab {
  padding: 8px 14px;
  text-decoration: none;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  font-size: 13px;
}
.admin-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}
.admin-tab:hover { color: var(--text); }

.metrics-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.metric-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text);
}
.metric-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.metric-value { font-size: 28px; font-weight: 600; margin-top: 4px; color: var(--text); }
.metric-sub { font-size: 11px; color: var(--text-dim); margin-top: 4px; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  color: var(--text);
}
.data-table th, .data-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th { font-weight: 600; color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.data-table tr.row-inactive { opacity: 0.5; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.inline-form .form-input { width: auto; }

/* ==================== balance pill (на /account) ==================== */
.balance-pill {
  display: inline-flex;
  gap: 8px;
  align-items: baseline;
  padding: 8px 14px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 16px;
  color: var(--text);
}
.balance-pill-label { color: var(--text-dim); }
.balance-pill-value {
  font-weight: 700;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 16px;
  color: var(--accent);
}
.balance-pill-error {
  background: rgba(255, 107, 107, 0.12);
  border-color: rgba(255, 107, 107, 0.4);
  color: #ffb0b0;
}

/* ==================== sidebar balance block ==================== */
.sidebar-balance {
  margin: 12px 16px 0 16px;
  padding: 10px 12px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-balance-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-dim);
  letter-spacing: 0.05em;
}
.sidebar-balance-value {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}

/* Расцветка sidebar-balance в зависимости от типа */
/* live (Баланс fal.ai) — accent-цвет (жёлтый), уже задан выше */
/* spent — приглушённый серый, чтобы не путать с балансом */
.sidebar-balance-spent {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}
.sidebar-balance-spent .sidebar-balance-value { color: var(--text); }
/* budget — зелёный оттенок */
.sidebar-balance-budget {
  background: rgba(165, 214, 167, 0.10);
  border-color: rgba(165, 214, 167, 0.4);
}
.sidebar-balance-budget .sidebar-balance-value { color: #a5d6a7; }

/* ==================== аудио-настройки на странице запуска ==================== */
.audio-settings {
  margin-bottom: 16px;
  padding: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.audio-settings .field { margin-bottom: 0; }
input[type="range"] {
  width: 100%;
  margin-top: 4px;
  accent-color: var(--accent);
}
.duration-cost {
  font-weight: normal;
  color: var(--text-dim, #888);
  font-size: 11px;
}
