:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #1f2937;
  --muted: #64748b;
  --primary: #185fa5;
  --primary-d: #0c447c;
  --accent: #0f6e56;
  --danger: #a32d2d;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; }
#app { min-height: 100vh; }

/* 登录 */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 32px; width: 340px; box-shadow: 0 4px 20px rgba(0,0,0,.06); }
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card .sub { color: var(--muted); margin-bottom: 20px; }

/* 布局 */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 200px; background: #0c2238; color: #cbd5e1; padding: 16px 0; flex-shrink: 0; }
.sidebar .brand { padding: 0 20px 16px; font-weight: 600; color: #fff; font-size: 16px; border-bottom: 1px solid #1e3a55; }
.sidebar a { display: block; padding: 11px 20px; color: #cbd5e1; text-decoration: none; cursor: pointer; }
.sidebar a:hover { background: #15314c; color: #fff; }
.sidebar a.active { background: var(--primary); color: #fff; }
.main { flex: 1; display: flex; flex-direction: column; }
.topbar { height: 52px; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 20px; }
.topbar .right { color: var(--muted); display: flex; gap: 14px; align-items: center; }
.content { padding: 20px; overflow: auto; }
.page-title { font-size: 18px; font-weight: 600; margin: 0 0 14px; display: flex; gap: 10px; align-items: center; }

/* 表格/表单 */
table.grid { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); }
table.grid th, table.grid td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; font-size: 13px; }
table.grid th { background: #f1f5f9; font-weight: 600; }
table.grid tr:nth-child(even) td { background: #fafcff; }
.toolbar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
input, select, textarea { border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; font-size: 13px; font-family: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid #b5d4f4; border-color: var(--primary); }
button { cursor: pointer; border: none; border-radius: 6px; padding: 8px 14px; font-size: 13px; background: var(--primary); color: #fff; }
button:hover { background: var(--primary-d); }
button.ghost { background: #eef2f7; color: var(--text); }
button.ghost:hover { background: #e2e8f0; }
button.danger { background: var(--danger); }
button.sm { padding: 5px 10px; font-size: 12px; }
.muted { color: var(--muted); }
.tag { display: inline-block; background: #eef2f7; border-radius: 4px; padding: 1px 7px; font-size: 12px; margin-right: 4px; }
.section { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.ro { display: inline-block; padding: 7px 9px; background: #f4f6f9; border-radius: 6px; font-size: 13px; color: #334155; min-height: 34px; line-height: 1.4; }
.field label { font-size: 12px; color: var(--muted); }
.grow { flex: 1; min-width: 150px; }
.history-hint { background: #fff7ed; border: 1px solid #fdba74; color: #9a3412; padding: 6px 10px; border-radius: 6px; font-size: 12px; }

/* 模态 */
.modal-mask { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border-radius: 12px; padding: 20px; width: 720px; max-width: 94vw; max-height: 92vh; overflow: auto; }
.modal h3 { margin: 0 0 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }

/* 打印 */
@media print {
  /* 打印时把应用外壳彻底移出文档流。旧写法只用 visibility:hidden ——
     元素仍占据高度，页面内容一多就会在打印区之后顶出空白页
     （唛头「打印预览下方还是空白」的根因，与唛头宽度无关）。 */
  /* 关键：必须重置 html/body 的高度与 min-height。否则即使 #app 已 display:none，
     documentElement 仍残留 100vh（约 344mm）高度，超出 A4 297mm 顶出第二张空白页。 */
  html, body { margin: 0 !important; padding: 0 !important; background: #fff !important;
    height: auto !important; min-height: 0 !important; }
  #app, #modal-root, .no-print, .shell, .login-wrap { display: none !important; }
  #print-area { display: block !important; position: static !important; width: auto !important;
    height: auto !important; min-height: 0 !important; padding: 24px !important; }
  #print-area, #print-area * { visibility: visible !important; }
  /* 唛头是满页排版，不能再叠加内边距（否则会被挤到第二页） */
  #print-area.bare { padding: 0 !important; }
}
/* 单据（PI / PL / 合同）统一版式：同一字体，层次靠加粗/放大，区块间虚线分割 */
.doc { font-family: "Arial", "Helvetica Neue", "Microsoft YaHei", sans-serif; color: #111; font-size: 12.5px; line-height: 1.5; }
.doc * { font-family: inherit; }

/* 表头：标题突出 → 公司名+地址 → 电话+邮箱 → 实线分割 */
.doc-head { text-align: center; padding-bottom: 4px; }
.doc-title { font-size: 26px; font-weight: 800; letter-spacing: 3px; text-transform: uppercase; margin: 0 0 6px; }
.doc-co { font-size: 14px; font-weight: 700; }
.doc-co2 { font-size: 12.5px; color: #333; margin-top: 2px; }
.doc .sep { color: #aaa; padding: 0 8px; }

/* 分割线：表头下方实线；各信息区块之间虚线 */
.doc-rule { border-top: 2px solid #111; height: 0; margin: 8px 0; }
.doc-rule.dashed { border-top: 1px dashed #999; height: 0; margin: 10px 0; }

/* 买卖双方信息区：左 = 收方；右 = PI No./日期 */
.doc-parties { display: flex; justify-content: space-between; gap: 24px; margin: 4px 0; }
.doc-parties .party-l { flex: 1; min-width: 0; font-size: 13px; line-height: 1.8; }
.doc-parties .party-r { text-align: right; font-size: 13px; line-height: 1.9; white-space: nowrap; }
.doc-sec-title { font-weight: 700; font-size: 12.5px; letter-spacing: .5px; text-transform: uppercase; margin-bottom: 3px; }
/* 收方信息每行都带字段说明（Buyer / Consi:、Address:、Contact:、Country:） */
.doc .party-row { display: flex; gap: 6px; align-items: flex-start; }
.doc .party-row .plbl { flex: 0 0 92px; font-weight: 700; }
.doc .party-row .pval { flex: 1; min-width: 0; word-break: break-word; }

/* ---------- 唛头（Shipping Mark）：A4 打印，1 页 2 箱 / 1 页 4 箱 ---------- */
@page { size: A4; margin: 8mm; }
#print-area.bare { padding: 0; }
/* 每一「页」= 一张 A4 的可打印区域：210-8*2=194mm 宽、297-8*2=281mm 高。
   用 grid 的 1fr 行把每张唛头平均撑满整页 —— 既不超出裁剪、下方也不留白。 */
/* 高度定为 275mm 而非 280mm：A4 可打印高度约 281mm，但 Chromium 在内容高度
   超过约 276mm 时会多吐一张空白页（边界四舍五入导致「下方空白」）。
   275mm 既几乎撑满整页，又稳稳落在安全区，彻底消除尾部空白页。 */
/* 宽度定为 191mm 而非 194mm（可打印区满宽）：卡片外框若正好压在可打印区边界，
   右侧框线会在四舍五入/裁剪时被抹掉（「唛头右侧没有框线」）。
   左右各留 1.5mm 安全余量即可稳稳画出四条边。 */
.mark-page { display: grid; gap: 4mm; width: 191mm; height: 275mm; box-sizing: border-box;
  background: #fff; }
.mark-page.per2 { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
.mark-page.per4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.mark-page + .mark-page { break-before: page; page-break-before: always; }
.mark-card { border: 1.2pt solid #000; display: flex; flex-direction: column; background: #fff;
  font-family: Arial, "Microsoft YaHei", sans-serif; color: #000; overflow: hidden;
  --mk-val-color: #0033cc;
  --mk-lab: 22pt; --mk-title: 36pt; --mk-val: 50pt; --mk-desc: 24pt; --mk-foot: 18pt; }
.mark-page.per4 .mark-card { --mk-lab: 11pt; --mk-title: 20pt; --mk-val: 25pt; --mk-desc: 14pt; --mk-foot: 10pt; }
/* 1 页 4 箱：卡片窄而高，让信息行自动撑满（垂直居中），避免行下方留一大块空白 */
.mark-page.per4 .mk-row { flex: 1 1 auto; align-items: center; }
.mark-page.per4 .mk-foot { margin-top: 0; }
/* 1 页 2 箱：卡片同样撑满整页，行高自适应分配，避免整页撑满后仍留空白 */
.mark-page.per2 .mk-row { flex: 1 1 auto; align-items: center; }
.mark-page.per2 .mk-foot { margin-top: 0; }
.mk-head { padding: 2.5mm 4mm 2mm; border-bottom: 1pt solid #000; }
.mk-lab { font-size: var(--mk-lab); font-weight: 700; }
.mk-title { font-size: var(--mk-title); font-weight: 800; text-align: center; line-height: 1.05;
  margin-top: 1mm; word-break: break-word; }
.mk-row { display: flex; gap: 3mm; align-items: baseline; padding: 2mm 4mm; border-bottom: 1pt solid #000; }
.mk-row .mk-lab { flex: 0 0 auto; }
/* 数值统一蓝色（标签保持黑色） */
.mk-row .mk-val { flex: 1; min-width: 0; font-size: var(--mk-val); font-weight: 700; color: var(--mk-val-color);
  line-height: 1.05; word-break: break-word; }
.mk-row .mk-val.mk-desc { font-size: var(--mk-desc); font-weight: 800; }
.mk-foot { margin-top: auto; text-align: center; font-size: var(--mk-foot); font-weight: 700;
  letter-spacing: 1.5px; padding: 3mm 2mm; }
/* 预览：灰底 + 白纸页 + 投影，一眼看清「一页 A4」的边界。
   .doc-wrap 在样式表更后面定义，用双类名提高优先级，避免底色/内边距被它覆盖。 */
.doc-wrap.mk-wrap { background: #e9edf2; padding: 12px 10px; display: flex;
  align-items: flex-start; justify-content: center; }
.mk-zoom { display: flex; flex-direction: column; align-items: center; gap: 16px; }
/* flex 子项默认会被压缩 —— 必须锁死尺寸，否则 A4 页高被压扁（预览显示不全的元凶） */
.mk-zoom .mark-page { flex: 0 0 auto; box-shadow: 0 1px 6px rgba(0,0,0,.22); }
/* 打印时唛头之间画虚线，方便沿中线裁剪 */
@media print {
  /* 宽度固定 191mm 并水平居中：避免卡片外框与可打印区右边界重合导致「右侧无框线」 */
  .mark-page { width: 191mm; margin-left: auto; margin-right: auto;
    height: 275mm; position: relative; box-shadow: none; }
  .mark-page.per2::after { content: ''; position: absolute; left: 0; right: 0; top: 50%;
    border-top: 0.6pt dashed #999; }
  .mark-page.per4::after { content: ''; position: absolute; left: 0; right: 0; top: 50%;
    border-top: 0.6pt dashed #999; }
  .mark-page.per4::before { content: ''; position: absolute; top: 0; bottom: 0; left: 50%;
    border-left: 0.6pt dashed #999; }
}

/* 区块（条款 / 备注 / 银行） */
.doc-block { font-size: 12.5px; line-height: 1.7; }
.doc-note { white-space: pre-wrap; font-size: 12.5px; line-height: 1.7; }
.moq-warn { color: #c0392b; font-size: 11px; font-weight: 700; }

/* 表格 */
.doc table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.doc th, .doc td { border: 1px solid #333; padding: 5px 7px; font-size: 12px; vertical-align: top; text-align: left; }
.doc th { background: #f2f2f2; text-align: center; font-weight: 700; }
.doc td.num, .doc th.num, .doc .num { text-align: right; }
.doc td.imgc { text-align: center; }
/* 图片必须严格限制在单元格内：max-width:100% 相对单元格内容框计算。
   旧写法 max-width:66px 是绝对值，A4 可打印宽约 735px，Image 列 8%≈59px，
   再减去左右各 7px 内边距只剩约 45px —— 66px 的图必然溢出到右侧单元格。
   预览窗口更宽（约 1030px，8%≈82px）所以看不出问题，只有导出 PDF 才错位。
   顺带解决：图随列宽自适应 + 水平居中，不再写死尺寸。 */
.doc td.imgc img { display: block; margin: 0 auto; max-width: 100%; max-height: 54px; width: auto; height: auto; }
/* PI 明细表（9 列）：固定列宽 + 允许断词。
   之前用浏览器自动布局，导出 PDF 时 Description 列被其他列挤压，
   颜色拆分「yellow-300pcs」被切成一两个字一行。colgroup 定宽后
   Description 稳定占约 1/4 页宽，每个颜色一行显示清晰。 */
.doc table.pi-tb { table-layout: fixed; }
.doc table.pi-tb td, .doc table.pi-tb th { word-break: break-word; }
.doc-tot { text-align: right; font-size: 13px; line-height: 1.9; margin: 6px 0; }
.doc-sign { margin-top: 26px; font-size: 12.5px; line-height: 1.9; }
.doc-meta { display: flex; flex-wrap: wrap; gap: 4px 30px; font-size: 13px; line-height: 1.9; }
.doc-meta div { white-space: nowrap; }
.doc-sign2 { display: flex; justify-content: space-between; gap: 24px; margin-top: 32px; }
.doc-sign2 .sign-col { flex: 1; max-width: 46%; }
.doc-sign2 .sign-line { border-top: 1px solid #333; padding-top: 5px; font-size: 12.5px; min-height: 28px; }
.doc-sign2 .sign-name { font-size: 12px; color: #555; margin-top: 2px; }

/* 单据预览 / 版式 */
.modal.wide { width: 1080px; }
.doc-wrap { background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: auto; max-height: 72vh; padding: 18px 22px; }

/* 状态标签 */
.st { display: inline-block; padding: 1px 9px; border-radius: 10px; font-size: 12px; }
.st-draft { background: #eef2f7; color: #475569; }
.st-sent { background: #e0f2fe; color: #075985; }
.st-ok { background: #dcfce7; color: #166534; }
.st-off { background: #fee2e2; color: #991b1b; }
.st-note { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-ok { display: inline-block; padding: 1px 9px; border-radius: 10px; font-size: 12px; background: #dcfce7; color: #166534; }
.chk-line { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 500; white-space: nowrap; cursor: pointer; }
.pos { color: #166534; font-weight: 700; }
.neg { color: #b91c1c; font-weight: 700; }
.supp-block { margin-top: 8px; }
.supp-row { display: flex; align-items: baseline; justify-content: flex-start; gap: 12px; padding: 4px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.supp-row:last-child { border-bottom: none; }
.supp-row b { font-variant-numeric: tabular-nums; }
.supp-note { font-size: 11px; color: var(--muted, #888); padding: 0 0 4px 12px; }
.st-thumb { text-align: center; vertical-align: middle; }
.st-thumb img { width: 46px; height: 46px; object-fit: contain; border: 1px solid var(--border); border-radius: 4px; background: #fff; cursor: zoom-in; }
/* 装箱单：产品图列 + 拼箱标记 + 颜色中英提示 */
.pack-grid .pl-img { text-align: center; vertical-align: middle; width: 62px; }
.pack-grid .pl-img img { width: 40px; height: 40px; object-fit: contain; border: 1px solid var(--border); border-radius: 4px; background: #fff; cursor: zoom-in; }
.pack-grid .pl-img .pl-noimg { display: inline-block; font-size: 11px; color: #b8c0cc; }
.pack-grid .pl-img .pk-img { display: block; margin: 2px auto 0; border: none; background: #eef2f7; color: #5b6b7e; border-radius: 4px; font-size: 11px; padding: 1px 6px; cursor: pointer; }
.pack-grid .pl-img .pk-img:hover { background: #dde6f0; }
.pack-grid tr.pl-mixed { background: #fff8f0; }
.pack-grid tr.pl-mixed td { border-top: 2px solid #f0a23c; }
.pl-mixed-tag { display: inline-block; margin-left: 6px; font-size: 11px; color: #c8761a; background: #fff0dc; border: 1px solid #f0c089; border-radius: 3px; padding: 0 5px; vertical-align: middle; }
.xhint { font-size: 11px; color: #8a94a6; line-height: 1.3; margin-top: 1px; }
.doc .pl-mixed-tag { font-size: 11px; color: #c8761a; }
/* 图片点击放大覆盖层（叠在弹窗之上） */
#imgzoom-root { display: none; position: fixed; inset: 0; z-index: 200; align-items: center; justify-content: center; background: rgba(15,23,42,.82); }
#imgzoom-root .imgzoom-mask { position: relative; max-width: 94vw; max-height: 94vh; display: flex; align-items: center; justify-content: center; }
#imgzoom-root img { max-width: 94vw; max-height: 94vh; object-fit: contain; background: #fff; border-radius: 6px; box-shadow: 0 10px 40px rgba(0,0,0,.4); }
#imgzoom-root .imgzoom-close { position: absolute; top: -16px; right: -16px; width: 34px; height: 34px; border: none; border-radius: 50%; background: #fff; color: #0f172a; font-size: 18px; line-height: 1; cursor: pointer; box-shadow: 0 2px 10px rgba(0,0,0,.3); }
.settle-breakdown { display: flex; gap: 28px; flex-wrap: wrap; margin-top: 14px; padding: 12px 16px; background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; line-height: 2; }
.bd-col { min-width: 280px; }
.bd-col .doc-sec-title { margin-bottom: 4px; }
.bd-col b { font-variant-numeric: tabular-nums; }
.bd-col input[type=number], .bd-col input:not([type]) { padding: 3px 6px; border: 1px solid var(--border); border-radius: 5px; font-size: 13px; }
select.stsel { padding: 3px 6px; font-size: 12px; }
td.ops { white-space: nowrap; }

/* 轻提示 */
.toast { position: fixed; left: 50%; bottom: 36px; transform: translateX(-50%) translateY(20px);
  background: #111827; color: #fff; padding: 9px 18px; border-radius: 8px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 99; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 批量导入弹窗 */
.imp h3 { margin: 4px 0 6px; font-size: 14px; }
.imp p { margin: 0 0 8px; }
.imp code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.imp-preview { margin: 8px 0 10px; max-height: 180px; overflow: auto; font-size: 13px; line-height: 1.7; border: 1px dashed #cbd5e1; border-radius: 6px; padding: 8px 10px; }
.imp input[type=file] { display: block; margin-bottom: 6px; }
.primary { background: var(--primary); color: #fff; }
.primary:disabled { opacity: .5; cursor: not-allowed; }

/* 报价单明细行贴图（与产品库图片隔离：存 quote_images，仅本次报价用） */
.imgcell { width: 56px; text-align: center; cursor: text; outline: none; vertical-align: middle; }
.imgcell:focus { box-shadow: inset 0 0 0 2px #4a90e2; }
.imgcell .qthumb { max-width: 48px; max-height: 38px; vertical-align: middle; border: 1px solid #ddd; border-radius: 3px; }

/* 报价单明细：拖动排序 */
th.move-col { width: 30px; padding: 4px 2px; text-align: center; color: #94a3b8; font-size: 11px; }
td.grip { width: 30px; text-align: center; cursor: grab; color: #94a3b8; user-select: none; font-size: 15px; line-height: 1; }
td.grip:hover { color: #475569; background: #f1f5f9; }
td.grip:active { cursor: grabbing; }
td.grip.drag-over { background: #dbeafe; box-shadow: inset 0 0 0 2px #4a90e2; color: #1d4ed8; }
#ibody tr { transition: background .12s; }

/* 条款 / 收款方式 设置页 */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs .tab { border: 1px solid #d7dee8; background: #fff; color: #334155; padding: 7px 14px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.tabs .tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.preset-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.preset-row { border: 1px solid #e2e8f0; border-radius: 8px; padding: 10px 12px; background: #fff; }
.preset-head { margin-bottom: 6px; }
.preset-content { margin: 0 0 8px; white-space: pre-wrap; word-break: break-word; font-family: var(--mono, Consolas, monospace); font-size: 12.5px; color: #334155; background: #f8fafc; border: 1px solid #eef2f7; border-radius: 6px; padding: 8px 10px; max-height: 220px; overflow: auto; }
.preset-ops { text-align: right; }
.tag { display: inline-block; margin-left: 6px; font-size: 11px; color: #b45309; background: #fef3c7; border-radius: 4px; padding: 1px 6px; vertical-align: middle; }
.fee-box { display: inline-flex; align-items: center; gap: 6px; }
.pay-note { margin-top: 6px; font-size: 12px; color: #b45309; background: #fffbeb; border: 1px solid #fde68a; border-radius: 6px; padding: 5px 8px; }
/* 付款安排（定金/尾款）——在 PI 上醒目标记，方便客户查看支付 */
.pay-sched { border: 2px solid #d97706; background: #fffaf0; border-radius: 8px; padding: 10px 12px; }
.pay-sched .doc-sec-title { color: #b45309; }
.pay-sched .pay-row { display: flex; justify-content: space-between; align-items: baseline; padding: 3px 0; font-size: 13px; }
.pay-sched .pay-row b { font-variant-numeric: tabular-nums; font-size: 15px; }
.pay-sched .pay-row.dep b { color: #b45309; }
.pay-sched .pay-row.bal b { color: #15803d; }
.pay-sched, .pay-sched .pay-row { break-inside: avoid; }

/* ===== 手机端适配（≤768px）：侧栏变抽屉、表格横滑、表单堆叠、弹窗近全屏 ===== */
.menu-btn { display: none; align-items: center; justify-content: center; background: #fff; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 11px; font-size: 18px; line-height: 1; }
.topbar-left { display: flex; align-items: center; gap: 10px; }
.nav-overlay { display: none; }

@media (max-width: 768px) {
  /* 侧边栏 → 左侧滑出抽屉 */
  .shell { display: block; }
  .sidebar { position: fixed; top: 0; left: 0; height: 100vh; height: 100dvh; width: 78vw; max-width: 280px;
    z-index: 45; transform: translateX(-100%); transition: transform .25s ease; overflow-y: auto;
    box-shadow: 2px 0 14px rgba(0,0,0,.28); padding-top: 10px; }
  body.nav-open .sidebar { transform: translateX(0); }
  .nav-overlay { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 40;
    opacity: 0; pointer-events: none; transition: opacity .2s ease; }
  body.nav-open .nav-overlay { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }

  /* 顶栏：显示菜单按钮，固化在顶部 */
  .menu-btn { display: inline-flex; }
  .topbar { position: sticky; top: 0; z-index: 35; padding: 0 12px; }
  .topbar .right { gap: 8px; }
  .uname { display: none; }

  /* 内容区：由 body 滚动，避免顶栏被推走 */
  .content { padding: 12px; overflow: visible; }
  .page-title { font-size: 16px; flex-wrap: wrap; }

  /* 表单：字段整行堆叠，输入框占满、字号 16px（防 iOS 聚焦缩放） */
  .row { flex-direction: column; gap: 8px; }
  .field { min-width: 0; flex: 1 1 100%; margin-bottom: 8px; }
  .field input, .field select, .field textarea { width: 100%; font-size: 16px; }
  .row .field input, .row .field select { font-size: 16px; }

  /* 表格：容器横向滚动，窄屏不再被压扁（单据表格 .doc table 不在此列，保持原样） */
  table.grid { display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table.grid th, table.grid td { white-space: normal; }
  table.grid input, table.grid select { font-size: 16px; }

  /* 弹窗近全屏，操作按钮吸底 */
  .modal { width: 100vw; height: 100dvh; max-width: none; max-height: none; border-radius: 0;
    padding: 14px 14px 18px; }
  .modal.wide { width: 100vw; }
  .modal-actions { position: sticky; bottom: 0; background: #fff; padding-top: 12px; margin-top: 10px;
    border-top: 1px solid var(--border); gap: 8px; flex-wrap: wrap; }
  .modal-actions button { flex: 1 1 auto; }

  /* 触摸友好：按钮加高；登录卡不超屏宽 */
  .toolbar button, .topbar .right button, .tabs .tab, .menu-btn { min-height: 38px; }
  .login-card { width: min(340px, 92vw); }

  /* 单据预览：去掉高度限制，随内容滚动 */
  .doc-wrap { max-height: none; padding: 12px; }
}
@media (max-width: 380px) {
  .topbar strong { display: none; }
  .content { padding: 10px; }
}
