:root {
  --bg: #0e1117;
  --bg-soft: #151a24;
  --bg-card: #1a2030;
  --bg-hover: #232b3f;
  --border: #272f42;
  --text: #e8ebf2;
  --text-soft: #9aa3b5;
  --text-dim: #6b7486;
  --accent: #ff3d71;
  --accent-2: #7c5cff;
  --grad: linear-gradient(135deg, #ff3d71, #7c5cff);
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --radius: 14px;
  --sidebar-w: 240px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; }
.cat-move-select {
  max-width: 150px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.cat-move-select:disabled { opacity: .6; cursor: wait; }
.cat-move-select:hover:not(:disabled) { border-color: var(--accent); }

code {
  background: rgba(124, 92, 255, 0.12);
  color: #b39dff;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 0.82em;
}

.admin-body { display: flex; min-height: 100vh; }

/* ----- Sidebar ----- */
.admin-sidebar {
  width: var(--sidebar-w);
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
  gap: 10px;
}

.admin-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.2rem;
  padding: 4px 8px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--grad);
  color: #fff;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(255, 61, 113, 0.4);
}

.brand-name { background: var(--grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }

.admin-tag {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--bg-card);
  color: var(--text-soft);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 6px;
}

.admin-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }

.admin-nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  color: var(--text-soft);
  font-weight: 600;
  font-size: 0.92rem;
  transition: background 0.2s, color 0.2s;
}

.admin-nav-link:hover { background: var(--bg-hover); color: var(--text); }
.nav-active { background: var(--bg-hover); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.nav-danger { color: #fca5a5; }
.nav-danger:hover { background: rgba(239, 68, 68, 0.12); color: var(--red); }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 10px;
  border-top: 1px solid var(--border);
}

.avatar {
  width: 36px; height: 36px;
  min-width: 36px;
  border-radius: 50%;
  background: var(--grad);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
}

.user-name { font-size: 0.9rem; font-weight: 600; }
.user-role { font-size: 0.76rem; color: var(--text-dim); }

/* ----- Main ----- */
.admin-main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title { font-size: 1.15rem; font-weight: 800; }

.admin-content { padding: 28px; flex: 1; }

/* ----- Buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
  font-family: inherit;
}

.btn:hover { filter: brightness(1.12); }
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--grad); color: #fff; box-shadow: 0 5px 16px rgba(255, 61, 113, 0.25); }
.btn-ghost { background: transparent; color: var(--text-soft); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-danger { background: rgba(239, 68, 68, 0.12); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.35); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 8px 14px; font-size: 0.82rem; }
.btn-xs { padding: 5px 10px; font-size: 0.76rem; border-radius: 8px; }
.btn-block { width: 100%; }

/* ----- Stats ----- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-bottom: 24px;
}

@media (max-width: 900px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .stats-grid { grid-template-columns: 1fr; } }

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  transition: border-color 0.2s, transform 0.2s;
}

.stat-card:hover { border-color: var(--accent-2); transform: translateY(-3px); }

.stat-icon { font-size: 1.5rem; margin-bottom: 8px; }
.stat-value { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.02em; }
.stat-label { color: var(--text-dim); font-size: 0.86rem; font-weight: 500; margin-top: 2px; }

/* ----- Panels ----- */
.admin-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-bottom: 18px;
}

@media (max-width: 900px) { .admin-grid-2 { grid-template-columns: 1fr; } }

.admin-layout-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

@media (max-width: 900px) { .admin-layout-grid { grid-template-columns: 1fr; } }

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.panel-head h3 { font-size: 1.05rem; font-weight: 700; }

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

.upload-pick-btn { cursor: pointer; display: inline-flex; align-items: center; }

.upload-pick-btn:active { transform: scale(0.97); }

.panel-link { color: var(--accent); font-weight: 600; font-size: 0.84rem; }

.panel-foot, .panel-foot p { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }

/* ----- Tables ----- */
.table-wrap { overflow-x: auto; }

.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }

.table th {
  text-align: left;
  color: var(--text-dim);
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 12px;
  border-bottom: 1px solid rgba(39, 47, 66, 0.6);
  vertical-align: middle;
}

.table tr:hover td { background: rgba(255, 255, 255, 0.02); }
.table tr:last-child td { border-bottom: none; }

.table-title { font-weight: 600; color: var(--text); transition: color 0.2s; }
.table-title:hover { color: var(--accent); }

.table-thumb {
  width: 96px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 8px;
}

.actions { display: flex; gap: 6px; align-items: center; white-space: nowrap; }

.inline-form { display: inline-flex; }
.category-edit { gap: 8px; width: 100%; }
.input-inline {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 12px;
  width: 100%;
  max-width: 260px;
  font-family: inherit;
  font-size: 0.9rem;
}

/* ----- Badges ----- */
.badge {
  display: inline-block;
  background: var(--bg-hover);
  color: var(--text-soft);
  font-size: 0.74rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
}

.badge-featured {
  background: linear-gradient(135deg, rgba(255, 61, 113, 0.2), rgba(124, 92, 255, 0.2));
  color: #ff8fb0;
}

.badge-ok { background: rgba(34, 197, 94, 0.15); color: var(--green); }
.badge-warn { background: rgba(245, 158, 11, 0.15); color: var(--amber); }
.badge-ban { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }
.badge-timeout { background: rgba(245, 158, 11, 0.15); color: var(--amber); }

.btn-warn { background: rgba(245, 158, 11, 0.12); color: var(--amber); border: 1px solid rgba(245, 158, 11, 0.35); }
.btn-warn:hover { background: var(--amber); color: #fff; }

.timeout-select {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.8rem;
}

.tag {
  display: inline-block;
  background: rgba(124, 92, 255, 0.12);
  color: #b39dff;
  font-size: 0.76rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
}

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

.form-group { display: flex; flex-direction: column; gap: 7px; }

.form-group label { font-size: 0.86rem; font-weight: 600; color: var(--text-soft); }

.form-group input,
.form-group textarea,
.form-group select {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 11px 14px;
  font-size: 0.92rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus { border-color: var(--accent-2); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

.field-hint { color: var(--text-dim); font-size: 0.78rem; }

.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  cursor: pointer;
  margin: 4px 0;
}

.checkbox input {
  width: 18px; height: 18px;
  accent-color: var(--accent);
}

.form-submit { display: flex; gap: 10px; padding-top: 6px; }

/* ----- Alerts ----- */
.alert {
  padding: 13px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 18px;
}

.alert-error { background: rgba(239, 68, 68, 0.12); border: 1px solid rgba(239, 68, 68, 0.35); color: #fca5a5; }

/* ----- Login ----- */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 38px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.4);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.35rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.login-hint { margin-top: 18px; font-size: 0.82rem; text-align: center; }

.muted { color: var(--text-dim); }

/* ----- Preview / status ----- */
.preview-strip {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 20px;
}

.preview-thumb {
  width: 140px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 8px;
}

.preview-title { font-weight: 700; margin-bottom: 2px; }

.video-status-ok, .video-status-warn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 18px;
}

.video-status-warn .badge { font-weight: 600; }
.video-path { word-break: break-all; }

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

/* ----- Uploader column ----- */
.admin-uploader { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 0.88rem; }

.admin-uploader:hover .avatar { filter: brightness(1.15); }

.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }

.avatar-xs {
  width: 30px;
  height: 30px;
  min-width: 30px;
  font-size: 0.8rem;
  border: 1px solid var(--border);
}

.table-thumb { border-radius: 8px; }

/* ----- Responsive admin ----- */
@media (max-width: 860px) {
  .admin-sidebar {
    position: static;
    width: 100%;
    flex-direction: column;
  }
  .admin-body { flex-direction: column; }
  .admin-main { margin-left: 0; }
  .admin-nav { flex-direction: row; flex-wrap: wrap; }
  .admin-content { padding: 18px; }
}

/* ----- Upload notifications (bottom right) ----- */
.upload-toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10000;
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
  width: 330px;
  max-width: calc(100vw - 36px);
  pointer-events: none;
}

.upload-toast {
  pointer-events: auto;
  background: rgba(21, 26, 36, 0.96);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  animation: toastIn 0.25s ease-out;
}

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

.toast-head { display: flex; align-items: center; gap: 9px; }
.toast-icon { width: 20px; text-align: center; }
.toast-title { flex: 1; font-weight: 600; font-size: 0.86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast-pct { font-variant-numeric: tabular-nums; font-size: 0.8rem; font-weight: 700; color: var(--text-soft); }
.toast-msg { font-size: 0.78rem; color: var(--text-dim); margin-top: 4px; }

.toast-progress { height: 5px; border-radius: 999px; background: var(--bg-hover); margin-top: 9px; overflow: hidden; }
.toast-progress-bar { height: 100%; width: 0%; border-radius: 999px; background: var(--grad); transition: width 0.2s ease; }

.upload-toast[data-state="done"] .toast-progress-bar { background: var(--green); }
.upload-toast[data-state="error"] .toast-progress-bar { background: var(--red); }
.upload-toast[data-state="error"] .toast-icon,
.upload-toast[data-state="error"] .toast-msg { color: #fca5a5; }
.upload-toast[data-state="done"] .toast-icon { color: var(--green); }

/* ----- Admin playlists ----- */
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.tab {
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-soft);
  font-weight: 600;
  font-size: 0.86rem;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.tab:hover { color: var(--text); border-color: var(--accent-2); }
.tab-active { background: var(--grad); color: #fff; border-color: transparent; }
.tab-count { display: inline-block; margin-left: 6px; background: rgba(0, 0, 0, 0.25); border-radius: 999px; padding: 0 7px; font-size: 0.72rem; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.admin-h2 { font-size: 1.25rem; font-weight: 800; margin-bottom: 14px; }
.admin-pl { padding: 18px; margin-bottom: 16px; }
.admin-pl-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.admin-pl-name { font-weight: 700; color: var(--text); transition: color 0.2s; }
.admin-pl-name:hover { color: var(--accent); }
.admin-pl-vids { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.admin-pl-vid { position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); display: block; }
.admin-pl-vid img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; display: block; }
.admin-pl-vid:hover { border-color: var(--accent-2); }
.pl-vid-title {
  position: absolute; inset: auto 0 0 0;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
  color: #fff; font-size: 0.78rem; font-weight: 600;
  padding: 14px 8px 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pl-vid-18 { position: absolute; right: 6px; top: 6px; background: var(--red); color: #fff; font-size: 0.64rem; font-weight: 800; padding: 2px 7px; border-radius: 999px; }

/* ----- Audit log ----- */
.audit-note { margin-bottom: 16px; font-size: 0.86rem; }
.audit-time { white-space: nowrap; font-size: 0.82rem; color: var(--text-soft); }
.audit-time .muted { font-size: 0.72rem; }
.audit-actor { white-space: nowrap; }
.audit-badge {
  background: rgba(124, 92, 255, 0.14);
  color: #b39dff;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.audit-detail { min-width: 300px; }
.audit-kv { display: inline-flex; gap: 6px; align-items: baseline; margin: 1px 14px 1px 0; font-size: 0.82rem; color: var(--text-soft); }
.audit-kv em { font-style: normal; color: var(--text-dim); font-family: 'JetBrains Mono', Consolas, monospace; font-size: 0.74rem; }
.audit-kv span { color: var(--text); word-break: break-word; }

/* ----- Confirm (delete) modal ----- */
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 9900;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 6, 12, 0.72);
  backdrop-filter: blur(3px);
}
.confirm-overlay[hidden] { display: none; }

.confirm-box {
  width: min(440px, calc(100vw - 32px));
  background: var(--bg-card, #141420);
  border: 1px solid var(--border, #2a2a3a);
  border-radius: 14px;
  padding: 24px;
  box-shadow: var(--shadow, 0 12px 40px rgba(0, 0, 0, 0.5));
}

.confirm-title { font-size: 1.05rem; font-weight: 800; margin-bottom: 8px; }
.confirm-text { font-size: 0.88rem; color: var(--text-soft, #9a9ab0); margin-bottom: 20px; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ----- Deleted videos table helpers ----- */
.cell-item { display: flex; align-items: center; gap: 10px; }
.cell-thumb { width: 64px; height: 40px; object-fit: cover; border-radius: 6px; background: #000; }
.cell-title { font-weight: 600; font-size: 0.9rem; margin-bottom: 2px; }
.cell-item .small { font-size: 0.72rem; }