/* ==================== 全局 ==================== */
:root {
  --sidebar-width: 220px;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --success: #10b981;
  --success-bg: #d1fae5;
  --success-text: #065f46;
  --error: #ef4444;
  --error-bg: #fee2e2;
  --error-text: #991b1b;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --warning-text: #92400e;
  --info-bg: #dbeafe;
  --info-text: #1e40af;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.10);
  --transition: 0.2s ease;
}

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

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

/* ==================== 侧边栏布局 ==================== */
.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  width: 40px;
  height: 40px;
  background: var(--primary);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
}

.sidebar-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.sidebar-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-footer {
  padding: 8px 10px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ==================== 导航按钮 ==================== */
.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-secondary);
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
}

.nav-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.nav-btn.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.nav-icon {
  font-size: 16px;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

.nav-label {
  white-space: nowrap;
}

/* ==================== 主内容区 ==================== */
.main {
  flex: 1;
  padding: 32px 40px;
  max-width: 860px;
  min-width: 0;
}

/* ==================== 面板头 ==================== */
.panel-header {
  margin-bottom: 28px;
}

.panel-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

.panel-desc {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ==================== 区块 ==================== */
.section-block {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 16px;
}

.section-block:last-child {
  margin-bottom: 0;
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.section-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* ==================== 表单控件 ==================== */
textarea, input, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--card-bg);
  transition: border-color var(--transition);
}

textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.10);
}

textarea { resize: vertical; min-height: 80px; }
select { cursor: pointer; }

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

/* ==================== 参数网格 ==================== */
.param-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 8px;
}

.param-item {
  display: flex;
  flex-direction: column;
}

.builder-select-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 8px;
}

.builder-custom-input {
  margin-top: 6px;
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 12px;
  outline: none;
  transition: border var(--transition);
  background: var(--bg);
  color: var(--text);
}
.builder-custom-input:focus { border-color: var(--primary); }

/* ==================== 操作栏 ==================== */
.action-bar {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* ==================== 按钮 ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 22px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-outline:hover {
  background: var(--bg);
  border-color: var(--text-muted);
  color: var(--text);
}

/* ==================== 拆分提示词输入 ==================== */
.prompt-split {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}
.prompt-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.prompt-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}
.prompt-field-hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 12px;
}
.prompt-field textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border var(--transition);
}
.prompt-field textarea:focus {
  border-color: var(--primary);
}
.prompt-field textarea[readonly] {
  background: #f8fafc;
  cursor: default;
  color: var(--text-secondary);
}

@media (max-width: 640px) {
  .prompt-split { flex-direction: column; gap: 8px; }
}

/* ==================== 进度条 ==================== */
.progress-bar {
  width: 100%;
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 16px;
  display: none;
}

.progress-bar.show { display: block; }

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  animation: progress-indeterminate 1.5s infinite ease-in-out;
}

@keyframes progress-indeterminate {
  0% { width: 0%; margin-left: 0; }
  50% { width: 60%; margin-left: 20%; }
  100% { width: 0%; margin-left: 100%; }
}

/* ==================== 状态 ==================== */
.status-bar {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  margin-top: 12px;
  display: none;
}

.status-bar.show { display: block; }
.status-success { background: var(--success-bg); color: var(--success-text); }
.status-error { background: var(--error-bg); color: var(--error-text); }
.status-info { background: var(--info-bg); color: var(--info-text); }
.status-warning { background: var(--warning-bg); color: var(--warning-text); }

/* ==================== 结果区 ==================== */
.result-area {
  display: none;
  margin-top: 16px;
}

.result-area.show { display: block; }

/* 图像结果 */
#result-image img {
  max-width: 100%;
  max-height: 400px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: block;
  margin: 0 auto;
}

#result-image .filename {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 8px;
}

#result-image .btn {
  display: block;
  margin: 12px auto 0;
}

/* 图像网格 */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.image-grid-item {
  text-align: center;
}

.image-grid-item img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-radius: 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.image-grid-item .label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* 文本结果 */
#result-text .content {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-size: 14px;
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 400px;
  overflow-y: auto;
}

#result-text .btn {
  margin-top: 12px;
}

/* ==================== 历史记录 ==================== */
.history-list {
  max-height: 400px;
  overflow-y: auto;
}

.history-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  transition: background var(--transition);
}

.history-item:last-child { border-bottom: none; }
.history-item:hover { background: var(--bg); }

.history-item .type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.history-copy-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-family: inherit;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.history-copy-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.type-image { background: #dbeafe; color: #1e40af; }
.type-text { background: #d1fae5; color: #065f46; }

/* ==================== 标签面板 ==================== */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ==================== 弹窗 ==================== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}

.modal-overlay.show { display: flex; }

.modal-panel {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 700px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg);
  font-size: 20px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.modal-close:hover {
  background: var(--border);
  color: var(--text);
}

.modal-body {
  padding: 20px 28px;
}

.modal-footer {
  display: flex;
  gap: 10px;
  padding: 16px 28px;
  border-top: 1px solid var(--border);
}

/* 构建器预览 */
.builder-preview {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.6;
  min-height: 60px;
  margin-top: 8px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* 余额弹窗 */
.balance-list { display: flex; flex-direction: column; gap: 8px; }
.balance-model {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--bg);
}
.balance-model-name {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}
.balance-prices { display: flex; flex-wrap: wrap; gap: 8px; }
.balance-prices span {
  font-size: 12px;
  background: var(--bg-card);
  padding: 3px 8px;
  border-radius: 4px;
  color: var(--text-secondary);
}

/* ==================== 响应式 ==================== */
@media (max-width: 820px) {
  .sidebar {
    width: 60px;
  }
  .sidebar-title,
  .sidebar-subtitle,
  .nav-label {
    display: none;
  }
  .sidebar-brand {
    padding: 16px 10px;
    display: flex;
    justify-content: center;
  }
  .sidebar-logo {
    margin-bottom: 0;
  }
  .sidebar-nav,
  .sidebar-footer {
    padding: 8px 6px;
    align-items: center;
  }
  .nav-btn {
    justify-content: center;
    padding: 10px;
  }
  .nav-icon {
    width: auto;
  }
  .main {
    padding: 24px 20px;
  }
}

@media (max-width: 640px) {
  .param-grid,
  .builder-select-grid {
    grid-template-columns: 1fr 1fr;
  }
  .panel-title {
    font-size: 20px;
  }
  .section-block {
    padding: 16px;
  }
  .modal-body {
    padding: 16px;
  }
  .modal-header,
  .modal-footer {
    padding: 16px;
  }
}
