:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --border: #e4e7ee;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef0ff;
  --success: #059669;
  --success-soft: #e7f7f0;
  --warn: #b45309;
  --warn-soft: #fff4e0;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --info: #2563eb;
  --info-soft: #e8f0fe;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; line-height: 1.35; }
h2 { font-size: 16px; margin: 0 0 12px; }
code { background: #f1f2f6; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.pre { white-space: pre-wrap; word-break: break-word; }

/* ---------- layout ---------- */
.topbar { background: #fff; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1240px; margin: 0 auto; padding: 0 20px; height: 56px; display: flex; align-items: center; gap: 24px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--text); font-size: 15px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-logo { width: 24px; height: 24px; }
.nav { display: flex; align-items: center; gap: 4px; flex: 1; overflow-x: auto; }
.nav a { color: #475066; padding: 6px 12px; border-radius: 8px; white-space: nowrap; }
.nav a:hover { background: #f2f3f7; text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-sep { width: 1px; height: 18px; background: var(--border); margin: 0 6px; }
.userbox { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.userbox a { color: var(--text); }
.role-tag { font-size: 11px; color: var(--primary); background: var(--primary-soft); border-radius: 4px; padding: 1px 6px; margin-left: 6px; }
.inline { display: inline; margin: 0; }
.container { max-width: 1240px; margin: 0 auto; padding: 24px 20px 64px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; }
.page-head .muted { margin: 4px 0 0; }
.back { font-size: 13px; color: var(--muted); display: inline-block; margin-bottom: 4px; }
.back::before { content: "‹ "; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.card.narrow { max-width: 520px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px 16px; align-items: end; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 16px; border-radius: 8px;
  border: 1px solid var(--border); background: #fff; color: var(--text); font-size: 14px; cursor: pointer; white-space: nowrap; font-family: inherit; }
.btn:hover { background: #f6f7fb; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #f3c4c4; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.large { height: 44px; padding: 0 28px; font-size: 15px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.linklike { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font: inherit; }
.linklike.danger { color: var(--danger); }
.userbox .linklike { color: var(--muted); }
input, select, textarea { font: inherit; color: inherit; border: 1px solid #d5d9e2; border-radius: 8px; background: #fff; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, .15); }
textarea { resize: vertical; min-height: 120px; line-height: 1.6; }
select.compact { width: auto; min-width: 140px; height: 34px; padding: 4px 8px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: #4a5162; font-weight: 500; }
.field > input, .field > select, .field > textarea { font-weight: 400; }
.inline-field { flex-direction: row; align-items: center; gap: 10px; }
.inline-field select { width: auto; }
.checkbox-field { flex-direction: row; align-items: center; gap: 8px; height: 38px; }
.checkbox-field input { width: auto; }
.input-with-btn { display: flex; gap: 6px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form.grid-4 { display: grid; }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; grid-column: 1 / -1; }
.error-text { color: var(--danger); font-size: 13px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }
.alert { border-radius: 8px; padding: 10px 12px; margin: 12px 0; font-size: 13.5px; }
.alert.error { background: var(--danger-soft); color: #9b1c1c; }

/* ---------- login ---------- */
.page-login .container { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding-top: 0; }
.login-card { width: 380px; max-width: 100%; background: #fff; border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 10px 30px rgba(30, 41, 80, .08); padding: 32px; }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.login-brand img { width: 32px; height: 32px; }
.login-card .btn.block { margin-top: 6px; height: 42px; }

/* ---------- tabs / task list ---------- */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs { display: inline-flex; background: #eceef4; padding: 3px; border-radius: 10px; gap: 2px; }
.tabs button { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; cursor: pointer; color: #4a5162; font: inherit; }
.tabs button.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.tabs .count { margin-left: 6px; font-size: 12px; color: var(--muted); }
.task-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; }
.task-card { display: flex; flex-direction: column; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); color: var(--text); transition: box-shadow .15s, transform .15s; }
.task-card:hover { text-decoration: none; box-shadow: 0 6px 18px rgba(30, 41, 80, .10); transform: translateY(-1px); }
.task-card .thumb { aspect-ratio: 16 / 10; background: linear-gradient(135deg, #e9ebf5, #f6f7fb); display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
.task-card .thumb img { width: 100%; height: 100%; object-fit: contain; background: #111; }
.task-card .thumb .ph { color: #8a91a6; font-size: 13px; text-align: center; padding: 0 12px; }
.task-card .thumb .ph strong { display: block; font-size: 26px; color: #4a5162; font-weight: 600; }
.task-card .thumb .duration-tag { position: absolute; right: 8px; bottom: 8px; background: rgba(0, 0, 0, .65); color: #fff; font-size: 12px; padding: 1px 6px; border-radius: 4px; }
.task-card .body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.task-card .title-row { display: flex; gap: 6px; align-items: baseline; }
.task-card .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seq { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.task-card .meta { color: var(--muted); font-size: 12.5px; }
.task-card .status-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; min-height: 22px; }
.task-card .stage { color: #4a5162; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-card .foot { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: auto; padding-top: 4px; }
.task-card .owner { color: #4a5162; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.more { text-align: center; margin-top: 18px; }

/* ---------- badges / progress ---------- */
.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.queued { background: #eef0f5; color: #4a5162; }
.badge.assigned, .badge.running { background: var(--info-soft); color: var(--info); }
.badge.succeeded { background: var(--success-soft); color: var(--success); }
.badge.failed { background: var(--danger-soft); color: var(--danger); }
.badge.cancelled { background: #f0f0f2; color: #7b8090; }
.badge.cancelling { background: var(--warn-soft); color: var(--warn); }
.progress { height: 6px; background: #eceef4; border-radius: 999px; overflow: hidden; }
.progress .bar { height: 100%; width: 0; background: var(--primary); border-radius: 999px; transition: width .6s ease; }
.progress.big { height: 10px; margin: 12px 0 10px; }
.progress.active .bar { background-image: linear-gradient(45deg, rgba(255, 255, 255, .25) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .25) 50%, rgba(255, 255, 255, .25) 75%, transparent 75%, transparent);
  background-size: 16px 16px; animation: stripes 1s linear infinite; }
.progress.done .bar { background: var(--success); }
.progress.failed .bar { background: var(--danger); }
@keyframes stripes { from { background-position: 16px 0; } to { background-position: 0 0; } }

/* ---------- new task form ---------- */
.new-task .card h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.step { display: inline-flex; width: 22px; height: 22px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 12px; align-items: center; justify-content: center; }
.mode-picker { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.mode-option { border: 1.5px solid var(--border); border-radius: 10px; padding: 14px 16px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; position: relative; }
.mode-option input { position: absolute; opacity: 0; pointer-events: none; }
.mode-option:hover { border-color: #c7cbe0; }
.mode-option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.mode-option.selected { border-color: var(--primary); background: var(--primary-soft); }
.mode-title { font-weight: 600; font-size: 15px; }
.mode-desc { color: var(--muted); font-size: 12.5px; }
.frame-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.dropzone { border: 1.5px dashed #c9cede; border-radius: 10px; min-height: 200px; display: flex; align-items: stretch; justify-content: center; cursor: pointer; background: #fafbfd; position: relative; overflow: hidden; }
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--primary-soft); }
.dz-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: #4a5162; padding: 20px; text-align: center; width: 100%; }
.dz-empty strong { font-size: 15px; }
.dz-preview { display: flex; flex-direction: column; width: 100%; }
.dz-preview img { width: 100%; height: 260px; object-fit: contain; background: #111; }
.dz-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 10px; font-size: 12px; color: var(--muted); background: #fff; }
.dz-remove { border: 0; background: none; color: var(--danger); cursor: pointer; font: inherit; }
.ref-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.ref-item { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff; display: flex; flex-direction: column; }
.ref-item img { width: 100%; height: 130px; object-fit: contain; background: #111; }
.ref-item .ref-bar { display: flex; justify-content: space-between; align-items: center; padding: 4px 8px; font-size: 12px; gap: 4px; }
.ref-item .ref-tag { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; color: var(--primary); }
.ref-item button { border: 0; background: none; color: var(--danger); cursor: pointer; font-size: 12px; padding: 0; }
.ref-actions { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.audio-box { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.audio-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.audio-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.audio-preview { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.audio-preview audio { height: 36px; max-width: 320px; }
.audio-info { color: var(--muted); font-size: 12.5px; }
.tag-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.tag-buttons button { border: 1px solid #d8dbf5; background: var(--primary-soft); color: var(--primary); border-radius: 6px; font-size: 12px; padding: 2px 8px; cursor: pointer; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.tips { margin-top: 12px; color: #4a5162; font-size: 13px; }
.tips summary { cursor: pointer; color: var(--primary); }
.tips ul { margin: 8px 0 0; padding-left: 20px; }
.summary { margin-top: 16px; background: #f7f8fc; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; font-size: 13.5px; line-height: 1.8; }
.summary strong { color: var(--text); }
.summary .warn { color: var(--warn); }
.submit-bar { position: sticky; bottom: 0; background: rgba(245, 246, 250, .92); backdrop-filter: blur(6px); padding: 14px 0; display: flex; align-items: center; justify-content: flex-end; gap: 16px; border-top: 1px solid var(--border); }
.upload-progress { display: flex; align-items: center; gap: 10px; flex: 1; max-width: 420px; }
.upload-progress .progress { flex: 1; }

/* ---------- task detail ---------- */
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.status-line { display: flex; align-items: center; gap: 10px; }
.stage-text { font-weight: 600; }
.status-meta { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 13px; }
.video-wrap { background: #0b0d12; border-radius: 10px; overflow: hidden; display: flex; justify-content: center; }
.video-wrap video { max-width: 100%; max-height: 72vh; display: block; }
.result-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.prompt { white-space: pre-wrap; word-break: break-word; background: #f7f8fc; border-radius: 8px; padding: 12px 14px; margin: 0; font-family: inherit; font-size: 13.5px; max-height: 360px; overflow: auto; }
.asset-list { display: flex; flex-wrap: wrap; gap: 12px; }
.asset { width: 170px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff; }
.asset img { width: 100%; height: 130px; object-fit: contain; background: #111; display: block; }
.asset .asset-cap { padding: 6px 8px; font-size: 12px; color: #4a5162; display: flex; justify-content: space-between; gap: 6px; }
.asset .asset-cap span:last-child { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asset.audio { width: 100%; max-width: 420px; padding: 10px; }
.asset.audio audio { width: 100%; }
.kv { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 7px 10px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.timeline { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow: auto; font-size: 12.5px; }
.timeline li { display: grid; grid-template-columns: 62px minmax(0, 1fr); gap: 8px; padding: 5px 0; border-bottom: 1px dashed #edf0f5; }
.timeline li:last-child { border-bottom: 0; }
.timeline time { color: var(--muted); font-variant-numeric: tabular-nums; }
.timeline .warn { color: var(--warn); }
.timeline .error { color: var(--danger); }
.timeline .debug { color: var(--muted); white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; }

/* ---------- admin ---------- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }
.worker-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.worker { border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.worker-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.worker-head strong { font-size: 15px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: #b8bdc9; }
.dot.on { background: var(--success); box-shadow: 0 0 0 3px rgba(5, 150, 105, .15); }
.dot.off { background: var(--danger); }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 9px 10px; border-bottom: 1px solid #f0f2f6; white-space: nowrap; }
.table td.actions-cell { text-align: right; display: flex; gap: 8px; justify-content: flex-end; }
.tag { display: inline-block; font-size: 12px; border-radius: 4px; padding: 0 6px; background: #eef0f5; color: #4a5162; }
.tag.green { background: var(--success-soft); color: var(--success); }
.tag.red { background: var(--danger-soft); color: var(--danger); }
.tag.blue { background: var(--primary-soft); color: var(--primary); }
.dialog { border: 0; border-radius: 14px; padding: 24px; width: 420px; max-width: 92vw; box-shadow: 0 20px 50px rgba(0, 0, 0, .2); }
.dialog::backdrop { background: rgba(15, 20, 35, .35); }
.dialog form { display: flex; flex-direction: column; gap: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.error-page { margin: 60px auto; }
.error-code { font-size: 48px; font-weight: 700; color: #c5cad8; margin: 0; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px); background: #1f2433; color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 13.5px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: #9b1c1c; }
.toast.success { background: #046c4e; }

@media (max-width: 960px) {
  .detail-grid { grid-template-columns: 1fr; }
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mode-picker { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar-inner { gap: 12px; padding: 0 12px; }
  .brand span, .brand { font-size: 14px; }
  .container { padding: 16px 12px 64px; }
  .frame-pair, .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; align-items: stretch; }
}
