:root {
  --bg: #0b0f14;
  --bg-soft: #111823;
  --bg-card: #141d2a;
  --bg-input: #0d141d;
  --border: #223044;
  --border-soft: #1a2636;
  --text: #e6edf6;
  --text-muted: #8ca0b8;
  --accent: #ff2d55;
  --accent-soft: rgba(255, 45, 85, 0.12);
  --ok: #2ecc71;
  --warn: #f1c40f;
  --error: #ff5c5c;
  --info: #4aa8ff;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a {
  color: var(--info);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

h1,
h2,
h3 {
  margin: 0 0 12px;
  line-height: 1.25;
}
h1 {
  font-size: 24px;
}
h2 {
  font-size: 18px;
}
h3 {
  font-size: 15px;
}

.muted {
  color: var(--text-muted);
  font-size: 13px;
}
.error-text {
  color: var(--error);
  font-size: 12px;
  word-break: break-word;
}
.tiny {
  font-size: 12px;
}
.tiny.ok {
  color: var(--ok);
}
.tiny.err {
  color: var(--error);
}

/* ------------------------------- Layout -------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 15, 20, 0.92);
  border-bottom: 1px solid var(--border-soft);
  backdrop-filter: blur(8px);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.brand {
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
  letter-spacing: 0.2px;
}
.brand span {
  color: var(--accent);
}
.nav {
  display: flex;
  gap: 6px;
}
.nav a {
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 14px;
}
.nav a:hover {
  background: var(--bg-soft);
  color: var(--text);
  text-decoration: none;
}
.nav a.active {
  background: var(--accent-soft);
  color: #ff8aa1;
}
.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-head .grow {
  flex: 1;
}
.page-head .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.grid {
  display: grid;
  gap: 16px;
}
.grid.cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card h2 {
  margin-bottom: 14px;
}
.card + .card,
/* Thẻ đứng ngay sau một <form> (trang Cài đặt) cũng cần khoảng cách tương tự */
form + .card {
  margin-top: 18px;
}

.stat {
  background: linear-gradient(160deg, var(--bg-card), var(--bg-soft));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat .label {
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.stat .value {
  font-size: 26px;
  font-weight: 700;
  margin-top: 4px;
}
.stat .sub {
  color: var(--text-muted);
  font-size: 12px;
}

/* ------------------------------- Buttons ------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
  white-space: nowrap;
  font-family: inherit;
}
.btn:hover {
  background: #1a2536;
  border-color: #2d3f57;
}
.btn:active {
  transform: translateY(1px);
}
.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn.primary {
  background: linear-gradient(135deg, #ff2d55, #ff5f7a);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}
.btn.primary:hover {
  filter: brightness(1.08);
}
.btn.danger {
  color: #ff9aa8;
  border-color: rgba(255, 92, 92, 0.35);
  background: rgba(255, 92, 92, 0.08);
}
.btn.danger:hover {
  background: rgba(255, 92, 92, 0.18);
}
.btn.ghost {
  background: transparent;
}
.btn.sm {
  padding: 5px 10px;
  font-size: 13px;
  border-radius: 7px;
}

/* -------------------------------- Forms -------------------------------- */

label.field {
  display: block;
  margin-bottom: 14px;
}
label.field > span {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
input[type='text'],
input[type='password'],
input[type='number'],
input[type='url'],
input[type='date'],
input[type='search'],
select,
textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 45, 85, 0.12);
}
input[type='checkbox'] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  vertical-align: -2px;
}
.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.form-row.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.checkbox-line {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  font-size: 14px;
}

.add-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.add-form input[type='text'] {
  width: 100%;
}
.add-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.add-row .checkbox-line {
  flex: 1;
  min-width: 220px;
  margin: 0;
}
.add-row .btn {
  flex: 0 0 auto;
}
.filter-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.filter-form input[type='text'] {
  min-width: 180px;
  flex: 1 1 220px;
}
.filter-form input[type='date'] {
  min-width: 150px;
  flex: 0 1 160px;
  color-scheme: dark;
}
.filter-form select {
  min-width: 120px;
  flex: 0 1 140px;
}
.filter-form .muted {
  margin: 0 2px;
}
.video-user {
  margin-bottom: 4px;
  font-size: 13px;
  font-weight: 600;
}
.video-user .user-link {
  color: var(--info);
}
.hint {
  color: var(--text-muted);
  font-size: 12px;
  margin: 8px 0 0;
}

/* -------------------------------- Tables ------------------------------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: var(--bg-card);
}
.table th,
.table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
.table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  background: var(--bg-soft);
  white-space: nowrap;
}
.table tr:last-child td {
  border-bottom: none;
}
.table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}
.row-error {
  background: rgba(255, 92, 92, 0.08) !important;
  box-shadow: inset 3px 0 0 var(--error);
}
.row-error .user-link {
  color: #ff9aa8;
}
.user-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 170px;
}
.user-link {
  font-weight: 600;
  color: var(--text);
}
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  background: #1d2a3b;
  flex: 0 0 auto;
}
.avatar.placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--text-muted);
}
.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge.ok {
  color: var(--ok);
  background: rgba(46, 204, 113, 0.1);
  border-color: rgba(46, 204, 113, 0.3);
}
.badge.error {
  color: var(--error);
  background: rgba(255, 92, 92, 0.12);
  border-color: rgba(255, 92, 92, 0.35);
}
.badge.checking {
  color: var(--warn);
  background: rgba(241, 196, 15, 0.1);
  border-color: rgba(241, 196, 15, 0.3);
}
.badge.pending {
  color: var(--text-muted);
  background: rgba(140, 160, 184, 0.1);
  border-color: rgba(140, 160, 184, 0.3);
}
.pill {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #ff8aa1;
  border: 1px solid rgba(255, 45, 85, 0.3);
}

/* -------------------------------- Toolbar ------------------------------ */

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.toolbar .right {
  margin-left: auto;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.check-all {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}

/* ------------------------------- Videos -------------------------------- */

.video-grid {
  display: grid;
  grid-template-columns: repeat(var(--cards-per-row, 4), minmax(0, 1fr));
  gap: 16px;
}
@media (max-width: 900px) {
  .video-grid {
    grid-template-columns: repeat(min(var(--cards-per-row, 4), 3), minmax(0, 1fr));
  }
}
@media (max-width: 640px) {
  .video-grid {
    grid-template-columns: repeat(min(var(--cards-per-row, 4), 2), minmax(0, 1fr));
  }
}
@media (max-width: 420px) {
  .video-grid {
    grid-template-columns: repeat(1, minmax(0, 1fr));
  }
}
.sort-form {
  display: flex;
  gap: 8px;
  align-items: center;
}
.sort-form select {
  min-width: 120px;
}
.video-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.video-card:hover {
  border-color: rgba(255, 255, 255, 0.75);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2), 0 10px 30px rgba(0, 0, 0, 0.45);
}
.video-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 45, 85, 0.25);
}
.video-card .thumb {
  position: relative;
  aspect-ratio: 9 / 13;
  background: #0a0f16;
  cursor: pointer;
  overflow: hidden;
}
.video-card .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.video-card .thumb .play-btn {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-card .thumb:hover .play-btn {
  opacity: 1;
}
.video-card .duration {
  position: absolute;
  right: 8px;
  bottom: 8px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 12px;
  padding: 2px 7px;
  border-radius: 6px;
}
.video-card .check {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 3;
  background: rgba(0, 0, 0, 0.55);
  padding: 5px;
  border-radius: 7px;
  line-height: 0;
}
.video-body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  cursor: pointer;
}
.video-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.video-meta {
  color: var(--text-muted);
  font-size: 12px;
}
.video-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: 8px;
  position: relative;
  z-index: 2;
}
.btn.icon-btn {
  padding: 6px 8px;
  min-width: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn.icon-btn svg {
  width: 16px;
  height: 16px;
  display: block;
}

.pagination {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 24px;
  flex-wrap: wrap;
}

/* ----------------------------- Download progress -------------------------- */

.download-progress {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  width: min(420px, calc(100vw - 32px));
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.download-progress.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
.download-progress .dp-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}
.download-progress .dp-bar {
  height: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.download-progress .dp-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.15s ease;
}
.download-progress .dp-fill.indeterminate {
  width: 100%;
  background: linear-gradient(90deg, var(--accent), var(--info), var(--accent));
  background-size: 200% 100%;
  animation: dp-slide 1.2s linear infinite;
}
.download-progress .dp-text {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-word;
}
@keyframes dp-slide {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* -------------------------------- Responsive (mobile) --------------------- */

@media (max-width: 768px) {
  .topbar-inner {
    flex-wrap: wrap;
    gap: 8px;
  }
  .nav {
    width: 100%;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }
  .page-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .page-head .actions {
    width: 100%;
  }
  .page-head .actions .btn {
    flex: 1;
  }
  .add-form input[type='text'] {
    width: 100%;
  }
  .filter-form input,
  .filter-form select {
    flex: 1 1 100%;
    min-width: 0;
  }
  .toolbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .toolbar .right {
    width: 100%;
    margin-left: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }
  .toolbar .right .btn {
    flex: 1 1 45%;
  }
  .sort-form {
    width: 100%;
    margin-left: 0;
  }
  .sort-form select {
    flex: 1;
  }
  .table-wrap {
    font-size: 13px;
  }
  .modal-inner {
    width: min(92vw, 520px);
    padding: 10px;
  }
  .modal-inner video {
    max-height: 60vh;
  }
  .btn.icon-btn {
    min-width: 36px;
    padding: 7px 9px;
  }
}

@media (max-width: 480px) {
  body {
    font-size: 14px;
  }
  .card {
    padding: 12px;
  }
  .video-actions .btn {
    min-width: 34px;
  }
  .dp-title {
    font-size: 12px;
  }
}

.runs {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.runs li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  font-size: 13px;
  flex-wrap: wrap;
}

.user-hero {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.user-hero .avatar {
  width: 64px;
  height: 64px;
  font-size: 24px;
}
.user-hero .who {
  flex: 1;
  min-width: 220px;
}
.user-hero h1 {
  margin: 0;
  font-size: 22px;
}
.rename-note {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 2px;
}
.warn-text {
  color: var(--warn);
  font-size: 12px;
  margin-top: 2px;
  word-break: break-word;
}
.warn-box {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 9px;
  background: rgba(241, 196, 15, 0.1);
  border: 1px solid rgba(241, 196, 15, 0.35);
  color: #ffe58a;
  font-size: 13px;
  word-break: break-word;
}
.rename-history {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 9px;
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  font-size: 13px;
}
.rename-history summary {
  cursor: pointer;
  color: var(--text-muted);
  user-select: none;
}
.rename-history ul {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.rename-history li {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.rename-history .old {
  color: var(--text-muted);
  text-decoration: line-through;
}
.rename-history .new {
  color: var(--ok);
  font-weight: 600;
}
.rename-history .arrow {
  color: var(--text-muted);
}
.error-box {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 9px;
  background: rgba(255, 92, 92, 0.1);
  border: 1px solid rgba(255, 92, 92, 0.35);
  color: #ffb3bd;
  font-size: 13px;
  word-break: break-word;
}

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* --------------------------------- Modal ------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}
.modal[hidden] {
  display: none;
}
.modal-inner {
  position: relative;
  width: min(520px, 100%);
  max-height: 92vh;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-inner video {
  width: 100%;
  max-height: 75vh;
  background: #000;
  border-radius: 9px;
}
.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  cursor: pointer;
  font-size: 15px;
}

/* --------------------------------- Login ------------------------------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 20% -10%, rgba(255, 45, 85, 0.18), transparent 60%),
    radial-gradient(700px 500px at 110% 110%, rgba(74, 168, 255, 0.12), transparent 55%),
    var(--bg);
}
.login-card {
  width: min(400px, 100%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 30px;
  box-shadow: var(--shadow);
}
.login-card .logo {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}
.login-card .logo span {
  color: var(--accent);
}
.login-card p {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 20px;
}
.login-error {
  background: rgba(255, 92, 92, 0.1);
  border: 1px solid rgba(255, 92, 92, 0.35);
  color: #ffb3bd;
  padding: 9px 12px;
  border-radius: 9px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* --------------------------------- Toast ------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 100;
  background: #1b2636;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: var(--shadow);
  max-width: min(560px, calc(100vw - 40px));
}
.toast[hidden] {
  display: none;
}
.toast.ok {
  border-color: rgba(46, 204, 113, 0.45);
}
.toast.error {
  border-color: rgba(255, 92, 92, 0.5);
  color: #ffc2c8;
}

.settings-save {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
}

@media (max-width: 900px) {
  .grid.cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid.cols-2,
  .form-row,
  .form-row.three {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .grid.cols-4 {
    grid-template-columns: 1fr;
  }
  .topbar-inner {
    gap: 10px;
    padding: 10px 14px;
    flex-wrap: wrap;
  }
  .container {
    padding: 18px 14px 48px;
  }
  .row-actions {
    justify-content: flex-start;
  }
}
