/* ============ 可视化编辑器样式 ============ */
:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #eef2ff;
  --success: #10b981;
  --danger: #ef4444;

  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.06), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);

  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.editor { display: flex; flex-direction: column; height: 100vh; }

/* 顶部栏 */
.ed-top {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 60px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ed-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.ed-back svg { width: 16px; height: 16px; }
.ed-back:hover { background: var(--primary-light); color: var(--primary); }

.ed-top-title {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  text-align: center;
}

.ed-top-actions { display: flex; gap: 10px; }

.ed-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 36px;
  padding: 0 16px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition);
}

.ed-btn:hover { background: var(--border-light); color: var(--text); }
.ed-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.ed-btn.primary:hover { background: var(--primary-dark); }
.ed-btn.danger { color: var(--danger); border-color: #fecaca; background: #fef2f2; }
.ed-btn.danger:hover { background: #fee2e2; }
.ed-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* 主体两栏 */
.ed-body { display: flex; flex: 1; min-height: 0; }

/* 画布区 */
.ed-canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  overflow: auto;
  background:
    radial-gradient(circle at 20% 20%, rgba(99, 102, 241, 0.06) 0%, transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(99, 102, 241, 0.05) 0%, transparent 40%);
}

.ed-canvas {
  width: 100%;
  max-width: 420px;
  height: 100%;
  max-height: 820px;
  background: #fff;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 8px solid #fff;
}

/* 文件下载模式画布 */
.ed-file-canvas {
  align-items: center;
  justify-content: center;
  background: #f8fafc;
}
.ed-file-card {
  width: 100%;
  max-width: 320px;
  text-align: center;
  padding: 28px 22px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.ed-file-icon {
  width: 56px; height: 56px;
  margin: 0 auto 14px;
  color: #2563eb;
  background: #eff6ff;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
}
.ed-file-icon svg { width: 30px; height: 30px; }
.ed-file-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  outline: none;
  border-radius: 8px;
  padding: 4px 6px;
  min-height: 28px;
}
.ed-file-title:empty::before {
  content: attr(data-placeholder);
  color: var(--text-tertiary);
}
.ed-file-name {
  font-size: 16px; font-weight: 600; color: var(--text);
  word-break: break-all; margin-bottom: 6px;
}
.ed-file-sub {
  font-size: 12px; color: var(--text-tertiary);
  margin-bottom: 16px; word-break: break-all;
}

/* 模拟手机浏览器顶部导航栏（与真机扫码一致） */
.ed-browser-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 42px;
  padding: 0 14px;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}

.ed-browser-close,
.ed-browser-more {
  flex: 0 0 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #333;
  font-size: 19px;
  line-height: 1;
  cursor: default;
  user-select: none;
}

.ed-browser-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: #1f2937;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 模拟 view.php 页面（浅色干净风，与真机一致） */
.ed-view-body {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  padding: 0;
  overflow: auto;
  background: #ffffff;
}

.ed-view-card {
  width: 100%;
  height: fit-content;
  background: transparent;
  overflow: hidden;
}

/* 页面标题输入框（控制微信/支付宝导航条标题，不显示在照片页） */
.ed-page-title-input {
  width: 100%;
  font-size: 15px;
  color: #111827;
  padding: 10px 12px;
  border: 1px solid #d8dee6;
  border-radius: 10px;
  background: #fff;
  outline: none;
  box-sizing: border-box;
  transition: border-color .15s, box-shadow .15s;
}
.ed-page-title-input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

/* 照片（全屏黑底） */
.ed-photo-wrap {
  position: relative;
  min-height: 240px;
  background: #ffffff;
  cursor: pointer;
  overflow: hidden;
}

.ed-photo { width: 100%; height: auto; display: block; }

/* 网页形式：预览的是 PDF 首页（A4 竖长图），等比缩到手机框里，
   否则整页图会撑出框、底部多出一截「照片」 */
.ed-photo-wrap .ed-photo {
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: min(72vh, 720px);
  margin: 0 auto;
  object-fit: contain;
}

.ed-photo-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #9ca3af;
  pointer-events: none;
}

.ed-photo-empty svg { width: 44px; height: 44px; opacity: 0.7; }

.ed-photo-tip { font-size: 14px; font-weight: 500; }

.ed-photo-mask {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.5);
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  transition: var(--transition);
}

.ed-photo-wrap:hover .ed-photo-mask { display: flex; }
.ed-photo-wrap.ed-no-photo .ed-photo-mask { display: flex; background: rgba(15, 23, 42, 0.35); }

.ed-wm {
  position: absolute;
  inset: 0;
  display: grid;
  /* 同 view.php：必须 minmax(0,1fr)，否则 16px nowrap 文字会把列撑到 64px */
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(20, minmax(0, 1fr));
  pointer-events: none;
  overflow: hidden;
}
.ed-wm span {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #000;
  /* 同 view.php：基准 16px + scale(0.1875) = 视觉 3px，绕过 iOS 最小字号钳制 */
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  user-select: none;
  transform: rotate(-26deg) scale(0.1875);
}

/* 侧栏 */
.ed-sidebar {
  width: 320px;
  flex-shrink: 0;
  padding: 20px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ed-panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
}

.ed-panel-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 14px;
  letter-spacing: 0.02em;
}

.ed-field { margin-bottom: 16px; }
.ed-field:last-child { margin-bottom: 0; }

.ed-field label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.ed-field-val {
  font-weight: 600;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.ed-field input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  background: var(--border);
  border-radius: 4px;
  outline: none;
}

.ed-field input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.2);
}

.ed-field input[type="range"]::-moz-range-thumb {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid #fff;
}

.ed-qr-wrap { display: flex; align-items: center; justify-content: center; padding: 8px 0 12px; }

#qr-canvas {
  background: #fff;
  border-radius: 0;
  border: 1px solid var(--border);
}

.ed-qr-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  text-align: center;
  margin-bottom: 12px;
  min-height: 18px;
}

.ed-field select,
.ed-field input[type="text"],
.ed-field input[type="datetime-local"] {
  width: 100%;
  font-size: 14px;
  color: var(--text);
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  outline: none;
  box-sizing: border-box;
  transition: var(--transition);
}

.ed-field select:focus,
.ed-field input[type="datetime-local"]:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

.ed-btn.block {
  width: 100%;
  justify-content: center;
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}

.ed-btn.block:hover { background: var(--border-light); }

.ed-tips {
  margin: 0;
  padding-left: 18px;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.9;
}

/* Toast */
.ed-toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #fff;
  padding: 11px 20px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s;
  z-index: 9999;
  box-shadow: var(--shadow-lg);
}

.ed-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.ed-toast.error { background: var(--danger); }
.ed-toast.success { background: var(--success); }

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* 校验成功页编辑器预览 */
.ed-success-canvas { background: #f1f2f4; }
.ed-success-card { width: 100%; background: #f1f2f4; }
.ed-success-banner { display: flex; flex-direction: column; align-items: center; padding: 30px 0 6px; }
.ed-success-ok { width: 64px; height: 64px; display: block; }
.ed-success-ok circle { fill: none; stroke: #23a06f; stroke-width: 5; }
.ed-success-ok path { fill: none; stroke: #23a06f; stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
.ed-success-tip { margin: 20px 0 0; font-size: 15px; font-weight: 400; letter-spacing: 1px; color: #9ba1a8; }
.ed-success-viewer {
  position: relative; margin: 18px auto 0; width: 80%; max-width: 300px;
  aspect-ratio: 865 / 1200; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .06); overflow: hidden; border-radius: 1px; cursor: pointer;
}
.ed-success-viewer img { width: 100%; height: 100%; object-fit: contain; display: block; }
.ed-success-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; color: #9ca3af; pointer-events: none;
}
.ed-success-empty svg { width: 40px; height: 40px; opacity: .7; }
.ed-success-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.ed-success-thumb {
  position: relative; width: 54px; height: 72px; border: 1px solid var(--border);
  border-radius: 6px; overflow: hidden; background: #fff;
}
.ed-success-thumb img { width: 100%; height: 100%; object-fit: contain; }
.ed-success-thumb-del {
  position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; line-height: 16px;
  text-align: center; border: 0; border-radius: 50%; background: rgba(15, 23, 42, .7);
  color: #fff; font-size: 13px; cursor: pointer; padding: 0;
}
.ed-success-thumb-del:hover { background: var(--danger); }

/* 响应式 */
@media (max-width: 768px) {
  .ed-body { flex-direction: column; }
  .ed-sidebar { width: 100%; border-left: none; border-top: 1px solid var(--border); }
  .ed-canvas { max-height: none; height: auto; min-height: 520px; }
  .ed-view-body { min-height: 480px; }
  .ed-photo-wrap { min-height: 280px; }
  .ed-top { padding: 0 12px; gap: 8px; }
  .ed-btn { height: 34px; padding: 0 12px; font-size: 12px; }
  .ed-top-title { display: none; }
}
