/*
 * Moteful 拼接工具页面私有样式（V0.5）
 * 仅包含 stitch.html 页面特有的样式，不修改 moteful.css。
 * 所有颜色走 CSS 变量，字号/圆角/间距遵守设计规范。
 */

/* ---------- 模式切换 ---------- */
.stitch-mode-bar {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

/* ---------- 组件间距（导入区独立于 panel，需手动补齐相邻兄弟间距。
   用通用兄弟选择器 ~ 同时覆盖单向/网格两个 .stitch-dropzone，
   根治"切换模式后邻接选择器 + 不匹配第二个导入区"导致网格模式贴页头的复发问题） ---------- */
.hero ~ .stitch-dropzone { margin-top: 16px; }
.stitch-dropzone + .panel { margin-top: 16px; }

/* ---------- 导入区（复用 .dropzone 标准组件结构，对齐 image-tool.html） ----------
   .dz-empty / .dz-gallery / .dz-g-head / .dz-count / .dz-g-acts /
   .dz-g-list / .dz-thumb / .dz-idx / .dz-rm 的组件定义已于 V0.6
   提升到 _governance/missing_styles_proposal.css 共享层（三页复用同一份）。
   本页仅保留「拖拽排序」特有的样式。 ---------- */
/* 拖动排序插入指示线（绝对定位，不占据 grid 空间，避免布局抖动） */
.dz-insert-line {
  position: absolute;
  width: 3px;
  border-radius: 2px;
  background: var(--primary);
  pointer-events: none;
  z-index: 5;
  display: none;
}

.dz-thumb {
  cursor: grab;                       /* 本页缩略图可拖拽排序；共享层不写 cursor */
  user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;              /* IE/Trident、搜狗兼容模式：防止拖成选中文本 */
  -webkit-touch-callout: none;        /* 禁止 iOS 长按弹出“存储图像”系统菜单 */
  -webkit-tap-highlight-color: transparent;
}
.dz-thumb:active { cursor: grabbing; }
.dz-thumb img {
  pointer-events: none;               /* 拖拽排序时缩略图不拦截指针事件 */
}
.dz-thumb.dragging { opacity: 0.4; }
/* 移动端长按进入拖拽时的反馈（桌面用 .dragging，触屏用 .is-dragging） */
.dz-thumb.is-dragging {
  opacity: 0.55;
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  transform: scale(0.96);
}
.dz-thumb.drag-over { outline: 2px solid var(--primary); outline-offset: 2px; }

/* 已导入态 dropzone 收缩 */
.dropzone.mini { padding: 16px; min-height: 0; background: var(--surface); align-items: stretch; text-align: left; gap: 0; }
.dropzone.dragover { border-color: var(--primary); background: var(--primary-soft); }

/* 移动端排序按钮 */
.dz-move-btns {
  display: none;
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  gap: 2px;
}
.dz-move-btns button {
  width: 16px;
  height: 16px;
  border-radius: var(--r-sm);
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 10px;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- 参数工具栏 ---------- */
.stitch-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md) var(--r-md) 0 0;
  border-bottom: none;
}
.stitch-toolbar .field {
  display: flex;
  align-items: center;
  gap: 6px;
}
.stitch-toolbar .field-label {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
}
.stitch-toolbar .field-val {
  font-size: 12px;
  font-family: var(--mono);
  color: var(--text);
  min-width: 32px;
  text-align: right;
}

/* ---------- 预览区 ---------- */
.stitch-preview {
  background: var(--bg);
  border: 1px solid var(--border);
  border-top: none;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 300px;
  max-height: 600px;
  overflow: auto;
  position: relative;
}
.stitch-preview img {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: var(--r-sm);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.stitch-preview .preview-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  font-size: 13px;
  padding: 40px 0;
}
.stitch-preview .preview-empty svg {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  opacity: 0.4;
}

/* 预览信息条 */
.stitch-info-bar {
  display: flex;
  gap: 16px;
  padding: 8px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--r-md) var(--r-md);
  font-size: 12px;
  color: var(--text-3);
  font-family: var(--mono);
}
.stitch-info-bar .info-item {
  display: flex;
  align-items: center;
  gap: 4px;
}
.stitch-info-bar .info-label {
  color: var(--text-3);
}
.stitch-info-bar .info-val {
  color: var(--text);
  font-weight: 600;
}
.stitch-stream-tag {
  color: var(--warning);
  font-weight: 600;
}

/* ---------- 流式进度条 ---------- */
.stitch-progress {
  display: none;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  margin-top: 12px;
}
.stitch-progress.active {
  display: block;
}
.stitch-progress .progress-label {
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
}

/* ---------- 导出区 ---------- */
.stitch-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 16px;
  flex-wrap: wrap;
}
.stitch-actions .export-btn {
  min-width: 160px;
}
.stitch-actions .clear-btn {
  margin-left: auto;
}

/* ---------- 网格模式：模板选择栏 ---------- */
.grid-template-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md) var(--r-md) 0 0;
  border-bottom: none;
}
.tpl-btn {
  width: 48px;
  height: 48px;
  border-radius: var(--r-sm);
  border: 2px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  transition: border-color 0.15s;
  position: relative;
}
.tpl-btn:hover {
  border-color: var(--border-strong);
}
.tpl-btn.on {
  border-color: var(--primary);
  border-width: 2px;
}
.tpl-btn .tpl-mini {
  display: grid;
  gap: 1px;
  width: 100%;
  height: 100%;
}
.tpl-btn .tpl-mini span {
  background: var(--border-strong);
  border-radius: 1px;
}
.tpl-btn.custom {
  border-style: dashed;
  font-size: 10px;
  color: var(--text-3);
  flex-direction: column;
  gap: 2px;
}
.tpl-custom-ctl {
  display: none;
  align-items: center;
  gap: 16px;
  margin-left: 8px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}
.tpl-custom-ctl.active {
  display: flex;
}
/* 自定义行列：复用全站 .step 标准步进器（仅私有微调，令牌化） */
.tpl-custom-ctl label {
  font-size: 12px;
  color: var(--text-3);
}
.tpl-custom-ctl input.step-val {
  color: inherit;                 /* 继承主题文字色，消灭原生黑字 */
  background: none;
  border-top: none;
  border-bottom: none;
  outline: none;
  width: 44px;
  min-width: 44px;
  font-variant-numeric: tabular-nums;  /* 数字等宽 */
}
.tpl-custom-ctl input.step-val:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
}


/* ---------- 网格预览 ---------- */
.grid-preview-wrap {
  background: var(--bg);
  border: 1px solid var(--border);
  border-top: none;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 300px;
  max-height: 600px;
  overflow: auto;
}
.grid-canvas {
  display: grid;
  gap: 4px;
  width: 100%;            /* 让 max-width:100% / JS 的 maxWidth 真正生效，画布填满预览区 */
  max-width: 100%;
}
.grid-cell {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  /* --cell-radius 由 JS 按「预览缩放比」换算后写入（圆角参数的实时预览）；
     未设置时回退到设计规范的固定小圆角。 */
  border-radius: var(--cell-radius, var(--r-sm));
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 1;
  transition: outline 0.15s;
}
.grid-cell:hover {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
.grid-cell img {
  width: 100%;
  height: 100%;
  /* 填充方式由 JS 写入 --cell-fit（覆盖 cover / 包含 contain / 拉伸 fill），
     默认 cover 与导出默认值保持一致 */
  object-fit: var(--cell-fit, cover);
  display: block;
}
.grid-cell.empty {
  border-style: dashed;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  font-size: 20px;
  background: transparent;
}
.grid-cell .cell-idx {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 10px;
  font-family: var(--mono);
  color: var(--primary);
  font-weight: 600;
  text-shadow: 0 0 2px var(--surface);
  z-index: 1;
}
.grid-cell.selected {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.grid-cell.drag-over {
  outline: 2px dashed var(--primary);
  outline-offset: 2px;
}

/* 网格预览图（canvas 渲染后的完整图） */
.grid-preview-img {
  max-width: 100%;
  height: auto;
  border-radius: var(--r-sm);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ---------- 单格替换面板 ---------- */
.cell-panel-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.cell-panel-mask.active {
  display: flex;
}
.cell-panel {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 20px;
  max-width: 480px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}
.cell-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.cell-panel-head h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}
.cell-panel-close {
  width: 28px;
  height: 28px;
  border-radius: var(--r-full);
  border: none;
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  padding: 0;
}
.cell-panel-close:hover {
  background: var(--border);
}
.cell-panel-section {
  margin-bottom: 16px;
}
.cell-panel-section .section-label {
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 8px;
  font-weight: 600;
}
.cell-panel-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.cell-panel-thumb {
  width: 56px;
  height: 56px;
  border-radius: var(--r-sm);
  overflow: hidden;
  border: 2px solid var(--border);
  cursor: pointer;
  position: relative;
  background: var(--surface-2);
}
.cell-panel-thumb:hover {
  border-color: var(--border-strong);
}
.cell-panel-thumb.on {
  border-color: var(--primary);
}
.cell-panel-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.cell-panel-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.cell-panel-actions button {
  flex: 1;
}

/* ---------- 移动端移动模式 ---------- */
.move-mode-bar {
  display: none;
  padding: 8px 16px;
  background: var(--primary-soft);
  border: 1px solid var(--primary);
  border-radius: var(--r-md);
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--primary);
  align-items: center;
  gap: 8px;
}
.move-mode-bar.active {
  display: flex;
}
.move-mode-bar button {
  margin-left: auto;
}

/* ---------- 响应式 ---------- */
@media (max-width: 768px) {
  .stitch-toolbar {
    gap: 8px;
    padding: 10px 12px;
  }
  .stitch-toolbar .field {
    flex: 1 1 calc(50% - 8px);
  }
  .stitch-preview,
  .grid-preview-wrap {
    padding: 12px;
    min-height: 200px;
    max-height: 400px;
  }
  .dz-thumb {
    width: 48px;
    height: 48px;
  }
  .dz-move-btns {
    display: flex;
  }
  .tpl-btn {
    width: 40px;
    height: 40px;
  }
  .tpl-custom-ctl {
    width: 100%;
    margin-left: 0;
    padding-left: 0;
    border-left: none;
    border-top: 1px solid var(--border);
    padding-top: 8px;
  }
  .stitch-actions .export-btn {
    flex: 1;
    min-width: auto;
  }
  .stitch-actions .clear-btn {
    margin-left: 0;
    flex: 1;
  }
  .stitch-info-bar {
    flex-wrap: wrap;
    gap: 8px;
  }
}

@media (max-width: 480px) {
  .stitch-toolbar .field {
    flex: 1 1 100%;
  }
}

/* ---------- 工具类（替代内联样式） ---------- */
.stitch-toolbar-grid {
  border-radius: 0 0 var(--r-md) var(--r-md);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.ml-auto {
  margin-left: auto;
}
.seo-desc {
  font-size: 13px;
  font-weight: 400;
}

/* 使用场景描述文字：改为常见问题答案正文风格（13px / 常规字重 / 正文字体 / 舒展行高） */
.stat .nm.seo-desc {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.65;
  color: var(--text);
}
/* 模板按钮网格布局（替代内联 grid-template-columns） */
.tpl-btn[data-tpl="2x2"] .tpl-mini { grid-template-columns: 1fr 1fr; }
.tpl-btn[data-tpl="3x3"] .tpl-mini { grid-template-columns: repeat(3, 1fr); }
.tpl-btn[data-tpl="4x4"] .tpl-mini { grid-template-columns: repeat(4, 1fr); }
.tpl-btn[data-tpl="2x3"] .tpl-mini { grid-template-columns: repeat(3, 1fr); }
