/* ============================================
   KLING MOTION CONTROL — DESIGN SYSTEM
   Premium Dark Theme + Glassmorphism
   ============================================ */

/* --- Google Font --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

/* --- CSS Variables --- */
:root {
  /* Colors */
  --bg-primary: #07070d;
  --bg-secondary: #0e0e1a;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-hover: rgba(255, 255, 255, 0.07);
  --bg-input: rgba(255, 255, 255, 0.06);
  --bg-input-focus: rgba(255, 255, 255, 0.1);

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(124, 58, 237, 0.5);

  --accent-purple: #7c3aed;
  --accent-blue: #3b82f6;
  --accent-cyan: #06b6d4;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --accent-amber: #f59e0b;

  --gradient-primary: linear-gradient(135deg, #7c3aed, #3b82f6);
  --gradient-accent: linear-gradient(135deg, #7c3aed, #06b6d4);
  --gradient-glow: linear-gradient(135deg, rgba(124,58,237,0.3), rgba(59,130,246,0.3));

  --text-primary: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --text-accent: #c4b5fd;

  /* Typography */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-xs: 0.75rem;
  --font-sm: 0.8125rem;
  --font-base: 0.9375rem;
  --font-lg: 1.125rem;
  --font-xl: 1.5rem;
  --font-2xl: 2rem;
  --font-3xl: 2.75rem;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Borders & Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-card: 0 4px 30px rgba(0, 0, 0, 0.3);
  --shadow-glow-purple: 0 0 40px rgba(124, 58, 237, 0.15);
  --shadow-glow-blue: 0 0 40px rgba(59, 130, 246, 0.15);

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-base: 0.25s ease;
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

/* --- Animated Background --- */
.bg-mesh {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.bg-mesh .orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.35;
  animation: orbFloat 20s ease-in-out infinite alternate;
}

.bg-mesh .orb-1 {
  width: 600px;
  height: 600px;
  background: var(--accent-purple);
  top: -200px;
  left: -100px;
  animation-delay: 0s;
}

.bg-mesh .orb-2 {
  width: 500px;
  height: 500px;
  background: var(--accent-blue);
  bottom: -150px;
  right: -100px;
  animation-delay: -7s;
}

.bg-mesh .orb-3 {
  width: 400px;
  height: 400px;
  background: var(--accent-cyan);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation-delay: -14s;
  opacity: 0.15;
}

@keyframes orbFloat {
  0% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(60px, -40px) scale(1.1); }
  66% { transform: translate(-30px, 50px) scale(0.95); }
  100% { transform: translate(20px, -20px) scale(1.05); }
}

/* --- Layout Container --- */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-6);
  padding-bottom: 100px;
}

/* --- Header --- */
.app-header {
  text-align: center;
  margin-bottom: var(--space-12);
  animation: fadeInDown 0.8s ease;
}

.app-header .logo-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: var(--radius-lg);
  background: var(--gradient-primary);
  margin-bottom: var(--space-5);
  box-shadow: var(--shadow-glow-purple);
}

.app-header .logo-icon svg {
  width: 32px;
  height: 32px;
  fill: none;
  stroke: white;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-header h1 {
  font-size: var(--font-3xl);
  font-weight: 800;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.app-header .tagline {
  font-size: var(--font-lg);
  color: var(--text-secondary);
  margin-top: var(--space-2);
  font-weight: 400;
}

/* --- Glass Card --- */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  box-shadow: var(--shadow-card);
  transition: all var(--transition-base);
  animation: fadeInUp 0.6s ease both;
}

.glass-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.12);
}

.glass-card + .glass-card {
  margin-top: var(--space-6);
}

.card-title {
  font-size: var(--font-lg);
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.card-title .icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--gradient-glow);
  flex-shrink: 0;
}

.card-title .icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--accent-purple);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- API Key Section --- */
.apikey-section {
  animation-delay: 0.1s;
}

.apikey-row {
  display: flex;
  gap: var(--space-3);
  align-items: stretch;
}

.apikey-input-wrap {
  flex: 1;
  position: relative;
}

.apikey-input-wrap input {
  width: 100%;
  height: 48px;
  padding: 0 var(--space-12) 0 var(--space-4);
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: var(--font-sm);
  font-family: 'Courier New', monospace;
  letter-spacing: 0.02em;
  transition: all var(--transition-fast);
}

.apikey-input-wrap input:focus {
  outline: none;
  background: var(--bg-input-focus);
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}

.apikey-input-wrap input::placeholder {
  color: var(--text-muted);
  font-family: var(--font-family);
}

.btn-toggle-key {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  transition: color var(--transition-fast);
}

.btn-toggle-key:hover {
  color: var(--text-primary);
}

.btn-toggle-key svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-save-key {
  height: 48px;
  padding: 0 var(--space-6);
  background: var(--gradient-primary);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-size: var(--font-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-save-key:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.apikey-status {
  margin-top: var(--space-3);
  font-size: var(--font-xs);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.apikey-status.saved {
  color: var(--accent-green);
}

.apikey-status .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* --- Media Grid (Image + Video) --- */
.media-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-6);
}

.media-card {
  animation-delay: 0.2s;
}

.media-card:nth-child(2) {
  animation-delay: 0.3s;
}

/* --- Form Inputs --- */
.form-group {
  margin-bottom: var(--space-5);
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
  letter-spacing: 0.01em;
}

.form-label .badge {
  font-size: var(--font-xs);
  font-weight: 500;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: rgba(124, 58, 237, 0.15);
  color: var(--text-accent);
}

.form-label .badge.optional {
  background: rgba(113, 113, 122, 0.2);
  color: var(--text-muted);
}

.form-input {
  width: 100%;
  height: 44px;
  padding: 0 var(--space-4);
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: var(--font-sm);
  font-family: var(--font-family);
  transition: all var(--transition-fast);
}

.form-input:focus {
  outline: none;
  background: var(--bg-input-focus);
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}

.form-input::placeholder {
  color: var(--text-muted);
}

textarea.form-input {
  height: auto;
  min-height: 100px;
  padding: var(--space-4);
  resize: vertical;
  line-height: 1.6;
}

.char-counter {
  text-align: right;
  font-size: var(--font-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

.char-counter.warning {
  color: var(--accent-amber);
}

.char-counter.danger {
  color: var(--accent-red);
}

/* --- Media Preview --- */
.media-preview {
  margin-top: var(--space-4);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-subtle);
  aspect-ratio: 16/10;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.media-preview .placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  color: var(--text-muted);
  font-size: var(--font-sm);
}

.media-preview .placeholder svg {
  width: 40px;
  height: 40px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.5;
}

.media-preview img,
.media-preview video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.media-preview.has-content .placeholder {
  display: none;
}

/* --- Select Inputs --- */
.form-select {
  width: 100%;
  height: 44px;
  padding: 0 var(--space-10) 0 var(--space-4);
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: var(--font-sm);
  font-family: var(--font-family);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  transition: all var(--transition-fast);
}

.form-select:focus {
  outline: none;
  background-color: var(--bg-input-focus);
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}

/* --- Toggle Switch --- */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.toggle-row .toggle-label {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-secondary);
}

.toggle-row .toggle-desc {
  font-size: var(--font-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

.toggle-switch {
  position: relative;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-base);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  transition: all var(--transition-base);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent-purple);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(22px);
}

/* --- Settings Grid --- */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-6);
}

.settings-grid .form-group.full-width {
  grid-column: 1 / -1;
}

/* --- Generate Button --- */
.generate-section {
  margin-top: var(--space-8);
  text-align: center;
  animation: fadeInUp 0.6s ease both;
  animation-delay: 0.6s;
}

.btn-generate {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  width: 100%;
  max-width: 480px;
  height: 56px;
  background: var(--gradient-primary);
  border: none;
  border-radius: var(--radius-md);
  color: white;
  font-size: var(--font-lg);
  font-weight: 700;
  font-family: var(--font-family);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all var(--transition-base);
  box-shadow: 0 4px 25px rgba(124, 58, 237, 0.3);
}

.btn-generate::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.1), transparent);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.btn-generate:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 35px rgba(124, 58, 237, 0.4);
}

.btn-generate:hover:not(:disabled)::before {
  opacity: 1;
}

.btn-generate:active:not(:disabled) {
  transform: translateY(0);
}

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

.btn-generate svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-generate .spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* --- Status Tracker --- */
.status-section {
  margin-top: var(--space-8);
  animation: fadeInUp 0.6s ease both;
}

.status-section.hidden {
  display: none;
}

.stepper {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin: var(--space-8) 0;
  position: relative;
}

.stepper::before {
  content: '';
  position: absolute;
  top: 20px;
  left: 40px;
  right: 40px;
  height: 3px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
}

.stepper-progress {
  position: absolute;
  top: 20px;
  left: 40px;
  height: 3px;
  background: var(--gradient-primary);
  border-radius: 2px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  width: 0%;
}

.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  position: relative;
  z-index: 1;
  flex: 1;
}

.step-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.15);
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-slow);
}

.step-circle svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke var(--transition-base);
}

.step-label {
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: color var(--transition-base);
}

/* Step States */
.step.active .step-circle {
  border-color: var(--accent-purple);
  background: rgba(124, 58, 237, 0.15);
  box-shadow: 0 0 20px rgba(124, 58, 237, 0.3);
  animation: pulse 2s ease-in-out infinite;
}

.step.active .step-circle svg {
  stroke: var(--accent-purple);
}

.step.active .step-label {
  color: var(--text-accent);
}

.step.done .step-circle {
  border-color: var(--accent-green);
  background: rgba(16, 185, 129, 0.15);
}

.step.done .step-circle svg {
  stroke: var(--accent-green);
}

.step.done .step-label {
  color: var(--accent-green);
}

.step.failed .step-circle {
  border-color: var(--accent-red);
  background: rgba(239, 68, 68, 0.15);
}

.step.failed .step-circle svg {
  stroke: var(--accent-red);
}

.step.failed .step-label {
  color: var(--accent-red);
}

.task-id-display {
  text-align: center;
  padding: var(--space-4);
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.task-id-display:hover {
  background: var(--bg-input-focus);
}

.task-id-display .label {
  font-size: var(--font-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.task-id-display .value {
  font-family: 'Courier New', monospace;
  font-size: var(--font-sm);
  color: var(--text-accent);
  font-weight: 600;
}

.task-id-display .copy-icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke var(--transition-fast);
}

.task-id-display:hover .copy-icon {
  stroke: var(--text-primary);
}

/* --- Result Section --- */
.result-section {
  margin-top: var(--space-8);
  animation: fadeInUp 0.6s ease both;
}

.result-section.hidden {
  display: none;
}

/* --- Error Section (separate from result) --- */
.error-section {
  margin-top: var(--space-8);
  animation: fadeInUp 0.6s ease both;
}

.error-section.hidden {
  display: none;
}

.result-video-wrap {
  border-radius: var(--radius-md);
  overflow: hidden;
  background: black;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-glow-purple);
  position: relative;
  min-height: 200px;
}

.result-video-wrap video {
  width: 100%;
  display: block;
  min-height: 200px;
}

/* Video loading overlay */
.video-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  color: var(--text-secondary);
  font-size: var(--font-sm);
  background: rgba(0, 0, 0, 0.6);
  z-index: 2;
}

.video-loading .spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent-purple);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.video-loading.hidden {
  display: none;
}

/* Video error fallback */
.video-error-msg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  color: var(--accent-amber);
  font-size: var(--font-sm);
  background: rgba(0, 0, 0, 0.8);
  padding: var(--space-6);
  text-align: center;
  z-index: 2;
}

/* Result URL display */
.result-url-display {
  margin-top: var(--space-4);
  padding: var(--space-4) var(--space-5);
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.result-url-label {
  font-size: var(--font-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  flex-shrink: 0;
}

.result-url-link {
  font-family: 'Courier New', monospace;
  font-size: var(--font-sm);
  color: var(--accent-cyan);
  text-decoration: none;
  word-break: break-all;
  transition: color var(--transition-fast);
}

.result-url-link:hover {
  color: var(--text-primary);
  text-decoration: underline;
}

.result-actions {
  display: flex;
  gap: var(--space-3);
  margin-top: var(--space-5);
  justify-content: center;
  flex-wrap: wrap;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-sm);
  font-size: var(--font-sm);
  font-weight: 600;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid var(--border-subtle);
  background: var(--bg-input);
  color: var(--text-primary);
  text-decoration: none;
}

.btn-action:hover {
  background: var(--bg-input-focus);
  transform: translateY(-1px);
}

.btn-action.primary {
  background: var(--gradient-primary);
  border: none;
  color: white;
}

.btn-action.primary:hover {
  box-shadow: 0 4px 20px rgba(124, 58, 237, 0.3);
}

.btn-action svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- Error Display --- */
.error-display {
  padding: var(--space-6);
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-md);
  text-align: center;
}

.error-display .error-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-4);
  background: rgba(239, 68, 68, 0.15);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.error-display .error-icon svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: var(--accent-red);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.error-display .error-title {
  font-size: var(--font-lg);
  font-weight: 700;
  color: var(--accent-red);
  margin-bottom: var(--space-2);
}

.error-display .error-msg {
  font-size: var(--font-sm);
  color: var(--text-secondary);
}

/* --- Task History --- */
.history-section {
  margin-top: var(--space-12);
  animation: fadeInUp 0.6s ease both;
  animation-delay: 0.7s;
}

.history-section.hidden {
  display: none;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.history-item {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  cursor: pointer;
}

.history-item:hover {
  background: var(--bg-input-focus);
  border-color: rgba(255,255,255,0.12);
}

.history-item .status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.history-item .status-dot.success { background: var(--accent-green); box-shadow: 0 0 8px rgba(16,185,129,0.4); }
.history-item .status-dot.fail { background: var(--accent-red); box-shadow: 0 0 8px rgba(239,68,68,0.4); }
.history-item .status-dot.pending { background: var(--accent-amber); box-shadow: 0 0 8px rgba(245,158,11,0.4); animation: pulse 2s ease-in-out infinite; }

.history-item .task-info {
  flex: 1;
  min-width: 0;
}

.history-item .task-id-text {
  font-family: 'Courier New', monospace;
  font-size: var(--font-sm);
  color: var(--text-primary);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item .task-time {
  font-size: var(--font-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

.history-item .task-state {
  font-size: var(--font-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.history-item .task-state.success { background: rgba(16,185,129,0.15); color: var(--accent-green); }
.history-item .task-state.fail { background: rgba(239,68,68,0.15); color: var(--accent-red); }
.history-item .task-state.pending { background: rgba(245,158,11,0.15); color: var(--accent-amber); }

.btn-clear-history {
  margin-top: var(--space-4);
  padding: var(--space-2) var(--space-4);
  background: none;
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm);
  color: var(--accent-red);
  font-size: var(--font-xs);
  font-family: var(--font-family);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-clear-history:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* --- Toast Notifications --- */
.toast-container {
  position: fixed;
  top: var(--space-6);
  right: var(--space-6);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  background: rgba(20, 20, 30, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  min-width: 300px;
  max-width: 420px;
  animation: slideInRight 0.3s ease;
  font-size: var(--font-sm);
}

.toast.success { border-left: 3px solid var(--accent-green); }
.toast.error { border-left: 3px solid var(--accent-red); }
.toast.info { border-left: 3px solid var(--accent-blue); }

.toast.fade-out {
  animation: slideOutRight 0.3s ease forwards;
}

.toast svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.toast.success svg { stroke: var(--accent-green); }
.toast.error svg { stroke: var(--accent-red); }
.toast.info svg { stroke: var(--accent-blue); }

/* --- Animations --- */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(60px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes slideOutRight {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(60px); }
}

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

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(124, 58, 237, 0.4); }
  50% { box-shadow: 0 0 0 10px rgba(124, 58, 237, 0); }
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .app-container {
    padding: var(--space-4) var(--space-4);
    padding-bottom: 80px;
  }

  .app-header h1 {
    font-size: var(--font-2xl);
  }

  .media-grid {
    grid-template-columns: 1fr;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .glass-card {
    padding: var(--space-5);
  }

  .stepper {
    gap: var(--space-1);
  }

  .step-label {
    font-size: 0.625rem;
  }

  .step-circle {
    width: 34px;
    height: 34px;
  }

  .stepper::before {
    left: 30px;
    right: 30px;
  }

  .stepper-progress {
    left: 30px;
  }

  .apikey-row {
    flex-direction: column;
  }

  .toast-container {
    left: var(--space-4);
    right: var(--space-4);
  }

  .toast {
    min-width: unset;
    max-width: unset;
  }
}

@media (max-width: 480px) {
  .app-header h1 {
    font-size: 1.75rem;
  }

  .btn-generate {
    height: 50px;
    font-size: var(--font-base);
  }
}
