:root {
  --bg: #0f1117;
  --bg-elevated: #171a22;
  --bg-hover: #1e2330;
  --border: #2a3142;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --primary: #5b8cff;
  --primary-hover: #7aa2ff;
  --success: #3ecf8e;
  --warn: #f0b429;
  --error: #f07178;
  --info: #6ec1ff;
  --radius: 10px;
  --font: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

.app-shell { display: flex; flex-direction: column; min-height: 100vh; }
.brand {
  display: flex; align-items: center; gap: 0.65rem; font-weight: 700;
  color: var(--text);
}
.brand:hover { color: var(--text); }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #9b7bff);
  display: grid; place-items: center; color: #fff; font-size: 0.9rem;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.75rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}
.sticky-chrome {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
}
.sticky-chrome-stepper {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: 0.65rem 1.75rem;
}
.topbar-left { display: flex; align-items: center; gap: 1rem; min-width: 0; }
.page-title {
  margin: 0; font-size: 1.15rem; font-weight: 650;
  padding-left: 1rem;
  border-left: 1px solid var(--border);
}
.topbar-settings.is-active {
  border-color: var(--primary);
  color: var(--text);
  background: var(--bg-hover);
}
.content { padding: 1.25rem 1.75rem 2.5rem; }

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 1rem;
}
.card-header h2 { margin: 0; font-size: 1.05rem; }

.grid { display: grid; gap: 1rem; }
.stats-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.stat-card .stat-label { color: var(--muted); font-size: 0.8rem; }
.stat-card .stat-value { font-size: 1.6rem; font-weight: 700; margin-top: 0.25rem; }

.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th, .table td {
  text-align: left; padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table th { color: var(--muted); font-weight: 500; font-size: 0.8rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 0.35rem;
  background: var(--bg-hover);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  font: inherit;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-busy { display: inline-flex; align-items: center; gap: 0.4rem; }
.btn-busy[hidden], .btn-label[hidden] { display: none !important; }

.spinner {
  width: 0.9rem; height: 0.9rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
.spinner-lg { width: 1.4rem; height: 1.4rem; border-width: 3px; }

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

.search-busy {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  margin-top: 1rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-hover);
}
.search-busy[hidden] { display: none !important; }
.search-busy strong { display: block; margin-bottom: 0.15rem; color: var(--text); }
.search-busy .muted { margin: 0; }

#search-form.is-searching {
  pointer-events: none;
  opacity: 0.72;
}
.btn-danger { background: transparent; border-color: var(--error); color: var(--error); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.85rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

.toolbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap;
}

.form { display: flex; flex-direction: column; gap: 1rem; }
.form-row { display: flex; flex-direction: row; flex-wrap: wrap; gap: 1rem; align-items: flex-end; }
.form.form-row { flex-direction: row; }
.form-row label { min-width: 140px; }
.form-row .grow { flex: 1; min-width: 200px; }
.form label, fieldset label {
  display: flex; flex-direction: column; gap: 0.35rem;
  font-size: 0.9rem; color: var(--muted);
}
/* The display above outranks the UA rule for [hidden], so restate it. */
.form label[hidden], fieldset label[hidden] { display: none !important; }
.form input, .form select, .form textarea,
fieldset input, fieldset select, fieldset textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.55rem 0.7rem;
  font: inherit;
}
.form textarea { resize: vertical; }
.form-actions {
  display: flex; justify-content: flex-end; gap: 0.75rem; align-items: center;
}
.form-actions.align-end { margin-left: auto; }
fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
legend { padding: 0 0.4rem; color: var(--text); font-weight: 600; }

.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.source-hints { margin: 0.25rem 0 0; padding-left: 1.1rem; }
.source-hints li { margin-bottom: 0.2rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1.25rem; }
.text-right { text-align: right; }
.inline-form { display: inline; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: lowercase;
  background: var(--bg-hover);
  color: var(--muted);
}
.badge-success { background: rgba(62, 207, 142, 0.15); color: var(--success); }
.badge-warn { background: rgba(240, 180, 41, 0.15); color: var(--warn); }
.badge-error { background: rgba(240, 113, 120, 0.15); color: var(--error); }
.badge-info { background: rgba(110, 193, 255, 0.15); color: var(--info); }
.badge-muted { background: var(--bg-hover); color: var(--muted); }

.chip {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 6px;
  background: var(--bg-hover);
  font-size: 0.8rem;
  margin-left: 0.35rem;
}
.chip-muted { opacity: 0.7; }

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
}
.alert-success { background: rgba(62, 207, 142, 0.1); border-color: var(--success); }
.alert-error { background: rgba(240, 113, 120, 0.1); border-color: var(--error); }
.alert-info { background: rgba(110, 193, 255, 0.1); border-color: var(--info); }

.stepper-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.stepper {
  display: flex; align-items: center; gap: 0.5rem;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}
.stepper-nav {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
  flex-shrink: 0;
}
.step {
  display: flex; align-items: center; gap: 0.45rem;
  color: var(--muted); font-size: 0.9rem;
}
.step-num {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  font-weight: 600; font-size: 0.85rem;
}
.step.current { color: var(--text); }
.step.current .step-num {
  background: var(--primary); border-color: var(--primary); color: #fff;
}
.step.done .step-num {
  background: rgba(62, 207, 142, 0.2); border-color: var(--success); color: var(--success);
}
.step-line {
  flex: 1; min-width: 24px; height: 2px;
  background: var(--border); max-width: 60px;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}
.video-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
  cursor: pointer;
  position: relative;
  display: block;
}
.video-card.selected { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.video-card input.video-select {
  position: absolute; top: 8px; left: 8px; z-index: 2; width: 18px; height: 18px;
}
.thumb-wrap { aspect-ratio: 16/9; background: #000; overflow: hidden; }
.thumb-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-placeholder { width: 100%; height: 100%; background: var(--bg-hover); }
.video-meta { padding: 0.65rem 0.75rem 0.85rem; }
.video-title {
  font-size: 0.9rem; font-weight: 600;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.progress-wrap {
  height: 8px; background: var(--bg-hover); border-radius: 999px; overflow: hidden;
}
.progress-bar {
  height: 100%; background: linear-gradient(90deg, var(--primary), var(--success));
  transition: width 0.4s ease;
}

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.simple-list { list-style: none; padding: 0; margin: 0; }
.simple-list li { padding: 0.4rem 0; border-bottom: 1px solid var(--border); }

.dl {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 0.5rem 1rem;
  margin: 0;
}
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }

.error-card { text-align: center; padding: 3rem 1.5rem; max-width: 480px; margin: 2rem auto; }

@media (max-width: 800px) {
  .topbar { padding: 0.75rem 1rem; }
  .sticky-chrome-stepper { padding: 0.55rem 1rem; }
  .content { padding: 1rem 1rem 2rem; }
  .brand-text { display: none; }
  .page-title { padding-left: 0.75rem; font-size: 1.05rem; }
  .dl { grid-template-columns: 1fr; }
}
