:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --blue: #0284c7;
  --emerald: #059669;
  --pink: #db2777;
  --radius: 16px;
  --shadow: 0 4px 20px rgba(15, 23, 42, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: #eef2ff;
  color: var(--accent);
  display: grid;
  place-items: center;
}

.brand-mark svg {
  width: 20px;
  height: 20px;
}

.brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.brand p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-pill {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-muted);
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.workspace {
  flex: 1;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: minmax(290px, 360px) 220px minmax(360px, 1fr);
  gap: 20px;
  align-items: stretch;
}

/* 左侧三个方框 */
.panel-left {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.element-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.element-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.box-badge {
  font-size: 13px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
}

.element-box[data-accent="blue"] .box-badge {
  background: #e0f2fe;
  color: var(--blue);
}

.element-box[data-accent="emerald"] .box-badge {
  background: #d1fae5;
  color: var(--emerald);
}

.element-box[data-accent="pink"] .box-badge {
  background: #fce7f3;
  color: var(--pink);
}

.box-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.element-box textarea {
  width: 100%;
  resize: vertical;
  min-height: 76px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: #fafbfd;
  outline: none;
}

.element-box textarea:focus {
  background: var(--surface);
  border-color: var(--border-strong);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: #334155;
  font-size: 12px;
  padding: 4px 9px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.chip:hover {
  background: #e2e8f0;
  border-color: var(--border-strong);
}

/* 中间生成按钮区 */
.panel-middle {
  display: flex;
  align-items: center;
  justify-content: center;
}

.control-stack {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn-generate {
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 16px 14px;
  background: var(--accent);
  color: #ffffff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 8px 18px rgba(79, 70, 229, 0.25);
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn-generate:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-generate:disabled {
  opacity: 0.65;
  cursor: wait;
}

.btn-ghost {
  width: 100%;
  border: 1px dashed var(--border-strong);
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
}

.btn-ghost:hover {
  background: var(--surface-muted);
}

.mini-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 4px;
}

.mini-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
}

.mini-field select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fafbfd;
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.prompt-preview-box {
  margin-top: 4px;
  padding: 10px;
  border-radius: 10px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
}

.preview-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.preview-text {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: #334155;
  word-break: break-word;
}

/* 右侧图片展示区 */
.panel-right {
  display: flex;
}

.result-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.result-head h2 {
  margin: 0;
  font-size: 16px;
}

.result-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.btn-secondary,
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

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

.btn-secondary:hover:not(.disabled) {
  background: var(--surface-muted);
}

.btn-secondary.disabled {
  opacity: 0.45;
  pointer-events: none;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  border: none;
}

.image-stage {
  flex: 1;
  min-height: 420px;
  border-radius: 12px;
  border: 1px dashed var(--border-strong);
  background: #f8fafc;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 12px;
}

.empty-state,
.loading-state {
  text-align: center;
  color: var(--text-muted);
  max-width: 340px;
}

.empty-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 10px;
  color: #94a3b8;
}

.empty-title {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.empty-sub {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
}

.spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 12px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.result-image {
  max-width: 100%;
  max-height: 520px;
  border-radius: 10px;
  object-fit: contain;
  display: block;
}

.notice-banner {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 12px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
}

.history-wrap {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.link-btn {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
}

.link-btn:hover {
  color: var(--text);
}

.history-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.history-empty {
  font-size: 12px;
  color: #94a3b8;
}

.history-thumb {
  width: 64px;
  height: 48px;
  border-radius: 8px;
  border: 2px solid transparent;
  overflow: hidden;
  padding: 0;
  cursor: pointer;
  flex: 0 0 auto;
  background: var(--surface-muted);
}

.history-thumb.active {
  border-color: var(--accent);
}

.history-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* 弹窗 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.2);
  overflow: hidden;
}

.modal-head,
.modal-foot {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-foot {
  border-bottom: none;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

.modal-head h3 {
  margin: 0;
  font-size: 15px;
}

.icon-close {
  border: none;
  background: none;
  font-size: 22px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 70vh;
  overflow-y: auto;
}

.fieldset {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.fieldset-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
}

.field input,
.field select {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font: inherit;
  font-size: 13px;
  color: var(--text);
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .image-stage {
    min-height: 300px;
  }
}
