/* =============================================================================
 * AI 设计 · 画板编辑器（assets/sp-design-board.css）
 * 只服务于 ai-design.php 的画板浮层，前缀统一 spb-，不依赖 Tailwind。
 *
 * 配色：深色工具外壳 + 浅色画板（设计工具的常规分工：UI 退后，作品在前）。
 * 纪律：不用渐变 / 玻璃拟态 / emoji 当图标 / 发丝描边；圆角只决定一次（10px）；
 *       UI 字号 13px 起，次级注释 12px。
 * ========================================================================== */

.spb-mask {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  flex-direction: column;
  background: #101011;
  color: #f1f1ed;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.spb-mask[hidden] { display: none; }
.spb-mask * { box-sizing: border-box; }

/* ---------- 顶栏 ---------- */
.spb-top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 52px;
  padding: 0 12px;
  background: #17171a;
  border-bottom: 1px solid #26262b;
}
.spb-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #9c9c95;
  font-size: 13px;
  white-space: nowrap;
}
.spb-brand i { color: #5b9bff; font-size: 15px; }

.spb-title {
  width: 200px;
  height: 30px;
  padding: 0 9px;
  background: #0f0f11;
  border: 1px solid #2a2a30;
  border-radius: 8px;
  color: #f1f1ed;
  font-size: 13px;
  outline: none;
}
.spb-title:focus { border-color: #3b62a8; }

.spb-gap { flex: 1 1 auto; }

/* ---------- 通用按钮 ---------- */
.spb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 30px;
  padding: 0 10px;
  background: #212126;
  border: 1px solid #2c2c32;
  border-radius: 8px;
  color: #d8d8d2;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.spb-btn:hover { background: #2a2a30; color: #fff; }
.spb-btn:disabled { opacity: .38; cursor: default; }
.spb-btn:disabled:hover { background: #212126; color: #d8d8d2; }
.spb-btn i { font-size: 15px; }

.spb-btn-primary {
  background: #2f6bff;
  border-color: #2f6bff;
  color: #fff;
}
.spb-btn-primary:hover { background: #4480ff; border-color: #4480ff; }

.spb-btn-danger { color: #ff8b8b; }
.spb-btn-danger:hover { background: #33211f; color: #ffb0b0; }

.spb-btn.is-on {
  background: #24304a;
  border-color: #2f6bff;
  color: #fff;
}

.spb-btn-icon { width: 30px; padding: 0; }

/* 分段控件（画布尺寸 / 对齐） */
.spb-seg {
  display: inline-flex;
  padding: 2px;
  background: #0f0f11;
  border: 1px solid #2a2a30;
  border-radius: 9px;
}
.spb-seg button {
  height: 24px;
  padding: 0 8px;
  background: transparent;
  border: 0;
  border-radius: 7px;
  color: #9c9c95;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.spb-seg button:hover { color: #e6e6e0; }
.spb-seg button.is-on { background: #2f6bff; color: #fff; }

.spb-color {
  width: 30px;
  height: 30px;
  padding: 0;
  background: #0f0f11;
  border: 1px solid #2a2a30;
  border-radius: 8px;
  cursor: pointer;
}
.spb-color::-webkit-color-swatch-wrapper { padding: 3px; }
.spb-color::-webkit-color-swatch { border: 0; border-radius: 5px; }

.spb-save {
  font-size: 12px;
  color: #86867f;
  min-width: 68px;
  text-align: right;
}
.spb-save[data-state="dirty"] { color: #e2b04a; }
.spb-save[data-state="error"] { color: #ff8b8b; }

/* ---------- 主体三栏 ---------- */
.spb-body {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

/* 左栏 */
.spb-left {
  flex: 0 0 208px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 12px 10px;
  background: #17171a;
  border-right: 1px solid #26262b;
  overflow-y: auto;
}
.spb-left::-webkit-scrollbar,
.spb-right::-webkit-scrollbar { width: 6px; }
.spb-left::-webkit-scrollbar-thumb,
.spb-right::-webkit-scrollbar-thumb { background: #303036; border-radius: 3px; }

.spb-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 7px;
  color: #86867f;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: .02em;
}
.spb-h button {
  background: none;
  border: 0;
  color: #86867f;
  font-size: 12px;
  cursor: pointer;
  padding: 0;
}
.spb-h button:hover { color: #e6e6e0; }

.spb-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.spb-tool {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 9px;
  background: #212126;
  border: 1px solid #2c2c32;
  border-radius: 8px;
  color: #d8d8d2;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}
.spb-tool:hover { background: #2a2a30; color: #fff; }
.spb-tool i { font-size: 15px; color: #9c9c95; }
.spb-tool:hover i { color: #5b9bff; }

/* 图层列表 */
.spb-layers { display: flex; flex-direction: column; gap: 3px; }
.spb-layer {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 7px;
  border-radius: 7px;
  color: #b9b9b2;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}
.spb-layer:hover { background: #212126; }
.spb-layer.is-on { background: #24304a; color: #fff; }
.spb-layer i { font-size: 14px; color: #7f7f79; flex: 0 0 auto; }
.spb-layer.is-on i { color: #7ea6ff; }
.spb-layer span {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.spb-layer em { font-style: normal; color: #6e6e68; font-size: 11px; }
.spb-empty {
  padding: 10px 8px;
  color: #6e6e68;
  font-size: 12px;
  line-height: 1.6;
}

/* 画板列表 */
.spb-boards { display: flex; flex-direction: column; gap: 3px; }
.spb-board-row {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 7px;
  border-radius: 7px;
  color: #b9b9b2;
  font-size: 12px;
  cursor: pointer;
}
.spb-board-row:hover { background: #212126; color: #fff; }
.spb-board-row span { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spb-board-row em { font-style: normal; color: #6e6e68; font-size: 11px; }
.spb-board-row button {
  flex: 0 0 auto;
  width: 18px; height: 18px;
  background: none; border: 0; padding: 0;
  color: #6e6e68; cursor: pointer; font-size: 13px;
}
.spb-board-row button:hover { color: #ff8b8b; }

/* 舞台 */
.spb-stage-wrap {
  flex: 1 1 auto;
  display: flex;
  overflow: auto;
  padding: 28px;
  background: #101011;
  background-image: radial-gradient(#26262b 1px, transparent 1px);
  background-size: 22px 22px;
}
.spb-stage-wrap::-webkit-scrollbar { width: 8px; height: 8px; }
.spb-stage-wrap::-webkit-scrollbar-thumb { background: #303036; border-radius: 4px; }

/* margin:auto 在 flex 容器里双向居中，且内容超出时仍能正常滚动（比 justify-content 稳） */
.spb-fit { margin: auto; }
.spb-stage {
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .55);
  user-select: none;
  touch-action: none;
}
.spb-stage.is-checker {
  background-image:
    linear-gradient(45deg, #e3e3e3 25%, transparent 25%),
    linear-gradient(-45deg, #e3e3e3 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e3e3e3 75%),
    linear-gradient(-45deg, transparent 75%, #e3e3e3 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-color: #fff;
}

/* 图元 */
.spb-obj {
  position: absolute;
  transform-origin: center center;
  cursor: move;
}
.spb-obj img { display: block; width: 100%; height: 100%; pointer-events: none; }
.spb-obj-text {
  white-space: pre;
  user-select: none;
}
.spb-obj-text > div { pointer-events: none; }
.spb-obj.is-locked { cursor: default; }

/* 选中框 */
.spb-sel {
  position: absolute;
  transform-origin: center center;
  pointer-events: none;
  outline: 1.5px solid #2f6bff;
  outline-offset: 0;
}
.spb-sel.dragging { outline-color: #5b9bff; }
.spb-handle {
  position: absolute;
  width: 9px;
  height: 9px;
  margin: -5px 0 0 -5px;
  background: #fff;
  border: 1.5px solid #2f6bff;
  border-radius: 2px;
  pointer-events: auto;
}
.spb-handle[data-h="nw"] { left: 0; top: 0; cursor: nwse-resize; }
.spb-handle[data-h="ne"] { left: 100%; top: 0; cursor: nesw-resize; }
.spb-handle[data-h="se"] { left: 100%; top: 100%; cursor: nwse-resize; }
.spb-handle[data-h="sw"] { left: 0; top: 100%; cursor: nesw-resize; }
.spb-rot {
  position: absolute;
  left: 50%;
  top: -26px;
  width: 13px;
  height: 13px;
  margin-left: -7px;
  background: #fff;
  border: 1.5px solid #2f6bff;
  border-radius: 50%;
  pointer-events: auto;
  cursor: grab;
}
.spb-rot::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 13px;
  width: 1.5px;
  height: 12px;
  background: #2f6bff;
  transform: translateX(-50%);
}

/* 右栏 */
.spb-right {
  flex: 0 0 216px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 12px 10px;
  background: #17171a;
  border-left: 1px solid #26262b;
  overflow-y: auto;
}
.spb-field { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.spb-field > label {
  flex: 0 0 42px;
  color: #86867f;
  font-size: 12px;
}
.spb-field input[type="number"],
.spb-field input[type="text"],
.spb-field select {
  flex: 1 1 auto;
  min-width: 0;
  height: 28px;
  padding: 0 7px;
  background: #0f0f11;
  border: 1px solid #2a2a30;
  border-radius: 7px;
  color: #e6e6e0;
  font-size: 12px;
  outline: none;
}
.spb-field input:focus,
.spb-field select:focus { border-color: #3b62a8; }
.spb-field input[type="range"] { flex: 1 1 auto; min-width: 0; accent-color: #2f6bff; }
.spb-field .spb-unit { color: #6e6e68; font-size: 11px; }

.spb-row2 { display: flex; gap: 6px; }
.spb-row2 > * { flex: 1 1 0; min-width: 0; }

.spb-align-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.spb-align-grid button {
  height: 28px;
  background: #212126;
  border: 1px solid #2c2c32;
  border-radius: 7px;
  color: #b9b9b2;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.spb-align-grid button:hover { background: #2a2a30; color: #fff; }

.spb-none {
  padding: 12px 4px;
  color: #6e6e68;
  font-size: 12px;
  line-height: 1.7;
}

/* 底部提示条 */
.spb-hint {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 30px;
  padding: 0 14px;
  background: #17171a;
  border-top: 1px solid #26262b;
  color: #6e6e68;
  font-size: 12px;
  overflow: hidden;
  white-space: nowrap;
}
.spb-hint b { color: #9c9c95; font-weight: 500; }

/* 下拉菜单 */
.spb-menu {
  position: fixed;
  z-index: 95;
  min-width: 208px;
  padding: 5px;
  background: #1d1d21;
  border: 1px solid #2c2c32;
  border-radius: 10px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .5);
}
.spb-menu[hidden] { display: none; }
.spb-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 32px;
  padding: 0 9px;
  background: none;
  border: 0;
  border-radius: 7px;
  color: #d8d8d2;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.spb-menu button:hover { background: #2a2a30; color: #fff; }
.spb-menu button i { font-size: 15px; color: #8d8d87; }
.spb-menu button:hover i { color: #5b9bff; }
.spb-menu .spb-menu-note {
  padding: 7px 9px 4px;
  color: #6e6e68;
  font-size: 11px;
  line-height: 1.6;
}
.spb-menu hr {
  height: 1px;
  margin: 5px 4px;
  background: #2c2c32;
  border: 0;
}

/* 提示 toast */
.spb-toast {
  position: fixed;
  left: 50%;
  bottom: 54px;
  z-index: 96;
  transform: translate(-50%, 12px);
  padding: 9px 16px;
  background: #26262b;
  border: 1px solid #34343a;
  border-radius: 9px;
  color: #f1f1ed;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s, transform .16s;
}
.spb-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* 窄屏：左右栏收起，只留舞台 */
@media (max-width: 1080px) {
  .spb-left { flex-basis: 176px; }
  .spb-right { flex-basis: 186px; }
}
@media (max-width: 860px) {
  .spb-left, .spb-right { display: none; }
  .spb-title { width: 120px; }
  .spb-hint { display: none; }
}
