/* ─────────────────────────────────────────────────────────
   Reset & tokens
───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --pink:          #e91e8c;
  --purple:        #8b5cf6;
  --purple-dark:   #7c3aed;
  --teal:          #10b981;
  --charcoal:      #4b5563;
  --gray-text:     #6b7280;
  --gray-light:    #f3f4f6;
  --gray-border:   #e5e7eb;

  --grad-title:    linear-gradient(135deg, #e91e8c 0%, #9c27b0 100%);
  --grad-count:    linear-gradient(135deg, #ff512f 0%, #f09819 100%);
  --grad-quality:  linear-gradient(135deg, #f472b6 0%, #a855f7 100%);
  --grad-example:  linear-gradient(135deg, #f97316 0%, #ea580c 100%);
  --grad-select:   linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
  --grad-results:  linear-gradient(135deg, #fce4ec 0%, #fff9c4 50%, #f3e8ff 100%);

  --radius-card:  16px;
  --radius-sm:    10px;
  --radius-xs:    7px;
  --shadow-card:  0 2px 12px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.06);
}

html { font-size: 14px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background-color: #fefce8;
  background-image:
    radial-gradient(circle, rgba(0,0,0,.06) 1px, transparent 1px);
  background-size: 24px 24px;
  min-height: 100vh;
  color: #1f2937;
}

/* ─────────────────────────────────────────────────────────
   Layout  —  两列等高，右侧跟随左侧
───────────────────────────────────────────────────────── */
.app-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
  /* 不再 min-height:100vh，让两列各自由内容高度决定 */
  align-items: start;
}

/* ─────────────────────────────────────────────────────────
   LEFT — Settings card
───────────────────────────────────────────────────────── */
.settings-card {
  background: #fff;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  border: 1px solid rgba(255,255,255,.9);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-self: start;
}

/* Card header */
.sc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sc-title {
  font-size: 20px;
  font-weight: 800;
  background: var(--grad-title);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: .3px;
}
.sc-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Mode toggle */
.mode-toggle {
  display: flex;
  align-items: center;
  background: var(--gray-light);
  border-radius: 20px;
  padding: 3px;
  gap: 2px;
}
.mode-btn {
  border: none;
  border-radius: 16px;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--gray-text);
  background: transparent;
  transition: background .18s, color .18s, box-shadow .18s;
  white-space: nowrap;
}
.mode-btn.active {
  background: var(--purple);
  color: #fff;
  box-shadow: 0 2px 8px rgba(139,92,246,.45);
}

/* Gear button */
.gear-btn {
  background: none;
  border: 1px solid var(--gray-border);
  border-radius: 8px;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--gray-text);
  transition: background .15s, border-color .15s;
  flex-shrink: 0;
}
.gear-btn svg { width: 16px; height: 16px; }
.gear-btn:hover { background: var(--gray-light); border-color: #d1d5db; }

/* Section label */
.sc-section { display: flex; flex-direction: column; gap: 8px; }
.sc-label {
  font-size: 13px;
  font-weight: 700;
  color: #374151;
}

/* Textarea */
.textarea-box {
  position: relative;
  border: 1.5px solid #f9a8d4;
  border-radius: var(--radius-sm);
  background: #fff;
  transition: border-color .18s, box-shadow .18s;
}
.textarea-box:focus-within {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px rgba(233,30,140,.1);
}
.textarea-box textarea {
  width: 100%;
  min-height: 110px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 14px 28px;
  font-size: 13px;
  color: #374151;
  background: transparent;
  resize: vertical;
  font-family: inherit;
  line-height: 1.6;
  outline: none;
}
.textarea-box textarea::placeholder { color: #9ca3af; }
.char-counter {
  position: absolute;
  bottom: 8px;
  right: 12px;
  font-size: 11px;
  color: #9ca3af;
  pointer-events: none;
}

/* Action row */
.action-row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.btn-clear {
  display: flex; align-items: center; gap: 5px;
  border: 1.5px solid var(--gray-border);
  background: #fff;
  color: var(--gray-text);
  border-radius: 20px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn-clear:hover { background: var(--gray-light); border-color: #d1d5db; }

.btn-example {
  display: flex; align-items: center; gap: 5px;
  background: var(--grad-example);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 7px 18px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(249,115,22,.4);
  transition: opacity .18s, transform .1s;
}
.btn-example:hover { opacity: .9; }
.btn-example:active { transform: scale(.97); }

/* Style pills (txt2img) */
.style-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.style-pill {
  border: 1.5px solid var(--gray-border);
  background: #fff;
  color: var(--gray-text);
  border-radius: 16px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .16s;
}
.style-pill:hover { border-color: var(--purple); color: var(--purple); }
.style-pill.active {
  background: var(--grad-quality);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 1px 6px rgba(168,85,247,.4);
}

/* Reference upload */
.ref-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.ref-badge {
  background: var(--gray-light);
  color: var(--gray-text);
  border-radius: 10px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 600;
}

.upload-zone {
  border: 2px dashed #f9a8d4;
  border-radius: var(--radius-sm);
  background: #fff;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  transition: border-color .18s, background .18s;
  cursor: pointer;
  width: 100%;
}
.upload-zone.drag-over {
  border-color: var(--pink);
  background: #fdf2f8;
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 28px 20px;
  text-align: center;
  width: 100%;
}
.upload-cloud-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}
.upload-cloud-icon svg { width: 56px; height: 56px; }
.upload-text {
  font-size: 14px;
  color: #6b7280;
  font-weight: 500;
  white-space: nowrap;
}
.upload-hint {
  font-size: 12px;
  color: #9ca3af;
  white-space: nowrap;
}

.btn-select-file {
  background: var(--grad-select);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 9px 28px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(139,92,246,.4);
  transition: opacity .18s, transform .1s;
}
.btn-select-file:hover { opacity: .9; }
.btn-select-file:active { transform: scale(.97); }

.upload-thumbs {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
}

/* 单张图铺满上传区 */
.thumb-full-wrap {
  position: relative;
  width: 100%;
  height: 100%;
}
.thumb-full {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: calc(var(--radius-sm) - 2px);
}
.thumb-full-remove {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0,0,0,.55);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background .15s;
}
.thumb-full-remove:hover { background: rgba(0,0,0,.75); }

/* ─────────────────────────────────────────────────────────
   RIGHT area  —  高度跟随左侧，用 JS 动态写 min-height
───────────────────────────────────────────────────────── */
.right-area {
  display: flex;
  flex-direction: column;
  gap: 16px;
  /* min-height 由 JS syncHeight() 注入，保证与左侧等高 */
}

/* Controls bar */
.controls-bar {
  background: #fff;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  border: 1px solid rgba(255,255,255,.9);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 28px;
}

.ctrl-group {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ctrl-label {
  font-size: 13px;
  font-weight: 700;
  color: #374151;
  white-space: nowrap;
}

/* Count pills */
.count-pills {
  display: flex;
  gap: 6px;
}
.count-pill {
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1.5px solid var(--gray-border);
  background: var(--gray-light);
  color: var(--gray-text);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all .16s;
  display: flex; align-items: center; justify-content: center;
}
.count-pill:hover { border-color: #f97316; color: #f97316; }
.count-pill.active {
  background: var(--grad-count);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 10px rgba(255,81,47,.4);
}

/* Quality pills */
.quality-pills {
  display: flex;
  gap: 6px;
}
.quality-pill {
  height: 40px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1.5px solid var(--gray-border);
  background: var(--gray-light);
  color: var(--gray-text);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all .16s;
  display: flex; align-items: center; justify-content: center;
}
.quality-pill:hover { border-color: var(--purple); color: var(--purple); }
.quality-pill.active {
  background: var(--grad-quality);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 10px rgba(168,85,247,.4);
}

/* Ratio dropdown */
.ratio-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.ratio-wrap select {
  appearance: none;
  -webkit-appearance: none;
  height: 40px;
  padding: 0 36px 0 14px;
  border: 1.5px solid var(--gray-border);
  border-radius: 10px;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  cursor: pointer;
  outline: none;
  font-family: inherit;
  transition: border-color .16s;
}
.ratio-wrap select:focus { border-color: var(--purple); }
.ratio-arrow {
  position: absolute;
  right: 10px;
  width: 16px; height: 16px;
  color: var(--gray-text);
  pointer-events: none;
}

/* Generate button */
.btn-generate {
  margin-left: auto;
  display: flex; align-items: center; gap: 6px;
  background: var(--charcoal);
  color: #fff;
  border: none;
  border-radius: 10px;
  height: 40px;
  padding: 0 22px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background .18s, transform .1s;
  box-shadow: 0 2px 8px rgba(75,85,99,.35);
  font-family: inherit;
}
.btn-generate:hover { background: #374151; }
.btn-generate:active { transform: scale(.97); }
.btn-generate:disabled { opacity: .45; cursor: not-allowed; transform: none; }

/* ─────────────────────────────────────────────────────────
   Results card  —  填满 right-area 剩余空间
───────────────────────────────────────────────────────── */
.results-card {
  background: var(--grad-results);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  border: 1px solid rgba(255,255,255,.7);
  flex: 1;          /* 撑满 right-area 减去 controls-bar 后的剩余高度 */
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  /* 无固定 min-height，由父容器高度控制 */
}

.rc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 14px;
  flex-shrink: 0;
}
.rc-title {
  font-size: 17px;
  font-weight: 800;
  background: var(--grad-title);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.rc-tabs {
  display: flex;
  gap: 8px;
}
.rc-tab {
  border-radius: 20px;
  padding: 7px 18px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all .16s;
  font-family: inherit;
}
.rc-tab.active {
  background: var(--teal);
  color: #fff;
  border: none;
  box-shadow: 0 2px 10px rgba(16,185,129,.4);
}
.rc-tab.plain {
  background: transparent;
  color: var(--gray-text);
  border: 1.5px solid var(--gray-border);
}
.rc-tab.plain:hover { border-color: var(--teal); color: var(--teal); }

/* Empty state */
.rc-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 40px;
  text-align: center;
}
.empty-icon svg { color: #c9d0da; }
.empty-title {
  font-size: 20px;
  font-weight: 800;
  color: #374151;
}
.empty-desc {
  font-size: 13px;
  color: #9ca3af;
  max-width: 320px;
  line-height: 1.7;
}

/* Loading */
.rc-loading {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 14px;
  color: var(--gray-text);
}
.spin-ring {
  width: 44px; height: 44px;
  border: 3px solid rgba(233,30,140,.2);
  border-top-color: var(--pink);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Result grid —— 铺满可用空间 */
.rc-grid {
  flex: 1;           /* 占据 results-card 中 header 以外的全部高度 */
  display: grid;
  gap: 12px;
  padding: 0 16px 16px;
  /* 列数由 JS 动态写 grid-template-columns / grid-template-rows */
  align-content: stretch;
  justify-content: stretch;
  overflow: hidden;
}

/* Result card —— 填满网格单元格，不固定 aspect-ratio */
.result-card {
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  background: rgba(255,255,255,.6);
  border: 1px solid rgba(255,255,255,.8);
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
  /* 高度由网格行高决定，图片铺满单元格 */
  transition: transform .2s, box-shadow .2s;
  min-height: 0;
}
.result-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,.14); }
.result-card img {
  width: 100%; height: 100%;
  object-fit: cover; display: block;
}
.result-card-actions {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,.65));
  padding: 24px 10px 10px;
  display: flex; gap: 6px; justify-content: flex-end;
  opacity: 0; transition: opacity .2s;
}
.result-card:hover .result-card-actions { opacity: 1; }
.result-card-actions button {
  background: rgba(255,255,255,.92);
  border: none; border-radius: 6px;
  padding: 4px 10px; font-size: 11px;
  cursor: pointer; color: #1f2937; font-weight: 700;
  transition: background .15s;
}
.result-card-actions button:hover { background: #fff; }

/* Decorative orb */
.deco-orb {
  position: absolute;
  bottom: -30px; right: -30px;
  width: 120px; height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(6,182,212,.5), rgba(14,165,233,.2));
  pointer-events: none;
  filter: blur(20px);
}

/* ─────────────────────────────────────────────────────────
   Settings dialog
───────────────────────────────────────────────────────── */
.overlay {
  display: none;
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(5px);
  align-items: center; justify-content: center;
}
.overlay.open { display: flex; }

.dialog {
  background: #fff;
  border-radius: var(--radius-card);
  width: 440px; max-width: 92vw;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  overflow: hidden;
}
.dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-border);
  font-size: 15px; font-weight: 700;
}
.dialog-close {
  background: none; border: none; font-size: 17px;
  cursor: pointer; color: var(--gray-text);
  padding: 3px 7px; border-radius: 4px;
}
.dialog-close:hover { background: var(--gray-light); }
.dialog-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.form-row { display: flex; flex-direction: column; gap: 5px; }
.form-row label { font-size: 12px; font-weight: 700; color: var(--gray-text); }
.form-row input,
.form-row select {
  border: 1.5px solid var(--gray-border);
  border-radius: var(--radius-xs);
  padding: 9px 12px; font-size: 13px; color: #1f2937;
  width: 100%; font-family: inherit;
  transition: border-color .18s;
  background: #fff;
}
.form-row input:focus,
.form-row select:focus { outline: none; border-color: var(--purple); box-shadow: 0 0 0 3px rgba(139,92,246,.12); }
.dialog-foot {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 13px 20px;
  border-top: 1px solid var(--gray-border);
  background: var(--gray-light);
}
.btn-cancel {
  background: #fff; border: 1.5px solid var(--gray-border);
  border-radius: 20px; padding: 7px 18px;
  font-size: 13px; font-weight: 600; color: var(--gray-text);
  cursor: pointer; font-family: inherit;
}
.btn-cancel:hover { background: var(--gray-light); }
.btn-save {
  background: var(--grad-quality);
  border: none; border-radius: 20px; padding: 7px 22px;
  font-size: 13px; font-weight: 700; color: #fff;
  cursor: pointer; font-family: inherit;
  box-shadow: 0 2px 8px rgba(168,85,247,.4);
}
.btn-save:hover { opacity: .9; }

/* Custom model management */
.custom-model-add { display: flex; gap: 6px; }
.custom-model-add input {
  flex: 1; min-width: 0;
  padding: 7px 10px;
  border: 1.5px solid var(--gray-border); border-radius: 8px;
  font-size: 13px; font-family: inherit;
}
.custom-model-add input:focus { outline: none; border-color: var(--purple); box-shadow: 0 0 0 3px rgba(139,92,246,.12); }
.btn-custom-add {
  background: var(--grad-quality); color: #fff; border: none;
  border-radius: 8px; padding: 0 14px;
  font-size: 13px; font-weight: 700; cursor: pointer; font-family: inherit;
  white-space: nowrap;
}
.btn-custom-add:hover { opacity: .9; }
.custom-model-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.custom-model-list:empty { display: none; }
.custom-model-tag {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--gray-light); border: 1px solid var(--gray-border);
  border-radius: 14px; padding: 3px 6px 3px 10px;
  font-size: 12px; color: var(--gray-text);
}
.custom-model-tag .tag-remove {
  background: transparent; border: none; cursor: pointer;
  width: 18px; height: 18px; border-radius: 50%;
  font-size: 14px; line-height: 1; color: var(--gray-text);
  display: inline-flex; align-items: center; justify-content: center;
}
.custom-model-tag .tag-remove:hover { background: #fee2e2; color: #dc2626; }
.custom-model-hint { font-size: 11px; color: var(--gray-text); opacity: .7; margin-top: 2px; }

/* ─────────────────────────────────────────────────────────
   Image preview modal
───────────────────────────────────────────────────────── */
.img-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 400;
  align-items: center; justify-content: center;
}
.img-overlay.open { display: flex; }
.img-bg {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.82);
  backdrop-filter: blur(8px);
}
.img-box {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  max-width: min(88vw, 860px); max-height: 92vh;
}
.img-close {
  position: absolute; top: -44px; right: 0;
  background: rgba(255,255,255,.15); border: none; color: #fff;
  font-size: 17px; width: 36px; height: 36px; border-radius: 50%;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.img-close:hover { background: rgba(255,255,255,.28); }
.img-preview {
  max-width: 100%; max-height: calc(92vh - 90px);
  border-radius: var(--radius-card);
  box-shadow: 0 24px 72px rgba(0,0,0,.5);
  display: block;
}
.btn-dl-preview {
  background: var(--grad-quality); color: #fff; border: none;
  border-radius: 20px; padding: 9px 24px; font-size: 14px; font-weight: 700;
  cursor: pointer; font-family: inherit;
  box-shadow: 0 2px 10px rgba(168,85,247,.4);
}

/* ─────────────────────────────────────────────────────────
   Toast
───────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 32px; left: 50%;
  transform: translateX(-50%) translateY(70px);
  background: rgba(31,41,55,.92); color: #fff;
  padding: 9px 22px; border-radius: 22px;
  font-size: 13px; font-weight: 600; z-index: 500;
  transition: transform .28s cubic-bezier(.34,1.56,.64,1);
  pointer-events: none; white-space: nowrap;
  opacity: 0;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ─────────────────────────────────────────────────────────
   Generating lock overlay
───────────────────────────────────────────────────────── */
.gen-lock {
  display: none;
  position: fixed; inset: 0; z-index: 600;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  justify-content: center; align-items: center;
}
.gen-lock.open { display: flex; }
.gen-lock-card {
  background: #fff; border-radius: 18px;
  padding: 36px 40px; text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,.18);
  max-width: 340px; width: 90%;
  animation: lockFadeIn .25s ease;
}
@keyframes lockFadeIn {
  from { opacity: 0; transform: scale(.92); }
  to   { opacity: 1; transform: scale(1); }
}
.gen-lock-card .spin-ring { margin: 0 auto 16px; }
.gen-lock-title {
  font-size: 16px; font-weight: 700; color: #1f2937;
  margin: 0 0 6px;
}
.gen-lock-desc {
  font-size: 13px; color: #6b7280;
  margin: 0 0 20px; line-height: 1.5;
}
.gen-lock-bg-btn {
  display: inline-block; padding: 8px 28px;
  border: 1.5px solid #d1d5db; border-radius: 10px;
  background: #fff; color: #374151;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all .18s;
}
.gen-lock-bg-btn:hover {
  background: #f3f4f6; border-color: #9ca3af;
}

/* ─────────────────────────────────────────────────────────
   Responsive
───────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .app-layout { grid-template-columns: 1fr; padding: 12px; }
  .controls-bar { flex-wrap: wrap; gap: 14px; }
  .btn-generate { margin-left: 0; }
}

/* ─────────────────────────────────────────────────────────
   History panel — 独立整块，铺满下方
───────────────────────────────────────────────────────── */
.history-panel {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px 32px;
}
.hp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.hp-title {
  font-size: 18px;
  font-weight: 800;
  background: var(--grad-title);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hp-empty {
  background: #fff;
  border: 1.5px dashed var(--gray-border);
  border-radius: var(--radius-card);
  padding: 48px 20px;
  text-align: center;
  color: #9ca3af;
  font-size: 14px;
}

/* History toolbar / search / filter */
.rc-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}
.hist-search {
  width: 260px;
  max-width: 60vw;
  border: 1.5px solid var(--gray-border);
  border-radius: 20px;
  padding: 7px 14px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  outline: none;
  transition: border-color .16s, box-shadow .16s;
}
.hist-search:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(139,92,246,.12); }
.rc-tool-btn {
  border: 1.5px solid var(--gray-border);
  background: #fff;
  color: var(--gray-text);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: all .16s;
}
.rc-tool-btn:hover { border-color: var(--purple); color: var(--purple); }
.rc-tool-btn.active {
  background: var(--grad-select);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(139,92,246,.4);
}

/* ─────────────────────────────────────────────────────────
   Queue progress bar
───────────────────────────────────────────────────────── */
.queue-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 22px 12px;
  padding: 8px 14px;
  background: rgba(255,255,255,.9);
  border: 1px solid var(--gray-border);
  border-radius: 12px;
  flex-shrink: 0;
}
.q-title { font-size: 12px; font-weight: 700; color: #374151; white-space: nowrap; }
.q-chips { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.q-chip {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--gray-border);
  transition: background .2s;
}
.q-chip.running { background: var(--purple); animation: qpulse .9s ease-in-out infinite; }
.q-chip.done    { background: var(--teal); }
.q-chip.error   { background: #ef4444; }
.q-chip.canceled{ background: #9ca3af; }
@keyframes qpulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }
.q-cancel {
  border: 1.5px solid #fca5a5; background: #fff; color: #dc2626;
  border-radius: 16px; padding: 4px 14px; font-size: 12px; font-weight: 700;
  cursor: pointer; white-space: nowrap; font-family: inherit;
}
.q-cancel:hover { background: #fee2e2; }

/* ─────────────────────────────────────────────────────────
   History gallery
───────────────────────────────────────────────────────── */
.rc-history {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
  align-content: start;
}
.hist-card {
  background: rgba(255,255,255,.75);
  border: 1.5px solid rgba(255,255,255,.9);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.07);
  transition: transform .18s, box-shadow .18s, border-color .18s;
  display: flex;
  flex-direction: column;
}
.hist-card:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(0,0,0,.13); }
.hist-card.selected { border-color: var(--purple); box-shadow: 0 0 0 2px rgba(139,92,246,.4); }
.hist-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  background: #f3f4f6;
  cursor: pointer;
  overflow: hidden;
}
.hist-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hist-fav {
  position: absolute; top: 6px; right: 6px;
  width: 26px; height: 26px; border-radius: 50%;
  border: none; background: rgba(0,0,0,.4); color: rgba(255,255,255,.7);
  font-size: 14px; cursor: pointer; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(3px); transition: all .15s;
}
.hist-fav:hover { background: rgba(0,0,0,.6); }
.hist-fav.on { color: #fbbf24; background: rgba(0,0,0,.5); }
.hist-sel {
  position: absolute; top: 6px; left: 6px;
  width: 22px; height: 22px; border-radius: 6px;
  border: 2px solid #fff; background: rgba(0,0,0,.25);
  color: #fff; font-size: 13px; font-weight: 800;
  display: none; align-items: center; justify-content: center;
}
.rc-history.selectmode .hist-sel { display: flex; }
.hist-card.selected .hist-sel { background: var(--purple); }
.hist-meta { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 6px; }
.hist-prompt {
  font-size: 12px; color: #374151; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.hist-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.ht-tag {
  font-size: 10px; font-weight: 600; color: var(--gray-text);
  background: var(--gray-light); border-radius: 8px; padding: 1px 7px;
}
.hist-actions { display: flex; gap: 4px; margin-top: 2px; }
.ha-btn {
  flex: 1;
  border: 1px solid var(--gray-border); background: #fff;
  border-radius: 7px; padding: 5px 0; font-size: 13px; cursor: pointer;
  transition: all .14s; line-height: 1;
}
.ha-btn:hover { border-color: var(--purple); background: #faf5ff; }
.ha-del:hover { border-color: #fca5a5; background: #fee2e2; }

/* ─────────────────────────────────────────────────────────
   Selection bar
───────────────────────────────────────────────────────── */
.selection-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  bottom: 16px;
  margin-top: 16px;
  padding: 10px 16px;
  background: rgba(31,41,55,.94);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
}
.sel-count { color: #fff; font-size: 13px; font-weight: 700; white-space: nowrap; }
.sel-actions { display: flex; gap: 8px; }
.sel-actions button {
  border: none; border-radius: 16px; padding: 6px 14px;
  font-size: 12px; font-weight: 700; cursor: pointer;
  background: rgba(255,255,255,.16); color: #fff;
  font-family: inherit; transition: background .15s;
}
.sel-actions button:hover { background: rgba(255,255,255,.28); }
.sel-actions .sel-danger { background: rgba(239,68,68,.85); }
.sel-actions .sel-danger:hover { background: #ef4444; }

/* ─────────────────────────────────────────────────────────
   Settings: connection mode / model refresh / test
───────────────────────────────────────────────────────── */
.conn-seg {
  display: inline-flex;
  background: var(--gray-light);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
  width: fit-content;
}
.conn-seg button {
  border: none; background: transparent;
  border-radius: 8px; padding: 6px 20px;
  font-size: 13px; font-weight: 600; color: var(--gray-text);
  cursor: pointer; font-family: inherit; transition: all .16s;
}
.conn-seg button.active {
  background: var(--purple); color: #fff;
  box-shadow: 0 2px 6px rgba(139,92,246,.4);
}
.model-row { display: flex; gap: 6px; }
.model-row input { flex: 1; min-width: 0; }
.btn-refresh-models {
  white-space: nowrap;
  border: 1.5px solid var(--gray-border); background: #fff;
  color: var(--purple); border-radius: 8px; padding: 0 12px;
  font-size: 12px; font-weight: 700; cursor: pointer; font-family: inherit;
  transition: all .15s;
}
.btn-refresh-models:hover { border-color: var(--purple); background: #faf5ff; }
.btn-test-conn {
  width: 100%;
  border: 1.5px solid var(--gray-border); background: #fff;
  color: #374151; border-radius: 8px; padding: 9px 0;
  font-size: 13px; font-weight: 700; cursor: pointer; font-family: inherit;
  transition: all .15s;
}
.btn-test-conn:hover { border-color: var(--purple); background: #faf5ff; }
.test-result { font-size: 12px; color: var(--gray-text); min-height: 16px; line-height: 1.5; }

/* ─────────────────────────────────────────────────────────
   Multi-reference thumbnails
───────────────────────────────────────────────────────── */
.upload-thumbs.multi {
  position: static;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  align-content: flex-start;
}
.thumb-mini {
  position: relative;
  width: calc(50% - 4px);
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--gray-border);
}
.thumb-mini img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-mini-remove {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  border: none; background: rgba(0,0,0,.55); color: #fff;
  font-size: 12px; cursor: pointer; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.thumb-mini-remove:hover { background: rgba(0,0,0,.8); }
.thumb-add {
  width: calc(50% - 4px);
  aspect-ratio: 1 / 1;
  border: 2px dashed #d8b4fe;
  border-radius: 8px;
  background: #faf5ff;
  color: var(--purple);
  font-size: 28px; font-weight: 300;
  cursor: pointer;
  transition: all .15s;
}
.thumb-add:hover { border-color: var(--purple); background: #f3e8ff; }
