:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #e6e9ee;
  --text: #1f2a37;
  --muted: #8a94a6;
  --muted-2: #aeb6c2;
  --brand: #14b8a6;
  --brand-dark: #0d9488;
  --brand-soft: #e6fbf7;
  --req: #ef4444;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 16px rgba(16, 24, 40, 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.page { max-width: 1240px; margin: 0 auto; padding: 24px 28px 56px; }

/* 顶部 */
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.brand-eyebrow {
  font-size: 11px;
  letter-spacing: 1.5px;
  color: var(--brand-dark);
  font-weight: 600;
}
.brand-title { margin: 4px 0 6px; font-size: 26px; font-weight: 700; }
.brand-desc { margin: 0; color: var(--muted); max-width: 720px; }
.brand-link {
  flex: none;
  color: var(--brand-dark);
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
}
.brand-link:hover { text-decoration: underline; }

/* 布局 */
.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 22px;
  align-items: start;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

/* 左侧 */
.panel-head, .card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.panel-head h2 { margin: 0; font-size: 16px; }
.card-head h3 { margin: 0; font-size: 14px; }

.field { margin-bottom: 16px; }
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}
.req { color: var(--req); font-weight: 600; font-size: 11px; margin-left: 4px; }

input[type="text"],
input[type="password"],
textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: #fbfcfd;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
  background: #fff;
}
textarea { resize: vertical; }

.inline { display: flex; gap: 8px; }
.inline input { flex: 1; }

.hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
.hint.subtle { color: var(--muted-2); margin-top: 2px; }

.card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  background: #fcfdfe;
}

.upload-row { margin: 10px 0; }
.upload-label { cursor: pointer; display: inline-flex; align-items: center; }

.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.thumb {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .del {
  position: absolute;
  top: 2px; right: 2px;
  width: 16px; height: 16px;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,.6);
  color: #fff;
  font-size: 11px;
  line-height: 16px;
  cursor: pointer;
  padding: 0;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.advanced {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 16px;
  background: #fbfcfd;
}
.advanced summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  list-style: none;
}
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary::before { content: "▸ "; color: var(--muted); }
.advanced[open] summary::before { content: "▾ "; }

/* 按钮 */
.primary-btn {
  width: 100%;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  cursor: pointer;
  transition: opacity .15s, transform .05s;
}
.primary-btn:hover { opacity: .92; }
.primary-btn:active { transform: translateY(1px); }
.primary-btn:disabled { opacity: .6; cursor: not-allowed; }

.ghost-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.ghost-btn:hover { border-color: var(--brand); color: var(--brand-dark); }

.link-btn {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.link-btn:hover { color: var(--brand-dark); }

/* 右侧 */
.tabs { display: flex; gap: 18px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab {
  border: none;
  background: none;
  padding: 6px 2px 12px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.active { color: var(--text); font-weight: 600; border-bottom-color: var(--brand); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.result-title { margin: 0 0 4px; font-size: 16px; }
.result-sub { margin: 0 0 16px; color: var(--muted); font-size: 13px; }

.result-area {
  min-height: 420px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #fcfdfe;
}
.placeholder { text-align: center; }
.placeholder-title { font-size: 18px; font-weight: 600; margin-bottom: 12px; }
.placeholder-text { color: var(--muted); font-size: 13px; max-width: 360px; margin: 0 auto; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  width: 100%;
}
.result-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}
.result-card img { width: 100%; display: block; }
.result-card .actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
}
.result-card .actions a {
  color: var(--brand-dark);
  text-decoration: none;
  font-size: 13px;
}

/* loading */
.loading { text-align: center; color: var(--muted); }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--brand-soft);
  border-top-color: var(--brand);
  border-radius: 50%;
  margin: 0 auto 14px;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-box {
  width: 100%;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

.label-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.prompt-tools { display: flex; align-items: center; gap: 6px; }
.prompt-tools select {
  width: auto;
  padding: 3px 6px;
  font-size: 12px;
  border-radius: 6px;
  background: #fff;
}
.opt-btn { color: var(--brand-dark); font-weight: 600; white-space: nowrap; }
.opt-btn:disabled { opacity: .6; cursor: default; }

.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.checkbox-row input { width: auto; }

/* 流式进度卡片 */
.stream-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  display: flex;
  flex-direction: column;
}
.stream-img-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #f3f5f8;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stream-img-wrap img { width: 100%; height: 100%; object-fit: contain; display: block; }
.stream-img-wrap .empty { color: var(--muted-2); font-size: 13px; }
.stream-badge {
  position: absolute;
  top: 8px; left: 8px;
  background: rgba(17, 24, 39, .7);
  color: #fff;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
}
.stream-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.stream-status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--brand);
  animation: pulse 1s ease-in-out infinite;
}
.stream-status.done .dot { background: #22c55e; animation: none; }
.stream-status.error { color: #b91c1c; }
.stream-status.error .dot { background: #ef4444; animation: none; }
.stream-status a { margin-left: auto; color: var(--brand-dark); text-decoration: none; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.history-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.history-actions { display: flex; gap: 8px; flex: none; }

.history-card { position: relative; }
.history-card .hc-check {
  position: absolute;
  top: 8px; left: 8px;
  width: 20px; height: 20px;
  cursor: pointer;
  z-index: 2;
  accent-color: var(--brand);
}
.history-card.selected { outline: 2px solid var(--brand); outline-offset: -2px; }

.history-area { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.history-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}
.history-card .hc-img { width: 100%; aspect-ratio: 1/1; object-fit: cover; cursor: zoom-in; display: block; background: #f3f5f8; }
.history-card .hc-meta { padding: 8px 10px; }
.history-card .hc-prompt {
  font-size: 12px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 6px;
  min-height: 32px;
}
.history-card .hc-actions { display: flex; gap: 10px; align-items: center; }
.history-card .hc-actions a, .history-card .hc-actions button {
  font-size: 12px;
  color: var(--brand-dark);
  text-decoration: none;
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
}
.history-card .hc-actions .del { color: #ef4444; margin-left: auto; }

/* 让生成结果图也可点击放大 */
.result-card img, .stream-img-wrap img { cursor: zoom-in; }

/* 灯箱 */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 32px;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 92vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.lb-close {
  position: absolute;
  top: 18px; right: 24px;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,.12);
  color: #fff;
  font-size: 24px;
  line-height: 40px;
  cursor: pointer;
}
.lb-close:hover { background: rgba(255,255,255,.25); }
.lb-download {
  position: absolute;
  top: 22px; left: 24px;
  background: var(--brand);
  color: #fff;
  text-decoration: none;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 8px;
}
.lb-download:hover { background: var(--brand-dark); }
