:root {
  --bg: #0f172a;
  --bg-soft: #16203a;
  --card: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --input-bg: #0f172a;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}
[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-soft: #e8eef6;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --input-bg: #ffffff;
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- 生成模式选择（全自动 / 中途人工确认） ---------- */
.flow-opt {
  padding: 12px 14px; border: 1.5px solid var(--border); border-radius: 10px;
  background: var(--card); transition: border-color .15s, background .15s;
}
.flow-opt:hover { border-color: var(--accent); }
.flow-opt-active { border-color: var(--accent); background: var(--accent-soft); }
.flow-radio {
  display: inline-block; width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid var(--border); position: relative; flex-shrink: 0;
}
.flow-radio-on { border-color: var(--accent); }
.flow-radio-on::after {
  content: ""; position: absolute; inset: 2px; border-radius: 50%; background: var(--accent);
}
.flow-opt strong { color: var(--text); }

/* ---------- 导航 ---------- */
.nav {
  position: sticky; top: 0; z-index: 100;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  max-width: 1100px; margin: 0 auto; padding: 0 20px;
  height: 56px; display: flex; align-items: center; gap: 24px;
}
.brand { font-size: 17px; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.nav-links { display: flex; gap: 4px; flex: 1; }
.nav-links a {
  padding: 6px 14px; border-radius: 8px; color: var(--muted); font-size: 14px;
}
.nav-links a:hover { color: var(--text); text-decoration: none; background: var(--accent-soft); }
.nav-links a.active { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.nav-right { display: flex; align-items: center; gap: 8px; }
.nav-user { color: var(--muted); font-size: 13px; }

/* ---------- 布局 ---------- */
.container { max-width: 1280px; margin: 0 auto; padding: 24px 20px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.page-title { font-size: 20px; font-weight: 700; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; }

/* 统计卡片 */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .num { font-size: 26px; font-weight: 700; color: var(--accent); }
.stat .label { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--card); color: var(--text); cursor: pointer; font-size: 14px;
  transition: all .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { opacity: .9; color: #fff; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }
.btn-warning { color: var(--warning); }
.btn-warning:hover { border-color: var(--warning); color: var(--warning); background: rgba(245, 158, 11, .1); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--accent-soft); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
/* 任务列表操作栏：横向排列、不换行，紧凑但其内按钮保持可点击热区 */
.ops-cell { display: inline-flex; align-items: center; gap: 6px; flex-wrap: nowrap; white-space: nowrap; }
.ops-cell .btn { padding: 4px 9px; font-size: 12px; }
.ops-cell .btn + .btn { margin-left: 0; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- 分页 ---------- */
.pagination { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.pagination .pg-info, .pagination .pg-page { font-size: 13px; color: var(--muted); white-space: nowrap; }
/* 覆盖基础 select（width:100% + 大 padding），让「条/页」选择框保持紧凑、随内容自适应宽度 */
.pagination select.pg-size {
  width: auto; margin: 0; padding: 5px 8px; font-size: 12px;
  flex: 0 0 auto; min-height: 0; height: auto;
}

/* ---------- 表单 ---------- */
input, textarea, select {
  width: 100%; padding: 9px 12px; margin-bottom: 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--input-bg); color: var(--text); font-size: 14px; font-family: inherit;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 90px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.form-row { display: flex; gap: 12px; }
.form-row > div { flex: 1; }
.hint { font-size: 12px; color: var(--muted); margin-top: -6px; margin-bottom: 10px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
/* v4.6.3 定宽列布局：让"创作需求"等长文本列按份额分配并截断省略，避免横向滚动条 */
table.fixed-tbl { table-layout: fixed; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
tr:hover td { background: var(--accent-soft); }
.brief-cell { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 徽章 ---------- */
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.st-pending { background: rgba(245, 158, 11, .15); color: var(--warning); }
.st-warning { background: rgba(245, 158, 11, .15); color: var(--warning); }
.st-running { background: rgba(59, 130, 246, .15); color: var(--accent); }
.st-success { background: rgba(34, 197, 94, .15); color: var(--success); }
.st-stage-done { background: rgba(34, 197, 94, .12); color: var(--success); box-shadow: inset 0 0 0 1px rgba(34, 197, 94, .45); }
.st-failed { background: rgba(239, 68, 68, .15); color: var(--danger); }
.st-cancelled { background: rgba(148, 163, 184, .15); color: var(--muted); }
.st-novel { background: rgba(168, 85, 247, .15); color: #a855f7; }

/* ---------- 进度条 ---------- */
.progress { height: 8px; background: var(--bg-soft); border-radius: 6px; overflow: hidden; min-width: 100px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 6px; transition: width .4s; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 200;
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal-mask.show { display: flex; }
.modal {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
  padding: 24px; box-shadow: var(--shadow);
}
.modal-lg { max-width: 640px; }
.step-back { font-size: 13px; color: var(--muted); cursor: pointer; margin-bottom: 10px; user-select: none; }
.step-back:hover { color: var(--accent); }

/* ---------- 小说改剧：上传/拆解卡片 ---------- */
.novel-card {
  border: 1px solid var(--border); border-radius: 10px; padding: 14px;
  background: var(--bg-soft); margin-top: 12px;
}
.novel-title { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.novel-meta { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.novel-notice {
  font-size: 13px; color: var(--warning); background: color-mix(in srgb, var(--warning) 12%, transparent);
  border-radius: 8px; padding: 8px 10px; line-height: 1.5;
}
.novel-notice-ok {
  color: var(--success); background: color-mix(in srgb, var(--success) 12%, transparent);
}
.novel-result-title { font-size: 15px; font-weight: 700; margin-bottom: 8px; }
.novel-result-line { font-size: 13px; line-height: 1.7; margin-bottom: 4px; }
.novel-result-line b { color: var(--text); }
.chapter-preview {
  margin-top: 10px; max-height: 140px; overflow-y: auto; border-top: 1px dashed var(--border);
  padding-top: 8px; font-size: 12px; color: var(--muted); line-height: 1.8;
}
.chapter-preview .ch { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.novel-reupload { font-size: 12px; color: var(--accent); cursor: pointer; margin-left: 8px; }
.novel-reupload:hover { text-decoration: underline; }

/* ---------- 小说改剧：拆解进度/结果美化（v4.0.1） ---------- */
.decompose-stage {
  display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600;
  margin-bottom: 8px; color: var(--text);
}
.decompose-stage .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  animation: dcm-pulse 1.2s infinite;
}
@keyframes dcm-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.novel-hero {
  border-radius: 12px; padding: 14px 16px; margin-bottom: 10px;
  background: linear-gradient(135deg, rgba(168, 85, 247, .16), rgba(59, 130, 246, .10));
  border: 1px solid rgba(168, 85, 247, .30);
}
.novel-hero .nh-title { font-size: 17px; font-weight: 800; color: #a855f7; line-height: 1.4; }
.novel-hero .nh-line { font-size: 13px; line-height: 1.7; margin-top: 4px; color: var(--text); }
.novel-hero .nh-line b { color: var(--muted); font-weight: 600; }
.novel-hero .nh-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.novel-hero .nh-tag {
  font-size: 12px; padding: 2px 9px; border-radius: 20px;
  background: rgba(168, 85, 247, .12); color: #a855f7; border: 1px solid rgba(168, 85, 247, .28);
}
.novel-sec { margin-top: 10px; }
.novel-sec-title {
  font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px;
  display: flex; align-items: center; gap: 6px;
}
.novel-sec-title::before { content: ""; width: 3px; height: 12px; border-radius: 2px; background: var(--accent); }
.novel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.novel-char {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  background: var(--card); font-size: 12px; line-height: 1.6;
}
.novel-char b { color: #a855f7; }
.novel-char .nc-sub { color: var(--muted); }
.novel-arc { display: flex; gap: 8px; font-size: 12px; line-height: 1.6; margin-bottom: 4px; }
.novel-arc .arc-range { flex: none; color: #a855f7; font-weight: 700; min-width: 52px; }
.novel-arc .arc-phase { color: var(--text); font-weight: 600; }
.novel-arc .arc-sum { color: var(--muted); }
.novel-plan {
  border: 1px solid rgba(34, 197, 94, .35); border-radius: 8px; padding: 8px 10px;
  font-size: 12px; line-height: 1.7; margin-bottom: 6px; color: var(--text);
  background: color-mix(in srgb, var(--success) 6%, transparent);
}
.novel-plan b { color: var(--success); }
.novel-chapters-toggle { font-size: 12px; color: var(--accent); cursor: pointer; margin-top: 6px; user-select: none; }
.novel-chapters-toggle:hover { text-decoration: underline; }
.novel-chapters-list {
  display: none; margin-top: 6px; max-height: 190px; overflow-y: auto;
  border-top: 1px dashed var(--border); padding-top: 6px;
  font-size: 12px; color: var(--muted); line-height: 1.8;
}
.novel-chapters-list .nch { margin-bottom: 2px; }
.novel-chapters-list .nch .kps { color: var(--warning); }
.novel-summary-line { font-size: 13px; line-height: 1.8; color: var(--muted); }
.novel-summary-line b { color: var(--text); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-title { font-size: 17px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 22px; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ---------- 空状态 ---------- */
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.empty .icon { font-size: 36px; margin-bottom: 8px; }

/* ---------- 标签页 ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab {
  padding: 8px 16px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent;
  font-size: 14px; user-select: none;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------- 阶段列表 ---------- */
.stage-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px;
}
.stage-item .code { font-weight: 700; width: 42px; color: var(--accent);
  word-break: break-word; overflow-wrap: anywhere; line-height: 1.3; }
.stage-item .info { flex: 1; min-width: 0; }
.stage-item .info .name { font-weight: 600; }
.stage-item .info .meta { color: var(--muted); font-size: 12px;
  word-break: break-word; overflow-wrap: anywhere; }

/* ---------- 产物卡片 ---------- */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.product-card {
  border: 1px solid var(--border); border-radius: 10px; padding: 14px; cursor: pointer;
  transition: all .15s; background: var(--card);
}
.product-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.product-card .p-name { font-weight: 600; margin-bottom: 4px; }
.product-card .p-meta { color: var(--muted); font-size: 12px; }
.product-card .p-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.product-card .cover-ops {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.product-card .cover-ops .cover-ops-label {
  flex-basis: 100%; font-size: 12px; color: var(--muted); font-weight: 500;
}
.product-card .cover-ops .btn { flex: 1 1 auto; white-space: nowrap; }
.product-card .regen-status {
  margin-top: 8px; padding: 4px 8px; border-radius: 6px; font-size: 12px;
  background: var(--accent-soft, rgba(0,122,255,.1)); color: var(--accent);
  display: inline-block; max-width: 100%;
}

/* ---------- 内容查看 ---------- */
.content-view {
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px;
  padding: 18px; white-space: pre-wrap; word-break: break-word;
  font-size: 13px; max-height: 60vh; overflow-y: auto; font-family: inherit;
}
.content-view:not(.content-html) { white-space: pre-wrap; }
.content-html { white-space: normal; }

/* ---------- 阶段/成果 JSON 美化渲染（production-format.js） ---------- */
.pf-hero { border-left: 4px solid var(--primary, #5b6cff); padding: 6px 0 12px 12px; margin-bottom: 12px; }
.pf-title { font-size: 20px; font-weight: 700; margin-bottom: 8px; color: var(--text); }
.pf-logline { font-size: 14px; color: var(--muted); line-height: 1.6; margin-bottom: 8px; }
.pf-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.pf-tag { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 3px 10px; font-size: 12px; }
.pf-sec-title { font-size: 15px; font-weight: 700; margin: 18px 0 10px; padding-left: 10px; border-left: 4px solid var(--primary, #5b6cff); }
.pf-card { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; background: var(--card); overflow: hidden; }
.pf-card-h { background: var(--accent-soft); color: var(--text); font-weight: 700; font-size: 13px; padding: 8px 12px; }
.pf-row { display: flex; gap: 10px; padding: 6px 12px; border-top: 1px dashed var(--border); font-size: 13px; }
.pf-row:first-of-type { border-top: none; }
.pf-key { flex: 0 0 84px; color: var(--muted); font-weight: 600; }
.pf-val { flex: 1; color: var(--text); line-height: 1.6; white-space: pre-wrap; }
.pf-val.pf-full { flex: 1; }
.pf-callout { background: color-mix(in srgb, var(--warning) 12%, transparent); border: 1px solid var(--warning); border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; font-size: 13px; color: var(--warning); font-weight: 600; }
.pf-warn { border-color: var(--danger); }
.pf-warn .pf-card-h { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.pf-score .pf-card-h { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.pf-verdict { color: var(--success); font-weight: 700; }
.pf-dim { display: flex; gap: 10px; padding: 7px 12px; font-size: 13px; }
.pf-dim .pf-key { flex: 0 0 auto; }
.pf-pre { white-space: pre-wrap; word-break: break-word; }
/* 分集大纲 */
.pf-eps { display: flex; flex-direction: column; gap: 8px; }
.pf-ep { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--card); }
.pf-ep-h { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 5px; }
.pf-ep-no { font-weight: 700; color: var(--primary, #5b6cff); font-size: 13px; }
.pf-ep-title { font-size: 14px; font-weight: 600; color: var(--text); }
.pf-badge { font-size: 11px; padding: 1px 8px; border-radius: 6px; background: var(--bg-soft); color: var(--muted); }
.pf-badge-warn { background: color-mix(in srgb, var(--warning) 15%, transparent); color: var(--warning); }
.pf-ep-sum { font-size: 13px; color: var(--muted); line-height: 1.6; }
.pf-ep-details { margin-top: 6px; border-top: 1px dashed var(--border); padding-top: 6px; }
.pf-detail { font-size: 12px; color: var(--muted); padding: 2px 0; display: flex; gap: 8px; }
.pf-detail-k { flex: 0 0 64px; color: var(--muted); font-weight: 600; }
.pf-detail-v { flex: 1; white-space: pre-wrap; }

/* ---------- 对话 ---------- */
.chat-layout { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; }
.chat-sessions { max-height: calc(100vh - 160px); overflow-y: auto; }
.session-item {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  margin-bottom: 8px; cursor: pointer; transition: all .15s;
}
.session-item:hover { border-color: var(--accent); }
.session-item.active { border-color: var(--accent); background: var(--accent-soft); }
.session-item .s-title { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item .s-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.chat-box { display: flex; flex-direction: column; height: calc(100vh - 200px); min-height: 420px; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 82%; padding: 10px 14px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; font-size: 13px; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--bg-soft); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg .m-time { font-size: 11px; opacity: .7; margin-top: 6px; }
.msg .m-copy { font-size: 11px; opacity: .7; cursor: pointer; margin-top: 4px; display: inline-block; }
.msg .m-copy:hover { opacity: 1; text-decoration: underline; }
.chat-input { display: flex; gap: 10px; padding: 12px; border-top: 1px solid var(--border); }
.chat-input textarea { margin-bottom: 0; min-height: 44px; max-height: 120px; }
.chat-input .btn { align-self: flex-end; }
.typing { color: var(--muted); font-size: 13px; padding: 10px 14px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 20px; border-radius: 8px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 300;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 响应式 ---------- */
@media (max-width: 720px) {
  .chat-layout { grid-template-columns: 1fr; }
  .chat-sessions { max-height: 200px; }
  .chat-box { height: 60vh; }
  .nav-inner { gap: 10px; }
  .nav-user { display: none; }
}
