:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f7f8fa;
  --bg-tertiary: #eef1f5;
  --text-primary: #1a1a2e;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --accent: #e63946;
  --accent-hover: #d62828;
  --accent-light: #fce4e6;
  --success: #2ecc71;
  --warning: #f39c12;
  --danger: #e74c3c;
  --border: #e5e7eb;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.12);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* Toast 提示 */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%) translateY(-100px);
  background: #1a1a2e; color: #fff; padding: 12px 28px; border-radius: 8px;
  font-size: 14px; z-index: 9999; opacity: 0; transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 导航栏 */
.navbar {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.nav-brand { display: flex; align-items: center; gap: 10px; }

.logo {
  background: linear-gradient(135deg, var(--accent), #f06292);
  color: white;
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
}

.brand-text { font-size: 18px; font-weight: 600; }

.nav-actions { display: flex; align-items: center; gap: 12px; }

/* 按钮 */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-outline { background: transparent; color: var(--text-primary); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg-tertiary); }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 14px 32px; font-size: 16px; width: 100%; }

/* 主内容 */
main { max-width: 1400px; margin: 0 auto; padding: 32px 24px; }

/* 认证页面 */
.auth-container {
  max-width: 420px;
  margin: 40px auto;
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  padding: 40px;
  box-shadow: var(--shadow-md);
}

.auth-container h2 { text-align: center; margin-bottom: 8px; font-size: 24px; }
.auth-subtitle { text-align: center; color: var(--text-secondary); margin-bottom: 32px; font-size: 14px; }

/* 表单 */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 500; }
.required { color: var(--accent); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: border-color 0.2s;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.form-group textarea { resize: vertical; min-height: 80px; }

.form-row-two { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 640px) { .form-row-two { grid-template-columns: 1fr; } }

.auth-switch { text-align: center; margin-top: 20px; font-size: 14px; color: var(--text-secondary); }
.auth-switch a { color: var(--accent); text-decoration: none; font-weight: 500; }

/* 卡片 */
.card {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
  border: 1px solid var(--border);
}

.card-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-subtitle {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-tertiary);
  margin-left: auto;
}

/* 步骤标记 */
.step-badge {
  width: 28px; height: 28px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

/* 模板网格 */
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
}

.template-card {
  background: var(--bg-primary);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s;
}

.template-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.template-card.selected {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 0 3px var(--accent-light);
}

/* 旧模板样式已移至文件底部统一定义 */

.template-card-body {
  padding: 12px 16px;
}

.template-card-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.template-card-id {
  font-size: 12px;
  color: var(--text-tertiary);
  font-family: monospace;
}

.template-card-variants {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.variant-tag {
  background: var(--bg-tertiary);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  color: var(--text-secondary);
}

/* 参数网格 */
.param-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.param-grid > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.param-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin: 0 !important;
}

.param-grid select {
  padding: 8px 12px !important;
  font-size: 13px !important;
}

/* 表单操作区 */
.form-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 24px;
}

.form-actions .btn-lg {
  flex: 1;
}

/* 上传区域 */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.upload-zone:hover { border-color: var(--accent); background: var(--accent-light); }
.upload-zone.has-file { border-color: var(--success); border-style: solid; }

.upload-icon { font-size: 28px; margin-bottom: 4px; color: var(--text-tertiary); }
.upload-text { color: var(--text-secondary); font-size: 13px; }
.upload-preview { max-width: 160px; max-height: 160px; border-radius: var(--radius-sm); margin-top: 12px; }

/* 结果画廊 */
.result-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

.result-item {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  background: var(--bg-secondary);
}

.result-item img {
  width: 100%;
  display: block;
  cursor: zoom-in;
  transition: transform 0.2s;
}
.result-item img:hover { transform: scale(1.02); }

.result-item .download-btn {
  display: inline-block;
  margin: 12px;
  padding: 8px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background 0.2s;
}
.result-item .download-btn:hover { background: var(--accent-hover); }

/* 图片灯箱 */
.lightbox {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 10000;
  justify-content: center;
  align-items: center;
  cursor: zoom-out;
}
.lightbox.show { display: flex; }
.lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
}

/* 提示 */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 14px;
}
.alert-info { background: #e7f5ff; color: #1971c2; }
.alert-success { background: #e6f9ee; color: #2b8a3e; }
.alert-error { background: #fff0f0; color: #c92a2a; }
.alert-warning { background: #fff9db; color: #e67700; }

/* 加载 */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay { text-align: center; padding: 40px; }
.loading-overlay .spinner { width: 40px; height: 40px; border-width: 4px; }
.loading-text { margin-top: 16px; color: var(--text-secondary); font-size: 14px; }

/* 历史记录 */
.history-item {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
  transition: box-shadow 0.2s;
}
.history-item:hover { box-shadow: var(--shadow-sm); }
.history-item-with-img { padding: 16px; }
.history-item-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0;
}
.history-item-info { flex: 1; }
.history-item-name { font-weight: 600; font-size: 14px; }
.history-item-time { font-size: 12px; color: var(--text-tertiary); }
.history-thumbs {
  display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px;
}
.history-thumb {
  position: relative; width: 160px; border-radius: var(--radius-sm); overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.history-thumb img {
  width: 100%; display: block; max-height: 200px; object-fit: cover;
}
.download-btn-sm {
  display: block; text-align: center; padding: 6px;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 600;
  text-decoration: none; border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}
.download-btn-sm:hover { background: var(--accent-hover); }

.history-status {
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}
.status-success { background: #e6f9ee; color: #2b8a3e; }
.status-failed { background: #fff0f0; color: #c92a2a; }
.status-pending { background: #e7f5ff; color: #1971c2; }

/* 空状态 */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-tertiary); }
.empty-state-icon { font-size: 48px; margin-bottom: 16px; }

/* Key 配置 */
.key-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--success);
  color: white;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
}
.key-badge.not-configured { background: var(--bg-tertiary); color: var(--text-secondary); }

/* Prompt 预览 */
.prompt-preview {
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-family: "SF Mono", "Consolas", monospace;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 16px;
  line-height: 1.5;
}

/* 标签页 */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--border);
}

.tab {
  padding: 12px 24px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}

.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* 复选框 */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}
.checkbox-row input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }
.checkbox-row label { font-size: 14px; cursor: pointer; margin: 0; }

/* 帮助文字 */
.help-text { font-size: 12px; color: var(--text-tertiary); margin-top: 4px; }

/* 模板 Prompt 预览框 */
.prompt-hint-box {
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
  font-family: "SF Mono", "Consolas", "Menlo", monospace;
  max-height: 100px;
  overflow-y: auto;
  word-break: break-all;
}

.link-btn {
  background: none; border: none; color: var(--accent);
  cursor: pointer; font-size: 14px; text-decoration: underline; padding: 0;
}

/* 步骤徽章 */
.step-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: white; font-size: 14px; font-weight: 700;
  margin-right: 8px;
}

/* 卡片副标题 */
.card-subtitle {
  font-size: 13px; color: var(--text-tertiary); font-weight: 400; margin-left: 8px;
}

/* 必填标记 */
.required { color: var(--danger); }

/* 模板缩略图 - 完整展示图片 */
.tpl-thumb {
  width: 100%; height: 320px; border-radius: var(--radius-md);
  overflow: hidden; position: relative; display: flex;
  align-items: center; justify-content: center;
  background: var(--bg-tertiary);
}
.tpl-thumb-img {
  width: 100%; height: 100%; object-fit: contain; display: block;
}
.tpl-thumb-icon {
  width: 100%; height: 100%; display: flex; align-items: center;
  justify-content: center; font-size: 40px;
}

/* 模板卡片 - 极简大图风格 */
.template-card {
  background: var(--bg-primary); border: none; border-radius: var(--radius-lg);
  overflow: hidden; cursor: pointer; transition: all 0.2s;
  box-shadow: var(--shadow-sm); padding: 0;
}
.template-card:hover {
  box-shadow: var(--shadow-lg); transform: translateY(-4px);
}
.template-card.selected { box-shadow: 0 0 0 3px var(--accent); }
.template-card-body { padding: 10px 12px 12px; }
.template-card-name { font-weight: 600; font-size: 13px; line-height: 1.3; }
.template-card-id { display: none; }
.template-card-variants { display: none; }

/* 模板网格 - 更大卡片 */
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.tpl-section-label {
  font-size: 13px; font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.08em;
  margin-bottom: 14px; padding-left: 2px;
}

/* 选中模板横幅 */
.selected-tpl-banner {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: var(--radius-md); margin-bottom: 20px;
}
.tpl-banner-icon {
  width: 40px; height: 40px; border-radius: 50%; color: white;
  display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0;
}

/* 双列表单行 */
.form-row-two {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}
@media (max-width: 768px) {
  .form-row-two { grid-template-columns: 1fr; }
}

/* 参数网格 */
.param-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.param-label {
  display: block; font-size: 12px; color: var(--text-secondary);
  margin-bottom: 4px; font-weight: 500; cursor: pointer;
}
.param-grid select {
  padding: 8px 12px; font-size: 13px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); width: 100%; background: var(--bg-primary);
}

/* 生成页左右布局 */
.gen-layout {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 24px;
  align-items: start;
}
.gen-left { position: sticky; top: 80px; }
.gen-right { min-height: 500px; }
.gen-right .card { margin-bottom: 0; min-height: 500px; }

@media (max-width: 900px) {
  .gen-layout { grid-template-columns: 1fr; }
  .gen-left { position: static; }
}
