:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3250;
  --accent: #6c63ff;
  --accent2: #a78bfa;
  --text: #e2e8f0;
  --muted: #64748b;
  --success: #10b981;
  --warn: #f59e0b;
  --error: #ef4444;
  --radius: 12px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
header h1 { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; }
header .logo { font-size: 1.5rem; }

/* ── Progress bar ── */
.steps {
  display: flex;
  align-items: center;
  padding: 16px 32px;
  gap: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  transition: color 0.3s;
}
.step.active { color: var(--accent2); }
.step.done { color: var(--success); }
.step-num {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--surface2);
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 700;
  transition: all 0.3s;
}
.step.active .step-num { background: var(--accent); border-color: var(--accent); color: #fff; }
.step.done .step-num { background: var(--success); border-color: var(--success); color: #fff; }
.step-divider { flex: 1; min-width: 20px; height: 1px; background: var(--border); margin: 0 8px; }

/* ── App layout with sidebar ── */
.app-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Sidebar ── */
#sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-new {
  width: 100%;
  justify-content: center;
  margin-bottom: 4px;
}

.sidebar-section-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 4px 4px 2px;
}

#job-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-item {
  padding: 10px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}
.sidebar-item:hover {
  background: var(--surface2);
  border-color: var(--border);
}
.sidebar-item.active {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  border-color: var(--accent);
}

.sidebar-item-name {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-item-meta {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 3px;
}

.sidebar-empty {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 8px 4px;
  text-align: center;
}

/* ── Main layout ── */
main {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
  min-width: 0;
}

@media (max-width: 900px) {
  .app-layout { flex-direction: column; }
  #sidebar { width: 100%; min-width: unset; border-right: none; border-bottom: 1px solid var(--border); max-height: 200px; }
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}
.card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 16px; color: var(--accent2); }

/* ── Form elements ── */
label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; }

input[type=text], input[type=number], textarea, select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 14px;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  resize: vertical;
}
input[type=text]:focus, input[type=number]:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 120px; }
textarea.large { min-height: 300px; line-height: 1.7; }

/* ── Buttons ── */
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

button {
  padding: 10px 20px;
  border-radius: 8px;
  border: none;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex; align-items: center; gap: 6px;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #7c74ff; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #059669; }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent2); }
.btn-ghost.active { border-color: var(--accent); color: var(--accent2); background: rgba(108,99,255,0.1); }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }

/* ── Two column layout ── */
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 768px) { .cols { grid-template-columns: 1fr; } }

/* ── Image prompts ── */
.prompt-list { display: flex; flex-direction: column; gap: 10px; }
.prompt-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}
.prompt-item-layout {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 12px;
  align-items: start;
}
@media (max-width: 600px) { .prompt-item-layout { grid-template-columns: 80px 1fr; } }

.prompt-item-thumb {
  width: 120px;
  aspect-ratio: 16/9;
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.prompt-item-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  cursor: pointer;
  display: block;
  transition: opacity 0.2s;
}
.prompt-item-thumb img:hover { opacity: 0.85; }
.thumb-placeholder {
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px; color: var(--muted); font-size: 0.7rem;
}
.thumb-placeholder span { font-size: 1.2rem; }
.thumb-placeholder.spinning { animation: progress-pulse 1s ease-in-out infinite; }

.prompt-item-body { min-width: 0; }
.prompt-item-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
}
.prompt-item-header span { font-size: 0.75rem; color: var(--muted); }
.prompt-item-body textarea { min-height: 56px; font-size: 0.8rem; background: var(--bg); }

/* ── Image grid ── */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 16px;
}
.image-card {
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.2s;
  position: relative;
}
.image-card.active { border-color: var(--accent); }
.image-card img { width: 100%; display: block; aspect-ratio: 16/9; object-fit: cover; }
.image-card .img-overlay {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.8));
  padding: 8px;
  font-size: 0.7rem;
  color: #ccc;
  opacity: 0;
  transition: opacity 0.2s;
}
.image-card:hover .img-overlay { opacity: 1; }
.image-placeholder {
  aspect-ratio: 16/9;
  background: var(--surface2);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  font-size: 0.8rem;
  border: 1px dashed var(--border);
}
.spinner { animation: spin 1s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Preview section ── */
.preview-main {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16/9;
  margin-bottom: 16px;
}
.preview-main img {
  width: 100%; height: 100%;
  object-fit: cover;
  position: absolute; top: 0; left: 0;
  transition: opacity 0.5s ease;
}
.preview-main img.fade-out { opacity: 0; }
.preview-main .preview-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 0.9rem;
}

/* ── Audio player ── */
.audio-wrap { margin: 16px 0; }
#waveform { margin-bottom: 8px; border-radius: 8px; overflow: hidden; }
audio { width: 100%; margin-top: 8px; }

/* ── Block timing indicator ── */
.block-indicator {
  display: flex; gap: 4px; flex-wrap: wrap; margin-top: 8px;
}
.block-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--surface2); border: 1px solid var(--border);
  transition: background 0.3s;
}
.block-dot.active { background: var(--accent); }

/* ── Video section ── */
video { width: 100%; border-radius: var(--radius); background: #000; }

/* ── Status/progress bar ── */
.progress-bar {
  height: 4px;
  background: var(--surface2);
  border-radius: 2px;
  overflow: hidden;
  margin: 12px 0;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 0.4s ease;
  border-radius: 2px;
}
.progress-fill.pulsing {
  animation: progress-pulse 1.2s ease-in-out infinite;
}
@keyframes progress-pulse {
  0%, 100% { opacity: 1; filter: brightness(1); }
  50% { opacity: 0.6; filter: brightness(1.4); }
}

/* ── Toast / status ── */
.status-msg {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 8px;
  min-height: 20px;
}
.status-msg.ok { color: var(--success); }
.status-msg.err { color: var(--error); }

/* ── Hidden ── */
.hidden { display: none !important; }

/* ── Download bar ── */
.download-bar {
  display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px;
  padding: 16px;
  background: var(--surface2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.download-bar a {
  color: var(--accent2);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--border);
  transition: border-color 0.2s;
}
.download-bar a:hover { border-color: var(--accent); }
