:root {
  --bg: #f5f6f4;
  --card: #ffffff;
  --text: #1f2a24;
  --muted: #6b766f;
  --line: #e2e6e3;
  --accent: #2f7d4f;
  --accent-soft: #e8f3ec;
  --danger: #c0392b;
  --readonly: #f7f8f7;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}
.wrap { max-width: 1120px; margin: 0 auto; padding: 20px 16px 110px; }
.muted { color: var(--muted); font-size: 12px; }

/* 顶部导航 */
.topnav { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topnav .inner { max-width: 1120px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 4px; overflow-x: auto; }
.brand { font-weight: 700; font-size: 16px; margin-right: 20px; white-space: nowrap; padding: 14px 0; }
.topnav a {
  padding: 15px 14px 13px; color: var(--muted); text-decoration: none; white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.topnav a:hover { color: var(--text); }
.topnav a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.badge { background: var(--accent-soft); color: var(--accent); border-radius: 10px; padding: 0 7px; font-size: 12px; }

.view { display: none; }
.view.active { display: block; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 16px; }
.card h2 { font-size: 15px; margin: 0 0 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.full { grid-column: 1 / -1; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px;
  font: inherit; color: inherit; background: #fff;
}
input:disabled { background: var(--readonly); color: var(--muted); }
textarea { resize: vertical; min-height: 60px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=number] { text-align: right; }
button {
  font: inherit; border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 6px; cursor: pointer; white-space: nowrap;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.link { border: none; color: var(--danger); padding: 4px 8px; background: none; }
button.small { padding: 4px 10px; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* 单据头部 + 步骤条 */
.qhead { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.qno { font-size: 20px; font-weight: 700; }
.qhead select { width: auto; }
.steps { display: flex; gap: 6px; margin-bottom: 14px; overflow-x: auto; }
.steps button { flex: 1; border-radius: 8px; padding: 10px 12px; color: var(--muted); }
.steps button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.pane { display: none; }
.pane.active { display: block; }

/* 产品信息 + 图片 */
.info-layout { display: grid; grid-template-columns: 1fr 220px; gap: 18px; }
.photo {
  border: 1px dashed var(--line); border-radius: 8px; min-height: 220px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; overflow: hidden; background: var(--readonly); color: var(--muted); text-align: center; position: relative;
}
.photo img { max-width: 100%; max-height: 260px; display: block; }
.photo-actions { margin-top: 8px; display: flex; gap: 8px; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
.cost-table { min-width: 860px; }
th, td { padding: 6px; border-bottom: 1px solid var(--line); text-align: left; }
th { font-size: 12px; color: var(--muted); font-weight: 500; white-space: nowrap; }
td.num, th.num { text-align: right; }
td.calc { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; color: var(--muted); }
td.amt { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; font-weight: 600; }
.col-idx { width: 36px; color: var(--muted); }
tfoot td { font-weight: 700; border-bottom: none; padding-top: 10px; }
.ex-name { font-weight: 500; white-space: nowrap; }

.summary { max-width: 460px; margin-left: auto; }
.summary td { border: none; padding: 5px 0; }
.summary td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.summary tr.sep td { border-top: 1px solid var(--line); padding-top: 10px; }
.summary tr.total td { border-top: 2px solid var(--text); padding-top: 10px; font-size: 20px; font-weight: 700; color: var(--accent); }

/* 底部固定合计条 */
.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line);
  box-shadow: 0 -2px 10px rgba(0,0,0,.04); z-index: 10;
}
.bottombar .inner { max-width: 1120px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.bb-left { color: var(--muted); font-size: 13px; flex: 1; min-width: 180px; }
.bb-total { font-size: 20px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }

/* 记录列表 */
.records td { vertical-align: middle; }
.records tbody tr { cursor: pointer; }
.records tbody tr:hover { background: #fafbfa; }
.records tr.current { background: var(--accent-soft); }
.thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; display: block; background: var(--readonly); }
.status { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: #eef0ee; color: var(--muted); white-space: nowrap; }
.status.sent { background: #e8f0fb; color: #2d5fa8; }
.status.won { background: var(--accent-soft); color: var(--accent); }
.status.lost { background: #fbeceb; color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 200px; }
.toolbar select { width: auto; }
input[type=checkbox] { width: 16px; height: 16px; }

/* 打印 */
#printSheet { display: none; }
/* 打印样式仿照纸质「产品（成本核算）单」：黑色细框线、宋体正文、黑体标题 */
@media print {
  body { background: #fff; }
  .topnav, .wrap, .bottombar { display: none !important; }
  #printSheet {
    display: block; color: #000; padding: 12mm 12mm 8mm;
    font: 12px/1.3 "Songti SC", "STSong", SimSun, serif;
  }
  #printSheet h1 {
    font: 700 24px "PingFang SC", "Heiti SC", "Microsoft YaHei", sans-serif;
    text-align: center; margin: 0 0 6px; letter-spacing: 2px;
  }
  #printSheet .company { text-align: center; margin: -2px 0 8px; font-size: 11px; }
  #printSheet table { border-collapse: collapse; width: 100%; table-layout: fixed; border: 1.5px solid #000; }
  #printSheet th, #printSheet td { border: 1px solid #000; padding: 0 5px; color: #000; overflow: hidden; }
  #printSheet th { font-weight: 700; text-align: center; }
  #printSheet .hd td { height: 9.5mm; }
  #printSheet .hd .lab { font-weight: 700; white-space: nowrap; }
  #printSheet .rows th { height: 9mm; }
  #printSheet .rows td { height: 8.2mm; }
  #printSheet .right { text-align: right; }
  #printSheet .center { text-align: center; }
  #printSheet .pic { text-align: center; vertical-align: middle; }
  #printSheet .pic img { max-width: 100%; max-height: 36mm; display: block; margin: 2px auto; }
  #printSheet .grand td { font-weight: 700; }
  #printSheet .foot { margin-top: 6px; display: flex; justify-content: space-between; font-size: 12px; }
  #printSheet .notes { margin-top: 8px; white-space: pre-wrap; }
  /* 页边距设为 0 可去掉浏览器自动加的日期、文件路径页眉页脚，留白由 #printSheet 的 padding 提供 */
  @page { size: A4; margin: 0; }
}
@media (max-width: 700px) {
  .info-layout { grid-template-columns: 1fr; }
  .steps button { flex: none; }
  .bb-left { display: none; }
}

/* ---------- 登录页（布局沿用记账系统） ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px;
  background: linear-gradient(160deg, #1f5c3a, #2f7d4f); }
.login-card { background: #fff; border-radius: 18px; box-shadow: 0 10px 40px rgba(0,0,0,.25); width: 100%; max-width: 380px; padding: 28px 24px; }
.login-logo { text-align: center; margin-bottom: 18px; }
.login-logo h1 { font-size: 21px; margin: 0 0 4px; }
.login-sub { color: var(--muted); font-size: 13px; margin: 0; }
.login-tabs { display: flex; background: #eef1ee; border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.ltab { flex: 1; padding: 9px; border-radius: 8px; color: var(--muted); font-weight: 600; border: none; background: none; }
.ltab.active { background: #fff; color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-form input[type=text], .login-form input[type=password] { padding: 12px 14px; font-size: 15px; border-radius: 10px; }
.login-form .primary { padding: 12px; font-size: 16px; border-radius: 10px; }
.remember { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; margin: 0; }
.form-hint { font-size: 12px; color: var(--muted); text-align: center; line-height: 1.6; }
.form-msg { font-size: 13px; text-align: center; min-height: 18px; }
.form-msg.err { color: var(--danger); } .form-msg.ok { color: var(--accent); }
.hidden { display: none !important; }

/* ---------- 顶栏右侧：用户菜单 ---------- */
.topnav .spacer { flex: 1; }
.user-btn { border: none; background: none; color: var(--text); padding: 6px 10px; display: flex; align-items: center; gap: 6px; }
.user-btn .role { font-size: 11px; background: var(--accent-soft); color: var(--accent); border-radius: 8px; padding: 0 6px; }
.user-menu { position: fixed; top: 52px; right: 16px; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.15); overflow: hidden; z-index: 30; min-width: 150px; }
.user-menu button { display: block; width: 100%; text-align: left; border: none; border-radius: 0; padding: 11px 16px; }
.user-menu button:hover { background: var(--bg); }
.user-menu .danger { color: var(--danger); border-top: 1px solid var(--line); }
.dot { display: inline-block; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }

/* 保存状态 */
.save-state { font-size: 12px; }
.save-state.saving { color: #b7791f; }
.save-state.err { color: var(--danger); font-weight: 600; }

/* 弹窗 */
dialog { border: none; border-radius: 12px; padding: 22px; width: min(360px, 92vw); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h3 { margin: 0 0 14px; font-size: 16px; }
dialog form { display: flex; flex-direction: column; gap: 10px; }

/* 管理页 */
.subtabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.subtabs button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.admin-table td, .admin-table th { white-space: nowrap; }
.admin-table td.detail { white-space: normal; min-width: 280px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: #eef0ee; color: var(--muted); }
.tag.ok { background: var(--accent-soft); color: var(--accent); }
.tag.warn { background: #fdf3e1; color: #b7791f; }
.tag.bad { background: #fbeceb; color: var(--danger); }
.readonly-note { background: #fdf3e1; color: #8a5a12; border-radius: 8px; padding: 8px 12px; font-size: 13px; margin-bottom: 12px; }

/* 密码框右侧的「眼睛」 */
.pwd-wrap { position: relative; }
.pwd-wrap input { width: 100%; padding-right: 44px !important; }
.pwd-eye {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  border: none; background: none; padding: 6px 8px; color: var(--muted); line-height: 0; border-radius: 6px;
}
.pwd-eye:hover { color: var(--accent); }

/* 尺寸：长 × 宽 × 高 cm，乘号和单位固定 */
.size-input { display: flex; align-items: center; gap: 6px; }
.size-input input { flex: 1; min-width: 0; text-align: center; }
.size-input span { color: var(--muted); flex: none; }

/* 打印：多页、客户版英文小字 */
@media print {
  #printSheet .page { break-after: page; }
  #printSheet .page:last-child { break-after: auto; }
  #printSheet h1 .en { font-size: 16px; letter-spacing: 1px; margin-left: 6px; }
  #printSheet small { display: block; font-size: 8.5px; font-weight: 400; line-height: 1.1; }
  #printSheet .rows.quote td { height: 8mm; padding: 0 5px; }
  #printSheet .rows.quote .hd td { height: 9.5mm; }
  #printSheet .rows.quote th { height: 10mm; }
}
.size-input input { padding-left: 4px; padding-right: 4px; }
@media (min-width: 700px) { .size-field { grid-column: span 2; } }
.size-input select { width: auto; flex: none; padding-left: 6px; padding-right: 6px; }

/* 每件成本列高亮 */
th.hl { color: var(--accent); }
td.hl, .cost-table td.calc.hl { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* 汇总：成本 → 利润 → 报价 */
.flow { display: grid; grid-template-columns: 1fr auto 1.1fr auto 1fr; gap: 12px; align-items: stretch; }
.flow-block { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.flow-block h3 { font-size: 15px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.flow-block .summary { max-width: none; margin: 0; }
.flow-arrow { align-self: center; color: var(--muted); font-size: 22px; }
.step-no { display: inline-flex; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff;
  font-size: 13px; align-items: center; justify-content: center; }
.big-input { display: flex; align-items: center; gap: 8px; }
.big-input input { font-size: 22px; font-weight: 700; padding: 8px 12px; }
.big-input span { color: var(--muted); white-space: nowrap; }
.quote-block { background: var(--accent-soft); border-color: var(--accent); }
.quote-block .summary tr.total td { border-top: none; padding-top: 0; font-size: 26px; }
.warn-text { color: var(--danger); font-weight: 600; }
@media (max-width: 900px) {
  .flow { grid-template-columns: 1fr; }
  .flow-arrow { transform: rotate(90deg); justify-self: center; }
}
#costTable td + td { text-align: right; }
#costTable tr.muted td { font-size: 12px; padding-bottom: 0; }
@media print {
  #printSheet .internal-tag { text-align: right; font-size: 10px; color: #555; margin-bottom: -14px; }
  #printSheet .profit-table { margin-top: 6px; }
  #printSheet .profit-table td { height: 8mm; padding: 0 6px; }
  #printSheet .profit-table .lab { font-weight: 700; white-space: nowrap; }
}

/* ---------- 输入联想下拉框 ---------- */
.ac-box {
  position: fixed; z-index: 60; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15); max-height: 280px; overflow-y: auto; padding: 4px 0;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.ac-item { display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer; }
.ac-item:hover, .ac-item.active { background: var(--accent-soft); }
.ac-item b { color: var(--accent); }
.ac-v { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-sub { color: var(--muted); font-size: 12px; white-space: nowrap; max-width: 45%; overflow: hidden; text-overflow: ellipsis; }
.ac-del { border: none; background: none; color: #b5bdb8; padding: 2px 6px; font-size: 12px; }
.ac-del:hover { color: var(--danger); border: none; }
.m-only { display: none; }

/* ================= 手机排版 ================= */
@media (max-width: 640px) {
  input, select, textarea { font-size: 16px; }          /* 小于 16px 时 iPhone 会自动放大页面 */
  .wrap { padding: 12px 10px 110px; }
  .card { padding: 14px 12px; border-radius: 12px; }
  .ac-item { padding: 12px 14px; }                      /* 手指好点 */

  /* 顶部导航：去掉系统名，只留页面和用户 */
  .topnav .brand { display: none; }
  .topnav .inner { padding: 0 4px; gap: 0; }
  .topnav a { padding: 13px 9px 11px; font-size: 14px; }
  .user-btn { padding: 6px 4px; font-size: 14px; }
  .user-btn .role { display: none; }
  .user-menu { right: 8px; }

  /* 核算单头部：按钮排成两列 */
  .qhead { gap: 10px; margin-bottom: 10px; }
  .qhead > div:first-child { width: 100%; }
  .qno { font-size: 18px; }
  .qhead .actions { display: grid; grid-template-columns: 1fr 1fr; width: 100%; gap: 8px; }
  .qhead .actions > * { width: 100%; }
  .qhead .actions .primary { grid-column: span 2; }

  /* 步骤条：短名字 */
  .steps { gap: 4px; margin-bottom: 10px; }
  .steps button { flex: 1; padding: 9px 2px; font-size: 14px; }
  .steps .long { display: none; }

  .photo { min-height: 150px; }
  .size-input { gap: 4px; }
  .size-input select { max-width: 96px; }

  /* 表格变卡片：每一行一张卡片，不用左右滑 */
  table.mcard { min-width: 0 !important; }
  .mcard thead { display: none; }
  .mcard, .mcard tbody, .mcard tfoot { display: block; }
  .mcard tbody tr {
    display: grid; gap: 8px; padding: 10px; margin-bottom: 10px;
    border: 1px solid var(--line); border-radius: 10px; background: #fff;
  }
  .mcard td { display: block; border: none; padding: 0; text-align: left; min-width: 0; }
  .mcard td.calc, .mcard td.amt { text-align: left; padding-top: 2px; }
  .mcard td[data-label]::before {
    content: attr(data-label); display: block; font-size: 11px; color: var(--muted); font-weight: 400; margin-bottom: 2px;
  }
  .mcard td.empty { grid-column: 1 / -1; }
  .mcard .c-idx { display: none; }
  .mcard .c-name { grid-area: name; } .mcard .c-del { grid-area: del; align-self: start; }
  .mcard .c-qty { grid-area: qty; } .mcard .c-unit { grid-area: unit; } .mcard .c-price { grid-area: price; }
  .mcard .c-per { grid-area: per; } .mcard .c-total { grid-area: total; } .mcard .c-amt { grid-area: amt; }
  .mcard .c-mode { grid-area: mode; }

  /* 物料明细 / 附加费用：名称一行，用量·单位·单价一行，每件成本·总数·总金额一行 */
  .cost-table.mcard .c-oq { display: none; }
  #mats tr { grid-template-columns: 1fr 0.8fr 1fr auto; grid-template-areas: "name name name del" "qty unit price price" "per total amt amt"; }
  #extras tr { grid-template-columns: 1fr 0.8fr 1fr 1fr; grid-template-areas: "name name mode mode" "qty unit price price" "per total amt amt"; }
  #extras .c-name { align-self: center; font-weight: 600; }
  .cost-table.mcard td.c-per { border-radius: 6px; padding: 2px 6px; }
  .mcard tfoot tr { display: flex; align-items: flex-end; gap: 16px; padding: 4px 10px; }
  .mcard tfoot td { display: block; border: none; padding: 0; }
  .mcard tfoot td:empty { display: none; }
  .mcard tfoot .f-label { flex: 1; text-align: left; }

  /* 核算记录卡片 */
  .records.mcard .c-chk { grid-area: chk; } .records.mcard .c-thumb { grid-area: thumb; }
  .records.mcard .c-item { grid-area: item; } .records.mcard .c-prod { grid-area: prod; }
  .records.mcard .c-cust { grid-area: cust; } .records.mcard .c-oq { grid-area: oq; text-align: right; }
  .records.mcard .c-cost { grid-area: cost; } .records.mcard .c-price { grid-area: price; text-align: right; }
  .records.mcard .c-status { grid-area: status; } .records.mcard .c-upd { grid-area: upd; align-self: center; font-size: 12px; }
  .records.mcard .c-act { grid-area: act; justify-content: flex-end; }
  .records.mcard tbody tr {
    grid-template-columns: 52px 1fr 1fr auto; gap: 4px 10px;
    grid-template-areas: "thumb item item status" "thumb prod prod prod" "thumb cust cust oq" "thumb cost price price" "chk upd upd act";
  }
  .records.mcard tr.current { background: var(--accent-soft); }
  .records.mcard td[data-label]::before { display: inline; margin-right: 4px; }
  .records.mcard .thumb { width: 52px; height: 52px; }
  .records.mcard .c-price b { font-size: 16px; color: var(--accent); }
  .m-only { display: inline; }
  .records.mcard .c-chk label { display: flex; align-items: center; gap: 4px; margin: 0; font-size: 13px; color: var(--muted); }

  /* 物料库卡片 */
  .lib-table.mcard tbody tr { grid-template-columns: 1fr 1fr auto; grid-template-areas: "name name del" "unit price price" "sup note note"; }
  .lib-table.mcard .c-sup { grid-area: sup; } .lib-table.mcard .c-note { grid-area: note; }

  .toolbar input { flex-basis: 100%; }
  .toolbar select, .toolbar button { flex: 1; }

  /* 汇总 */
  .flow-block { padding: 12px; }
  .big-input input { font-size: 20px; }
  .quote-block .summary tr.total td { font-size: 24px; }

  /* 底部合计条 */
  .bottombar .inner { padding: 8px 10px; gap: 8px; flex-wrap: nowrap; }
  .bb-total { font-size: 17px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .bottombar button { padding: 8px 12px; }
  #prevBtn { display: none; }                          /* 手机上用顶部步骤条切换 */
}
@media (max-width: 640px) {
  .records.mcard .c-cost, .records.mcard .c-price, .records.mcard .c-oq, .records.mcard .c-upd { white-space: nowrap; }
  .records.mcard .c-status { justify-self: end; }
  .records.mcard .c-chk { align-self: center; justify-self: center; }
  .records.mcard .c-chk .m-only { display: none; }
  .records.mcard .c-chk input { width: 20px; height: 20px; }
}

/* 产品信息：两列，顺序和纸质单一致 */
.info-grid { grid-template-columns: 1fr 1fr; }
.en-label { margin-top: 8px; }
.en-row { display: flex; gap: 6px; }
.en-row input { flex: 1; min-width: 0; }
.unit-input { display: flex; align-items: center; gap: 6px; }
.unit-input span { color: var(--muted); }
/* 可选择的输入框：右边加个小箭头，提示可以点开选 */
input[data-ac=packing], input[data-ac=unit], input[data-ac=size] {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236b766f' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; padding-right: 22px;
}
/* 总金额下面的「每件」小字 */
small.per { display: block; font-size: 11px; font-weight: 400; color: var(--accent); }
.mode-sel { display: block; width: auto; margin-top: 4px; padding: 3px 6px; font-size: 12px; font-weight: 400; }
@media (max-width: 640px) {
  .info-grid { grid-template-columns: 1fr; }
  #mats tr { grid-template-areas: "name name name del" "qty unit price price" "total total amt amt"; }
  #extras tr { grid-template-columns: 1fr 0.8fr 1fr 1fr; grid-template-areas: "name name name name" "qty unit price price" "total total amt amt"; }
  .mode-sel { display: inline-block; margin: 0 0 0 8px; }
  .mcard .c-amt { text-align: right; }
}
.carton-hint { align-self: end; padding-bottom: 10px; }
.unit-input span { white-space: nowrap; }

/* ================= 生产单 ================= */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; border-radius: 0; padding: 6px 14px; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.pgrid { grid-template-columns: repeat(3, 1fr); }
.pgrid4 { grid-template-columns: repeat(4, 1fr); }
.pgrid4 .span2 { grid-column: span 2; }
.pgrid2 { display: grid; grid-template-columns: 1fr 1.3fr; gap: 18px; }
.pgrid2 textarea { min-height: 170px; }
.qty-row { display: flex; gap: 6px; }
.qty-row input:first-child { flex: 1; min-width: 0; }
.qty-row .qty-unit { width: 76px; flex: none; text-align: center; }
.pack-row { display: flex; align-items: center; gap: 6px; }
.pack-row input { flex: 1; min-width: 0; text-align: center; }
.pack-row span { color: var(--muted); white-space: nowrap; }
.ptable { min-width: 900px; }
.ptable td { padding: 4px 3px; vertical-align: middle; }
.ptable input { padding: 6px 6px; }
.ptable td > input[data-auto]::placeholder { color: #8fa597; }
.fmatrix { min-width: 860px; }
.fmatrix th { padding: 3px; }
.fmatrix th input { font-weight: 600; text-align: center; background: #fbfcfb; }
.fmatrix td input { text-align: center; }
.fmatrix td.w-fab input, .fmatrix td.w-col input { text-align: left; }
.fmatrix .w-fab { width: 13%; } .fmatrix .w-col { width: 14%; }
.hint-th { text-align: right; font-size: 12px; color: var(--muted); }
input[data-ac=fabric], input[data-ac=fcolor], input[data-ac=pcolor], input[data-ac=qtyUnit] {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236b766f' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 6px center; padding-right: 20px;
}
/* 图片格子 */
.pimgs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.pimgs.wide { grid-template-columns: repeat(4, 1fr); }
.pslot {
  position: relative; border: 1px dashed #c9d1cc; border-radius: 8px; background: var(--readonly); color: var(--muted);
  min-height: 130px; display: flex; align-items: center; justify-content: center; cursor: pointer; overflow: hidden;
}
.pslot:hover, .pslot.drop { border-color: var(--accent); color: var(--accent); }
.pslot img { max-width: 100%; max-height: 180px; display: block; }
.pslot.small { min-height: 46px; width: 64px; margin: 0 auto; font-size: 12px; }
.pslot.small img { max-height: 46px; }
.pslot-del {
  position: absolute; top: 4px; right: 4px; border: none; border-radius: 50%; width: 24px; height: 24px; padding: 0;
  background: rgba(0,0,0,.55); color: #fff; font-size: 12px; line-height: 24px;
}
.pslot.small .pslot-del { width: 18px; height: 18px; line-height: 18px; top: 2px; right: 2px; font-size: 10px; }
.prod-list td.c-date, .prod-list td.c-no, .prod-list td.c-cust, .prod-list td.c-item, .prod-list td.c-oq, .prod-list td.c-upd { white-space: nowrap; }
.prod-list td.c-act { flex-wrap: nowrap; }

@media (max-width: 900px) {
  .pgrid, .pgrid4 { grid-template-columns: 1fr 1fr; }
  .pgrid2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .pgrid { grid-template-columns: 1fr; }
  .pgrid4 { grid-template-columns: 1fr 1fr; }
  .pimgs.wide { grid-template-columns: repeat(2, 1fr); }
  .ptable.mcard .c-idx { display: none; }
  /* 配件：名称一行，用量·总数量一行，来源·颜色一行，1公斤数量·KG·损耗一行 */
  #pparts tr { grid-template-columns: 1fr 1fr 1fr auto;
    grid-template-areas: "name name name del" "usage total total total" "src color color color" "perkg kg loss loss"; }
  #pparts .c-usage { grid-area: usage; } #pparts .c-total { grid-area: total; } #pparts .c-src { grid-area: src; }
  #pparts .c-color { grid-area: color; } #pparts .c-perkg { grid-area: perkg; } #pparts .c-kg { grid-area: kg; } #pparts .c-loss { grid-area: loss; }
  #pflist tr { grid-template-columns: 1fr 1fr 1fr auto; grid-template-areas: "fab mold mold del" "usage oq total total"; }
  #pflist .c-fab { grid-area: fab; } #pflist .c-mold { grid-area: mold; } #pflist .c-usage { grid-area: usage; }
  #pflist .c-oq { grid-area: oq; display: block; } #pflist .c-total { grid-area: total; }
  #pcut tr { grid-template-columns: 1fr 1fr 1fr auto;
    grid-template-areas: "name name fab del" "mold mold qty qty" "usage spec pieces pieces" "img bundles note note"; }
  #pcut .c-qty { grid-area: qty; } #pcut .c-mold { grid-area: mold; } #pcut .c-fab { grid-area: fab; }
  #pcut .c-usage { grid-area: usage; } #pcut .c-spec { grid-area: spec; } #pcut .c-pieces { grid-area: pieces; }
  #pcut .c-img { grid-area: img; } #pcut .c-bundles { grid-area: bundles; } #pcut .c-note { grid-area: note; }
  #pcut .pslot.small { margin: 0; width: 100%; }
  /* 生产单列表卡片 */
  .prod-list.mcard tbody tr { grid-template-columns: 52px 1fr 1fr auto; gap: 4px 10px;
    grid-template-areas: "thumb no no kind" "thumb prod prod prod" "thumb cust cust oq" "thumb item item item" "thumb date date date" "chk act act act"; }
  .prod-list.mcard td { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .prod-list.mcard .c-upd { display: none; }
  .prod-list.mcard .c-oq { text-align: right; }
  .prod-list.mcard .c-no { grid-area: no; } .prod-list.mcard .c-kind { grid-area: kind; justify-self: end; }
  .prod-list.mcard .c-date { grid-area: date; font-size: 12px; }
  .prod-list.mcard .c-upd { white-space: nowrap; }
  .prod-list.mcard .c-chk { align-self: center; justify-self: center; }
  .prod-list.mcard .c-chk input { width: 20px; height: 20px; }
  .prod-list.mcard .c-act { flex-wrap: nowrap; gap: 4px; }
  .prod-list.mcard .c-act .small { padding: 4px 8px; }
  .prod-list.mcard td:empty { display: none; }
}

/* 打印：生产单（宋体、黑色细框线，和纸质单一样） */
@media print {
  #printSheet .prod-page { padding-top: 0; }
  #printSheet .pblock { break-inside: avoid; margin-bottom: 9mm; }
  #printSheet .pblock:last-child { margin-bottom: 0; }
  #printSheet .ptitle { font: 700 17px "Songti SC", "STSong", SimSun, serif; text-align: center; margin: 0 0 4px; letter-spacing: 1px; }
  #printSheet .pt { border: 1px solid #000; font-size: 11.5px; }
  #printSheet .pt td { height: 6.2mm; padding: 0 4px; line-height: 1.2; }
  #printSheet .pt .c { text-align: center; }
  #printSheet .pt .r { text-align: right; }
  #printSheet .pt .b { font-weight: 700; }
  #printSheet .pt tr.th td { text-align: center; font-weight: 700; height: 7mm; }
  #printSheet .pt .sm, #printSheet .pp tr.th td.sm { font-size: 9.5px; }
  #printSheet .pt .yellow { background: #ffe699 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #printSheet .pt .cream { background: #fbefc9 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #printSheet .ph { margin-bottom: 3mm; }
  #printSheet .ph td { height: 7.5mm; }
  #printSheet .ph .blank { display: inline-block; min-width: 10mm; text-align: center; }
  #printSheet .pt .sp { font-size: 10px; white-space: nowrap; padding: 0 1px; }
  #printSheet .pt.names { border: none; }
  #printSheet .pt.names td { border: none; height: 5.5mm; text-align: center; font-weight: 700; font-size: 11px; }
  #printSheet .pf, #printSheet .pp { margin-top: -1px; }
  #printSheet .pf tr.sum td { font-weight: 700; }
  #printSheet .pt .pic { padding: 1mm; text-align: center; vertical-align: middle; }
  #printSheet .ppics { display: grid; gap: 1mm; align-items: center; justify-items: center; }
  #printSheet .ppics.n2, #printSheet .ppics.n3, #printSheet .ppics.n4 { grid-template-columns: 1fr 1fr; }
  #printSheet .ppics img { max-width: 100%; max-height: 40mm; object-fit: contain; display: block; margin: 0; }
  #printSheet .ppics.n3 img, #printSheet .ppics.n4 img { max-height: 20mm; }
  /* 冲布·染色单 */
  #printSheet .pc td { height: 8mm; }
  #printSheet .pt .nw { white-space: nowrap; font-size: 10.5px; padding: 0 2px; }
  #printSheet .pc .big { font-size: 13px; letter-spacing: 1px; }
  #printSheet .pc tr.crow td { height: 17mm; }
  #printSheet .pc .pic img { max-width: 100%; max-height: 15mm; margin: 0 auto; display: block; }
  #printSheet .pphotos { display: flex; gap: 5mm; margin-top: 6mm; justify-content: flex-start; }
  #printSheet .pphotos img { flex: 0 1 auto; max-width: calc(25% - 4mm); max-height: 80mm; object-fit: contain; }
}

/* 「打印 / 导出成本单」菜单、提示条 */
.menu-pop { position: fixed; z-index: 50; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.15); overflow: hidden; min-width: 190px; }
.menu-pop button { display: block; width: 100%; text-align: left; border: none; border-radius: 0; padding: 11px 16px; }
.menu-pop button + button { border-top: 1px solid var(--line); }
.menu-pop button:hover { background: var(--accent-soft); color: var(--accent); }
.toast { position: fixed; left: 50%; top: 64px; transform: translate(-50%, -20px); opacity: 0; pointer-events: none; z-index: 70;
  background: #1f2a24; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: min(520px, 92vw);
  box-shadow: 0 8px 24px rgba(0,0,0,.25); transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media print { .menu-pop, .toast { display: none !important; } }

/* 表格里的操作按钮格子：保持普通表格格子（不用 flex），这样和同一行其它格子一样高、底线对齐 */
@media (min-width: 641px) {
  td.actions { display: table-cell; white-space: nowrap; vertical-align: middle; }
  td.actions > * { vertical-align: middle; }
  td.actions > * + * { margin-left: 6px; }
}

/* 汇率：「↻ 今日」小按钮 + 下面的今日汇率说明 */
.fx-btn { border: none; background: none; color: var(--accent); padding: 0 0 0 4px; font-size: 12px; }
.fx-btn:hover { text-decoration: underline; }
.fx-note { margin-top: 8px; min-height: 18px; }
.fx-today { padding: 8px 10px; background: var(--readonly); border: 1px solid var(--line); border-radius: 6px; line-height: 1.7; }
