* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --blue: #3b6cf6;
  --red: #ee4a3b;
  --red-dark: #d63a2c;
  --bg: #f5f5f6;
  --card: #ffffff;
  --text: #2b2b2e;
  --text-2: #8a8a92;
  --border: #ececef;
  --radius: 14px;
}
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* 顶栏 */
.topbar {
  display: flex; align-items: center; gap: 40px;
  background: #fff; padding: 0 28px; height: 58px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-size: 20px; font-weight: 700; color: var(--red); }
.brand span { margin-left: 2px; }
.topnav { display: flex; gap: 34px; flex: 1; justify-content: center; }
.topnav a { color: #666; text-decoration: none; font-size: 15px; padding: 18px 2px 16px; border-bottom: 3px solid transparent; }
.topnav a.active { color: var(--red); border-bottom-color: var(--red); font-weight: 600; }
.topnav a.disabled { cursor: default; opacity: .75; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.conn { font-size: 12px; color: var(--text-2); background: #f4f4f6; border-radius: 999px; padding: 4px 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--red); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 15px; }
.btn-ghost { border: 1px solid var(--border); background: #fff; border-radius: 8px; padding: 7px 12px; cursor: pointer; font-size: 13px; color: #444; }
.btn-ghost:hover { border-color: var(--red); color: var(--red); }

/* 布局 */
.layout { display: flex; gap: 20px; padding: 20px 24px; max-width: 1500px; margin: 0 auto; }
.panel { width: 320px; flex-shrink: 0; display: flex; flex-direction: column; gap: 14px; }

/* 卡片 */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.card-head { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.card-head h3 { font-size: 15px; }
.step-no { width: 20px; height: 20px; border-radius: 50%; background: var(--red); color: #fff; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.card-head .btn-link { margin-left: auto; }
.btn-link { border: none; background: none; color: #999; cursor: pointer; font-size: 12px; }
#btn-close-settings {
  font-size: 18px; color: #666; line-height: 1;
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
#btn-close-settings:hover { background: #f2f2f2; color: #333; }
.btn-link:hover { color: var(--red); }
.btn-link.danger:hover { color: var(--red); }
.field-label { font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.field-label em { font-style: normal; }
.field-label em.req { color: var(--red); }

/* 参考图 */
.drop-zone {
  border: 1.5px dashed #d9d9de; border-radius: 10px; padding: 22px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  color: var(--text-2); font-size: 12px; cursor: pointer; text-align: center;
  transition: border-color .15s, background .15s;
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--red); background: #fff7f6; }
.drop-zone .plus { color: var(--red); font-size: 20px; }
.ref-preview { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.ref-item { position: relative; width: 72px; height: 72px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.ref-item img { width: 100%; height: 100%; object-fit: cover; }
.ref-item .rm {
  position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: rgba(0,0,0,.55); color: #fff; border: none; cursor: pointer; font-size: 11px; line-height: 1;
}

/* 提示词 */
textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 13px; resize: vertical; min-height: 96px;
  font-family: inherit; color: var(--text); outline: none;
}
textarea:focus { border-color: var(--red); }
.prompt-foot { text-align: right; font-size: 11px; color: #bbb; margin-top: 4px; }

/* Klein 精修：模型强度滑杆 */
.strength-row { display: flex; align-items: center; gap: 12px; }
.strength-row input[type="range"] {
  flex: 1; height: 4px; -webkit-appearance: none; appearance: none;
  background: linear-gradient(to right, var(--blue) 0%, var(--blue) var(--fill, 90%), #e6e8ef var(--fill, 90%), #e6e8ef 100%);
  border-radius: 2px; outline: none; cursor: pointer;
}
.strength-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; border: 2px solid var(--blue);
  box-shadow: 0 1px 4px rgba(59,108,246,.35); cursor: pointer;
}
.strength-row input[type="number"] {
  width: 72px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; text-align: center; color: var(--text); background: #fff;
}

/* 提示词预设 */
.preset-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.preset-chip {
  border: 1px solid var(--border); background: #fafafa; border-radius: 999px;
  padding: 4px 12px; font-size: 12px; color: #555; cursor: pointer;
  transition: border-color .12s, color .12s, background .12s;
}
.preset-chip:hover { border-color: var(--red); color: var(--red); background: #fff5f4; }

/* 参数 */
.param-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.param label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 5px; }
.param select {
  width: 100%; padding: 8px 8px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; background: #fff; color: var(--text); outline: none;
}
.param select:focus { border-color: var(--red); }

.form-error {
  background: #fff2f0; border: 1px solid #ffd6d1; color: var(--red-dark);
  font-size: 12px; border-radius: 10px; padding: 10px 12px; line-height: 1.6;
  word-break: break-all;
}

.btn-primary {
  width: 100%; background: var(--red); color: #fff; border: none;
  border-radius: 999px; padding: 13px; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: var(--red-dark); }
.btn-primary:disabled { background: #f3b1aa; cursor: not-allowed; }
.btn-primary.small { width: auto; padding: 8px 18px; font-size: 13px; text-decoration: none; display: inline-block; }

/* 模型选择 */
.model-select { position: relative; }
.model-btn {
  width: 100%; display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--border); background: #fff; border-radius: 10px;
  padding: 8px 12px; cursor: pointer; text-align: left;
}
.model-btn:hover { border-color: var(--red); }
.model-btn .caret { margin-left: auto; color: #999; font-size: 11px; }
.m-ico {
  width: 26px; height: 26px; border-radius: 8px; color: #fff;
  font-size: 14px; font-weight: 700; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.m-txt { display: flex; flex-direction: column; min-width: 0; }
.m-txt b { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-txt i { font-style: normal; font-size: 11px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-menu {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 6px; z-index: 40;
  max-height: 320px; overflow: auto;
}
.model-group-title {
  padding: 7px 8px 3px; font-size: 11px; color: #9aa0aa;
  border-bottom: 1px solid var(--border); margin: 2px 4px 4px;
}
.model-item {
  width: 100%; display: flex; align-items: center; gap: 10px;
  border: none; background: none; padding: 8px; border-radius: 8px;
  cursor: pointer; text-align: left;
}
.model-item:hover { background: #f7f7f8; }

/* 比例宫格 / 分辨率分段 */
.ratio-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ratio-grid button, .seg button {
  border: 1px solid var(--border); background: #fff; border-radius: 8px;
  padding: 7px 2px 6px; font-size: 12px; color: var(--text); cursor: pointer;
  transition: border-color .12s, color .12s, background .12s;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.ratio-grid button:hover, .seg button:hover { border-color: var(--red); color: var(--red); }
.ratio-grid button.active, .seg button.active {
  border-color: var(--red); color: var(--red); background: #fff5f4; font-weight: 600;
}
.ratio-shape {
  display: block; border: 1.5px solid currentColor; border-radius: 3px;
  min-width: 4px; min-height: 4px;
}
.ratio-shape.auto { width: 15px; height: 15px; border-style: dashed; }
.ratio-num { font-size: 11px; line-height: 1; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; }

/* 生成数量滑杆 */
.param input[type="range"] { width: 100%; accent-color: var(--red); cursor: pointer; }
.range-marks { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-2); margin-top: 2px; padding: 0 4px; }
.param label em { font-style: normal; color: var(--red); }

/* 画板 */
.board-wrap {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  background: #fff; border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.board-toolbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.board-toolbar h2 { font-size: 17px; }
.board-toolbar h2 span { font-size: 13px; color: var(--text-2); font-weight: 400; }
#board {
  position: relative; flex: 1; overflow: hidden; cursor: grab;
  background: #f7f7f9;
  background-image: radial-gradient(#e2e2e9 1px, transparent 1px);
  background-size: 24px 24px;
}
#board:active { cursor: grabbing; }
.board-canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.board-item {
  position: absolute; width: 230px; background: #fff; border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.08); overflow: hidden; cursor: pointer;
  user-select: none;
}
.board-item.dragging { opacity: .85; box-shadow: 0 10px 28px rgba(0,0,0,.2); }
.board-item.dim { opacity: .12; pointer-events: none; }
.b-img { position: relative; background: #fafafa; }
.b-img img { width: 100%; display: block; }
.b-cap {
  padding: 8px 10px 4px; font-size: 11px; color: #555; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.b-foot { display: flex; align-items: center; justify-content: space-between; padding: 2px 10px 8px; }
.b-foot > span { font-size: 10px; color: #b0b0b6; }
.b-actions { display: flex; gap: 4px; }
.b-actions .g-btn { padding: 2px 8px; font-size: 11px; }
.b-loading { height: 170px; display: flex; flex-direction: column; gap: 8px; align-items: center; justify-content: center; color: var(--text-2); font-size: 12px; }
.b-error { padding: 14px; }
.b-error h4 { color: var(--red); font-size: 13px; margin-bottom: 6px; }
.b-error p { color: var(--red-dark); font-size: 10px; line-height: 1.6; word-break: break-all; max-height: 110px; overflow: auto; }
.board-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #b5b5bc; font-size: 14px; pointer-events: none; padding: 0 40px; text-align: center;
}
.board-empty[hidden] { display: none; }
.zoom-ctl { display: flex; align-items: center; gap: 4px; }
.zoom-ctl button {
  border: 1px solid var(--border); background: #fff; border-radius: 6px;
  width: 24px; height: 24px; cursor: pointer; font-size: 13px; color: #555; line-height: 1;
}
.zoom-ctl button:hover { border-color: var(--red); color: var(--red); }
.zoom-ctl span { font-size: 12px; color: var(--text-2); width: 42px; text-align: center; }

/* 记录墙（旧样式，保留兼容） */
.gallery-wrap { flex: 1; min-width: 0; }
.gallery-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.gallery-tools { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.gallery-tools input[type="search"] {
  border: 1px solid var(--border); border-radius: 999px; padding: 6px 14px;
  font-size: 12px; width: 180px; outline: none; color: var(--text);
}
.gallery-tools input[type="search"]:focus { border-color: var(--red); }
.foot-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.conn-test { font-size: 12px; color: var(--text-2); line-height: 1.4; }
.conn-test.ok { color: #2ea44f; }
.conn-test.bad { color: var(--red); }
.gallery-head h2 { font-size: 17px; }
.gallery-head h2 span { font-size: 13px; color: var(--text-2); font-weight: 400; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.gallery-empty { text-align: center; color: #b5b5bc; font-size: 14px; padding: 80px 0; }

.card-g {
  background: #fff; border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.05); display: flex; flex-direction: column;
}
.g-img { position: relative; background: #fafafa; cursor: zoom-in; min-height: 160px; }
.g-img img { width: 100%; display: block; height: auto; max-height: 420px; object-fit: cover; }
.g-loading { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; height: 220px; color: var(--text-2); font-size: 12px; }
.spinner { width: 26px; height: 26px; border: 3px solid #f0d9d6; border-top-color: var(--red); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.g-error { padding: 18px 14px; text-align: center; }
.g-error h4 { color: var(--red); font-size: 14px; margin-bottom: 8px; }
.g-error p { color: var(--red-dark); font-size: 11px; line-height: 1.7; word-break: break-all; max-height: 130px; overflow: auto; text-align: left; }
.g-info { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.g-prompt { font-size: 12px; color: #444; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.g-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; }
.g-time { font-size: 11px; color: #b0b0b6; }
.g-actions { display: flex; gap: 6px; }
.g-btn { border: 1px solid var(--border); background: #fff; border-radius: 7px; padding: 4px 12px; font-size: 12px; color: #555; cursor: pointer; }
.g-btn:hover { border-color: var(--red); color: var(--red); }
.badge { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.5); color: #fff; font-size: 11px; border-radius: 6px; padding: 2px 8px; }

/* 灯箱 & 弹窗 */
.lightbox, .modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 30px;
}
.lightbox[hidden], .modal[hidden] { display: none; }
.lightbox-inner { max-width: 86vw; max-height: 90vh; display: flex; flex-direction: column; gap: 12px; }
.lightbox-inner img { max-width: 86vw; max-height: 78vh; object-fit: contain; border-radius: 10px; background: #111; }
.lightbox-bar { display: flex; align-items: center; gap: 14px; justify-content: space-between; color: #fff; font-size: 13px; }
.lightbox-bar span { max-width: 55vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .85; }

/* 图片右键菜单 */
.img-ctx {
  position: fixed; z-index: 999; min-width: 132px;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,.14); padding: 4px; display: flex; flex-direction: column;
}
.img-ctx button {
  border: none; background: none; text-align: left; padding: 8px 12px;
  font-size: 13px; color: var(--text); border-radius: 7px; cursor: pointer;
}
.img-ctx button:hover { background: #f4f5f7; color: var(--red); }
.img-ctx[hidden] { display: none; }
.lb-pos { font-size: 12px; opacity: .7; }
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 48px; height: 48px; border: none; border-radius: 50%;
  background: rgba(0,0,0,.45); color: #fff; font-size: 28px; line-height: 1;
  cursor: pointer; z-index: 2;
}
.lb-nav:hover { background: rgba(0,0,0,.7); }
#lb-prev { left: 24px; }
#lb-next { right: 24px; }

/* 多图卡片：并排展示 */
.b-imgs { display: grid; grid-template-columns: 1fr; }
.b-imgs.multi { grid-template-columns: 1fr 1fr; }
.b-imgs.multi .b-img { position: relative; }
.b-img { position: relative; background: #fafafa; }
.b-img img { width: 100%; display: block; height: 100%; object-fit: cover; }

.modal-box {
  background: #fff; border-radius: 16px; width: 560px; max-width: 94vw; max-height: 88vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 10px; }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 4px 20px 10px; overflow: auto; }
.modal-foot { padding: 12px 20px 18px; }
.hint { font-size: 12px; color: var(--text-2); line-height: 1.6; margin: 8px 0; }
.settings-group h4 { font-size: 13px; margin: 14px 0 10px; color: #333; }
.settings-group label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 10px; }
.settings-group input {
  width: 100%; margin-top: 4px; padding: 9px 10px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; outline: none; color: var(--text);
}
.settings-group input:focus { border-color: var(--red); }

.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%);
  background: rgba(20,20,22,.85); color: #fff; font-size: 13px;
  padding: 10px 18px; border-radius: 999px; z-index: 99; max-width: 70vw;
}
