:root {
  /* 配色灵感：温暖米色 + 鼠尾草绿 */
  --bg: #F2EDE6;
  --surface: #FDFBF7;
  --border: #DCD4C8;
  --text: #2C2416;
  --text-muted: #8C8276;
  --primary: #6A9B4A;
  --primary-dark: #557A3C;
  --success: #4A8C5C;
  --warning: #C78A3A;
  --danger: #B84B4B;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(44, 36, 22, 0.06), 0 1px 2px rgba(44, 36, 22, 0.04);
  --shadow-lg: 0 10px 30px rgba(44, 36, 22, 0.10);
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }

a { color: var(--primary); text-decoration: none; }
.text-muted { color: var(--text-muted); }

/* ===== 登录页 ===== */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 380px;
  padding: 32px;
}
.auth-card h1 { margin: 0 0 4px; font-size: 22px; font-family: Georgia, "Times New Roman", serif; letter-spacing: 0.02em; }
.auth-card .sub { margin: 0 0 24px; color: var(--text-muted); font-size: 13px; }
.auth-lockup {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 0 0 14px;
}
.auth-icon {
  display: block;
  height: 70px;
  width: auto;
  border-radius: 14px;
  box-shadow: var(--shadow-md);
}
.auth-word {
  display: block;
  height: 50px;   /* 高度低于图标，上下边缘不超出图标范围 */
  width: auto;
}

/* ===== 顶栏 ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 60px;
  background: var(--text);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--surface);
  letter-spacing: 0.04em;
}
.lockup {
  display: flex;
  align-items: center;
  gap: 10px;
}
.lockup-icon {
  display: block;
  height: 38px;
  width: auto;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
.lockup-word {
  display: block;
  height: 27px;  /* 严格低于图标高度，垂直居中 */
  width: auto;
}
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a {
  padding: 8px 14px;
  border-radius: 8px;
  color: rgba(253, 251, 247, 0.62);
  font-weight: 500;
  white-space: nowrap;
}
.nav a:hover { background: rgba(253, 251, 247, 0.10); color: var(--surface); }
.nav a.active { background: rgba(106, 155, 74, 0.25); color: #D6E8C9; }
.userbox { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.userbox span { color: rgba(253, 251, 247, 0.85); font-size: 13px; }
.userbox .btn-ghost { color: var(--surface); border-color: rgba(253, 251, 247, 0.3); }
.userbox .btn-ghost:hover { background: rgba(253, 251, 247, 0.10); }

.container { max-width: 1100px; margin: 0 auto; padding: 24px; }

.page-title { font-size: 22px; font-weight: 700; margin: 0 0 16px; font-family: Georgia, "Times New Roman", serif; letter-spacing: 0.02em; }

/* ===== 卡片 ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card h3 { margin: 0 0 12px; font-size: 15px; }

/* ===== 表单 ===== */
.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 13px; }
.input, .select, .textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(106, 155, 74, 0.15); }
.textarea { min-height: 90px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ===== 按钮 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  transition: background .15s, opacity .15s;
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #9E3E3E; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }

/* ===== 上传区 ===== */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: #EAF2E2; }
.dropzone img { max-width: 200px; max-height: 200px; border-radius: 8px; margin-top: 12px; }
#preview-a { display: block; max-width: 220px; max-height: 220px; border-radius: 8px; margin-top: 12px; object-fit: contain; border: 1px solid var(--border); }

/* ===== 进度与预览 ===== */
.progress-steps { display: flex; align-items: center; gap: 8px; margin: 16px 0; flex-wrap: wrap; }
.step {
  flex: 1;
  min-width: 120px;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}
.step.active { border-color: var(--primary); color: var(--primary-dark); background: #EAF2E2; }
.step.done { border-color: var(--success); color: var(--success); background: #E8F3EB; }
.step.failed { border-color: var(--danger); color: var(--danger); background: #F7EAEA; }
.preview-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.preview-box { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.preview-box .label { padding: 8px 12px; font-size: 13px; font-weight: 600; border-bottom: 1px solid var(--border); }
.preview-box img { width: 100%; height: 220px; object-fit: contain; background: #F5F1EA; display: block; }
.preview-box .placeholder { height: 220px; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 13px; }
.spinner {
  width: 20px; height: 20px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin .8s linear infinite; margin: 0 auto 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 表格 ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { background: #F5F1EA; font-weight: 600; color: var(--text-muted); white-space: nowrap; }
td img.thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.success { background: #E8F3EB; color: var(--success); }
.badge.failed { background: #F7EAEA; color: var(--danger); }
.badge.processing { background: #EAF2E2; color: var(--primary-dark); }
.badge.pending { background: #F0EBE3; color: var(--text-muted); }
.badge.admin { background: #EAF2E2; color: var(--primary-dark); }
.badge.user { background: #F0EBE3; color: var(--text-muted); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.toolbar .input, .toolbar .select { width: auto; flex: 0 0 220px; }
.spacer { flex: 1; }

/* ===== 空状态 ===== */
.empty { text-align: center; color: var(--text-muted); padding: 48px 0; }

/* ===== Toast ===== */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 16px; border-radius: 8px; color: #fff; font-size: 13px;
  box-shadow: var(--shadow-lg); animation: slidein .2s ease;
  max-width: 320px;
}
.toast.info { background: #2C2416; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(44, 36, 22, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 900; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: 12px; width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto; padding: 24px; box-shadow: var(--shadow-lg);
}
.modal.wide { max-width: 800px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-header h3 { margin: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 12px 16px; }
  .nav { order: 3; width: 100%; }
  .userbox { margin-left: auto; }
  .container { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .preview-grid { grid-template-columns: 1fr; }
  .toolbar .input, .toolbar .select { flex: 1 1 100%; }
}

/* ===== 16 张成品图（手机长按保存到相册）：PC 6列 / 平板 4列 / 手机 2列 ===== */
.crop-tip { margin: 0 0 12px; font-size: 13px; color: var(--text-muted); }
.crop-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 14px;
}
@media (max-width: 1024px) {
  .crop-grid { grid-template-columns: repeat(4, 1fr); gap: 12px; }
}
@media (max-width: 640px) {
  .crop-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}
.crop-item {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  text-align: center;
}
.crop-item img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  display: block;
  background: #F5F1EA;
  /* 保证移动端长按可触发「保存图片」系统菜单 */
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
}
.crop-item figcaption { padding: 8px 8px 0; font-size: 12px; color: var(--text-muted); }
.crop-item .btn { margin: 8px; }

/* ===== 9 图（3×3）/ 6 图（3×2）成品网格：3 列 ===== */
.crop-grid.cols3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 640px) {
  .crop-grid.cols3 { grid-template-columns: repeat(3, 1fr); gap: 10px; }
}

/* ===== 模板阵列（缩略图选择）：PC 6列 / 平板 4列 / 手机 2列 ===== */
.tpl-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}
@media (max-width: 1024px) {
  .tpl-grid { grid-template-columns: repeat(4, 1fr); gap: 12px; }
}
@media (max-width: 640px) {
  .tpl-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}
.tpl-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
  position: relative;
}
.tpl-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.tpl-card.selected { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(106, 155, 74, 0.18); }
.tpl-cover { width: 100%; height: 130px; object-fit: cover; display: block; background: #F0EBE3; }
.tpl-cover--empty { display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 12px; }
.tpl-name { padding: 10px 12px; font-size: 13px; font-weight: 600; text-align: center; border-top: 1px solid var(--border); }
.tpl-preview {
  position: absolute; top: 6px; right: 6px; z-index: 2;
  background: rgba(0, 0, 0, 0.55); color: #fff; border: none;
  border-radius: 6px; padding: 3px 8px; font-size: 12px; cursor: pointer;
  transition: background .15s;
}
.tpl-preview:hover { background: rgba(0, 0, 0, 0.78); }
/* ===== 模板缩略图放大预览 ===== */
.preview-full { display: flex; align-items: center; justify-content: center; }
.preview-full img { max-width: 100%; max-height: 70vh; object-fit: contain; border-radius: 8px; border: 1px solid var(--border); }
/* ===== 生成结果 ===== */
.result-wrap { text-align: center; min-height: 220px; }
.result-wrap img { max-width: 100%; max-height: 420px; border-radius: 8px; border: 1px solid var(--border); }
.result-wrap .placeholder {
  min-height: 220px; display: flex; align-items: center; justify-content: center;
  flex-direction: column; color: var(--text-muted); font-size: 13px;
}

.result-actions { margin-top: 12px; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; align-items: center; }
.text-danger { color: var(--danger); font-size: 13px; margin: 8px 0; }

/* ===== 前台：分类目录 ===== */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.cat-card {
  display: block;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.cat-card:hover { border-color: var(--primary); box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.cat-cover { height: 150px; background: #F0EBE3; overflow: hidden; }
.cat-cover-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cat-cover-empty {
  height: 100%; display: flex; align-items: center; justify-content: center;
  font-family: Georgia, "Times New Roman", serif; font-size: 30px; letter-spacing: 0.08em;
  color: #A79C8C; background: linear-gradient(135deg, #F6F1E8, #E8E0D2);
}
.cat-body { padding: 12px 14px 14px; }
.cat-name { display: flex; align-items: center; gap: 6px; font-size: 15px; font-weight: 600; }
.cat-tag {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  background: #EAF2E2; color: var(--primary-dark);
  font-size: 11px; font-weight: 600; vertical-align: middle;
}
.cat-desc {
  margin-top: 4px; font-size: 12px; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.cat-meta { margin-top: 8px; font-size: 12px; color: var(--primary-dark); }
.back-link { display: inline-flex; align-items: center; margin-bottom: 12px; font-size: 13px; color: var(--text-muted); }
.back-link:hover { color: var(--primary); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h3 { margin: 0; }

/* ===== 前台：购买卡片 ===== */
.tpl-buy-grid { grid-template-columns: repeat(4, 1fr); }
.tpl-desc {
  padding: 0 12px 8px; font-size: 12px; line-height: 1.5; min-height: 34px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tpl-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px 10px; border-top: 1px solid var(--border);
}
.tpl-price { font-size: 15px; font-weight: 700; color: var(--primary-dark); }
.tpl-price.free { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.tpl-lock {
  display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 999px;
  background: #EAF2E2; color: var(--primary-dark); font-size: 11px; font-weight: 600;
}
.tpl-search { width: 220px; }

/* ===== 后台导航（平铺） ===== */
/* 导航项直接作为 .nav 的 flex 子项，无需额外分组容器 */

/* ===== 表单内联勾选 ===== */
.check-line { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }

@media (max-width: 1024px) {
  .cat-grid { grid-template-columns: repeat(3, 1fr); }
  .tpl-buy-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 768px) {
  .cat-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .tpl-search { width: 100%; }
}
@media (max-width: 640px) {
  .tpl-buy-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===== 裁剪成品网格：PC 8列 / 平板 4列 / 手机 2列 ===== */
.crop-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.crop-cell {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.crop-cell img { width: 100%; height: 100%; display: block; object-fit: cover; aspect-ratio: 1 / 1; }
.crop-idx {
  position: absolute; left: 4px; bottom: 4px;
  background: rgba(44, 36, 22, 0.72); color: #fff;
  font-size: 10px; line-height: 1; padding: 3px 5px; border-radius: 4px;
}
@media (max-width: 1024px) {
  .crop-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 640px) {
  .crop-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}
.pv-actions { display: flex; gap: 8px; padding: 10px 12px; }
.pv-remark {
  padding: 0 12px 10px; font-size: 12px; line-height: 1.6;
  color: var(--muted, #888); word-break: break-all;
}
.pv-remark b { color: var(--text, #333); font-weight: 600; }
.split-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.split-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.split-cell {
  position: relative; display: block; border: 2px solid var(--border);
  border-radius: var(--radius); overflow: hidden; background: var(--surface); cursor: pointer;
}
.split-cell.checked { border-color: var(--primary); }
.split-cell img { width: 100%; display: block; }
.split-cell input[type="checkbox"] { position: absolute; top: 6px; left: 6px; width: 16px; height: 16px; z-index: 2; }
.split-num {
  position: absolute; bottom: 4px; right: 6px; font-size: 11px; color: #fff;
  background: rgba(0,0,0,0.5); padding: 0 5px; border-radius: 4px; z-index: 2;
}
@media (max-width: 640px) {
  .split-grid { grid-template-columns: repeat(2, 1fr); }

  /* 移动端触摸适配：更大的点击区域、更紧凑的顶栏 */
  .btn { min-height: 42px; }
  .btn-sm { min-height: 36px; }
  .tpl-card { min-height: 44px; }
  .tpl-cover { height: 110px; }
  .tpl-name { padding: 12px 8px; }
  .brand { font-size: 16px; }
  .lockup { gap: 8px; }
  .lockup-icon { height: 32px; border-radius: 8px; }
  .lockup-word { height: 23px; }
  .auth-lockup { gap: 9px; }
  .auth-icon { height: 56px; border-radius: 11px; }
  .auth-word { height: 40px; }
  .topbar { gap: 12px; padding: 10px 12px; }
  .userbox span { display: none; } /* 小屏隐藏角色文字，保留退出按钮 */
  .dropzone { padding: 28px 12px; }
  .container { padding: 12px; }
}

/* ===== 分页条 ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 0 4px;
  flex-wrap: wrap;
}
.pagination .pg-info { font-size: 13px; color: var(--text-muted); }

/* ===== 开关组件 ===== */
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .switch-track {
  width: 48px; height: 27px; border-radius: 999px;
  background: #C9C0B3; position: relative; flex: none;
  transition: background-color .2s ease;
}
.switch .switch-thumb {
  position: absolute; top: 3px; left: 3px;
  width: 21px; height: 21px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.28);
  transition: transform .2s ease;
}
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(21px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px rgba(106, 155, 74, 0.25); }
.switch-label { font-size: 14px; font-weight: 600; }

/* ===== 页脚（左下角信息栏 + 反馈入口） ===== */
.app-footer {
  max-width: 1100px;
  margin: 8px auto 32px;
  padding: 0 24px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 16px;
}

/* 左下角备用栏 1-3（文字/图片/链接，后台可配置） */
.footer-slots {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-right: auto;
  flex-wrap: wrap;
  min-width: 0;
}
.footer-slots:empty { display: none; }
.footer-slot-text { font-size: 13px; color: var(--text-muted); }
.footer-slot-img {
  display: block;
  max-height: 48px;
  max-width: 160px;
  object-fit: contain;
}
.footer-slot-link { font-size: 13px; color: var(--primary); }
.footer-slot-link:hover { text-decoration: underline; }

/* 首页标题下方 / 子目录标题下方的备用栏 */
.page-slot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: -6px 0 18px;
  flex-wrap: wrap;
}
.page-slot:empty { display: none; }

/* 下载按钮高亮脉冲（移动端/Safari 提示用户轻点） */
.btn-pulse { animation: btnPulse 1.4s ease-in-out infinite; }
@keyframes btnPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(106, 155, 74, 0.45); }
  50% { box-shadow: 0 0 0 10px rgba(106, 155, 74, 0); }
}

/* 后台配置页分组标题 */
.cfg-header {
  grid-column: 1 / -1;
  margin: 8px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--border, #e5e0d8);
  font-size: 14px;
  color: var(--text);
}