/* 钉钉 H5 微应用 - 共享样式（移动优先） */

:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --border: #e3e6ea;
  --text: #1a1d21;
  --muted: #6b7280;
  --primary: #1a7ef4;
  --primary-dark: #1466c8;
  --danger: #d93025;
  --ok: #16a34a;
  --warn-bg: #fff7e6;
  --warn-border: #ffd591;
  --warn-text: #8a5a00;
  --radius: 10px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { padding-bottom: calc(72px + var(--safe-b)); }

/* 隐藏但保留给读屏 */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---- 顶栏 ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 600; flex: 1; }
.topbar .sub { font-size: 12px; color: var(--muted); font-weight: 400; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--bg); object-fit: cover; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: var(--muted);
}

/* ---- 容器 ---- */
.wrap { padding: 12px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card-title { font-size: 14px; font-weight: 600; margin: 0 0 10px; }

/* 多行输入（指派签署人名单） */
.field {
  width: 100%; font: inherit; color: var(--text);
  padding: 10px; margin-top: 8px;
  border: 1px solid var(--border); border-radius: 8px;
  background: #fff; resize: vertical; min-height: 88px;
}
.field:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

/* ---- 警告条 ---- */
.notice {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}
.notice.ok { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }

/* ---- 按钮：触控目标 >= 44px ---- */
.btn {
  appearance: none; border: 1px solid var(--border);
  background: var(--card); color: var(--text);
  min-height: 44px; padding: 0 16px;
  border-radius: 8px; font-size: 15px; font-family: inherit;
  cursor: pointer; display: inline-flex; align-items: center;
  justify-content: center; gap: 6px;
}
.btn:active { background: #f0f0f0; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #f3c0bc; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* 底部固定操作条 */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; gap: 10px;
  padding: 10px 12px calc(10px + var(--safe-b));
  background: var(--card);
  border-top: 1px solid var(--border);
}

/* ---- 列表 ---- */
.list { list-style: none; margin: 0; padding: 0; }
.list-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-main { display: flex; align-items: flex-start; gap: 10px; }
.list-name {
  flex: 1; min-width: 0; font-size: 15px; font-weight: 500;
  word-break: break-all;
}
.list-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.list-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.badge {
  display: inline-block; font-size: 11px; padding: 1px 6px;
  border-radius: 4px; background: #eef4ff; color: var(--primary-dark);
  margin-left: 6px; vertical-align: middle;
}
.badge.ok { background: #f0fdf4; color: #166534; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; font-size: 14px; }
.empty-icon { font-size: 34px; display: block; margin-bottom: 8px; }

/* ---- 签名库 ---- */
.sig-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
}
.sig-item {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px;
  text-align: center; position: relative; background: #fff;
}
.sig-item img { max-width: 100%; height: 48px; object-fit: contain; display: block; margin: 0 auto; }
.sig-item .del {
  position: absolute; top: 2px; right: 2px;
  width: 28px; height: 28px; line-height: 1;
  border: none; background: transparent; color: var(--muted);
  font-size: 18px; cursor: pointer;
}

/* ---- 签署页 ---- */
/* 禁用双击缩放与手势缩放，否则会干扰手写 */
.pad-canvas, .page-canvas {
  touch-action: none; display: block; margin: 0 auto;
  max-width: 100%; background: #fff;
}
.pad-wrap { position: relative; width: 100%; }
.pad-stack { position: relative; width: 100%; aspect-ratio: 1 / 1; }
.pad-stack canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  border-radius: 8px;
}
.pad-grid { z-index: 1; }
.pad-ink { z-index: 2; }
.pad-hint {
  position: absolute; inset: 0; z-index: 3;
  display: flex; align-items: center; justify-content: center;
  color: #b9bec6; font-size: 14px; pointer-events: none;
}
.pad-hint.hidden { display: none; }

.page-stage {
  position: relative; overflow: auto; -webkit-overflow-scrolling: touch;
  background: #4a4f57; padding: 10px; border-radius: 8px;
}
.placed-sig {
  position: absolute; z-index: 5;
  border: 1px dashed var(--primary);
  background: rgba(255, 255, 255, .25);
  border-radius: 2px;
}

.pager { display: flex; align-items: center; gap: 10px; justify-content: center; margin-top: 10px; }
.pager .page-no { font-size: 14px; min-width: 74px; text-align: center; }

.chars { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.char-item {
  position: relative; width: 44px; height: 44px;
  border: 1px solid var(--border); border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  background: #fff;
}
.char-item img { max-width: 40px; max-height: 40px; }
.char-item.active { border-color: var(--primary); }
.char-item .del {
  position: absolute; top: -6px; right: -6px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--danger); color: #fff; border: none;
  font-size: 13px; line-height: 1; cursor: pointer;
}

.settings { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; font-size: 13px; }
.settings label { display: inline-flex; align-items: center; gap: 5px; }
.settings select, .settings input[type=color] {
  font: inherit; padding: 4px; border: 1px solid var(--border);
  border-radius: 6px; background: #fff; min-height: 32px;
}

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 100; max-width: 84vw;
  background: rgba(26, 29, 33, .93); color: #fff;
  padding: 10px 16px; border-radius: 8px; font-size: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
}
.toast-err { background: rgba(217, 48, 37, .95); }
.toast-ok { background: rgba(22, 163, 74, .95); }

/* ---- 弹层 ---- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, .5);
  display: flex; align-items: flex-end;
}
.modal[hidden] { display: none; }
.modal-panel {
  background: var(--card); width: 100%;
  border-radius: 14px 14px 0 0;
  padding: 16px 14px calc(16px + var(--safe-b));
  max-height: 82vh; overflow: auto;
}
.modal-title { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
.modal-actions { display: flex; gap: 10px; margin-top: 14px; }
.modal-actions .btn { flex: 1; }

/* 横屏提示 */
.rotate-tip {
  position: fixed; inset: 0; z-index: 60; background: var(--card);
  display: none; align-items: center; justify-content: center;
  flex-direction: column; gap: 12px; text-align: center; padding: 24px;
}
@media (orientation: landscape) and (max-height: 460px) {
  .rotate-tip { display: flex; }
}

@media (min-width: 640px) {
  .wrap { max-width: 720px; margin: 0 auto; }
  .topbar { max-width: 720px; margin: 0 auto; width: 100%; }
}
/* 当前登录人:头部姓名与角色徽章。放在 avatar 旁,一眼可验「这个窗口现在是谁」
   (?as= 身份切换的兜底可读性 —— 标签与头像字母可能都看不清全名) */
.user-name { font-size: 14px; font-weight: 600; flex: none; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar { align-items: center; }
.badge { font-size: 11px; }

/* 签名库按归属人分段的小节标题 */
.lib-user { grid-column: 1 / -1; color: var(--muted); font-size: 12px; margin-top: 4px; }
