* { box-sizing: border-box; }

body {
  margin: 0 auto;
  max-width: 1400px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f7f3cf;
  color: #3f3f56;
  padding: 18px;
}

.dot { position: fixed; border-radius: 50%; opacity: .25; z-index: 0; pointer-events: none; }
.dot1 { width: 90px; height: 90px; background: #ffb8c6; left: 22px; top: 52px; }
.dot2 { width: 100px; height: 100px; background: #cdb4ff; left: 220px; bottom: 80px; }
.dot3 { width: 90px; height: 90px; background: #a0d8ff; right: 160px; top: 280px; }

.grid-main,
.card {
  position: relative;
  z-index: 1;
}

.brand { display: flex; align-items: center; gap: 10px; }
.banana {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #ffb48a, #f6d0ff);
  display: grid;
  place-items: center;
}
.brand h1 { margin: 0; color: #d65adf; }
.brand p { margin: 0; font-size: 12px; color: #5c6077; }
.top-actions { display: flex; gap: 10px; }

.btn { border: none; border-radius: 12px; padding: 10px 14px; cursor: pointer; }
.btn.soft { background: #dceee8; color: #2f7968; }
.btn.icon {
  background: #e8ddff;
  color: #7959df;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
}
.btn.icon svg { width: 18px; height: 18px; fill: currentColor; }
.btn.green { background: #c9f0da; color: #2c8b5a; }
.btn.gray { background: #ececf0; color: #666; }
.btn.orange { background: linear-gradient(90deg, #ff8b2c, #ff5db1); color: #fff; }
.btn.purple { background: linear-gradient(90deg, #d044c0, #7a53f2); color: #fff; }
.btn.cyan { background: #14b8b0; color: #fff; }

.grid-main {
  display: grid;
  grid-template-columns: 480px 1fr;
  gap: 16px;
  width: 100%;
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
}

.card {
  background: linear-gradient(135deg, #f7e9f2, #edf6ef);
  border: 1px solid #efdce9;
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .05);
}

/* 右侧卡片内边距一致，避免视觉错位 */
.card.right { padding: 18px; }

.title-row { display: flex; justify-content: space-between; align-items: center; }
.title-row h2 { margin: 0; color: #6a55ff; }

.switch {
  background: #fff;
  border: 1px solid #eed4e9;
  border-radius: 16px;
  padding: 4px;
  display: flex;
  gap: 4px;
}
.switch button {
  border: none;
  border-radius: 12px;
  padding: 8px 16px;
  background: transparent;
  cursor: pointer;
}
.switch .active { background: #5d7cff; color: #fff; }

label { display: block; margin: 14px 0 8px; font-weight: 600; color: #666b82; }
textarea {
  width: 100%;
  height: 120px;
  border: 2px solid #f1c7e2;
  border-radius: 14px;
  padding: 12px;
  font-size: 16px;
}
.counter { text-align: right; color: #9196ad; margin-top: 4px; }
.row { display: flex; gap: 10px; margin-top: 12px; }

.image-panel { margin-top: 14px; }
.ref-row { display: flex; justify-content: space-between; align-items: center; }
.upload-box {
  margin-top: 8px;
  border: 2px dashed #f0b9dc;
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  background: rgba(255, 255, 255, .4);
}
.upload-box input { display: none; }

.thumbs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 10px;
}
.thumbs img { width: 100%; height: 70px; object-fit: cover; border-radius: 8px; }

.hidden { display: none !important; }

.num-group { display: flex; gap: 6px; }
.num-group button {
  border: 1px solid #d9ced8;
  background: #efeef0;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.num-group .active {
  background: linear-gradient(90deg, #ff8731, #ff57b6);
  color: #fff;
  border: none;
}

/* ===== Toolbar（稳定版：按钮始终右对齐）===== */
.card.right .toolbar {
  width: 100%;
  display: flex;
  align-items: end;
  gap: 12px;
}
/* 左侧参数区：模型/比例/分辨率/质量 */
.card.right .toolbar .toolbar-fields {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(120px, max-content);
  gap: 10px;
  align-items: end;
  justify-content: start;
}
/* 如果你当前 HTML 还没有 .toolbar-fields，也兼容直接放在 toolbar 下的普通项 */
.card.right .toolbar > div:not(.gen-wrap):not(.history-wrap-btn) {
  min-width: 0;
}
/* 字段块 */
.card.right .toolbar p {
  margin: 0 0 6px;
  font-weight: 600;
  line-height: 1.2;
}
/* 下拉框 */
.card.right .toolbar select {
  width: 100%;
  min-width: 0;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid #d8d8de;
  background: #f4f4f6;
}
/* 分辨率 */
.card.right .toolbar #resolution-wrap.hidden {
  display: none !important;
}
.card.right .toolbar #resolution-wrap {
  max-width: 200px;
}
.card.right .toolbar #resolution {
  width: 100%;
  min-width: 0;
}
/* 质量 */
.card.right .toolbar .quality-group {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
}
.card.right .toolbar .quality-group button {
  border: 1px solid #d8dbe4;
  background: #fff;
  color: #4a4f5c;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}
.card.right .toolbar .quality-group button.active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(90deg, #7b4dff, #ff5ca8);
  box-shadow: 0 6px 16px rgba(123, 77, 255, .25);
}
/* 右侧按钮区：永远贴右 */
.card.right .toolbar .gen-wrap,
.card.right .toolbar .history-wrap-btn {
  flex: 0 0 auto;
  align-self: end;
  margin: 0;
}
.card.right .toolbar .gen-wrap { margin-left: auto; } /* 核心：把后面按钮推到最右 */
.card.right .toolbar .gen-wrap .btn,
.card.right .toolbar .history-wrap-btn .btn {
  height: 40px;
  padding: 0 14px;
  white-space: nowrap;
}
/* 结果区域与工具栏拉齐 */
.card.right .result { margin-top: 14px; }
.card.right .result-head { margin: 0 0 10px; }

.result-head { display: flex; justify-content: space-between; align-items: center; }
.result h2 { margin: 0; color: #c950ea; }
#status { color: #666c87; }
#status.error { color: #d43b3b; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  min-height: 240px;
}
.result-grid img { width: 100%; border-radius: 12px; cursor: zoom-in; }

.samples {
  margin-top: 16px;
  width: 100%;
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
}

.samples-grid.one-line {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 175px;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  padding-bottom: 4px;
  font-size: .875rem;
  text-align: center;
}
.sample-item img {
  width: 160px;
  height: 160px;
  object-fit: cover;
  border-radius: 10px;
  display: block;
  cursor: pointer;
}

/* 弹层必须高于 top.css 里的 topbar(300) */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  display: grid;
  place-items: center;
  z-index: 666;
}
.panel {
  width: min(520px, 92vw);
  background: #fff;
  border-radius: 16px;
  padding: 16px;
}
.panel input {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 10px;
  margin-bottom: 10px;
}
.test-msg { margin: 8px 0 0; font-size: 14px; color: #333; }
.test-msg.ok { color: #13a165; }
.test-msg.err { color: #d43b3b; }

.preview {
  width: min(1000px, 94vw);
  position: relative;
  z-index: 600;
}
.preview img {
  width: 100%;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 12px;
}
#btn-close-preview {
  position: absolute;
  top: 8px;
  right: 8px;
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  cursor: pointer;
  z-index: 2;
}

/* 历史记录 */
.history-wrap {
  background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 10px;
  padding: 10px 12px;
}
.history-wrap #history-list {
  margin: 0;
  padding-left: 18px;
  max-height: 220px;
  overflow: auto;
}
.history-wrap #history-list li,
.history-item {
  margin: 6px 0;
  color: #3f3f56;
  cursor: pointer;
  line-height: 1.45;
  word-break: break-word;
  font-size: .875rem;
}
.history-wrap #history-list li:hover,
.history-item:hover {
  color: #f1894f;
  text-decoration: underline;
}
.history-empty { color: #aab4c3; margin: 6px 0; }

/* 拖拽上传态 */
.dropzone { cursor: pointer; }
.dropzone.is-dragover {
  border-color: #7c5cff;
  background: rgba(124, 92, 255, 0.08);
}
#image-panel .upload-box.is-dragover {
  border-color: #7c5cff;
  background: rgba(124, 92, 255, 0.08);
}

/* 响应式 */
@media (max-width: 1440px) {
  body {
    padding-left: 12px;
    padding-right: 12px;
  }
}

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

/* 中屏：工具栏缩放 */
@media (max-width: 1280px) {
  .card.right .toolbar {
    grid-template-columns:
      minmax(160px, 1fr)
      minmax(95px, 0.7fr)
      minmax(115px, 0.75fr)
      minmax(220px, 1.25fr)
      auto
      auto;
  }
}

/* 小屏 */
@media (max-width: 900px) {
  .card.right .toolbar {
    flex-wrap: wrap;
    align-items: stretch;
  }
  .card.right .toolbar .toolbar-fields {
    width: 100%;
    grid-auto-flow: row;
    grid-template-columns: 1fr 1fr;
  }
  .card.right .toolbar .gen-wrap {
    margin-left: 0;
  }
}