/* ===== 基础变量（浅色主题，可随系统切换深色） ===== */
:root {
  --primary: #1d9e75;
  --primary-dark: #0f6e56;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --text: #1f2a27;
  --muted: #6b7a75;
  --border: #e2e8e6;
  --danger: #d85a30;
  --ok: #0f6e56;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615;
    --surface: #1c2120;
    --text: #e7eeec;
    --muted: #9aa8a3;
    --border: #2c3331;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

/* ===== 顶栏 ===== */
.topbar {
  background: var(--primary-dark);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { font-weight: 600; font-size: 16px; }
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.uname { opacity: .95; }
.btn-logout {
  color: #fff; text-decoration: none;
  border: 1px solid rgba(255,255,255,.5);
  padding: 4px 10px; border-radius: 8px; font-size: 13px;
}
.btn-manual {
  color: #fff; text-decoration: none;
  border: 1px solid rgba(255,255,255,.5);
  background: rgba(255,255,255,.15);
  padding: 4px 10px; border-radius: 8px; font-size: 13px;
}
.btn-manual:hover { background: rgba(255,255,255,.28); text-decoration: none; }

/* ===== 容器 ===== */
/* 主内容区加宽：给销售列表、采购列表等宽表格留足空间 */
.container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 16px 24px;
}

/* ===== 提示条 ===== */
.alert { padding: 10px 14px; border-radius: 10px; margin: 0 0 14px; font-size: 14px; }
.alert-success { background: #e1f5ee; color: #0f6e56; }
.alert-danger { background: #faece7; color: #993c1d; }
@media (prefers-color-scheme: dark) {
  .alert-success { background: #0f3a2e; color: #9fe1cb; }
  .alert-danger { background: #3a1f17; color: #f5c4b3; }
}

/* ===== 登录 / 品牌门户 ===== */
.login-wrap { min-height: calc(100vh - 120px); display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 36px 28px; width: 100%; max-width: 400px;
  box-shadow: 0 12px 40px rgba(0,0,0,.10);
}
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-logo {
  width: 64px; height: 64px; border-radius: 16px;
  background: linear-gradient(135deg, #2f6df6, #6a3df6); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; font-weight: 700; box-shadow: 0 6px 18px rgba(47,109,246,.35);
}
.login-title { margin: 0; font-size: 20px; text-align: center; }
.login-tagline { margin: 2px 0 0; text-align: center; color: var(--muted); font-size: 13px; }
.login-tip { margin: 16px 0 0; font-size: 12px; color: var(--muted); text-align: center; line-height: 1.6; }

/* ===== 表单 ===== */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field i { color: var(--danger); font-style: normal; }
.section-title {
  font-size: 14px; font-weight: 600; color: var(--text);
  margin: 18px 0 10px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.checkbox-field { display: flex; align-items: center; gap: 10px; }
.checkbox-field > span { margin-bottom: 0; }
.checkbox-field input[type=checkbox] {
  width: 20px; height: 20px; cursor: pointer; accent-color: var(--primary);
}
input[type=text], input[type=password], input[type=number], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; padding: 11px 12px; font-size: 15px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
  color-scheme: light dark;
}
input:focus { outline: none; border-color: var(--primary); }

/* ===== 可搜索下拉（供应商 / 客户选择，select.searchable 自动增强）===== */
.ss-wrap { position: relative; }
.ss-native {
  position: absolute !important; width: 1px !important; height: 1px !important;
  margin: -1px !important; padding: 0 !important; border: 0 !important;
  clip: rect(0 0 0 0) !important; overflow: hidden !important; white-space: nowrap !important;
}
.ss-trigger {
  width: 100%; padding: 11px 34px 11px 12px; font-size: 15px; text-align: left;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
  cursor: pointer; position: relative; font-family: inherit;
}
.ss-trigger::after {
  content: "▾"; position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 12px; pointer-events: none;
}
.ss-trigger.ss-placeholder { color: var(--muted); }
.ss-trigger:focus { outline: none; border-color: var(--primary); }
.ss-panel {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 60;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .12); overflow: hidden;
}
.ss-search {
  width: 100%; padding: 10px 12px; font-size: 14px;
  border: none; border-bottom: 1px solid var(--border); border-radius: 0;
  background: var(--surface); color: var(--text); box-sizing: border-box;
}
.ss-search:focus { outline: none; border-color: var(--border); }
.ss-list { max-height: 240px; overflow-y: auto; }
.ss-item { padding: 10px 12px; font-size: 14px; cursor: pointer; }
.ss-item:hover, .ss-item-active { background: rgba(0, 0, 0, .05); color: var(--primary); }
/* 带副标题的选项（如合同下拉：主标题=单号+名称，副标题=供应商/品种/数量/单价/金额/剩余） */
.ss-item-main { font-size: 14px; line-height: 1.35; }
.ss-item-sub {
  font-size: 12px; line-height: 1.45; color: var(--muted); margin-top: 3px;
  word-break: break-all;
}
.ss-item-active .ss-item-sub { color: inherit; opacity: .85; }
.ss-list:has(.ss-item-sub) { max-height: 320px; }
.ss-empty { padding: 12px; font-size: 13px; color: var(--muted); text-align: center; }
@media (prefers-color-scheme: dark) {
  .ss-item:hover, .ss-item-active { background: rgba(255, 255, 255, .08); }
}

/* ===== 按钮 ===== */
.btn {
  display: inline-block; border: none; border-radius: 10px;
  padding: 10px 16px; font-size: 14px; cursor: pointer; text-decoration: none;
  text-align: center;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-block { width: 100%; padding: 12px; font-size: 16px; margin-top: 4px; }

/* ===== 仪表盘 ===== */
.welcome h1 { margin: 8px 0 2px; font-size: 22px; }
.muted { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.quick-actions { margin: 10px 0 4px; display: flex; gap: 10px; flex-wrap: wrap; }
.qa-btn {
  display: inline-block; background: var(--brand); color: #fff; text-decoration: none;
  padding: 8px 16px; border-radius: 10px; font-size: 14px; font-weight: 600;
}
.qa-btn:hover { background: var(--brand-d); text-decoration: none; }
.menu-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 20px;
}
@media (min-width: 600px) { .menu-grid { grid-template-columns: repeat(4, 1fr); } }
.menu-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px 10px; text-align: center; text-decoration: none; color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.menu-card:hover { border-color: var(--primary); }
.menu-icon { font-size: 26px; }
.menu-name { font-size: 14px; font-weight: 500; }
.menu-tip { font-size: 11px; color: var(--muted); }

.info-card, .form-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 18px; margin-bottom: 18px;
}
.info-card h2 { margin: 0 0 12px; font-size: 16px; }
.kv { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.kv:last-child { border-bottom: none; }
.kv span { color: var(--muted); }
.perm-detail { margin-top: 12px; }
.perm-detail summary { cursor: pointer; font-size: 13px; color: var(--primary); }
.perm-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.perm-tag { background: #e1f5ee; color: #0f6e56; font-size: 12px; padding: 3px 8px; border-radius: 6px; }
@media (prefers-color-scheme: dark) { .perm-tag { background: #0f3a2e; color: #9fe1cb; } }

/* ===== 页面头 ===== */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; margin: 0; }
.page-head-left { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.font-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }

/* ===== 查询栏 ===== */
.query-bar { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; }
.query-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.q-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.q-field input, .q-field select { width: 100%; }
.query-actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.btn-secondary { background: #e7e2d6; color: #3a4a42; border: 1px solid var(--border); }
.btn-secondary:hover { background: #ddd6c6; }
.col-sel { width: 36px; text-align: center; }
.col-sel input { width: 16px; height: 16px; }

/* ===== 表格 ===== */
.table-wrap { overflow-x: visible; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 0; }
.data-table th, .data-table td { padding: 10px 10px; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { color: var(--muted); font-weight: 500; font-size: 13px; white-space: nowrap; }
.data-table tr:last-child td { border-bottom: none; }
.empty { text-align: center; color: var(--muted); padding: 24px; }

/* 单元格自动换行，避免名称/地址/备注被挤成竖排或出现滚动条 */
.data-table td {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.45;
  vertical-align: top;
}

/* 关键文本列给一个舒适的最小宽度，防止被压成单字竖排；最大宽度限制换行幅度 */
.data-table th[data-col-key="item_name"], .data-table td[data-col-key="item_name"],
.data-table th[data-col-key="spec"], .data-table td[data-col-key="spec"],
.data-table th[data-col-key="region"], .data-table td[data-col-key="region"],
.data-table th[data-col-key="ship_from"], .data-table td[data-col-key="ship_from"],
.data-table th[data-col-key="carrier"], .data-table td[data-col-key="carrier"],
.data-table th[data-col-key="customer_name"], .data-table td[data-col-key="customer_name"],
.data-table th[data-col-key="gift_to"], .data-table td[data-col-key="gift_to"],
.data-table th[data-col-key="source"], .data-table td[data-col-key="source"],
.data-table th[data-col-key="remarks"], .data-table td[data-col-key="remarks"] {
  min-width: 86px;
  max-width: 220px;
}
.data-table th[data-col-key="display_code"], .data-table td[data-col-key="display_code"] { min-width: 130px; }
.data-table th[data-col-key="plate_no"], .data-table td[data-col-key="plate_no"],
.data-table th[data-col-key="op"], .data-table td[data-col-key="op"] { min-width: 84px; }

/* 旧版 class 规则保留（其它页面若使用仍可生效） */
.data-table td.text-wrap {
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.45;
}
.data-table .col-name { min-width: 90px; max-width: 130px; }
.data-table .col-supplier { min-width: 110px; max-width: 160px; }
.data-table .col-region { min-width: 100px; max-width: 150px; }
.data-table .col-remarks { min-width: 100px; max-width: 180px; }

/* 手机/小屏仍允许横向滚动，避免信息丢失 */
@media (max-width: 899px) {
  .table-wrap { overflow-x: auto; }
}

/* 中等屏幕适当压缩表格字号和间距，进一步降低滚动概率 */
@media (max-width: 1200px) {
  .data-table { font-size: 13px; }
  .data-table th, .data-table td { padding: 8px 8px; }
}

.badge { font-size: 12px; padding: 3px 9px; border-radius: 20px; }
.badge-ok { background: #e1f5ee; color: #0f6e56; }
.badge-off { background: #f1efea; color: #6b7a75; }
@media (prefers-color-scheme: dark) {
  .badge-ok { background: #0f3a2e; color: #9fe1cb; }
  .badge-off { background: #2c3331; color: #9aa8a3; }
}

/* ===== 新增用户表单 ===== */
.role-options { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.role-check {
  display: flex; flex-direction: column; gap: 2px;
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
.role-check input { margin-right: 8px; }
.role-check span { font-size: 14px; font-weight: 500; }
.role-check em { font-size: 12px; color: var(--muted); font-style: normal; }

/* ===== 页脚 ===== */
.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 20px; }

/* ===== 列表操作 / 表单链接 ===== */
.row-actions { white-space: nowrap; display: flex; gap: 10px; align-items: center; }
.link-edit { color: var(--primary); text-decoration: none; font-size: 13px; }
.link-del { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 13px; padding: 0; }
.link-add { display: inline-block; margin-top: 4px; font-size: 12px; color: var(--primary); text-decoration: none; }
.link-amount { color: var(--primary); text-decoration: none; font-weight: 600; }
.link-amount:hover { text-decoration: underline; }

/* 一车多品时，车头信息跨行垂直居中；作废信息另起一行 */
.data-table td.group-cell { vertical-align: middle; display: table-cell; }
.op-wrap { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.void-info { width: 100%; font-size: 11px; color: var(--muted); }

/* ===== 标签页（采购三大块）===== */
.tabs { display: flex; gap: 8px; margin: 4px 0 6px; flex-wrap: wrap; }
.tab {
  flex: 1; min-width: 90px; text-align: center; padding: 10px 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); text-decoration: none; font-size: 14px; font-weight: 500;
}
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.hint-drag { color: var(--muted); font-size: 12px; }

/* ===== 卡片 / 提示 / 过滤栏 / 状态选择 ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 18px; margin-bottom: 16px; }
/* 二级菜单卡片：整卡可点击（点击标签名直接进入），去掉「进入 →」后保留链接语义 */
.nav-card { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; cursor: pointer; transition: border-color .15s; }
.nav-card:hover { border-color: var(--primary); }
.card-title { font-size: 16px; font-weight: 600; margin-bottom: 14px; color: var(--text); }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; margin: 0 0 10px; }
.filter-bar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filter-bar .tab { flex: 0 1 auto; min-width: 64px; }
.status-select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font-size: 13px; color: var(--text); cursor: pointer; }
.import-result-ok { color: var(--primary); font-weight: 600; }
.import-result-fail { color: var(--danger); font-weight: 600; }

/* ===== 表单：两列网格 & 发货地三联动 ===== */
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.region-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
input[readonly], input:disabled {
  background: var(--bg); color: var(--muted); cursor: not-allowed;
}
.hint-auto {
  display: inline-block; margin-top: 4px; font-size: 12px; color: var(--primary);
}
.calc-hint {
  margin: 2px 0 6px; padding: 7px 12px; font-size: 13px; line-height: 1.5;
  color: #1d6fb8; background: #eef6ff; border: 1px dashed #b9d8f5; border-radius: 8px;
}
input[type=datetime-local] { color-scheme: light dark; }
@media (max-width: 480px) {
  .field-grid { grid-template-columns: 1fr; }
  .region-row { grid-template-columns: 1fr; }
}

/* ===== 表头可拖动提示 ===== */
.data-table th { cursor: grab; user-select: none; }
.data-table th:active { cursor: grabbing; }

/* ===== 图片上传 / 缩略图 ===== */
.img-upload { display: flex; flex-direction: column; gap: 8px; }
.img-upload input[type=file] { padding: 8px; font-size: 13px; }
.img-preview {
  width: 120px; height: 120px; object-fit: cover; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); display: none;
}
.img-preview.show { display: block; }
.thumb {
  width: 56px; height: 56px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--border); cursor: zoom-in; vertical-align: middle;
}
.thumb-empty { color: var(--muted); font-size: 13px; }
.img-hint { font-size: 12px; color: var(--muted); }
.img-hint.err { color: var(--danger); }


/* ===== 左侧导航布局（工作台/模块页共用） ===== */
.brand-link { color: #fff; text-decoration: none; }
.sidebar-toggle {
  display: inline-flex; background: none; border: 1px solid rgba(255,255,255,.45);
  color: #fff; font-size: 18px; line-height: 1; padding: 4px 10px; border-radius: 8px; cursor: pointer;
}
.app-layout { display: flex; align-items: stretch; position: relative; }
.sidebar {
  flex: 0 0 220px; width: 220px; background: var(--surface);
  border-right: 1px solid var(--border); padding: 12px 8px 24px;
  position: sticky; top: 52px; align-self: flex-start;
  max-height: calc(100vh - 52px); overflow-y: auto; z-index: 30;
  transition: width .2s ease, padding .2s ease;
}
.sidebar-header {
  display: flex; justify-content: flex-end; align-items: center;
  padding: 0 4px 8px; margin-bottom: 6px; border-bottom: 1px solid var(--border);
}
.sidebar-collapse {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  border-radius: 8px; width: 28px; height: 28px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 13px;
}
.sidebar-collapse:hover { color: var(--text); background: var(--bg); }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px;
  border-radius: 10px; color: var(--text); text-decoration: none; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.side-item:hover { background: rgba(0,0,0,.05); }
.side-item.active { background: #e1f5ee; color: var(--primary-dark); font-weight: 600; }
.side-icon { font-size: 16px; flex-shrink: 0; }
.side-tip { font-size: 11px; color: var(--muted); margin-left: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-disabled { color: var(--muted); cursor: not-allowed; }
.nav-group { margin-top: 10px; }
.nav-group-title {
  font-size: 12px; color: var(--muted); padding: 6px 12px 4px;
  font-weight: 600; letter-spacing: .5px;
}
.sidebar-mask { display: none; }
.main { flex: 1; min-width: 0; }
@media (prefers-color-scheme: dark) {
  .side-item:hover { background: rgba(255,255,255,.08); }
  .side-item.active { background: #0f3a2e; color: #9fe1cb; }
}
/* 桌面端折叠 */
@media (min-width: 900px) {
  .sidebar.collapsed {
    width: 0; flex-basis: 0; padding: 0; border-right: none;
    overflow: hidden; opacity: 0;
  }
}
@media (max-width: 899px) {
  .sidebar-toggle { display: inline-flex; }
  .sidebar-collapse { display: none; }
  .sidebar-header { display: none; }
  .sidebar {
    position: fixed; left: 0; top: 52px; bottom: 0; width: 250px;
    transform: translateX(-102%); transition: transform .22s ease; max-height: none; z-index: 50;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 18px rgba(0,0,0,.18); }
  .sidebar-mask.show { display: block; position: fixed; inset: 52px 0 0 0; background: rgba(0,0,0,.35); z-index: 40; }
}

/* ===== 仪表盘统计卡 ===== */
.stat-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 20px;
}
@media (min-width: 700px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 16px; display: flex; flex-direction: column; gap: 6px;
}
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 22px; font-weight: 700; line-height: 1.2; }
.stat-sub { font-size: 12px; color: var(--muted); }
.stat-value.warn { color: var(--danger); }
.dash-cols { display: grid; grid-template-columns: 1fr; gap: 16px; margin-bottom: 20px; }
@media (min-width: 900px) { .dash-cols { grid-template-columns: 1fr 1fr; } }
.dash-mini { margin-bottom: 0; }
.dash-mini .mini-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.dash-mini .mini-row:last-child { border-bottom: none; }
.dash-mini .mini-name { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-mini .mini-amt { font-weight: 600; white-space: nowrap; }
.dash-mini .mini-qty { color: var(--muted); font-size: 12px; white-space: nowrap; }
.link-more { font-size: 13px; color: var(--primary); text-decoration: none; }
.dash-empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

/* ===== 市补销售：售价区间勾稽提示 ===== */
.price-hint { display: block; font-size: 12px; color: var(--muted); margin-top: -8px; }
.price-hint.err { color: var(--danger); }

/* ===== 一车多品：商品明细表（市补/议价新增/编辑）===== */
.items-table { min-width: 620px; }
.items-table th, .items-table td { white-space: nowrap; }
.items-table .col-op { width: 44px; text-align: center; }
.items-table td { padding: 6px 8px; }
.items-table input[type="number"], .items-table input[type="text"] {
  width: 100%; min-width: 78px; box-sizing: border-box;
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px;
  font-size: 13px; background: var(--surface); color: var(--text);
}
.items-table select.it-prod { width: 100%; min-width: 180px; }
.items-table .it-amount-disp, .items-table .it-tax-disp, .items-table .it-spec-disp, .items-table .it-unit-disp {
  background: var(--bg) !important; color: var(--muted) !important; cursor: default;
}
.btn-remove-row {
  border: 1px solid var(--border); background: var(--surface); color: var(--danger);
  width: 26px; height: 26px; border-radius: 8px; cursor: pointer; line-height: 1; font-size: 13px;
}
.btn-remove-row:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
#itemsSummary { font-weight: 600; color: var(--text); }

/* =========================================================
   移动端适配增强（手机自适应 / 表格卡片化）
   仅作用于 ≤768px；桌面端布局完全不受影响
   ========================================================= */
@media (max-width: 768px) {
  body { font-size: 14px; }
  .container { padding: 12px 12px; }
  .topbar-inner { padding: 10px 12px; gap: 8px; }
  .topbar-user { gap: 8px; font-size: 13px; }
  .brand { font-size: 15px; }
  .btn-manual, .btn-logout { padding: 4px 9px; font-size: 12px; }
  .card, .form-card, .info-card, .query-bar { padding: 14px 12px; margin-bottom: 14px; }
  .page-head { margin-bottom: 10px; }
  .page-head h1 { font-size: 18px; }
  .section-title { font-size: 14px; }
  .btn { padding: 9px 14px; font-size: 14px; }
  /* 移动端输入框用 16px，避免 iOS 聚焦时整页放大；同时加大点按区域 */
  input[type=text], input[type=password], input[type=number], input[type=date], input[type=datetime-local], select, textarea, .ss-trigger {
    padding: 12px; font-size: 16px;
  }
  .field > span { font-size: 13px; }
  /* 查询条件手机单列，按钮占满更方便点按 */
  .query-grid { grid-template-columns: 1fr; }
  .query-actions .btn { flex: 1 1 auto; }
  /* 表单两列 / 发货地三列网格，手机强制单列 */
  .field-grid, .region-row { grid-template-columns: 1fr; }
  /* 宽表去掉强制最小宽度，让文字尽量换行，减少横向滑动 */
  .data-table th[data-col-key], .data-table td[data-col-key] {
    min-width: 0 !important; max-width: none !important;
  }
  .data-table th, .data-table td { font-size: 13px; padding: 8px 8px; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
}

/* 简单列表表在手机上转为卡片竖排（由 base.html 脚本自动加 .rwd-stacked） */
@media (max-width: 768px) {
  /* 已卡片化的表不需要外层横向滚动 */
  .table-wrap:has(.rwd-stacked) { overflow: visible; }
  .rwd-stacked { background: transparent; border: none; }
  .rwd-stacked thead { display: none; }
  .rwd-stacked tbody { display: block; }
  .rwd-stacked tr {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 4px 12px;
    margin-bottom: 12px;
  }
  .rwd-stacked td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
    text-align: right;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
  }
  .rwd-stacked td:last-child { border-bottom: none; }
  /* 字段名（来自表头）显示在左侧，值显示在右侧，窄屏自动换行 */
  .rwd-stacked td::before {
    content: attr(data-label);
    flex: 0 0 40%;
    font-weight: 600;
    color: var(--muted);
    text-align: left;
    white-space: normal;
  }
  .rwd-stacked td > * { max-width: 58%; text-align: right; }
  /* 手机端隐藏批量勾选列，卡片视图里意义不大 */
  .rwd-stacked td.col-sel { display: none; }
  /* 操作列：链接/按钮右对齐、可换行 */
  .rwd-stacked td.row-actions { display: block; text-align: right; padding-top: 10px; }
  .rwd-stacked td.row-actions::before { display: block; margin-bottom: 6px; }
  .rwd-stacked .thumb { width: 48px; height: 48px; }
  /* 空数据行（单行 colspan）在卡片模式下居中提示，不显示字段名 */
  .rwd-stacked tr td[colspan] {
    display: block; text-align: center; border: none; color: var(--muted); font-size: 13px;
  }
  .rwd-stacked tr td[colspan]::before { content: none; }
}

/* =========================================================
   移动端卡片化增强（仅 ≤768px，避免影响桌面）
   ========================================================= */
@media (max-width: 768px) {
  /* 整张卡：轻投影 + 更舒适内边距 */
  .rwd-stacked tr { box-shadow: 0 1px 3px rgba(0,0,0,.06); padding: 6px 14px 10px; }
  .rwd-stacked td > * { max-width: 60%; }

  /* 数值类字段（金额/数量/单价）加粗，便于手机扫读 */
  .rwd-stacked td[data-col-key$="amount"],
  .rwd-stacked td[data-col-key$="qty"],
  .rwd-stacked td[data-col-key="price"],
  .rwd-stacked td[data-col-key="received_amount"],
  .rwd-stacked td[data-col-key="profit"] {
    font-weight: 600; font-variant-numeric: tabular-nums;
  }

  /* 空值（— / 空）弱化，不抢视线 */
  .rwd-stacked td[data-empty="1"] { color: var(--muted); opacity: .5; }
  .rwd-stacked td[data-empty="1"]::before { opacity: 1; }

  /* 操作列：链接/按钮变成可点块，手机更好按 */
  .rwd-stacked td.row-actions::before { font-weight: 600; color: var(--muted); }
  .rwd-stacked td.row-actions .op-wrap { justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
  .rwd-stacked td.row-actions a,
  .rwd-stacked td.row-actions button {
    display: inline-block; padding: 7px 12px; border-radius: 8px;
    border: 1px solid var(--primary); color: var(--primary);
    background: transparent; font-size: 13px; text-decoration: none; line-height: 1.2;
  }
  .rwd-stacked td.row-actions a:active,
  .rwd-stacked td.row-actions button:active { background: var(--primary); color: #fff; }

  /* ===== 分组卡片：一车多品（车头信息区 + 商品明细）===== */
  .rwd-groups { display: block; }
  .rwd-group {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; margin-bottom: 14px; overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
  }
  .rwd-group-head {
    padding: 12px 14px 8px; border-bottom: 1px dashed var(--border);
    background: linear-gradient(180deg, rgba(29,158,117,.07), transparent);
  }
  .rwd-group-title {
    font-size: 14px; font-weight: 700; color: var(--text);
    display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
  }
  .rwd-group-title .badge-tag {
    font-size: 11px; font-weight: 600; color: var(--primary);
    background: rgba(29,158,117,.12); padding: 2px 8px; border-radius: 10px;
  }
  .rwd-kv {
    display: flex; justify-content: space-between; gap: 12px;
    padding: 5px 0; font-size: 13px; line-height: 1.45;
  }
  .rwd-kv .k { color: var(--muted); flex: 0 0 38%; }
  .rwd-kv .v { color: var(--text); text-align: right; word-break: break-word; overflow-wrap: anywhere; }
  .rwd-kv .v[data-empty="1"] { color: var(--muted); opacity: .5; }
  .rwd-detail { padding: 4px 14px 12px; }
  .rwd-detail-label {
    font-size: 12px; color: var(--muted); font-weight: 600;
    margin: 10px 0 6px; letter-spacing: .3px;
  }
  .rwd-detail-item {
    border: 1px solid var(--border); border-radius: 10px;
    padding: 8px 10px; margin-bottom: 8px; background: var(--bg);
  }
  .rwd-detail-item .rwd-kv { padding: 3px 0; font-size: 12.5px; }
  .rwd-detail-item .rwd-kv .k { flex-basis: 34%; }

  /* ===== 统计表：保留表格结构（展开/勾选交互依赖），仅优化手机横滑 ===== */
  .stats-table { -webkit-overflow-scrolling: touch; }
  .stats-table th[style*="min-width"] { min-width: auto !important; white-space: normal !important; }
  .stats-table th, .stats-table td { white-space: normal; }
  .stats-table .name { white-space: normal; }
  .stats-table th, .stats-table td.num, .stats-table td { font-size: 12px; padding: 8px 8px; }
  .stats-table input.leafchk { width: 20px; height: 20px; }

  /* 分组卡片容器：外层不要横向滚动 */
  .table-wrap:has(.rwd-groups) { overflow: visible; }
  /* 分组 / 明细里的链接（编辑、删除、打印）保持可点可辨 */
  .rwd-kv .v a, .rwd-group-head .v a, .rwd-detail .v a { color: var(--primary); text-decoration: none; font-size: 13px; }
  .rwd-kv .v a:hover { text-decoration: underline; }
  .rwd-kv .v .op-wrap { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
}

/* ===== 列表分页条 ===== */
.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin: 12px 2px 6px; font-size: 13px; }
.pager-btn { padding: 6px 12px; border: 1px solid #cfd8d3; border-radius: 6px; color: var(--primary, #2F6F4E); text-decoration: none; background: #fff; }
.pager-btn:hover { background: #f1f7f3; }
.pager-disabled { color: #bbb; border-color: #e8e8e8; background: #fafafa; cursor: not-allowed; }
.pager-info { color: #666; }

/* ===== 列显示设置 ===== */
.colvis-bar { position: relative; display: flex; justify-content: flex-end; margin: 2px 2px 6px; }
.colvis-toggle { font-size: 12px; padding: 4px 10px; }
.colvis-panel { position: absolute; right: 0; top: calc(100% + 4px); z-index: 60; background: #fff; border: 1px solid #d8e2dc; border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .12); width: 250px; max-height: 60vh; overflow: auto; }
.colvis-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-bottom: 1px solid #eee; font-weight: 600; font-size: 13px; color: var(--primary, #2F6F4E); }
.colvis-x { border: 0; background: none; font-size: 18px; line-height: 1; cursor: pointer; color: #888; }
.colvis-body { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; }
.colvis-item { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 4px 2px; border-radius: 4px; cursor: pointer; user-select: none; }
.colvis-item:hover { background: #f5f9f6; }
.colvis-foot { padding: 8px 10px; border-top: 1px solid #eee; text-align: right; }
.col-hidden { display: none !important; }
@media (max-width: 768px) { .colvis-bar { display: none; } }


/* ===== 供应商仪表盘（合同 ↔ 采购 比对） ===== */
.sup-id { display: grid; grid-template-columns: 1fr; gap: 0 26px; }
@media (min-width: 700px) { .sup-id { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1100px) { .sup-id { grid-template-columns: repeat(4, 1fr); } }
.sup-id .kv { padding: 7px 0; gap: 10px; }
.sup-id .kv b { font-weight: 500; text-align: right; word-break: break-all; }

.sup-insights { margin-bottom: 18px; display: flex; flex-direction: column; gap: 8px; }
.sup-insight {
  display: flex; gap: 9px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border); border-left-width: 3px;
  border-radius: 10px; padding: 10px 14px; font-size: 13.5px; line-height: 1.6;
}
.sup-insight .sup-dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 7px; flex: 0 0 auto; background: var(--muted); }
.sup-insight-danger { border-left-color: var(--danger); }
.sup-insight-danger .sup-dot { background: var(--danger); }
.sup-insight-warn { border-left-color: #d99a26; }
.sup-insight-warn .sup-dot { background: #d99a26; }
.sup-insight-info { border-left-color: #4a86c8; }
.sup-insight-info .sup-dot { background: #4a86c8; }
.sup-insight-ok { border-left-color: var(--primary); }
.sup-insight-ok .sup-dot { background: var(--primary); }

/* 差额：正数=超交/超付（红），负数=未交/未付（蓝） */
.sup-pos { color: var(--danger); font-weight: 600; }
.sup-neg { color: #3d6f9e; font-weight: 600; }

.sup-tag { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 20px; white-space: nowrap; }
.sup-tag-ok { background: #e1f5ee; color: #0f6e56; }
.sup-tag-warn { background: #fdf1dd; color: #a8752a; }
.sup-tag-danger { background: #fbe6df; color: #b8431f; }
.sup-tag-info { background: #e8f0fb; color: #3d6f9e; }
.sup-tag-muted { background: #f1efea; color: #6b7a75; }

.sup-sub { font-size: 11px; color: var(--muted); margin-left: 4px; }
.sup-flag {
  display: inline-block; width: 15px; height: 15px; line-height: 15px; text-align: center;
  border-radius: 50%; background: #fdf1dd; color: #a8752a; font-size: 11px; font-weight: 700;
  margin-right: 3px; vertical-align: 1px;
}
.sup-note { font-size: 12px; color: var(--muted); margin: 8px 2px 18px; line-height: 1.65; }
.sup-foot { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 10px; }
.empty-box {
  background: var(--surface); border: 1px dashed var(--border); border-radius: 12px;
  padding: 22px 16px; text-align: center; color: var(--muted); font-size: 13.5px; margin-bottom: 18px;
}

.sup-bar-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 12.5px; }
.sup-bar-label { flex: 0 0 40px; color: var(--muted); }
.sup-bar-track { flex: 1 1 auto; height: 10px; background: var(--border); border-radius: 6px; overflow: hidden; }
.sup-bar-fill { height: 100%; background: var(--primary); border-radius: 6px; min-width: 2px; }
.sup-bar-val { flex: 0 0 100px; text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 768px) {
  .sup-bar-label { flex: 0 0 34px; }
  .sup-bar-val { flex: 0 0 86px; font-size: 11.5px; }
  .sup-note { margin-bottom: 14px; }
}

/* 仪表盘内的宽表：PC 上也允许横向滚动，避免列被挤成竖排 */
.sup-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.sup-cellsub {
  font-size: 11.5px; color: var(--muted); max-width: 190px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px;
}

/* 仪表盘宽表：PC 端给最小宽度让列不挤压；手机端卡片化后必须归零 */
.sup-wide { min-width: 1020px; }
.sup-wide-2 { min-width: 860px; }
.sup-wide-3 { min-width: 900px; }
@media (max-width: 768px) {
  .sup-wide, .sup-wide-2, .sup-wide-3,
  .sup-wide.rwd-stacked, .sup-wide-2.rwd-stacked, .sup-wide-3.rwd-stacked {
    min-width: 0; width: 100%;
  }
}

/* ===== 供应商总览 ===== */
.sup-wide-4 { min-width: 1180px; }
@media (max-width: 768px) {
  .sup-wide-4, .sup-wide-4.rwd-stacked { min-width: 0; width: 100%; }
}
.sort-link {
  color: inherit; text-decoration: none; display: inline-flex;
  align-items: center; gap: 3px; white-space: nowrap;
}
.sort-link:hover { color: var(--primary); }
.sort-arrow { font-size: 11px; color: var(--primary); }

/* 列表里的迷你标签（合同已挂 / 未挂） */
.tag-mini {
  display: inline-block; font-size: 11.5px; padding: 1px 7px;
  border-radius: 10px; white-space: nowrap; line-height: 1.5;
}
.tag-mini-ok { background: #e1f5ee; color: #0f6e56; }
.tag-mini-warn { background: #fdf1dd; color: #a8752a; }

/* 仪表盘：未挂合同原因的小标签 */
.sup-reasons { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.sup-reason {
  font-size: 11.5px; color: var(--muted); background: #f6f4ef;
  border: 1px solid var(--border); border-radius: 8px; padding: 2px 8px;
}
.sup-reason b { color: var(--text); font-weight: 600; }

/* 采购列表列多：数字/日期不折行，超宽时在容器内横向滚动（手机端卡片化后不生效） */
@media (min-width: 769px) {
  table[data-table-key^="purchase_"] th,
  table[data-table-key^="purchase_"] td:not(.text-wrap) { white-space: nowrap; }
}
