:root {
  --bg: #0d1016;
  --bg-soft: #121722;
  --card: #161c28;
  --card-2: #1b2230;
  --line: #263042;
  --text: #e8edf7;
  --muted: #8b97ab;
  --accent: #5b8cff;
  --accent-2: #7aa2ff;
  --green: #35d39a;
  --amber: #f5b544;
  --red: #ff627d;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  color-scheme: dark;
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  font-size: 14px;
}

button, input, select, textarea { font: inherit; color: inherit; }

.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

/* ---------------- 侧栏 ---------------- */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px 16px;
  background: linear-gradient(180deg, #111725 0%, #0d1119 100%);
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; gap: 12px; align-items: center; }

.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, #5b8cff, #8b5bff);
  color: #fff; font-size: 15px;
  box-shadow: 0 6px 18px rgba(91, 140, 255, .35);
}

.brand h1 { margin: 0; font-size: 16px; letter-spacing: .5px; }
.brand p { margin: 3px 0 0; font-size: 11px; color: var(--muted); }

nav { display: flex; flex-direction: column; gap: 6px; }

.nav-btn {
  text-align: left;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: .16s ease;
}

.nav-btn:hover { background: rgba(91, 140, 255, .08); color: var(--text); }
.nav-btn.active {
  background: rgba(91, 140, 255, .14);
  border-color: rgba(91, 140, 255, .32);
  color: #dce6ff;
}

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }

.queue-state {
  padding: 9px 11px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.queue-state.busy { color: var(--accent-2); border-color: rgba(91, 140, 255, .4); }
.queue-state.paused { color: var(--amber); border-color: rgba(245, 181, 68, .4); }

.version { font-size: 11px; color: #5d687c; }

/* ---------------- 主区 ---------------- */

main { padding: 26px 30px 60px; min-width: 0; }

.tab { display: none; animation: fade .2s ease; }
.tab.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin-bottom: 18px;
}

.page-head h2 { margin: 0; font-size: 22px; }
.page-head p { margin: 6px 0 0; color: var(--muted); font-size: 12px; }

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

/* ---------------- 表单 ---------------- */

textarea, input[type="text"], input[type="number"], input[type="password"], select {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

textarea:focus, input:focus, select:focus {
  border-color: rgba(91, 140, 255, .65);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, .12);
}

/* 浏览器自动填充默认是白底黑字，强制改回暗色，保持所有输入框颜色统一 */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active,
textarea:-webkit-autofill,
select:-webkit-autofill {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--bg-soft) inset;
  box-shadow: 0 0 0 1000px var(--bg-soft) inset;
  caret-color: var(--text);
  transition: background-color 9999s ease-in-out 0s;
}

textarea { min-height: 148px; resize: vertical; line-height: 1.65; }

.composer-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; color: var(--muted); }

.check { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; padding-top: 22px; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }

.upload-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: .16s ease;
  white-space: nowrap;
  text-decoration: none;
}

.btn:hover { border-color: rgba(91, 140, 255, .5); background: #212b3d; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, #5b8cff, #7a5bff); border-color: transparent; color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn.danger { color: var(--red); border-color: rgba(255, 98, 125, .3); }
.btn.danger:hover { background: rgba(255, 98, 125, .1); }

.composer-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; gap: 12px; }
.hint { color: var(--muted); font-size: 12px; }

.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumb {
  position: relative; width: 54px; height: 54px; border-radius: 9px; overflow: hidden;
  border: 1px solid var(--line); background: #000;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button {
  position: absolute; top: 2px; right: 2px; width: 17px; height: 17px;
  border-radius: 50%; border: 0; background: rgba(0, 0, 0, .7); color: #fff;
  font-size: 11px; line-height: 1; cursor: pointer;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 320px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-soft);
  color: var(--muted);
  font-size: 12px;
}
.file-chip b { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip button { border: 0; background: transparent; color: var(--red); cursor: pointer; font-size: 12px; }

/* ---------------- 任务列表 ---------------- */

.list-tools { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }

.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  border-radius: 999px; padding: 5px 12px; font-size: 12px; cursor: pointer;
}
.chip.active { color: #fff; background: rgba(91, 140, 255, .18); border-color: rgba(91, 140, 255, .45); }

.task-list { display: flex; flex-direction: column; gap: 8px; }

.task {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--bg-soft);
  transition: border-color .15s ease;
}
.task:hover { border-color: #33415a; }
.task.running { border-color: rgba(91, 140, 255, .5); box-shadow: inset 3px 0 0 var(--accent); }
.task.failed { border-color: rgba(255, 98, 125, .35); }
.task.completed { border-color: rgba(53, 211, 154, .25); }

.task-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.task-name { font-weight: 600; font-size: 13px; }
.task-meta { color: var(--muted); font-size: 12px; }
.task-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }

.badge {
  font-size: 11px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.badge.queued { color: var(--amber); border-color: rgba(245, 181, 68, .35); background: rgba(245, 181, 68, .08); }
.badge.running { color: var(--accent-2); border-color: rgba(91, 140, 255, .4); background: rgba(91, 140, 255, .1); }
.badge.completed { color: var(--green); border-color: rgba(53, 211, 154, .35); background: rgba(53, 211, 154, .08); }
.badge.failed { color: var(--red); border-color: rgba(255, 98, 125, .35); background: rgba(255, 98, 125, .08); }
.badge.canceled { color: #9aa4b5; }

.task-step { margin-top: 8px; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-error { margin-top: 6px; color: var(--red); font-size: 12px; }

.task-progress-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.task-progress { flex: 1; height: 5px; border-radius: 999px; background: #222b3b; overflow: hidden; }
.task-progress > i { display: block; height: 100%; background: linear-gradient(90deg, #5b8cff, #7a5bff); transition: width .3s ease; }
.task-progress.completed > i { background: var(--green); }
.task-progress.failed > i { background: var(--red); }
.task-progress-text { color: var(--muted); font-size: 11px; white-space: nowrap; text-align: right; }

.empty { padding: 30px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------------- 账号 ---------------- */

.account-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }

.account-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.account-head { display: flex; align-items: center; gap: 10px; }
.account-name { font-size: 15px; font-weight: 600; }
.account-sub { font-size: 11px; color: var(--muted); }
.account-tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: rgba(91, 140, 255, .14); color: var(--accent-2); white-space: nowrap; }
.account-tag.busy { background: rgba(245, 181, 68, .1); color: var(--amber); }
.account-proxy-row, .account-fp-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.account-proxy-row .btn, .account-fp-row .btn { padding: 2px 9px; font-size: 11px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #566076; }
.dot.on { background: var(--green); box-shadow: 0 0 10px rgba(53, 211, 154, .6); }

.account-rows { display: flex; flex-direction: column; gap: 7px; font-size: 12px; color: var(--muted); }
.account-rows b { color: var(--text); font-weight: 500; }
.canvas-url { word-break: break-all; color: #93a4c3; }

.quota { height: 6px; border-radius: 999px; background: #222b3b; overflow: hidden; }
.quota > i { display: block; height: 100%; background: linear-gradient(90deg, #5b8cff, #7a5bff); }
.quota.full > i { background: var(--red); }

.account-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.limit-row { display: flex; gap: 8px; align-items: center; }
.limit-row input { width: 74px; padding: 6px 8px; }

/* ---------------- 设置 / 日志 ---------------- */

.settings-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.settings-actions { margin-top: 16px; display: flex; gap: 10px; align-items: center; }

.log-list {
  font-family: "Cascadia Mono", "Consolas", monospace;
  font-size: 12px;
  display: flex; flex-direction: column; gap: 4px;
  max-height: 70vh; overflow: auto;
}
.log-line { color: var(--muted); word-break: break-all; }
.log-line .t { color: #5d687c; margin-right: 8px; }
.log-line.warn { color: var(--amber); }
.log-line.error { color: var(--red); }

/* ---------------- 弹窗 / 提示 ---------------- */

.modal {
  position: fixed; inset: 0; background: rgba(4, 7, 12, .72);
  display: grid; place-items: center; padding: 24px; z-index: 50;
  backdrop-filter: blur(3px);
}
.modal.hidden { display: none; }
.modal-card {
  width: min(760px, 100%); max-height: 82vh; overflow: auto;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 20px;
}
.modal-card h3 { margin: 0 0 12px; font-size: 16px; }
.account-modal-card { width: min(440px, 100%); display: flex; flex-direction: column; gap: 12px; }
.account-modal-card h3 { margin: 0; }
.account-modal-card .hint { margin: 0; }
.modal-card pre {
  white-space: pre-wrap; word-break: break-word; background: var(--bg-soft);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  font-size: 12px; line-height: 1.65; color: #c9d3e4; max-height: 44vh; overflow: auto;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.play-card {
  width: min(960px, 94vw);
  max-height: 94vh;
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.play-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.play-head h3 { margin: 0; font-size: 16px; }
#play-video { width: 100%; max-height: 72vh; border-radius: 12px; background: #000; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
  background: #1f2940; border: 1px solid #33415a; color: #e8edf7;
  padding: 10px 18px; border-radius: 999px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: .2s ease; z-index: 60;
  max-width: 70vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(255, 98, 125, .5); color: #ffd3db; }

.hidden { display: none !important; }

/* ---------------- 登录 ---------------- */

.login-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 30% 18%, rgba(91, 140, 255, .14), transparent 42%),
    radial-gradient(circle at 75% 85%, rgba(139, 91, 255, .1), transparent 40%),
    var(--bg);
  z-index: 100;
}

.login-card {
  width: min(390px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
}

.login-card .brand-mark { width: 46px; height: 46px; border-radius: 14px; font-size: 17px; }
.login-card h1 { margin: 0; font-size: 20px; }
.login-card > p { margin: 0; color: var(--muted); font-size: 12px; }
.login-card .btn { width: 100%; }
.login-error { color: var(--red); font-size: 12px; min-height: 16px; }
.login-tip { color: #5d687c; font-size: 11px; line-height: 1.65; }
.login-tip code { color: #8fa7d6; }

/* ---------------- 用户 / 成员 / API ---------------- */

.user-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.user-box b { color: var(--text); font-weight: 600; font-size: 13px; }
.user-box span { margin-left: 6px; color: #5d687c; }

.member-create {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 200px auto;
  gap: 10px;
}

.card-title { margin: 0 0 10px; font-size: 15px; }

.key-line { display: flex; align-items: center; gap: 10px; }
.key-line code {
  flex: 1;
  min-width: 0;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  color: #a9c1f5;
  word-break: break-all;
}

.key-box {
  margin-top: 12px;
  padding: 12px;
  border-radius: 10px;
  border: 1px dashed rgba(91, 140, 255, .5);
  background: rgba(91, 140, 255, .06);
  font-size: 12px;
  color: var(--muted);
}
.key-box code { display: block; margin-top: 6px; color: #cfe0ff; font-size: 13px; word-break: break-all; }

.code-block {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  font-size: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  color: #c9d3e4;
  margin: 0;
}

/* ---------------- 内嵌画面 ---------------- */

.screen-modal { padding: 16px; }

.screen-card {
  width: min(1180px, 97vw);
  max-height: 95vh;
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, .55);
}

.screen-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.screen-head h3 { margin: 0; font-size: 16px; }
.screen-head p { margin: 5px 0 0; }
.screen-head-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.screen-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.screen-zoom { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.screen-zoom .btn { padding: 4px 9px; }
#screen-zoom-label { min-width: 42px; text-align: center; color: var(--text); }

.screen-body {
  position: relative;
  background: #06080c;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: auto;
  max-height: calc(96vh - 300px);
  min-height: 240px;
}

#screen-img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(96vh - 300px);
  margin: 0 auto;
  cursor: crosshair;
  outline: none;
}

.click-ripple {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(91, 140, 255, .95);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: click-ripple .38s ease-out forwards;
}
@keyframes click-ripple {
  from { opacity: 1; transform: translate(-50%, -50%) scale(.6); }
  to { opacity: 0; transform: translate(-50%, -50%) scale(2.2); }
}

.screen-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(8, 11, 16, .86);
  color: var(--muted);
  font-size: 13px;
}

.screen-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: 8px;
}

@media (max-width: 700px) {
  .screen-controls { grid-template-columns: 1fr; }
}

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

@media (max-width: 1080px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; gap: 14px; padding: 14px 16px; overflow-x: auto; }
  .sidebar nav { flex-direction: row; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; }
  .queue-state { display: none; }
  main { padding: 18px; }
  .composer-grid, .settings-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  .composer-grid, .settings-grid { grid-template-columns: 1fr; }
  .brand p { display: none; }
}
