* { box-sizing: border-box; }
:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --ink: #101828;
  --muted: #667085;
  --line: #e4e7ec;
  --primary: #1465d8;
  --primary-dark: #0f4fa8;
  --primary-soft: #eaf2fe;
  --success: #0f7a5a;
  --success-soft: #e6f6f0;
  --warn: #b45309;
  --warn-soft: #fff4e5;
  --danger: #c92a2a;
  --danger-soft: #fdecec;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
}
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p { margin: 0; }
button { font-family: inherit; }
.hidden { display: none !important; }

/* ---------- 通用控件 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 9px 14px; border-radius: 9px; font-size: 14px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .06s;
  min-height: 38px; white-space: nowrap;
}
.btn:hover { background: #f9fafb; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.success:hover { filter: brightness(.94); }
.btn.danger { color: var(--danger); border-color: #f3c9c9; background: #fff; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { background: #f8fafc; }
.btn.sm { padding: 5px 10px; min-height: 30px; font-size: 13px; border-radius: 7px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.link { background: none; border: none; color: var(--primary); cursor: pointer; padding: 0; font-size: 13px; }
.link:hover { text-decoration: underline; }

input, select, textarea {
  font-family: inherit; font-size: 14px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; background: #fff;
  outline: none; width: 100%; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { resize: vertical; min-height: 70px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }

.tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; background: #f2f4f7; color: var(--muted); white-space: nowrap; font-weight: 500;
}
.tag.ok { background: var(--success-soft); color: var(--success); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.info { background: var(--primary-soft); color: var(--primary-dark); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- 登录 ---------- */
.login-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border-radius: 16px; padding: 28px 24px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.login-card .brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.brand-mark { width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(135deg, var(--primary), #3b8bf0); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 700; }
.login-card h1 { font-size: 18px; font-weight: 600; }
.login-card p { font-size: 12px; color: var(--muted); margin-top: 2px; }
.login-card label { display: block; margin-bottom: 14px; font-size: 12px; color: var(--muted); }
.login-card label input { margin-top: 5px; font-size: 15px; padding: 11px 12px; }
.login-msg { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- PDA ---------- */
body.pda { font-size: 16px; }
.pda-top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  background: #0b3f86; color: #fff; padding: 12px 14px; padding-top: calc(12px + env(safe-area-inset-top));
}
.pda-top .pda-title { flex: 1; font-size: 17px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pda-top .top-btn { background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.22); color: #fff; border-radius: 8px; padding: 7px 11px; font-size: 14px; cursor: pointer; }
.pda-top .top-btn:active { background: rgba(255,255,255,.28); }
.pda-main { padding: 14px 14px calc(28px + env(safe-area-inset-bottom)); max-width: 720px; margin: 0 auto; }
.pda-user { font-size: 13px; color: var(--muted); margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; }

.task-cards { display: flex; flex-direction: column; gap: 12px; }
.task-card { padding: 16px; cursor: pointer; }
.task-card:active { background: #fafcff; }
.task-card h3 { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.task-card .meta { font-size: 13px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.progress { display: flex; align-items: center; gap: 10px; }
.progress .bar { flex: 1; height: 8px; background: #edf0f4; border-radius: 99px; overflow: hidden; }
.progress .bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), #4d97ef); border-radius: 99px; transition: width .3s; }
.progress .num { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; font-size: 14px; }

.task-head { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.task-head .tname { font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.task-head .tmeta { font-size: 13px; color: var(--muted); margin-bottom: 12px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.scan-box { display: flex; gap: 10px; margin-bottom: 10px; }
.scan-box input {
  font-size: 19px; padding: 15px 14px; letter-spacing: .5px; font-variant-numeric: tabular-nums;
  border: 2px solid var(--primary); background: #fff;
}
.scan-box .btn { min-height: 56px; padding: 0 20px; font-size: 16px; }
.scan-hint { font-size: 13px; color: var(--muted); margin-bottom: 14px; padding-left: 2px; min-height: 18px; }
.scan-hint.err { color: var(--danger); font-weight: 500; }
.voice-toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); margin: -4px 0 14px 2px; user-select: none; }
.voice-toggle input { width: 18px; height: 18px; accent-color: var(--primary); margin: 0; }
.alert { padding: 14px; border-radius: var(--radius); font-size: 15px; margin-bottom: 14px; }
.alert.err { background: var(--danger-soft); color: var(--danger); border: 1px solid #f6caca; }

.result { padding: 16px; }
.res-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; padding-bottom: 12px; border-bottom: 1px dashed var(--line); }
.res-name { font-size: 18px; font-weight: 600; line-height: 1.35; }
.res-sub { font-size: 13px; color: var(--muted); margin-top: 5px; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; margin: 14px 0; }
.kv .k { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.kv .v { font-size: 15px; word-break: break-all; }
.kv .full { grid-column: 1 / -1; }
.res-state { font-size: 13px; color: var(--muted); background: #f8fafc; border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }
.res-state b { color: var(--ink); font-weight: 600; }
.pda-actions { display: grid; gap: 10px; }
.pda-actions .row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pda-actions .btn { min-height: 52px; font-size: 16px; border-radius: 11px; }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 13px; color: var(--muted); cursor: pointer; }
.chip.on { background: var(--primary-soft); border-color: #b9d5fb; color: var(--primary-dark); }

/* PDA 模式切换与台账 */
.seg { display: flex; background: #e5eaf1; border-radius: 11px; padding: 4px; gap: 4px; margin-bottom: 14px; }
.seg button { flex: 1; border: none; background: none; padding: 10px; border-radius: 8px; font-size: 15px; color: var(--muted); cursor: pointer; }
.seg button.on { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(16, 24, 40, .14); }
.ledger-search { margin-bottom: 8px; }
.ledger-search input { font-size: 15px; padding: 11px 12px; border-width: 1px; }
.ledger-search .btn { min-height: 44px; }
.ledger-count { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; padding-left: 2px; }
.ledger-list { display: flex; flex-direction: column; gap: 8px; padding-bottom: 20px; }
.ledger-row { display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; cursor: pointer; }
.ledger-row:active { background: #f7faff; }
.ledger-row .l-main { flex: 1; min-width: 0; }
.ledger-row .l-name { font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ledger-row .l-sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ledger-row .tag { flex-shrink: 0; }
.ledger-row .l-marks { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.ring-check { width: 36px; height: 36px; border-radius: 50%; border: 2.5px solid #16a34a; background: #f0fdf4; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ring-check::after { content: ''; width: 17px; height: 9px; border-left: 3px solid #16a34a; border-bottom: 3px solid #16a34a; transform: rotate(-45deg) translate(1px, -2px); }

/* 盘点成功大赞 */
.praise {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 1000;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: rgba(255, 255, 255, .93);
}
.praise-thumb { font-size: 120px; line-height: 1; animation: praisePop .55s cubic-bezier(.2, 1.5, .4, 1); }
.praise-text { font-size: 21px; font-weight: 700; color: var(--success); margin-top: 16px; }
.praise-sub { font-size: 14px; color: var(--muted); }
@keyframes praisePop { 0% { transform: scale(.2); opacity: 0; } 60% { transform: scale(1.18); } 100% { transform: scale(1); opacity: 1; } }

/* PDA 编辑弹框 */
.pda-modal { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 900; display: flex; align-items: flex-end; justify-content: center; }
.pda-modal-mask { position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: rgba(16, 24, 40, .45); animation: pdaFade .16s ease; }
.pda-modal-panel {
  position: relative; width: 100%; max-width: 720px; background: #fff;
  border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: 86vh; overflow: auto; box-shadow: 0 -8px 30px rgba(16, 24, 40, .22);
  animation: pdaSlideUp .2s ease;
}
.pda-modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.pda-modal-head h4 { font-size: 17px; font-weight: 600; }
.pda-modal-label { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.pda-modal-panel .chip-row { max-height: 156px; overflow: auto; margin-bottom: 12px; }
.pda-modal-panel .chip { font-size: 14px; padding: 8px 13px; }
.pda-modal-panel input { font-size: 17px; padding: 12px 13px; }
.pda-modal-panel textarea { font-size: 16px; min-height: 96px; }
.pda-modal-foot { display: flex; gap: 10px; margin-top: 14px; }
.pda-modal-foot .btn { flex: 1; min-height: 48px; font-size: 16px; border-radius: 11px; }
.result-panel .card.result { border: 0; box-shadow: none; padding: 0; background: transparent; }
.result-panel .res-head { padding-top: 2px; }
@keyframes pdaFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pdaSlideUp { from { transform: translateY(18px); opacity: .6; } to { transform: none; opacity: 1; } }

.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translate(-50%, 16px);
  background: #101828; color: #fff; padding: 12px 20px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 999; max-width: 86vw;
  box-shadow: 0 8px 24px rgba(0,0,0,.24);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); }

/* ---------- 后台 ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 210px; flex-shrink: 0; background: #0b2e57; color: #cfe0f5;
  display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh;
}
.sidebar .logo { font-size: 16px; font-weight: 700; color: #fff; padding: 6px 10px 20px; display: flex; align-items: center; gap: 9px; }
.sidebar .logo i { width: 26px; height: 26px; border-radius: 7px; background: linear-gradient(135deg,#2f7fe0,#54a3ff); display: inline-block; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { padding: 10px 12px; border-radius: 8px; color: #cfe0f5; text-decoration: none; font-size: 14px; cursor: pointer; }
.sidebar nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar nav a.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.side-foot { margin-top: auto; padding: 10px; font-size: 12px; color: #a9c4e2; display: flex; flex-direction: column; gap: 8px; }
.side-foot .who { color: #fff; font-size: 13px; font-weight: 500; }
.side-foot .link { color: #a9c4e2; text-align: left; }
.side-foot .link:hover { color: #fff; }

.main { flex: 1; min-width: 0; padding: 22px 26px 40px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { font-size: 20px; font-weight: 600; }
.page-head p { font-size: 13px; color: var(--muted); margin-top: 4px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { padding: 16px 18px; }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 28px; font-weight: 650; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 4px; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; }
.toolbar .grow { flex: 1; min-width: 160px; }
.toolbar .spacer { flex: 1; }

.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: #f8fafc; color: var(--muted); font-weight: 500; font-size: 12.5px; position: sticky; top: 0; z-index: 1; }
tbody tr:hover { background: #fafcff; }
tbody tr:last-child td { border-bottom: none; }
td.num { font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 180px; max-width: 320px; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 14px; font-size: 13px; color: var(--muted); }

.panel { padding: 18px; margin-bottom: 18px; }
.panel h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.panel .sub { font-size: 12.5px; color: var(--muted); margin-bottom: 14px; }
.import-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.import-row label { flex: 1; min-width: 200px; }
.import-row label > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.import-row input[type=file] { padding: 7px; background: #fbfcfe; }

.modal-mask { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 800; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.28); }
.modal.wide { max-width: 900px; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal header h3 { font-size: 16px; font-weight: 600; }
.modal .body { padding: 18px 20px; overflow: auto; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
.close-x { background: none; border: none; font-size: 20px; color: var(--muted); cursor: pointer; line-height: 1; }

@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; flex-direction: row; align-items: center; padding: 10px; overflow-x: auto; }
  .sidebar .logo { padding: 0 12px 0 4px; }
  .sidebar nav { flex-direction: row; gap: 4px; }
  .sidebar nav a { padding: 8px 12px; white-space: nowrap; }
  .side-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; padding: 0 4px; }
  .main { padding: 16px 14px 40px; }
  .form-grid { grid-template-columns: 1fr; }
  .modal { max-height: 92vh; }
}
