:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --line: #e6e8ef;
  --text: #1c1f2b;
  --muted: #6b7182;
  --brand: #4f46e5;
  --brand-soft: #eef0ff;
  --danger: #d92d20;
  --radius: 14px;
}

* { box-sizing: border-box; }

/*
 * 必须放在所有布局规则之前（同等权重下后者会赢，所以这里用 !important 兜底）：
 * 下面的 .modal / .auth-wrap / .preview 都设了 display:flex|block，
 * 那些作者样式会覆盖浏览器给 [hidden] 的 display:none，导致元素"藏不住"。
 */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 17px; font-weight: 600; margin: 0; }
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #16a34a; display: inline-block;
}
.queue { font-size: 13px; color: var(--muted); }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px 60px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }

textarea, input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  color: inherit;
  background: #fff;
  outline: none;
  resize: vertical;
}
textarea:focus, input:focus, select:focus { border-color: var(--brand); }

button {
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 9px 16px;
  cursor: pointer;
  color: inherit;
}
button:hover { border-color: var(--brand); color: var(--brand); }

button.primary {
  width: 100%;
  margin-top: 14px;
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 500;
  padding: 12px;
}
button.primary:hover { opacity: 0.92; color: #fff; }
button.primary:disabled { opacity: 0.55; cursor: not-allowed; }

.ghost { color: var(--muted); text-decoration: none; font-size: 14px; }

.upload {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
}
.upload:hover { border-color: var(--brand); color: var(--brand); }

.preview, .result {
  width: 100%;
  border-radius: 10px;
  margin-top: 12px;
  display: block;
}
.preview { max-height: 180px; width: auto; }

.advanced { margin-top: 14px; }
.advanced summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  padding: 6px 0;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.bar {
  height: 8px;
  background: var(--brand-soft);
  border-radius: 99px;
  overflow: hidden;
  margin: 10px 0 6px;
}
.bar-fill {
  height: 100%;
  width: 0;
  background: var(--brand);
  border-radius: 99px;
  transition: width 0.4s ease;
}

.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.error { color: var(--danger); font-size: 14px; margin: 10px 0 0; }

h2 { font-size: 15px; font-weight: 600; margin: 0; }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.gallery img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: pointer;
  background: var(--brand-soft);
}

.thumb { position: relative; }
.thumb-del {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  padding: 0;
  line-height: 1;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  font-size: 15px;
}
.thumb-del:hover { color: var(--danger); border-color: var(--danger); }

/* ---------- 登录 ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.auth-card { width: 100%; max-width: 420px; }
.auth-card h1 { font-size: 19px; margin: 0 0 8px; }
.auth-card form { margin-top: 16px; }
.auth-card form label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}
.auth-card form input { margin-top: 6px; }

.tabs {
  display: flex;
  gap: 6px;
  background: var(--brand-soft);
  padding: 4px;
  border-radius: 10px;
  margin-top: 16px;
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px;
  border-radius: 8px;
  color: var(--muted);
}
.tab.active { background: #fff; color: var(--brand); font-weight: 500; }

.privacy-note {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: #eaf5ee;
  border: 1px solid #bfe0cb;
  color: #1d6b3f;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ---------- 弹层 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 30, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
  overflow-y: auto;
}
.modal-card { width: 100%; max-width: 460px; }

.row.wrap { flex-wrap: wrap; }
button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); color: var(--danger); }

/* ---------- 模板字段 ---------- */
.field-group { margin-top: 18px; }
.field-group-title {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}
.field { margin-bottom: 14px; }
.field-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
.field-tag {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--brand-soft);
  color: var(--brand);
}
.field-tag.locked { background: #f1efe8; color: #888780; }

/* 每个框里的一条描述：多行文本域，随内容自动增高，直接点进去就能改 */
.variants { display: flex; flex-direction: column; gap: 6px; }
.variant-row { display: flex; align-items: flex-start; gap: 6px; }
.variant-input {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  line-height: 1.7;
  padding: 8px 10px;
  overflow: hidden;      /* 高度由脚本撑开，框内不出现滚动条 */
  resize: none;
}
.variant-del {
  flex: none;
  width: 30px;
  height: 30px;
  padding: 0;
  margin-top: 4px;
  font-size: 17px;
  line-height: 1;
  color: var(--muted);
  border-radius: 8px;
}
.variant-del:hover { border-color: var(--danger); color: var(--danger); }
.variant-add {
  margin-top: 8px;
  padding: 5px 11px;
  font-size: 12.5px;
  color: var(--muted);
  border-style: dashed;
}
.variant-add:disabled { opacity: 0.55; cursor: not-allowed; }
.variant-add:disabled:hover { border-color: var(--line); color: var(--muted); }
.field-count {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 99px;
  background: #f1efe8;
  color: var(--muted);
}

/* 长文本域统一自动增高 */
.auto-grow { overflow: hidden; resize: none; }

/* ---------- 画幅 ---------- */
.aspect-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 18px 0 4px;
}
.aspect-label { flex: none; font-size: 13px; color: var(--muted); }
.aspect-opts { display: flex; flex-wrap: wrap; gap: 6px; }
.aspect-opt {
  padding: 5px 11px;
  font-size: 13px;
  border-radius: 8px;
  color: var(--muted);
}
.aspect-opt.on { background: var(--brand); border-color: var(--brand); color: #fff; }

.variant-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
  font-size: 14px;
}
.warn { color: var(--danger); }

.preview-box {
  background: #f7f8fb;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 8px 0 0;
  font-family: inherit;
  max-height: 220px;
  overflow: auto;
}

/* ---------- 方案栏 ---------- */
.preset-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
}
.preset-bar select { flex: 1; min-width: 150px; }

/* ---------- 执行历史 ---------- */
.hist-list { margin-top: 10px; }
.hist-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.hist-item:last-child { border-bottom: none; }
.hist-thumb {
  width: 64px;
  height: 64px;
  flex: 0 0 64px;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--muted);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.hist-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: pointer;
}
.hist-body { flex: 1; min-width: 0; }
.hist-meta { font-size: 12px; color: var(--muted); }
.hist-prompt {
  font-size: 13px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.modal-wide { max-width: 660px; }

/* ---------- 任务列表 ---------- */
.task-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.task-item:last-child { border-bottom: none; }
.task-thumb {
  width: 76px;
  height: 76px;
  flex: 0 0 76px;
  border-radius: 10px;
  background: var(--brand-soft);
  overflow: hidden;
}
.task-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: pointer; }
.task-body { flex: 1; min-width: 0; }
.task-status { font-size: 13px; }
.task-prompt {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.task-actions { display: flex; flex-direction: column; gap: 6px; }
.task-actions button { font-size: 12px; padding: 4px 10px; }

/* ---------- 套餐与用户管理 ---------- */
.plan-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--brand);
  color: #fff;
}
.plan-badge.off { background: #e6e8ef; color: var(--muted); }

.user-list { margin-top: 12px; max-height: 46vh; overflow: auto; }
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.user-row:last-child { border-bottom: none; }
.user-info { display: flex; flex-direction: column; min-width: 0; }

@media (max-width: 520px) {
  main { padding: 14px 12px 40px; }
  .grid { grid-template-columns: 1fr; }
  .topbar { padding: 12px 14px; }
  .topbar .row { gap: 6px; }
  .queue { display: none; }
}
