:root {
  --bg: #0f1117;
  --panel: #171a23;
  --panel-2: #1d2130;
  --border: #2a2f3d;
  --text: #e8eaf0;
  --muted: #9aa3b2;
  --accent: #4f8cff;
  --accent-2: #3f7ff0;
  --ok: #28c76f;
  --warn: #ff9f43;
  --danger: #ea5455;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 32px rgba(0, 0, 0, 0.38);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; }

/* ===== Top bar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: rgba(15, 17, 23, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex: none;
  background: linear-gradient(135deg, #4f8cff, #7a5cff);
  font-weight: 700;
  color: #fff;
}
.brand-text { min-width: 0; }
.topbar h1 { margin: 0; font-size: 17px; white-space: nowrap; }
.topbar .sub { margin: 0; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 6px;
  padding: 10px 16px 0;
  max-width: 1180px;
  margin: 0 auto;
  overflow-x: auto;
}
.tab {
  padding: 9px 18px;
  border: 1px solid transparent;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 700;
}
.task-count {
  display: inline-block;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  padding: 0 5px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--warn);
  color: #1c1c1c;
  font-size: 11px;
  text-align: center;
}

.tab-panel { display: none; }
.tab-panel.active { display: grid; gap: 16px; }

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 16px 64px;
  display: grid;
  gap: 16px;
}

/* ===== Cards ===== */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.head-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.card h2 { margin: 0; font-size: 16px; }
.card h3 { margin: 0 0 12px; font-size: 14px; }

.step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: none;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

/* ===== Controls ===== */
input, select, textarea {
  width: 100%;
  background: #0c0e14;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 14px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

button {
  background: #232a3c;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: #2c3550; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-2); }
button.warn { background: var(--warn); border-color: var(--warn); color: #1c1c1c; }
button.ghost { background: transparent; }

.hint { color: var(--muted); font-size: 12px; margin: 6px 0; }
.hidden { display: none !important; }

.badge {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  background: #2a2f3d;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
}
.badge.ok { background: rgba(40, 199, 111, 0.14); color: var(--ok); border-color: var(--ok); }
.badge.bad { background: rgba(234, 84, 85, 0.14); color: var(--danger); border-color: var(--danger); }

/* ===== Filters ===== */
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  align-items: end;
}
.dynamic-filters { display: contents; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { color: var(--muted); font-size: 12px; }
.search-group { display: flex; gap: 8px; grid-column: 1 / -1; flex-wrap: wrap; }
.search-group input { flex: 1; min-width: 180px; }

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.spacer { flex: 1 1 auto; min-width: 8px; }
.check-all { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.check-all input { width: auto; }
.page-group { display: flex; align-items: center; gap: 8px; }
.page-info { color: var(--muted); font-size: 13px; min-width: 60px; text-align: center; }
.action-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== Video grid ===== */
.video-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 14px;
}
.video-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--panel-2);
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.video-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.video-card .poster { position: relative; aspect-ratio: 3 / 4; background: #0c0e14; }
.video-card .poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.video-card .poster .vip {
  position: absolute; top: 8px; right: 8px;
  background: rgba(234, 84, 85, 0.9); color: #fff;
  padding: 2px 8px; border-radius: 999px; font-size: 11px;
}
.video-card .poster .pick {
  position: absolute; top: 8px; left: 8px;
  width: 18px; height: 18px;
}
.video-card .body { padding: 10px 11px 12px; display: flex; flex-direction: column; gap: 8px; }
.video-card .title {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.video-card .meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.video-card .meta .id { color: var(--muted); font-size: 11px; }
.video-card .actions { display: flex; gap: 6px; }
.video-card .preview-btn, .video-card .add-btn { padding: 5px 10px; font-size: 12px; }
.video-card .add-btn { background: var(--accent); border-color: var(--accent); color: #fff; }
.video-card .add-btn:hover { background: var(--accent-2); }

.empty {
  grid-column: 1 / -1;
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 10px;
}

/* ===== Jobs ===== */
.job-list { display: grid; gap: 10px; }
.job-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: var(--panel-2);
}
.job-item .head { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.job-item .head .name { font-weight: 600; }
.job-item .head .state { color: var(--muted); white-space: nowrap; }
.job-item .bar { height: 7px; border-radius: 999px; background: #2a2f3d; overflow: hidden; margin: 10px 0 6px; }
.job-item .bar > span { display: block; height: 100%; background: var(--accent); transition: width 0.25s ease; }
.job-item .stats { color: var(--muted); font-size: 12px; }
.job-log { max-height: 180px; overflow: auto; margin-top: 8px; font-size: 12px; line-height: 1.6; }
.job-log .log-success { color: var(--ok); }
.job-log .log-error { color: var(--danger); }
.job-log .log-warn { color: var(--warn); }

/* ===== Modals ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 16px;
}
.modal-card {
  width: min(760px, 100%);
  max-height: min(90vh, 100%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.modal-head h3 { margin: 0; }
.modal-body { padding: 16px; overflow: auto; min-height: 0; }

.login-card { width: min(720px, 100%); }
.login-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}
.panel {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
.domain { color: var(--muted); font-weight: 400; font-size: 12px; }

.qr-wrap { margin-top: 12px; text-align: center; }
.qr-wrap img { width: min(210px, 70vw); height: auto; aspect-ratio: 1; border-radius: 10px; background: #fff; }
.qr-status { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 8px; font-size: 13px; }
.qr-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.preview-meta { display: flex; gap: 14px; margin-bottom: 14px; }
.preview-meta img { width: 96px; height: 136px; object-fit: cover; border-radius: 8px; flex: none; }
.preview-meta > div { min-width: 0; }
.preview-meta h4 { margin: 0 0 6px; font-size: 15px; }
.preview-actions { margin-bottom: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.modal textarea { width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 12px; line-height: 1.6; }

.bar { height: 8px; border-radius: 999px; background: #2a2f3d; overflow: hidden; margin: 10px 0; }
.bar > span { display: block; height: 100%; background: var(--accent); transition: width 0.25s ease; }

.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(88vw, 480px);
  padding: 12px 18px;
  background: #0f172a;
  color: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 600;
  z-index: 100;
}

.player-card { width: min(760px, 100%); }
.player-body { padding: 16px; }
.player-card video { width: 100%; max-height: 48vh; background: #000; border-radius: 10px; }
.player-actions { margin: 12px 0; }
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 12px 0 8px; }
.episode-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: 8px;
  max-height: 190px;
  overflow: auto;
}
.episode-list button { min-width: 0; height: 34px; padding: 0 8px; font-size: 13px; }
.episode-list button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ===== Auth gate ===== */
.auth-modal {
  z-index: 200;
  background: rgba(8, 10, 15, 0.82);
}
.auth-card { width: min(360px, 100%); }
.auth-card .modal-body { display: grid; gap: 14px; }
.auth-card .primary { width: 100%; }

/* ===== Responsive ===== */
@media (max-width: 760px) {
  .topbar { padding: 10px 14px; }
  .topbar .sub { display: none; }
  main { padding: 14px 12px 56px; }
  .filters { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .video-list { grid-template-columns: repeat(auto-fill, minmax(142px, 1fr)); gap: 10px; }
  .card { padding: 14px; }
}

@media (max-width: 480px) {
  .top-actions { width: 100%; }
  .top-actions button { flex: 1; }
  .filters { grid-template-columns: 1fr; }
  .video-list { grid-template-columns: repeat(2, 1fr); }
  .toolbar { gap: 8px; }
  .toolbar .action-group { width: 100%; }
  .toolbar .action-group button { flex: 1; }
  .page-group { width: 100%; justify-content: space-between; }
  .preview-meta { flex-direction: column; }
  .preview-meta img { width: 100%; height: auto; aspect-ratio: 16 / 10; }
}
