/* ============================================================
   用印盖章系统 · 共享样式
   设计原则：少层级、清晰状态、移动端可用（企微内置浏览器）
   ============================================================ */
:root {
  --navy: #1f2d3d;
  --navy-600: #2c3e52;
  --ink: #1c2530;
  --muted: #6b7785;
  --line: #e3e7ec;
  --bg: #f4f6f8;
  --card: #ffffff;
  --brand: #b0211f;
  --brand-600: #8e1a18;
  --blue: #1a5fb4;
  --green: #1f7a4d;
  --amber: #a15c00;
  --red-soft: #fdecea;
  --blue-soft: #e8f0fb;
  --green-soft: #e7f4ec;
  --amber-soft: #fff4e0;
  --gray-soft: #eef1f4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Source Han Sans SC", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; color: var(--ink); }
p { margin: 0; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 22px;
  height: 60px;
  background: var(--navy);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.brand .seal-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 2px solid #f2b8b6;
  border-radius: 6px;
  color: #ffd9d7;
  font-size: 13px;
  font-weight: 700;
}
.brand small { font-weight: 400; opacity: 0.7; font-size: 12px; }
.brand-logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: block;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  flex: 0 0 auto;
}
.login-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  display: block;
  margin-bottom: 16px;
  box-shadow: 0 6px 18px rgba(242, 166, 0, 0.28);
}

.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav a {
  color: rgba(255, 255, 255, 0.78);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 14px;
}
.nav a:hover { background: rgba(255, 255, 255, 0.1); text-decoration: none; }
.nav a.active { background: rgba(255, 255, 255, 0.16); color: #fff; }

.userbar {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  min-width: 0;
}
.userbar .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.userbar .avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
}

/* ---------- 布局 ---------- */
.page { max-width: 1280px; margin: 0 auto; padding: 24px 22px 64px; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 22px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 18px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.card-head h2 { font-size: 16px; }
.card-head .sub { color: var(--muted); font-size: 12px; margin-left: 2px; }
.card-head .spacer { margin-left: auto; }
.card-body { padding: 20px; }
.card-body.tight { padding: 14px 16px; }
.section-title {
  display: flex; align-items: center; gap: 10px;
  font-size: 15px; font-weight: 600; margin-bottom: 12px;
}
.step-no {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--navy); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, "Courier New", monospace; }
.hidden { display: none !important; }

/* ---------- 表单 ---------- */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #cfd6de;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(26, 95, 180, 0.12);
}
textarea { min-height: 76px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 120px; gap: 12px; }

/* 印章选择 */
.seal-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.seal-option {
  border: 1px solid #d8dee6;
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.seal-option:hover { border-color: #9db3cf; }
.seal-option.selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(26, 95, 180, 0.12);
  background: #f7faff;
}
.seal-option .no { font-size: 12px; color: var(--muted); }
.seal-option .nm { font-weight: 600; }
.seal-option .type { font-size: 12px; color: var(--muted); }
.seal-option.disabled { opacity: 0.5; cursor: not-allowed; }

/* 上传区 */
.dropzone {
  border: 2px dashed #c3ccd7;
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  background: #fbfcfd;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--blue); background: var(--blue-soft); }
.dropzone .big { font-size: 28px; line-height: 1; margin-bottom: 8px; color: var(--blue); }
.dropzone strong { display: block; margin-bottom: 4px; }
.dropzone .muted { font-size: 12px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid #cfd6de;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn:hover { background: #f5f7f9; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: #154c92; }
.btn-danger { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-danger:hover { background: var(--brand-600); }
.btn-dark { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-dark:hover { background: var(--navy-600); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--gray-soft); }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 7px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- 状态徽章 ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.pending_approval { background: var(--amber-soft); color: var(--amber); }
.badge.pending_stamp { background: var(--blue-soft); color: var(--blue); }
.badge.stamping { background: var(--blue-soft); color: var(--blue); }
.badge.stamped { background: var(--green-soft); color: var(--green); }
.badge.delivered { background: var(--gray-soft); color: #59636e; }
.badge.rejected { background: var(--red-soft); color: var(--brand); }
.badge.canceled { background: var(--gray-soft); color: #59636e; }
.badge.expired { background: var(--gray-soft); color: #59636e; }

/* ---------- 任务列表 ---------- */
.task-list { display: flex; flex-direction: column; gap: 10px; }
.task-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px 14px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.task-item:hover { border-color: #b9c6d6; box-shadow: 0 2px 8px rgba(16, 24, 40, 0.06); }
.task-item .row1 { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.task-item .apply-no { font-weight: 600; font-size: 13px; }
.task-item .seal { font-size: 13px; color: var(--navy); }
.task-item .row2 { display: flex; gap: 8px; color: var(--muted); font-size: 12px; }
.task-item .reason { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 36px 12px;
  font-size: 13px;
}
.empty .big { font-size: 30px; margin-bottom: 8px; opacity: 0.4; }

/* ---------- PDF 预览 ---------- */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 12px;
}
.toolbar .spacer { margin-left: auto; }
.pdf-scroll {
  max-height: 70vh;
  overflow: auto;
  background: #eceff3;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}
.pdf-pages { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.pdf-page {
  position: relative;
  background: #fff;
  box-shadow: 0 2px 10px rgba(16, 24, 40, 0.15);
  line-height: 0;
  user-select: none;
  width: 100%;
  max-width: 820px;
}
.pdf-page canvas { display: block; width: 100%; height: 100%; }
.pdf-page .overlay { position: absolute; inset: 0; z-index: 2; }
.pdf-page .page-no {
  position: absolute; left: 8px; top: 8px; z-index: 3;
  background: rgba(31, 45, 61, 0.72); color: #fff;
  font-size: 11px; padding: 2px 7px; border-radius: 4px;
  line-height: 1.5;
}
.pdf-page .page-loading {
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px;
}
.pdf-page .add-here {
  position: absolute; right: 8px; top: 8px; z-index: 3;
  width: 28px; height: 28px; border-radius: 6px;
  border: 1px solid rgba(31, 45, 61, 0.25);
  background: rgba(255, 255, 255, 0.9);
  color: var(--navy); font-size: 18px; line-height: 1;
  cursor: pointer; display: none;
}
.pdf-page:hover .add-here { display: block; }

/* 只读位置标记（保管人复核） */
.marker {
  position: absolute;
  border: 2px dashed var(--brand);
  background: rgba(176, 33, 31, 0.08);
  pointer-events: none;
}
.marker::after {
  content: attr(data-label);
  position: absolute; left: -2px; top: -22px;
  background: var(--brand); color: #fff;
  font-size: 11px; padding: 1px 7px; border-radius: 4px 4px 0 0;
  line-height: 18px; white-space: nowrap;
}
.marker .marker-seal {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: fill;
  opacity: 0.55;
}

.field-box {
  position: absolute;
  border: 2px solid var(--brand);
  background: rgba(176, 33, 31, 0.08);
  cursor: move;
  box-sizing: border-box;
  touch-action: none;
}
.field-box.selected { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(176, 33, 31, 0.2); }
.field-box::after {
  content: attr(data-label);
  position: absolute; left: -2px; top: -22px;
  background: var(--brand); color: #fff;
  font-size: 11px; padding: 1px 7px; border-radius: 4px 4px 0 0;
  white-space: nowrap; line-height: 18px;
}
.field-box .handle {
  position: absolute; right: -7px; bottom: -7px;
  width: 14px; height: 14px; border-radius: 3px;
  background: var(--brand); border: 2px solid #fff;
  cursor: nwse-resize;
}
.field-box .remove {
  position: absolute; right: -10px; top: -10px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; border: 1px solid var(--brand); color: var(--brand);
  font-size: 13px; line-height: 1; cursor: pointer;
  display: none; align-items: center; justify-content: center;
}
.field-box.selected .remove { display: flex; }

.preview-hint {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted);
  padding: 8px 2px 0;
}

/* ---------- 表格 ---------- */
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data th { color: var(--muted); font-weight: 600; font-size: 12px; background: #fafbfc; }
table.data tr:last-child td { border-bottom: none; }
table.data td.actions { text-align: right; white-space: nowrap; }
.thumb {
  width: 44px; height: 44px; object-fit: contain;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.thumb.empty-thumb { display: inline-flex; align-items: center; justify-content: center; color: var(--muted); font-size: 11px; }

/* ---------- 弹窗 ---------- */
dialog.modal {
  border: none;
  border-radius: 12px;
  padding: 0;
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  box-shadow: 0 24px 64px rgba(16, 24, 40, 0.28);
}
dialog.modal::backdrop { background: rgba(16, 24, 40, 0.45); }
dialog.modal .modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
dialog.modal .modal-head h3 { font-size: 16px; }
dialog.modal .modal-head .close {
  margin-left: auto; border: none; background: transparent;
  font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer;
}
dialog.modal .modal-body { padding: 20px; overflow: auto; max-height: calc(100vh - 180px); }
dialog.modal .modal-foot {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 14px 20px; border-top: 1px solid var(--line); background: #fafbfc;
}

/* 详情信息 */
.detail-grid { display: grid; grid-template-columns: 110px 1fr; gap: 8px 14px; font-size: 13px; }
.detail-grid dt { color: var(--muted); }
.detail-grid dd { margin: 0; word-break: break-all; }
.kv { display: grid; grid-template-columns: 96px 1fr; gap: 6px 12px; font-size: 13px; }
.kv .k { color: var(--muted); }

.notice {
  border: 1px solid #f0d9a8;
  background: #fffaf0;
  color: #7a4b00;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
}
.notice.blue { border-color: #cfe0f5; background: #f5f9ff; color: #1c4b85; }
.notice.red { border-color: #f2c9c7; background: #fdf5f5; color: #8e1a18; }

/* 印章预览框 */
.seal-preview {
  display: flex; align-items: center; justify-content: center;
  width: 120px; height: 120px;
  border: 1px dashed #cfd6de; border-radius: 10px; background: #fff;
}
.seal-preview img { max-width: 104px; max-height: 104px; }

/* 统计块 */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat {
  border: 1px solid var(--line); border-radius: 10px; padding: 14px;
  background: #fff;
}
.stat .n { font-size: 24px; font-weight: 700; line-height: 1.2; }
.stat .l { font-size: 12px; color: var(--muted); }

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: calc(100vh - 60px);
  display: flex; align-items: center; justify-content: center;
  padding: 40px 20px;
}
.login-card { width: min(420px, 100%); }
.login-card .card-body { padding: 28px; }
.login-card h1 { font-size: 20px; margin-bottom: 6px; }
.login-card .lead { color: var(--muted); font-size: 13px; margin-bottom: 22px; }

/* ---------- Toast ---------- */
#toast-root {
  position: fixed; right: 20px; bottom: 20px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  pointer-events: none;
}
.toast {
  background: var(--navy); color: #fff;
  padding: 10px 16px; border-radius: 8px;
  font-size: 13px; box-shadow: 0 8px 24px rgba(16, 24, 40, 0.2);
  animation: toast-in 0.18s ease-out;
  max-width: 360px;
}
.toast.error { background: var(--brand); }
.toast.success { background: var(--green); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- 响应式 ---------- */
@media (max-width: 980px) {
  .split { grid-template-columns: 1fr; }
  .nav { display: none; }
  .page { padding: 16px 14px 48px; }
  .topbar { padding: 0 14px; }
  .pdf-scroll { max-height: 60vh; }
}
@media (max-width: 560px) {
  .form-row { grid-template-columns: 1fr; }
  .card-body { padding: 14px; }
  .userbar .name { max-width: 90px; }
}
