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

:root {
  --bg:        #0f0f13;
  --surface:   #1a1a22;
  --surface2:  #22222e;
  --border:    #2e2e3e;
  --primary:   #5b6af0;
  --primary-h: #4a58e0;
  --success:   #3ecf8e;
  --danger:    #f05b5b;
  --warning:   #f0b05b;
  --text:      #e8e8f0;
  --text-dim:  #888899;
  --radius:    10px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  display: flex;
  min-height: 100vh;
  font-size: 14px;
}

/* ── SIDEBAR ── */
.sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  position: fixed;
  height: 100vh;
  z-index: 100;
}
.logo {
  padding: 0 20px 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-icon { font-size: 22px; color: var(--primary); }
.logo-text  { font-weight: 700; font-size: 15px; }
.nav-links  { list-style: none; padding: 0 10px; }
.nav-links li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius);
  color: var(--text-dim);
  text-decoration: none;
  transition: all 0.2s;
}
.nav-links li a:hover,
.nav-links li a.active {
  background: var(--surface2);
  color: var(--text);
}
.nav-links li a.active { color: var(--primary); }
.icon { font-size: 16px; }

/* ── MAIN CONTENT ── */
.main-content {
  margin-left: 220px;
  flex: 1;
  padding: 32px;
  max-width: 1200px;
}
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
}
.page-header h1 { font-size: 24px; font-weight: 700; }

/* ── BUTTONS ── */
.btn {
  padding: 9px 18px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-outline   { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface2); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-sm        { padding: 5px 12px; font-size: 12px; }
.btn-full      { width: 100%; justify-content: center; }
.btn:disabled  { opacity: 0.5; cursor: not-allowed; }

/* ── FORMS ── */
.form-group   { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-group label { font-size: 13px; color: var(--text-dim); font-weight: 500; }
.form-control {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border 0.2s;
}
.form-control:focus { border-color: var(--primary); }
.form-control.form-lg { font-size: 16px; padding: 12px 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.hint { color: var(--text-dim); font-size: 11px; font-weight: 400; }

/* ── TOGGLE BUTTON GROUP ── */
.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-toggle {
  padding: 7px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}
.btn-toggle:hover  { border-color: var(--primary); color: var(--text); }
.btn-toggle.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── SLIDER ── */
.slider-wrap { display: flex; align-items: center; gap: 12px; }
.slider {
  flex: 1;
  -webkit-appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
}
.slider-val { color: var(--primary); font-weight: 600; min-width: 48px; }

/* ── STATS ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
}
.stat-number { font-size: 36px; font-weight: 700; color: var(--primary); }
.stat-label  { color: var(--text-dim); margin-top: 4px; }

/* ── TABLE ── */
.section h2 { font-size: 18px; margin-bottom: 16px; }
.video-table { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th { background: var(--surface2); padding: 12px 16px; text-align: left; color: var(--text-dim); font-size: 12px; text-transform: uppercase; }
td { padding: 12px 16px; border-top: 1px solid var(--border); }

/* ── BADGES & STATUS ── */
.badge { padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; text-transform: uppercase; }
.badge-beginner     { background: #1a3a2a; color: var(--success); }
.badge-intermediate { background: #2a2a1a; color: var(--warning); }
.badge-advanced     { background: #2a1a1a; color: var(--danger); }
.status { padding: 3px 10px; border-radius: 6px; font-size: 11px; font-weight: 600; }
.status-done               { background: #1a3a2a; color: var(--success); }
.status-pending            { background: #22222e; color: var(--text-dim); }
.status-generating_script,
.status-generating_audio,
.status-rendering          { background: #1a2a3a; color: #5b9af0; }
.status-failed             { background: #2a1a1a; color: var(--danger); }

/* ── GENERATE PAGE ── */
.generate-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
}
.controls-panel,
.progress-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}

/* ── STEPS ── */
.steps { display: flex; flex-direction: column; gap: 16px; margin: 24px 0; }
.step {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: var(--surface2);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.step-icon  { font-size: 22px; }
.step-info  { flex: 1; }
.step-name  { font-weight: 600; }
.step-desc  { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.step-status { font-size: 12px; font-weight: 600; }
.step-status.active  { color: #5b9af0; }
.step-status.done    { color: var(--success); }
.step-status.waiting { color: var(--text-dim); }

/* ── PROGRESS BAR ── */
.progress-bar-wrap { display: flex; align-items: center; gap: 12px; margin: 16px 0; }
.progress-bar { flex: 1; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 4px; transition: width 0.5s ease; }
.progress-topic { font-size: 18px; font-weight: 700; color: var(--primary); margin-bottom: 8px; }

/* ── RESULT / ERROR ── */
.result-panel { margin-top: 20px; display: flex; flex-direction: column; gap: 12px; }
.result-info  { background: var(--surface2); border-radius: 8px; padding: 16px; }
.result-row   { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); }
.result-row:last-child { border-bottom: none; }
.error-panel  { margin-top: 20px; text-align: center; padding: 24px; background: #2a1a1a; border-radius: 8px; }
.error-icon   { font-size: 32px; color: var(--danger); margin-bottom: 8px; }
.error-msg    { color: var(--danger); margin-bottom: 16px; }
.success-msg  { color: var(--success); font-weight: 600; }

/* ── LIBRARY GRID ── */
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.video-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.video-card-header { display: flex; justify-content: space-between; align-items: center; }
.video-card h3     { font-size: 16px; font-weight: 600; }
.lang-badge { background: var(--surface2); padding: 3px 10px; border-radius: 6px; font-size: 11px; }
.video-meta  { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.video-stats { display: flex; gap: 12px; color: var(--text-dim); font-size: 12px; flex-wrap: wrap; }
.video-date  { color: var(--text-dim); font-size: 12px; }
.video-actions { display: flex; gap: 8px; margin-top: 4px; }

/* ── SETTINGS ── */
.settings-panel  { max-width: 640px; }
.settings-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; margin-bottom: 20px; }
.settings-section h2 { font-size: 16px; margin-bottom: 20px; color: var(--text-dim); text-transform: uppercase; font-size: 12px; letter-spacing: 1px; }

/* ── EMPTY STATE ── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-dim); }
.empty-state h2 { font-size: 20px; margin-bottom: 8px; color: var(--text); }
.empty-state p  { margin-bottom: 20px; }

/* ── MODE TOGGLE (AI / Manual) ── */
.mode-toggle {
  display: flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 24px;
  gap: 4px;
}
.mode-tab {
  flex: 1;
  padding: 9px 0;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.mode-tab.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(91,106,240,0.35);
}
.mode-tab:not(.active):hover { color: var(--text); }

/* ── SCRIPT EDITOR ── */
.script-editor-wrap {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.script-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface2);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.script-toolbar-left  { display: flex; gap: 8px; align-items: center; }
.script-toolbar-right { display: flex; gap: 8px; }
.json-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.2s;
}
.json-dot.valid   { background: var(--success); }
.json-dot.invalid { background: var(--danger); }
.json-label {
  font-size: 12px;
  color: var(--text-dim);
  font-family: monospace;
}
.script-editor {
  width: 100%;
  min-height: 340px;
  background: #0d0d14;
  border: none;
  color: #cdd6f4;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.6;
  padding: 16px;
  resize: vertical;
  outline: none;
  tab-size: 2;
}
.script-editor.valid   { box-shadow: inset 0 0 0 2px rgba(62,207,142,0.2); }
.script-editor.invalid { box-shadow: inset 0 0 0 2px rgba(240,91,91,0.2); }
.json-status {
  font-size: 12px;
  font-weight: 600;
  transition: color 0.2s;
}
.json-status.valid   { color: var(--success); }
.json-status.invalid { color: var(--danger); }
.json-status.empty   { color: var(--text-dim); }

/* ── STEP: SKIPPED ── */
.step.skipped {
  opacity: 0.45;
}
.step-status.skipped { color: var(--text-dim); }

/* ── MODE BADGE in progress header ── */
.mode-badge {
  display: inline-block;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 20px;
  margin-left: 8px;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
/* monitoring badge gets a pulsing blue accent */
.mode-badge:not(:empty)[data-mode="monitoring"],
.mode-badge:empty { display: none; }

/* ── SSE REAL-TIME PROGRESS ── */

/* Timing row above steps */
.timing-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-dim);
  padding: 4px 0 12px;
}
.timing-row strong { color: var(--text); font-variant-numeric: tabular-nums; }

/* Step sub-detail (audio clips / render actions) */
.step-detail {
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 6px;
  font-size: 12px;
}
.step-detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  color: var(--text-dim);
}
.step-detail-row strong { color: var(--text); }
.thread-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(91,106,240,0.15);
  border: 1px solid rgba(91,106,240,0.35);
  color: #7b8af0;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
}

/* Sub-progress bar inside step-detail */
.sub-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 4px;
}
.sub-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* Render action log */
.action-log {
  margin-top: 8px;
  max-height: 88px;
  overflow-y: auto;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 11px;
  line-height: 1.6;
}
.log-line {
  display: flex;
  gap: 6px;
  padding: 1px 0;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
}
.log-line:last-child { color: var(--text); }
.log-act {
  display: inline-block;
  width: 58px;
  flex-shrink: 0;
  font-weight: 700;
  font-size: 10px;
  padding: 0 4px;
  border-radius: 3px;
  text-align: center;
}
.log-act-type    { background: rgba(91,106,240,0.2); color: #7b8af0; }
.log-act-speak   { background: rgba(62,207,142,0.15); color: #3ecf8e; }
.log-act-run     { background: rgba(240,176,91,0.2); color: #f0b05b; }
.log-act-clear   { background: rgba(136,136,153,0.2); color: #888899; }
.log-act-intro   { background: rgba(62,207,142,0.15); color: #3ecf8e; }
.log-act-outro   { background: rgba(62,207,142,0.15); color: #3ecf8e; }
.log-act-new_file    { background: rgba(240,176,91,0.15); color: #f0b05b; }
.log-act-switch_file { background: rgba(240,176,91,0.15); color: #f0b05b; }
.log-speak { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.log-dur   { flex-shrink: 0; color: var(--text-dim); }

/* Step timing breakdown inside result panel */
.result-timing {
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  padding-top: 4px;
}
.result-timing span { color: var(--text); font-weight: 600; }

/* Log messages (script/audio/render phases) */
.pipeline-log {
  margin-top: 12px;
  max-height: 72px;
  overflow-y: auto;
  font-size: 11px;
  font-family: monospace;
  color: var(--text-dim);
  line-height: 1.7;
}
.pipeline-log-line { padding: 0; }
.pipeline-log-line.step-script { color: #7b8af0; }
.pipeline-log-line.step-audio  { color: #3ecf8e; }
.pipeline-log-line.step-render { color: #f0b05b; }

/* Pulsing dot for active SSE step */
@keyframes pulse-dot {
  0%,100% { opacity: 1; }
  50%      { opacity: 0.3; }
}
.step-status.active::before {
  content: '● ';
  animation: pulse-dot 1.2s ease-in-out infinite;
}
