:root {
  --bg: #f4f6fa; --panel: #fff; --text: #172033; --muted: #687386;
  --line: #e3e8f0; --primary: #5b5bd6; --primary-dark: #4848b8;
  --danger: #d74646; --success: #15803d; --warning: #a16207;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; line-height: 1.55; }
a { color: var(--primary); text-decoration: none; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .5; cursor: not-allowed; }
.container { max-width: 1240px; margin: 0 auto; padding: 24px; }
.topbar { display: flex; align-items: center; gap: 20px; padding: 16px 0 22px; }
.brand { font-size: 21px; font-weight: 750; margin-right: auto; }
.nav { display: flex; gap: 6px; }
.nav a, .nav button { padding: 8px 13px; border-radius: 8px; color: var(--muted); border: 0; background: transparent; }
.nav a:hover, .nav a.active { color: var(--primary); background: #ededfc; }
.user-name { color: var(--muted); font-size: 13px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; margin-bottom: 20px; box-shadow: 0 3px 12px rgba(30, 40, 70, .03); }
.panel h2, .panel h3 { margin: 0 0 18px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
label { display: block; color: var(--muted); font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
input, textarea, select { width: 100%; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 8px; padding: 10px 12px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(91, 91, 214, .1); }
textarea { min-height: 110px; resize: vertical; }
.btn { border: 0; border-radius: 8px; padding: 10px 17px; background: var(--primary); color: #fff; font-weight: 650; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #eef1f6; color: #465168; }
.btn.danger { background: #fff0f0; color: var(--danger); }
.btn.small-btn { padding: 6px 10px; font-size: 12px; }
.btn.full { width: 100%; margin-top: 20px; padding: 13px; }
.mode-tabs, .admin-tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.mode-tabs button, .admin-tabs button { border: 1px solid var(--line); background: #fff; color: var(--muted); padding: 9px 16px; border-radius: 8px; }
.mode-tabs button.active, .admin-tabs button.active { color: #fff; border-color: var(--primary); background: var(--primary); }
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 12px; }
.template-card { position: relative; border: 2px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; cursor: pointer; }
.template-card.selected { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(91, 91, 214, .1); }
.template-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: #eef1f6; }
.template-card .template-info { padding: 10px; }
.template-card strong { display: block; font-size: 13px; }
.template-card p { margin: 4px 0 0; color: var(--muted); font-size: 11px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.template-placeholder { aspect-ratio: 1; display: grid; place-items: center; background: #eef1f6; color: var(--muted); }
.upload-zone { border: 1px dashed #b8c1d2; border-radius: 10px; padding: 20px; text-align: center; color: var(--muted); background: #fafbfc; cursor: pointer; }
.upload-zone input { display: none; }
.preview-list { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.preview-item { width: 90px; position: relative; }
.preview-item img { width: 90px; height: 90px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.preview-item button { position: absolute; right: -5px; top: -5px; width: 22px; height: 22px; border: 0; border-radius: 50%; background: var(--danger); color: #fff; }
.quota { display: flex; gap: 24px; align-items: center; padding: 14px 18px; background: #ededfc; border-radius: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.quota strong { color: var(--primary); font-size: 20px; }
.quota-item { font-size: 12px; color: var(--muted); }
.task { border-top: 1px solid var(--line); padding: 18px 0; }
.task:first-child { border-top: 0; }
.task-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.task-head .actions { margin-left: auto; display: flex; gap: 6px; }
.task-prompt { white-space: pre-wrap; margin: 10px 0; color: #465168; }
.task-meta { color: var(--muted); font-size: 12px; }
.result-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-top: 14px; }
.result-card { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.result-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.result-card a { display: block; text-align: center; padding: 8px; font-size: 12px; }
.status { border-radius: 20px; padding: 3px 9px; font-size: 11px; background: #eef1f6; color: var(--muted); }
.status.success { background: #eaf8ef; color: var(--success); }
.status.failed { background: #fff0f0; color: var(--danger); }
.status.pending, .status.partial_success { background: #fff7df; color: var(--warning); }
.status.running { background: #eaf3ff; color: #2563eb; }
.empty { text-align: center; padding: 36px; color: var(--muted); }
.toast { position: fixed; right: 22px; top: 22px; z-index: 1000; max-width: 420px; background: #172033; color: #fff; border-radius: 9px; padding: 12px 17px; box-shadow: 0 8px 30px rgba(0,0,0,.18); }
.toast.error { background: #a92f2f; } .toast.success { background: #187443; }
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(145deg, #eef0ff, #f8f9fc); }
.login-card { width: 100%; max-width: 410px; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 34px; box-shadow: 0 18px 50px rgba(52, 55, 110, .09); }
.login-card h1 { margin: 0 0 8px; font-size: 25px; }
.login-card p { color: var(--muted); margin: 0 0 18px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.stat { padding: 18px; background: #f7f8fc; border-radius: 10px; }
.stat strong { font-size: 25px; display: block; }
.stat span { color: var(--muted); font-size: 12px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 11px 9px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: 12px; white-space: nowrap; }
td input, td select { min-width: 90px; padding: 7px; }
.admin-template { display: grid; grid-template-columns: 80px 1fr auto; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.admin-template img, .admin-template .template-placeholder { width: 80px; height: 80px; border-radius: 8px; object-fit: cover; }
.admin-template p { margin: 3px 0; color: var(--muted); font-size: 12px; }
.admin-template .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.alert { padding: 12px 14px; border-radius: 8px; background: #eef1f6; color: var(--muted); margin-top: 12px; white-space: pre-wrap; }
.hidden { display: none !important; }
@media (max-width: 760px) {
  .container { padding: 14px; } .topbar { align-items: flex-start; flex-wrap: wrap; gap: 10px; }
  .brand { width: 100%; } .panel { padding: 17px; } .task-head .actions { margin-left: 0; width: 100%; }
  .admin-template { grid-template-columns: 60px 1fr; } .admin-template .actions { grid-column: 1 / -1; }
}

.generation-progress {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 94px;
  margin-top: 14px;
  padding: 18px;
  overflow: hidden;
  border: 1px solid #dfe0fa;
  border-radius: 10px;
  background: linear-gradient(110deg, #f5f5ff 25%, #e9eaff 45%, #f5f5ff 65%);
  background-size: 250% 100%;
  animation: generation-shimmer 2.2s linear infinite;
}
.generation-progress strong { color: var(--primary); }
.generation-progress p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.loading-ring {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border: 3px solid #d9daf8;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: generation-spin .85s linear infinite;
}
.image-skeleton {
  width: 58px;
  height: 58px;
  margin-left: auto;
  flex: 0 0 58px;
  border-radius: 9px;
  background: linear-gradient(135deg, #dedff8, #f7f7ff);
  animation: generation-pulse 1.4s ease-in-out infinite;
}
@keyframes generation-spin { to { transform: rotate(360deg); } }
@keyframes generation-shimmer { to { background-position: -250% 0; } }
@keyframes generation-pulse { 50% { opacity: .45; transform: scale(.94); } }
@media (prefers-reduced-motion: reduce) {
  .generation-progress, .loading-ring, .image-skeleton { animation: none; }
}

.fixed-prompt { min-height: 76px; background: #fafaff; border-color: #dcdcf5; }
.fixed-prompt-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }

.container { max-width: 1500px; }
.workspace { display: grid; grid-template-columns: minmax(0, 1.08fr) minmax(380px, .92fr); gap: 20px; align-items: start; }
.workspace .panel { margin-bottom: 0; }
.records-column { min-width: 0; }
.records-column > .panel { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
.records-column .task-head { align-items: flex-start; }
.records-column .task-head h2 { margin-bottom: 0; }
.records-column .actions { margin-left: auto; }
.records-column .result-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
@media (max-width: 1050px) {
  .workspace { grid-template-columns: 1fr; }
  .records-column > .panel { position: static; max-height: none; overflow: visible; }
}

.model-note { display: inline-flex; gap: 5px; margin: -8px 0 16px; padding: 6px 10px; border-radius: 7px; background: #ededfc; color: var(--muted); font-size: 12px; }
.model-note strong { color: var(--primary); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.template-upload-step { padding: 28px 18px; border: 1px dashed #bfc2e8; border-radius: 12px; background: #fafaff; text-align: center; }
.template-upload-step input[type="file"] { display: none; }
.template-upload-button { display: inline-flex; margin: 0; padding: 13px 24px; border-radius: 9px; background: var(--primary); color: #fff; font-size: 14px; cursor: pointer; }
.template-upload-button:hover { background: var(--primary-dark); }
.template-upload-step p { margin: 12px 0 0; }
#preview-current { margin-bottom: 14px; }
#preview-current img { width: 120px; height: 120px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
