/* ==========================================================================
   图像工作台 — 视觉规范
   中性灰底、白卡片、近黑主按钮、单一低饱和强调色。
   不使用渐变、光晕、玻璃拟态、emoji 或图标字体；图标走内联 SVG。
   ========================================================================== */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --surface-3: #f2f4f6;
  --border: #e2e5e9;
  --border-strong: #cfd4da;
  --text: #1c2024;
  --text-2: #5c6570;
  --text-3: #8a929c;
  --ink: #1f2328;
  --ink-hover: #000000;
  --accent: #2f6bd8;
  --accent-weak: #eaf1fc;
  --danger: #b42318;
  --danger-weak: #fef3f2;
  --success: #0f7b4f;
  --success-weak: #ecf7f0;
  --warning: #8a5a00;
  --warning-weak: #fdf6e7;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-2: 0 8px 24px rgba(16, 24, 40, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

code {
  font-family: var(--mono);
  font-size: 12px;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

a {
  color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- 布局 ---------- */

.shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: var(--ink);
  position: relative;
  flex: none;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 1px;
  background: #fff;
  opacity: 0.9;
}

.brand-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.brand-divider {
  width: 1px;
  height: 12px;
  background: var(--border-strong);
}

.brand-sub {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-2);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-3);
}

.status[data-state="online"] .status-dot {
  background: var(--success);
}

.status[data-state="warning"] .status-dot {
  background: var(--warning);
}

.status[data-state="offline"] .status-dot {
  background: var(--danger);
}

.layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 20px;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px;
  align-items: start;
}

.panel {
  position: sticky;
  top: 72px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-width: 0;
}

/* ---------- 表单 ---------- */

.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-1);
}

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

.field-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

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

.counter,
.hint {
  font-size: 12px;
  color: var(--text-3);
  font-weight: 400;
}

textarea {
  width: 100%;
  min-height: 132px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13px;
  line-height: 1.7;
  resize: vertical;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea::placeholder {
  color: var(--text-3);
}

textarea:hover {
  border-color: #b9c0c8;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}

.size-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.size-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  text-align: left;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.size-option:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.size-option[aria-checked="true"] {
  border-color: var(--ink);
  background: var(--surface-3);
}

.size-option-ratio {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}

.size-option-dims {
  font-size: 11px;
  color: var(--text-3);
  line-height: 1.4;
  font-family: var(--mono);
}

.custom-size details {
  border-top: 1px dashed var(--border);
  padding-top: 10px;
}

.custom-size summary {
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.custom-size summary::-webkit-details-marker {
  display: none;
}

.custom-size summary::before {
  content: "+";
  font-family: var(--mono);
  color: var(--text-3);
}

.custom-size details[open] summary::before {
  content: "−";
}

.custom-size-body {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.custom-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--text-2);
  font-weight: 400;
  flex: 1;
}

.custom-field input {
  width: 100%;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: var(--mono);
  font-size: 12px;
}

.custom-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}

.times {
  color: var(--text-3);
  padding-bottom: 6px;
}

.custom-size .hint {
  margin: 8px 0 0;
}

/* ---------- 按钮 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

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

.btn:active:not(:disabled) {
  transform: translateY(0.5px);
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--ink-hover);
  border-color: var(--ink-hover);
  color: #fff;
}

.btn-primary:disabled {
  background: #9aa0a7;
  border-color: #9aa0a7;
  color: #fff;
}

.btn-quiet {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text-2);
}

.btn-quiet:hover:not(:disabled) {
  color: var(--text);
}

.btn-danger {
  border-color: var(--border);
  background: var(--surface);
  color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-weak);
  border-color: #f1c4bf;
}

.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.btn-block {
  width: 100%;
  height: 38px;
}

.btn[aria-busy="true"] {
  pointer-events: none;
  opacity: 0.75;
}

.form-note {
  margin: -4px 0 0;
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.5;
}

.form-error {
  padding: 9px 11px;
  border: 1px solid #f1c4bf;
  border-radius: var(--radius-sm);
  background: var(--danger-weak);
  color: #7a271a;
  font-size: 12px;
  line-height: 1.6;
  word-break: break-word;
}

.form-error[hidden] {
  display: none;
}

/* ---------- 侧栏元信息 ---------- */

.meta-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow-1);
}

.meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--text-3);
  padding: 5px 0;
}

.meta-row + .meta-row {
  border-top: 1px solid var(--surface-3);
}

.meta-row code {
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta-row span:last-child {
  color: var(--text-2);
}

/* ---------- 区块 ---------- */

.section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 28px;
}

.section-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.section-note {
  font-size: 12px;
  color: var(--text-3);
}

.section-action {
  margin-left: auto;
}

/* ---------- 当前任务 ---------- */

.current {
  min-width: 0;
}

.task-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-1);
}

.task-card[data-status="failed"] {
  border-color: #f1c4bf;
}

.task-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.task-head-meta {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-3);
  font-family: var(--mono);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
}

.pill[data-tone="running"] {
  background: var(--accent-weak);
  color: #1d4ea8;
}

.pill[data-tone="success"] {
  background: var(--success-weak);
  color: var(--success);
}

.pill[data-tone="danger"] {
  background: var(--danger-weak);
  color: var(--danger);
}

.pill[data-tone="neutral"] {
  background: var(--surface-3);
  color: var(--text-2);
}

.pill-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.pill[data-tone="running"] .pill-dot {
  animation: pulse 1.4s ease-in-out infinite;
}

.task-body {
  display: grid;
  grid-template-columns: minmax(0, 420px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.task-body-single {
  grid-template-columns: minmax(0, 1fr);
}

.task-image {
  cursor: zoom-in;
}

.task-media {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  overflow: hidden;
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.task-media img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 460px;
  object-fit: contain;
  background: #0f1115;
}

.media-pending {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 20px;
  color: var(--text-3);
  font-size: 12px;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.task-info {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.task-prompt {
  margin: 0;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 132px;
  overflow: auto;
}

.task-sub {
  margin: 0;
  font-size: 12px;
  color: var(--text-3);
}

.task-error {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #f1c4bf;
  border-radius: var(--radius-sm);
  background: var(--danger-weak);
  color: #7a271a;
  font-size: 12px;
  line-height: 1.65;
  word-break: break-word;
}

.task-error code {
  display: block;
  margin-top: 4px;
  color: #9d3b2f;
  font-size: 11px;
}

.task-error-detail {
  margin: 6px 0 0;
  color: #9d3b2f;
  font-size: 11px;
  word-break: break-word;
}

.task-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
}

.empty {
  margin: 0;
  padding: 28px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-3);
  font-size: 13px;
  text-align: center;
  background: transparent;
}

/* ---------- 历史记录 ---------- */

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
  gap: 12px;
}

.history-item {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-1);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.history-open {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: #0f1115;
  aspect-ratio: 1 / 1;
  overflow: hidden;
}

.history-open img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.15s ease;
}

.history-open:hover img {
  opacity: 0.88;
}

.history-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 16px;
  border: 0;
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 12px;
  text-align: center;
}

.history-placeholder[data-status="failed"] {
  color: #7a271a;
  background: var(--danger-weak);
}

.history-placeholder-text {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.history-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  min-height: 34px;
}

.history-meta {
  font-size: 11px;
  color: var(--text-3);
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-3);
  flex: none;
}

.icon-btn:hover {
  border-color: var(--border);
  color: var(--danger);
  background: var(--surface-2);
}

.icon-btn svg {
  width: 14px;
  height: 14px;
}

.empty-panel {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 32px 20px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-3);
  font-size: 13px;
}

.empty-panel p {
  margin: 0;
}

.example-prompt {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.example-prompt:hover {
  color: #1d4ea8;
}

/* ---------- 预览弹层 ---------- */

.preview {
  width: min(1080px, 92vw);
  max-height: 88vh;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}

.preview::backdrop {
  background: rgba(16, 24, 40, 0.45);
}

.preview-inner {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(300px, 0.9fr);
  max-height: 88vh;
}

.preview-media {
  background: #0f1115;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  overflow: hidden;
}

.preview-media img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 88vh;
  object-fit: contain;
}

.preview-media .preview-error {
  padding: 32px;
  color: #f5d6d2;
  font-size: 13px;
  line-height: 1.7;
  text-align: center;
  max-width: 420px;
}

.preview-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  overflow: auto;
  max-height: 88vh;
}

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

.preview-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.preview-prompt {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow: auto;
}

.preview-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  margin: 0;
  font-size: 12px;
}

.preview-meta dt {
  color: var(--text-3);
}

.preview-meta dd {
  margin: 0;
  color: var(--text-2);
  font-family: var(--mono);
  word-break: break-all;
}

.preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
  padding-top: 8px;
}

.preview-delete {
  margin-left: auto;
}

/* ---------- 提示条 ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  background: #1f2328;
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow-2);
  z-index: 100;
  max-width: min(560px, calc(100vw - 40px));
}

.toast[hidden] {
  display: none;
}

/* ---------- 动效 ---------- */

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

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- 响应式 ---------- */

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 320px minmax(0, 1fr);
    gap: 16px;
  }

  .task-body {
    grid-template-columns: 1fr;
  }

  .preview-inner {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(200px, 55vh) minmax(0, 1fr);
  }

  .preview-media {
    min-height: 200px;
  }

  .preview-media img {
    max-height: 55vh;
  }
}

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

  .panel {
    position: static;
  }

  .history-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .topbar {
    padding: 0 16px;
  }

  .brand-sub {
    display: none;
  }

  .brand-divider {
    display: none;
  }
}

@media (max-width: 520px) {
  .size-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .task-head-meta {
    margin-left: 0;
    width: 100%;
  }
}