:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --border: #e2e6ee;
  --text: #1f2733;
  --muted: #7a8494;
  --primary: #3b6cf6;
  --primary-hover: #2f5ae0;
  --danger: #e5484d;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 26px; }
.brand h1 { font-size: 18px; font-weight: 700; }
.brand .sub { color: var(--muted); font-size: 13px; margin-left: 6px; }

.actions { display: flex; gap: 10px; }

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn:hover { border-color: #c9d1e0; background: #f8fafc; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-primary:disabled { background: #b9c8f7; border-color: #b9c8f7; cursor: not-allowed; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: #f3c4c6; }
.btn-danger:hover { background: #fdf0f0; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ---------- 主布局 ---------- */
.layout {
  display: flex;
  flex: 1;
  gap: 16px;
  padding: 16px;
  min-height: 0;
}

.sidebar {
  width: 330px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  max-height: calc(100vh - 90px);
  position: sticky;
  top: 76px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.panel h2 { font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.panel h2 small { color: var(--muted); font-weight: 400; }

/* ---------- 上传区 ---------- */
.dropzone {
  border: 2px dashed #c9d1e0;
  border-radius: 10px;
  padding: 22px 12px;
  text-align: center;
  cursor: pointer;
  transition: all .15s;
  background: #fafbfe;
}
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: #eef3ff; }
.dz-icon { font-size: 30px; margin-bottom: 6px; }
.dropzone p { font-size: 13px; }
.dz-hint { color: var(--muted); font-size: 12px; margin-top: 4px; }

.info {
  font-size: 13px;
  background: #f0f6ff;
  border: 1px solid #d5e4ff;
  color: #1f4e9e;
  border-radius: 8px;
  padding: 8px 10px;
  margin-top: 10px;
  word-break: break-all;
}
.info.muted { background: #f6f7f9; border-color: var(--border); color: var(--muted); }
.info.error { background: #fdf0f0; border-color: #f3c4c6; color: #b02a2e; }

.hidden { display: none !important; }

/* PDF 缩略图 */
.thumbs { margin-top: 10px; }
.thumbs h3 { font-size: 13px; color: var(--muted); font-weight: 400; margin-bottom: 8px; }
.thumb-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
}
.thumb-item {
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: #fff;
  position: relative;
  transition: border-color .15s;
}
.thumb-item:hover { border-color: var(--primary); }
.thumb-item.active { border-color: var(--primary); }
.thumb-item img, .thumb-item canvas { width: 100%; display: block; }
.thumb-item .thumb-no {
  position: absolute;
  left: 6px;
  bottom: 6px;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 6px;
}

/* 叠加图槽位 */
.slot-row { display: flex; gap: 10px; }
.slot {
  flex: 1;
  border: 2px dashed #c9d1e0;
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
  background: #fafbfe;
  transition: all .15s;
  position: relative;
}
.slot:hover { border-color: var(--primary); background: #eef3ff; }
.slot.filled { border-style: solid; border-color: #9fc0ff; }
.slot.active { border-color: var(--primary); background: #eef3ff; }
.slot-label {
  position: absolute;
  top: -9px;
  left: 8px;
  background: var(--panel);
  padding: 0 6px;
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.slot-body { min-height: 64px; display: flex; align-items: center; justify-content: center; flex-direction: column; }
.slot-empty { font-size: 12px; color: var(--muted); }
.slot-preview { max-width: 100%; max-height: 64px; border-radius: 6px; display: block; }
.slot-name { font-size: 11px; color: var(--muted); margin-top: 4px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tip { font-size: 12px; color: var(--muted); line-height: 1.6; margin-top: 10px; }
.tip b { color: #44506a; }

/* ---------- 调整面板 ---------- */
.adjust { display: flex; flex-direction: column; gap: 12px; }
.adj-row { display: flex; align-items: center; gap: 10px; }
.adj-row label { font-size: 13px; color: #44506a; width: 86px; flex-shrink: 0; }
.adj-row label .val { color: var(--primary); font-weight: 600; margin-left: 2px; }
.adj-row select, .adj-row input[type=range] { flex: 1; }
.adj-row select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
}
input[type=range] { accent-color: var(--primary); cursor: pointer; }
.adj-actions { gap: 10px; }

/* ---------- 画布区 ---------- */
.canvas-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.canvas-toolbar {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.canvas-box {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  background:
    repeating-conic-gradient(#eef0f4 0% 25%, #ffffff 0% 50%) 0 0 / 22px 22px;
  padding: 24px;
  position: relative;
}
#stage {
  max-width: 100%;
  max-height: calc(100vh - 220px);
  background: #fff;
  box-shadow: 0 4px 24px rgba(16,24,40,.18);
  border-radius: 4px;
  cursor: default;
  touch-action: none;
}
#stage.selected { cursor: move; }

.placeholder {
  position: absolute;
  color: #98a2b3;
  font-size: 14px;
  text-align: center;
  line-height: 1.8;
  pointer-events: none;
}

/* toast */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: #232b36;
  color: #fff;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 99;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  animation: fadeUp .25s ease;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #c9d1e0; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; position: static; max-height: none; }
}
