:root {
  --bg: #f3f5f9;
  --panel: #ffffff;
  --line: #e4e8ef;
  --line-soft: #eef1f6;
  --text: #1b2129;
  --muted: #6b7482;
  --brand: #2f6bff;
  --brand-dark: #1f52d6;
  --brand-soft: #eaf0ff;
  --danger: #e0454b;
  --ok: #18a058;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .05), 0 8px 24px rgba(20, 30, 50, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), #6d9bff);
  color: #fff;
  display: grid; place-items: center;
  font-size: 17px; font-weight: 700;
  letter-spacing: .5px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 12px; color: var(--muted); }
.privacy {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--ok);
  background: #eafaf1; border: 1px solid #cdeeda;
  padding: 5px 11px; border-radius: 999px; white-space: nowrap;
}

/* ---------- 布局 ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  padding: 18px 22px 40px;
  align-items: start;
  max-width: 1440px;
  margin: 0 auto;
}
.stage { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- 证件类型 ---------- */
.typebar {
  display: flex; gap: 8px; flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow);
}
.type-chip {
  border: 1px solid var(--line);
  background: #fbfcfe;
  border-radius: 9px;
  padding: 7px 14px;
  cursor: pointer;
  transition: .15s;
  font-size: 13px;
  display: flex; flex-direction: column; align-items: flex-start;
  line-height: 1.3;
}
.type-chip small { font-size: 11px; color: var(--muted); }
.type-chip:hover { border-color: #c3d3f7; background: #f6f9ff; }
.type-chip.on {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand-dark);
  font-weight: 600;
}
.type-chip.on small { color: #5c86e0; }

/* ---------- 拖放区 ---------- */
.dropzone {
  border: 2px dashed #cdd6e4;
  border-radius: var(--radius);
  background: var(--panel);
  padding: 46px 24px;
  text-align: center;
  transition: .18s;
}
.dropzone.drag { border-color: var(--brand); background: #f5f8ff; }
.dropzone h2 { margin: 14px 0 6px; font-size: 17px; }
.dropzone p { margin: 0; color: var(--muted); font-size: 13px; }
.drop-actions { display: flex; gap: 10px; justify-content: center; margin: 18px 0 4px; flex-wrap: wrap; }
.dropzone .tip {
  margin-top: 16px; font-size: 12px; color: #93a0b1;
  background: #f7f9fc; display: inline-block; padding: 7px 12px; border-radius: 8px;
}
.dropzone svg { opacity: .5; }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 9px;
  padding: 9px 16px;
  cursor: pointer;
  transition: .15s;
  font-size: 13px;
  white-space: nowrap;
}
.btn:hover { border-color: #c3ccda; background: #fafbfd; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.big { width: 100%; padding: 11px 16px; font-size: 14px; }
.btn.small { padding: 6px 12px; font-size: 12px; }
.btn.tiny { padding: 4px 9px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: #f1f3f7; color: var(--danger); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- 编辑器 ---------- */
.editor { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.canvas-holder {
  position: relative;
  background: #20242b;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  line-height: 0;
  touch-action: none;
  max-width: 100%;
}
.canvas-holder canvas { display: block; max-width: 100%; height: auto; }
.handle {
  position: absolute;
  width: 34px; height: 34px;
  margin: -17px 0 0 -17px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: var(--brand);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
  cursor: grab;
  touch-action: none;
  z-index: 3;
}
.handle:hover { transform: scale(1.12); }
.handle.active { background: #ffb020; cursor: grabbing; }
.editor-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* ---------- 结果列表 ---------- */
.pages {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px 16px;
}
.pages-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.pages-head h3 { margin: 0; font-size: 14px; display: flex; align-items: center; gap: 7px; }
.pages-head em {
  font-style: normal; font-size: 12px; color: var(--brand);
  background: var(--brand-soft); border-radius: 999px; padding: 1px 9px;
}
.page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.page-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fbfcfe;
  position: relative;
}
.page-thumb {
  width: 100%; aspect-ratio: 4 / 3;
  background: #eef1f6;
  display: block;
  object-fit: contain;
  cursor: zoom-in;
}
.page-meta { padding: 7px 9px; display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.page-meta span { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-del {
  border: none; background: #fdecec; color: var(--danger);
  border-radius: 6px; width: 24px; height: 24px; cursor: pointer; flex: none; line-height: 1;
}
.page-del:hover { background: var(--danger); color: #fff; }
.page-order { display: flex; gap: 4px; padding: 0 9px 9px; }
.page-order button {
  flex: 1; border: 1px solid var(--line); background: #fff; border-radius: 6px;
  font-size: 11px; padding: 3px 0; cursor: pointer; color: var(--muted);
}
.page-order button:hover { border-color: var(--brand); color: var(--brand); }
.empty { text-align: center; color: #9aa5b4; font-size: 13px; margin: 16px 0 4px; }

/* ---------- 右侧面板 ---------- */
.panel { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 78px; }
.block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 15px;
}
.block h4 { margin: 0 0 10px; font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: .3px; }
.block.actions { display: flex; flex-direction: column; gap: 9px; }

.seg { display: flex; gap: 4px; background: #f1f3f8; padding: 4px; border-radius: 9px; }
.seg button {
  flex: 1; border: none; background: transparent; border-radius: 7px;
  padding: 7px 4px; cursor: pointer; font-size: 13px; color: var(--muted); transition: .15s;
}
.seg button:hover { color: var(--text); }
.seg button.on { background: #fff; color: var(--brand-dark); font-weight: 600; box-shadow: 0 1px 3px rgba(20, 30, 50, .1); }
.seg.small button { padding: 5px 4px; font-size: 12px; }

.slider { display: flex; align-items: center; gap: 9px; margin-top: 11px; font-size: 12px; color: var(--muted); }
.slider input[type=range] { flex: 1; accent-color: var(--brand); }
.slider > span { width: 38px; text-align: right; font-variant-numeric: tabular-nums; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 9px; margin-top: 10px; font-size: 13px; }
.row > span { color: var(--muted); }
select, input[type=text], input[type=number] {
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; background: #fff; min-width: 0;
}
select { flex: 1; }
input[type=number] { width: 74px; }
input[type=text] { width: 100%; margin-top: 8px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.check input { accent-color: var(--brand); width: 15px; height: 15px; }
.meta { margin: 10px 0 0; font-size: 12px; color: #93a0b1; line-height: 1.5; }
#outMeta { color: var(--muted); }

/* ---------- 效果预览 ---------- */
.preview {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  width: min(460px, 100%);
  display: flex; flex-direction: column; gap: 9px;
}
.preview-head {
  display: flex; align-items: baseline; gap: 9px; justify-content: space-between;
  font-size: 13px; font-weight: 600;
}
.preview-head span { font-size: 11px; font-weight: 400; color: #93a0b1; }
.preview canvas {
  width: 100%; height: auto; display: block;
  background: #eef1f6; border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(20, 30, 50, .06);
}

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(16, 22, 32, .62);
  display: grid; place-items: center; z-index: 60; padding: 18px;
}
.modal[hidden] { display: none; }
.modal-box {
  background: #fff; border-radius: 14px; padding: 16px;
  max-width: min(720px, 96vw); width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.modal-box h3 { margin: 0 0 12px; font-size: 15px; }
.video-wrap { position: relative; background: #000; border-radius: 10px; overflow: hidden; line-height: 0; }
.video-wrap video { width: 100%; display: block; max-height: 62vh; object-fit: contain; }
.cam-frame {
  position: absolute; border: 2px solid rgba(255, 255, 255, .85);
  border-radius: 8px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .28);
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  pointer-events: none;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 14px; }
#viewerImg { width: 100%; border-radius: 10px; background: #f0f2f6; display: block; }

/* ---------- 提示条 ---------- */
.toast-wrap {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 80; align-items: center;
  pointer-events: none;
}
.toast {
  background: #1f2530; color: #fff; padding: 9px 16px; border-radius: 9px;
  font-size: 13px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  animation: toastIn .18s ease-out;
}
.toast.err { background: var(--danger); }
.toast.ok { background: #16a04f; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- 底栏 ---------- */
.footer {
  grid-column: 1 / -1;
  text-align: center;
  color: #93a0b1;
  font-size: 12px;
  padding: 18px 0 4px;
  letter-spacing: .2px;
}

/* ---------- 响应式 ---------- */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; padding: 14px; }
  .panel { position: static; }
  .topbar { padding: 12px 14px; }
  .footer { padding: 10px 0 0; }
}
@media (max-width: 560px) {
  .brand-text span { display: none; }
  .dropzone { padding: 30px 14px; }
  .page-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}
