:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #eef2ff;
  --dark: #0f172a;
  --gray: #64748b;
  --gray-light: #f1f5f9;
  --border: #e2e8f0;
  --bg: #fafbfc;
  --white: #ffffff;
  --green: #10b981;
  --red: #ef4444;
  --orange: #f59e0b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
  --font: 'Inter', -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--dark); font-size: 15px; line-height: 1.6; min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select { font-family: inherit; font-size: inherit; }

/* Layout */
.container { max-width: 720px; margin: 0 auto; padding: 20px; }

/* Header */
.header {
  background: var(--white); border-bottom: 1px solid var(--border);
  padding: 16px 20px; display: flex; align-items: center; justify-content: space-between;
}
.header-brand { font-weight: 700; font-size: 1.1rem; color: var(--dark); display: flex; align-items: center; gap: 8px; }
.header-brand svg { color: var(--primary); }
.header-user { display: flex; align-items: center; gap: 12px; font-size: 0.9rem; color: var(--gray); }
.header-credits { background: var(--primary-light); color: var(--primary); padding: 4px 12px; border-radius: 20px; font-weight: 600; font-size: 0.85rem; }
.btn-logout { background: none; border: 1px solid var(--border); padding: 6px 14px; border-radius: 8px; font-size: 0.85rem; color: var(--gray); }
.btn-logout:hover { border-color: var(--red); color: var(--red); }

/* Login */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 40px; width: 100%; max-width: 400px; }
.login-card h1 { font-size: 1.4rem; margin-bottom: 4px; }
.login-card p { color: var(--gray); font-size: 0.9rem; margin-bottom: 24px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 6px; }
.form-group input { width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.95rem; outline: none; transition: border 0.2s; }
.form-group input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.1); }
.btn-primary { width: 100%; padding: 12px; background: var(--primary); color: #fff; border: none; border-radius: 8px; font-size: 1rem; font-weight: 600; transition: background 0.2s; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.error-msg { color: var(--red); font-size: 0.85rem; margin-top: 12px; text-align: center; }

/* Generate Form */
.card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; margin-bottom: 20px; }
.card h2 { font-size: 1.1rem; margin-bottom: 16px; }
.form-group textarea { width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.95rem; outline: none; resize: vertical; min-height: 100px; transition: border 0.2s; }
.form-group textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.1); }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.form-group select { width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.95rem; outline: none; background: var(--white); }
.cost-preview { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--primary-light); border-radius: 8px; margin-bottom: 16px; font-size: 0.9rem; }
.cost-preview strong { color: var(--primary); font-size: 1.1rem; }

/* Videos Grid */
.videos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.video-card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; transition: transform 0.2s, box-shadow 0.2s; }
.video-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.video-thumb { position: relative; aspect-ratio: 16/9; background: #1a1a2e; overflow: hidden; cursor: pointer; }
.video-thumb img { width: 100%; height: 100%; object-fit: cover; }
.video-thumb video { width: 100%; height: 100%; object-fit: cover; }
.video-play-btn { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.3); transition: opacity 0.2s; }
.video-play-btn span { width: 44px; height: 44px; background: rgba(255,255,255,0.9); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; padding-left: 3px; }
.video-meta { padding: 12px; }
.video-prompt { font-size: 0.82rem; color: var(--gray); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.video-status { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 0.75rem; font-weight: 600; margin-top: 6px; }
.status-completed { background: #d1fae5; color: #065f46; }
.status-queued, .status-in_progress { background: #fef3c7; color: #92400e; }
.status-failed { background: #fee2e2; color: #991b1b; }

/* Progress bar */
.progress-bar { height: 4px; background: var(--gray-light); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 2px; transition: width 0.3s; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: var(--white); border-radius: var(--radius); max-width: 800px; width: 100%; max-height: 90vh; overflow: auto; }
.modal video { width: 100%; display: block; border-radius: var(--radius) var(--radius) 0 0; }
.modal-body { padding: 20px; }
.modal-body p { color: var(--gray); font-size: 0.9rem; }
.modal-close { position: absolute; top: 12px; right: 12px; background: rgba(0,0,0,0.7); color: #fff; border: none; width: 36px; height: 36px; border-radius: 50%; font-size: 1.2rem; z-index: 10; cursor: pointer; }

/* Empty state */
.empty { text-align: center; padding: 60px 20px; color: var(--gray); }
.empty-icon { font-size: 3rem; margin-bottom: 12px; opacity: 0.4; }
.empty p { font-size: 0.95rem; }

/* Toast */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--dark); color: #fff; padding: 10px 20px; border-radius: 8px; font-size: 0.9rem; z-index: 200; animation: fadeInUp 0.3s; }
@keyframes fadeInUp { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Responsive */
@media (max-width: 600px) {
  .form-row { flex-direction: column; }
  .videos-grid { grid-template-columns: 1fr; }
  .header { padding: 12px 16px; }
}

/* Spinner */
.spinner { width: 20px; height: 20px; border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff; border-radius: 50%; animation: spin 0.6s linear infinite; display: inline-block; vertical-align: middle; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Download button */
.btn-download { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; background: var(--primary); color: #fff; border: none; border-radius: 8px; font-size: 0.85rem; font-weight: 500; margin-top: 12px; }
.btn-download:hover { background: var(--primary-hover); }
