/* ============ 鼎信商务内部合同系统 - 视觉设计 ============ */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --navy: #0f172a;
  --text: #1e293b;
  --text2: #64748b;
  --text3: #94a3b8;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --danger: #dc2626;
  --success: #059669;
  --warning: #d97706;
  --radius: 14px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow: 0 4px 20px rgba(15, 23, 42, .07);
  --shadow-lg: 0 20px 60px rgba(15, 23, 42, .14);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
.hidden { display: none !important; }

/* ---------- 顶栏 ---------- */
#topbar { background: rgba(255,255,255,.92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1160px; margin: 0 auto; padding: 0 24px; height: 64px; display: flex; justify-content: space-between; align-items: center; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 700; color: var(--navy); letter-spacing: -.3px; }
.brand-mark { font-size: 22px; }
.userbox { display: flex; align-items: center; gap: 16px; color: var(--text2); font-size: 14px; }
#welcome-user { font-weight: 500; color: var(--text); }

/* ---------- 按钮 ---------- */
.btn { border: none; border-radius: 9px; padding: 10px 20px; font-size: 14px; font-weight: 600; cursor: pointer; transition: all .18s ease; font-family: inherit; white-space: nowrap; flex-shrink: 0; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(37,99,235,.22); }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 12px rgba(37,99,235,.3); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { background: #93b4f5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-ghost { background: #fff; color: var(--text2); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: #cbd5e1; background: #f8fafc; }
.btn-danger-ghost { background: #fff; color: var(--danger); border: 1px solid var(--border); }
.btn-danger-ghost:hover { border-color: #fca5a5; background: #fef2f2; }
.btn-block { width: 100%; margin-top: 8px; padding: 13px; font-size: 15px; }
.btn-sm { padding: 7px 13px; font-size: 13px; border-radius: 7px; }

/* ---------- 登录页 ---------- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 32px 20px 60px; background: radial-gradient(ellipse at 15% 10%, #e0e7ff 0%, transparent 45%), radial-gradient(ellipse at 90% 90%, #dbeafe 0%, transparent 40%), var(--bg); }
.auth-shell { width: 100%; max-width: 1000px; min-height: 600px; display: grid; grid-template-columns: 1.05fr .95fr; background: var(--card); border-radius: 22px; box-shadow: var(--shadow-lg); overflow: hidden; }
.auth-brand { position: relative; padding: 56px 48px; display: flex; flex-direction: column; justify-content: space-between; background: linear-gradient(150deg, #1e3a8a 0%, #1d4ed8 55%, #2563eb 100%); color: #fff; overflow: hidden; }
.auth-brand::before { content: ''; position: absolute; width: 380px; height: 380px; border-radius: 50%; background: rgba(255,255,255,.07); top: -140px; right: -120px; }
.auth-brand::after { content: ''; position: absolute; width: 260px; height: 260px; border-radius: 50%; background: rgba(255,255,255,.05); bottom: -110px; left: -80px; }
.brand-inner { position: relative; z-index: 1; }
.logo-mark { width: 54px; height: 54px; background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.25); border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 27px; margin-bottom: 30px; }
.auth-brand h1 { font-size: 38px; font-weight: 800; line-height: 1.25; letter-spacing: -1px; margin-bottom: 16px; }
.brand-sub { font-size: 15px; line-height: 1.8; color: rgba(255,255,255,.78); }
.feature-list { list-style: none; margin-top: 44px; display: flex; flex-direction: column; gap: 22px; }
.feature-list li { display: flex; gap: 14px; align-items: flex-start; }
.feat-icon { width: 38px; height: 38px; flex-shrink: 0; background: rgba(255,255,255,.14); border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; }
.feature-list b { display: block; font-size: 14px; font-weight: 600; margin-bottom: 3px; }
.feature-list small { font-size: 12px; color: rgba(255,255,255,.68); }
.brand-foot { position: relative; z-index: 1; font-size: 12px; color: rgba(255,255,255,.5); }
.auth-panel { display: flex; align-items: center; justify-content: center; padding: 48px 52px; }
.auth-card { width: 100%; max-width: 340px; }
.auth-title { font-size: 26px; font-weight: 800; color: var(--navy); letter-spacing: -.5px; }
.auth-subtitle { font-size: 14px; color: var(--text2); margin: 8px 0 30px; }

/* ---------- 表单（统一） ---------- */
.tabs { display: flex; gap: 4px; background: #f1f5f9; padding: 4px; border-radius: 10px; width: fit-content; margin-bottom: 28px; }
.tab { border: none; background: transparent; padding: 9px 22px; border-radius: 7px; font-size: 14px; font-weight: 500; color: var(--text2); cursor: pointer; transition: all .15s; font-family: inherit; white-space: nowrap; flex-shrink: 0; }
.tab:hover { color: var(--text); }
.tab.active { background: #fff; color: var(--primary); font-weight: 700; box-shadow: var(--shadow-sm); }
.auth-card label, .card label, .sign-pane label, #tpl-fields label {
  display: block; font-size: 13px; font-weight: 600; color: var(--text);
  margin: 18px 0 8px;
}
.auth-card label:first-of-type, .card label:first-of-type { margin-top: 0; }
.auth-card input, .card input, .card select, .sign-pane input, #tpl-fields input {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--border); border-radius: 9px;
  font-size: 14px; font-family: inherit; color: var(--text); background: #fff;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.auth-card input:focus, .card input:focus, .card select:focus, .sign-pane input:focus, #tpl-fields input:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.auth-card input::placeholder, .card input::placeholder, .sign-pane input::placeholder { color: var(--text3); }
.auth-card input[type=file], .card input[type=file] { padding: 10px; background: #f8fafc; cursor: pointer; }
.form-error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }
.tpl-desc { font-size: 13px; color: var(--text2); margin-top: 10px; padding: 10px 12px; background: #f8fafc; border-radius: 8px; border-left: 3px solid var(--primary); }
.mytpl-select-row { display: flex; gap: 10px; align-items: stretch; }
.mytpl-select-row select { flex: 1 1 auto; min-width: 0; }
.mytpl-select-row .btn { flex: 0 0 auto; white-space: nowrap; }
.mytpl-select-row .btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- 主界面 ---------- */
#view-main { max-width: 1160px; margin: 0 auto; padding: 38px 24px 80px; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 26px; }
.page-head h2 { font-size: 26px; font-weight: 800; color: var(--navy); letter-spacing: -.5px; }
.page-sub { font-size: 14px; color: var(--text2); margin-top: 5px; }
.card { background: var(--card); border-radius: var(--radius); padding: 30px 32px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.card form { max-width: 560px; }

/* ---------- 合同列表 ---------- */
.contract-list { display: flex; flex-direction: column; gap: 14px; }
.contract-item { background: var(--card); border-radius: var(--radius); padding: 20px 24px; display: flex; justify-content: space-between; align-items: center; gap: 20px; box-shadow: var(--shadow-sm); border: 1px solid var(--border); transition: box-shadow .18s, transform .18s; }
.contract-item:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.contract-info h3 { font-size: 16px; font-weight: 700; color: var(--navy); margin-bottom: 9px; }
.contract-meta { font-size: 12.5px; color: var(--text2); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.badge { font-size: 12px; padding: 3px 10px; border-radius: 20px; font-weight: 600; white-space: nowrap; }
.badge-upload { background: #f1f5f9; color: var(--text2); }
.badge-template { background: var(--primary-light); color: var(--primary); }
.badge-pending { background: #fef3c7; color: var(--warning); }
.badge-signed { background: #d1fae5; color: var(--success); }
.contract-ops { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.empty { text-align: center; color: var(--text2); padding: 90px 20px; background: var(--card); border-radius: var(--radius); border: 1px dashed #cbd5e1; }
.empty-icon { font-size: 56px; margin-bottom: 18px; opacity: .75; }
.empty h3 { font-size: 18px; color: var(--navy); margin-bottom: 8px; }
.empty p { font-size: 14px; }

/* ---------- 签署页 ---------- */
.sign-layout { display: grid; grid-template-columns: 1fr 350px; gap: 22px; align-items: start; }
@media (max-width: 980px) { .sign-layout { grid-template-columns: 1fr; } .auth-shell { grid-template-columns: 1fr; } .auth-brand { display: none; } }
.hint { font-size: 13px; color: #92400e; background: #fffbeb; border: 1px solid #fde68a; padding: 11px 15px; border-radius: 9px; margin-bottom: 18px; }
.pdf-pane { padding: 22px; }
.pdf-pages { max-height: 72vh; overflow: auto; padding: 6px; display: flex; flex-direction: column; gap: 16px; align-items: center; background: #f8fafc; border-radius: 10px; }
/* 关键：绝不压缩页面高度。.pdf-pages 是带 max-height 的纵向 flex 容器，
   若允许 flex-shrink，canvas 会被压扁并被 overflow:hidden 裁掉，
   既看不到完整合同，也会让点选坐标 relY 映射到错误位置。 */
.pdf-page-wrap { position: relative; cursor: crosshair; box-shadow: 0 2px 10px rgba(15,23,42,.13); border-radius: 3px; overflow: hidden; background: #fff; width: 100%; flex: 0 0 auto; }
.pdf-page-wrap canvas { display: block; width: 100%; height: auto; }
.pdf-pages.zoomed .pdf-page-wrap { min-width: 900px; }
.pdf-pages.zoomed { background: #e2e8f0; }
.client-zoom-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 2px 10px; }
.client-zoom-bar small { font-size: 12px; color: var(--text2); }
.contract-text-box { padding: 22px 20px; }
.contract-text { font-size: 15px; line-height: 1.9; color: var(--text); white-space: pre-wrap; word-break: break-word; font-family: inherit; }
.contract-text-box a { display: inline-block; margin-top: 18px; text-decoration: none; }
.sign-marker { position: absolute; width: 150px; height: 60px; border: 2px dashed var(--primary); background: rgba(37,99,235,.09); border-radius: 6px; pointer-events: none; transform: translate(-50%, -50%); display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--primary); font-weight: 600; }
.sign-pane { position: sticky; top: 84px; }
.sign-pane .card { padding: 26px; }
.sig-pad-wrap { position: relative; border: 1.5px dashed #cbd5e1; border-radius: 10px; background: #fbfcfe; overflow: hidden; touch-action: none; overscroll-behavior: contain; }
#sig-pad, #client-sig-pad { display: block; width: 100%; height: 190px; touch-action: none !important; overscroll-behavior: contain; -webkit-user-select: none; user-select: none; cursor: crosshair; border-radius: 10px; }
.sig-pad-tip { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--text3); font-size: 14px; pointer-events: none; }
.sig-actions { margin-top: 12px; text-align: right; }
.sign-note { font-size: 12px; color: var(--text2); margin-top: 16px; line-height: 1.7; padding-top: 14px; border-top: 1px solid var(--border); }

/* ---------- 提示 ---------- */
.toast { position: fixed; top: 82px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 13px 26px; border-radius: 10px; font-size: 14px; z-index: 100; box-shadow: 0 10px 30px rgba(15,23,42,.25); }

/* ---------- 客户签署页（手机优先） ---------- */
.client-wrap { max-width: 760px; margin: 0 auto; padding: 30px 18px 70px; }
.client-header { text-align: center; margin-bottom: 28px; }
.client-logo { width: 56px; height: 56px; margin: 0 auto 14px; background: var(--primary); border-radius: 15px; display: flex; align-items: center; justify-content: center; font-size: 28px; box-shadow: 0 6px 18px rgba(37,99,235,.28); }
.client-header h1 { font-size: 24px; color: var(--navy); font-weight: 800; letter-spacing: -.5px; }
.client-header p { font-size: 14px; color: var(--text2); margin-top: 6px; word-break: break-all; }
.client-step { display: flex; gap: 12px; align-items: flex-start; margin: 24px 0 12px; }
.step-num { width: 26px; height: 26px; flex-shrink: 0; background: var(--primary); color: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
.client-step b { display: block; font-size: 15px; color: var(--navy); }
.client-step small { display: block; font-size: 12.5px; color: var(--text2); margin-top: 2px; }
.client-pdf-box { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow-sm); }
.client-pdf-box .pdf-pages { max-height: 60vh; background: #f8fafc; }
.client-form-card { margin-top: 4px; }
.result-card { text-align: center; padding: 56px 30px; margin-top: 30px; }
.result-icon { width: 72px; height: 72px; margin: 0 auto 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 38px; font-weight: 700; }
.result-icon.success { background: #d1fae5; color: var(--success); }
.result-icon.warn { background: #fef3c7; color: var(--warning); }
.result-card h2 { font-size: 22px; color: var(--navy); margin-bottom: 10px; }
.result-card p { font-size: 14px; color: var(--text2); line-height: 1.8; }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.5); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-card { background: #fff; border-radius: 16px; padding: 30px; width: 100%; max-width: 480px; box-shadow: var(--shadow-lg); }
.modal-card h3 { font-size: 19px; color: var(--navy); margin-bottom: 10px; }
.modal-card p { font-size: 13.5px; color: var(--text2); line-height: 1.7; margin-bottom: 18px; }
.modal-card input { width: 100%; padding: 12px 14px; border: 1.5px solid var(--border); border-radius: 9px; font-size: 13px; color: var(--text); background: #f8fafc; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ---------- 手机端微调 ---------- */
@media (max-width: 640px) {
  .auth-page { padding: 0; }
  .auth-shell { border-radius: 0; min-height: 100vh; box-shadow: none; }
  .auth-panel { padding: 40px 26px; }
  .auth-brand { padding: 40px 26px; }
  .auth-brand h1 { font-size: 30px; }

  /* 手机顶栏：品牌独占第一行；用户信息与操作按钮在第二行，杜绝挤压换行/竖排 */
  .topbar-inner {
    height: auto;
    padding: 10px 14px;
    flex-wrap: wrap;
    row-gap: 10px;
    align-items: center;
  }
  .brand {
    flex: 0 0 100%;
    white-space: nowrap;
    font-size: 15px;
    gap: 7px;
  }
  .brand-mark { font-size: 19px; }
  .userbox {
    flex: 0 0 100%;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
  }
  #welcome-user {
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
  }
  .userbox .btn {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 6px 11px;
    font-size: 12px;
  }

  /* 新建合同页签：改成自动换行的独立小按钮，杜绝文字竖排 */
  #create-tabs {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    gap: 8px;
    background: transparent;
    padding: 0;
    margin-bottom: 20px;
  }
  #create-tabs .tab {
    flex: 0 0 auto;
    padding: 9px 14px;
    font-size: 13px;
    background: #fff;
    border: 1px solid var(--border);
    color: var(--text2);
    box-shadow: var(--shadow-sm);
  }
  #create-tabs .tab.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    font-weight: 600;
    box-shadow: 0 3px 10px rgba(37, 99, 235, .28);
  }

  #view-main { padding: 20px 16px 60px; }
  .page-head { align-items: flex-start; gap: 12px; }
  .page-head h2 { font-size: 21px; }
  .page-head .btn { padding: 9px 14px; font-size: 13px; }
  .contract-item { flex-direction: column; align-items: stretch; padding: 18px; }
  .contract-ops { justify-content: flex-start; }
  .contract-ops .btn { flex: 1 1 auto; text-align: center; }
  .card { padding: 22px 20px; }
  .sign-layout { grid-template-columns: 1fr; }
  .sign-pane { position: static; }
  .client-wrap { padding: 22px 14px 60px; }
  .client-pdf-box { padding: 8px; }
  #sig-pad, #client-sig-pad { height: 170px; }
  .modal-card { padding: 24px 20px; }
}

/* ---------- 客户本人确认 ---------- */
.signee-box { background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 10px; padding: 14px 16px; margin-bottom: 18px; }
.signee-box span { display: block; font-size: 12px; color: var(--text2); margin-bottom: 4px; }
.signee-box b { font-size: 18px; color: var(--primary); font-weight: 700; }
.confirm-label { display: flex !important; align-items: flex-start; gap: 8px; font-size: 13px !important; font-weight: 400 !important; color: var(--text) !important; line-height: 1.6; margin: 16px 0 4px !important; cursor: pointer; }
.confirm-label input { width: 16px !important; height: 16px; margin-top: 2px; accent-color: var(--primary); flex-shrink: 0; }

/* 模板表单：下拉框 / 多行文本 */
#tpl-fields select, #tpl-fields textarea {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--border); border-radius: 9px;
  font-size: 14px; font-family: inherit; color: var(--text); background: #fff; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#tpl-fields select:focus, #tpl-fields textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }

/* ---------- 拍照合同：照片预览与签名位置指定 ---------- */
.badge-photo { background: #fce7f3; color: #be185d; }
.photo-preview-box { margin-top: 18px; }
.photo-hint { font-size: 13px; color: var(--primary); font-weight: 600; margin-bottom: 8px; }
.photo-preview-wrap {
  position: relative; display: inline-block; max-width: 100%; border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden; background: #fff; cursor: crosshair; box-shadow: var(--shadow-sm);
}
.photo-preview-wrap img { display: block; max-width: 100%; height: auto; }
.photo-preview-wrap .sign-marker { border-color: var(--danger); background: rgba(220,38,38,.10); color: var(--danger); }
.photo-pos-tip { font-size: 13px; color: var(--text2); margin-top: 10px; }
.sign-marker.fixed { border-color: var(--danger); background: rgba(220,38,38,.10); color: var(--danger); font-weight: 700; }

/* ---------- 注册待审核提示 ---------- */
.auth-notice { margin-top: 18px; padding: 14px 16px; background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 10px; color: #047857; font-size: 13.5px; line-height: 1.7; }

/* ---------- 后台：用户审核 ---------- */
.admin-summary { font-size: 13.5px; color: var(--text2); margin-bottom: 18px; padding: 12px 14px; background: #f8fafc; border-radius: 9px; }
.admin-summary b { color: var(--warning); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th { text-align: left; font-size: 12.5px; color: var(--text2); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.admin-table td { padding: 14px 12px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-ops { display: flex; gap: 8px; flex-wrap: wrap; }
.badge-status-pending { background: #fef3c7; color: var(--warning); }
.badge-status-approved { background: #d1fae5; color: var(--success); }
.badge-status-rejected { background: #fee2e2; color: var(--danger); }
.badge-admin { background: var(--primary-light); color: var(--primary); margin-left: 6px; }
@media (max-width: 640px) {
  .admin-table th:nth-child(2), .admin-table td:nth-child(2) { display: none; }
  .admin-table th, .admin-table td { padding: 12px 8px; }
}

/* ---------- 后台：用户数据卡片 ---------- */
.admin-user-list { display: flex; flex-direction: column; gap: 14px; }
.admin-user-card { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: #fff; }
.admin-user-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 18px; cursor: pointer; transition: background .15s; }
.admin-user-head:hover { background: #f8fafc; }
.admin-user-id { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.admin-user-id > b { font-size: 15px; color: var(--navy); }
.admin-user-count { font-size: 12.5px; color: var(--primary); background: var(--primary-light); padding: 3px 9px; border-radius: 20px; }
.admin-user-right { display: flex; align-items: center; gap: 12px; }
.admin-user-time { font-size: 12px; color: var(--text2); }
.admin-user-arrow { font-size: 12px; color: var(--text3); }
.admin-user-body { border-top: 1px solid var(--border); padding: 14px 18px 18px; background: #fafcff; }
.admin-user-ops { margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px dashed var(--border); }
.admin-contract { padding: 14px 0; border-bottom: 1px solid var(--border); }
.admin-contract:last-child { border-bottom: none; }
.admin-contract-main { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.admin-contract-main b { font-size: 14px; color: var(--text); }
.admin-contract-meta { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text2); margin-bottom: 10px; }
.admin-contract-ops { display: flex; gap: 8px; flex-wrap: wrap; }
.admin-no-contract { color: var(--text2); font-size: 13px; padding: 8px 0; }
@media (max-width: 640px) {
  .admin-user-head { align-items: flex-start; flex-direction: column; gap: 8px; padding: 14px; }
  .admin-user-body { padding: 12px 14px 16px; }
  .admin-user-time { font-size: 11.5px; }
}

/* ---------- 自定义模板：表单按钮组 / 预览框 ---------- */
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.preview-box { margin-top: 20px; padding: 16px; background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; }
.preview-box .pdf-pages { max-height: 60vh; }
.badge-custom { background: #fce7f3; color: #be185d; }

/* ---------- 创建模板向导 ---------- */
.wizard-step { max-width: 720px; }
.wizard-title { font-size: 17px; color: var(--navy); font-weight: 700; margin-bottom: 12px; display: flex; align-items: center; gap: 10px; }
.wizard-title .step-num { width: 26px; height: 26px; font-size: 13px; }
.mark-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0 12px; }
.mark-tool.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.nt-field-input-row { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.nt-field-input-row input { flex: 1 1 200px; padding: 9px 12px; border: 1.5px solid var(--border); border-radius: 9px; font-size: 14px; font-family: inherit; outline: none; }
.nt-field-input-row input:focus { border-color: var(--primary); }
.nt-preview-pages { max-height: 56vh; }
.mark-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.mark-row:last-child { border-bottom: none; }
.mark-row b { color: var(--text); flex: 1; }
.mark-row > span:not(.mark-dot) { color: var(--text2); font-size: 12.5px; }
.mark-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot-sign { background: var(--primary); }
.dot-seal { background: var(--danger); }
.dot-field { background: var(--success); }
.marks-summary { margin-top: 12px; padding: 12px 14px; background: #f8fafc; border-radius: 9px; border: 1px solid var(--border); }
.sign-marker.marker-sign { border-color: var(--primary); background: rgba(37,99,235,.12); color: var(--primary); }
.sign-marker.marker-seal { border-color: var(--danger); background: rgba(220,38,38,.12); color: var(--danger); }
.sign-marker.marker-field { border-color: var(--success); background: rgba(5,150,105,.12); color: var(--success); }
.admin-mode-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px dashed var(--border); }
.admin-mode-label { font-size: 13px; font-weight: 600; color: var(--text2); }
.convert-note { margin-top: 14px; padding: 11px 14px; background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 9px; color: #047857; font-size: 13px; line-height: 1.6; }

/* ---------- 标注预览：加宽 + 缩放 + 页码导航（解决看不到完整合同） ---------- */
/* 第 3 步标注区占满卡片宽度，不再局限 720px */
#create-newtpl #nt-step3 { max-width: 100%; }
/* 预览高度放大到 80vh，尽量一屏多看 */
.nt-preview-pages { max-height: 80vh; }
.nt-preview-pages .pdf-page-wrap { max-width: 1000px; }
/* 缩放工具条 */
.nt-zoom-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 6px 0 12px; padding: 8px 10px; background: #f8fafc; border: 1px solid var(--border); border-radius: 9px; }
.nt-zoom-left, .nt-zoom-right { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }
.nt-zoom-right .btn { padding: 6px 10px; font-size: 12px; }
.nt-page-info { font-size: 12.5px; color: var(--text2); }
.nt-jump-input { width: 52px; padding: 6px 8px; border: 1.5px solid var(--border); border-radius: 7px; font-size: 13px; text-align: center; font-family: inherit; outline: none; }
.nt-jump-input:focus { border-color: var(--primary); }
.nt-page-sep { color: var(--text3); font-size: 13px; }
/* 每页顶部页码标签 */
.nt-page-label { position: absolute; top: 8px; left: 8px; z-index: 3; background: rgba(15,23,42,.72); color: #fff; font-size: 11px; padding: 3px 9px; border-radius: 12px; pointer-events: none; }
/* 放大模式：页面固定更宽，横向滚动 */
.nt-preview-pages.zoomed .pdf-page-wrap { min-width: 1000px; max-width: 1000px; }
.nt-preview-pages.zoomed { background: #e2e8f0; }
@media (max-width: 640px) {
  .nt-preview-pages { max-height: 68vh; }
  .nt-zoom-bar { justify-content: center; }
  .nt-page-info { width: 100%; text-align: center; order: 3; }
}

/* ---------- 手机端：新建合同 / 向导细节精修 ---------- */
@media (max-width: 640px) {
  .page-sub { line-height: 1.7; margin-top: 8px; }
  /* 向导步骤标题更紧凑：序号与文字对齐 */
  .wizard-title { font-size: 16px; gap: 9px; margin-bottom: 14px; }
  .wizard-title .step-num { width: 28px; height: 28px; font-size: 14px; flex-shrink: 0; }
  /* 提示框：柔和、行距舒展 */
  .hint { line-height: 1.75; padding: 11px 13px; }
  /* 卡片内表单留白更舒适 */
  #page-create .card { padding: 20px 18px; }
  /* 表单主按钮在手机上更饱满 */
  #page-create .btn-primary { padding: 11px 18px; }
}

/* ---------- AI 智能生成标准合同 ---------- */
.nt-step1-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.btn-ai { background: linear-gradient(135deg,#7c3aed,#4f46e5); color:#fff; border:1px solid #4f46e5; box-shadow:0 4px 14px rgba(79,70,229,.25); font-weight:700; }
.btn-ai:hover { filter:brightness(1.06); }
.ai-hint { margin-top:14px; padding:11px 14px; background:#f5f3ff; border:1px solid #ddd6fe; border-radius:9px; color:#5b21b6; font-size:12.5px; line-height:1.7; }
.ai-fields-box { margin:16px 0; max-height:340px; overflow:auto; border:1px solid var(--border); border-radius:10px; background:#f8fafc; }
.ai-field-row { display:flex; align-items:center; gap:10px; padding:9px 14px; border-bottom:1px solid var(--border); font-size:13px; }
.ai-field-row:last-child { border-bottom:none; }
.ai-field-name { flex:1; font-weight:600; color:var(--text); }
.ai-field-type { font-size:11px; color:#6d28d9; background:#ede9fe; border-radius:20px; padding:2px 9px; }
.ai-field-val { color:var(--text2); font-size:12px; max-width:42%; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.derived-tag { display:inline-block; font-size:11px; font-weight:600; color:#047857; background:#d1fae5; border-radius:20px; padding:2px 9px; vertical-align:middle; }
.derived-input { color:#64748b; background:#f1f5f9; border-style:dashed; cursor:not-allowed; }
.nt-ai-preview-head { font-size:14px; font-weight:700; color:var(--navy); margin:18px 0 10px; }
.nt-ai-preview-pages { max-height:70vh; }
@media (max-width:640px) {
  .nt-step1-actions { flex-direction:column; }
  .nt-step1-actions .btn { width:100%; }
  .ai-field-val { max-width:35%; }
}

/* ---------- AI 确认页：印章上传 ---------- */
.ai-seal-box { margin:16px 0; padding:14px 16px; background:#fff7ed; border:1px solid #fed7aa; border-radius:10px; }
.ai-seal-title { font-size:14px; font-weight:700; color:#9a3412; margin-bottom:6px; }
.ai-seal-hint { font-size:12px; color:#c2410c; line-height:1.6; margin:0 0 10px; }
.ai-seal-row { display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
.ai-seal-row input[type=file] { font-size:12.5px; flex:1 1 220px; }
.ai-seal-status { margin-top:9px; font-size:12px; color:#9a3412; }
.ai-seal-status.sealed { color:#047857; font-weight:600; }

/* ==================================================================
   v27 手机端整站美化（首页 + 全部内页）
   仅作用于 max-width:640px；桌面端样式完全不受影响。
   注意：不改 .pdf-page-wrap 的 flex:0 0 auto（v22 修复），不改签名区 touch-action。
   ================================================================== */
@media (max-width: 640px) {
  html, body { overflow-x: hidden; }

  /* ---------------- 顶栏 ---------------- */
  #topbar {
    background: rgba(255,255,255,.96);
    border-bottom: 1px solid rgba(226,232,240,.9);
    box-shadow: 0 1px 12px rgba(15,23,42,.05);
  }
  .topbar-inner { padding: 9px 14px; row-gap: 8px; }
  .brand { font-size: 15.5px; letter-spacing: -.2px; }
  .brand-mark {
    width: 30px; height: 30px;
    display: inline-flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    border-radius: 9px; font-size: 15px;
    box-shadow: 0 3px 9px rgba(37,99,235,.3);
  }
  .userbox { gap: 7px; padding-top: 1px; }
  .userbox .btn {
    min-height: 32px;
    border-radius: 8px;
    background: #f8fafc;
    border-color: #e2e8f0;
    color: #475569;
  }

  /* ---------------- 登录页（首页）---------------- */
  .auth-page {
    padding: 0;
    display: block;
    background: linear-gradient(180deg, #eef2f7 0%, #e3ebf6 100%);
  }
  .auth-shell {
    display: block;
    max-width: 100%;
    min-height: 100vh;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
    overflow: visible;
  }
  /* 手机端不再隐藏品牌区，改为顶部渐变 hero */
  .auth-brand {
    display: block;
    position: relative;
    padding: 34px 24px 30px;
    border-radius: 0 0 26px 26px;
    background: linear-gradient(150deg, #1e3a8a 0%, #1d4ed8 52%, #2563eb 100%);
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(29,78,216,.22);
  }
  .auth-brand::before { width: 240px; height: 240px; top: -110px; right: -90px; }
  .auth-brand::after { display: none; }
  .auth-brand .logo-mark {
    width: 46px; height: 46px; font-size: 23px;
    border-radius: 13px; margin-bottom: 15px;
    background: rgba(255,255,255,.18);
  }
  .auth-brand h1 { font-size: 26px; line-height: 1.28; margin-bottom: 7px; letter-spacing: -.6px; }
  .auth-brand h1 br { display: none; }
  .brand-sub { font-size: 12.5px; line-height: 1.65; color: rgba(255,255,255,.82); }
  .brand-sub br { display: none; }
  .feature-list, .brand-foot { display: none; }
  .auth-panel { padding: 20px 15px calc(32px + env(safe-area-inset-bottom)); }
  .auth-card {
    max-width: 100%;
    background: #fff;
    border-radius: 18px;
    padding: 22px 19px;
    border: 1px solid rgba(226,232,240,.9);
    box-shadow: 0 12px 34px rgba(15,23,42,.10);
  }
  .auth-title { font-size: 21px; }
  .auth-subtitle { margin: 6px 0 20px; font-size: 13px; }
  .auth-tabs { width: 100%; margin-bottom: 22px; }
  .auth-tabs .tab { flex: 1 1 0; padding: 10px 0; }

  /* ---------------- 表单：iOS 防自动缩放（16px）+ 触控友好 ---------------- */
  .auth-card input,
  .card input, .card select, .card textarea,
  .sign-pane input,
  #tpl-fields input, #tpl-fields select, #tpl-fields textarea,
  .modal-card input,
  .nt-field-input-row input { font-size: 16px; }
  .auth-card input, .card input, .card select, .card textarea,
  .sign-pane input { padding: 12px 14px; border-radius: 10px; }
  .nt-jump-input { font-size: 16px; width: 60px; }
  .card label, .auth-card label { margin: 16px 0 7px; }

  /* ---------------- 按钮：统一触控高度 ---------------- */
  .btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .btn-sm { min-height: 36px; }
  .btn-block { min-height: 50px; font-size: 16px; }

  /* ---------------- 主区域 / 页面标题 ---------------- */
  #view-main { padding: 16px 14px calc(48px + env(safe-area-inset-bottom)); }
  .page-head {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(226,232,240,.85);
  }
  .page-head > div { position: relative; padding-left: 12px; }
  .page-head > div::before {
    content: '';
    position: absolute; left: 0; top: 3px; bottom: 4px;
    width: 4px; border-radius: 4px;
    background: linear-gradient(180deg, #3b82f6, #1d4ed8);
  }
  .page-head h2 { font-size: 21px; letter-spacing: -.4px; }
  .page-sub { font-size: 12.5px; margin-top: 4px; }
  .page-head .btn { width: 100%; }

  /* ---------------- 合同列表卡片 ---------------- */
  .contract-list { gap: 12px; }
  .contract-item {
    position: relative;
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    padding: 16px 16px 15px 18px;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(15,23,42,.06);
  }
  .contract-item::before {
    content: '';
    position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
    background: #cbd5e1;
  }
  .contract-item.status-pending::before { background: linear-gradient(180deg, #fbbf24, #d97706); }
  .contract-item.status-signed::before { background: linear-gradient(180deg, #34d399, #059669); }
  .contract-info h3 { font-size: 15.5px; line-height: 1.45; margin-bottom: 10px; }
  .contract-meta { gap: 8px; font-size: 12px; }
  .badge { font-size: 11.5px; padding: 3px 9px; }
  .contract-ops {
    justify-content: stretch;
    gap: 8px;
    padding-top: 12px;
    border-top: 1px dashed #e2e8f0;
  }
  .contract-ops .btn {
    flex: 1 1 calc(50% - 4px);
    min-height: 40px;
    font-size: 13px;
    padding: 8px 10px;
  }
  .contract-ops .btn-primary { flex: 1 1 100%; }

  /* ---------------- 通用卡片 / 空状态 ---------------- */
  .card {
    padding: 20px 16px;
    border-radius: 16px;
    box-shadow: 0 2px 12px rgba(15,23,42,.06);
  }
  .card form { max-width: 100%; }
  .empty { padding: 56px 18px; border-radius: 16px; }
  .empty-icon { font-size: 46px; margin-bottom: 14px; }

  /* ---------------- 新建合同页签 ---------------- */
  #create-tabs { gap: 7px; margin-bottom: 18px; }
  #create-tabs .tab { padding: 9px 13px; font-size: 12.5px; border-radius: 10px; }

  /* ---------------- 签署页 / 客户签署页 ---------------- */
  .sign-layout { gap: 16px; }
  .pdf-pane { padding: 14px; border-radius: 16px; }
  .pdf-pane .pdf-pages { max-height: 64vh; gap: 12px; padding: 4px; }
  .client-wrap { padding: 18px 13px calc(56px + env(safe-area-inset-bottom)); }
  .client-header { margin-bottom: 20px; }
  .client-logo { width: 50px; height: 50px; font-size: 25px; border-radius: 14px; margin-bottom: 12px; }
  .client-header h1 { font-size: 21px; }
  .client-header p { font-size: 13px; }
  .client-step { gap: 10px; margin: 20px 0 10px; }
  .client-step b { font-size: 14.5px; }
  .client-step small { font-size: 12px; }
  .client-pdf-box { padding: 8px; border-radius: 14px; }
  .client-pdf-box .pdf-pages { max-height: 62vh; }
  .sign-pane .card { padding: 20px 16px; }
  #sig-pad, #client-sig-pad { height: 180px; }
  .sig-pad-wrap { border-radius: 12px; }
  .sign-note { font-size: 11.5px; }
  .contract-text-box { padding: 18px 15px; }
  .contract-text { font-size: 15px; line-height: 1.95; }

  /* ---------------- 弹窗：底部抽屉 ---------------- */
  .modal { align-items: flex-end; padding: 0; }
  .modal-card {
    max-width: 100%;
    width: 100%;
    border-radius: 22px 22px 0 0;
    padding: 24px 18px calc(22px + env(safe-area-inset-bottom));
    max-height: 90vh;
    overflow-y: auto;
    animation: sheetUp .26s cubic-bezier(.22,.8,.3,1);
  }
  .modal-card h3 { font-size: 17px; }
  .modal-actions { flex-direction: column; gap: 9px; }
  .modal-actions .btn { width: 100%; }
  .toast {
    top: auto;
    bottom: calc(24px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 32px);
    text-align: center;
  }
  @keyframes sheetUp {
    from { transform: translateY(100%); opacity: .55; }
    to { transform: translateY(0); opacity: 1; }
  }

  /* ---------------- 后台：用户 / 合同操作 ---------------- */
  .admin-user-card { border-radius: 14px; }
  .admin-user-ops .btn { min-height: 40px; }
  .admin-contract-ops { gap: 7px; }
  .admin-contract-ops .btn { flex: 1 1 calc(50% - 4px); min-height: 38px; }

  /* ---------------- 模板向导 / 标注 ---------------- */
  .wizard-step { max-width: 100%; }
  .mark-toolbar { gap: 7px; }
  .mark-toolbar .btn { flex: 1 1 calc(50% - 4px); min-height: 40px; font-size: 12.5px; }
  .nt-field-input-row input { flex: 1 1 100%; }
  .nt-field-input-row .btn { flex: 1 1 auto; }
  .nt-zoom-bar { padding: 9px 8px; gap: 8px; }
  .nt-zoom-left, .nt-zoom-right { width: 100%; justify-content: center; }
  .form-actions { flex-direction: column; gap: 9px; }
  .form-actions .btn { width: 100%; }
  .nt-step1-actions .btn { min-height: 46px; }
  .ai-field-row { padding: 9px 12px; }
  .preview-box { padding: 12px; border-radius: 12px; }
}

/* ---------------- v27.1 手机端细节修正 ---------------- */
.file-mobile-tip { display: none; }
@media (max-width: 640px) {
  /* 返回类次要按钮不再占满整行，避免顶掉内容 */
  .page-head .btn-ghost { width: auto; align-self: flex-start; }

  /* 模板下拉 + 删除按钮：窄屏改为上下两行，长文案不再被截断 */
  .mytpl-select-row { flex-wrap: wrap; gap: 8px; }
  .mytpl-select-row select { flex: 1 1 100%; }
  .mytpl-select-row .btn { flex: 0 0 auto; margin-left: auto; }

  /* 空描述的浅色条不再占位 */
  .tpl-desc:empty { display: none; }

  /* 底部留白，避开固定备案条遮挡（含 iPhone 安全区） */
  #view-main { padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
  .client-wrap { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

  /* 手机上传提示：说明如何进入「文件」目录 */
  .file-mobile-tip {
    display: block;
    font-size: 12px;
    line-height: 1.7;
    color: #475569;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-left: 3px solid var(--primary);
    border-radius: 8px;
    padding: 9px 11px;
    margin: 4px 0 10px;
  }
  .file-mobile-tip b { color: var(--primary); }
}
