:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --line: #e4e7ec;
  --text: #1f2328;
  --muted: #6b7280;
  --brand: #12897c;
  --brand-dark: #0e6f65;
  --brand-soft: #e6f4f2;
  --accent: #a9784f;
  --danger: #c8462f;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- 顶部 ---------- */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), #1fa89a);
  color: #fff; font-weight: 700; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
}
.topbar h1 { font-size: 16px; margin: 0; font-weight: 600; letter-spacing: .3px; }
.topbar .sub { color: var(--muted); font-size: 12px; margin-left: 2px; }
.topbar .spacer { flex: 1; }

/* ---------- 布局 ---------- */
.wrap { max-width: 1280px; margin: 0 auto; padding: 22px 24px 60px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
}
.card h2 { font-size: 15px; margin: 0 0 14px; font-weight: 600; }
.row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.ok { color: var(--brand-dark); }

.live-indicator { display: flex; align-items: center; gap: 6px; color: var(--muted); margin-right: 6px; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: #38a169; animation: pulse 2s infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

.flash-new { animation: flashRow 1.4s ease-in-out 3; }
@keyframes flashRow {
  0%, 100% { background: transparent; }
  50% { background: #e8f5e9; }
}

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
  white-space: nowrap;
}
.btn:hover { border-color: #cdd2da; background: #fafbfc; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.danger { color: var(--danger); border-color: #f0d4ce; }
.btn.danger:hover { background: #fdf3f1; }
.btn.sm { padding: 5px 11px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- 上传 ---------- */
.drop {
  border: 2px dashed #cdd3dc;
  border-radius: var(--radius);
  background: #fbfcfd;
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all .18s;
}
.drop:hover, .drop.over { border-color: var(--brand); background: var(--brand-soft); }
.drop .big { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.drop .ico { font-size: 30px; line-height: 1; margin-bottom: 10px; display: block; }

/* ---------- 表格 ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
tbody tr:hover { background: #fafbfc; }
td .name { font-weight: 500; }
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 12px; background: #f0f2f5; color: var(--muted);
}
.badge.ok { background: var(--brand-soft); color: var(--brand-dark); }
.badge.wait { background: #fdf4e7; color: var(--accent); }

/* ---------- 编辑器 ---------- */
.editor { display: grid; grid-template-columns: 1fr 300px; gap: 18px; align-items: start; }
@media (max-width: 1000px) { .editor { grid-template-columns: 1fr; } }

.pdf-stage {
  background: #e9ebef;
  border-radius: var(--radius);
  padding: 18px;
  display: flex; flex-direction: column; align-items: center;
  overflow: auto;
}
.page-wrap { position: relative; margin-bottom: 16px; box-shadow: 0 3px 14px rgba(0,0,0,.15); background: #fff; }
.page-wrap canvas { display: block; }
.field-layer { position: absolute; inset: 0; }
.field-box {
  position: absolute;
  border: 2px dashed var(--brand);
  background: rgba(18, 137, 124, .08);
  border-radius: 4px;
  cursor: move;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--brand-dark); font-weight: 600;
  user-select: none;
  overflow: hidden;
  text-align: center;
  padding: 4px;
}
.field-box.sel { border-style: solid; background: rgba(18, 137, 124, .18); box-shadow: 0 0 0 3px rgba(18,137,124,.15); }
.field-box .del {
  position: absolute; top: -9px; right: -9px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--danger); color: #fff; font-size: 13px; line-height: 18px;
  text-align: center; cursor: pointer; display: none;
  font-family: Arial, sans-serif;
}
.field-box:hover .del, .field-box.sel .del { display: block; }
.field-box .handle {
  position: absolute; right: -5px; bottom: -5px;
  width: 12px; height: 12px; background: var(--brand);
  border: 2px solid #fff; border-radius: 3px; cursor: se-resize; display: none;
}
.field-box.sel .handle { display: block; }

/* ---------- 侧栏 ---------- */
.side { position: sticky; top: 74px; }
.side label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px; }
.input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
}
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(18,137,124,.1); }
.field-item {
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
  margin-bottom: 8px; cursor: pointer; background: #fff;
}
.field-item.sel { border-color: var(--brand); background: var(--brand-soft); }
.field-item .t { font-weight: 500; font-size: 13px; display: flex; justify-content: space-between; gap: 8px; }
.field-item .m { font-size: 12px; color: var(--muted); }
.hint {
  background: #fbf8f4; border: 1px solid #f0e4d6; color: #7a5a3a;
  border-radius: 8px; padding: 10px 12px; font-size: 12.5px; line-height: 1.7;
}

/* ---------- 链接 ---------- */
.link-box {
  display: flex; gap: 8px; align-items: center;
  background: var(--brand-soft); border: 1px dashed var(--brand);
  border-radius: 8px; padding: 11px 13px; margin-top: 12px;
}
.link-box input {
  flex: 1; border: none; background: transparent; font-size: 13px;
  font-family: Consolas, Menlo, monospace; color: var(--brand-dark); outline: none; min-width: 0;
}

/* ---------- 签署页 ---------- */
.sign-head {
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 12px 20px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 40;
}
.sign-head .doc-title { font-weight: 600; font-size: 15px; }
.sign-body { max-width: 900px; margin: 0 auto; padding: 20px 16px 130px; }
.sign-page { position: relative; margin-bottom: 16px; box-shadow: 0 2px 12px rgba(0,0,0,.13); background: #fff; }
.sign-page canvas, .sign-page img { display: block; width: 100%; height: auto; }
.slot {
  position: absolute;
  border: 2px dashed var(--brand);
  background: rgba(18,137,124,.07);
  border-radius: 5px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--brand-dark); font-weight: 600; font-size: 13px;
  transition: all .15s;
  overflow: hidden;
}
.slot:hover { background: rgba(18,137,124,.15); border-style: solid; }
.slot.done { border-style: solid; background: #fff; }
.slot img { max-width: 100%; max-height: 100%; object-fit: contain; }
.slot .ph { text-align: center; padding: 4px; line-height: 1.3; }
.slot .ph small { display: block; font-weight: 400; font-size: 11px; opacity: .75; }

.sign-bar {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 12px 20px; display: flex; gap: 12px; align-items: center;
  justify-content: center; flex-wrap: wrap; z-index: 60;
  box-shadow: 0 -2px 12px rgba(16,24,40,.06);
}
.sign-bar .prog { font-size: 13px; color: var(--muted); }

/* ---------- 弹窗 ---------- */
.mask {
  position: fixed; inset: 0; background: rgba(15,20,28,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 16px;
}
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 620px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25); overflow: hidden;
}
.modal .mh { padding: 15px 20px; border-bottom: 1px solid var(--line); font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.modal .mb { padding: 18px 20px; }
.modal .mf { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; background: #fafbfc; }
.pad-wrap {
  border: 2px dashed #cdd3dc; border-radius: 10px; background: #fff;
  position: relative; touch-action: none;
}
.pad-wrap canvas { display: block; width: 100%; height: 220px; border-radius: 8px; touch-action: none; user-select: none; -webkit-user-select: none; cursor: crosshair; }
.pad-tip { position: absolute; left: 0; right: 0; bottom: 10px; text-align: center; color: #c3c9d2; font-size: 13px; pointer-events: none; }

/* ---------- 完成页 ---------- */
.done { max-width: 520px; margin: 60px auto; text-align: center; }
.done .tick {
  width: 62px; height: 62px; border-radius: 50%; margin: 0 auto 18px;
  background: var(--brand-soft); color: var(--brand);
  font-size: 32px; line-height: 62px;
}

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 90px;
  background: #1f2328; color: #fff; padding: 10px 20px; border-radius: 8px;
  font-size: 14px; z-index: 300; opacity: 0; pointer-events: none; transition: opacity .25s;
}
.toast.show { opacity: 1; }
