/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --bg:           #09090b;
  --bg-card:      #18181b;
  --bg-elevated:  #27272a;
  --bg-hover:     #1c1c1f;
  --border:       #3f3f46;
  --border-sub:   #27272a;
  --text-1:       #fafafa;
  --text-2:       #a1a1aa;
  --text-3:       #52525b;
  --primary:      #6366f1;
  --primary-h:    #4f46e5;
  --primary-mut:  rgba(99,102,241,.15);
  --success:      #22c55e;
  --warning:      #f59e0b;
  --danger:       #ef4444;
  --info:         #3b82f6;
  --purple:       #8b5cf6;
  --sidebar-w:    220px;
  --r:            8px;
  --r-lg:         12px;
  --shadow:       0 1px 3px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.3);
  --shadow-lg:    0 10px 25px rgba(0,0,0,.6);
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text-1);
  min-height: 100vh;
  display: flex;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
img, video { max-width: 100%; }

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; width: 100%; }

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 18px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo-icon {
  width: 32px; height: 32px;
  background: var(--primary);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}

.sidebar-logo-text {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.3px;
  color: var(--text-1);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--r);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.nav-item:hover { background: var(--bg-elevated); color: var(--text-1); }
.nav-item.active { background: var(--primary-mut); color: var(--primary); }
.nav-item .nav-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }

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

.api-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-2);
}

.api-status .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-3);
}
.api-status .dot.online  { background: var(--success); }
.api-status .dot.offline { background: var(--danger); }

/* ── Main ───────────────────────────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Page header ────────────────────────────────────────────────────────────── */
.page-header {
  padding: 28px 32px 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.page-header-info {}
.page-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.4px;
  color: var(--text-1);
}
.page-subtitle {
  font-size: 14px;
  color: var(--text-2);
  margin-top: 4px;
}

/* ── Page content ───────────────────────────────────────────────────────────── */
.page-content {
  padding: 24px 32px 40px;
  flex: 1;
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--r);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s, transform .1s;
  white-space: nowrap;
  user-select: none;
  line-height: 1;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:disabled:active { transform: none; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-h); border-color: var(--primary-h); }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-1);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: #333338; }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) { background: rgba(239,68,68,.1); }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-elevated); color: var(--text-1); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title { font-size: 15px; font-weight: 600; }
.card-subtitle { font-size: 13px; color: var(--text-2); margin-top: 2px; }

/* ── Status badges ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .2px;
  white-space: nowrap;
}

.badge-queued     { background: rgba(245,158,11,.15);  color: #f59e0b; }
.badge-generating { background: rgba(99,102,241,.15);  color: #818cf8; }
.badge-rendering  { background: rgba(139,92,246,.15);  color: #8b5cf6; }
.badge-completed  { background: rgba(34,197,94,.15);   color: #22c55e; }
.badge-failed     { background: rgba(239,68,68,.15);   color: #f87171; }
.badge-draft      { background: rgba(251,191,36,.15);  color: #fbbf24; }

.badge-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge-generating .badge-dot,
.badge-queued     .badge-dot { animation: pulse 1.5s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .3; }
}

/* ── Tag chips ──────────────────────────────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-2);
}

/* ── Job grid ───────────────────────────────────────────────────────────────── */
.job-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.job-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 0;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s, transform .1s;
}
.job-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  transform: translateY(-2px);
}

/* ── Job card — media area ──────────────────────────────────────────────────── */
.job-card-media {
  position: relative;
  height: 160px;
  background: var(--bg-elevated);
  overflow: hidden;
  flex-shrink: 0;
}

.job-card-media video,
.job-card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.job-card-media .video-thumb-placeholder {
  height: 100%;
}

.job-card-status {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  pointer-events: none;
}

.job-card-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  opacity: 0;
  transition: opacity .18s;
  z-index: 3;
}
.job-card:hover .job-card-overlay {
  opacity: 1;
}

/* ── Job card — info area ───────────────────────────────────────────────────── */
.job-card-info {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.job-card-prompt {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-1);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.job-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.job-card-footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
}

.job-card-date {
  font-size: 11px;
  color: var(--text-3);
}

/* ── Thumbnail / video placeholder ─────────────────────────────────────────── */
.video-thumb {
  width: 100%;
  aspect-ratio: 9/16;
  background: var(--bg-elevated);
  border-radius: var(--r);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  max-height: 200px;
}

.video-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-thumb-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-3);
  font-size: 13px;
}

.video-thumb-placeholder .thumb-icon {
  font-size: 28px;
  opacity: .5;
}

/* ── Full video player ──────────────────────────────────────────────────────── */
.video-player-wrap {
  display: flex;
  justify-content: center;
  padding: 20px 0;
}

.video-player {
  width: 100%;
  max-width: 360px;
  aspect-ratio: 9/16;
  background: #000;
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.video-player video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form { display: flex; flex-direction: column; gap: 24px; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: .1px;
}

.form-label .req { color: var(--danger); margin-left: 3px; }
.form-label .form-hint { font-size: 10px; font-weight: 400; margin-left: 6px; color: var(--text-3); }

.form-input,
.form-select,
.form-textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text-1);
  padding: 10px 12px;
  font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-3); }
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-mut);
}
.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath fill='%2371717a' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
  cursor: pointer;
}
.form-select option { background: var(--bg-card); color: var(--text-1); }

.form-textarea { resize: vertical; min-height: 120px; line-height: 1.6; }
.form-textarea.large { min-height: 160px; }

.form-error {
  font-size: 12px;
  color: var(--danger);
  margin-top: 2px;
}

.form-hint {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
}

.form-group.field-overridden label,
.form-group.field-overridden select,
.form-group.field-overridden .form-hint {
  opacity: 0.35;
}
.form-group.field-overridden select { pointer-events: none; }

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* ── Empty state ────────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 64px 32px;
  text-align: center;
  color: var(--text-3);
}

.empty-state-icon { font-size: 48px; opacity: .4; }
.empty-state-title { font-size: 16px; font-weight: 600; color: var(--text-2); }
.empty-state-desc { font-size: 14px; max-width: 320px; }

/* ── Loading spinner ────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
.spinner.lg { width: 36px; height: 36px; border-width: 3px; }

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

/* ── Generation progress card ───────────────────────────────────────────────── */
.progress-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.progress-title { font-size: 16px; font-weight: 600; }
.progress-subtitle { font-size: 14px; color: var(--text-2); }

.progress-bar-wrap {
  width: 100%;
  background: var(--bg-elevated);
  border-radius: 99px;
  height: 6px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--purple));
  border-radius: 99px;
  transition: width .4s ease;
}
.progress-bar.indeterminate {
  width: 40%;
  animation: indeterminate 1.8s ease-in-out infinite;
}

@keyframes indeterminate {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(300%); }
}

/* ── Job detail layout ──────────────────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  align-items: start;
}

.detail-info { display: flex; flex-direction: column; gap: 20px; }

.info-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.info-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-3);
}
.info-value {
  font-size: 14px;
  color: var(--text-1);
  line-height: 1.5;
  overflow-wrap: break-word;
  min-width: 0;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* ── Back link ──────────────────────────────────────────────────────────────── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 20px;
  cursor: pointer;
  transition: color .15s;
}
.back-link:hover { color: var(--text-1); }

/* ── Section ────────────────────────────────────────────────────────────────── */
.section { margin-bottom: 28px; }
.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-3);
  margin-bottom: 12px;
}

/* ── Narration block ────────────────────────────────────────────────────────── */
.narration-block {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 16px;
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.7;
  white-space: pre-wrap;
}

/* ── Error block ────────────────────────────────────────────────────────────── */
.error-block {
  background: rgba(239,68,68,.08);
  border: 1px solid rgba(239,68,68,.25);
  border-radius: var(--r);
  padding: 14px 16px;
  font-size: 13px;
  color: #fca5a5;
  line-height: 1.5;
  font-family: 'Courier New', monospace;
}

/* ── Stats row on dashboard ─────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-label { font-size: 12px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.stat-sub   { font-size: 12px; color: var(--text-3); }

/* ── Section header with action ─────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-heading {
  font-size: 16px;
  font-weight: 700;
}

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

/* ── Toast ──────────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text-1);
  box-shadow: var(--shadow-lg);
  min-width: 240px;
  max-width: 360px;
  animation: slide-in .25s ease;
}
.toast.success { border-color: rgba(34,197,94,.4); }
.toast.error   { border-color: rgba(239,68,68,.4); color: #fca5a5; }

@keyframes slide-in {
  from { transform: translateX(30px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Search / filter bar ────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-search { max-width: 280px; }
.filter-select  { max-width: 160px; }

.results-label {
  font-size: 13px;
  color: var(--text-3);
  margin-bottom: 14px;
  min-height: 18px;
}

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

.scene-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.scene-img-wrap {
  position: relative;
  aspect-ratio: 9/16;
  background: var(--bg-elevated);
  border-radius: var(--r);
  overflow: hidden;
  border: 1px solid var(--border);
}

.scene-img-clickable {
  cursor: zoom-in;
}

.scene-zoom-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: #fff;
  background: rgba(0,0,0,.45);
  opacity: 0;
  transition: opacity .15s;
  pointer-events: none;
}

.scene-img-clickable:hover .scene-zoom-icon {
  opacity: 1;
}

.scene-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity .2s;
}

.scene-img-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.scene-num-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0,0,0,.7);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 99px;
  pointer-events: none;
}

.scene-prompt {
  font-size: 11px;
  color: var(--text-3);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.scene-edit-btn {
  width: 100%;
}

.scene-add-card {
  display: flex;
}

.scene-add-btn {
  flex: 1;
  aspect-ratio: 9/16;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 2px dashed var(--border);
  border-radius: var(--r);
  cursor: pointer;
  transition: border-color .15s, background .15s;
  color: var(--text-3);
}

.scene-add-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: rgba(99,102,241,.06);
  color: var(--accent);
}

.scene-add-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.scene-add-icon {
  font-size: 28px;
  line-height: 1;
  font-weight: 300;
}

.scene-add-label {
  font-size: 12px;
  font-weight: 500;
}

.scene-remove-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 10;
  background: rgba(0,0,0,.55);
  border: none;
  color: #fff;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .15s, background .15s;
}

.scene-img-wrap:hover .scene-remove-btn {
  opacity: 1;
}

.scene-remove-btn:hover {
  background: rgba(239,68,68,.9);
}

.inline-confirm {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.inline-confirm-msg {
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
}

.inline-confirm-btns {
  display: flex;
  gap: 6px;
}

.delete-popup {
  position: fixed;
  z-index: 300;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.5);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 160px;
}

.delete-popup-msg {
  margin: 0;
  font-size: 13px;
  color: var(--text-1);
  font-weight: 500;
}

.delete-popup-btns {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.scene-confirm-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(0,0,0,.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-radius: inherit;
}

.scene-confirm-msg {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  text-align: center;
  padding: 0 12px;
}

.scene-confirm-btns {
  display: flex;
  gap: 8px;
}

.scene-confirm-yes {
  background: var(--danger);
  color: #fff;
  border: none;
}

/* ── Image preview lightbox ──────────────────────────────────────────────────── */

.ip-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.85);
  z-index: 1100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.ip-modal {
  display: flex;
  flex-direction: column;
  max-height: 95vh;
  max-width: 480px;
  width: 100%;
}

.ip-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 10px;
}

.ip-title {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,.75);
  letter-spacing: .04em;
}

.ip-close {
  background: rgba(255,255,255,.1);
  border: none;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}

.ip-close:hover { background: rgba(255,255,255,.2); }

.ip-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.ip-img {
  max-width: 100%;
  max-height: calc(95vh - 60px);
  object-fit: contain;
  border-radius: var(--r);
  display: block;
}

/* ── Scene editor modal ──────────────────────────────────────────────────────── */
.sm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.sm-modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slide-in .2s ease;
}

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

.sm-title {
  font-size: 15px;
  font-weight: 600;
}

.sm-close {
  background: none;
  border: none;
  color: var(--text-2);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--r);
  transition: background .15s, color .15s;
}
.sm-close:hover { background: var(--bg-elevated); color: var(--text-1); }

.sm-preview {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  padding: 16px 20px 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: relative;
}

.sm-preview-has-image {
  cursor: zoom-in;
}

.sm-preview-zoom-icon {
  position: absolute;
  inset: 16px 20px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: #fff;
  background: rgba(0,0,0,.4);
  opacity: 0;
  transition: opacity .15s;
  pointer-events: none;
}

.sm-preview-has-image:hover .sm-preview-zoom-icon {
  opacity: 1;
}

.sm-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sm-preview-placeholder {
  width: 100%;
  aspect-ratio: 9/16;
  max-height: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r);
}

.sm-preview img {
  max-height: 260px;
  max-width: 100%;
  border-radius: var(--r);
  object-fit: contain;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
}

.sm-narration-wrap {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 10px 14px;
}

.sm-narration-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-3);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sm-narration-saved {
  font-size: 10px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

.sm-narration-saving { color: var(--text-3); }
.sm-narration-ok     { color: #86efac; }
.sm-narration-err    { color: #fca5a5; }

.sm-narration {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.5;
  background: transparent;
  border: none;
  resize: vertical;
  padding: 0;
  min-height: 56px;
}

.sm-narration:focus {
  outline: none;
  box-shadow: none;
  border-color: transparent;
}

.sm-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sm-instruction-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sm-instruction-hint {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 400;
}

.sm-instruction-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.sm-instruction-input {
  flex: 1;
  min-width: 0;
}

.sm-ref-label {
  cursor: pointer;
  flex-shrink: 0;
  padding: 6px 10px;
  font-size: 15px;
  line-height: 1;
}

.sm-upload-label {
  cursor: pointer;
}

.sm-upload-busy {
  pointer-events: none;
  opacity: 0.55;
}

.sm-ref-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding: 6px 8px;
  background: var(--bg-elevated);
  border-radius: var(--r);
  border: 1px solid var(--border);
}

.sm-ref-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.sm-ref-name {
  font-size: 12px;
  color: var(--text-2);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sm-ref-remove {
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  flex-shrink: 0;
}

.sm-ref-remove:hover {
  background: rgba(239,68,68,.15);
  color: #fca5a5;
}

.sm-status {
  font-size: 13px;
  min-height: 18px;
  border-radius: var(--r);
  padding: 0;
  transition: all .2s;
}
.sm-status:not(:empty) { padding-left: 12px; }
.sm-status-info    { background: rgba(59,130,246,.1); color: #93c5fd; }
.sm-status-success { background: rgba(34,197,94,.1);  color: #86efac; }
.sm-status-error   { background: rgba(239,68,68,.1);  color: #fca5a5; }

.sm-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Assets section label ───────────────────────────────────────────────────── */
.assets-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  margin-bottom: -4px;
}

/* ── Asset upload widget ────────────────────────────────────────────────────── */
.asset-upload-widget {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.asset-thumb-wrap {
  width: 64px;
  height: 64px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.asset-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.asset-no-thumb {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-3);
  background: var(--bg-elevated);
  text-align: center;
  padding: 4px;
}

.asset-upload-label {
  cursor: pointer;
}

.asset-status {
  font-size: 12px;
}

.asset-status-saving { color: var(--text-3); }
.asset-status-ok     { color: #86efac; }
.asset-status-err    { color: #fca5a5; }

.asset-disabled {
  opacity: 0.4;
  pointer-events: none;
}

.asset-audio-widget {
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--bg-elevated);
}

.asset-audio-name {
  flex: 1;
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.asset-audio-badge {
  font-size: 12px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 4px;
  word-break: break-all;
}

.asset-thumb-wrap .asset-audio-badge {
  width: 100%;
  height: 100%;
  justify-content: center;
  text-align: center;
  padding: 4px;
  background: var(--bg-elevated);
  border-radius: 6px;
}

.asset-view-thumb {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  display: block;
}

/* ── Tooltip ────────────────────────────────────────────────────────────────── */
[data-tooltip] { position: relative; }

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #111113;
  color: var(--text-1);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
  z-index: 200;
}

[data-tooltip]:hover::after { opacity: 1; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
  .detail-grid > :last-child { order: -1; }
}

@media (max-width: 700px) {
  .sidebar {
    width: 60px;
  }
  .sidebar-logo-text,
  .nav-item span:not(.nav-icon),
  .sidebar-footer { display: none; }
  .sidebar-logo { justify-content: center; padding: 16px 0; }
  .nav-item { justify-content: center; padding: 10px; }
  .main { margin-left: 60px; }
  .page-header, .page-content { padding-left: 16px; padding-right: 16px; }
  .stats-row { grid-template-columns: 1fr 1fr; }
}
