:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --ink: #1b2233;
  --muted: #6b7280;
  --line: #e6e8ef;
  --brand: #3b5bdb;
  --brand-ink: #ffffff;
  --ok: #0f9d58;
  --warn: #d97706;
  --bad: #d64545;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

a { color: var(--brand); text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; }

/* ---------- 布局 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 18px;
  padding: 12px 24px;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: .5px; }
.brand span { color: var(--brand); }
.nav { display: flex; gap: 6px; flex: 1; }
.nav button {
  border: 0; background: transparent; color: var(--muted);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.nav button:hover { background: #eef1f8; color: var(--ink); }
.nav button.active { background: #e6ecff; color: var(--brand); font-weight: 600; }
.userbox { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.credits {
  background: #fff7e6; color: #8a5a00; border: 1px solid #ffe1b3;
  padding: 4px 10px; border-radius: 999px; font-weight: 600;
}

main { max-width: 1120px; margin: 0 auto; padding: 24px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.page-head h1 { font-size: 22px; margin: 0 0 4px; }
.page-head p { margin: 0; color: var(--muted); font-size: 13px; }

/* ---------- 卡片 ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 6px; font-size: 16px; }
.card .meta { color: var(--muted); font-size: 13px; }
.card-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

.empty {
  text-align: center; color: var(--muted); padding: 48px 24px;
  border: 1px dashed var(--line); border-radius: var(--radius); background: #fff;
}

/* ---------- 按钮 / 表单 ---------- */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 9px; cursor: pointer; font-size: 14px;
  transition: .15s ease;
}
button:hover { border-color: #c9cee0; background: #fafbff; }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
button.primary:hover { filter: brightness(1.05); background: var(--brand); }
button.danger { color: var(--bad); border-color: #f0c9c9; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.small { padding: 4px 9px; font-size: 12px; border-radius: 7px; }

label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px;
  font: inherit; background: #fff; color: var(--ink); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px #e6ecff; }
textarea { resize: vertical; min-height: 88px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 4px; }

/* ---------- 状态 ---------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: #eef1f8; color: var(--muted);
}
.badge.queued { background: #fff4e0; color: #9a5b00; }
.badge.running { background: #e6ecff; color: var(--brand); }
.badge.succeeded { background: #e5f7ed; color: var(--ok); }
.badge.failed { background: #fdeaea; color: var(--bad); }
.badge.cancelled { background: #eee; color: #666; }

.progress { height: 8px; background: #eef1f8; border-radius: 999px; overflow: hidden; margin: 10px 0 6px; }
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: 999px; transition: width .4s ease; }
.progress-text { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }

/* ---------- 任务详情 ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.summary-strip { display: flex; gap: 24px; flex-wrap: wrap; margin-top: 12px; }
.summary-strip div { font-size: 13px; color: var(--muted); }
.summary-strip strong { display: block; font-size: 18px; color: var(--ink); }

.section { margin-top: 22px; }
.section h2 { font-size: 16px; margin: 0 0 10px; }

details.ep {
  border: 1px solid var(--line); border-radius: 10px; background: #fff; margin-bottom: 10px;
  padding: 0 14px;
}
details.ep summary {
  cursor: pointer; padding: 12px 0; font-weight: 600; list-style: none;
  display: flex; justify-content: space-between; gap: 10px;
}
details.ep[open] summary { border-bottom: 1px solid var(--line); }
.script-body { padding: 12px 0 16px; font-size: 14px; }
.script-block { margin-bottom: 12px; }
.script-block b { color: var(--brand); }
.dialogue { padding: 4px 0; }
.dialogue em { font-style: normal; color: var(--muted); font-size: 12px; margin-left: 6px; }

/* ---------- 表格 ---------- */
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; font-size: 13px; border-bottom: 1px solid var(--line); }
th { background: #f8f9fc; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }

/* ---------- 弹窗 ---------- */
#modal-root {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .45);
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 40;
}
.modal {
  background: #fff; border-radius: 14px; width: min(720px, 100%);
  max-height: 88vh; overflow: auto; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- 登录 ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: min(400px, 100%); background: #fff; border: 1px solid var(--line);
  border-radius: 16px; padding: 28px; box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.tabs { display: flex; gap: 6px; margin-bottom: 6px; }
.tabs button { flex: 1; }
.tabs button.active { background: #e6ecff; color: var(--brand); border-color: #d5ddf7; font-weight: 600; }
.auth-card .primary { width: 100%; margin-top: 18px; padding: 10px; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; right: 20px; bottom: 20px; z-index: 60; display: grid; gap: 8px; }
.toast {
  background: #1b2233; color: #fff; padding: 10px 14px; border-radius: 9px; font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,.2); animation: in .2s ease;
}
.toast.error { background: var(--bad); }
@keyframes in { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; padding: 10px 14px; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  main { padding: 16px; }
  .row { grid-template-columns: 1fr; }
}
