/* ═══════════════════════════════════════════
   Viewer3D — 3D 产品模板预览（three.js）
   抱枕/画框模型 · 拖动环绕 · 滚轮/双指缩放 · 图片贴面
   截屏 → /api/upload → 作为 reference_images 进入生图工作流（图生图）
   ═══════════════════════════════════════════ */

.v3d-overlay {
  position: fixed; inset: 0; z-index: 400;
  background: var(--overlay);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.v3d-overlay.on { display: flex; animation: overlayIn 0.18s ease; }
.v3d-overlay.on .v3d { animation: modalIn 0.32s var(--ease-emph); }
.v3d {
  width: 960px; max-width: 96vw; max-height: 92vh;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  display: grid; grid-template-columns: 1fr 280px;
  overflow: hidden; position: relative;
}
.v3d__stage { position: relative; min-height: 480px; background: var(--bg-soft); }
.v3d__stage canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.v3d__stage canvas:active { cursor: grabbing; }
.v3d__hint {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  font-size: 0.7rem; color: var(--fg-dim); background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 999px; padding: 4px 14px;
  pointer-events: none; white-space: nowrap; opacity: 0.9;
}
.v3d__side { padding: 22px 20px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.v3d__close { position: absolute; top: 12px; right: 14px; z-index: 2; font-size: 1.3rem; color: var(--fg-dim); padding: 4px 8px; transition: color 0.15s; }
.v3d__close:hover { color: var(--fg); }
.v3d__title { font-size: 1.05rem; font-weight: 500; }
.v3d__title small { display: block; font-size: 0.7rem; font-weight: 400; color: var(--fg-dim); margin-top: 3px; letter-spacing: 0.05em; }
.v3d__label { font-size: 0.74rem; color: var(--fg-muted); margin-bottom: 6px; }
.v3d__models { display: flex; gap: 8px; }
.v3d__model {
  flex: 1; padding: 9px 0; text-align: center; font-size: 0.8rem;
  border: 1px solid var(--border); border-radius: var(--radius); color: var(--fg-muted);
  transition: all 0.15s;
}
.v3d__model.active { border-color: var(--fg); color: var(--fg); font-weight: 500; background: var(--accent-soft); }
/* 部位选择（六面） */
.v3d__faces { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.v3d__face {
  padding: 7px 0; text-align: center; font-size: 0.76rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--fg-muted);
  transition: all 0.15s;
}
.v3d__face:hover { border-color: var(--border-strong); color: var(--fg); }
.v3d__face.active { border-color: var(--pop); color: var(--pop); font-weight: 500; background: var(--pop-soft); }
/* 贴图列表（多图 · 点选 · 可取消） */
.v3d__texlist { display: flex; flex-wrap: wrap; gap: 8px; min-height: 0; }
.v3d__texempty { font-size: 0.72rem; color: var(--fg-dim); padding: 8px 2px; }
.v3d__tex {
  position: relative; width: 46px; height: 46px;
  border-radius: var(--radius); overflow: hidden;
  border: 2px solid var(--border); cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.v3d__tex:hover { transform: translateY(-1px); }
.v3d__tex.active { border-color: var(--pop); }
.v3d__tex img { width: 100%; height: 100%; object-fit: cover; }
.v3d__tex-x {
  position: absolute; top: 1px; right: 1px;
  width: 16px; height: 16px; border-radius: 50%;
  background: rgba(0,0,0,0.55); color: #fff;
  font-size: 0.72rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.15s;
}
.v3d__tex:hover .v3d__tex-x { opacity: 1; }
.v3d__tex-x:hover { background: var(--pop); }
/* 显隐切换（眼睛） */
.v3d__tex-eye {
  position: absolute; bottom: 1px; left: 1px;
  width: 16px; height: 16px; border-radius: 50%;
  background: rgba(0,0,0,0.55); color: #fff;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.15s, background 0.15s;
}
.v3d__tex:hover .v3d__tex-eye { opacity: 1; }
.v3d__tex.hidden-tex .v3d__tex-eye { opacity: 1; background: var(--fg); }
.v3d__tex-eye svg { width: 10px; height: 10px; }
.v3d__tex-eye:hover { background: var(--pop); }
.v3d__tex.hidden-tex { border-style: dashed; }
/* 电子围栏 2D 编辑器 */
.v3d-fence {
  position: absolute; inset: 0; z-index: 5;
  background: var(--bg-card); display: flex; flex-direction: column;
}
.v3d-fence__head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  font-size: 0.82rem; font-weight: 500;
}
.v3d-fence__body { position: relative; flex: 1; overflow: hidden; background: var(--bg-soft); }
/* 背景拉满整个编辑区（拉伸可接受），保证拉框坐标与画布像素 1:1 映射 */
.v3d-fence__bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; }
.v3d-fence__rect {
  position: absolute; border: 2px dashed var(--pop);
  background: rgba(198,54,44,0.08); cursor: move; touch-action: none;
}
.v3d-fence__hd {
  position: absolute; right: -7px; bottom: -7px;
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff; border: 2px solid var(--pop); cursor: nwse-resize;
}
.v3d__texrow { display: flex; gap: 8px; align-items: center; }
.v3d__texthumb {
  width: 44px; height: 44px; border-radius: var(--radius); flex-shrink: 0;
  border: 1px dashed var(--border-strong); background: var(--bg-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.62rem; color: var(--fg-dim); overflow: hidden;
}
.v3d__texthumb img { width: 100%; height: 100%; object-fit: cover; }
.v3d__row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 0.82rem; }
.v3d__row input[type="range"] { flex: 1; accent-color: var(--fg); }
.v3d__row .v3d__val { font-size: 0.72rem; color: var(--fg-dim); min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.v3d__switch { position: relative; width: 36px; height: 20px; background: var(--border-strong); border-radius: 999px; transition: background 0.2s; flex-shrink: 0; }
.v3d__switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 0.2s; box-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.v3d__switch.on { background: var(--fg); }
.v3d__switch.on::after { transform: translateX(16px); }
.v3d__foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.v3d__note { font-size: 0.68rem; color: var(--fg-dim); line-height: 1.5; }
@media (max-width: 860px) { .v3d { grid-template-columns: 1fr; } .v3d__stage { min-height: 42vh; } }
@media (max-width: 500px) {
  .v3d-overlay { padding: 0; align-items: flex-end; }
  .v3d { max-width: 100vw; border-radius: 16px 16px 0 0; }
  .v3d__stage { min-height: 38vh; }
}
