:root {
  --nav: #001529;
  --primary: #1677ff;
  --primary-dark: #0958d9;
  --danger: #ff4d4f;
  --warn-bg: #fffbe6;
  --warn-border: #ffe58f;
  --bg: #f0f2f5;
  --card: #fff;
  --text: #1f1f1f;
  --muted: #8c8c8c;
  --border: #e5e6eb;
  --radius: 10px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); text-decoration: none; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--nav); color: #fff;
  height: 52px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; padding-top: env(safe-area-inset-top);
}
.brand { color: #fff; font-size: 17px; font-weight: 600; }
.brand-sub { font-size: 12px; color: rgba(255,255,255,.55); margin-left: 8px; font-weight: 400; }
.topbar-right { display: flex; gap: 6px; align-items: center; font-size: 14px; }
.topbar-right button { background: transparent; color: rgba(255,255,255,.85); border: 1px solid rgba(255,255,255,.25); border-radius: 6px; padding: 4px 10px; font-size: 13px; min-height: 44px; white-space: nowrap; }
.topbar-right .who { color: rgba(255,255,255,.75); font-size: 13px; white-space: nowrap; max-width: 6em; overflow: hidden; text-overflow: ellipsis; }
.brand { white-space: nowrap; }
@media (max-width: 420px) { .brand-sub { display: none; } }
.container { max-width: 980px; margin: 0 auto; padding: 12px 12px 160px; }
.loading { text-align: center; color: var(--muted); padding: 60px 0; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.card h2 { font-size: 16px; margin: 0 0 10px; display: flex; align-items: center; justify-content: space-between; gap: 4px 8px; flex-wrap: wrap; }
.card h2 .muted, .card h2 .lock { font-weight: 400; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1 1 auto; }

button, .btn {
  font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; color: var(--text); padding: 8px 14px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button: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: #ffccc7; }
.btn-text { border: none; background: none; color: var(--primary); padding: 4px 8px; min-height: 44px; }
.btn-big { min-height: 52px; font-size: 17px; font-weight: 600; width: 100%; }
.btn-block { width: 100%; }

input, select, textarea {
  font: inherit; width: 100%; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text); min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(22,119,255,.15); }
input[readonly] { background: #fafafa; color: #595959; }
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 13px; color: #595959; margin-bottom: 4px; }

/* 登录 */
.login-wrap { max-width: 380px; margin: 40px auto; }
.login-wrap h1 { text-align: center; font-size: 22px; margin: 0 0 4px; }
.login-wrap .sub { text-align: center; color: var(--muted); margin-bottom: 20px; }
.err { color: var(--danger); font-size: 14px; margin: 6px 0; }
.divider { text-align: center; color: var(--muted); font-size: 13px; margin: 14px 0; }

/* 列表 */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filters .kw { grid-column: 1 / -1; }
.sheet-card { display: block; color: inherit; }
.sheet-card .title { font-weight: 600; font-size: 16px; }
.sheet-card .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.sheet-card .total { font-weight: 600; color: var(--primary); white-space: nowrap; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 4px; background: #e6f4ff; color: var(--primary); font-size: 12px; margin-right: 6px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* 清单编辑 */
.info-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.info-table th { text-align: left; color: #595959; font-weight: 400; width: 84px; padding: 6px 0; vertical-align: top; }
.info-table td { padding: 6px 0; }
.lock { font-size: 12px; color: var(--muted); }
.header-fields { display: grid; grid-template-columns: 1fr; gap: 0 12px; margin-top: 8px; }
.sign-note { font-size: 14px; color: #1677ff; background: #e6f4ff; border-radius: 6px; padding: 6px 10px; margin: 6px 0 10px; }
.sign-groups { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 8px; }
.sign-group { border: 1px solid var(--border); border-radius: 8px; padding: 10px; }
.sign-title { font-weight: 600; color: #595959; margin-bottom: 6px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.sign-title .sign-count { font-weight: 400; }
label.sgn-field { display: block; min-width: 0; }
.sign-tip { margin-top: 4px; font-size: 13px; }
.sign-group textarea { min-height: 88px; resize: vertical; }
.presence { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.chip { background: #f6ffed; border: 1px solid #b7eb8f; color: #389e0d; border-radius: 12px; padding: 1px 10px; }
.chip.me { background: #e6f4ff; border-color: #91caff; color: var(--primary); }
.banner { background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.banner .row { margin-top: 6px; }

.item { border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 10px; position: relative; }
.item-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.item-no { font-weight: 600; color: #595959; }
.item-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.item-grid .full { grid-column: 1 / -1; }
.item-grid label > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.item-amount { margin-top: 8px; text-align: right; font-size: 14px; }
.item-amount b { color: var(--primary); }
.none { color: var(--muted); }

.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; background: #fff;
  border-top: 1px solid var(--border); padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}
.bottom-inner { max-width: 980px; margin: 0 auto; display: flex; gap: 8px; align-items: center; }
.bottom-total { flex: 1; font-size: 14px; }
.bottom-total b { font-size: 18px; color: var(--primary); }
.dirty { color: #d46b08; font-size: 12px; display: block; }

/* 照片 */
.photo-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.photo-actions label { cursor: pointer; }
.photo-actions input[type=file] { display: none; }
.photo-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.photo { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fafafa; }
.photo img { width: 100%; height: 130px; object-fit: cover; display: block; cursor: zoom-in; }
.photo .cap { padding: 6px; }
.photo .cap input { min-height: 44px; font-size: 13px; padding: 5px 8px; }
.photo .ops { display: flex; justify-content: space-between; align-items: center; padding: 0 6px 6px; font-size: 12px; color: var(--muted); }

/* 弹层 */
.mask { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; max-height: 86vh; overflow: auto; padding: 16px; }
.modal h3 { margin: 0 0 10px; font-size: 17px; }
.modal .actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.diff-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.diff-table th, .diff-table td { border: 1px solid var(--border); padding: 4px 6px; text-align: left; }
.diff-table tr.changed td { background: #fff7e6; }
.lightbox { background: rgba(0,0,0,.92); flex-direction: column; }
.lightbox img { max-width: 100%; max-height: 80vh; object-fit: contain; }
.lightbox .lb-cap { color: #fff; margin-top: 10px; text-align: center; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: rgba(0,0,0,.8); color: #fff; padding: 8px 16px; border-radius: 20px; z-index: 60; font-size: 14px; max-width: 86vw; text-align: center; }

/* 用户管理 */
.user-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.user-row:last-child { border-bottom: none; }
.badge-off { color: var(--danger); font-size: 12px; }

/* ---- #213.003 ---- */
.status { display: inline-block; padding: 1px 8px; border-radius: 4px; font-size: 12px; margin-right: 6px; font-weight: 400; }
.status-draft { background: #fff7e6; color: #d46b08; }
.status-submitted { background: #e6f4ff; color: var(--primary); }
.status-archived { background: #f0f0f0; color: #595959; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; overflow-x: auto; }
.tab { flex: 1 1 0; white-space: nowrap; padding: 8px 4px; }
.tab.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.project-pick { display: block; width: 100%; text-align: left; margin-bottom: 10px; padding: 14px; border-radius: 10px; }
.project-pick, .project-pick div { min-width: 0; overflow-wrap: anywhere; word-break: break-word; white-space: normal; }
.project-pick .pp-name { font-weight: 600; font-size: 16px; margin-bottom: 4px; white-space: normal; }
.check { cursor: pointer; min-height: 44px; }
.check input { flex: 0 0 auto; width: 22px !important; height: 22px; }
.field.invalid input, label.invalid input, .field.invalid select, label.invalid select, label.invalid textarea { border-color: var(--danger); background: #fff2f0; }
.cat-card.invalid { border-color: var(--danger); background: #fff2f0; }
.banner.problems { background: #fff2f0; border-color: #ffccc7; }
.banner.problems .btn-text { color: var(--danger); text-align: left; min-height: 36px; padding: 2px 4px; }
.events { margin-top: 8px; font-size: 13px; }
.events summary { cursor: pointer; min-height: 32px; display: flex; align-items: center; color: var(--muted); }

.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cat-card { border: 1px solid var(--border); border-radius: 8px; padding: 8px; }
.cat-card.ok { border-color: #b7eb8f; background: #f6ffed; }
.cat-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.cat-n { font-size: 12px; color: var(--danger); }
.cat-n.ok { color: #389e0d; }
.cat-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.cat-btns .btn { padding: 4px 6px; cursor: pointer; }
.cat-btns input[type=file] { display: none; }
.att-page { border: 1px dashed #bfbfbf; border-radius: 8px; padding: 8px; margin-bottom: 12px; background: #fafafa; }
.att-page-title { font-size: 13px; color: #595959; margin-bottom: 6px; font-weight: 600; }
.att-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ptile { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 6px; min-width: 0; }
.pimg { aspect-ratio: 6.9 / 8.0; background: #f0f0f0; border-radius: 4px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.pimg img { max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in; display: block; }
.plabel { font-size: 12px; color: #595959; margin: 4px 0; }
.ptile .cap input { min-height: 44px; font-size: 13px; padding: 5px 8px; }
.pbtns { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 6px 0; }
.pbtns button { padding: 4px 2px; font-size: 13px; }
.pfield { display: block; margin-bottom: 6px; }
.pfield span { display: block; font-size: 12px; color: var(--muted); }
.pfield select { font-size: 13px; padding: 4px 6px; }
.ptile .btn-danger { font-size: 13px; }
.bar-btns { display: flex; gap: 6px; }
.bar-btns button { padding: 8px 10px; white-space: nowrap; }

.modal.wide { max-width: 760px; }
/* #213.004 预览弹层：顶部固定栏（标题+按钮）+ 单独滚动的正文；宽屏加宽到 min(1180px, 96vw)；高度跟随视口（dvh） */
.modal.top-actions { display: flex; flex-direction: column; padding: 0; overflow: hidden; height: calc(100vh - 32px); height: calc(100dvh - 32px); max-height: none; }
.modal.top-actions.wide { max-width: min(1180px, 96vw); }
.modal-head { flex: 0 0 auto; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; padding: 12px 16px; background: #fff; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; }
.modal-head .actions { flex-direction: row; margin-top: 0; gap: 8px; }
.modal-head .actions button { min-height: 44px; padding: 8px 22px; white-space: nowrap; }
.modal-body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 12px 16px 16px; scrollbar-gutter: stable; background: #f2f3f5; }
.preview-note { margin: 0 0 8px; font-size: 13px; line-height: 1.5; }
.preview-wrap { overflow-x: auto; }
.paper-holder { margin: 0 auto 12px; border: 1px solid #d9d9d9; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.12); overflow: hidden; }
.paper { transform-origin: top left; padding: 20px 26px 14px; font-family: "SimSun", "宋体", "Songti SC", serif; font-size: 12px; color: #000; background: #fff; }
.paper-title { text-align: center; font-size: 18px; margin-bottom: 6px; font-family: "SimSun", "宋体", "Songti SC", serif; }
.ptable { width: 100%; border-collapse: collapse; table-layout: fixed; }
.ptable td { border: 1px solid #000; padding: 3px 4px; vertical-align: middle; word-break: break-all; font-size: 12px; }
.ptable td.lab { text-align: center; }
.ptable td.center { text-align: center; }
.ptable td.vert { writing-mode: vertical-rl; letter-spacing: 8px; text-align: center; font-size: 13px; }
.ptable tr.itemrow td { height: 22px; }
.ptable tr.signrow td { height: 70px; vertical-align: top; font-size: 11px; padding: 4px 6px; }
.sline { white-space: pre-wrap; min-height: 12px; line-height: 12px; }
.attach-label { margin-top: 14px; font-size: 12px; }
.attach-box { border: 1px solid #000; margin-top: 2px; min-height: 40px; padding: 0; }
.attach-box.empty { min-height: 60px; }
.att-prev-grid { display: grid; grid-template-columns: 1fr 1fr; }
.att-cell { aspect-ratio: 7.33 / 10; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 4px; min-width: 0; min-height: 0; overflow: hidden; } /* 复核修正：竖图不再把格子撑高（否则图片加载后纸面底边被裁掉） */
.att-img { flex: 1 1 auto; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; }
.att-img img { max-width: 94%; max-height: 100%; object-fit: contain; }
.att-cap { font-size: 9px; text-align: center; margin-top: 2px; word-break: break-all; }

/* ---- #213.005 现场服务记录单 ---- */
.svc-grid { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
.svc-cats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.svc-cat { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; margin: 0; background: #fff; }
.svc-calc { margin-top: 6px; font-size: 14px; }
.svc-calc b { color: var(--primary); font-weight: 600; }
.svc-calc b.none { color: var(--muted); font-weight: 400; }
.svc-photos .pimg { aspect-ratio: 4 / 3; }
.svc-table td.lab { white-space: normal; word-break: normal; padding: 3px 1px; font-size: 11px; }
.svc-table td { vertical-align: top; }
.svc-table td.lab { vertical-align: middle; }
.svc-table tr.svc-photo-row td { padding: 0; }
.svc-photo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 3px; }
.svc-photo-cell { background: #fff; display: flex; align-items: center; justify-content: center; overflow: hidden; min-width: 0; }
.svc-photo-cell img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.svc-table tr.svc-sum td { height: 70px; }
.svc-table tr.signrow td { height: 40px; }

@media (max-width: 719px) {
  .modal { max-height: 92vh; padding: 14px 12px; }
  .mask { padding: 8px; }
  .modal.wide { max-width: none; }
  .modal.top-actions { height: calc(100vh - 16px); height: calc(100dvh - 16px); padding: 0; }
  .modal-head { padding: 10px 12px; }
  .modal-head h3 { flex: 1 1 100%; font-size: 16px; }
  .modal-head .actions { flex: 1 1 100%; }
  .modal-head .actions button { flex: 1 1 0; padding: 8px 10px; }
  .modal-body { padding: 10px 8px 14px; }
  .bottom-inner { flex-direction: column; align-items: stretch; gap: 6px; }
  .bottom-total { display: flex; align-items: center; justify-content: space-between; }
  .bar-btns button { flex: 1 1 0; }
  .cat-btns .btn { min-height: 44px; }
}
@media (min-width: 720px) {
  .svc-grid { grid-template-columns: 1fr 1fr; }
  .svc-cats { grid-template-columns: repeat(6, 1fr); }
  .item-grid.parts { grid-template-columns: 3fr 1fr 1fr 1.4fr; }
  .att-grid { max-width: 560px; }
  .cat-grid { grid-template-columns: repeat(4, 1fr); }
  .filters { grid-template-columns: 160px 140px 1fr auto; }
  .filters .kw { grid-column: auto; }
  .header-fields { grid-template-columns: 1fr 1fr; }
  .sign-groups { grid-template-columns: 1fr; }
  .item-grid { grid-template-columns: 2.2fr 1.6fr .8fr .9fr 1.1fr; }
  .item-grid .full { grid-column: auto; }
  .photo-grid { grid-template-columns: repeat(4, 1fr); }
  .photo-actions { grid-template-columns: 220px 220px; }
}
@media (min-width: 900px) {
  /* #213.004 第二轮：工程信息的 施工单位 / 项目经理 / 工程地点 / 施工日期 在宽屏上并排一行（手机与窄屏仍上下排） */
  .header-fields { grid-template-columns: 1.8fr 1fr 1.1fr 1.3fr; }
}

/* ---- #213.004 第二轮：预览按 Word 真实尺寸画（96dpi，表格 600.5px，10.5 磅 = 14px，每行 20.8px），再整体缩放 ---- */
.paper.word { padding: 14px 17px 8px; font-size: 14px; line-height: 20.8px; }
.paper.word .paper-title { font-family: "SimHei", "Heiti SC", "STHeiti", "Microsoft YaHei", sans-serif; font-size: 20px; line-height: 24px; margin: 0 0 1px; }
.wtable { border-collapse: collapse; table-layout: fixed; margin: 0; }
.wtable td { border: 1px solid #000; padding: 0 7.2px; vertical-align: middle; overflow-wrap: anywhere; font-size: 14px; line-height: 20.8px; }
.wtable td.lab { text-align: center; }
.wtable td.vert { text-align: center; padding: 0 2px; }
.wtable .wp { min-height: 20.8px; }
.wtable td.signcell { vertical-align: middle; padding: 0 7.2px; }
.sp { min-height: 20.8px; line-height: 20.8px; }
.sp.fixed { white-space: nowrap; }
.sp.opinion { white-space: pre-wrap; overflow-wrap: anywhere; }
.sgap { display: inline-block; height: 1px; }
.paper.word .attach-label { font-size: 14px; }

/* #213.005 第三轮：现场服务记录单预览按 Word 真实版式（字号、行高、列宽、行高、照片图位都由接口给出，见 service.js） */
.paper.word.svcw { padding: 14px 17px 8px; line-height: normal; }
.paper.svcw .wsvc { font-family: "SimSun", "宋体", "Songti SC", "STSong", serif; color: #000; }
.paper.svcw .wsvc-title { font-family: "SimHei", "黑体", "Heiti SC", "STHeiti", sans-serif; text-align: center; margin: 0; }
.paper.svcw .ptable td { font-size: inherit; line-height: inherit; border: 1px solid #000; word-break: normal; overflow-wrap: anywhere; }
.paper.svcw .wsp { white-space: pre-wrap; min-height: 1em; }
.paper.svcw .svc-photo-grid.wphoto { display: block; position: relative; padding: 0; gap: 0; }
.paper.svcw .svc-photo-cell { position: absolute; display: flex; align-items: center; justify-content: center; overflow: visible; aspect-ratio: auto; }
.paper.svcw .svc-photo-cell img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* #213.006 分享 */
body.share-mode .brand { pointer-events: none; }
.share-url { width: 100%; font-size: 13px; background: #fafafa; }
.share-meta { display: grid; gap: 4px; margin: 6px 0 4px; font-size: 14px; }
.share-meta b { color: var(--primary); }
.share-head h2 { margin: 0 0 6px; justify-content: flex-start; flex-wrap: wrap; gap: 6px; }
.share-head .row { align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.share-dl { white-space: nowrap; }
.share-paper { padding: 8px; overflow: hidden; }
.share-dead { text-align: center; padding: 32px 16px; }
.share-dead .share-msg { font-size: 16px; color: #d4380d; }
.share-loading { text-align: center; color: #8c8c8c; }
.share-row .grow { min-width: 0; }
.share-st { display: inline-block; padding: 1px 8px; border-radius: 4px; font-size: 12px; margin-right: 6px; }
.share-st-on { background: #f6ffed; color: #389e0d; }
.share-st-off { background: #f0f0f0; color: #8c8c8c; }
