:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --line: #e2e5ea;
  --line-strong: #cbd1d9;
  --ink: #1b2430;
  --muted: #697586;
  --accent: #0f766e;
  --accent-soft: #e6f2f0;
  --danger: #b42318;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

body { display: flex; flex-direction: column; }

svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: 0; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.status { color: var(--muted); font-size: 13px; }

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
}

.panel {
  overflow-y: auto;
  padding: 16px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.block { margin-bottom: 22px; }
.block:last-child { margin-bottom: 0; }

.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.block-head h2 { margin: 0; font-size: 13px; font-weight: 650; color: var(--muted); }

.badge {
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 650;
  text-align: center;
}

.dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 16px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: #fbfcfd;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.dropzone:hover, .dropzone.dragover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.filelist, .stamplist { list-style: none; margin: 10px 0 0; padding: 0; }

.filelist li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
}

.filelist li:nth-child(odd) { background: #f8f9fb; }
.filelist li { cursor: pointer; }
.filelist li:hover { background: #eef2f5; }
.filelist li.active {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}
.filelist li.active .name { font-weight: 650; color: var(--accent); }
.filelist .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filelist .size { color: var(--muted); font-size: 12px; }

.stamplist { display: flex; flex-wrap: wrap; gap: 8px; }

.stamplist li {
  position: relative;
  width: 62px;
  height: 62px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: repeating-conic-gradient(#eef1f4 0 25%, #ffffff 0 50%) 0 0 / 12px 12px;
  cursor: pointer;
  overflow: hidden;
}

.stamplist li.active { border-color: var(--accent); }
.stamplist img { width: 100%; height: 100%; object-fit: contain; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:not(:disabled):hover { background: #0b5f59; }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.btn-ghost:hover { color: var(--ink); border-color: var(--line-strong); }
.btn-icon { padding: 7px; }

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--muted);
}

.field em { font-style: normal; font-weight: 650; color: var(--accent); }

input[type=range] {
  width: 100%;
  accent-color: var(--accent);
}

.text-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  color: var(--ink);
}

.text-input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8f9fb;
}

.segmented button {
  padding: 6px 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.segmented button.active {
  background: var(--surface);
  color: var(--accent);
  font-weight: 650;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .12);
}

.switch-row { margin-bottom: 14px; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.switch input { accent-color: var(--accent); width: 15px; height: 15px; }

.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.stage-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px;
  color: var(--muted);
}

.stage-hint { margin-left: auto; }

.zoom {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 8px;
  padding-left: 10px;
  border-left: 1px solid var(--line);
}

.zoom-label {
  min-width: 46px;
  text-align: center;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.doc-select {
  max-width: 200px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  font: inherit;
  font-size: 13px;
  color: var(--ink);
}

.doclist {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 150px;
  overflow-y: auto;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.doclist .doc-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 2px 4px;
  border-radius: 5px;
  font-size: 13px;
  cursor: pointer;
}

.doclist .doc-row.active { background: var(--accent-soft); }
.doclist input { accent-color: var(--accent); width: 14px; height: 14px; }
.doclist .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doclist .rule { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.doclist .doc-row.active .rule { color: var(--accent); }
.doclist .empty { color: var(--muted); font-size: 12px; }

.rule-body { margin-top: 12px; }
.rule-body[hidden] { display: none; }

.stage-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 24px;
}

.page-wrap {
  position: relative;
  width: fit-content;
  margin: 0 auto;
  background: #fff;
  box-shadow: 0 1px 3px rgba(16, 24, 40, .14), 0 8px 24px rgba(16, 24, 40, .08);
  touch-action: none;
}

.page-wrap canvas { display: block; }

.overlay { position: absolute; inset: 0; }

.stamp-box {
  position: absolute;
  cursor: grab;
  outline: 1px dashed transparent;
}

.stamp-box:hover { outline-color: rgba(15, 118, 110, .45); }
.stamp-box.active { outline: 1px dashed var(--accent); }
.stamp-box.dragging { cursor: grabbing; }

.stamp-box canvas {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  user-select: none;
}

.stamp-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  border: 2px solid var(--accent);
  border-radius: 3px;
  background: #fff;
  cursor: nwse-resize;
}

.empty-note {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
}

.empty-note[hidden] { display: none; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto minmax(320px, 1fr); }
  .panel { border-right: none; border-bottom: 1px solid var(--line); max-height: 46vh; }
}
