:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --ink: #18212b;
  --muted: #68727e;
  --line: #d8dee5;
  --accent: #d94841;
  --accent-dark: #b8322d;
  --blue: #2879b9;
  --green: #20856b;
  --shadow: 0 10px 28px rgba(26, 35, 45, .09);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font-family: "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif; color: var(--ink); background: var(--bg); font-size: 14px; }
button, input { font: inherit; }
button { cursor: pointer; }
.topbar { height: 72px; display: flex; align-items: center; justify-content: space-between; padding: 0 24px; background: #fff; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { width: 42px; height: 42px; }
.brand h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: 0; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.print-toolbar { display: flex; flex-wrap: wrap;justify-content: center;gap: 8px 6px; align-items: center; }
.print-toolbar [draggable="true"] { cursor: grab; }
.print-toolbar .dragging { opacity: .4; }
.print-toolbar .drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; border-radius: 6px; }
.print-toolbar .button { min-height: 34px; padding: 0 10px; font-size: 13px; white-space: nowrap; }
.print-toolbar .switch { font-size: 13px; }
.print-toolbar .switch i { font-style: normal; font-size: 12px; font-weight: 600; }
.toolbar-tip { flex-basis: 100%; font-size: 11px; color: #8a94a0; text-align: center; user-select: none; }
.button { min-height: 38px; border: 1px solid transparent; border-radius: 6px; padding: 0 14px; font-weight: 600; color: var(--ink); background: #fff; display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.button:hover { filter: brightness(.97); }
.button:disabled { cursor: not-allowed; opacity: .45; }
.button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { border-color: #aeb8c2; }
.button.ghost { background: #f3f5f7; border-color: #e0e5ea; }
.switch { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-right: 6px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch span { width: 38px; height: 22px; border-radius: 12px; background: #adb5bd; position: relative; transition: .2s; }
.switch span::after { content: ""; width: 16px; height: 16px; background: #fff; border-radius: 50%; position: absolute; left: 3px; top: 3px; transition: .2s; box-shadow: 0 1px 3px #5555; }
.switch input:checked + span { background: var(--ink); }
.switch input:checked + span::after { transform: translateX(16px); }
.workspace { height: calc(100vh - 72px); min-height: 680px; display: grid; grid-template-columns: 260px minmax(520px, 1.3fr) minmax(300px, .62fr); gap: 14px; padding: 14px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); min-width: 0; }
.setup-panel { padding: 18px 16px; overflow: auto; }
.setup-panel section + section { border-top: 1px solid #e8ebee; margin-top: 18px; padding-top: 18px; }
.section-label { color: #515c68; text-transform: uppercase; font-size: 12px; font-weight: 700; margin-bottom: 9px; }
.section-head { display: flex; align-items: center; justify-content: space-between; }
.small-note { color: var(--muted); font-size: 12px; }
.segmented { background: #edf0f3; padding: 3px; border-radius: 6px; display: grid; grid-template-columns: repeat(3, 1fr); }
#docTabs { grid-template-columns: repeat(4, 1fr); }
#paperCanvas { cursor: grab; touch-action: none; }
#paperCanvas.card-dragging { cursor: grabbing; }
#templateDocTabs { grid-template-columns: repeat(4, 1fr); }
.segmented button { height: 36px; border: 0; background: transparent; border-radius: 4px; color: #5f6974; font-weight: 600; }
.segmented button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 4px #22334422; }
.source-list { display: grid; gap: 8px; }
.source-card { height: 68px; border: 1px dashed #bdc5cd; border-radius: 6px; padding: 8px; display: grid; grid-template-columns: 50px 1fr 30px; align-items: center; gap: 9px; cursor: pointer; background: #fafbfc; }
.source-card:hover, .source-card.active { border-color: var(--accent); background: #fff7f6; }
.source-card[draggable="true"] { cursor: grab; }
.source-card.dragging { opacity: .45; }
.source-card.drag-over { border-color: var(--accent); background: #fff7f6; box-shadow: inset 0 0 0 1px var(--accent); }
.source-card.has-image { border-style: solid; }
.source-thumb { width: 50px; height: 50px; border-radius: 4px; background: #e9edf1; display: grid; place-items: center; overflow: hidden; color: #8a949e; font-size: 20px; }
.source-thumb img { width: 100%; height: 100%; object-fit: cover; }
.source-text strong { display: block; font-size: 13px; margin-bottom: 4px; }
.source-text span { color: var(--muted); font-size: 11px; }
.source-action { width: 28px; height: 28px; border: 0; border-radius: 4px; background: #eef1f4; font-size: 17px; color: #5f6974; }
.template-list { display: grid; gap: 8px; }
.template-card { min-height: 56px; display: grid; grid-template-columns: 44px 1fr; gap: 10px; align-items: center; padding: 7px; border: 1px solid var(--line); background: #fff; border-radius: 6px; text-align: left; }
.template-card:hover, .template-card.active { border-color: var(--accent); background: #fff8f7; }
.template-card strong { display: block; font-size: 13px; }
.template-card span { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.mini-paper { width: 34px; height: 44px; border: 1px solid #87919c; background: #fff; display: grid; gap: 2px; padding: 3px; }
.mini-paper.landscape { width: 42px; height: 30px; grid-template-columns: 1fr 1fr; }
.mini-paper i { background: #cfd5db; display: block; min-height: 3px; }
.mini-paper i:nth-child(odd) { background: #e99b97; }
.field-row { display: grid; grid-template-columns: 35px 1fr 46px; gap: 8px; align-items: center; color: #505a65; font-size: 12px; margin-top: 6px; }
.field-row input { width: 100%; accent-color: var(--accent); }
.field-row output { text-align: right; color: var(--ink); }
.editor-panel, .preview-panel { padding: 16px; display: flex; flex-direction: column; overflow: hidden; }
.panel-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; min-height: 48px; }
.panel-title-row .section-label { margin-bottom: 3px; }
.panel-title-row h2 { margin: 0; font-size: 17px; }
.mode-group { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; flex-shrink: 0; }
.mode-group button { height: 34px; border: 0; border-right: 1px solid var(--line); padding: 0 9px; background: #fff; font-size: 12px; color: #58636e; }
.mode-group button:last-child { border-right: 0; }
.mode-group button.active { background: var(--ink); color: #fff; }
.canvas-stage { flex: 1; min-height: 330px; background: #222831; border-radius: 6px; position: relative; overflow: auto; display: flex; align-items: center; justify-content: center; }
.canvas-stage.dragover { outline: 3px solid var(--accent); outline-offset: -3px; }
#editorCanvas { display: block; touch-action: none; flex: 0 0 auto; margin: auto; }
.editor-zoom { position: sticky; left: calc(100% - 64px); bottom: 10px; align-self: flex-end; z-index: 3; min-width: 50px; margin: 0 10px 10px -60px; padding: 5px 7px; border-radius: 4px; background: rgba(10, 15, 20, .78); color: #fff; text-align: center; font-size: 11px; pointer-events: none; }
.canvas-stage.empty .editor-zoom { display: none; }
.empty-state { display: none; position: absolute; color: #dce2e8; text-align: center; pointer-events: none; }
.empty-state strong, .empty-state span { display: block; }
.empty-state strong { font-size: 15px; margin-top: 12px; }
.empty-state span { color: #9aa5b0; margin-top: 6px; font-size: 12px; }
.canvas-stage.empty .empty-state { display: block; }
.upload-symbol { width: 54px; height: 54px; border: 1px dashed #87929e; border-radius: 50%; margin: auto; display: grid; place-items: center; font-size: 28px; }
.point-guide { min-height: 68px; display: flex; justify-content: center; flex-direction: column; align-items: center; }
.steps { display: flex; align-items: center; gap: 8px; color: #8a939d; font-size: 12px; }
.steps span { display: flex; align-items: center; gap: 4px; }
.steps i { width: 19px; height: 19px; border: 1px solid #aab2bb; border-radius: 50%; display: grid; place-items: center; font-style: normal; font-size: 10px; }
.steps span.active { color: var(--accent); font-weight: 700; }
.steps span.active i { color: white; background: var(--accent); border-color: var(--accent); }
.steps span.done { color: var(--green); }
.steps span.done i { color: white; background: var(--green); border-color: var(--green); }
.point-guide p { margin: 7px 0 0; color: var(--muted); font-size: 11px; }
.editor-actions { display: flex; gap: 8px; justify-content: flex-end; }
.paper-wrap { flex: 1; min-height: 0; margin-top: 8px; background: #d9dee3; padding: 20px; display: grid; place-items: center; overflow: hidden; border-radius: 6px; }
#paperCanvas { display: block; max-width: 84%; max-height: 84%; width: auto; height: auto; background: white; box-shadow: 0 5px 18px #18212b33; }
.zoom-label { font-size: 11px; color: var(--muted); background: #f1f3f5; padding: 5px 8px; border-radius: 4px; }
.legend { display: flex; justify-content: center; gap: 24px; height: 18px; align-items: end; color: #6c7680; font-size: 11px; }
.preview-panel .print-actions { flex-shrink: 0; border-top: 1px solid #e8ebee; margin-top: 6px; padding-top: 6px; }
.preview-panel .print-settings { flex-shrink: 0; border-top: 1px solid #e8ebee; margin-top: 6px; padding-top: 6px; }
.preview-panel .print-settings .field-row { grid-template-columns: 66px 1fr 56px; }
.print-settings input[type=range]:disabled { opacity: .35; cursor: not-allowed; }
.margin-note { margin: 0 0 4px; color: #a17a22; font-size: 11px; line-height: 1.6; }
.hidden { display: none !important; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 2px; display: block; }
.legend b { font-weight: 500; }
.front-dot { background: var(--accent); }
.back-dot { background: var(--blue); }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); background: #17212b; color: #fff; padding: 10px 16px; border-radius: 5px; opacity: 0; pointer-events: none; transition: .2s; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 235px 1fr; height: auto; }
  .preview-panel { grid-column: 2; min-height: 720px; }
  .editor-panel { min-height: 660px; }
  .setup-panel { grid-row: span 2; }
}
@media (max-width: 760px) {
  .topbar { height: auto; padding: 12px; align-items: flex-start; gap: 10px; }
  .toolbar-tip { display: none; }
  .workspace { display: block; padding: 8px; }
  .panel { margin-bottom: 8px; }
  .editor-panel { min-height: 640px; }
  .preview-panel { min-height: 620px; }
  .mode-group button { padding: 0 6px; }
  .editor-actions { flex-wrap: wrap; }
}
@media print {
  @page { margin: 0; }
  html, body { width: 100% !important; height: 100% !important; margin: 0 !important; overflow: hidden !important; background: #fff; }
  body > *:not(.workspace), .workspace > *:not(.preview-panel), .preview-panel > *:not(.paper-wrap) { display: none !important; }
  .workspace, .preview-panel, .paper-wrap { display: block !important; position: static !important; margin: 0 !important; padding: 0 !important; border: 0 !important; box-shadow: none !important; background: white !important; width: 100% !important; height: 100% !important; min-height: 0 !important; overflow: hidden !important; }
  #paperCanvas { display: block !important; width: 210mm !important; height: 297mm !important; max-width: none !important; max-height: none !important; margin: 0 !important; box-shadow: none !important; }
}

/* 顶栏中间快捷链接（后台「链接管理」维护）· 胶囊风格，图标 + 文字 */
.top-links { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; margin: 0 auto; padding: 0 14px; }
.top-links a { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 15px; border-radius: 999px; border: 1px solid #e3e8ee; background: #f7f9fb; color: #40505f; font-size: 13px; font-weight: 600; text-decoration: none; white-space: nowrap; box-shadow: 0 1px 2px rgba(24, 33, 43, .05); transition: border-color .18s ease, background .18s ease, color .18s ease, transform .18s ease, box-shadow .18s ease; }
.top-links a .lnk-ico { font-size: 15px; line-height: 1; }
.top-links a:hover { border-color: #b6d0f2; background: #ecf4ff; color: #1f6feb; transform: translateY(-1px); box-shadow: 0 4px 10px rgba(31, 111, 235, .16); }
.top-links a:active { transform: translateY(0); }
@media (max-width: 760px) {
  .top-links { order: 3; width: 100%; justify-content: flex-start; }
  .top-links a { height: 30px; padding: 0 11px; font-size: 12px; }
}

/* 用户区 */
.user-area { display: flex; align-items: center; gap: 8px; margin-left: 6px; padding-left: 12px; border-left: 1px solid var(--line); }
.user-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: #515c68; background: #f3f5f7; border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; }
.user-badge .role-tag { font-size: 10px; font-weight: 700; color: #fff; background: var(--blue); border-radius: 999px; padding: 1px 7px; }
.user-badge .role-tag.admin { background: var(--accent); }
.offline-hint { font-size: 11px; color: #a17a22; background: #fff6e0; border: 1px solid #ecd9a0; border-radius: 999px; padding: 5px 10px; font-weight: 600; }

/* 模态框 */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(18, 24, 31, .5); }
.modal-card { position: relative; width: 340px; max-width: calc(100vw - 32px); background: #fff; border-radius: 10px; box-shadow: 0 18px 50px rgba(10, 16, 24, .35); padding: 20px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-close { width: 30px; height: 30px; border: 0; background: #f1f3f5; border-radius: 6px; font-size: 18px; color: #5f6974; line-height: 1; }
.auth-tabs { margin-bottom: 14px; }
.auth-tabs button { height: 34px; }
#authForm input { width: 100%; height: 42px; border: 1px solid var(--line); border-radius: 6px; padding: 0 12px; margin-bottom: 10px; font-size: 14px; }
#authForm input:focus { outline: 2px solid #d9484133; border-color: var(--accent); }
#authForm .button.block { width: 100%; margin-top: 4px; }
.button.block { width: 100%; }
.auth-error { min-height: 16px; margin: 0 0 6px; color: var(--accent); font-size: 12px; }
.auth-note { margin: 14px 0 0; text-align: center; color: var(--muted); font-size: 11px; }
