/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --text-muted: #666;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --warning: #d97706;
  --nav-bg: #1e293b;
  --nav-text: #e2e8f0;
  --radius: 8px;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
input, textarea, button, select { font: inherit; }

/* ── Navbar ─────────────────────────────────────────────────────────────────── */
.navbar {
  background: var(--nav-bg);
  color: var(--nav-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.brand { color: var(--nav-text); font-size: 1.25rem; font-weight: 700; letter-spacing: -0.5px; }
.nav-links { display: flex; align-items: center; gap: 1rem; }
.nav-links a { color: var(--nav-text); }
.nav-email { font-size: 0.875rem; color: #94a3b8; }
.nav-email:hover { color: #e2e8f0; text-decoration: none; }

/* ── Container ──────────────────────────────────────────────────────────────── */
.container { max-width: 1100px; margin: 0 auto; padding: 2rem 1rem; }

/* ── Alerts ─────────────────────────────────────────────────────────────────── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  border-left: 4px solid transparent;
}
.alert-success  { background: #f0fdf4; border-color: var(--success); color: #166534; }
.alert-error    { background: #fef2f2; border-color: var(--danger);  color: #991b1b; }
.alert-info     { background: #eff6ff; border-color: var(--primary); color: #1e40af; }
.alert-warning  { background: #fffbeb; border-color: var(--warning); color: #92400e; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-primary    { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-hover); text-decoration: none; color: #fff; }
.btn-danger     { background: var(--danger); color: #fff; }
.btn-danger:hover   { background: var(--danger-hover); }
.btn-ghost      { background: transparent; color: var(--nav-text); border: 1px solid #475569; }
.btn-ghost:hover    { background: #334155; }
.btn-secondary  { background: #f1f5f9; color: #475569; border: 1px solid var(--border); }
.btn-secondary:hover { background: #e2e8f0; text-decoration: none; color: #334155; }
.btn-block    { width: 100%; margin-top: 0.5rem; }
.btn-sm       { padding: 0.35rem 0.8rem; font-size: 0.8rem; }

/* ── Auth card ──────────────────────────────────────────────────────────────── */
.auth-card {
  max-width: 420px;
  margin: 4rem auto;
  background: var(--surface);
  padding: 2rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.auth-card h1 { margin-bottom: 0.25rem; }
.auth-card .subtitle { color: var(--text-muted); margin-bottom: 1.5rem; }
.auth-card label { display: block; font-size: 0.875rem; font-weight: 500; margin: 1rem 0 0.25rem; }
.auth-card input[type="email"],
.auth-card input[type="password"] {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s;
}
.auth-card input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.auth-link  { margin-top: 1.25rem; text-align: center; font-size: 0.875rem; }
.tos-note   { font-size: 0.75rem; color: var(--text-muted); margin-top: 1rem; }
.hint       { font-weight: 400; color: var(--text-muted); }

/* ── Dashboard header ────────────────────────────────────────────────────────── */
.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.dashboard-header h1 { font-size: 1.75rem; margin: 0; }
.dashboard-header-actions { display: flex; align-items: center; gap: 0.5rem; }

/* ── View toggle ─────────────────────────────────────────────────────────────── */
.view-toggle { display: flex; gap: 4px; }
.view-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.view-btn:hover { background: #e2e8f0; color: var(--text); }
.view-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── Profile page ────────────────────────────────────────────────────────────── */
.profile-header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.profile-header h1 { margin: 0; font-size: 1.75rem; }

.profile-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}
.profile-danger-zone { border-color: #fca5a5; }

.profile-section-title { font-size: 1.1rem; margin: 0 0 0.5rem; }
.profile-subsection { font-size: 0.9rem; margin: 1.25rem 0 0.5rem; color: var(--text-muted); font-weight: 600; }
.profile-desc { font-size: 0.875rem; color: var(--text-muted); margin-bottom: 0.75rem; }

.token-row { display: flex; gap: 0.5rem; align-items: center; }
.token-input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: monospace;
  font-size: 0.8rem;
  background: #f8fafc;
  color: var(--text);
  min-width: 0;
}
.copy-feedback { font-size: 0.8rem; color: var(--success); height: 1.2em; margin-top: 0.25rem; }
.invite-code-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.invite-code-row.invite-code-used { opacity: 0.6; }
.invite-code { font-family: monospace; font-size: 1rem; letter-spacing: 0.05em; }
.invite-used-by { font-size: 0.8rem; color: var(--text-muted); }

.code-block {
  background: #1e293b;
  color: #e2e8f0;
  padding: 0.9rem 1rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
  overflow-x: auto;
  white-space: pre;
  margin-bottom: 0.75rem;
}

.profile-notes {
  margin: 0.75rem 0 0 1.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.7;
}
.profile-notes code {
  background: #f1f5f9;
  padding: 0.1em 0.35em;
  border-radius: 3px;
  font-size: 0.95em;
}

/* ── Pagination ──────────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}
.page-info {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-right: 0.5rem;
}
.page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.875rem;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
  cursor: pointer;
}
a.page-btn:hover { background: #e2e8f0; border-color: #cbd5e1; text-decoration: none; }
.page-current { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.page-disabled { color: var(--text-muted); cursor: default; }
.page-gap { padding: 0 0.25rem; color: var(--text-muted); font-size: 0.875rem; line-height: 2rem; }

/* ── Submit panel ────────────────────────────────────────────────────────────── */
.submit-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 2rem;
  padding: 1rem 1.25rem;
}
.submit-panel summary { cursor: pointer; font-weight: 600; font-size: 1rem; user-select: none; }
.submit-form { margin-top: 1rem; }
.submit-form label { display: block; margin-bottom: 0.5rem; font-size: 0.875rem; font-weight: 500; }
.submit-form textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: vertical;
  font-family: monospace;
  font-size: 0.875rem;
}
.submit-form textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }

/* ── Video grid ──────────────────────────────────────────────────────────────── */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}

.video-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s;
}
.video-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.08); }

.card-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #e2e8f0;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
}
.card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.card-body { padding: 0.75rem 1rem 0.5rem; flex: 1; min-width: 0; }
.card-title { font-size: 0.875rem; font-weight: 500; word-break: break-word; margin-bottom: 0.25rem; }
.card-url { display: block; font-size: 0.7rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 0.4rem; }
.card-url:hover { color: var(--primary); text-decoration: underline; }
.meta { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.25rem; }
.error-msg { font-size: 0.75rem; color: var(--danger); margin-top: 0.25rem; word-break: break-word; }

.card-actions {
  padding: 0.5rem 1rem 0.75rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

/* ── List view ───────────────────────────────────────────────────────────────── */
.video-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.video-list .video-card {
  flex-direction: row;
  align-items: stretch;
  border-radius: var(--radius);
}
.video-list .card-thumb {
  width: 144px;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius) 0 0 var(--radius);
  overflow: hidden;
}
.video-list .card-body {
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.15rem;
}
.video-list .card-title { margin-bottom: 0; }
.video-list .card-actions {
  padding: 0.5rem 0.75rem;
  flex-direction: column;
  justify-content: center;
  gap: 0.35rem;
  border-left: 1px solid var(--border);
  min-width: 110px;
  align-items: stretch;
}
.video-list .card-actions .btn,
.video-list .card-actions a.btn { width: 100%; text-align: center; }
.video-list .card-actions form { width: 100%; }
.video-list .card-actions form .btn { width: 100%; }
.video-list .thumb-play { display: none; }

/* ── Status badges ───────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-queued      { background: #f1f5f9; color: #475569; }
.badge-downloading { background: #dbeafe; color: #1e40af; }
.badge-processing  { background: #e0f2fe; color: #0369a1; }
.badge-ready       { background: #dcfce7; color: #166534; }
.badge-failed      { background: #fee2e2; color: #991b1b; }
.badge-deleted     { background: #f1f5f9; color: #9ca3af; }

/* ── Spinner ─────────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: 3px solid #cbd5e1;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.icon-failed { font-size: 2rem; color: var(--danger); }

/* ── Empty state ─────────────────────────────────────────────────────────────── */
.empty-state { text-align: center; color: var(--text-muted); padding: 3rem 0; }

/* ── Thumbnail play overlay ──────────────────────────────────────────────────── */
.thumb-link { display: block; position: relative; width: 100%; height: 100%; }
.thumb-link img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  color: #fff;
  background: rgba(0,0,0,.35);
  opacity: 0;
  transition: opacity 0.2s;
}
.card-thumb:hover .thumb-play { opacity: 1; }

/* ── Watch page ──────────────────────────────────────────────────────────────── */
.watch-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.watch-title {
  flex: 1;
  font-size: 1.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-wrap {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 2rem;
  line-height: 0;
}

/* ── Screenshots grid ────────────────────────────────────────────────────────── */
.shots-section { margin-bottom: 2rem; }
.shots-heading {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.shots-count { font-size: 0.8rem; color: var(--text-muted); font-weight: 400; }

.shots-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.shot-item {
  cursor: pointer;
  border-radius: 4px;
  overflow: hidden;
  border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  background: #1e293b;
}
.shot-item:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.shot-item.shot-active { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.35); }
.shot-img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; }
.shot-label {
  display: block;
  text-align: center;
  font-size: 0.7rem;
  color: #94a3b8;
  padding: 2px 0 3px;
  font-variant-numeric: tabular-nums;
}

/* ── Lightbox ─────────────────────────────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-overlay {
  position: absolute;
  inset: 0;
  background: rgba(30, 30, 30, 0.88);
  backdrop-filter: blur(3px);
}
.lightbox-box {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  max-width: 95vw;
  max-height: 95vh;
}
.lightbox-img {
  max-width: 95vw;
  max-height: 88vh;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0,0,0,.6);
  display: block;
}
.lightbox-close {
  position: absolute;
  top: -2.25rem;
  right: 0;
  background: none;
  border: none;
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.8;
  padding: 0;
}
.lightbox-close:hover { opacity: 1; }
.lightbox-label {
  color: #cbd5e1;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

/* ── Regenerate panel ─────────────────────────────────────────────────────────── */
.regen-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}
.regen-panel summary { cursor: pointer; font-weight: 500; user-select: none; color: var(--text-muted); }
.regen-form { margin-top: 0.75rem; }
.regen-form label { display: block; margin-bottom: 0.4rem; font-weight: 500; }
.regen-row { display: flex; align-items: center; gap: 0.6rem; }
.regen-row input[type="number"] {
  width: 7rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
}
.regen-row input[type="number"]:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.regen-hint { margin-top: 0.4rem; font-size: 0.75rem; color: var(--text-muted); }

.regen-pending {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Prev / Next nav buttons */
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  background: rgba(0, 0, 0, 0.55);
  border: none;
  color: #fff;
  font-size: 3rem;
  line-height: 1;
  width: 3rem;
  padding: 0.5rem 0;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s;
  user-select: none;
}
.lightbox-nav:hover { background: rgba(0, 0, 0, 0.85); }
.lightbox-prev { left: 1rem; }
.lightbox-next { right: 1rem; }
