/* ============================================================
   谷忆进销存 · 样式
   品牌色板：沉静檀褐 / 原生米白 / 松烟墨 / 金茶色
   浅色主题，电脑与手机双端适配
   ============================================================ */
:root {
  /* —— 品牌主色 —— */
  --brand: #9C6F4F;          /* 沉静檀褐：主按钮、重点标题、Logo */
  --brand-dark: #82573A;     /* 檀褐加深：悬停 / 按下 */
  --brand-deep: #8A5F42;     /* 檀褐更深：现在只用于选中导航的文字色 */
  --brand-light: #F2E9DE;    /* 檀褐淡化：选中底、品牌标签底 */

  /* —— 辅助色 金茶 —— */
  --accent: #B78C5A;         /* 金茶色：标签、分割线、次要图标 */
  --accent-dark: #8A6A3C;    /* 金茶加深：需要当文字用时 */
  --accent-light: #F6EEE2;   /* 金茶淡化：底色 */

  /* —— 底色 —— */
  --bg: #F5F1E6;             /* 原生米白：页面整体背景 */
  --bg-soft: #FAF7F0;        /* 表头 / 次级面板 */
  --card: #FFFFFF;           /* 卡片、表格、弹窗底色 */

  /* —— 文字（松烟墨体系）—— */
  --text: #434D3F;           /* 正文、表格内容 */
  --text-2: #5C6354;         /* 次要说明文字 */
  --text-3: #676E5F;         /* 提示、单位、时间（已调深，看得更清） */

  /* —— 描边 —— */
  --border: #E6DED0;         /* 常规分割线（金茶冷暖调） */
  --border-strong: #D5C9B4;  /* 输入框、按钮描边 */

  /* —— 语义色 —— */
  --ok: #4F7A4A;
  --ok-bg: #EDF3E9;
  --warn: #A8781F;
  --warn-bg: #FAF0DC;
  --danger: #B5492F;         /* 危险色：删除、作废、库存预警 */
  --danger-bg: #FBEDE9;
  --info: #7A6238;
  --info-bg: #F5EEE1;

  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 14px;
  /* 阴影统一用暖灰，避免纯黑发脏 */
  --shadow: 0 1px 2px rgba(67, 77, 63, .05), 0 4px 14px rgba(67, 77, 63, .05);
  --shadow-sm: 0 1px 2px rgba(67, 77, 63, .04), 0 1px 3px rgba(67, 77, 63, .04);
  --shadow-md: 0 2px 6px rgba(67, 77, 63, .06), 0 8px 24px rgba(67, 77, 63, .07);
  /* 动效：时长与缓动统一，交互反馈才一致 */
  --dur-fast: .13s;
  --dur: .2s;
  --ease: cubic-bezier(.4, 0, .2, 1);
  --focus: 0 0 0 3px rgba(156, 111, 79, .18);
  --sidebar-w: 216px;
  --topbar-h: 56px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.65;          /* 中文正文行高比英文略大更耐看 */
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
input, select, textarea, button { font-family: inherit; font-size: inherit; color: inherit; }
.hidden { display: none !important; }

/* 选中文字跟随品牌色，视觉语言统一 */
::selection { background: rgba(156, 111, 79, .22); }

/* 细滚动条：进销存天天要用，系统默认滚动条太抢眼 */
* { scrollbar-width: thin; scrollbar-color: #D8CDB9 transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #D8CDB9; border: 2px solid transparent; background-clip: content-box; border-radius: 8px;
}
::-webkit-scrollbar-thumb:hover { background: #C6B69B; background-clip: content-box; }
::-webkit-scrollbar-corner { background: transparent; }

/* 尊重系统「减少动态效果」设置（无障碍） */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}

/* 键盘可达性：焦点清晰可见 */
.btn:focus-visible, .nav-item:focus-visible, .input:focus-visible, .select:focus-visible,
.dd-item:focus-visible, .icon-btn:focus-visible, .side-foot-btn:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* 全局提示条（安全提醒等） */
.global-alert {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 12px 16px 0; padding: 11px 14px; border-radius: var(--radius);
  background: var(--warn-bg); border: 1px solid #EBD5A8; color: #6E4E05;
  font-size: 13.5px;
}
.global-alert.danger { background: var(--danger-bg); border-color: #E5B3A8; color: #7C2E1B; }
.global-alert strong { font-weight: 600; }
.global-alert .ga-actions { margin-left: auto; display: flex; gap: 8px; }
@media (max-width: 900px) { .global-alert { margin: 10px 12px 0; } }

/* ---------- 登录 ---------- */
.login-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(170deg, #FAF7F0 0%, var(--bg) 55%, #EFE8DA 100%);
  padding: 20px; z-index: 100;
}
.login-box {
  position: relative; width: 100%; max-width: 372px; background: var(--card);
  border: 1px solid var(--border); border-radius: 16px; padding: 34px 28px 26px;
  box-shadow: 0 2px 4px rgba(67, 77, 63, .04), 0 12px 32px rgba(67, 77, 63, .09);
  overflow: hidden;
}
/* 卡片顶部一条金茶细带 */
.login-box::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--brand) 0%, var(--accent) 100%);
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-logo {
  width: 60px; height: 60px; margin: 0 auto 14px; border-radius: 16px; background: var(--brand);
  color: #fff; font-size: 30px; font-weight: 600; display: flex; align-items: center; justify-content: center;
  letter-spacing: 1px; box-shadow: 0 4px 12px rgba(156, 111, 79, .28);
}
.login-brand h1 { font-size: 20px; letter-spacing: 2px; color: var(--text); }
.login-brand p {
  margin: 7px 0 0; color: var(--accent-dark); font-size: 12px; letter-spacing: 3px; text-transform: uppercase;
}
/* 登录表单沿中轴对称：标签文字居中、输入框与按钮同宽 */
.login-box .field { margin-bottom: 14px; text-align: center; }
.login-box .field > span {
  display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px;
  text-align: center; width: 100%;
}
.login-box .field .input {
  width: 100%; display: block; margin: 0 auto;
  padding: 10px 12px; min-height: 42px; font-size: 15px; text-align: left;
}
.login-error {
  color: var(--danger); background: var(--danger-bg); border-radius: var(--radius-sm);
  font-size: 13px; padding: 0 12px; max-height: 0; overflow: hidden; transition: .18s;
}
.login-error.show { max-height: 80px; padding: 9px 12px; margin-bottom: 12px; }
.login-box .btn-block { margin-top: 4px; min-height: 42px; font-size: 15px; letter-spacing: 4px; }
.login-tip { text-align: center; color: var(--text-3); font-size: 12px; margin-top: 16px; }

/* ---------- 布局 ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: #FBF7EF; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; z-index: 40;
}
.side-brand {
  display: flex; align-items: center; gap: 10px; padding: 16px 16px 15px;
  border-bottom: 1px solid var(--border);
}
.side-logo {
  width: 34px; height: 34px; border-radius: 9px; background: var(--brand); color: #fff;
  font-size: 18px; font-weight: 600; display: flex; align-items: center; justify-content: center; flex: none;
}
.side-brand-text { min-width: 0; }
.side-brand-text strong {
  display: block; font-size: 14px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.side-brand-text small { color: var(--text-3); font-size: 11.5px; }
.nav { flex: 1; overflow-y: auto; padding: 10px 8px 20px; }
.nav-group { margin-top: 12px; }
.nav-group-title {
  font-size: 11.5px; color: var(--text-3); padding: 6px 10px 5px; letter-spacing: 1.2px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--text); cursor: pointer; font-size: 13.5px; border: none; background: none;
  width: 100%; text-align: left; position: relative;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-item:hover { background: #F3ECE0; color: var(--text); }
.nav-item.active { background: #F0E5D2; color: var(--brand-deep); font-weight: 600; }
.nav-item.active::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--brand);
}
.nav-item .ni-icon { width: 17px; height: 17px; flex: none; opacity: .95; }
.nav-item .ni-badge {
  margin-left: auto; background: var(--danger); color: #fff; font-size: 11px; font-weight: 600;
  border-radius: 9px; padding: 1px 6px; min-width: 18px; text-align: center;
}
.side-foot { padding: 10px 12px; border-top: 1px solid var(--border); }
.side-foot-btn {
  width: 100%; background: #fff; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 8px; font-size: 12.5px; color: var(--text-2); cursor: pointer;
}
.side-foot-btn:hover { background: #F3ECE0; color: var(--text); }

/* ---------- 备案号悬挂（公安联网备案要求；设置里值留空则不渲染） ---------- */
.badge-foot { font-size: 12px; color: var(--text-3); text-align: center; line-height: 1.7; }
.badge-foot a { color: inherit; text-decoration: none; }
.badge-foot a:hover { color: var(--text); text-decoration: underline; }
.badge-foot > * + *::before { content: " · "; }
.login-badges {
  position: absolute; left: 0; right: 0; bottom: 14px; padding: 0 20px;
  pointer-events: none;
}
.login-badges a { pointer-events: auto; }
.side-foot .badge-foot { margin-top: 8px; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; padding: 0 16px; position: sticky; top: 0; z-index: 30;
  box-shadow: 0 1px 3px rgba(67, 77, 63, .04);   /* 滚动时与内容拉开层次 */
}
.topbar-title { font-size: 15.5px; font-weight: 600; color: var(--brand); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.topbar-date { color: var(--text-3); font-size: 12.5px; }
.only-mobile { display: none; }
.page { padding: 16px; flex: 1; min-width: 0; }

/* 用户菜单 */
.user-menu { position: relative; }
.user-btn {
  display: flex; align-items: center; gap: 7px; background: none; border: 1px solid transparent;
  border-radius: 20px; padding: 3px 10px 3px 3px; cursor: pointer;
}
.user-btn:hover { background: var(--brand-light); border-color: var(--border); }
.avatar {
  width: 27px; height: 27px; border-radius: 50%; background: var(--brand); color: #fff;
  font-size: 13px; display: flex; align-items: center; justify-content: center; flex: none;
}
.user-name { font-size: 13px; }
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 8px); width: 176px; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 6px; display: none; z-index: 50;
}
.user-dropdown.open { display: block; }
.dd-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.dd-head strong { display: block; font-size: 13.5px; }
.dd-head span { color: var(--text-3); font-size: 12px; }
.dd-item {
  display: block; width: 100%; text-align: left; background: none; border: none; padding: 9px 10px;
  border-radius: var(--radius-sm); cursor: pointer; font-size: 13px;
}
.dd-item:hover { background: var(--bg-soft); }
.dd-danger { color: var(--danger); }

.mask { display: none; }
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .only-mobile { display: inline-flex; }
  .mask.show { display: block; position: fixed; inset: 0; background: rgba(67, 77, 63, .38); z-index: 35; }
  .topbar-date { display: none; }
  .page { padding: 12px; }
}

/* ---------- 卡片与栅格 ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);          /* 一点点浮起，页面不再像线框图 */
}
.card + .card { margin-top: 12px; }
.card-head {
  display: flex; align-items: center; gap: 10px; padding: 13px 14px; border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.card-head h3 { font-size: 14.5px; color: var(--text); letter-spacing: .2px; }
/* 筛选条：card-head 是 flex 行，而 .input 默认 width:100% —— 不兜底的话
   每个筛选控件都会各占一整行，白白吃掉三四行高度。这里让它们按内容排。 */
.card-head > .input, .card-head > .select { width: auto; min-width: 132px; }
.card-head > .input.search { min-width: 180px; flex: 1 1 180px; max-width: 340px; }
.card-head > input[type="date"], .card-head > input[type="month"] { min-width: 150px; }
/* 卡片标题前一小段品牌色竖条：不加粗也能一眼定位分区 */
.card-head h3::before {
  content: ""; display: inline-block; width: 3px; height: 13px; border-radius: 2px;
  background: var(--brand); margin-right: 8px; vertical-align: -1.5px;
}
.card-head .spacer { flex: 1; }
.card-body { padding: 14px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.stat { padding: 14px; position: relative; }
.stat .st-label { color: var(--text-2); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.stat .st-value {
  font-size: 25px; font-weight: 600; letter-spacing: -.5px; margin-top: 7px;
  font-variant-numeric: tabular-nums; color: var(--text);
}
.stat .st-value small { font-size: 13px; font-weight: 400; color: var(--text-2); margin-left: 2px; }
.stat .st-sub { color: var(--text-3); font-size: 12px; margin-top: 4px; }
.stat.brand { background: linear-gradient(150deg, #fff 0%, var(--brand-light) 100%); }
.stat.brand .st-value { color: var(--brand); }
/* 涨红跌绿（国内习惯） */
.st-up { color: var(--danger); }
.st-down { color: var(--ok); }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* 表格铺在无内边距的卡片里时，让四角跟着卡片圆角走。
   注意不能直接在滚动容器上裁切（overflow + border-radius）——那会把表尾右下角
   切掉一块，露出白底，看着就像「合计这行颜色不对」。改为给角落单元格圆角。 */
.card-body.tight table.tb th:first-child { border-top-left-radius: var(--radius); }
.card-body.tight table.tb th:last-child { border-top-right-radius: var(--radius); }
.card-body.tight table.tb > tfoot > tr:last-child > td:last-child,
.card-body.tight table.tb > tbody:last-child > tr:last-child > td:last-child { border-bottom-right-radius: var(--radius); }
.card-body.tight table.tb > tfoot > tr:last-child > td:first-child,
.card-body.tight table.tb > tbody:last-child > tr:last-child > td:first-child { border-bottom-left-radius: var(--radius); }
table.tb { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tb th, table.tb td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.tb th {
  background: var(--bg-soft); color: var(--text); font-weight: 600; font-size: 13px; letter-spacing: .2px;
  border-bottom: 1.5px solid var(--accent);
  position: sticky; top: 0; z-index: 1;
}
table.tb tbody tr { transition: background var(--dur-fast) var(--ease); }
table.tb tbody tr:hover { background: #F7F2E7; }
/* 最后一行不再画线：否则会与卡片底边叠成一条双线 */
table.tb tbody tr:last-child td { border-bottom: none; }
/* 可点表头：点一下升序、再点降序、第三次回默认顺序（逻辑在 core.js bindSort） */
table.tb th.sortable { cursor: pointer; user-select: none; }
table.tb th.sortable:hover { background: #F3EADA; color: var(--brand-deep); }
table.tb th .sort-arrow { margin-left: 4px; font-size: 10px; opacity: .32; }
table.tb th.sorted { color: var(--brand-deep); }
table.tb th.sorted .sort-arrow { opacity: 1; color: var(--brand); }
table.tb td.num, table.tb th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tb td.wrap, table.tb th.wrap { white-space: normal; min-width: 160px; }
/* 底色同时给 tr 和 td：万一某行 tfoot 的单元格数与列数对不上，
   没被 td 盖住的那块也不会露出白色（曾把「合计」行右下角弄出一块白斑） */
table.tb tfoot tr, table.tb tfoot td { background: var(--bg-soft); }
table.tb tfoot td { font-weight: 600; border-top: 1.5px solid var(--accent); }
table.tb .row-actions { display: flex; gap: 8px; }
.tb-empty { padding: 46px 16px; text-align: center; color: var(--text-3); font-size: 13.5px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.strong { font-weight: 600; }
.muted { color: var(--text-3); }
/* 表格单元格里的第二行小字（如「品种/数量」下的具体酒名）：
   允许换行，否则一行长商品名会把整张表撑得很宽 */
.cell-sub { margin-top: 3px; font-size: 12px; line-height: 1.5; font-weight: 400; white-space: normal; }
/* 「品种 / 数量」列给个下限宽度：酒名按列宽折成两行左右，整表仍能一屏放下 */
table.tb td.col-goods, table.tb th.col-goods { min-width: 208px; white-space: normal; }
/* 小程序订单的「收货人 / 地址」列：姓名、电话、地址竖排，地址两行封顶看全（title 悬停） */
table.tb td.col-recv, table.tb th.col-recv { min-width: 150px; max-width: 260px; white-space: normal; }
.cell-sub.addr {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; overflow-wrap: anywhere; color: var(--text); opacity: .78;
}
.row-link { cursor: pointer; }
.cell-link { color: var(--brand); border-bottom: 1px dashed currentColor; }

/* 详情页顶部「基本信息」：横向多列铺满，避免右侧大片留白 */
.kv-grid { display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); gap: 10px 26px; font-size: 13.5px; }
.kv-grid .kv { display: flex; gap: 8px; min-width: 0; align-items: baseline; }
.kv-grid .kv > span { color: var(--text-3); flex: 0 0 auto; min-width: 4.4em; }
.kv-grid .kv > b { font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.kv-grid .kv-full { grid-column: 1 / -1; }
@media (max-width: 900px) { .kv-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .kv-grid { grid-template-columns: 1fr; } }
.text-danger { color: var(--danger); }
.text-ok { color: var(--ok); }
.text-warn { color: var(--warn); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

@media (max-width: 760px) {
  table.tb.responsive thead { display: none; }
  table.tb.responsive tbody tr {
    display: block; border: 1px solid var(--border); border-radius: var(--radius-sm);
    margin: 10px; padding: 8px 12px; background: var(--card);
  }
  table.tb.responsive tbody td {
    display: flex; justify-content: space-between; gap: 12px; border: none; padding: 5px 0;
    white-space: normal; text-align: right;
  }
  table.tb.responsive tbody td::before {
    content: attr(data-label); color: var(--text-3); font-size: 12.5px; flex: none; text-align: left;
  }
  table.tb.responsive tbody td.num { text-align: right; }
  table.tb.responsive tbody td.col-goods { min-width: 0; }
  table.tb.responsive tbody td.col-recv { min-width: 0; max-width: none; }
  table.tb.responsive tfoot { display: block; margin: 0 10px 10px; }
  table.tb.responsive tfoot tr { display: block; }
  table.tb.responsive tfoot td { display: flex; justify-content: space-between; border: none; padding: 4px 12px; }
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 15px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--card); cursor: pointer; font-size: 13.5px; font-weight: 500; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--bg-soft); border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600;
  box-shadow: 0 1px 2px rgba(156, 111, 79, .3);
}
.btn-primary:hover {
  background: var(--brand-dark); border-color: var(--brand-dark);
  box-shadow: 0 2px 6px rgba(156, 111, 79, .34);
}
.btn-danger { background: var(--danger-bg); border-color: #E5B3A8; color: var(--danger); }
.btn-danger:hover { background: #F6DFD8; border-color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--brand); padding-left: 7px; padding-right: 7px; }
.btn-ghost:hover { background: var(--brand-light); border-color: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-lg { padding: 12px 20px; font-size: 15px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px;
  border: none; background: none; border-radius: var(--radius-sm); cursor: pointer; color: var(--text-2);
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }
@media (max-width: 760px) {
  .btn { min-height: 38px; }
  .btn-sm { min-height: 32px; }
}

/* ---------- 表单 ---------- */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 5px; }
.field > span .req { color: var(--danger); margin-left: 2px; }
.input, .select, textarea.input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--card); font-size: 14px; outline: none; min-height: 38px;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input:hover, .select:hover { border-color: var(--accent); }
.input:focus, .select:focus, textarea.input:focus { border-color: var(--brand); box-shadow: var(--focus); }
.input::placeholder, textarea.input::placeholder { color: var(--text-3); opacity: .85; }
.input:disabled { background: var(--bg-soft); color: var(--text-3); }
.input.num { text-align: right; font-variant-numeric: tabular-nums; }
textarea.input { resize: vertical; min-height: 64px; }
.form-row { display: grid; gap: 12px; }
.form-row.c2 { grid-template-columns: 1fr 1fr; }
.form-row.c3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 640px) { .form-row.c2, .form-row.c3 { grid-template-columns: 1fr; } }
.hint { color: var(--text-3); font-size: 12px; margin-top: 4px; }

/* 筛选条 */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters .input, .filters .select { width: auto; min-width: 130px; }
.filters .input.search { min-width: 190px; }

/* 标签 */
.tag {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 5px;
  font-size: 11.5px; font-weight: 500; background: var(--bg-soft); color: var(--text-2); white-space: nowrap;
  border: 1px solid var(--border);
}
.tag-ok { background: var(--ok-bg); color: var(--ok); border-color: #CFE0C6; }
.tag-warn { background: var(--warn-bg); color: var(--warn); border-color: #EBD5A8; }
.tag-danger { background: var(--danger-bg); color: var(--danger); border-color: #E5B3A8; }
.tag-info { background: var(--info-bg); color: var(--info); border-color: #E4D8C2; }
.tag-brand { background: var(--brand-light); color: var(--brand); border-color: #E3D3C2; }
.tag-muted { background: var(--bg-soft); color: var(--text-3); }
.qty-pill { font-variant-numeric: tabular-nums; }

/* 分页 */
.pager { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.pager .pg-info { color: var(--text-3); font-size: 12.5px; margin-right: auto; }
.pager .btn { padding: 5px 11px; font-size: 12.5px; }

/* 空状态 */
.empty { padding: 48px 20px; text-align: center; color: var(--text-3); }
.empty .em-icon { font-size: 30px; opacity: .35; margin-bottom: 8px; }
.empty p { margin: 4px 0; font-size: 13.5px; }

/* ---------- 弹窗 ---------- */
.modal-root { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-mask { position: absolute; inset: 0; background: rgba(67, 77, 63, .45); }
.modal {
  position: relative; background: var(--card); border-radius: 12px; width: 100%; max-width: 540px;
  max-height: calc(100vh - 40px); display: flex; flex-direction: column;
  box-shadow: 0 12px 40px rgba(67, 77, 63, .22);
}
.modal.wide { max-width: 860px; }
.modal.xwide { max-width: 1120px; }
.modal-head {
  display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 15px; flex: 1; color: var(--brand); }
.modal-body { padding: 16px; overflow: auto; flex: 1; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 9px; padding: 12px 16px;
  border-top: 1px solid var(--border); flex-wrap: wrap;
}
.modal-foot .spacer { flex: 1; }

/* ---------- 提示 ---------- */
.toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: var(--text); color: #fff; padding: 10px 17px; border-radius: 20px; font-size: 13.5px;
  box-shadow: 0 6px 20px rgba(67, 77, 63, .26); animation: toastIn .2s ease; max-width: 88vw;
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }
.toast.warn { background: var(--warn); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } }

/* ---------- 图表 ---------- */
/* 图表 SVG 自带真实像素宽高（core.js 按容器宽度 1:1 绘制），
   这里只做上限保护 —— 不要写 width:100%，那会把文字和圆点拉伸变形 */
.chart { max-width: 100%; display: block; }
.bar-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.bar-row .br-label { width: 120px; flex: none; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .br-track { flex: 1; height: 10px; background: #F1EDE3; border-radius: 5px; overflow: hidden; }
.bar-row .br-fill { height: 100%; background: var(--brand); border-radius: 5px; }
.bar-row .br-value { width: 92px; flex: none; text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---------- 明细录入表 ---------- */
.items-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.items-table th, .items-table td { padding: 7px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.items-table th {
  background: var(--bg-soft); font-size: 12.5px; color: var(--text); font-weight: 600; text-align: left;
  border-bottom: 1.5px solid var(--accent);
}
/* 数字输入框去掉上下箭头：开单时鼠标滚过/误点会把数量价格改掉 */
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; }

.items-table .input { padding: 6px 8px; font-size: 13.5px; min-height: 34px; }
.items-table td.num .input { width: 100%; min-width: 0; text-align: right; }
/* 改过价的行：折后价框描金边，一眼看出这一行不是系统价 */
.items-table .price-edited { border-color: #B78C5A !important; background: #fdf8ef; }
.prod-cell small a { color: var(--brand); text-decoration: underline; cursor: pointer; font-weight: 600; }
.items-table td.num, .items-table th.num { text-align: right; }
.items-table tfoot td { background: var(--bg-soft); font-weight: 600; }
.prod-cell { display: flex; flex-direction: column; gap: 1px; min-width: 150px; }
.prod-cell strong { font-size: 13.5px; font-weight: 600; }
.prod-cell small { color: var(--text-3); font-size: 11.5px; }

/* ---------- 商品图片 ---------- */
.pimg {
  border-radius: 6px; object-fit: cover; display: block; flex: none;
  background: var(--bg-soft); border: 1px solid var(--border);
}
img.pimg { background: #fff; }
.pimg-empty {
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; color: var(--text-3); border-style: dashed; letter-spacing: 0;
}
.pimg-broken { visibility: hidden; }

/* 图片 + 文字并排 */
.with-img { display: flex; align-items: center; gap: 10px; min-width: 0; }
.with-img .wi-text { min-width: 0; }

/* 表单里的图片上传控件 */
.imgfield-box { display: flex; gap: 14px; align-items: flex-start; }
.imgfield-prev {
  width: 108px; height: 108px; flex: none; border-radius: var(--radius-sm); overflow: hidden;
  background: var(--bg-soft); border: 1px dashed var(--border-strong);
  display: flex; align-items: center; justify-content: center;
}
.imgfield-prev img { width: 100%; height: 100%; object-fit: contain; display: block; }
.imgfield-hint { color: var(--text-3); font-size: 12px; text-align: center; padding: 0 6px; }
.imgfield-ops { flex: 1; min-width: 0; }
.imgfield-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 7px; }
@media (max-width: 560px) {
  .imgfield-box { flex-direction: column; }
  .imgfield-prev { width: 100%; height: 170px; }
}
.mix-input { display: flex; align-items: center; gap: 4px; }
.mix-input .input { width: 52px; text-align: center; padding: 5px 4px; }
.mix-input .unit { color: var(--text-3); font-size: 12px; }

/* ---------- 开单明细表 · 手机端卡片化（销售/采购/调拨/盘点四处共用） ----------
   桌面端表格不动；≤760px 时每个 <tr> 重排成一张卡片，td 变「标签 + 控件」一行。
   依赖：每个 td 都有 data-label（sale/purchase/inventory 三页渲染时已带）。
   纯 CSS 方案，repaintRow 按 data-qtyhint/data-amt 定位单元格的逻辑不受影响。 */
@media (max-width: 760px) {
  /* 整张表（含 table/tbody/tfoot）全部降为块级布局 —— 只要还有任何 table-row 参与，
     匿名单元格就会按 min-content 重算表宽，把卡片撑出屏幕（实测 table 比容器宽 22px） */
  .items-table, .items-table tbody, .items-table tfoot {
    display: block; width: auto; min-width: 0;
  }
  .items-table { font-size: 13.5px; }
  .items-table thead { display: none; }
  .items-table tr {
    display: block; border: 1px solid var(--border); border-radius: var(--radius-sm);
    margin: 0 0 10px; padding: 10px 12px 8px; background: var(--card);
    box-shadow: var(--shadow-sm);
  }
  .items-table tbody td {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
    gap: 8px; border: none; padding: 6px 0; text-align: right; white-space: normal;
  }
  .items-table tbody td::before {
    content: attr(data-label); color: var(--text-3); font-size: 12.5px; flex: none; text-align: left;
  }
  /* 商品行当卡片头：整行铺满，不显示「商品」标签 */
  .items-table tbody td:first-child { display: block; padding-bottom: 4px; }
  .items-table tbody td:first-child::before { content: none; }
  /* 输入框吃满标签外的剩余宽度，数字再也不会被压成一竖条。
     basis 必须 0：width:100% 在匿名表格单元格里会被当 intrinsic 宽度算，把卡片撑出屏幕 */
  .items-table tbody td .input, .items-table tbody td.num .input {
    flex: 1 1 0; width: auto; min-width: 72px; max-width: 100%;
  }
  /* 数量格：箱/瓶紧凑固定宽、整组靠右，不跟单价一样吃满行。
     选择器必须压过上面 td.num .input 的 flex:1（那里 b/c 数更高），否则箱/瓶格跟着撑满 */
  .items-table tbody td .mix-input { flex: 0 0 auto; justify-content: flex-end; }
  .items-table tbody td .mix-input .input { flex: 0 0 auto; width: 64px; min-width: 0; }
  .items-table tbody td .hint { flex: 1 1 100%; }
  /* 删除按钮那格没有 data-label：不生成标签、靠右 */
  .items-table tbody td:not([data-label]) { justify-content: flex-end; padding-top: 2px; }
  .items-table tbody td:not([data-label])::before { content: none; }
  /* 表尾合计：贴成一条横栏 */
  .items-table tfoot { display: block; margin: 2px 0 10px; }
  .items-table tfoot tr { display: block; border-radius: var(--radius-sm); overflow: hidden; }
  .items-table tfoot td { display: flex; justify-content: space-between; border: none; padding: 6px 12px; }
}

.sum-bar {
  display: flex; flex-wrap: wrap; gap: 18px; align-items: baseline; padding: 13px 14px;
  background: var(--bg-soft); border-radius: var(--radius-sm); border: 1px solid var(--border);
}
.sum-bar .sb-item { display: flex; align-items: baseline; gap: 6px; }
.sum-bar .sb-item span { color: var(--text-2); font-size: 12.5px; }
.sum-bar .sb-item strong { font-size: 17px; font-variant-numeric: tabular-nums; }
.sum-bar .sb-item.big strong { font-size: 21px; color: var(--brand); }

/* 商品选择器 */
.picker-list { max-height: 380px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.picker-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.picker-item:last-child { border-bottom: none; }
.picker-item:hover, .picker-item.hl { background: var(--brand-light); }
.picker-item .pi-main { flex: 1; min-width: 0; }
.picker-item .pi-name { font-size: 13.5px; font-weight: 600; }
.picker-item .pi-meta { color: var(--text-3); font-size: 12px; }
.picker-item .pi-right { text-align: right; flex: none; }
.picker-item .pi-price { font-size: 14px; font-weight: 600; color: var(--brand); font-variant-numeric: tabular-nums; }
.picker-item .pi-stock { font-size: 11.5px; color: var(--text-3); }

/* 小票打印（不受品牌色影响，保持黑白，黑白热敏机才打得清） */
.print-root { display: none; }
.receipt { font-family: var(--mono); color: #000; background: #fff; padding: 4mm 2mm; line-height: 1.45; }
.receipt .r-center { text-align: center; }
.receipt .r-title { font-size: 15px; font-weight: 700; letter-spacing: 2px; }
.receipt .r-sub { font-size: 11px; }
.receipt .r-line { border-top: 1px dashed #000; margin: 4px 0; }
.receipt table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.receipt table th { text-align: left; border-bottom: 1px dashed #000; padding: 2px 0; font-weight: 400; }
.receipt table td { padding: 1.5px 0; vertical-align: top; }
.receipt table td.num, .receipt table th.num { text-align: right; }
.receipt .r-total { display: flex; justify-content: space-between; font-size: 13px; font-weight: 700; padding: 2px 0; }
.receipt .r-row { display: flex; justify-content: space-between; font-size: 11.5px; }
.receipt .r-foot { font-size: 11px; text-align: center; margin-top: 6px; }
/* 小票上的商品缩略图：小尺寸，热敏机才打得清 */
.receipt .r-pic { width: 30px; padding: 2px 4px 2px 0; vertical-align: top; }
.receipt .r-pic img { width: 26px; height: 26px; object-fit: cover; display: block; }

/* A4 单据：用正常字体、整页宽度（打印时由 printReceipt 注入 @page 规则） */
.a4sheet {
  width: 190mm; margin: 0 auto; background: #fff; color: #000;
  font-family: var(--font); font-size: 13px; line-height: 1.6;
}

/* 针式打印机横向多联单：241mm × 140mm（三联）。
   纸宽 241mm，但左右走纸孔各约 10mm 打不到，所以内容按 200mm 排。
   针式机是黑白点阵，只用纯黑线条，不要灰、不要底色。 */
.trisheet {
  width: 200mm; margin: 0 auto; padding: 3mm 0 0; background: #fff; color: #000;
  font-family: var(--mono); font-size: 11px; line-height: 1.45;
}
.trisheet .ts-top { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 2mm; }
.trisheet .ts-shop { font-size: 12px; font-weight: 700; letter-spacing: 1px; }
.trisheet .ts-kind { font-size: 15px; font-weight: 700; letter-spacing: 5px; }
.trisheet .ts-no { font-size: 11px; }
.trisheet .ts-meta { display: flex; gap: 6mm; margin-bottom: 1.5mm; }
.trisheet .ts-meta > div { flex: 1; min-width: 0; }
.trisheet .ts-meta > div > div { white-space: nowrap; overflow: hidden; }
.trisheet table.ts-table { width: 100%; border-collapse: collapse; }
.trisheet .ts-table th, .trisheet .ts-table td {
  border: 1px solid #000; padding: 0.5mm 1mm; height: 5.4mm; vertical-align: middle;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.trisheet .ts-table th { font-weight: 400; text-align: center; }
.trisheet .ts-c { text-align: center; }
.trisheet .ts-num { text-align: right; }
.trisheet .ts-sum { display: flex; justify-content: space-between; margin-top: 1.5mm; }
.trisheet .ts-sign { display: flex; justify-content: space-between; margin-top: 3.5mm; }

/* 正式「销售单」：同样是 241mm × 140mm 针式三联单，但列多——单价与折后单价两套口径。
   针式机印不出灰度，所有线和字都用纯黑。 */
.slipsheet {
  width: 200mm; margin: 0 auto; padding: 3mm 0 0; background: #fff; color: #000;
  font-family: var(--mono); font-size: 11px; line-height: 1.5;
}
.slipsheet .sl-title { text-align: center; font-size: 15px; font-weight: 700; letter-spacing: 1px; margin-bottom: 1.5mm; }
.slipsheet .sl-head { display: flex; justify-content: space-between; gap: 6mm; }
.slipsheet .sl-head > div { flex: 1; min-width: 0; }
.slipsheet .sl-head > div > div { white-space: nowrap; overflow: hidden; }
.slipsheet table.sl-table { width: 100%; border-collapse: collapse; margin-top: 0.8mm; }
.slipsheet .sl-table th, .slipsheet .sl-table td {
  border: 1px solid #000; padding: 0.5mm 1mm; height: 5.2mm; vertical-align: middle;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.slipsheet .sl-table th { font-weight: 400; text-align: center; }
.slipsheet .sl-c { text-align: center; }
.slipsheet .sl-num { text-align: right; }
.slipsheet .sl-sumrow td { font-weight: 700; }
.slipsheet .sl-sumtag { text-align: center; }
.slipsheet .sl-pay { display: flex; flex-wrap: wrap; justify-content: flex-start; gap: 4mm 26mm; margin-top: 1.5mm; }
.slipsheet .sl-owe { margin-top: 1mm; }
.slipsheet .sl-sign { margin-top: 1mm; margin-bottom: 3.5mm; }
.slipsheet .sl-note { margin-top: 0; }
.slipsheet .sl-pay small { font-size: 10px; }
/* 没有针式机时的 A4 兜底版式：内容仍是那张横版单据，只是换张纸、缩放到不裁边。
   zoom 在 Chrome/Edge 的打印里有效，mm 定宽的表格列会跟着整体缩放。 */
.slipsheet.a4l { width: auto; max-width: 270mm; zoom: 1.25; margin: 0 auto; padding-top: 0; }
.slipsheet.a4p { width: auto; max-width: 176mm; zoom: 0.88; margin: 0 auto; padding-top: 0; }
.slipsheet.a4l .sl-table th, .slipsheet.a4l .sl-table td,
.slipsheet.a4p .sl-table th, .slipsheet.a4p .sl-table td { white-space: normal; word-break: break-all; }

/* ---------- 可点击的选择栏 ----------
   开单时「客户 / 供应商」整栏都能点，一点就弹选择列表，
   不必再去右上角找按钮。右侧箭头提示"这里可以点"，选了人之后换成清除按钮。 */
.pick-wrap { position: relative; display: block; }
input.pickable {
  cursor: pointer;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239C6F4F' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 15px;
}
input.pickable:hover { border-color: var(--brand); }
input.pickable:focus { border-color: var(--brand); border-right-width: 1px; }
/* 已经有值时把箭头收掉，免得和清除按钮叠在一起 */
input.pickable:not(:placeholder-shown) { background-image: none; }
.pick-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 21px; height: 21px; padding: 0; line-height: 19px; text-align: center;
  border: none; border-radius: 50%; background: #E6E1D6; color: var(--text-3);
  cursor: pointer; font-size: 14px;
}
.pick-clear:hover { background: #B5492F; color: #fff; }

@media print {
  body > *:not(.print-root) { display: none !important; }
  .print-root { display: block !important; }
  .print-root.printing { display: block !important; }
  @page { margin: 3mm; }
  html, body { background: #fff; }
}
