/* 布局：左侧按数据流分组的导航 + 右侧作业区；手机上导航变成顶部横向滚动条。 */
:root {
  --bg: #f2f4f6;
  --surface: #ffffff;
  --ink: #17212b;
  --muted: #5b6977;
  --line: #d6dce2;
  --accent: #1f5fa8;
  --accent-ink: #ffffff;
  --accent-soft: #e6eef8;
  --flag: #e8a800;
  --flag-bg: #fff5d6;
  --ok: #1d7a4c;
  --ok-bg: #e2f2e9;
  --bad: #b3261e;
  --bad-bg: #fbe5e3;
  --font: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", "Hiragino Sans GB", system-ui, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10161c; --surface: #18212a; --ink: #e5eaef; --muted: #96a4b1; --line: #2b3641;
    --accent: #6aa6ea; --accent-ink: #0c1620; --accent-soft: #1c2c3e; --flag: #f2c230; --flag-bg: #3a3112;
    --ok: #5fc493; --ok-bg: #133022; --bad: #f08a80; --bad-bg: #3a1a17; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.55 var(--font); }
[hidden] { display: none !important; }
a { color: var(--accent); }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0; }
h3 { font-size: 14px; margin: 0; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- 登录 ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 28px; width: min(380px, 100%); display: grid; gap: 14px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card label.check { display: flex; align-items: center; gap: 8px; }

/* ---------- 框架 ---------- */
.app { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: 100%; }
.side { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 16px; padding: 18px 18px 10px; letter-spacing: .04em; }
#nav { display: flex; flex-direction: column; padding: 4px 8px; gap: 2px; overflow-y: auto; }
#nav .group { font-size: 12px; color: var(--muted); padding: 12px 10px 4px; letter-spacing: .08em; }
#nav a { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; }
#nav a:hover { background: var(--bg); }
#nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.cnt { min-width: 22px; padding: 0 7px; border-radius: 999px; font-size: 12px; text-align: center; background: var(--flag-bg); color: var(--ink); box-shadow: inset 0 0 0 1px var(--flag); }
.cnt.bad { background: var(--bad-bg); color: var(--bad); box-shadow: none; }
.cnt:empty { display: none; }
.who { margin-top: auto; padding: 14px 18px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px; font-size: 13px; }
#whoName { flex: 1 1 100%; }
.main { padding: 22px 26px 60px; display: grid; gap: 18px; align-content: start; min-width: 0; outline: none; }
.content { min-width: 0; display: flex; flex-direction: column; }
.mbar, .tabbar, .scrim { display: none; }

/* ---------- 通用组件 ---------- */
.head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px 16px; }
.head .sub { color: var(--muted); font-size: 13px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 16px; display: grid; gap: 12px; min-width: 0; }
.row { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }
.btn { font: inherit; font-size: 14px; font-weight: 500; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 3px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.btn:focus-visible, .link:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, #nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select, textarea { font: inherit; font-size: 14px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; min-width: 0; }
input[type="checkbox"] { width: 16px; height: 16px; }
td input[type="number"] { width: 84px; text-align: right; }
td input[type="text"], td select { width: 100%; min-width: 110px; }
label.f { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px 12px; }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
th { background: var(--bg); color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .04em; position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--accent-soft); }
tr.flag td { background: var(--flag-bg); }
tr.flag td:first-child { box-shadow: inset 4px 0 0 var(--flag); }
td.wrap { white-space: normal; min-width: 180px; }
.pill { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--line); color: var(--ink); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--flag-bg); color: var(--ink); box-shadow: inset 0 0 0 1px var(--flag); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--accent-soft); color: var(--accent); }
.tag { font-size: 12px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 3px 12px; font: inherit; font-size: 13px; cursor: pointer; color: var(--ink); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.msg { margin: 0; padding: 9px 12px; border-radius: 6px; font-size: 13px; background: var(--bg); border: 1px solid var(--line); }
.msg.err { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.msg.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.msg.warn { background: var(--flag-bg); border-color: var(--flag); }
.empty { color: var(--muted); padding: 18px; text-align: center; }
.loading { color: var(--muted); padding: 30px; }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: sp .8s linear infinite; vertical-align: -1px; margin-right: 6px; }
@keyframes sp { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 50; max-width: min(420px, calc(100% - 36px)); background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; font-size: 14px; box-shadow: 0 6px 20px rgb(0 0 0 / .2); }
.toast.err { background: var(--bad); color: #fff; }
pre.json { margin: 0; padding: 10px; background: var(--bg); border-radius: 6px; font: 12px/1.5 var(--mono); overflow-x: auto; max-height: 340px; white-space: pre; }
.back { font-size: 13px; text-decoration: none; }

/* 工作台：数据流 */
.flow { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stage { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; display: grid; gap: 8px; align-content: start; min-width: 0; }
.stage .label { font-size: 12px; color: var(--muted); letter-spacing: .06em; }
.stage a { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; text-decoration: none; color: var(--ink); padding: 4px 0; border-top: 1px dashed var(--line); }
.stage a:first-of-type { border-top: 0; }
.stage a b { font-size: 22px; font-variant-numeric: tabular-nums; }
.stage a b.hot { color: var(--accent); }
.stage a b.alarm { color: var(--bad); }

/* 步骤条 */
.steps { display: flex; flex-wrap: wrap; gap: 6px; }
.steps span { padding: 3px 12px; border-radius: 999px; font-size: 12px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.steps span.done { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.steps span.now { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.photo { max-width: 100%; max-height: 360px; border: 1px solid var(--line); border-radius: 6px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: 8px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }

/* 到货清点卡片 */
.rc-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px; }
.rc { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: grid; gap: 10px; }
.rc.on { border-color: var(--accent); box-shadow: inset 4px 0 0 var(--accent); }
.rc.warn { border-color: var(--flag); box-shadow: inset 4px 0 0 var(--flag); background: var(--flag-bg); }
.rc.full:not(.on) { opacity: .6; }
.rc-head { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; line-height: 1.5; }
.rc-head input { width: 24px; height: 24px; flex: 0 0 auto; margin-top: 2px; }
.rc-head .todo { color: var(--accent); }
.rc-edit { display: grid; gap: 8px; }
.stepper { display: grid; grid-template-columns: 3em 48px minmax(0, 1fr) 48px; gap: 6px; align-items: center; }
.stepper > span { color: var(--muted); font-size: 13px; }
.stepper .btn { padding: 0; height: 44px; font-size: 20px; line-height: 1; }
.stepper input { text-align: center; font-size: 18px; font-weight: 600; height: 44px; width: 100%; }
.rc-warn { margin: 0; color: var(--ink); font-size: 13px; }
.submitbar { display: flex; justify-content: flex-end; }
.submitbar .btn { min-width: 260px; }
.batch { border-top: 1px dashed var(--line); padding-top: 10px; display: grid; gap: 6px; }
.batch:first-of-type { border-top: 0; padding-top: 0; }
.sheet .qr-big { width: 40mm; }
.sheet .qr-big svg { width: 40mm; height: 40mm; }
.sheet .qr-big b { display: block; font-size: 9pt; margin-top: 1mm; }

/* ---------- 打印（A4） ---------- */
body.printing { background: #fff; color: #000; }
body.printing .app { display: block; }
body.printing .side { display: none; }
body.printing .main { padding: 0; display: block; }
.printbar { display: flex; gap: 10px; align-items: center; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; color: var(--ink); }
.sheet { width: 210mm; min-height: 297mm; margin: 12px auto; padding: 14mm 12mm; background: #fff; color: #000; position: relative; box-shadow: 0 2px 12px rgb(0 0 0 / .15); font-family: var(--font); }
.sheet .corner { position: absolute; width: 8mm; height: 8mm; background: #000; }
.sheet .c1 { left: 4mm; top: 4mm; } .sheet .c2 { right: 4mm; top: 4mm; } .sheet .c3 { left: 4mm; bottom: 4mm; } .sheet .c4 { right: 4mm; bottom: 4mm; }
.sheet header { display: flex; justify-content: space-between; gap: 10mm; }
.sheet h1 { font-size: 24pt; margin: 0; }
.sheet h1 small { font-size: 10pt; font-family: var(--mono); margin-left: 3mm; }
.sheet .docno { font: 600 14pt var(--mono); margin: 2mm 0; }
.sheet .info { font-size: 10.5pt; line-height: 1.7; }
.sheet .qr { width: 34mm; text-align: center; font-size: 8pt; }
.sheet .qr svg { width: 34mm; height: 34mm; display: block; }
.sheet .inst { font-size: 9.5pt; color: #444; margin: 4mm 0 3mm; }
.sheet table { width: 100%; border-collapse: collapse; font-size: 10.5pt; }
.sheet thead { display: table-header-group; }
.sheet th { background: #e9edf1; color: #000; font-size: 9.5pt; border: 1px solid #333; padding: 2mm; position: static; text-align: center; }
.sheet td { border: 1px solid #333; padding: 1.5mm 2mm; height: 15mm; white-space: nowrap; color: #000; }
.sheet tr { page-break-inside: avoid; }
.sheet tbody tr:last-child td { border-bottom: 1px solid #333; }
.sheet td.c { text-align: center; }
.sheet td.big { font: 600 14pt var(--mono); text-align: center; }
.sheet td.name { white-space: normal; max-width: 52mm; }
.sheet .boxes { display: inline-flex; gap: 1.2mm; }
.sheet .boxes i { display: inline-block; width: 8mm; height: 10mm; border: 1.5px solid #6c88ad; }
.sheet .tick { display: inline-block; width: 8mm; height: 8mm; border: 1.5px solid #6c88ad; }
.sheet .sign { display: flex; flex-wrap: wrap; gap: 6mm 14mm; margin-top: 8mm; font-size: 11pt; align-items: flex-end; }
.sheet .sign > span { display: inline-flex; align-items: flex-end; gap: 1.5mm; }
.sheet .sign u { display: inline-block; min-width: 50mm; border-bottom: 1px solid #333; text-decoration: none; }
.sheet .foot { position: absolute; left: 14mm; bottom: 7mm; font: 8pt var(--mono); color: #666; }
.sheet .stamp { display: inline-block; border: 3px solid; padding: 1mm 4mm; font-size: 16pt; font-weight: 700; transform: rotate(-4deg); }
.sheet .diffneg { color: #b3261e; font-weight: 700; }
.sheet tr.hl td { background: #fff3d1; }
.sheet .pageno { font: 500 10pt var(--mono); color: #444; margin-left: 4mm; }
.sheet .cont { text-align: right; font-size: 9pt; color: #666; margin: 3mm 0 0; }
@media print {
  @page { size: A4; margin: 0; }
  body, body.printing { background: #fff; }
  .printbar, .noprint, .toast { display: none !important; }
  .sheet { margin: 0; box-shadow: none; }
  .sheet + .sheet { break-before: page; }   /* 多页单据：每张 .sheet 一页 */
}

/* ---------- 手机 ---------- */
@media screen and (max-width: 820px) {   /* 只管屏幕：打印时 A4 宽度也小于 820px，不能套用手机样式 */
  /* 手机：顶部标题栏 + 底部常用入口；完整菜单从左侧滑出 */
  .app { display: block; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(300px, 82%); height: auto; z-index: 40; transform: translateX(-102%); transition: transform .2s; border-right: 1px solid var(--line); padding-top: env(safe-area-inset-top); }
  body.navopen .side { transform: none; }
  body.navopen .scrim { display: block; position: fixed; inset: 0; background: rgb(0 0 0 / .35); z-index: 35; }
  .mbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; position: sticky; top: 0; z-index: 20;
          background: var(--surface); border-bottom: 1px solid var(--line);
          padding: calc(env(safe-area-inset-top) + 8px) max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left)); }
  #mTitle { font-weight: 700; font-size: 16px; flex: 1; text-align: center; }
  .tabbar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
            background: var(--surface); border-top: 1px solid var(--line); padding: 4px max(6px, env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left)); }
  .tabbar a, .tabbar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 50px; border: 0; background: none;
            font: inherit; font-size: 13px; color: var(--muted); text-decoration: none; position: relative; cursor: pointer; }
  .tabbar .on { color: var(--accent); font-weight: 700; }
  .tabbar .on::before { content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
  .tabbar .cnt { position: absolute; top: 4px; right: calc(50% - 30px); min-width: 18px; padding: 0 5px; font-size: 11px; }
  .main { padding: 14px max(14px, env(safe-area-inset-right)) calc(84px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); gap: 14px; }
  .main > .head h1 { font-size: 18px; }
  /* 触控：按钮、输入框加大，输入框 16px 字号避免 iOS 自动放大 */
  .btn { min-height: 44px; padding: 9px 16px; }
  .btn.sm { min-height: 36px; }
  .chip { min-height: 36px; padding: 6px 14px; }
  input, select, textarea { font-size: 16px; min-height: 44px; }
  input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; }
  .panel { padding: 14px; }
  /* 表格变卡片：每行一张卡片，左边是栏名，右边是内容 */
  .tablewrap { border: 0; overflow: visible; }
  .tablewrap table, .tablewrap tbody, .tablewrap tr, .tablewrap td { display: block; width: 100%; }
  .tablewrap thead { display: none; }
  .tablewrap tr { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; margin-bottom: 10px; }
  .tablewrap tr[hidden] { display: none; }
  .tablewrap td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 0; border: 0; border-bottom: 1px dashed var(--line); white-space: normal; text-align: right; }
  .tablewrap td:last-child { border-bottom: 0; }
  .tablewrap td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; flex: 0 0 auto; max-width: 40%; }
  .tablewrap td:not([data-label])::before, .tablewrap td[data-label=""]::before { display: none; }
  .tablewrap td.empty, .tablewrap td[colspan] { justify-content: center; text-align: center; }
  .tablewrap td input[type="number"] { width: 120px; }
  .tablewrap td input[type="text"], .tablewrap td select { width: auto; flex: 1; max-width: 62%; }
  .tablewrap td .row { justify-content: flex-end; }
  tr.flag { background: var(--flag-bg) !important; box-shadow: inset 4px 0 0 var(--flag); }
  tr.flag td, tr.flag td:first-child { background: none; box-shadow: none; }
  tr.click:hover td { background: none; }
  tr.click:active { border-color: var(--accent); }
  /* 打印只在电脑上做 */
  .main [data-a="print"] { display: none; }
  .sheet { zoom: .45; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); left: 14px; right: 14px; max-width: none; }
  .rc-list { grid-template-columns: minmax(0, 1fr); }
  .submitbar { position: sticky; bottom: calc(62px + env(safe-area-inset-bottom)); z-index: 15; margin: 0 -14px; padding: 10px 14px;
               background: linear-gradient(to top, var(--bg) 70%, transparent); }
  .submitbar .btn { width: 100%; min-width: 0; min-height: 52px; font-size: 16px; }
}
