/* ============================================
   Motion Control Studio — Kling 2.6
   Design System & Styles
   ============================================ */

:root {
  /* Dark palette */
  --bg-primary: #09090b;
  --bg-secondary: #0c0c10;
  --bg-card: rgba(17, 17, 21, 0.8);
  --bg-elevated: rgba(24, 24, 30, 0.9);
  --bg-input: rgba(20, 20, 26, 0.8);
  --bg-input-focus: rgba(26, 26, 34, 0.9);

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.1);
  --border-hover: rgba(255, 255, 255, 0.15);
  --border-focus: rgba(124, 58, 237, 0.5);

  --text-primary: #f4f4f5;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --text-hint: #52525b;

  --accent-purple: #7C3AED;
  --accent-purple-light: #8B5CF6;
  --accent-purple-dark: #6D28D9;
  --accent-pink: #EC4899;
  --accent-pink-light: #F472B6;
  --accent-blue: #3B82F6;
  --accent-green: #10B981;
  --accent-amber: #F59E0B;
  --accent-red: #EF4444;

  --gradient-primary: linear-gradient(135deg, var(--accent-purple) 0%, var(--accent-pink) 100%);
  --gradient-card: linear-gradient(180deg, rgba(255,255,255,0.03) 0%, rgba(255,255,255,0) 100%);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 30px rgba(124, 58, 237, 0.2);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-default: 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

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

/* ── Ambient Orbs ── */
.ambient-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

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

.orb-1 {
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(124,58,237,0.3) 0%, transparent 70%);
  top: -10%; left: -5%;
}

.orb-2 {
  width: 400px; height: 400px;
  background: radial-gradient(circle, rgba(236,72,153,0.2) 0%, transparent 70%);
  top: 40%; right: -10%;
  animation-delay: -7s; animation-duration: 25s;
}

.orb-3 {
  width: 350px; height: 350px;
  background: radial-gradient(circle, rgba(59,130,246,0.15) 0%, transparent 70%);
  bottom: -5%; left: 30%;
  animation-delay: -14s; animation-duration: 22s;
}

@keyframes orbFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  25% { transform: translate(30px, -40px) scale(1.05); }
  50% { transform: translate(-20px, 20px) scale(0.95); }
  75% { transform: translate(40px, 30px) scale(1.03); }
}

/* ── Header ── */
#app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(20px) saturate(1.5);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  background: rgba(9, 9, 11, 0.78);
  border-bottom: 1px solid var(--border-subtle);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.logo-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-subtitle {
  font-size: 10.5px;
  color: var(--text-hint);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Buttons ── */
.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition-fast);
}
.btn-ghost:hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.05);
  border-color: var(--border-hover);
}

.btn-primary-sm {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 16px;
  font-size: 12.5px;
  font-weight: 600;
  color: #fff;
  background: var(--accent-purple-dark);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition-fast);
}
.btn-primary-sm:hover {
  background: var(--accent-purple);
  box-shadow: var(--shadow-glow);
}

.btn-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-sans);
  color: var(--text-muted);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.btn-chip:hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.08);
  border-color: var(--border-hover);
}
.btn-chip-danger:hover {
  color: var(--accent-red);
  border-color: rgba(239,68,68,0.3);
  background: rgba(239,68,68,0.08);
}

.btn-generate {
  width: 100%;
  padding: 16px 24px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-sans);
  color: #fff;
  background: var(--gradient-primary);
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all var(--transition-default);
  box-shadow: var(--shadow-md), var(--shadow-glow);
}
.btn-generate::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.12) 0%, transparent 50%);
  opacity: 0;
  transition: opacity var(--transition-default);
}
.btn-generate:hover::before { opacity: 1; }
.btn-generate:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg), 0 0 40px rgba(124,58,237,0.35);
}
.btn-generate:active { transform: translateY(0); }
.btn-generate:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.btn-generate:disabled:hover::before { opacity: 0; }

.btn-content, .btn-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Main ── */
main { position: relative; z-index: 1; padding-bottom: 48px; }

.main-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* ── Page Header ── */
.page-header {
  text-align: center;
  margin-bottom: 40px;
  padding-top: 16px;
}

.badge-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
}

.badge {
  display: inline-flex;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: var(--radius-full);
}
.badge-purple {
  color: var(--accent-purple-light);
  background: rgba(124,58,237,0.15);
  border: 1px solid rgba(124,58,237,0.25);
}
.badge-pink {
  color: var(--accent-pink-light);
  background: rgba(236,72,153,0.12);
  border: 1px solid rgba(236,72,153,0.2);
}

.page-header h1 {
  font-size: clamp(26px, 4vw, 40px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--text-primary) 30%, var(--accent-purple-light) 70%, var(--accent-pink) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.page-description {
  max-width: 560px;
  margin: 0 auto 20px;
  font-size: 14.5px;
  color: var(--text-secondary);
  line-height: 1.7;
}
.page-description strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* Fixed params chips */
.fixed-params {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.param-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  font-size: 12px;
}

.param-label {
  color: var(--text-hint);
  font-weight: 500;
}

.param-value {
  color: var(--accent-purple-light);
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 11px;
}

/* ── Studio Grid ── */
.studio-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 1024px) {
  .studio-grid { grid-template-columns: 1fr; }
}

.config-panel, .output-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Panel Section ── */
.panel-section {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition-default);
}
.panel-section::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--gradient-card);
  pointer-events: none;
}
.panel-section:hover { border-color: var(--border-default); }

.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  position: relative;
}

.section-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  flex-shrink: 0;
}
.icon-key { background: rgba(124,58,237,0.12); color: var(--accent-purple-light); }
.icon-prompt { background: rgba(59,130,246,0.12); color: var(--accent-blue); }
.icon-media { background: rgba(236,72,153,0.1); color: var(--accent-pink); }

.section-header h2 {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

/* ── Form Fields ── */
.field-group {
  margin-bottom: 16px;
  position: relative;
}
.field-group:last-child { margin-bottom: 0; }

label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

input[type="text"],
input[type="password"],
input[type="url"],
textarea {
  width: 100%;
  padding: 10px 14px;
  font-size: 13px;
  font-family: var(--font-sans);
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  outline: none;
  transition: all var(--transition-fast);
}
input::placeholder, textarea::placeholder { color: var(--text-hint); }
input:focus, textarea:focus {
  background: var(--bg-input-focus);
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.1);
}

textarea {
  resize: vertical;
  min-height: 100px;
  line-height: 1.6;
}

.input-with-icon { position: relative; }
.input-with-icon input { padding-right: 42px; }

.input-icon-btn {
  position: absolute;
  right: 4px; top: 50%;
  transform: translateY(-50%);
  width: 32px; height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}
.input-icon-btn:hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.05);
}

.field-hint {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--text-hint);
  line-height: 1.5;
}
.field-hint a {
  color: var(--accent-purple-light);
  text-decoration: none;
}
.field-hint a:hover { text-decoration: underline; }

.textarea-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}
.char-count {
  font-size: 11px;
  color: var(--text-hint);
  font-family: var(--font-mono);
}

/* ── Media Preview ── */
.media-preview {
  margin-top: 10px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  position: relative;
  background: #000;
}
.media-preview img,
.media-preview video {
  width: 100%;
  max-height: 180px;
  object-fit: contain;
  display: block;
}
.preview-close {
  position: absolute;
  top: 6px; right: 6px;
  width: 24px; height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.7);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 50%;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  transition: all var(--transition-fast);
  line-height: 1;
}
.preview-close:hover { background: rgba(239,68,68,0.8); }

/* ── Output Cards ── */
.output-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: border-color var(--transition-default);
}
.output-card:hover { border-color: var(--border-default); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(255,255,255,0.02);
}
.card-header h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}
.card-header h3 svg { color: var(--accent-purple-light); flex-shrink: 0; }

.card-actions {
  display: flex;
  gap: 6px;
}

/* ── Code Block ── */
.code-block {
  padding: 16px 20px;
  overflow-x: auto;
}
.code-block pre { margin: 0; }
.code-block code {
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── JSON Syntax ── */
.json-key { color: #8B5CF6; }
.json-string { color: #34D399; }
.json-number { color: #F59E0B; }
.json-boolean { color: #60A5FA; }
.json-null { color: #71717A; }
.json-brace { color: #A1A1AA; }

/* ── Status Badge ── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: var(--radius-full);
  letter-spacing: 0.02em;
}
.status-badge .status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
}

.status-pending { background: rgba(245,158,11,0.12); color: var(--accent-amber); }
.status-pending .status-dot { background: var(--accent-amber); animation: pulse 1.5s ease-in-out infinite; }

.status-processing { background: rgba(59,130,246,0.12); color: var(--accent-blue); }
.status-processing .status-dot { background: var(--accent-blue); animation: pulse 1s ease-in-out infinite; }

.status-completed { background: rgba(16,185,129,0.12); color: var(--accent-green); }
.status-completed .status-dot { background: var(--accent-green); }

.status-failed { background: rgba(239,68,68,0.12); color: var(--accent-red); }
.status-failed .status-dot { background: var(--accent-red); }

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

/* ── Result Content ── */
.result-content { padding: 20px; }

.result-video-container {
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000;
  aspect-ratio: 16 / 9;
  margin-bottom: 16px;
}
.result-video-container video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.result-info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.result-info-item {
  padding: 10px 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}
.result-info-item .info-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-hint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 3px;
}
.result-info-item .info-value {
  font-size: 12.5px;
  color: var(--text-primary);
  font-weight: 500;
  word-break: break-all;
}
.result-info-item .info-value a {
  color: var(--accent-purple-light);
  text-decoration: none;
}
.result-info-item .info-value a:hover { text-decoration: underline; }

.polling-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 40px 20px;
  text-align: center;
}
.polling-spinner {
  width: 38px; height: 38px;
  border: 3px solid rgba(124,58,237,0.2);
  border-top-color: var(--accent-purple-light);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
.polling-text { font-size: 13.5px; color: var(--text-secondary); }
.polling-subtext { font-size: 11.5px; color: var(--text-hint); }

.error-message {
  padding: 14px;
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.2);
  border-radius: var(--radius-md);
  color: var(--accent-red);
  font-size: 13px;
  line-height: 1.6;
}

/* ── History ── */
.history-list {
  max-height: 360px;
  overflow-y: auto;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 36px 20px;
  text-align: center;
}
.empty-state p { font-size: 13px; font-weight: 500; color: var(--text-muted); }
.empty-state span { font-size: 11.5px; color: var(--text-hint); }

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.history-item:last-child { border-bottom: none; }
.history-item:hover { background: rgba(255,255,255,0.03); }

.history-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.history-dot.pending { background: var(--accent-amber); }
.history-dot.processing { background: var(--accent-blue); }
.history-dot.completed { background: var(--accent-green); }
.history-dot.failed { background: var(--accent-red); }

.history-info { flex: 1; min-width: 0; }
.history-title {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-meta {
  font-size: 11px;
  color: var(--text-hint);
  display: flex;
  gap: 6px;
}
.history-time {
  font-size: 11px;
  color: var(--text-hint);
  font-family: var(--font-mono);
  white-space: nowrap;
}

/* ── Toasts ── */
.toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  min-width: 260px;
  max-width: 400px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  pointer-events: auto;
  animation: toastIn 0.35s cubic-bezier(0.175,0.885,0.32,1.275);
}
.toast.toast-exit { animation: toastOut 0.25s ease forwards; }

.toast-icon { flex-shrink: 0; }
.toast-body { flex: 1; }
.toast-title { font-size: 12.5px; font-weight: 600; color: var(--text-primary); }
.toast-message { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }

.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-warning { border-left: 3px solid var(--accent-amber); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(16px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
  to { opacity: 0; transform: translateX(40px) scale(0.95); }
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ── Responsive ── */
@media (max-width: 768px) {
  .main-container { padding: 20px 16px; }
  .fixed-params { gap: 6px; }
  .param-chip { padding: 4px 10px; font-size: 11px; }
  .result-info-grid { grid-template-columns: 1fr; }
  .page-header { margin-bottom: 28px; }
}
@media (max-width: 480px) {
  .header-actions .btn-ghost { display: none; }
  .panel-section { padding: 16px; }
  .card-header { padding: 12px 16px; }
  .code-block { padding: 12px 16px; }
}

::selection {
  background: rgba(124,58,237,0.3);
  color: var(--text-primary);
}
