/* =========================================================
   HelloTopTen 定制篆刻弹窗组件 · engraving-widget.css
   接入方式：将本文件引入产品详情页 <head>，配合 engraving-widget.js 使用
   前缀约定：所有类名以 ht- 开头，避免与你网站现有样式冲突
   ========================================================= */

.ht-customize-link {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: rgba(37, 99, 235, .92);
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  backdrop-filter: blur(4px);
  box-shadow: 0 2px 10px rgba(15, 23, 42, .25);
  transition: background .15s ease;
  touch-action: manipulation;
}
.ht-customize-link:hover { background: #1d4ed8; }
.ht-customize-link:focus-visible,
.ht-close-btn:focus-visible,
.ht-tab-btn:focus-visible,
.ht-act-btn:focus-visible,
.ht-save-btn:focus-visible,
.ht-color-dot:focus-visible,
.ht-file-label:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}
.ht-customize-link svg { width: 16px; height: 16px; flex: none; }

/* ===== 弹窗 ===== */
.ht-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(15, 23, 42, .6);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.ht-modal-overlay.ht-open { display: flex; }

.ht-modal {
  width: 100%;
  max-width: 980px;
  max-height: calc(100vh - 32px);
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ht-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
}
.ht-modal-head h2 { font-size: 17px; font-weight: 700; margin: 0; }
.ht-modal-head .ht-hint { font-size: 12px; color: #6b7280; margin-top: 2px; }
.ht-close-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: #f1f5f9;
  color: #1f2937;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  flex: none;
}
.ht-close-btn:hover { background: #e2e8f0; }

.ht-modal-body {
  display: flex;
  flex-wrap: wrap;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* ===== 画布区 ===== */
.ht-canvas-wrap {
  flex: 1 1 560px;
  min-width: 300px;
  min-height: 340px;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(45deg, #eef2f7 25%, transparent 25%, transparent 75%, #eef2f7 75%),
    linear-gradient(45deg, #eef2f7 25%, transparent 25%, transparent 75%, #eef2f7 75%),
    #f8fafc;
  background-size: 24px 24px;
  background-position: 0 0, 12px 12px;
  position: relative;
}
.ht-canvas-frame {
  position: relative;
  width: 480px;
  max-width: 100%;
  box-shadow: 0 4px 20px rgba(15, 23, 42, .18);
  border-radius: 4px;
}
.ht-canvas-frame img.ht-base {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}
.ht-canvas-frame svg.ht-editor {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none; /* 手势由 pointer 事件接管，避免移动端页面滚动 */
}
.ht-canvas-hint {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  font-size: 12px;
  color: #475569;
  background: rgba(255, 255, 255, .88);
  border: 1px solid #e5e7eb;
  padding: 4px 10px;
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100% - 20px);
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== 侧栏 ===== */
.ht-side {
  flex: 0 0 300px;
  width: 300px;
  border-left: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
}

.ht-tabs { display: flex; gap: 8px; padding: 14px 16px 0; }
.ht-tab-btn {
  flex: 1;
  padding: 9px 0;
  font-size: 13px;
  font-weight: 600;
  color: #6b7280;
  background: #f1f5f9;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  cursor: pointer;
}
.ht-tab-btn.ht-active { color: #fff; background: #2563eb; border-color: #2563eb; }

.ht-tab-panel { padding: 14px 16px 4px; display: none; }
.ht-tab-panel.ht-active { display: block; }

.ht-field { margin-bottom: 12px; }
.ht-field label { display: block; font-size: 12px; font-weight: 600; color: #475569; margin-bottom: 6px; }
.ht-field input[type="text"] {
  width: 100%;
  padding: 9px 10px;
  font-size: 14px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
}
.ht-field input[type="text"]:focus { outline: 2px solid #2563eb; outline-offset: -1px; }

/* 顶部即时变色控件（跨文字 / Logo 两个面板共享） */
.ht-color-field { padding: 14px 16px 0; }
.ht-color-field.ht-layer-active {
  background: #eff6ff;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px #bfdbfe;
}
.ht-color-input {
  width: 34px;
  height: 30px;
  padding: 0;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  flex: none;
}
.ht-color-input::-webkit-color-swatch-wrapper { padding: 2px; }
.ht-color-input::-webkit-color-swatch { border: none; border-radius: 4px; }
.ht-mini-btn {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  background: #fff;
  color: #475569;
  cursor: pointer;
  flex: none;
}
.ht-mini-btn:hover { border-color: #2563eb; color: #2563eb; }

.ht-color-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ht-color-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #cbd5e1;
  cursor: pointer;
  padding: 0;
}
.ht-color-dot.ht-sel { box-shadow: 0 0 0 2px #2563eb; }

.ht-size-row { display: flex; align-items: center; gap: 10px; }
.ht-size-row input[type="range"] { flex: 1; accent-color: #2563eb; }
.ht-size-row output { font-size: 12px; color: #6b7280; width: 74px; text-align: right; }

.ht-file-label {
  display: block;
  text-align: center;
  padding: 18px 12px;
  border: 2px dashed #cbd5e1;
  border-radius: 10px;
  color: #2563eb;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: #f8fafc;
}
.ht-file-label:hover { border-color: #2563eb; background: #eff6ff; }
.ht-file-label small { display: block; font-weight: 400; color: #6b7280; margin-top: 4px; font-size: 11px; }
.ht-up-status { font-size: 12px; color: #6b7280; margin-top: 8px; min-height: 16px; }
.ht-up-status.ht-err { color: #dc2626; }
.ht-file-note { font-size: 11px; color: #94a3b8; margin-top: 8px; line-height: 1.6; }

.ht-act-btn {
  flex: 1;
  padding: 9px 0;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  background: #fff;
  color: #1f2937;
  cursor: pointer;
}
.ht-act-btn:disabled { opacity: .45; cursor: not-allowed; }
.ht-act-btn.ht-danger { color: #dc2626; }
.ht-act-btn.ht-danger:hover:not(:disabled) { border-color: #dc2626; }
.ht-btn-row { display: flex; gap: 8px; margin: 6px 0 14px; }

.ht-layer-list { max-height: 120px; overflow: auto; margin-top: 8px; }
.ht-layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  font-size: 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
}
.ht-layer-item.ht-sel { border-color: #2563eb; background: #eff6ff; }
.ht-layer-item .ht-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ht-layer-item .ht-del { color: #dc2626; border: none; background: none; cursor: pointer; font-size: 12px; padding: 2px 4px; }

.ht-save-btn {
  display: block;
  width: 100%;
  padding: 13px 0;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
.ht-save-btn:hover { filter: brightness(1.06); }
.ht-side-foot {
  padding: 14px 16px 16px;
  border-top: 1px solid #e5e7eb;
  margin-top: auto;
}

.ht-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: #111827;
  color: #fff;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 10000;
}
.ht-toast.ht-show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) {
  .ht-toast, .ht-customize-link, .ht-save-btn { transition: none; }
}


/* v4：弹窗内不再有图集列表（底图跟随页面当前选中图），缩略图样式已删除 */

/* 融合按钮 */
.ht-act-btn.ht-merge { color: #2563eb; border-color: #bfdbfe; background: #eff6ff; }
.ht-act-btn.ht-merge:hover { border-color: #2563eb; }

/* 变形态角手柄 */
.ht-scale-handle.ht-warp { fill: #bfdbfe; stroke: #1d4ed8; }

/* =========================================================
   v4.3：移动端 / 触摸适配
   ========================================================= */

/* 触摸命中区：透明但可点（fill:transparent 仍参与命中，配合 pointer-events:all）。
   盖在小的可见手柄之上，手指不必精确点中 5px 的小方块。 */
.ht-scale-handle.ht-hit,
.ht-rot-handle.ht-hit,
.ht-scale-handle.ht-hit.ht-warp {
  fill: transparent;
  stroke: none;
  pointer-events: all;
}

/* 触摸设备：可点区域放大到 ≥44px；输入框 16px，避免 iOS 聚焦时页面自动放大 */
@media (pointer: coarse) {
  .ht-act-btn,
  .ht-tab-btn,
  .ht-save-btn,
  .ht-mini-btn,
  .ht-layer-item,
  .ht-file-label,
  .ht-customize-link {
    min-height: 44px;
    font-size: 15px;
  }
  .ht-field input[type="text"],
  .ht-color-input {
    font-size: 16px;
    min-height: 44px;
  }
  .ht-color-input { width: 44px; height: 40px; }
  .ht-color-dot { width: 40px; height: 40px; }
  .ht-close-btn { width: 44px; height: 44px; }
  .ht-layer-item .ht-del { padding: 8px 12px; font-size: 13px; }
  .ht-size-row input[type="range"] { height: 32px; }
}

/* 小屏：弹窗全屏化 + 安全区适配 + 画布自适应 */
@media (max-width: 860px) {
  .ht-modal-overlay { padding: 0; align-items: stretch; justify-content: stretch; }
  .ht-modal {
    max-width: 100%;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
  }
  .ht-modal-head {
    padding: 12px 14px;
    padding-top: calc(12px + env(safe-area-inset-top));
    flex: none;
  }
  /* 关键修复：列方向下必须禁止换行。
     否则 flex-wrap:wrap 会把过高的侧栏面板折到「第二列」，
     容器横向溢出；聚焦隐藏的 file input 时浏览器会自动横向滚动，
     导致画布被推到屏幕左侧之外（实测偏移正好一个视口宽度 390px），触控点不到。 */
  .ht-modal-body {
    flex-direction: column;
    flex-wrap: nowrap;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
  }
  /* 画布区固定占位（不参与纵向压缩），侧栏自己内部滚动。
     否则侧栏（flex:0 0 auto）会把画布压到十几像素高，
     而画布是 align-items:center 垂直居中的 → 整块画布被推到屏幕上下之外，触控不到。 */
  .ht-canvas-wrap {
    flex: 0 0 auto;
    min-width: 0;
    min-height: 0;
    padding: 10px;
    overflow: hidden;
  }
  .ht-canvas-frame { width: 100%; }
  .ht-canvas-hint { white-space: normal; font-size: 11px; line-height: 1.5; text-align: center; }
  .ht-side {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    border-left: none;
    border-top: 1px solid #e5e7eb;
  }
  .ht-tabs { padding: 12px 12px 0; }
  .ht-tab-panel { padding: 12px 12px 4px; }
  .ht-color-field { padding: 12px 12px 0; }
  .ht-layer-list { max-height: 180px; }
  .ht-side-foot { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
}

/* 窄屏（≤420px）进一步压缩间距 */
@media (max-width: 420px) {
  .ht-modal-head h2 { font-size: 16px; }
  .ht-canvas-wrap { padding: 6px; }
  .ht-tabs { padding: 10px 10px 0; }
  .ht-tab-panel { padding: 10px 10px 4px; }
  .ht-color-field { padding: 10px 10px 0; }
}
