:root {
  --brand: #2f6b4f;
  --brand-light: #e8f2ec;
  --brand-dark: #23503c;
  --danger: #c0392b;
  --warn: #d68910;
  --ok: #27ae60;
  --text: #1f2a24;
  --text-sub: #6b7a72;
  --line: #dfe6e1;
  --bg: #f4f7f5;
  --card: #ffffff;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.04);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 15px; line-height: 1.55;
  overscroll-behavior-y: none;
}

/* ---------- 布局 ---------- */
#app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--brand); color: #fff;
  padding: 12px 16px calc(12px + env(safe-area-inset-top, 0px));
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: .5px; }
.topbar .user {
  font-size: 12px; opacity: .9; background: rgba(255,255,255,.18);
  padding: 4px 10px; border-radius: 20px; cursor: pointer;
}

.main {
  flex: 1; padding: 14px 14px calc(80px + env(safe-area-inset-bottom, 0px));
  max-width: 720px; width: 100%; margin: 0 auto;
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  background: #fff; border-top: 1px solid var(--line);
  display: flex;
  /* 页签会随角色变化（本地 9 个 / 云端店员 4 个）。
     9 个平摊到 375px 宽屏上每格约 41px，"组装单"会挤到换行变形。
     改成横向可滚动：每格保底 58px，超出部分左右滑。 */
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabbar::-webkit-scrollbar { display: none; }
.tabbar button {
  flex: 1 0 auto; min-width: 58px; border: 0; background: none; padding: 8px 4px 7px;
  font-size: 11px; color: var(--text-sub); cursor: pointer; white-space: nowrap;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-family: inherit; transition: color .15s;
}
.tabbar button .ico { font-size: 19px; line-height: 1; }
.tabbar button.active { color: var(--brand); font-weight: 600; }

/* ★ 2026-10-17 底部栏末尾的「导航」按钮（回 nav.html 场景首页）
   和页签并排但视觉上要区分开：左边一道细分割线 + 常驻不滚动（sticky right），
   这样哪怕本地模式 10 个页签超出屏幕要左右滑，导航按钮也始终露在最右边。
   注意：它不带 data-tab，navigate() 的 active 逻辑不会点亮它。 */
.tabbar button[data-nav] {
  position: sticky; right: 0; z-index: 1;
  background: #fff;
  box-shadow: -1px 0 0 var(--line);
  color: var(--text-sub);
}
.tabbar button[data-nav]:active { color: var(--brand); }

/* ---------- 卡片 / 通用 ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px;
}
.card-title {
  font-size: 15px; font-weight: 600; margin: 0 0 10px;
  display: flex; align-items: center; justify-content: space-between;
}
.card-title small { font-weight: 400; color: var(--text-sub); font-size: 12px; }

/* ---------- 开单页：已选标记 / 已选面板（2026-10-27） ---------- */
.sale-row.is-picked {
  box-shadow: -3px 0 0 var(--brand), var(--shadow);
  background: #f7fbf9;
}
.sale-row.is-picked input[data-cq] {
  color: var(--brand-dark); font-weight: 700; border-color: var(--brand);
}
.pick-row .qs { flex: 0 0 auto; gap: 3px; }
.pick-row .qs .qs-b { width: 30px; height: 32px; font-size: 17px; border-radius: 8px; }
.pick-row .qs .qs-i { flex: 0 0 auto; width: 42px; padding: 7px 2px; font-size: 13.5px; text-align: center; }
.pick-row:last-child { border-bottom: 0; }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 4px 2px 10px;
}
.section-head h2 { font-size: 16px; margin: 0; font-weight: 600; }

/* ---------- 按钮 ---------- */
.btn {
  border: 0; border-radius: 9px; padding: 10px 16px;
  font-size: 14px; font-family: inherit; cursor: pointer; font-weight: 500;
  background: var(--brand); color: #fff; transition: .15s; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--brand); border: 1px solid var(--brand); }
.btn.grey { background: #eef2f0; color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.danger-ghost { background: #fff; color: var(--danger); border: 1px solid var(--danger); }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 7px; }
.btn.block { width: 100%; display: block; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 12px; }
.field label {
  display: block; font-size: 13px; color: var(--text-sub);
  margin-bottom: 5px; font-weight: 500;
}
.field label .req { color: var(--danger); }
input, select, textarea {
  width: 100%; padding: 11px 12px; font-size: 15px; font-family: inherit;
  border: 1px solid var(--line); border-radius: 9px; background: #fff;
  color: var(--text); transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-light);
}
input[readonly] { background: #f5f7f6; color: var(--text-sub); }
/* 单选 / 复选框不吃上面全局 input 的 width:100% + 大内边距，
   否则在 flex 行里会把旁边文字挤成一字一行竖排（收货「剩余怎么处理」事故） */
input[type="radio"], input[type="checkbox"] {
  width: auto; padding: 0; margin: 0; flex: 0 0 auto;
  accent-color: var(--brand);
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- 数量步进（2026-10-21） ---------- */
/*
 * 干掉浏览器自带的上下箭头：
 * 手机上根本点不准，电脑上又是 0.001 一跳，5 变 5.001 谁也看不出来。
 * 数量统一改用下面的 ± 按钮（成品 1 件、材料 0.1），金额等其它字段直接手输。
 */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

.qs { display: flex; align-items: center; gap: 5px; min-width: 0; }
.qs .qs-i { flex: 1 1 auto; min-width: 0; text-align: center; padding: 9px 4px; }
.qs .qs-b {
  flex: 0 0 auto; width: 34px; height: 36px; padding: 0;
  border: 1px solid var(--line); border-radius: 9px; background: #fff;
  color: var(--text); font-size: 19px; line-height: 1; font-family: inherit;
  cursor: pointer; -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.qs .qs-b:active { background: var(--brand-light); border-color: var(--brand); }
.qs .qs-b:disabled { opacity: .4; cursor: default; }
.qs .qs-unit {
  flex: 0 0 auto; font-size: 12px; color: var(--text-sub); white-space: nowrap;
}
/* 表格里窄一些，手机上一行能放得下 */
td .qs { gap: 4px; }
td .qs .qs-b { width: 30px; height: 32px; font-size: 17px; border-radius: 7px; }
td .qs .qs-i { padding: 7px 3px; font-size: 14px; }
/* 表格里用：不要撑满整格，跟着内容走 */
.qs.qs-tight { width: auto; justify-content: flex-end; }
.qs.qs-tight .qs-i { flex: 0 0 auto; }

/* ---------- 列表 ---------- */
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: 0; }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title {
  font-weight: 600; font-size: 14.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list-item .li-sub { font-size: 12.5px; color: var(--text-sub); margin-top: 2px; }
.list-item .li-right { text-align: right; font-size: 13px; flex-shrink: 0; }

/* 商品缩略图 */
.li-thumb {
  width: 48px; height: 48px; flex: 0 0 auto; border-radius: 9px;
  background: #eef2f0 center/cover no-repeat;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: #b9c4bd; overflow: hidden;
  border: 1px solid var(--line);
}

/* 供应商卡片 */
.sup-card { padding: 13px 14px; }
.sup-pitfall {
  margin-top: 8px; padding: 7px 10px; border-radius: 7px;
  background: #fdf3e3; color: #8a6516; font-size: 12.5px; line-height: 1.5;
}

/* 底部导航 7 项时字号收一点 */
.tabbar button .ico { font-size: 19px; line-height: 1; }
@media (max-width: 380px) {
  .tabbar button { font-size: 10px; padding: 7px 1px 6px; }
  .tabbar button .ico { font-size: 17px; }
  /* 窄屏多一个「导航」钮，再压一档宽度，少滑一点 */
  .tabbar button { min-width: 54px; }
}

.empty {
  text-align: center; padding: 40px 20px; color: var(--text-sub); font-size: 14px;
}
.empty .big { font-size: 34px; display: block; margin-bottom: 10px; opacity: .35; }

/* ---------- 徽标 ---------- */
.tag {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.tag.pending { background: #fdf3e3; color: var(--warn); }
.tag.done { background: #e6f6ec; color: var(--ok); }
.tag.own { background: var(--brand-light); color: var(--brand); }
.tag.mat { background: #eef1f6; color: #4a5b78; }
.tag.short { background: #fdecea; color: var(--danger); }
/* 材料类别专用配色（2026-10-15 扩到 8 档，要求彼此可区分） */
.tag.lilac { background: #f2ecfb; color: #7a5bbd; }  /* 配件 */
.tag.teal { background: #e3f4f1; color: #2f8a80; }   /* 布料 */
.tag.gold { background: #fbf0d9; color: #a3751a; }   /* 宋锦底胚 */
.tag.slate { background: #efedea; color: #6b6459; }  /* 包材 */

/* ---------- 数字强调 ---------- */
.num { font-variant-numeric: tabular-nums; font-weight: 600; }
.hl { color: var(--brand); font-weight: 700; }

/* ---------- 浮层 / 弹窗 ---------- */
.mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 100; display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn .18s;
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

.sheet {
  background: #fff; width: 100%; max-width: 720px;
  border-radius: 16px 16px 0 0; max-height: 92vh; overflow-y: auto;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  animation: slideUp .22s cubic-bezier(.2,.8,.3,1);
}
@keyframes slideUp { from { transform: translateY(100%) } to { transform: translateY(0) } }

.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; position: sticky; top: -18px; background: #fff;
  padding: 4px 0 10px; z-index: 2;
}
.sheet-head h3 { margin: 0; font-size: 16.5px; }
.sheet-head .close {
  border: 0; background: #eef2f0; width: 30px; height: 30px; border-radius: 50%;
  font-size: 17px; color: var(--text-sub); cursor: pointer; line-height: 1;
}

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: rgba(31,42,36,.94); color: #fff; padding: 11px 20px;
  border-radius: 22px; font-size: 14px; z-index: 200;
  opacity: 0; pointer-events: none; transition: opacity .22s; max-width: 84vw; text-align: center;
}
#toast.show { opacity: 1; }

/* ---------- 看板数字卡 ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat {
  background: #fff; border-radius: var(--radius); padding: 13px 14px;
  box-shadow: var(--shadow);
}
.stat .k { font-size: 12.5px; color: var(--text-sub); }
.stat .v { font-size: 23px; font-weight: 700; color: var(--brand); margin-top: 3px; font-variant-numeric: tabular-nums; }
.stat .u { font-size: 12px; color: var(--text-sub); font-weight: 400; margin-left: 3px; }
.stat .s { font-size: 11.5px; color: var(--text-sub); margin-top: 4px; line-height: 1.4; }
.stat.clickable { cursor: pointer; }
.stat.on { outline: 2px solid var(--brand); outline-offset: -2px; }

/* ---------- 需求表（核心展示） ---------- */
.req-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.req-table th {
  background: var(--brand-light); color: var(--brand-dark);
  font-weight: 600; padding: 8px 6px; text-align: left; font-size: 12.5px;
  position: sticky; top: 0;
}
.req-table td { padding: 9px 6px; border-bottom: 1px solid var(--line); }
.req-table td.n, .req-table th.n { text-align: right; font-variant-numeric: tabular-nums; }
.req-table tr:last-child td { border-bottom: 0; }

.hint {
  background: #fffbee; border-left: 3px solid var(--warn);
  padding: 10px 12px; border-radius: 0 8px 8px 0; font-size: 13px;
  color: #7a5c14; margin-bottom: 12px; line-height: 1.5;
}
.hint.info { background: #eef6ff; border-left-color: #3b82c4; color: #2a5580; }

/* ---------- 列表分页 ---------- */
.pager {
  display: flex; align-items: center; justify-content: center;
  gap: 6px; flex-wrap: wrap; padding: 12px 4px 4px;
}
.pager .pg-info {
  font-size: 12.5px; color: var(--text-sub);
  font-variant-numeric: tabular-nums; margin: 0 4px;
}
.pager .btn.sm { padding: 6px 10px; }

/* ---------- 智能录入（截图 / 文字 → 表单） ---------- */
.ai-drop {
  border: 1.5px dashed var(--line); border-radius: 10px;
  padding: 12px; background: #fbfdfc;
}
.ai-thumbs { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-bottom: 8px; }
.ai-thumb {
  position: relative; width: 76px; height: 76px; border-radius: 8px;
  overflow: hidden; background: var(--bg); border: 1px solid var(--line);
}
.ai-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ai-thumb button {
  position: absolute; right: 2px; top: 2px; width: 20px; height: 20px;
  line-height: 18px; border: none; border-radius: 50%; padding: 0;
  background: rgba(0, 0, 0, .5); color: #fff; font-size: 14px; cursor: pointer;
}
.ai-item { border-left: 3px solid var(--brand); }
/* AI 识别回填的字段：黄底提醒「这是猜的，要核对」 */
input.ai-filled, textarea.ai-filled, select.ai-filled {
  background: #fffbe6; border-color: #e6c764;
}
input.ai-filled:focus, textarea.ai-filled:focus, select.ai-filled:focus {
  background: #fffbe6; border-color: #d9ae2f;
}

/* ---------- 无持久化提示条（预览沙箱环境） ---------- */
.no-persist {
  background: #fff4e5;
  border-bottom: 1px solid #f0c98a;
  color: #8a5a12;
  font-size: 12.5px;
  line-height: 1.5;
  padding: 8px 14px;
  text-align: center;
}

/* ---------- 报表页：分表切换 ---------- */
.rseg{display:flex;gap:6px;margin:0 0 10px;overflow-x:auto;padding-bottom:2px;-webkit-overflow-scrolling:touch}
.rseg-btn{
  flex:0 0 auto;cursor:pointer;white-space:nowrap;
  border:1px solid var(--line);background:var(--card);color:var(--text-sub);
  border-radius:999px;padding:7px 15px;font-size:13px;line-height:1.2;
}
.rseg-btn.on{background:var(--brand);border-color:var(--brand);color:#fff;font-weight:600}

/* ---------- 库存表里的商品照片 ---------- */
.st-thumb{
  flex:0 0 auto;width:34px;height:34px;border-radius:8px;
  background:#eef3f0 center/cover no-repeat;
  display:inline-flex;align-items:center;justify-content:center;
  font-size:16px;line-height:1;overflow:hidden;
}

/* ---------- 打印（组装工单等） ----------
   打印时只留 #print-root，页面其余部分（含弹层、页签、错误条）全部隐藏。
   ★ 打印区自带完整样式，不依赖主题变量 —— 打印机的白纸黑字跟屏幕配色不是一回事。 */
#print-root { display: none; }

@media print {
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block !important; }
  @page { size: A4 portrait; margin: 12mm; }

  #print-root { color: #000; font-size: 12px; line-height: 1.5; }
  #print-root .p-title { font-size: 18px; font-weight: 700; text-align: center; margin-bottom: 4px; }
  #print-root .p-sub { text-align: center; color: #666; font-size: 11px; margin-bottom: 12px; }
  #print-root .p-meta { border: 1px solid #333; padding: 8px 10px; margin-bottom: 12px; }
  #print-root .p-meta div { display: flex; justify-content: space-between; padding: 2px 0; }
  #print-root .p-meta b { font-weight: 700; }
  #print-root table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
  #print-root th, #print-root td { border: 1px solid #333; padding: 5px 6px; text-align: left; }
  #print-root th { background: #eee; font-weight: 700; }
  #print-root td.n, #print-root th.n { text-align: right; }
  #print-root td.c, #print-root th.c { text-align: center; }
  #print-root tr { break-inside: avoid; }
  #print-root .p-fee { border: 1px solid #333; padding: 8px 10px; margin-bottom: 12px; }
  #print-root .p-sign { margin-top: 24px; display: flex; justify-content: space-between; font-size: 11px; }
  #print-root .p-foot { margin-top: 10px; font-size: 10px; color: #888; text-align: center; }
}
