* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #e3e6ea;
  --line2: #eef0f3;
  --text: #16191d;
  --text2: #5c6470;
  --text3: #8b939f;
  --primary: #1f5fd8;
  --primary-d: #17489f;
  --primary-l: #eaf1fd;
  --ok: #1a7f4b;
  --ok-l: #e8f6ee;
  --warn: #a86a00;
  --warn-l: #fdf5e3;
  --danger: #c0322f;
  --danger-l: #fdeceb;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: var(--primary); text-decoration: none; }

.layout { display: flex; min-height: 100vh; }
.sidebar { width: 208px; background: #14181f; color: #ccd2db; flex-shrink: 0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 20px 18px 18px; border-bottom: 1px solid #232a34; }
.brand h1 { font-size: 15px; font-weight: 600; color: #fff; letter-spacing: .3px; }
.brand p { font-size: 11px; color: #6f7885; margin-top: 3px; letter-spacing: .5px; }
.nav { padding: 10px 8px; flex: 1; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 6px; color: #b6bdc7; font-size: 13.5px; margin-bottom: 2px; transition: .12s; }
.nav a:hover { background: #1d232c; color: #fff; }
.nav a.on { background: var(--primary); color: #fff; font-weight: 500; }
.nav .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .55; }
.side-foot { padding: 12px 14px; border-top: 1px solid #232a34; font-size: 12px; color: #6f7885; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 56px; background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; position: sticky; top: 0; z-index: 20; }
.topbar h2 { font-size: 16px; font-weight: 600; }
.topbar .who { font-size: 12.5px; color: var(--text2); display: flex; align-items: center; gap: 8px; white-space: nowrap; flex-shrink: 0; }
.who input { border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; width: 88px; background: #fbfbfc; }
.view { padding: 20px; flex: 1; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { font-size: 12px; color: var(--text2); margin-bottom: 6px; }
.stat .v { font-size: 24px; font-weight: 600; letter-spacing: -.5px; }
.stat .v small { font-size: 12px; font-weight: 400; color: var(--text3); margin-left: 3px; }
.stat.hl .v { color: var(--primary); }
.stat.warn .v { color: var(--warn); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden; }
.card-h { padding: 13px 16px; border-bottom: 1px solid var(--line2); display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card-h h3 { font-size: 14px; font-weight: 600; }
.card-h .sub { font-size: 12px; color: var(--text3); font-weight: 400; margin-left: 6px; }
.card-b { padding: 16px; }
.card-b.flush { padding: 0; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar input[type=text], .toolbar input[type=date], .toolbar select { height: 32px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 500; color: var(--text2); background: #fafbfc; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; font-size: 12.5px; }
td { padding: 9px 12px; border-bottom: 1px solid var(--line2); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfd; }
tfoot td { border-top: 1px solid var(--line); border-bottom: 0; background: #fafbfc; font-size: 12.5px; }
input:disabled, select:disabled { background: #f6f7f9; color: var(--text3); cursor: not-allowed; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--text3); }
.strong { font-weight: 600; }

input[type=text], input[type=number], input[type=date], select, textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; background: #fff; color: var(--text); width: 100%; outline: none; transition: .12s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31,95,216,.1); }
input:disabled, select:disabled { background: #f5f6f7; color: var(--text3); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 5px; height: 32px; padding: 0 13px; border-radius: 6px; border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer; font-size: 13px; white-space: nowrap; transition: .12s; }
.btn:hover { border-color: #ccd2da; background: #fafbfc; }
.btn.pri { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 500; }
.btn.pri:hover { background: var(--primary-d); border-color: var(--primary-d); }
.btn.danger { color: var(--danger); border-color: #f0cdcb; }
.btn.danger:hover { background: var(--danger-l); }
.btn.sm { height: 26px; padding: 0 9px; font-size: 12.5px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-link { background: none; border: 0; color: var(--primary); cursor: pointer; padding: 0 4px; font-size: 13px; }
.btn-link.danger { color: var(--danger); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 500; white-space: nowrap; }
.badge.gray { background: #f0f1f3; color: var(--text2); }
.badge.blue { background: var(--primary-l); color: var(--primary-d); }
.badge.green { background: var(--ok-l); color: var(--ok); }
.badge.amber { background: var(--warn-l); color: var(--warn); }
.badge.red { background: var(--danger-l); color: var(--danger); }

.empty { padding: 44px 20px; text-align: center; color: var(--text3); font-size: 13px; }
.empty b { display: block; color: var(--text2); font-size: 14px; margin-bottom: 6px; font-weight: 500; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row { display: grid; grid-template-columns: 96px 1fr; gap: 10px; align-items: center; margin-bottom: 12px; }
.form-row > label { font-size: 13px; color: var(--text2); text-align: right; }
.form-row.req > label::after { content: " *"; color: var(--danger); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px 18px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-size: 12.5px; color: var(--text2); }
.field.req > label::after { content: " *"; color: var(--danger); }
.hint { font-size: 11.5px; color: var(--text3); margin-top: 4px; line-height: 1.5; }

.overlay { position: fixed; inset: 0; background: rgba(16,20,26,.45); display: none; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.overlay.on { display: flex; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 620px; max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0,0,0,.18); }
.modal.wide { max-width: 860px; }
.modal-h { padding: 15px 18px; border-bottom: 1px solid var(--line2); display: flex; justify-content: space-between; align-items: center; }
.modal-h h3 { font-size: 15px; font-weight: 600; }
.modal-h .x { background: none; border: 0; font-size: 20px; color: var(--text3); cursor: pointer; line-height: 1; padding: 0 4px; }
.modal-b { padding: 18px; overflow-y: auto; flex: 1; }
.modal-f { padding: 12px 18px; border-top: 1px solid var(--line2); display: flex; justify-content: flex-end; gap: 8px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px); background: #1c222b; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13px; z-index: 200; opacity: 0; transition: .25s; max-width: 90vw; }
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: #a32724; }

.line-list { display: flex; flex-direction: column; gap: 8px; }
.line-item { display: grid; grid-template-columns: 1fr 84px 96px 28px; gap: 8px; align-items: center; }
.line-item .del { background: none; border: 0; color: var(--text3); cursor: pointer; font-size: 16px; }
.line-item .del:hover { color: var(--danger); }
.line-head { display: grid; grid-template-columns: 1fr 84px 96px 28px; gap: 8px; font-size: 12px; color: var(--text3); padding-bottom: 2px; }

.mobilebar { display: none; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 9px 14px; font-size: 13.5px; color: var(--text2); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }

.tree { font-size: 13px; }
.tree-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line2); }
.tree-row .lvl { color: var(--text3); font-size: 11px; background: #f2f4f6; border-radius: 3px; padding: 1px 5px; }
.tree-indent-2 { padding-left: 22px; }
.tree-indent-3 { padding-left: 44px; }

@media (max-width: 820px) {
  .sidebar { display: none; }
  .layout { flex-direction: column; }
  .view { padding: 12px; padding-bottom: 76px; }
  .topbar { padding: 0 14px; height: 52px; }
  .topbar h2 { font-size: 15px; }
  .grid2 { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 78px 1fr; }
  .card-b { padding: 12px; }
  .mobilebar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--line); z-index: 50; padding: 4px 0 max(4px, env(safe-area-inset-bottom)); overflow-x: auto; }
  .mobilebar a { flex: 0 0 auto; min-width: 62px; text-align: center; padding: 6px 2px; font-size: 10.5px; color: var(--text3); white-space: nowrap; }
  .mobilebar a.on { color: var(--primary); font-weight: 500; }
  .mobilebar .ico { display: block; font-size: 15px; line-height: 1.2; }
  .hide-m { display: none; }
  .line-item, .line-head { grid-template-columns: 1fr 68px 84px 24px; }
  table { font-size: 12.5px; }
  th, td { padding: 8px 9px; }
  .scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .scroll-x::-webkit-scrollbar { height: 4px; }
  .scroll-x::-webkit-scrollbar-thumb { background: #d6dae0; border-radius: 2px; }
}

/* ===== 二期：工序链 ===== */
.opchain { display: flex; align-items: flex-start; gap: 6px; flex-wrap: wrap; }
.opnode { display: flex; flex-direction: column; align-items: center; min-width: 84px; text-align: center; }
.opcircle {
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px;
  margin-bottom: 6px; flex-shrink: 0;
}
.opname { font-size: 13px; font-weight: 600; }
.opmeta { font-size: 11.5px; color: var(--text2); margin-top: 3px; line-height: 1.6; }
.oparrow { font-size: 18px; color: var(--text2); align-self: flex-start; margin-top: 9px; }

/* ===== 三期：扫码报工 ===== */
.scan-op {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 10px; cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.scan-op:hover { border-color: var(--primary); box-shadow: 0 2px 10px rgba(31,95,216,.10); }

/* ===== 三期：工单标签 ===== */
.print-bar { display: flex; align-items: center; margin-bottom: 16px; }
.label-sheet { display: flex; flex-wrap: wrap; gap: 16px; }
.label {
  width: 60mm; height: 40mm; background: #fff; border: 1px solid var(--line);
  border-radius: 4px; padding: 3mm; display: flex; gap: 3mm;
  font-family: var(--font); color: #000; overflow: hidden;
}
.label-qr { width: 24mm; height: 24mm; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.label-qr svg { width: 24mm; height: 24mm; }
.label-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.label-code { font-size: 12px; font-weight: 700; letter-spacing: .2px; white-space: nowrap; overflow: hidden; }
.label-item { font-size: 10.5px; margin-top: 1.2mm; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.label-qty { font-size: 11.5px; font-weight: 600; margin-top: .8mm; white-space: nowrap; }
.label-ops { font-size: 9px; color: #333; margin-top: .8mm; line-height: 1.4; overflow: hidden; }
.label-hint { font-size: 8.5px; color: #666; margin-top: auto; border-top: 1px dashed #bbb; padding-top: .8mm; white-space: nowrap; }

@media print {
  body { background: #fff; }
  .sidebar, .topbar, .mobilebar, .print-bar { display: none !important; }
  .main, .content { margin: 0 !important; padding: 0 !important; }
  .label { border: 1px dashed #ccc; page-break-inside: avoid; }
}

/* ---- 摄像头扫码取景层 ---- */
#camOverlay { position: fixed; inset: 0; background: #0b0f14; z-index: 200;
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
.cam-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center;
  justify-content: space-between; gap: 10px; padding: 12px 16px;
  background: rgba(0,0,0,.35); color: #fff; font-size: 13.5px; }
.cam-top .btn { background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.3); }
.cam-box { position: relative; width: min(92vw, 460px); aspect-ratio: 1; border-radius: 14px; overflow: hidden; background: #000; }
.cam-box video { width: 100%; height: 100%; object-fit: cover; }
.cam-frame { position: absolute; inset: 12%; border: 2px solid rgba(255,255,255,.75); border-radius: 12px;
  box-shadow: 0 0 0 2000px rgba(0,0,0,.35); pointer-events: none; }
.cam-tip { position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 14px; text-align: center;
  background: rgba(0,0,0,.5); color: #fff; font-size: 13.5px; }

/* ---- 登录页 / 用户区 ---- */
.login-wrap { min-height: 70vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 360px; max-width: 92vw; }
.who .uname { font-weight: 600; color: var(--text); }
.who .urole { background: var(--line); border-radius: 4px; padding: 2px 7px; font-size: 11.5px; }
.who .btn { padding: 4px 12px; font-size: 12.5px; }
