:root {
  --brand: #5d4df4;
  --brand-hover: #7c6ff7;
  --brand-dim: rgba(93, 77, 244, .10);
  --green: #12b76a;
  --green-bg: #d1fadf;
  --green-border: #a7f3d0;
  --red: #f04438;
  --red-bg: #fee4e2;
  --blue-bg: #dbeafe;
  --amber-bg: #fef0c7;
  --gray-bg: #f3f4f6;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --surface: #ffffff;
  --bg: #f4f6fb;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(
      ellipse 90% 45% at 50% -5%,
      rgba(93, 77, 244, .09) 0%,
      transparent 65%
    ),
    var(--bg);
}

button, input { font: inherit; }

/* ── Layout ───────────────────────────────────────────────────────────── */

.shell {
  width: min(820px, calc(100% - 32px));
  margin: 48px auto 80px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Card ─────────────────────────────────────────────────────────────── */

@keyframes slide-in {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 32px;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, .04),
    0 8px 32px rgba(93, 77, 244, .07);
  animation: slide-in .22s ease both;
}

/* ── Hero ─────────────────────────────────────────────────────────────── */

.hero .eyebrow {
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: .13em;
  font-weight: 700;
  font-size: .72rem;
  margin-bottom: 10px;
}

.hero h1 {
  font-size: clamp(2rem, 6vw, 3.6rem);
  line-height: .95;
  margin: 0 0 12px;
  letter-spacing: -.04em;
  background: linear-gradient(140deg, var(--text) 30%, #6d5dfc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  color: var(--text); /* fallback */
}

.lead {
  color: var(--text-muted);
  font-size: 1rem;
  margin: 0 0 28px;
}

/* ── Form ─────────────────────────────────────────────────────────────── */

label {
  display: block;
  font-weight: 600;
  font-size: .88rem;
  margin-bottom: 8px;
  color: var(--text);
}

.url-row { display: flex; gap: 8px; }

input[type="url"],
input[type="password"] {
  flex: 1;
  min-width: 0;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: #fafafa;
  outline: none;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s, background .15s;
}

input[type="url"]:focus,
input[type="password"]:focus {
  border-color: var(--brand);
  background: #fff;
  box-shadow: 0 0 0 3px var(--brand-dim);
}

/* ── Buttons ──────────────────────────────────────────────────────────── */

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: none;
  border-radius: 12px;
  padding: 12px 20px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  font-size: .88rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, box-shadow .15s, transform .1s;
}

button:hover {
  background: var(--brand-hover);
  box-shadow: 0 4px 14px rgba(93, 77, 244, .30);
}

button:active { transform: scale(.97); }

button:disabled {
  opacity: .5;
  cursor: default;
  box-shadow: none;
  transform: none;
}

button.secondary {
  background: #1e1b4b;
}

button.secondary:hover {
  background: #312e81;
  box-shadow: 0 4px 14px rgba(30, 27, 75, .28);
}

button.ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
  font-weight: 500;
}

button.ghost:hover {
  background: var(--gray-bg);
  color: var(--text);
  box-shadow: none;
}

/* ── Spinner (inside button) ──────────────────────────────────────────── */

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

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, .35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .65s linear infinite;
  flex-shrink: 0;
}

/* ── Message ──────────────────────────────────────────────────────────── */

.message {
  min-height: 1.4em;
  color: var(--text-muted);
  font-size: .88rem;
  margin-top: 12px;
}

/* ── Preview card ─────────────────────────────────────────────────────── */

.preview {
  display: grid;
  grid-template-columns: minmax(200px, 38%) 1fr;
  gap: 24px;
  align-items: center;
}

.preview img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 12px;
  background: var(--gray-bg);
}

.preview .eyebrow {
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: .11em;
  font-weight: 700;
  font-size: .72rem;
  margin-bottom: 4px;
}

.preview h2 {
  margin: 0 0 4px;
  font-size: 1.15rem;
  line-height: 1.3;
}

.preview .duration {
  color: var(--text-muted);
  font-size: .86rem;
  margin: 0 0 20px;
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ── Job card ─────────────────────────────────────────────────────────── */

.job-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.job-head .eyebrow {
  text-transform: uppercase;
  letter-spacing: .11em;
  font-weight: 700;
  font-size: .72rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.job-head h2 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--text);
}

/* ── Status badge ─────────────────────────────────────────────────────── */

.badge {
  padding: 4px 11px;
  border-radius: 999px;
  font-size: .73rem;
  font-weight: 700;
  letter-spacing: .03em;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge-queued      { background: var(--gray-bg);  color: #6b7280; }
.badge-downloading { background: var(--blue-bg);  color: #1d4ed8; }
.badge-processing  { background: var(--amber-bg); color: #b45309; }
.badge-completed   { background: var(--green-bg); color: #065f46; }
.badge-failed      { background: var(--red-bg);   color: #b91c1c; }
.badge-expired     { background: var(--gray-bg);  color: #9ca3af; }

/* ── Progress ─────────────────────────────────────────────────────────── */

.progress-track {
  width: 100%;
  height: 8px;
  background: var(--gray-bg);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--brand) 0%, #907cff 100%);
  border-radius: 999px;
  transition: width .4s ease;
  position: relative;
  overflow: hidden;
}

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

.progress-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, .45) 50%,
    transparent 100%
  );
  animation: shimmer 1.6s ease-in-out infinite;
}

.progress-bar.done::after { animation: none; opacity: 0; }

.metrics {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-muted);
  font-size: .82rem;
  margin-top: 8px;
}

/* ── Download link ────────────────────────────────────────────────────── */

.file-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 20px;
  padding: 14px 18px;
  background: var(--green-bg);
  border: 1.5px solid var(--green-border);
  border-radius: 12px;
  color: #065f46;
  font-weight: 600;
  font-size: .9rem;
  text-decoration: none;
  transition: background .15s;
}

.file-link:hover { background: #bbf7d0; }

.file-link .file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.file-link .file-size {
  color: #047857;
  font-weight: 400;
  font-size: .82rem;
  flex-shrink: 0;
}

/* ── Error & Reset ────────────────────────────────────────────────────── */

.job-error {
  color: var(--red);
  font-size: .88rem;
  margin-top: 14px;
  min-height: 1.2em;
}

.reset-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

/* ── Footer ───────────────────────────────────────────────────────────── */

footer {
  text-align: center;
  color: var(--text-muted);
  font-size: .8rem;
  padding: 4px;
  line-height: 1.6;
}

/* ── Login card ───────────────────────────────────────────────────────── */

.login-card {
  text-align: center;
  padding: 40px 36px 36px;
}

.login-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 20px;
  background: var(--brand-dim);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brand);
}

.login-icon svg { width: 26px; height: 26px; }

.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -.03em;
  margin: 0 0 6px;
  background: linear-gradient(140deg, var(--text) 30%, #6d5dfc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  color: var(--text);
}

.login-sub {
  color: var(--text-muted);
  font-size: .9rem;
  margin: 0 0 28px;
}

.login-form {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.pw-wrap { position: relative; display: flex; }

.pw-wrap input { padding-right: 44px; }

.pw-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 8px;
  border-radius: 8px;
  color: var(--text-muted);
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.pw-toggle:hover {
  background: var(--gray-bg);
  color: var(--brand);
  box-shadow: none;
  transform: translateY(-50%);
}

.pw-toggle:active { transform: translateY(-50%) scale(.92); }

.pw-toggle svg { width: 17px; height: 17px; pointer-events: none; }

.remember-row {
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  user-select: none;
}

.remember-check {
  width: 16px;
  height: 16px;
  accent-color: var(--brand);
  cursor: pointer;
  flex-shrink: 0;
  margin: 0;
}

.remember-label { font-size: .88rem; color: var(--text-muted); }

.btn-full { width: 100%; padding: 13px 20px; font-size: .95rem; }

.login-version {
  text-align: center;
  color: var(--text-muted);
  font-size: .78rem;
  margin-top: 12px;
}

/* ── Top nav (logout bar) ─────────────────────────────────────────────── */

.topnav {
  display: flex;
  justify-content: flex-end;
  padding: 0 4px;
}

.logout-link {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 8px;
  transition: background .15s, color .15s;
}

.logout-link:hover {
  background: var(--gray-bg);
  color: var(--text);
}

/* ── Login page (narrow shell) ────────────────────────────────────────── */

.shell-narrow {
  width: min(440px, calc(100% - 32px));
  margin: 80px auto;
}

.error-message { color: var(--red) !important; }

/* ── Utilities ────────────────────────────────────────────────────────── */

.hidden { display: none !important; }

/* ── Responsive ───────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .shell { margin: 20px auto 60px; }
  .card  { padding: 20px; border-radius: 16px; }
  .url-row { flex-direction: column; }
  .preview { grid-template-columns: 1fr; }
  .actions button { flex: 1; }
  .hero h1 { font-size: 2.2rem; }
}
