/* ==========================================================================
 * preview.css — 右侧预览区：工具栏、网格、导出栏样式
 * ========================================================================== */

/* ---------- 空状态提示 ---------- */
.preview-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--color-text-muted);
  text-align: center;
  gap: 8px;
}
.preview-empty .empty-icon {
  font-size: 48px;
  opacity: 0.5;
}
.preview-empty .empty-hint {
  font-size: 12px;
  opacity: 0.6;
}

/* ---------- 预览工具栏 ---------- */
.preview-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 10px 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  flex-shrink: 0;
}
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.toolbar-group label {
  font-size: 12px;
  color: var(--color-text-muted);
  white-space: nowrap;
}
.toolbar-group span {
  font-size: 12px;
  color: var(--color-text-muted);
}
.toolbar-group input[type="number"] {
  width: 56px;
}

/* ★ 工具栏弹性间距（把清除按钮推到最右侧） */
.toolbar-spacer {
  flex: 1;
}

/* ---------- 预览网格容器 ---------- */
.preview-grid {
  flex: 1;
  overflow: auto;
  min-height: 200px;
}
/* 网格使用 CSS Grid 布局，列数由 JS 动态设置 inline style
 * ★ 关键：align-content: start 防止行数较少时 Grid 的默认 stretch 行为
 *   撑开行高，确保 gap 严格等于用户设置的间距值，多余空白留在网格下方 */
.preview-grid-inner {
  display: grid;
  gap: var(--preview-gap, 4px);
  /* grid-template-columns 由 JS 设置 */
  align-content: start;
  padding: 4px;
}

/* 单个预览格子 */
.preview-cell {
  position: relative;
  aspect-ratio: 1;
  background: var(--color-border);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--transition-fast),
              box-shadow var(--transition-fast);
  cursor: grab;
}
.preview-cell:active {
  cursor: grabbing;
}
/* 有内容的格子 */
.preview-cell.filled {
  border-color: var(--color-border-active);
  background: var(--color-bg);
}
/* 空占位格子 */
.preview-cell.empty {
  border-style: dashed;
  border-color: var(--color-border);
  background: transparent;
}
.preview-cell.empty::after {
  content: '';
  width: 24px;
  height: 24px;
  border: 2px dashed var(--color-border);
  border-radius: 4px;
  opacity: 0.4;
}

/* 拖拽状态 */
.preview-cell.drag-over {
  border-color: var(--color-accent) !important;
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.3);
  z-index: 2;
}
.preview-cell.dragging {
  opacity: 0.4;
}

/* 预览图 */
.preview-cell img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;        /* 拖拽事件由父元素处理 */
}

/* 删除按钮 */
.preview-cell .cell-delete-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: var(--color-text-muted);
  opacity: 0;
  transition: opacity var(--transition-fast), color var(--transition-fast);
}
.preview-cell:hover .cell-delete-btn {
  opacity: 1;
}
.preview-cell .cell-delete-btn:hover {
  color: var(--color-danger);
  background: rgba(0, 0, 0, 0.8);
}

/* 格子编号（调试/排序参考，可选） */
.preview-cell .cell-index {
  position: absolute;
  bottom: 2px;
  left: 4px;
  font-size: 10px;
  color: var(--color-text-muted);
  opacity: 0.5;
  pointer-events: none;
}

/* ---------- 导出栏 ---------- */
.export-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  margin-top: 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  flex-shrink: 0;
}
.export-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.export-group label {
  font-size: 13px;
  color: var(--color-text-muted);
  white-space: nowrap;
}
.export-ext {
  font-size: 13px;
  color: var(--color-text-muted);
  font-weight: 600;
}
.btn-export {
  background: var(--color-success);
  color: #fff;
  padding: 8px 24px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius);
}
.btn-export:hover {
  filter: brightness(1.1);
}
.btn-export:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: none;
}

/* ---------- 响应式：工具栏折行 ---------- */
@media (max-width: 900px) {
  .preview-toolbar {
    gap: 8px;
  }
  .export-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .btn-export {
    width: 100%;
  }
}
