:root {
  --bg: #f5f2eb;
  --bg-darker: #e8e3db;
  --panel: #ffffff;
  --panel-border: rgba(109, 80, 46, 0.12);
  --text: #2d2118;
  --text-muted: #7a6a5a;
  --accent: #8b5e34;
  --accent-strong: #6f451f;
  --accent-light: rgba(139, 94, 52, 0.1);
  --success: #5a9a5a;
  --warning: #d4a855;
  --shadow-sm: 0 2px 8px rgba(70, 44, 12, 0.08);
  --shadow-md: 0 8px 24px rgba(70, 44, 12, 0.12);
  --shadow-lg: 0 16px 48px rgba(70, 44, 12, 0.16);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
}

* {
  box-sizing: border-box;
}

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

button,
input,
select,
textarea {
  font: inherit;
  cursor: pointer;
}

/* 工作台容器 */
.workspace {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ========== 顶部工具栏 ========== */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
  display: flex;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  color: var(--accent-strong);
}

.mode-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: var(--radius-lg);
}

.mode-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-md);
  transition: all 150ms ease;
}

.mode-tab svg {
  opacity: 0.7;
}

.mode-tab:hover {
  background: var(--panel);
  color: var(--text);
}

.mode-tab.active {
  background: var(--panel);
  color: var(--accent-strong);
  box-shadow: var(--shadow-sm);
}

.mode-tab.active svg {
  opacity: 1;
}

.quota-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--accent-light);
  color: var(--accent-strong);
  border-radius: var(--radius-lg);
  font-size: 13px;
  font-weight: 600;
}

/* ========== 主体区域 ========== */
.workspace-body {
  display: grid;
  grid-template-columns: 280px 1fr 360px;
  flex: 1;
  gap: 0;
  overflow: hidden;
}

/* ========== 左侧边栏 ========== */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--panel-border);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* 任务队列 */
.task-queue {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: var(--radius-md);
  transition: all 150ms ease;
}

.task-item.active {
  background: var(--accent-light);
  border: 1px solid var(--accent);
}

.task-status {
  display: flex;
  align-items: center;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-dot.generating {
  background: var(--warning);
  animation: pulse 1s infinite;
}

.status-dot.pending {
  background: var(--text-muted);
  opacity: 0.5;
}

.status-dot.done {
  background: var(--success);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.task-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.task-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.task-progress {
  font-size: 11px;
  color: var(--text-muted);
}

.task-cancel {
  padding: 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 150ms;
}

.task-item:hover .task-cancel {
  opacity: 1;
}

.task-cancel:hover {
  color: #c44;
}

.task-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
}

.task-empty p {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 500;
}

.task-empty span {
  font-size: 12px;
  opacity: 0.7;
}

/* 快速预设 */
.preset-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.preset-item {
  padding: 10px 12px;
  border: 1px solid var(--panel-border);
  background: var(--bg);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text);
  text-align: left;
  transition: all 150ms ease;
}

.preset-item:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

/* ========== 中央画布 ========== */
.canvas-area {
  display: flex;
  flex-direction: column;
  background: var(--bg-darker);
  overflow: hidden;
}

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

.canvas-tabs {
  display: flex;
  gap: 4px;
}

.canvas-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: all 150ms ease;
}

.canvas-tab:hover {
  background: var(--bg);
}

.canvas-tab.active {
  background: var(--accent);
  color: #fff;
}

.canvas-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  transition: all 150ms ease;
}

.icon-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* 画布舞台 */
.canvas-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px;
  overflow: auto;
  position: relative;
}

.canvas-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  text-align: center;
}

.canvas-empty svg {
  opacity: 0.3;
}

.canvas-empty p {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.canvas-empty span {
  font-size: 13px;
  opacity: 0.6;
}

/* 对比滑块视图 */
.compare-slider {
  flex: 1;
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: var(--panel);
}

.compare-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.compare-result {
  z-index: 1;
}

.compare-source {
  z-index: 2;
  clip-path: inset(0 50% 0 0);
}

.compare-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 4px;
  transform: translateX(-50%);
  z-index: 3;
  cursor: ew-resize;
}

.handle-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  background: #fff;
  transform: translateX(-50%);
  box-shadow: 0 0 8px rgba(0,0,0,0.3);
}

.handle-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  background: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
  color: var(--text);
  transition: transform 0.15s ease;
}

.handle-knob:hover {
  transform: translate(-50%, -50%) scale(1.1);
}

.compare-labels {
  position: absolute;
  bottom: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  z-index: 4;
  pointer-events: none;
}

.compare-labels span {
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  backdrop-filter: blur(4px);
}

.pane-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 12px;
  color: var(--text-muted);
  text-align: center;
  z-index: 0;
}

.pane-empty p {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.pane-empty span {
  font-size: 13px;
  opacity: 0.7;
}

/* 进度条 */
.progress-bar {
  display: none;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  padding: 14px 18px;
  background: var(--panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.progress-bar.active {
  display: flex;
}

.progress-fill {
  flex: 1;
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill::after {
  content: '';
  display: block;
  width: var(--progress, 0%);
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--warning));
  border-radius: 4px;
  transition: width 300ms ease;
}

.progress-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

/* 移动端提示 */
.mobile-tip {
  display: none;
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  font-size: 13px;
  border-radius: var(--radius-lg);
  gap: 8px;
  align-items: center;
}

@media (max-width: 900px) {
  .mobile-tip {
    display: flex;
  }
}

/* ========== 右侧面板 ========== */
.panel-right {
  background: var(--panel);
  border-left: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-section {
  padding: 20px;
  border-bottom: 1px solid var(--panel-border);
  overflow-y: auto;
}

.panel-section-grow {
  flex: 1;
  border-bottom: none;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 16px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.text-btn {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 150ms ease;
}

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

/* 参数表单 */
.param-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.form-field label small {
  font-weight: 400;
  color: var(--text-muted);
}

.form-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-field input,
.form-field select,
.form-field textarea {
  padding: 10px 12px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  transition: border-color 150ms ease;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.form-field textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

.form-field small {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.style-field {
  display: none;
}

.style-field.visible {
  display: flex;
}

/* 上传预览图片 */
.upload-preview-img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  border-radius: var(--radius-md);
  display: block;
}

.file-upload.has-file {
  border-style: solid;
  border-color: var(--accent);
}

/* 图片放大预览 */
.image-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  cursor: zoom-out;
  animation: fadeIn 0.2s ease;
}

.image-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-md);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* 加载旋转动画 */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.spin {
  animation: spin 1s linear infinite;
}

/* 文件上传 */
.file-upload {
  position: relative;
  border: 2px dashed var(--panel-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: all 150ms ease;
}

.file-upload:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.file-upload input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  color: var(--text-muted);
  font-size: 13px;
}

.file-upload.has-file .upload-preview {
  display: none;
}

.file-upload.has-file::after {
  content: '';
  display: block;
  padding-bottom: 75%;
}

/* 高级参数 */
.advanced-toggle {
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.advanced-toggle summary {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  background: var(--bg);
}

.advanced-toggle summary:hover {
  color: var(--text);
}

.advanced-fields {
  padding: 14px;
  background: var(--panel);
}

/* 提交按钮 */
.submit-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 20px;
  border: none;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  transition: all 150ms ease;
}

.submit-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* 历史记录网格（水平滚动） */
.history-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  max-height: 280px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 150ms ease;
  background: var(--bg);
}

.history-item:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.history-item img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.history-item .item-overlay {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.history-item .item-mode {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item .item-time {
  font-size: 11px;
  color: var(--text-muted);
}

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

.history-empty p {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 500;
}

.history-empty span {
  font-size: 11px;
  opacity: 0.7;
}

/* ========== 响应式 ========== */
@media (max-width: 1200px) {
  .workspace-body {
    grid-template-columns: 240px 1fr 300px;
  }
}

@media (max-width: 900px) {
  .workspace-body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .toolbar {
    padding: 0 12px;
  }

  .mode-tab span {
    display: none;
  }

  .canvas-stage {
    padding: 12px;
  }

  .compare-view {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }

  .compare-divider {
    width: auto;
    height: 40px;
    flex-direction: row;
  }

  .divider-handle {
    flex-direction: row;
  }
}

/* ========== 空状态 ========== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: var(--text-muted);
}

.empty-state svg {
  opacity: 0.4;
}

.empty-state p {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

/* ========== 滚动条 ========== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--panel-border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}