:root {
  --bg: #f5f6f7;
  --card: #ffffff;
  --line: #e4e7ea;
  --line-strong: #d3d7dc;
  --text: #1f2328;
  --muted: #6b7280;
  --red: #c8102e;
  --red-dark: #a60d26;
  --red-soft: #fdf2f3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: 14px;
}

/* 顶部导航 */
.site-header {
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--red);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.site-nav a {
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
}

.site-nav a:hover {
  background: #f2f3f5;
  color: var(--text);
}

.site-nav a.active {
  color: var(--red);
  background: var(--red-soft);
  font-weight: 600;
}

/* 页面骨架 */
.page-main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px;
}

.page-head {
  margin: 4px 0 16px;
}

.page-head h1 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 600;
}

.page-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.site-footer {
  border-top: 1px solid var(--line);
  margin-top: 28px;
  padding: 14px 20px;
  text-align: center;
  color: #9aa1a9;
  font-size: 12px;
}

.site-footer a {
  color: #9aa1a9;
}

.site-footer a:hover {
  color: var(--red);
}

/* 卡片与表单 */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-pad {
  padding: 18px;
}

.panel-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-title .hint {
  font-weight: 400;
  color: var(--muted);
  font-size: 12px;
}

.field {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.field > label {
  width: 86px;
  flex: 0 0 86px;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.field .control {
  flex: 1;
  min-width: 0;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 14px;
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 7px 10px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(200, 16, 46, 0.08);
}

input[type="color"] {
  width: 42px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
}

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

/* 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  border-radius: 7px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:hover {
  border-color: #b9bec5;
  background: #fafafa;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--red-dark);
  border-color: var(--red-dark);
}

.btn.active {
  background: var(--red-soft);
  border-color: var(--red);
  color: var(--red);
}

.btn.small {
  padding: 4px 10px;
  font-size: 12px;
}

.btn.block {
  width: 100%;
}

.btn.link {
  border: none;
  background: none;
  color: var(--muted);
  padding: 4px 6px;
}

.btn.link:hover {
  color: var(--red);
  background: none;
}

.btn.danger {
  color: var(--red);
  border-color: #efc2c9;
}

.btn.danger:hover {
  background: var(--red-soft);
}

/* 上传区域 */
.dropzone {
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  padding: 44px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--red);
  background: #fffafb;
}

.dropzone .dz-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  margin: 0 auto 12px;
  background: var(--red-soft);
  color: var(--red);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
}

.dropzone .dz-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.dropzone .dz-sub {
  color: var(--muted);
  font-size: 12.5px;
}

.feature-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 14px;
}

.feature {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.feature h3 {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 600;
}

.feature p {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}

/* 工具栏 */
.workspace {
  display: none;
}

.workspace.show {
  display: block;
}

.toolbar {
  position: sticky;
  top: 58px;
  z-index: 40;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.toolbar .spacer {
  flex: 1;
}

.seal-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 10px;
  border-right: 1px solid var(--line);
}

.front-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.front-account {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.seal-preview-btn {
  display: flex;
  align-items: center;
  padding: 0;
  border: 0;
  background: none;
  cursor: zoom-in;
  border-radius: 7px;
}

.seal-preview-btn:hover .seal-thumb,
.seal-preview-btn:focus-visible .seal-thumb {
  border-color: var(--red);
  box-shadow: 0 0 0 2px var(--red-soft);
}

.seal-thumb {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  object-fit: contain;
}

.seal-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

body.modal-open {
  overflow: hidden;
}

.seal-modal.hidden {
  display: none;
}

.seal-modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(24, 20, 22, 0.42);
}

.seal-modal-card {
  position: relative;
  width: min(420px, 100%);
  max-height: 90vh;
  overflow: auto;
  padding: 18px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(30, 20, 24, 0.24);
}

.seal-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.seal-modal-head h3 {
  margin: 0;
  font-size: 16px;
}

.seal-modal-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfbfa;
}

.seal-modal-stage img {
  width: min(260px, 70vw);
  height: min(260px, 70vw);
  object-fit: contain;
}

.seal-modal-meta {
  display: grid;
  gap: 7px;
  margin-top: 12px;
  font-size: 12.5px;
}

.sp-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--line);
}

.sp-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.sp-row span {
  color: var(--muted);
  flex: none;
}

.sp-row strong {
  font-weight: 500;
  text-align: right;
  word-break: break-all;
}

@media (max-height: 680px) {
  .seal-modal {
    padding: 10px;
  }

  .seal-modal-card {
    padding: 12px;
  }

  .seal-modal-head {
    margin-bottom: 8px;
  }

  .seal-modal-stage {
    padding: 8px;
  }

  .seal-modal-stage img {
    width: min(110px, 45vw);
    height: min(110px, 45vw);
  }

  .seal-modal-meta {
    grid-template-columns: 1fr 1fr;
    gap: 6px 14px;
  }

  .sp-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
    padding-bottom: 0;
    border-bottom: 0;
  }

  .sp-row span {
    font-size: 10px;
  }

  .sp-row strong {
    text-align: left;
    font-size: 11px;
    line-height: 1.35;
  }

  .seal-modal-card .image-hint {
    display: none;
  }
}

.seal-picker select {
  width: auto;
  min-width: 120px;
  max-width: 190px;
  padding: 5px 8px;
  font-size: 12.5px;
}

.file-meta {
  color: var(--muted);
  font-size: 12px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fmt-select {
  width: auto;
  padding: 6px 8px;
  font-size: 12.5px;
  border-radius: 8px;
  cursor: pointer;
}

/* 选中公章后的操作条：固定在视口底部，滚动时始终可操作 */
.seal-toolbar {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  background: #fff;
  border: 1px solid #f0c9cf;
  border-radius: 10px;
  padding: 8px 14px;
  box-shadow: 0 8px 28px rgba(15, 23, 42, 0.16);
  font-size: 12.5px;
  max-width: calc(100vw - 24px);
}

.seal-toolbar .st-title {
  color: var(--red);
  font-weight: 600;
}

.seal-toolbar .st-size {
  color: var(--muted);
}

/* 页面预览 */
.pages-wrap {
  background: #e9ebee;
  border-radius: var(--radius);
  padding: 22px 16px 28px;
  overflow-x: auto;
}

.pages-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  min-width: min-content;
}

.doc-page {
  position: relative;
  background: #fff;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.12);
  border-radius: 2px;
  flex: none;
  transform-origin: top left;
  overflow: hidden;
}

.page-scaler {
  position: relative;
  flex: none;
}

.page-signature-toggle {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 35;
  padding: 5px 9px;
  border: 1px solid #d8dce2;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.94);
  color: #4b5563;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.12);
}

.page-signature-toggle:hover,
.page-signature-toggle.active {
  border-color: var(--red);
  color: var(--red);
}

.doc-page.pdf-page canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 2px;
}

.doc-page.image-page {
  line-height: 0;
}

.doc-page.image-page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.doc-page.word-page {
  width: 794px;
  height: 1122px;
  padding: 56px 60px;
}

.doc-page.word-page .doc-body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "SimSun", "宋体", serif;
  font-size: 12pt;
  line-height: 1.75;
  color: #111;
}

.doc-body p {
  margin: 0 0 0.65em;
  text-align: justify;
}

.doc-body h1,
.doc-body h2,
.doc-body h3 {
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  line-height: 1.4;
  margin: 0.6em 0 0.4em;
}

.doc-body h1 {
  font-size: 18pt;
  text-align: center;
}

.doc-body h2 {
  font-size: 15pt;
}

.doc-body h3 {
  font-size: 13pt;
}

.doc-body img {
  max-width: 100%;
  height: auto;
}

.doc-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 0.8em;
  font-size: 10.5pt;
}

.doc-body td,
.doc-body th {
  border: 1px solid #999;
  padding: 4px 6px;
}

.doc-body ul,
.doc-body ol {
  margin: 0 0 0.7em;
  padding-left: 1.6em;
}

.pages-wrap.selecting .doc-page {
  cursor: crosshair;
}

.pages-wrap.selecting .doc-page:hover {
  outline: 2px solid rgba(200, 16, 46, 0.45);
  outline-offset: -2px;
}

/* 公章浮层 */
.seal-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.seal-holder {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: auto;
  cursor: move;
  z-index: 20;
  user-select: none;
}

.seal-holder img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
  opacity: 0.97;
}

/* 骑缝章：段裁切容器，贴页面右边缘，仅垂直居中 */
.seal-holder.rider-seal {
  transform: translateY(-50%);
  left: auto !important;
  right: 0;
}

.rider-clip {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.rider-clip img {
  transform-origin: top left;
}

.seal-holder::after {
  content: "";
  position: absolute;
  inset: -4px;
  border: 1px dashed transparent;
  border-radius: 4px;
  transition: border-color 0.12s ease;
}

.seal-holder.selected::after {
  border-color: var(--red);
}

.pages-wrap.exporting .seal-holder::after {
  display: none !important;
}

/* 空状态与加载 */
.loading-mask {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.72);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.loading-mask.show {
  display: flex;
}

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid #ebedef;
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* 轻提示 */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(12px);
  background: #1f2328;
  color: #fff;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 300;
  max-width: 86vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  background: var(--red);
}

/* 后台 */
.admin-grid {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
  align-items: start;
}

.seal-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.seal-list-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  background: #fff;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.seal-list-item:hover {
  border-color: #b9bec5;
}

.seal-list-item.active {
  border-color: var(--red);
  background: var(--red-soft);
}

.seal-list-item .name {
  font-size: 13.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.seal-list-item .meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 0 6px;
  border-radius: 4px;
  font-size: 11px;
  line-height: 18px;
  background: var(--red);
  color: #fff;
  font-weight: 500;
}

.editor-grid {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 18px;
}

.preview-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfbfc;
  padding: 16px;
  text-align: center;
  position: sticky;
  top: 78px;
}

.preview-box canvas {
  width: 240px;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
}

.preview-box .pv-caption {
  font-size: 12px;
  color: var(--muted);
  margin-top: 10px;
}

.form-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.image-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

.auth-card {
  max-width: 400px;
  margin: 40px auto;
}

.auth-card .brand {
  justify-content: center;
  margin-bottom: 6px;
  font-size: 18px;
}

.auth-card .sub {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 20px;
}

.auth-card .field > label {
  width: 76px;
  flex: 0 0 76px;
}

.section-gap {
  margin-top: 16px;
}

details.advanced {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 12px;
}

details.advanced summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12.5px;
  user-select: none;
}

details.advanced summary:hover {
  color: var(--red);
}

details.advanced .inner {
  margin-top: 12px;
}

.notice {
  padding: 10px 12px;
  border-radius: 8px;
  background: #f8f9fa;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
  margin-bottom: 14px;
}

.notice.red {
  background: var(--red-soft);
  border-color: #f2cfd4;
  color: #8f1a2c;
}

.footer-note {
  margin-top: 6px;
  font-size: 11.5px;
  color: #b0b6bd;
}

.log-list {
  max-height: 260px;
  overflow: auto;
  font-size: 12px;
  color: var(--muted);
}

.log-item {
  display: flex;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px dashed var(--line);
  line-height: 1.5;
}

.log-item:last-child {
  border-bottom: none;
}

.log-time {
  flex: none;
  color: #9aa1a9;
  font-variant-numeric: tabular-nums;
}

.log-text {
  word-break: break-all;
}

.user-chip {
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f8f9fa;
  color: var(--muted);
  font-size: 12px;
}

.user-chip b {
  color: var(--ink);
  font-weight: 600;
}

.user-list {
  margin-bottom: 12px;
  font-size: 12.5px;
}

.user-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--line);
}

.user-item:last-child {
  border-bottom: none;
}

.user-meta {
  min-width: 0;
  color: var(--muted);
  line-height: 1.5;
  word-break: break-all;
}

.user-meta strong {
  color: var(--ink);
  font-weight: 600;
}

.user-actions {
  display: flex;
  gap: 6px;
  flex: none;
}

.role-tag {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--red-soft);
  color: var(--red);
}

.role-tag.operator {
  background: #f1f3f5;
  color: var(--muted);
}

body.operator-mode .admin-only {
  display: none !important;
}

.form-error {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--red-soft);
  border: 1px solid #f2cfd4;
  color: #8f1a2c;
  font-size: 12.5px;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 980px) {
  .admin-grid,
  .editor-grid {
    grid-template-columns: 1fr;
  }

  .preview-box {
    position: static;
    order: -1;
  }

  .preview-box canvas {
    width: 180px;
  }

  .feature-row {
    grid-template-columns: 1fr;
  }

  .toolbar {
    top: 58px;
  }
}

@media (max-width: 640px) {
  .header-inner {
    padding: 0 14px;
  }

  .page-main {
    padding: 14px;
  }

  .field {
    align-items: flex-start;
  }

  .field > label {
    width: 70px;
    flex-basis: 70px;
    padding-top: 7px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .seal-picker {
    border-right: none;
    padding-right: 0;
  }

  .pages-wrap {
    padding: 16px 8px 22px;
  }
}
