:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --border: #e4e7ec;
  --text: #1f2430;
  --muted: #6b7280;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --green: #16a34a;
  --green-bg: #ecfdf3;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --amber: #d97706;
  --amber-bg: #fffbeb;
  --blue: #2563eb;
  --blue-bg: #eff6ff;
  --radius: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* 登录 */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 360px; max-width: 100%; padding: 28px; }
.brand { margin: 0; font-size: 22px; font-weight: 700; color: var(--primary); }
.sub { margin: 4px 0 20px; color: var(--muted); }

/* 卡片 */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.container { max-width: 1100px; margin: 0 auto; padding: 20px 16px 40px; }

/* 顶栏 */
.topbar { display: flex; align-items: center; gap: 20px; padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.topbar .brand { font-size: 18px; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav button { border: none; background: transparent; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-size: 14px; }
.nav button:hover { background: #f1f2f4; color: var(--text); }
.nav button.active { background: #eef0ff; color: var(--primary); font-weight: 600; }
.right { display: flex; align-items: center; gap: 10px; }
.who { color: var(--muted); font-size: 13px; }

/* 表单 */
label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
label input, label select, label textarea {
  display: block; width: 100%; margin-top: 6px; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px; color: var(--text);
  background: #fff; font-family: inherit;
}
label input:focus, label select:focus, label textarea:focus { outline: 2px solid #c7d2fe; border-color: var(--primary); }
textarea { resize: vertical; min-height: 70px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }
.check { display: flex; align-items: center; justify-content: flex-start; gap: 8px; font-size: 13px; color: var(--text); margin: 10px 0; white-space: nowrap; }
.readonly { margin-top: 6px; padding: 9px 11px; background: #f8f9fb; border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-weight: 600; }
.hint-inline { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 8px; }
.cost-line { margin: 14px 0; padding: 10px 12px; background: var(--blue-bg); border-radius: 8px; color: var(--text); font-size: 13px; }
.cost-line b { color: var(--primary); }

.btn { border: 1px solid var(--border); background: #fff; color: var(--text); padding: 9px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.btn:hover { background: #f8f9fb; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: #f1f2f4; color: var(--text); }
.btn.danger { color: var(--red); border-color: #fecaca; }
.btn.danger:hover { background: var(--red-bg); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; margin-top: 4px; }
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; line-height: 1.4; }
a.btn:hover { text-decoration: none; }

/* 面板 */
.panel { margin-top: 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 16px; }
.panel-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.panel-actions .sep { width: 1px; height: 18px; background: var(--border); }
.section-title { margin: 18px 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.panel-sub { margin-top: 4px; font-size: 12px; color: var(--muted); }

/* 积分消耗规则：按地区分区 */
#configs-regions { display: flex; flex-direction: column; gap: 14px; }
.region-block { overflow: hidden; }
.region-block-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; background: #fafbfc; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.region-block-title { display: flex; align-items: center; gap: 10px; }
.region-block-title .muted { font-size: 12px; }
.region-block-actions { display: flex; align-items: center; gap: 8px; }
.region-block table { border-radius: 0; }
.subtabs { display: flex; gap: 6px; margin: 2px 0 12px; flex-wrap: wrap; }
.subtab { border: 1px solid var(--border); background: #fff; color: var(--muted); padding: 7px 14px; border-radius: 999px; font: inherit; font-size: 13px; cursor: pointer; }
.subtab:hover { background: #f8f9fb; color: var(--text); }
.subtab.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.subtab .count { opacity: .75; }

/* 统计卡片 */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-top: 8px; }
.stat { padding: 16px; }
.stat .num { font-size: 26px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.stat .num.small { font-size: 18px; }

/* 仪表盘：今日消耗积分 feature 卡片 */
.dash-feature {
  display: flex; align-items: center; gap: 20px;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  color: #fff; border-radius: 14px; padding: 26px 28px;
  box-shadow: 0 10px 30px rgba(79, 70, 229, .28);
  margin: 8px 0 18px;
}
.dash-feature-icon {
  width: 62px; height: 62px; border-radius: 16px; flex: none;
  background: rgba(255, 255, 255, .16);
  display: flex; align-items: center; justify-content: center;
  font-size: 30px;
}
.dash-feature-label { font-size: 13px; opacity: .88; letter-spacing: .3px; }
.dash-feature-num { font-size: 46px; font-weight: 800; line-height: 1.05; margin-top: 2px; font-variant-numeric: tabular-nums; }
.dash-feature-sub { font-size: 13px; opacity: .72; margin-top: 6px; }

/* 仪表盘：带图标的统计卡片 */
.dash-stat { display: flex; align-items: center; gap: 14px; transition: transform .12s ease, box-shadow .12s ease; }
.dash-stat:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(16, 24, 40, .08); }
.dash-stat-icon {
  width: 46px; height: 46px; border-radius: 13px; flex: none;
  background: var(--bg); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
}
.dash-stat-body { min-width: 0; }

/* 表格 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: #fafbfc; color: var(--muted); font-weight: 600; font-size: 12px; }
th.chk, td.chk { width: 40px; }
th.chk input, td.chk input { cursor: pointer; }
tbody tr:hover { background: #fafbfc; }
td.prompt { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
td.trunc { max-width: 170px; overflow: hidden; text-overflow: ellipsis; }
.clip { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clip.account { max-width: 130px; }
.records-table td.prompt { max-width: 150px; }
td.ops .btn + .btn { margin-left: 6px; }

/* 管理端筛选与分页 */
.filter-input { padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; color: var(--text); background: #fff; font-family: inherit; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 12px; }
.pager .muted { font-size: 12px; }

/* 徽章 */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.succeeded { background: var(--green-bg); color: var(--green); }
.badge.failed { background: var(--red-bg); color: var(--red); }
.badge.pending, .badge.queued { background: var(--amber-bg); color: var(--amber); }
.badge.submitting, .badge.generating { background: var(--blue-bg); color: var(--blue); }
.badge.cancelled { background: #f3f4f6; color: var(--muted); }
.badge.active { background: var(--green-bg); color: var(--green); }
.badge.disabled, .badge.expired, .badge.banned { background: #f3f4f6; color: var(--muted); }
.badge.admin { background: #fdf2f8; color: #db2777; }
.badge.user { background: var(--blue-bg); color: var(--blue); }
.badge.gift { background: #f5f3ff; color: #7c3aed; }
.badge.normal { background: var(--blue-bg); color: var(--blue); }
.badge.region { background: var(--blue-bg); color: var(--blue); }
.badge.api { background: #eef2ff; color: #4f46e5; }

/* 账号三态圆点：绿=就绪，黄=缺 session 或未更新，灰=未就绪，红=停用/封禁 */
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; vertical-align: middle; }
.dot.green { background: #22c55e; }
.dot.yellow { background: #f59e0b; }
.dot.gray { background: #cbd5e1; }
.dot.red { background: #ef4444; }
.dot.blue { background: #3b82f6; }
.status-hint { color: var(--muted); cursor: help; font-style: normal; margin-left: 3px; }
.acct-name { color: var(--primary); cursor: pointer; text-decoration: none; }
.acct-name:hover { text-decoration: underline; }
a.link { color: var(--primary); text-decoration: none; margin-left: 8px; }
a.link:hover { text-decoration: underline; }
button.link { background: none; border: none; padding: 0; margin: 0; color: var(--primary); font: inherit; cursor: pointer; }
button.link:hover { text-decoration: underline; }
button.task-id { background: none; border: none; padding: 0; margin: 0; cursor: pointer; font: inherit; color: var(--primary); text-align: left; }
button.task-id:hover code { text-decoration: underline; }

/* 区块标题 + 操作按钮行 */
.section-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; margin-bottom: 8px; }
.section-row .section-title { margin: 0; }

/* 错误 / 空 */
.error { color: var(--red); font-size: 13px; }
.empty { color: var(--muted); padding: 24px; text-align: center; }
.hint { color: var(--muted); font-size: 12px; margin-top: 16px; text-align: center; }

/* 模态框 */
.modal { position: fixed; inset: 0; background: rgba(16,24,40,.4); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal-card { width: 520px; max-width: 100%; padding: 22px; max-height: 90vh; overflow-y: auto; position: relative; }
.modal-card.wide { width: 900px; }
.modal-card h3 { margin: 0 0 16px; padding-right: 24px; }
.modal-close { position: absolute; top: 14px; right: 16px; background: none; border: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0; }
.modal-close:hover { color: var(--text); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }

/* toast */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 100; box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }

/* 上传预览 & 任务详情 */
.muted { color: var(--muted); }
.preview { margin: 0 0 14px; display: flex; flex-wrap: wrap; gap: 10px; }
.preview img { max-width: 240px; max-height: 240px; border: 1px solid var(--border); border-radius: 8px; display: block; }
.preview-img { width: 96px; height: 96px; object-fit: cover; border: 1px solid var(--border); border-radius: 8px; }
.preview-item { position: relative; width: 96px; }
.preview-del { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; line-height: 16px; text-align: center; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; border: none; cursor: pointer; font-size: 13px; padding: 0; z-index: 2; }
.preview-name { font-size: 11px; color: var(--muted); margin-top: 4px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 素材库 */
.asset-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.asset-item { position: relative; width: 72px; height: 72px; border: 2px solid var(--border); border-radius: 8px; overflow: hidden; cursor: pointer; }
.asset-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.asset-item.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79, 70, 229, .35);
}
.asset-item.selected::after {
  content: '✓';
  position: absolute; right: 3px; bottom: 3px;
  width: 22px; height: 22px; line-height: 22px; text-align: center;
  background: var(--primary); color: #fff;
  border-radius: 50%; font-size: 14px; font-weight: 700;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}
.asset-del { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; line-height: 16px; text-align: center; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; border: none; cursor: pointer; font-size: 13px; padding: 0; }
.asset-play { position: absolute; top: 2px; left: 2px; width: 20px; height: 18px; line-height: 16px; text-align: center; border-radius: 4px; background: rgba(0,0,0,.55); color: #fff; border: none; cursor: pointer; font-size: 11px; padding: 0; }
.asset-media { display: flex; align-items: center; justify-content: center; background: var(--bg); }
.asset-icon { font-size: 26px; color: var(--muted); }
.upload-row { display: inline-block; margin-bottom: 8px; }
.upload-row input[type=file] { display: block; margin-top: 4px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px 16px; margin-bottom: 14px; }
.detail-block { margin-bottom: 12px; }
.detail-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.detail-prompt { white-space: pre-wrap; }
.detail-img { max-width: 100%; max-height: 320px; border-radius: 8px; border: 1px solid var(--border); display: block; }
.detail-video { max-width: 100%; max-height: 360px; border-radius: 8px; display: block; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.result-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

/* 提交页内联「生成结果」 */
.results { display: flex; flex-direction: column; gap: 12px; }
.result-card { padding: 14px 16px; }
.result-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.result-prompt { margin-bottom: 10px; white-space: pre-wrap; word-break: break-word; }
.result-video { max-width: 100%; max-height: 400px; border-radius: 8px; display: block; background: #000; }
.result-wait { padding: 22px 0; text-align: center; color: var(--muted); }
.result-error { color: var(--red); font-size: 13px; padding: 8px 0; }

/* API 接入 */
.api-key-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.api-key { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; background: var(--bg); border: 1px solid var(--border); padding: 8px 12px; border-radius: 8px; word-break: break-all; color: var(--text); }
.api-doc { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; line-height: 1.6; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; overflow-x: auto; white-space: pre; margin: 0; color: var(--text); }

@media (max-width: 640px) {
  .row > * { min-width: 100%; }
  .topbar { gap: 10px; }
}

/* ── 提交页美化 ── */
.submit-panel { max-width: 760px; margin: 0 auto; }
.submit-card { padding: 32px 28px; border-radius: 16px; box-shadow: 0 4px 24px rgba(16,24,40,.06); }
.submit-title { text-align: center; font-size: 24px; font-weight: 700; margin: 0 0 6px; }
.submit-sub { text-align: center; color: var(--muted); font-size: 14px; margin: 0 0 26px; }
.prompt-input { width: 100%; min-height: 120px; border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; font-size: 15px; font-family: inherit; line-height: 1.6; resize: vertical; background: var(--card); }
.prompt-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.12); }
.ref-header { font-size: 13px; font-weight: 600; color: var(--text); margin: 18px 0 8px; }
.ref-header .sub { font-weight: 400; color: var(--muted); }
.param-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 14px; }
.param-row label { margin: 0; }
.param-row select { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--card); font-size: 14px; }
.param-row .readonly { padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); font-size: 14px; }
.generate-btn { display: block; width: 100%; padding: 14px; font-size: 16px; font-weight: 600; border-radius: 12px; background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; border: none; cursor: pointer; margin-top: 20px; transition: opacity .15s; }
.generate-btn:hover { opacity: .9; }
.generate-btn:disabled { opacity: .5; cursor: not-allowed; }
.upload-row { display: inline-block; margin-bottom: 8px; }
.upload-row input[type=file] { display: block; margin-top: 4px; font-size: 13px; }
.cost-line { margin-top: 14px; font-size: 14px; color: var(--muted); }
.cost-line b { color: var(--text); }

/* 上传拖拽区 */
.drop-zone { border: 2px dashed #d5d9e2; border-radius: 14px; padding: 26px 16px; text-align: center; cursor: pointer; transition: all .18s; background: #fafbfc; margin: 4px 0 10px; }
.drop-zone:hover { border-color: var(--primary); background: rgba(99,102,241,.05); }
.drop-zone.dragover { border-color: var(--primary); background: rgba(99,102,241,.1); }
.drop-icon { font-size: 30px; line-height: 1; }
.drop-text { font-size: 14px; color: var(--text); margin-top: 8px; font-weight: 500; }
.drop-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.drop-zone-sm { padding: 14px 16px; }
.drop-zone-sm .drop-text { margin-top: 0; }
.ref-tip { font-size: 12px; color: var(--amber); background: var(--amber-bg); border: 1px solid #fde68a; border-radius: 8px; padding: 8px 10px; margin: 0 0 8px; line-height: 1.5; }
/* @ 引用素材下拉 */
.at-mention { position: relative; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(16,24,40,.12); margin-top: -8px; z-index: 30; max-height: 260px; overflow: auto; }
.at-item { padding: 8px 12px; cursor: pointer; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.at-item:hover { background: #f5f6f9; }
/* 素材库页面卡片 */
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.lib-card { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: #fff; display: flex; flex-direction: column; }
.lib-thumb { height: 120px; background: #f5f6f9; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.lib-thumb img { width: 100%; height: 100%; object-fit: cover; }
.lib-thumb-media span { font-size: 34px; }
.lib-info { padding: 10px 12px 6px; }
.lib-title { font-weight: 600; font-size: 14px; cursor: pointer; }
.lib-title:hover { color: var(--primary); text-decoration: underline; }
.lib-meta { font-size: 12px; margin-top: 2px; }
.lib-actions { padding: 4px 12px 12px; display: flex; gap: 6px; }
/* 角色资产卡片 */
.char-card { border: 1px solid var(--border); border-radius: 12px; background: #fff; padding: 12px; margin-bottom: 12px; }
.char-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.char-name { font-weight: 600; font-size: 15px; cursor: pointer; }
.char-name:hover { color: var(--primary); }
.char-assets { display: flex; flex-wrap: wrap; gap: 8px; }
.char-asset { position: relative; width: 72px; height: 72px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.char-asset-thumb { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; overflow: hidden; background: #f5f6f9; }
.char-asset-thumb img { width: 100%; height: 100%; object-fit: cover; }
.char-asset-media span { font-size: 22px; }
.char-asset-del { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; line-height: 16px; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; border: none; font-size: 12px; cursor: pointer; padding: 0; }
.char-asset-del:hover { background: var(--red); }
.char-actions { margin-top: 10px; display: flex; gap: 8px; }

/* 顶部闹铃图标（低积分提醒） */
.bell-btn { position: relative; background: none; border: none; font-size: 20px; cursor: pointer; margin-right: 14px; line-height: 1; }
.bell-badge { position: absolute; top: -4px; right: -8px; background: var(--red); color: #fff; border-radius: 10px; font-size: 11px; min-width: 16px; height: 16px; line-height: 16px; padding: 0 4px; text-align: center; font-weight: 700; }
