/* ── Reset & Variables ─────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0a0f;
  --bg-card: #13131d;
  --bg-card-hover: #1a1a28;
  --bg-input: #0e0e16;
  --border: #2a2a3a;
  --border-focus: #7c3aed;
  --text: #e4e4ef;
  --text-dim: #8888a0;
  --text-bright: #fff;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-soft: rgba(124, 58, 237, 0.12);
  --green: #22c55e;
  --green-soft: rgba(34, 197, 94, 0.12);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, 0.12);
  --yellow: #eab308;
  --yellow-soft: rgba(234, 179, 8, 0.12);
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'SF Mono', 'Menlo', 'Monaco', monospace;
  --transition: 0.2s ease;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Shell Layout (sidebar + main) ────────────── */
.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 50;
}

.sidebar-brand {
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.sidebar-brand h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-bright);
  letter-spacing: -0.02em;
}

.sidebar-brand .subtitle {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 8px 0;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  text-decoration: none;
  transition: all var(--transition);
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
  color: var(--text);
  background: rgba(255,255,255,0.03);
}

.sidebar-nav a.active {
  color: var(--text-bright);
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.sidebar-nav a .nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
}

/* ── Main Content Area ───────────────────────── */
.app {
  flex: 1;
  margin-left: 220px;
  max-width: 1200px;
  padding: 24px 32px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

header h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-bright);
  letter-spacing: -0.02em;
}

header .subtitle {
  font-size: 13px;
  color: var(--text-dim);
}

@media (max-width: 900px) {
  .sidebar { display: none; }
  .app { margin-left: 0; padding: 16px; }
}

/* ── Steps Nav ────────────────────────────────── */
.steps-nav {
  display: flex;
  gap: 4px;
  margin-bottom: 32px;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 4px;
  border: 1px solid var(--border);
}

.step-tab {
  flex: 1;
  padding: 10px 16px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.step-tab:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.step-tab.active { color: var(--text-bright); background: var(--accent); }
.step-tab.done { color: var(--green); }
.step-tab .num { font-weight: 700; margin-right: 4px; }

/* ── Step Content ─────────────────────────────── */
.step-content { display: none; }
.step-content.active { display: block; animation: fadeIn 0.3s ease; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Form Elements ────────────────────────────── */
.form-group { margin-bottom: 20px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

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

input:focus, textarea:focus, select:focus { border-color: var(--border-focus); }
textarea { resize: vertical; min-height: 80px; line-height: 1.5; }

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238888a0' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ── Buttons ──────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary { background: transparent; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: rgba(255,255,255,0.04); border-color: var(--text-dim); }

.btn-danger { background: var(--red-soft); color: var(--red); border-color: transparent; }
.btn-danger:hover { background: var(--red); color: #fff; }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }

.btn-group { display: flex; gap: 8px; margin-top: 20px; }

/* ── Character Picker ─────────────────────────── */
.char-picker { display: flex; gap: 12px; flex-wrap: wrap; }

.char-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  min-width: 180px;
}

.char-card:hover { border-color: var(--text-dim); }
.char-card.selected { border-color: var(--accent); background: var(--accent-soft); }

.char-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
}

.char-info .name { font-size: 14px; font-weight: 600; color: var(--text-bright); }
.char-info .role { font-size: 12px; color: var(--text-dim); }

/* ── Scene Cards ──────────────────────────────── */
.scenes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.scene-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border var(--transition);
}

.scene-card:hover { border-color: var(--text-dim); }

.scene-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
}

.scene-header .scene-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-bright);
}

.scene-header .scene-idx {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 99px;
}

.scene-body { padding: 16px; }

.scene-field { margin-bottom: 12px; }
.scene-field:last-child { margin-bottom: 0; }

.scene-field .field-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.scene-field textarea {
  width: 100%;
  font-size: 13px;
  padding: 8px 10px;
  min-height: 60px;
}

.scene-field .field-value {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.scene-actions {
  display: flex;
  gap: 6px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

/* ── Keyframe/Video Preview ───────────────────── */
.preview-area {
  position: relative;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 12px;
  aspect-ratio: 9/16;
  max-height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-area img, .preview-area video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-placeholder {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 20px;
}

/* ── Status Badges ────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 99px;
}

.badge-success { color: var(--green); background: var(--green-soft); }
.badge-pending { color: var(--text-dim); background: rgba(255,255,255,0.05); }
.badge-processing { color: var(--yellow); background: var(--yellow-soft); }
.badge-error { color: var(--red); background: var(--red-soft); }

/* ── Loading Spinner ──────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.spinner-lg { width: 32px; height: 32px; border-width: 3px; }

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

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.loading-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 40px;
  text-align: center;
  box-shadow: var(--shadow);
}

.loading-box .spinner { margin-bottom: 16px; }
.loading-box p { color: var(--text-dim); font-size: 14px; }

/* ── Toast ────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  animation: slideIn 0.3s ease;
  max-width: 400px;
}

.toast-success { background: #166534; color: #dcfce7; }
.toast-error { background: #991b1b; color: #fecaca; }
.toast-info { background: #1e3a5f; color: #dbeafe; }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Existing Scenarios List ──────────────────── */
.scenario-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.scenario-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
}

.scenario-item:hover { border-color: var(--accent); background: var(--bg-card-hover); }
.scenario-item .title { font-weight: 600; font-size: 14px; color: var(--text-bright); }
.scenario-item .meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.scenario-item .progress-dots { display: flex; gap: 4px; align-items: center; }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
}

.dot.filled { background: var(--green); }
.dot.partial { background: var(--yellow); }

/* ── Section Headers ──────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.section-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-bright);
}

.section-header p {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ── Divider ──────────────────────────────────── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}

/* ── Two Column Layout ────────────────────────── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 768px) {
  .two-col { grid-template-columns: 1fr; }
  .scenes-grid { grid-template-columns: 1fr; }
  .steps-nav { overflow-x: auto; }
}

/* ── Prompt Editor Modal ──────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.modal h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-bright);
  margin-bottom: 16px;
}

/* ── Add Scene Button ─────────────────────────── */
.add-scene-card {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  background: var(--bg-card);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-dim);
  font-size: 14px;
  transition: all var(--transition);
}

.add-scene-card:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

/* ── Summary Stats ────────────────────────────── */
.stats-row {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
}

.stat-box {
  padding: 12px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
  flex: 1;
}

.stat-box .stat-num {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-bright);
}

.stat-box .stat-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

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