:root {
  --bg: #f4f4f6;
  --panel: #ffffff;
  --ink: #1b1b1f;
  --ink-2: #5b5b63;
  --line: #d8d8de;
  --brand: #7d2b8b;
  --brand-soft: #f4ecf6;
  --danger: #b3261e;
  --ok: #1f7a45;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 30, .06), 0 6px 18px rgba(20, 20, 30, .06);
}

* { box-sizing: border-box; }

/* html 的 hidden 属性必须压过下面所有 display:grid/flex 规则。
   UA 的 [hidden]{display:none} 优先级低于作者样式表里的 .login-wrap{display:grid}，
   漏了这条会让「隐藏」的登录层/签名弹层照样显示——签名弹层是全屏遮罩，会直接盖住登录入口。 */
[hidden] { display: none !important; }

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

h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.3; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }

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

/* ---------- 控件 ---------- */
input, select, textarea, button { font: inherit; color: inherit; }

input[type=text], input[type=password], input[type=date], input[type=time],
input[type=tel], input[type=number], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  min-height: 40px;
}

textarea { resize: vertical; min-height: 96px; line-height: 1.55; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(125, 43, 139, .12);
}

input[readonly] { background: #f7f7f9; color: var(--ink-2); }

label.field { display: block; }
label.field > span.lbl, .lbl {
  display: block;
  font-size: 12px;
  color: var(--ink-2);
  margin-bottom: 4px;
  letter-spacing: .2px;
}
.lbl i { font-style: normal; color: var(--danger); margin-left: 2px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  min-height: 40px;
  white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { border-color: #bfbfc8; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #6b2278; }
.btn.danger { color: var(--danger); border-color: #e6c4c1; }
.btn.danger:hover { background: #fdf3f2; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px 20px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  background:
    radial-gradient(900px 420px at 50% -8%, #efe3f2 0%, rgba(239, 227, 242, 0) 62%),
    linear-gradient(180deg, #faf9fb 0%, var(--bg) 100%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(20,20,30,.05), 0 18px 44px rgba(20,20,30,.09);
  padding: 30px 28px 26px;
  border: 1px solid rgba(20,20,30,.05);
}
.login-head { text-align: center; margin-bottom: 22px; }
.login-logo { height: 42px; display: block; margin: 0 auto 14px; }
.login-card h1 { font-size: 19px; letter-spacing: .5px; margin: 0 0 6px; }
.login-sub {
  margin: 0;
  font-size: 9.5px;
  letter-spacing: 1.1px;
  color: #9a9aa4;
  text-transform: uppercase;
}
.login-field { display: block; margin-bottom: 14px; }
.login-field > span {
  display: block;
  font-size: 12.5px;
  color: var(--ink-2);
  margin-bottom: 6px;
  letter-spacing: .3px;
}
.login-field input {
  height: 46px;
  font-size: 15px;
  padding: 0 13px;
  border-radius: 9px;
}
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 62px; }
.pw-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font-size: 12.5px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.pw-toggle:hover { background: #f2f2f6; color: var(--ink); }
.login-submit {
  height: 46px;
  font-size: 15px;
  letter-spacing: 2px;
  margin-top: 6px;
  border-radius: 9px;
}
.login-alert {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fdf1f0;
  border: 1px solid #f2d3d0;
  color: var(--danger);
  font-size: 12.5px;
  line-height: 1.55;
}
.login-foot {
  margin: 0;
  font-size: 10.5px;
  letter-spacing: 1.4px;
  color: #b3b3bc;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 20px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { height: 30px; }
.brand strong { display: block; font-size: 15px; }
.brand small { display: block; font-size: 9px; letter-spacing: .8px; color: var(--ink-2); }
.nav { display: flex; gap: 6px; }
.nav a {
  padding: 7px 12px;
  border-radius: 8px;
  color: var(--ink-2);
  font-size: 14px;
}
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.ver { font: 11px/1 ui-monospace, Menlo, monospace; color: #a0a0aa; letter-spacing: .3px; }

.view { max-width: 1100px; margin: 0 auto; padding: 20px 20px 96px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card > h2 { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.muted { color: var(--ink-2); font-size: 13px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 180px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stack > * + * { margin-top: 12px; }

/* ---------- 列表 ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.toolbar .field { flex: 1 1 140px; }

.table-wrap { overflow-x: auto; border-radius: 8px; border: 1px solid var(--line); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; background: #fff; }
table.data th, table.data td { padding: 9px 12px; text-align: left; border-bottom: 1px solid #ececf0; vertical-align: middle; }
table.data th { background: #fafafb; font-weight: 600; font-size: 12.5px; color: var(--ink-2); white-space: nowrap; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: #fbf9fc; }
table.data tbody tr.picked { background: var(--brand-soft); }
table.data tbody tr.picked:hover { background: #efe0f3; }
table.data th.pick, table.data td.pick { width: 44px; padding-right: 0; text-align: center; }
table.data input[type=checkbox] {
  width: 18px; height: 18px; margin: 0; cursor: pointer; accent-color: var(--brand);
  vertical-align: middle;
}
table.data th input[type=checkbox]:indeterminate { outline: 2px solid var(--brand); outline-offset: -2px; }
table.data td.no { font-variant-numeric: tabular-nums; white-space: nowrap; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #f0f0f4;
  color: var(--ink-2);
  white-space: nowrap;
}
.badge.draft { background: #fff4e0; color: #8a5300; }
.badge.submitted { background: #e7f5ec; color: var(--ok); }
.badge.void { background: #fbeceb; color: var(--danger); }
.badge.warn { background: #fff4e0; color: #8a5300; }

/* 标签页（候选词条三个独立列表） */
.tabs { display: flex; gap: 6px; margin: 12px 0 4px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tab {
  border: 0; background: transparent; padding: 9px 14px; cursor: pointer;
  font-size: 14px; color: var(--ink-2); border-bottom: 2px solid transparent;
  margin-bottom: -1px; border-radius: 6px 6px 0 0;
}
.tab:hover { background: #f7f7fa; color: var(--ink); }
.tab.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; background: var(--brand-soft); }
.tab-count {
  display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 999px;
  background: #ececf0; color: var(--ink-2); font-size: 11px; font-weight: 500;
  min-width: 18px; text-align: center;
}
.tab.on .tab-count { background: #fff; color: var(--brand); }

.inline-edit {
  width: 100%; border: 1px solid transparent; background: transparent;
  padding: 6px 8px; border-radius: 6px; min-height: 34px;
}
.inline-edit:hover { border-color: var(--line); background: #fff; }
.inline-edit:focus { border-color: var(--brand); background: #fff; outline: none; }
.danger-text { color: var(--danger); }
.danger-text:hover { background: #fdf3f2; border-color: #e6c4c1; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }

/* ---------- 工单表单 ---------- */
.order-title { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.order-no {
  font: 600 20px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .5px;
  color: var(--brand);
}
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  background: #fff;
  min-height: 40px;
}
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--brand); }
.check.on { border-color: var(--brand); background: var(--brand-soft); }

.parts { display: grid; gap: 8px; }
.part-row { display: grid; grid-template-columns: 28px 1.2fr 1fr 1fr auto; gap: 8px; align-items: center; }
.part-row .idx { font-size: 12px; color: var(--ink-2); text-align: center; }

.sign-slot { position: relative; }
.sign-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 2px 7px;
  font-size: 12.5px;
  color: var(--ink-2);
  min-height: 30px;
}
.sign-label { font-weight: 600; color: var(--ink); }
.sign-state { font-size: 12px; }
.sign-state.ok { color: var(--ok); font-weight: 600; }
.signed .sign-state.ok::before { content: "✓ "; }

/* 画布必须有确定高度：靠 absolute 定位的提示层撑起来的盒子高度是 0，
   鼠标根本点不到，这正是「电脑上唤不起签名」的根因 */
.sign-box {
  position: relative;
  height: 168px;
  border: 1px dashed #c9c9d2;
  border-radius: 10px;
  background:
    linear-gradient(#fff, #fff) padding-box,
    repeating-linear-gradient(0deg, #f6f6f8 0 27px, #fff 27px 28px);
  overflow: hidden;
}
.signed .sign-box { border-style: solid; border-color: var(--brand); }
.sign-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}
.sign-guide {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #b9b9c2;
  font-size: 13px;
  letter-spacing: .5px;
  pointer-events: none;
}
.sign-img {
  display: block;
  width: 100%;
  height: 168px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--brand);
  border-radius: 10px;
  padding: 6px;
}
.sign-tools { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.sign-redo { align-self: center; }
.sign-slot .btn.sm { min-height: 34px; }

.sticky-actions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; gap: 10px; justify-content: flex-end; align-items: center;
  padding: 10px 20px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .95);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}
.sticky-actions .spacer { margin-right: auto; font-size: 13px; color: var(--ink-2); }

/* ---------- 客户下拉 ---------- */
.combo { position: relative; }
.combo-list {
  position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 260px; overflow: auto;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 12px 28px rgba(20, 20, 30, .12);
}
.combo-list button {
  display: block; width: 100%; text-align: left; padding: 8px 12px;
  border: 0; background: #fff; cursor: pointer; font-size: 14px;
}
.combo-list button:hover, .combo-list button.active { background: var(--brand-soft); }
.combo-list small { display: block; color: var(--ink-2); font-size: 12px; }
.combo-empty { padding: 10px 12px; font-size: 13px; color: var(--ink-2); line-height: 1.6; }
.combo-empty a { color: var(--brand); }

/* ---------- 导入 ---------- */
.steps { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.step { padding: 6px 12px; border-radius: 999px; background: #f0f0f4; font-size: 13px; color: var(--ink-2); }
.step.on { background: var(--brand); color: #fff; }

.dropzone {
  border: 2px dashed #cfcfd8; border-radius: 10px; padding: 28px; text-align: center;
  color: var(--ink-2); cursor: pointer; background: #fcfcfd;
}
.dropzone.over { border-color: var(--brand); background: var(--brand-soft); }
.dropzone strong { color: var(--ink); }
.drop-actions { margin-top: 12px; display: flex; justify-content: center; }
.dropzone label.btn { cursor: pointer; }

.stat-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.stat { flex: 1 1 120px; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--ink-2); }
.stat.ins b { color: var(--ok); }
.stat.upd b { color: var(--brand); }
.stat.skip b { color: var(--ink-2); }
.stat.bad b { color: var(--danger); }

/* ---------- 弹层 ---------- */
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.modal-head h3 { margin: 0; }
.icon-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-2);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { background: #f2f2f6; color: var(--ink); }
body.modal-open { overflow: hidden; }
.modal-card {
  width: 100%; max-width: 820px; background: #fff; border-radius: 14px;
  padding: 18px; box-shadow: 0 24px 60px rgba(0, 0, 0, .3);
}
.hint { color: var(--ink-2); font-size: 13px; margin: 0 0 10px; }

#pwd-dialog { border: none; border-radius: 12px; box-shadow: 0 24px 60px rgba(0, 0, 0, .3); padding: 20px; max-width: 360px; width: calc(100% - 32px); }
#pwd-dialog .field { margin-bottom: 12px; }
#pwd-dialog input { margin-top: 6px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.toast {
  position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%);
  background: #1b1b1f; color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 14px; z-index: 80; box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  max-width: calc(100vw - 40px);
}
.toast.bad { background: var(--danger); }

/* ---------- 打印纸 ---------- */
#print-sheet { display: none; }

@media print {
  @page { size: A4 portrait; margin: 8mm 9mm; }
  html, body { background: #fff; }
  body > #login-view, body > #app-view, #pwd-dialog, #toast { display: none !important; }
  #print-sheet { display: block; }

  .paper {
    width: 100%;
    color: #000;
    font: 9.6pt/1.35 "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  }
  .paper .p-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12mm; }
  .paper .p-head h1 { font-size: 15pt; margin: 0 0 1mm; letter-spacing: .2px; }
  .paper .p-head .p-cn { font-size: 16pt; font-weight: 700; margin: 0; }
  .paper .p-head .p-en { font-size: 7.5pt; letter-spacing: .5px; color: #333; margin: 0 0 1mm; }
  .paper .p-meta { font-size: 8.6pt; text-align: right; min-width: 55mm; }
  .paper .p-meta .no { font-size: 11pt; font-weight: 700; letter-spacing: .3px; border-bottom: .4pt solid #000; padding: 0 1mm 0.4mm; display: inline-block; min-width: 45mm; text-align: center; }
  .paper .p-logo { height: 9mm; margin-bottom: 1mm; }

  .paper table { width: 100%; border-collapse: collapse; table-layout: fixed; }
  .paper table + table { border-top: none; }
  .paper th, .paper td {
    border: .4pt solid #000;
    padding: 1.1mm 1.6mm;
    vertical-align: top;
    font-size: 8.4pt;
  }
  .paper .cell-label {
    display: block; font-size: 6.6pt; letter-spacing: .15px; color: #222;
    margin-bottom: .3mm;
  }
  .paper .cell-val { display: block; min-height: 3.6mm; white-space: pre-wrap; word-break: break-word; }
  .paper .box {
    display: inline-block; width: 2.6mm; height: 2.6mm; border: .4pt solid #000;
    margin-right: 1.2mm; vertical-align: -0.4mm; text-align: center; line-height: 2.4mm;
    font-size: 7pt;
  }
  .paper .box.on::after { content: "✓"; font-weight: 700; }
  .paper .opts { display: flex; flex-wrap: wrap; gap: 1mm 6mm; }
  .paper .opt { white-space: nowrap; font-size: 8pt; }
  .paper .sec-title { font-size: 6.8pt; color: #222; display: block; margin-bottom: .6mm; }
  .paper .tall { height: 30mm; }
  .paper .tall-2 { height: 24mm; }
  .paper .sig-img { display: block; height: 14mm; margin: 0 auto; }
  .paper .sig-empty { height: 14mm; }
  .paper .p-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 8mm; margin-top: 2mm; }
  .paper .p-foot .foot-l { font-size: 7.6pt; line-height: 1.5; }
  .paper .p-foot .foot-r { font-size: 7.6pt; text-align: right; line-height: 1.6; }
  .paper .p-foot .tel { font-size: 10.5pt; font-weight: 700; letter-spacing: .3px; }
}

@media (max-width: 700px) {
  .view { padding: 14px 12px 100px; }
  .topbar { gap: 10px; padding: 8px 12px; }
  .brand small { display: none; }
  .nav { order: 3; width: 100%; }
  .userbox { font-size: 12px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .part-row { grid-template-columns: 24px 1fr 1fr; }
  .part-row .old-sn { grid-column: 2 / 4; }
  .sign-box { height: 200px; }
  .sign-img { height: 200px; }
  .login-card { padding: 24px 20px 22px; border-radius: 14px; }
  .part-row .del { grid-column: 3; justify-self: end; }
  .sticky-actions { padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
  .sticky-actions .btn { flex: 1 1 auto; }
}
