:root {
  --brand-blue: #00529E;
  --brand-blue-dark: #003f7c;
  --brand-green: #33B7A2;
  --brand-green-dark: #26907f;
  --bg: #f4f7fa;
  --card-bg: #ffffff;
  --text: #1f2d3d;
  --text-light: #7a8ba0;
  --border: #e3e9f0;
  --warn: #e6a23c;
  --danger: #e25252;
  --ok: #33B7A2;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}
.hidden { display: none !important; }

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--brand-blue) 0%, #0a6cc4 55%, var(--brand-green) 130%);
}
.login-card {
  width: 380px; background: #fff; border-radius: 14px; padding: 40px 36px 32px;
  box-shadow: 0 18px 50px rgba(0, 40, 80, .35);
}
.login-logo { text-align: center; margin-bottom: 26px; }
.login-logo h1 { font-size: 21px; color: var(--brand-blue); margin-top: 10px; }
.login-sub { color: var(--text-light); font-size: 12px; margin-top: 6px; letter-spacing: 1px; }
.logo-dot {
  display: inline-block; width: 14px; height: 14px; border-radius: 4px;
  background: linear-gradient(135deg, var(--brand-blue) 50%, var(--brand-green) 50%);
}
.form-row { margin-bottom: 16px; }
.form-row label { display: block; font-size: 13px; color: var(--text-light); margin-bottom: 6px; }
.form-row input {
  width: 100%; height: 40px; border: 1px solid var(--border); border-radius: 8px;
  padding: 0 12px; font-size: 14px; outline: none; transition: border .15s;
}
.form-row input:focus { border-color: var(--brand-blue); box-shadow: 0 0 0 3px rgba(0, 82, 158, .1); }
.login-err { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 10px; }

/* ---------- 按钮 ---------- */
.btn {
  height: 38px; border: none; border-radius: 8px; padding: 0 18px; font-size: 14px;
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn-primary { background: var(--brand-blue); color: #fff; }
.btn-primary:hover { background: var(--brand-blue-dark); }
.btn-green { background: var(--brand-green); color: #fff; }
.btn-green:hover { background: var(--brand-green-dark); }
.btn-ghost { background: transparent; color: var(--text-light); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--brand-blue); border-color: var(--brand-blue); }
.btn-outline { background: #fff; color: var(--brand-blue); border: 1px solid var(--brand-blue); }
.btn-outline:hover { background: var(--brand-blue); color: #fff; }
.btn-outline:disabled { background: #f3f5f8; color: #999; border-color: var(--border); cursor: not-allowed; }
.btn-sm { height: 30px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- 顶栏 ---------- */
.topbar {
  height: 54px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  position: sticky; top: 0; z-index: 10;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.topbar-title { font-size: 16px; font-weight: 600; color: var(--brand-blue); }
.topbar-badge {
  font-size: 11px; color: var(--brand-green); border: 1px solid var(--brand-green);
  border-radius: 10px; padding: 1px 8px;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.hello-user { color: var(--text-light); font-size: 13px; margin-right: 4px; }

/* ---------- 主体 ---------- */
.container { max-width: 1200px; margin: 0 auto; padding: 20px 24px 40px; }

.cards { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 18px; }
.card {
  background: var(--card-bg); border-radius: 10px; padding: 16px 18px;
  border: 1px solid var(--border); box-shadow: 0 2px 8px rgba(30, 60, 100, .04);
}
.card-num { font-size: 26px; font-weight: 700; color: var(--brand-blue); }
.card-label { font-size: 12px; color: var(--text-light); margin-top: 4px; }
.card-warn .card-num { color: var(--warn); }
.card-danger .card-num { color: var(--danger); }

.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 14px; }
.search-box { flex: 1 1 420px; display: flex; gap: 8px; }
.search-box input {
  flex: 1; height: 38px; border: 1px solid var(--border); border-radius: 8px;
  padding: 0 14px; font-size: 14px; outline: none;
}
.search-box input:focus { border-color: var(--brand-blue); box-shadow: 0 0 0 3px rgba(0, 82, 158, .1); }
.mfr-input { flex: 0 1 260px; border-color: #b9e0d9 !important; }
.mfr-input:focus { border-color: var(--brand-green) !important; box-shadow: 0 0 0 3px rgba(51, 183, 162, .12) !important; }
.mfr-input::placeholder { color: #9db8b2; }
.filter-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  height: 32px; padding: 0 14px; border-radius: 16px; border: 1px solid var(--border);
  background: #fff; color: var(--text-light); font-size: 13px; cursor: pointer; transition: all .15s;
}
.pill:hover { color: var(--brand-blue); border-color: var(--brand-blue); }
.pill.active { background: var(--brand-blue); border-color: var(--brand-blue); color: #fff; }
.pill-danger.active { background: var(--danger); border-color: var(--danger); }
.toolbar-right { display: flex; gap: 8px; align-items: center; }
.toolbar-right select {
  height: 34px; border: 1px solid var(--border); border-radius: 8px; padding: 0 8px;
  background: #fff; font-size: 13px; color: var(--text); outline: none;
}

/* ---------- 表格 ---------- */
.table-wrap {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px;
  overflow: auto; box-shadow: 0 2px 8px rgba(30, 60, 100, .04);
}
.stock-table { width: 100%; border-collapse: collapse; min-width: 980px; }
.stock-table th {
  background: #f0f5fa; color: var(--text-light); font-size: 13px; font-weight: 600;
  padding: 10px 12px; text-align: left; position: sticky; top: 0;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.stock-table td { padding: 9px 12px; border-bottom: 1px solid #f0f3f7; vertical-align: middle; white-space: nowrap; }
/* 长文本列：限定宽度，超长自动换行（短内容仍单行，不强制拆字） */
.stock-table td.name-cell { max-width: 220px; white-space: normal; word-break: break-word; line-height: 1.5; }
.stock-table td.spec-cell { max-width: 170px; white-space: normal; word-break: break-word; line-height: 1.5; }
.stock-table td.cust-cell { max-width: 180px; white-space: normal; word-break: break-word; line-height: 1.5; }
.stock-table td.mfr-cell { max-width: 180px; white-space: normal; word-break: break-word; line-height: 1.5; }
.stock-table tbody tr:hover { background: #f7fafd; }
.stock-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.empty-tip { text-align: center; color: var(--text-light); padding: 30px 0 !important; }
.table-hint { padding: 8px 12px; color: var(--text-light); font-size: 12px; }

.badge {
  display: inline-block; font-size: 12px; border-radius: 4px; padding: 1px 8px; white-space: nowrap;
}
.badge-ok { background: #e8f7f4; color: #1c8c7a; }
.badge-warn { background: #fdf3e3; color: #b97d1e; }
.badge-danger { background: #fdeaea; color: #cf4444; }
.badge-gray { background: #eef1f5; color: #8b98a8; }
.qty-strong { font-weight: 700; color: var(--brand-blue); }
.mfr-cell { color: var(--text); }
.mfr-empty { color: var(--text-light); font-size: 12px; background: #f3f5f8; padding: 1px 8px; border-radius: 3px; }
.mfr-src { color: var(--warn); font-size: 11px; background: #fdf3e3; padding: 1px 6px; border-radius: 3px; margin-left: 4px; }
/* 管理员可编辑的厂家单元格 */
.mfr-edit { cursor: pointer; display: inline-block; border-radius: 4px; }
.mfr-edit:hover { outline: 1px dashed var(--brand-green); outline-offset: 3px; }
.mfr-edit:hover .mfr-empty { background: #e8f7f4; color: var(--brand-green); border: 1px dashed var(--brand-green); }
.mfr-edit-prod { color: var(--text-light); font-size: 13px; margin-bottom: 14px; word-break: break-all; }

/* 批量维护（仅 admin 可见） */
.admin-only { display: none; }
body.is-admin .admin-only { display: table-cell; }
.col-check { width: 36px; text-align: center; padding-left: 8px !important; padding-right: 8px !important; }
.row-check { cursor: pointer; width: 16px; height: 16px; accent-color: var(--brand-blue); }
.batch-ops { display: flex; align-items: center; gap: 8px; padding: 0 12px; margin-right: 8px; border-right: 1px solid var(--border); }
.batch-count { font-size: 13px; color: var(--text-light); }
.batch-count::before { content: '☑ '; color: var(--brand-blue); font-weight: 700; }
.batch-ops .btn { white-space: nowrap; }

/* ---------- 功能切换 tab ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 2px solid var(--border); }
.tab {
  padding: 10px 22px; font-size: 15px; font-weight: 600; color: var(--text-light);
  background: transparent; border: none; border-bottom: 3px solid transparent;
  margin-bottom: -2px; cursor: pointer; border-radius: 6px 6px 0 0;
}
.tab:hover { color: var(--brand-blue); background: rgba(0, 82, 158, .05); }
.tab.active { color: var(--brand-blue); border-bottom-color: var(--brand-blue); }

/* ---------- 单据查询 ---------- */
.date-range { display: flex; align-items: center; gap: 6px; }
.date-range input[type="date"] {
  height: 38px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; color: var(--text); background: #fff;
}
.date-range input[type="date"]:focus { border-color: var(--brand-blue); outline: none; }
.date-sep { color: var(--text-light); font-size: 13px; }
.bills-summary {
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 16px; margin-bottom: 12px; font-size: 13.5px; color: var(--text);
}
.bills-summary b { color: var(--brand-blue); }
.amt-strong { font-weight: 700; color: var(--brand-blue); }
.qty-neg { color: var(--danger); font-weight: 600; }
.bill-code { font-family: Consolas, monospace; font-size: 12.5px; color: var(--brand-blue); }
/* 查价格：商品行选中高亮 */
.price-row-sel { background: #e8f2fb !important; outline: 2px solid var(--brand-blue); outline-offset: -2px; }
/* 单据页搜索区：允许换行，日期和快捷按钮固定、输入框弹性 */
.search-box.bills-search { flex: 1 1 100%; flex-wrap: wrap; }
.bills-search .date-range { flex: 0 0 auto; }
.bills-search .filter-pills { flex: 0 0 auto; }
.bills-search input[type="text"] { flex: 1 1 220px; min-width: 180px; }

/* ---------- 分页 ---------- */
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 16px; }
.page-info { color: var(--text-light); font-size: 13px; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(15, 30, 50, .45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-card {
  width: 380px; background: #fff; border-radius: 12px; padding: 26px 28px 22px;
  box-shadow: 0 16px 40px rgba(0, 30, 60, .3);
}
.modal-card h3 { font-size: 16px; color: var(--brand-blue); margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.modal-card.modal-wide { width: 720px; max-width: 94vw; max-height: 90vh; overflow-y: auto; }

/* ---------- 账号管理 ---------- */
.users-tip {
  font-size: 12.5px; color: var(--text-light); line-height: 1.7;
  background: #f2f7fb; border-radius: 8px; padding: 10px 12px; margin-bottom: 16px;
}
.users-tip b { color: var(--brand-blue); }
.users-table-wrap { margin-bottom: 20px; }
.users-table-wrap .stock-table { font-size: 13px; }
.users-add { border-top: 1px solid #e6ebf1; padding-top: 16px; }
.users-add h4 { font-size: 14px; color: var(--brand-blue); margin-bottom: 12px; }
.users-add-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.users-add-grid select {
  width: 100%; padding: 9px 10px; border: 1px solid #cfd8e3; border-radius: 8px;
  font-size: 13.5px; color: var(--text-dark); background: #fff; font-family: inherit;
}
.role-badge {
  display: inline-block; padding: 2px 9px; border-radius: 10px;
  font-size: 12px; font-weight: 500;
}
.role-admin { background: #fdeceb; color: #a32d2d; }
.role-sales { background: #e6f1fb; color: #185fa5; }
.st-badge { font-size: 12px; }
.st-on { color: #3b6d11; }
.st-off { color: #a32d2d; }
.users-ops { display: flex; gap: 6px; flex-wrap: wrap; }
.users-ops .btn { padding: 3px 10px; font-size: 12px; }
.btn-danger-ghost { color: #a32d2d; border-color: #f0c6c6; }
.btn-danger-ghost:hover { background: #fdeceb; }

@media (max-width: 900px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
}
