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

html {
  background-color: #09090b;
  color: #e4e4e7;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: #09090b;
  color: #e4e4e7;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, p { margin: 0; }
a { color: #a78bfa; text-decoration: none; }
button { font-family: inherit; }

/* ── Topbar ─────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: rgba(9, 9, 11, 0.85);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  backdrop-filter: blur(20px) saturate(1.5);
  border-bottom: 1px solid #27272a;
}

.topbar-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon { flex-shrink: 0; }

.brand-name {
  font-weight: 700;
  font-size: 1.05rem;
  color: #fafafa;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-weight: 400;
  color: #71717a;
  font-size: 0.82rem;
  margin-left: 2px;
}

/* ── Layout ─────────────────────────────────────────── */
.shell {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 80px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Cards ──────────────────────────────────────────── */
.card {
  background-color: #18181b;
  border: 1px solid #27272a;
  border-radius: 16px;
  padding: 20px;
}

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

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #fafafa;
  letter-spacing: -0.01em;
}

.badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #a78bfa;
  background-color: rgba(167, 139, 250, 0.12);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(167, 139, 250, 0.2);
}

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

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

.field-compact { flex: 1; min-width: 0; }

.field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #a1a1aa;
}

.char-count {
  font-size: 0.72rem;
  color: #52525b;
  font-variant-numeric: tabular-nums;
}

textarea,
select {
  font-family: inherit;
  font-size: 0.92rem;
  color: #e4e4e7;
  background-color: #09090b;
  border: 1px solid #3f3f46;
  border-radius: 12px;
  padding: 12px 14px;
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}

textarea:focus,
select:focus {
  outline: none;
  border-color: #7c3aed;
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.2);
}

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

textarea::placeholder { color: #52525b; }

.select-wrap { position: relative; }

.select-wrap select {
  cursor: pointer;
  padding-right: 36px;
}

.select-wrap::after {
  content: '';
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid #71717a;
  pointer-events: none;
}

.field-hint {
  font-size: 0.75rem;
  color: #52525b;
  line-height: 1.5;
}

kbd {
  display: inline-block;
  font-family: inherit;
  font-size: 0.65rem;
  font-weight: 600;
  color: #a1a1aa;
  background-color: #27272a;
  border: 1px solid #3f3f46;
  border-radius: 4px;
  padding: 1px 5px;
}

/* ── Prompt Chips ───────────────────────────────────── */
.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  color: #a1a1aa;
  background-color: #27272a;
  border: 1px solid #3f3f46;
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}

.chip:hover,
.chip:active {
  color: #c4b5fd;
  background-color: rgba(167, 139, 250, 0.1);
  border-color: rgba(167, 139, 250, 0.3);
}

/* ── Controls Row ───────────────────────────────────── */
.controls-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.aspect-preview-wrap {
  display: flex;
  align-items: flex-end;
  padding-bottom: 4px;
}

.aspect-preview {
  border: 1px solid #3f3f46;
  border-radius: 6px;
  background-color: #27272a;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
  color: #52525b;
}

.aspect-preview.portrait  { width: 30px; height: 50px; }
.aspect-preview.square    { width: 40px; height: 40px; }
.aspect-preview.landscape { width: 50px; height: 30px; }

.play-icon { opacity: 0.5; }

/* ── Buttons ────────────────────────────────────────── */
.btn {
  font-family: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  padding: 12px 24px;
  text-decoration: none;
  transition: all 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}

.btn-primary {
  color: #ffffff;
  background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 50%, #5b21b6 100%);
  box-shadow: 0 2px 12px rgba(124, 58, 237, 0.3), inset 0 1px 0 rgba(255,255,255,0.1);
  width: 100%;
}

.btn-primary:hover {
  box-shadow: 0 4px 20px rgba(124, 58, 237, 0.45), inset 0 1px 0 rgba(255,255,255,0.1);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 1px 6px rgba(124, 58, 237, 0.2);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-ghost {
  color: #a1a1aa;
  background-color: transparent;
  border: 1px solid #3f3f46;
  padding: 8px 16px;
  border-radius: 10px;
}

.btn-ghost:hover {
  color: #e4e4e7;
  background-color: #27272a;
  border-color: #52525b;
}

.btn-sm {
  font-size: 0.75rem;
  padding: 6px 12px;
  border-radius: 8px;
}

.btn-icon { flex-shrink: 0; }

/* ── Status ─────────────────────────────────────────── */
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: capitalize;
  background-color: #27272a;
  color: #71717a;
  border: 1px solid #3f3f46;
}

.status-pill.completed {
  color: #34d399;
  background-color: rgba(52, 211, 153, 0.1);
  border-color: rgba(52, 211, 153, 0.2);
}

.status-pill.failed,
.status-pill.error,
.status-pill.cancelled {
  color: #f87171;
  background-color: rgba(248, 113, 113, 0.1);
  border-color: rgba(248, 113, 113, 0.2);
}

.status-pill.queued,
.status-pill.processing,
.status-pill.running,
.status-pill.in_progress {
  color: #fbbf24;
  background-color: rgba(251, 191, 36, 0.1);
  border-color: rgba(251, 191, 36, 0.2);
}

.status-message {
  color: #71717a;
  font-size: 0.88rem;
  margin-bottom: 14px;
  line-height: 1.5;
}

/* ── Progress ───────────────────────────────────────── */
.progress-track {
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background-color: #27272a;
  overflow: hidden;
  margin-bottom: 16px;
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #7c3aed, #a78bfa);
  transition: width 0.4s ease;
}

.progress-track.active .progress-bar {
  position: relative;
  overflow: hidden;
}

.progress-track.active .progress-bar::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.3) 50%, transparent 100%);
  animation: shimmer 1.5s ease infinite;
}

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

/* ── Job Meta ───────────────────────────────────────── */
.job-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.job-meta dt {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #52525b;
  margin-bottom: 2px;
}

.job-meta dd {
  font-size: 0.82rem;
  color: #a1a1aa;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

/* ── Result ─────────────────────────────────────────── */
.video-stage {
  border-radius: 12px;
  overflow: hidden;
  background-color: #09090b;
}

.video-player {
  width: 100%;
  display: block;
  border-radius: 12px;
  background-color: #000000;
}

.empty-result {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 36px 20px;
  color: #3f3f46;
  text-align: center;
}

.empty-result p {
  font-size: 0.82rem;
  color: #52525b;
}

/* ── History ────────────────────────────────────────── */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background-color: #09090b;
  border: 1px solid #27272a;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.history-item:hover,
.history-item:active {
  background-color: #1c1c1f;
  border-color: #3f3f46;
}

.history-item-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background-color: rgba(167, 139, 250, 0.1);
  color: #a78bfa;
}

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

.history-item-prompt {
  font-size: 0.82rem;
  color: #e4e4e7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.history-item-meta {
  font-size: 0.7rem;
  color: #52525b;
}

.history-item-status {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: capitalize;
  flex-shrink: 0;
  background-color: #27272a;
  color: #71717a;
}

.history-item-status.completed {
  color: #34d399;
  background-color: rgba(52, 211, 153, 0.1);
}

.history-item-status.failed {
  color: #f87171;
  background-color: rgba(248, 113, 113, 0.1);
}

.history-item-status.running,
.history-item-status.processing,
.history-item-status.in_progress,
.history-item-status.queued {
  color: #fbbf24;
  background-color: rgba(251, 191, 36, 0.1);
}

/* ── Toasts ─────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 72px;
  right: 16px;
  left: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 12px 16px;
  background-color: #27272a;
  border: 1px solid #3f3f46;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  font-size: 0.82rem;
  color: #e4e4e7;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn 0.3s ease forwards;
  max-width: 320px;
}

.toast.success {
  border-left: 3px solid #34d399;
}

.toast.error {
  border-left: 3px solid #f87171;
}

.toast.removing {
  animation: toastOut 0.25s ease forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(-12px) scale(0.95); }
}

/* ── Spinner ────────────────────────────────────────── */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.spin {
  animation: spin 0.8s linear infinite;
}

/* ── Utility ────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Mobile ─────────────────────────────────────────── */
@media (max-width: 640px) {
  .shell {
    padding: 16px 12px 60px;
    gap: 12px;
  }

  .card {
    padding: 16px;
    border-radius: 14px;
  }

  .controls-row {
    flex-direction: column;
    gap: 12px;
  }

  .aspect-preview-wrap { display: none; }

  .job-meta {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .job-meta > div {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .job-meta dt { margin-bottom: 0; }

  .prompt-chips { gap: 6px; }

  .chip {
    font-size: 0.72rem;
    padding: 6px 12px;
  }

  .topbar-inner { padding: 12px 12px; }
  .brand-sub { display: none; }

  .toast-container {
    top: 64px;
    right: 12px;
    left: 12px;
    align-items: stretch;
  }

  .toast { max-width: 100%; }
}

@media (min-width: 641px) {
  .shell { padding: 32px 24px 80px; gap: 20px; }
  .card { padding: 24px; }
}
