/* ================= GEM OIL · 设计系统 ================= */
:root {
  --navy: #0b2545;
  --navy-2: #13315c;
  --navy-3: #1d4478;
  --bg: #f2f5f9;
  --surface: #ffffff;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --red: #d92d20;
  --red-bg: #fef3f2;
  --blue: #175cd3;
  --blue-bg: #eff8ff;
  --amber: #b54708;
  --amber-bg: #fffaeb;
  --green: #067647;
  --green-bg: #ecfdf3;
  --orange: #e8590c;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  --sidebar-w: 236px;
  --tabbar-h: 58px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

body {
  -webkit-user-select: none;
  user-select: none;
}
input, textarea, select { user-select: text; -webkit-user-select: text; }

a { color: var(--blue); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

/* ================= 布局 ================= */
#app { min-height: 100vh; }

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: linear-gradient(180deg, var(--navy) 0%, #0a1f3a 100%);
  color: #cbd8ea;
  padding: 18px 12px 14px;
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex: 0 0 34px;
  background: linear-gradient(135deg, #2f6fdb, #4f93ff);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 15px;
}
.brand-text { min-width: 0; }
.brand-name { color: #fff; font-weight: 700; font-size: 15px; letter-spacing: .04em; }
.brand-sub { color: #7f97b8; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 10px; border-radius: 9px; color: #b9c9de; font-size: 13.5px;
  cursor: pointer; white-space: nowrap; overflow: hidden;
  border: 0; background: none; width: 100%; text-align: left; font-family: inherit;
  min-height: 42px;
}
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-item.active { background: var(--navy-3); color: #fff; box-shadow: inset 0 0 0 1px rgba(255,255,255,.06); }
.nav-item .ni { width: 18px; text-align: center; flex: 0 0 18px; opacity: .9; font-size: 15px; }
.nav-item .nl { overflow: hidden; text-overflow: ellipsis; }
.nav-sep { height: 1px; background: rgba(255,255,255,.08); margin: 10px 6px; }
.nav-group { color: #6f89ab; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; padding: 10px 10px 4px; }
.sidebar-foot { margin-top: auto; padding: 10px 10px 0; color: #6f89ab; font-size: 11px; line-height: 1.6; }

.main { margin-left: var(--sidebar-w); flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 58px; flex: 0 0 58px;
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  background: rgba(255,255,255,.92);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.page-title { font-size: 15.5px; font-weight: 650; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.lang-switch { display: inline-flex; background: #eef2f7; border-radius: 9px; padding: 3px; gap: 2px; }
.lang-switch button {
  border: 0; background: transparent; color: var(--muted); font-size: 12px; font-weight: 600;
  padding: 5px 9px; border-radius: 7px; cursor: pointer; min-width: 34px; font-family: inherit;
}
.lang-switch button.active { background: #fff; color: var(--navy); box-shadow: 0 1px 2px rgba(15,23,42,.12); }

.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 4px; border-radius: 999px; background: #f1f5f9; max-width: 190px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--navy-2); color: #fff; display: grid; place-items: center; font-size: 11.5px; font-weight: 700; flex: 0 0 26px; }
.user-meta { min-width: 0; line-height: 1.15; }
.user-meta b { display: block; font-size: 12px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta span { display: block; font-size: 10.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn {
  border: 0; background: transparent; color: var(--muted); width: 36px; height: 36px;
  border-radius: 9px; cursor: pointer; font-size: 15px; display: grid; place-items: center;
}
.icon-btn:hover { background: #eef2f7; color: var(--text); }
.menu-btn { display: none; }

.view { padding: 20px; flex: 1; min-width: 0; }

/* ================= 通用组件 ================= */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }

/* 指导价口径切换（税后 / 税前）——只切换基准价，不做税点换算 */
.basis-switch { display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg-soft, #f8fafc); }
.basis-switch .bs-label { font-size: 11px; color: var(--muted); margin-right: 2px; white-space: nowrap; }
.basis-switch .bs-btn { border: 0; background: transparent; color: var(--muted); font-size: 11.5px; font-weight: 600; padding: 4px 9px; border-radius: 999px; cursor: pointer; white-space: nowrap; }
.basis-switch .bs-btn:hover { color: var(--ink); }
.basis-switch .bs-btn.on { background: var(--navy, #0b2545); color: #fff; }
.hint-box { margin-top: 10px; padding: 9px 11px; border-radius: 8px; background: var(--bg-soft, #f8fafc); border: 1px solid var(--line); font-size: 11.5px; line-height: 1.55; color: var(--muted); }

@media (max-width: 639px) {
  .basis-switch { padding: 2px 3px 2px 7px; }
  .basis-switch .bs-label { display: none; }
  .basis-switch .bs-btn { font-size: 11px; padding: 4px 8px; }
  /* 手机上让「明细 + 报价口径 + 两个添加按钮」挤在一行，避免多出一行空白 */
  .card-head.head-with-basis { gap: 6px; padding: 12px 12px; }
  .card-head.head-with-basis .spacer { display: none; }
  .card-head.head-with-basis h3 { font-size: 13px; }
  .card-head.head-with-basis .btn-sm { padding-left: 8px; padding-right: 8px; }
}

.card-head h3 { font-size: 14px; }
.card-body { padding: 16px; }

.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h2 { font-size: 17px; }
.page-head .spacer { margin-left: auto; }
.page-head .head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters .field { margin: 0; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 550; }
.field .hint { font-size: 11.5px; color: var(--muted-2); }

.input, .select, .textarea {
  width: 100%; min-height: 40px; padding: 9px 11px;
  border: 1px solid var(--line-strong); border-radius: 9px; background: #fff;
  font-family: inherit; font-size: 14px; color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s;
  max-width: 100%;
}
.textarea { min-height: 74px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: #4f93ff; box-shadow: 0 0 0 3px rgba(79,147,255,.16); }
.input:disabled, .select:disabled { background: #f6f8fb; color: var(--muted); }
.input-sm { min-height: 36px; padding: 7px 9px; font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 9px 16px; border-radius: 9px;
  border: 1px solid transparent; background: #eef2f7; color: var(--text);
  font-family: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer;
  white-space: normal; text-align: center; line-height: 1.25;
  transition: filter .15s, background .15s;
  max-width: 100%;
}
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--navy-2); color: #fff; }
.btn-primary:hover { background: var(--navy-3); }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: #fff; border-color: var(--line-strong); color: var(--text); }
.btn-ghost:hover { background: #f8fafc; }
.btn-link { background: none; border: 0; color: var(--blue); padding: 4px 2px; min-height: 32px; font-weight: 600; cursor: pointer; font-family: inherit; font-size: 13px; }
.btn-sm { min-height: 34px; padding: 6px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 650;
  background: #eef2f7; color: #475569; white-space: nowrap;
}
.badge-ok { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-red-strong { background: var(--red); color: #fff; }
.badge-warn { background: var(--amber-bg); color: var(--amber); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-muted { background: #f1f5f9; color: var(--muted); }
.badge-yellow { background: #fef7e6; color: #b54708; }

.money { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }.num { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.strong { font-weight: 650; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.hide { display: none !important; }

/* ================= 表格 ================= */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { font-size: 11.5px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .04em; background: #f8fafc; white-space: normal; }
.table tbody tr:hover { background: #fafcff; }
.table td.num, .table th.num { text-align: right; }
.table .row-void td { color: var(--muted-2); text-decoration: line-through; }
.table .row-void .no-strike { text-decoration: none; }
.table-click tbody tr { cursor: pointer; }
.cellstack { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.table-cards td::before { content: none; }

/* ================= 页脚 / 分页 ================= */
.pager { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.pager .pinfo { color: var(--muted); font-size: 12px; }
.pager .spacer { margin-left: auto; }

/* ================= 登录页 ================= */
.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 15% 0%, #1b4079 0%, #0b2545 55%, #071a30 100%);
}
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 16px; padding: 28px 26px 24px; box-shadow: 0 24px 60px rgba(2, 12, 27, .45); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-brand .brand-mark { width: 42px; height: 42px; flex-basis: 42px; font-size: 17px; }
.login-brand h1 { font-size: 18px; letter-spacing: .04em; }
.login-brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.login-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.login-actions .btn { flex: 1; min-height: 46px; }
.login-foot { margin-top: 16px; text-align: center; color: var(--muted-2); font-size: 11.5px; }
.login-ver { margin-top: 6px; text-align: center; color: var(--muted-2); font-size: 11px; letter-spacing: .02em; min-height: 15px; }

/* ================= 首页 ================= */
.hero-search { position: relative; margin-bottom: 18px; }
.hero-search input {
  width: 100%; height: 52px; font-size: 15px; padding: 0 16px 0 44px;
  border-radius: 12px; border: 1px solid var(--line); background: #fff;
  box-shadow: var(--shadow); outline: none; font-family: inherit;
}
.hero-search input:focus { border-color: #9cc4ff; box-shadow: 0 0 0 4px rgba(79,147,255,.14); }
.hero-search .ic { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--muted-2); font-size: 16px; }
.search-panel { position: absolute; left: 0; right: 0; top: 58px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 18px 40px rgba(15,23,42,.14); z-index: 25; max-height: 60vh; overflow-y: auto; }
.search-group-title { padding: 10px 14px 6px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.search-row { display: flex; gap: 10px; align-items: center; padding: 10px 14px; cursor: pointer; border-top: 1px solid #f1f5f9; }
.search-row:hover { background: #f8fbff; }
.search-row .grow { min-width: 0; }
.search-row .t1 { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-row .t2 { font-size: 11.5px; color: var(--muted); }

.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.stat .k { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.stat .v { font-size: 21px; font-weight: 700; font-family: var(--mono); letter-spacing: -.02em; overflow: hidden; text-overflow: ellipsis; }
.stat .v.sm { font-size: 17px; }
.stat.danger .v { color: var(--red); }
.stat.warn .v { color: var(--amber); }
.stat.ok .v { color: var(--green); }

.quick-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.quick-tile { display: flex; align-items: center; gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff; cursor: pointer; font-weight: 600; font-size: 13px; }
.quick-tile:hover { border-color: #9cc4ff; background: #f8fbff; }
.quick-tile .qi { font-size: 17px; color: var(--navy-2); }

/* ================= 开单页 ================= */
.order-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 16px; align-items: start; }
.order-main { min-width: 0; }
.order-side { position: sticky; top: 74px; }

.cust-box { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.cust-box .cname { font-weight: 700; font-size: 15px; }
.cust-box .carea { color: var(--muted); font-size: 12px; }
.cust-empty { padding: 18px; text-align: center; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: 12px; background: #fbfdff; }

.credit-bar { margin-top: 10px; padding: 10px 13px; border-radius: 10px; font-size: 12.5px; font-weight: 600; border: 1px solid transparent; }
.credit-ok { background: var(--green-bg); color: var(--green); border-color: #abefc6; }
.credit-warn { background: var(--amber-bg); color: var(--amber); border-color: #fedf89; }
.credit-bad { background: var(--red-bg); color: var(--red); border-color: #fecdca; }

.items { display: flex; flex-direction: column; gap: 10px; }
.item-row { border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: 12px; display: grid; grid-template-columns: minmax(0, 1fr) 92px 128px 118px 36px; gap: 10px; align-items: center; }
.item-row .iname { font-weight: 650; font-size: 13.5px; }
.item-row .ispec { color: var(--muted); font-size: 11.5px; }
.item-row .iline { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.item-row .price-cell { display: flex; flex-direction: column; gap: 4px; }
.item-row.freight { background: #f8fafc; border-style: dashed; }
.item-row .rm { color: var(--muted); }

.price-diff { font-weight: 700; }
/* 注意：.item-row .iline 的权重高于单类，涨跌色必须写成 .item-row .iline.pd-* 才生效 */
.pd-low { color: var(--red); }
.pd-high { color: var(--blue); }
.item-row .iline.pd-low, .item-row .iline.pd-low .price-diff { color: var(--red); }
.item-row .iline.pd-high, .item-row .iline.pd-high .price-diff { color: var(--blue); }
.item-row input.pd-low { color: var(--red); font-weight: 700; }
.item-row input.pd-high { color: var(--blue); font-weight: 700; }
.pill { display: inline-block; padding: 1px 6px; border-radius: 999px; font-size: 10.5px; font-weight: 700; margin-left: 5px; vertical-align: 1px; }
.pill-low { background: var(--red); color: #fff; }
.pill-high { background: var(--blue); color: #fff; }

.totals { display: flex; flex-direction: column; gap: 8px; }
.totals .trow { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.totals .trow .k { color: var(--muted); }
.totals .grand { border-top: 1px dashed var(--line-strong); padding-top: 10px; margin-top: 4px; font-size: 15px; font-weight: 700; }
.totals .grand .money { font-size: 18px; }

.mobile-submit { display: none; }

/* 全屏客户搜索层 */
.sheet { position: fixed; inset: 0; background: #fff; z-index: 60; display: flex; flex-direction: column; }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); padding-top: calc(12px + env(safe-area-inset-top)); }
.sheet-body { flex: 1; overflow-y: auto; padding: 12px 14px calc(16px + env(safe-area-inset-bottom)); }
.sheet-item { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 12px 6px; border-bottom: 1px solid #f1f5f9; cursor: pointer; }
.sheet-item:hover { background: #f8fbff; }
.sheet-empty { padding: 30px 10px; text-align: center; color: var(--muted); }

/* ================= 空 / 错 / 载入 ================= */
.empty-state { padding: 44px 16px; text-align: center; color: var(--muted); font-size: 13px; }
.error-state { padding: 36px 16px; text-align: center; color: var(--red); display: flex; flex-direction: column; gap: 12px; align-items: center; }
.skeleton-wrap { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.skeleton-row { display: flex; gap: 10px; }
.sk { display: block; height: 14px; border-radius: 6px; background: linear-gradient(90deg, #eef2f7 25%, #f7f9fc 37%, #eef2f7 63%); background-size: 400% 100%; animation: sk 1.4s ease infinite; }
.sk-a { width: 38%; }
.sk-b { flex: 1; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ================= 弹窗 / 提示 ================= */
.modal-wrap { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(8, 20, 37, .55); backdrop-filter: blur(2px); }
.modal {
  position: relative; background: #fff; border-radius: 14px; width: 100%; max-width: 460px;
  max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 24px 60px rgba(2,12,27,.4);
}
.modal-wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); gap: 10px; }
.modal-head h3 { font-size: 14.5px; flex: 1; min-width: 0; }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.confirm-text { margin: 0; font-size: 13.5px; line-height: 1.6; }

#toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 120; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(92vw, 460px); }
.toast { background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; box-shadow: 0 10px 30px rgba(2,12,27,.3); opacity: 1; transition: opacity .4s; max-width: 100%; text-align: center; }
.toast-ok { background: #05603a; }
.toast-error { background: #912018; }
.toast-out { opacity: 0; }

/* ================= 水印 ================= */
#watermark {
  position: fixed; inset: 0; pointer-events: none; z-index: 45; opacity: .5;
  background-repeat: repeat; background-position: 0 0;
}

/* ================= 底部 tab（手机） ================= */
.tabbar { display: none; }

/* ================= 响应式 ================= */
@media (max-width: 1023px) {
  :root { --sidebar-w: 64px; }
  .sidebar { padding: 14px 8px; align-items: center; }
  .brand { padding: 4px 0 14px; justify-content: center; }
  .brand-text { display: none; }
  .nav-item { justify-content: center; padding: 10px 6px; }
  .nav-item .nl { display: none; }
  .nav-item .ni { flex: 0 0 auto; font-size: 17px; }
  .nav-group { display: none; }
  .sidebar-foot { display: none; }
  .order-layout { grid-template-columns: minmax(0, 1fr); }
  .order-side { position: static; }
  .item-row { grid-template-columns: minmax(0, 1fr) 80px 110px 100px 32px; }
}

@media (max-width: 639px) {
  :root { --sidebar-w: 0px; }
  html, body { font-size: 14px; }
  .sidebar { display: none; }
  .main { margin-left: 0; padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .topbar { height: 54px; flex-basis: 54px; padding: 0 12px; gap: 8px; }
  .menu-btn { display: grid; }
  .view { padding: 12px 12px 18px; }
  .page-title { font-size: 14.5px; }
  .user-chip { display: none; }
  .lang-switch button { min-width: 30px; padding: 5px 7px; font-size: 11.5px; }

  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(255,255,255,.97); border-top: 1px solid var(--line);
    backdrop-filter: blur(8px);
  }
  .tab {
    flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 3px; font-size: 10.5px; color: var(--muted); font-family: inherit;
    min-height: 44px; cursor: pointer; padding: 4px 2px;
  }
  .tab .ti { font-size: 17px; line-height: 1; }
  .tab.active { color: var(--navy-2); font-weight: 700; }

  /* 表单全部 16px，避免 iOS 自动放大 */
  .input, .select, .textarea, .hero-search input { font-size: 16px; }
  .btn { min-height: 44px; font-size: 14px; }
  .btn-sm { min-height: 38px; font-size: 13px; }
  .icon-btn { width: 44px; height: 44px; }
  .filters { gap: 8px; }
  .filters .field { flex: 1 1 46%; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px; }
  .stat .v { font-size: 17px; }

  /* 宽表格 → 卡片 */
  .table-wrap.cards { overflow: visible; }
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr {
    background: #fff; border: 1px solid var(--line); border-radius: 12px;
    padding: 6px 12px 10px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(15,23,42,.04);
  }
  .table-cards tbody tr:hover { background: #fff; }
  .table-cards td {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
    padding: 6px 0; border-bottom: 1px dashed #eef2f7; text-align: right; font-size: 13px;
  }
  .table-cards td:last-child { border-bottom: 0; }
  .table-cards td::before {
    content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 550;
    text-align: left; flex: 0 0 auto; max-width: 45%;
  }
  .table-cards td.no-label::before { display: none; }
  .table-cards td.no-label { justify-content: flex-end; }
  .table-cards td .cellstack { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; min-width: 0; text-align: right; }
  .table-cards td.cell-main { border-bottom: 1px solid var(--line); padding: 6px 0 10px; }
  .table-cards td.cell-main::before { display: none; }
  .table-cards td.cell-main .cm { font-weight: 700; font-size: 14px; text-align: left; }
  .table-cards td.num { justify-content: space-between; }

  /* 开单页 */
  .order-layout { display: block; }
  .order-side { display: none; }
  .item-row { position: relative; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; padding: 12px; }
  .item-row .iname-wrap { grid-column: 1 / -1; padding-right: 34px; }
  .item-row .qty-cell { grid-column: 1 / 2; }
  .item-row .price-cell { grid-column: 2 / 3; }
  .item-row .line-cell {
    grid-column: 1 / -1; display: flex; align-items: baseline; justify-content: space-between;
    gap: 10px; border-top: 1px dashed var(--line); padding-top: 8px; margin-top: 2px; text-align: left;
  }
  .item-row .line-cell .tiny.muted { margin: 0; }
  .item-row .rm-cell { position: absolute; top: 6px; right: 6px; }
  .item-row .rm-cell .btn { min-height: 34px; }
  .item-row.freight { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

  .order-page-pad { padding-bottom: 156px; }

  .page-head .head-actions { width: 100%; justify-content: flex-end; display: flex; gap: 8px; flex-wrap: wrap; }

  .mobile-submit {
    display: block; position: fixed; left: 0; right: 0;
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    background: #fff; border-top: 1px solid var(--line); padding: 10px 14px;
    z-index: 48; box-shadow: 0 -6px 18px rgba(15,23,42,.06);
  }
  .mobile-submit .ms-row { display: flex; align-items: center; gap: 10px; }
  .mobile-submit .ms-total { flex: 1; min-width: 0; }
  .mobile-submit .ms-k { font-size: 11px; color: var(--muted); }
  .mobile-submit .ms-v { font-size: 17px; font-weight: 700; font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; }
  .mobile-submit .btn { flex: 0 0 auto; min-width: 108px; min-height: 46px; }
  .order-page-pad { padding-bottom: 96px; }

  .modal-wrap { padding: 0; align-items: flex-end; }
  .modal { max-width: 100%; border-radius: 16px 16px 0 0; max-height: 92vh; padding-bottom: env(safe-area-inset-bottom); }
  .modal-foot .btn { flex: 1; }

  .hero-search input { height: 48px; }
  .search-panel { top: 54px; }

  .drawer { position: fixed; inset: 0; z-index: 70; display: flex; }
  .drawer-panel { width: 78%; max-width: 300px; background: var(--navy); color: #cbd8ea; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }
  .drawer-veil { flex: 1; background: rgba(8,20,37,.5); }
}

@media (min-width: 640px) and (max-width: 1023px) {
  .item-row { grid-template-columns: minmax(0, 1fr) 84px 116px 104px 34px; }
}

/* 打印：本段不做打印，仅避免误打印出导航 */
@media print {
  .sidebar, .topbar, .tabbar, #watermark, .mobile-submit { display: none !important; }
  .main { margin-left: 0; }
}
