/* ===================== 全局 ===================== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  font-size: 13px; color: #333; background: #eef1f6; overflow: hidden;
}

/* ===================== 登录页 ===================== */
.login-page {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #2f6fed 0%, #1f4fb8 100%);
}
.login-box {
  width: 380px; background: #fff; border-radius: 10px; padding: 36px 34px; box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.login-box h1 { font-size: 22px; text-align: center; color: #1f4fb8; margin-bottom: 4px; }
.login-sub { text-align: center; color: #999; font-size: 13px; margin-bottom: 22px; }
.login-field { margin-bottom: 14px; }
.login-field label { display: block; font-size: 12px; color: #666; margin-bottom: 5px; }
.login-field input {
  width: 100%; height: 40px; border: 1px solid #d5dbe5; border-radius: 6px; padding: 0 12px; font-size: 14px;
}
.login-field input:focus { outline: none; border-color: #2f6fed; box-shadow: 0 0 0 2px rgba(47,111,237,.15); }
.login-err { color: #e0353b; font-size: 12px; min-height: 18px; margin-bottom: 6px; }
.btn-block { width: 100%; }

/* ===================== 主界面布局 ===================== */
#mainPage { display: flex; flex-direction: column; height: 100vh; width: 100vw; }
#topbar {
  height: 48px; background: #1f3b66; color: #fff; display: flex; align-items: center;
  justify-content: space-between; padding: 0 16px; flex-shrink: 0;
}
#sysName { font-size: 18px; font-weight: 700; letter-spacing: 1px; }
.top-right { display: flex; align-items: center; gap: 12px; }
#topUser { font-size: 13px; opacity: .9; }

#mainWrap { display: flex; flex: 1; overflow: hidden; }

/* ===================== 左侧菜单（上下顶格） ===================== */
#sidebar {
  width: 128px; background: #2a3b52; flex-shrink: 0; position: relative; z-index: 50;
  padding-top: 4px; display: flex; flex-direction: column; height: 100%;
  /* overflow 保持 visible，让子菜单可浮动到右侧窗口之上 */
}
#menu { display: flex; flex-direction: column; }
.menu-group { position: relative; }
.menu-main {
  color: #cfd8e6; padding: 13px 8px; cursor: pointer; font-size: 14px;
  border-left: 3px solid transparent; transition: background .15s;
  display: flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
}
.menu-group:hover .menu-main, .menu-main:hover { background: #34486a; color: #fff; border-left-color: #4f9bff; }
.mi-ico { font-size: 17px; color: #fff; width: 20px; text-align: center; flex-shrink: 0; line-height: 1; }
.mi-name { font-size: 13px; white-space: nowrap; }

.menu-sub {
  display: none; position: absolute; left: 100%; top: 0; min-width: 150px; background: #fff;
  box-shadow: 0 6px 20px rgba(0,0,0,.22); border-radius: 0 6px 6px 0; z-index: 200; padding: 4px 0;
}
.menu-item { position: relative; padding: 9px 14px; cursor: pointer; font-size: 13px; color: #333; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.menu-item:hover { background: #eef3ff; color: #1f4fb8; }
.menu-item .mi-label { white-space: nowrap; }
.mi-query { color: #2f6fed; font-size: 12px; background: #eaf1ff; border-radius: 4px; padding: 1px 6px; }
.mi-query:hover { background: #2f6fed; color: #fff; }
.menu-sub.sub2 { left: 100%; top: 0; }

/* ===================== 多窗口区（tab 形式） ===================== */
#desktop {
  flex: 1; min-width: 0; background: #eef1f6;
  display: flex; flex-direction: column; overflow: hidden;
}
/* 顶部 tab 栏 */
#tabbar {
  display: flex; align-items: flex-end; gap: 2px; padding: 6px 10px 0;
  background: #dfe5f0; overflow-x: auto; flex-shrink: 0;
}
.tab {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px;
  background: #e9edf6; color: #44506b; border: 1px solid #d3dae8; border-bottom: none;
  border-radius: 6px 6px 0 0; cursor: pointer; font-size: 13px; white-space: nowrap; user-select: none;
}
.tab:hover { background: #f2f5fc; }
.tab.active { background: #fff; color: #1f3b66; font-weight: 600; }
.tab-close { color: #9aa3b5; font-size: 12px; padding: 0 2px; cursor: pointer; }
.tab-close:hover { color: #e0353b; }
/* tab 内容区 */
#tabpanes { flex: 1; overflow: hidden; background: #eef1f6; padding: 12px; }
#tabpanes .win {
  display: none; height: 100%; flex-direction: column;
  background: #fff; border-radius: 8px; box-shadow: 0 2px 8px rgba(31,59,102,.12); overflow: hidden;
}
#tabpanes .win.active { display: flex; }
#tabpanes .win .win-body { flex: 1; overflow: auto; padding: 14px; }

/* ===================== 按钮 ===================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; padding: 7px 14px; border: 1px solid #cdd5e2;
  background: #fff; color: #333; border-radius: 5px; cursor: pointer; font-size: 13px; line-height: 1; transition: all .12s;
}
.btn:hover { border-color: #2f6fed; color: #2f6fed; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: #2f6fed; border-color: #2f6fed; color: #fff; }
.btn-primary:hover { background: #1f5bd6; color: #fff; }
.btn-danger { background: #e0353b; border-color: #e0353b; color: #fff; }
.btn-danger:hover { background: #c52a30; color: #fff; }
.btn-cancel { background: #f0f2f5; border-color: #e0e4ea; }
.btn-sm { padding: 10px; font-size: 12px; }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.4); color: #fff; }
.btn-ghost:hover { border-color: #fff; color: #fff; }

/* ===================== 首页 ===================== */
.cards-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.card { border: 1px solid #dde4ef; border-radius: 8px; padding: 14px 18px; background: #fbfcff; }
.card .card-k { font-size: 12px; color: #8a94a6; margin: 4px 0 2px; }
.card .card-v { font-size: 20px; font-weight: 700; color: #1f3b66; margin-bottom: 6px; }
.quick-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.quick {
  border: 1px solid #dde4ef; border-radius: 8px; padding: 22px 14px; text-align: center; cursor: pointer;
  background: #fff; transition: all .12s;
}
.quick:hover { border-color: #2f6fed; box-shadow: 0 4px 14px rgba(47,111,237,.18); transform: translateY(-2px); }
.quick b { display: block; font-size: 16px; color: #1f3b66; margin-bottom: 6px; }
.quick span { font-size: 12px; color: #8a94a6; }

/* ===================== 查询/表单工具条 ===================== */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.toolbar input[type=text], .toolbar input[type=date], .toolbar select {
  height: 32px; border: 1px solid #d5dbe5; border-radius: 5px; padding: 0 8px; font-size: 13px; background: #fff;
}
.toolbar select { width: 22%; min-width: 130px; }
.toolbar input[type=text] { width: 180px; }
.toolbar input[type=date] { width: 160px; }
.toolbar input:focus, .toolbar select:focus { outline: none; border-color: #2f6fed; }
.toolbar label { font-size: 12px; color: #666; }

/* 操作按钮组 */
.op-group { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }

/* ===================== 表格 ===================== */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td { border: 1px solid #e4e9f2; padding: 6px 8px; white-space: nowrap; text-align: center; }
table.grid th { background: #f4f6fb; color: #1f3b66; text-align: center; font-weight: 600; }
table.grid tr:nth-child(even) td { background: #fafbfe; }
/* 表格内图片/文字居中 */
table.grid td img { display: inline-block; vertical-align: middle; }
table.grid td input[type=text], table.grid td input[type=number], table.grid td select {
  width: 100%; min-width: 60px; border: 1px solid #d5dbe5; border-radius: 4px; padding: 8px 5px; font-size: 12px; background: #fff;
}
table.grid td input:focus, table.grid td select:focus { outline: none; border-color: #2f6fed; }
/* 复选框列：仅比勾选框稍宽 */
table.grid th.ck, table.grid td.ck { width: 34px; text-align: center; }
/* 操作列：仅容纳图标 */
table.grid th.op, table.grid td.op { width: 76px; text-align: center; white-space: nowrap; }
/* 商品缩略图：点击查看原图 */
.cell-img { height: 30px; cursor: zoom-in; border: 1px solid #e0e6f0; border-radius: 4px; }

/* 行内编辑图标（bootstrap 图标字体适配） */
.icol { cursor: pointer; padding: 2px 4px; margin: 0 2px; font-size: 14px; color: #5a6b86; }
.icol i { font-size: 15px; vertical-align: middle; line-height: 1; }
.icol:hover { color: #2f6fed; }
.icol.del:hover { color: #e0353b; }
.arrow { font-size: 11px; color: #8a94a6; margin-left: 4px; vertical-align: middle; }

/* 状态标签 */
.tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; background: #fff; }
.tag-on { color: #16a34a; border: 1px solid #16a34a; }
.tag-off { color: #e0353b; border: 1px solid #e0353b; }
.tag-audited { color: #1f4fb8; border: 1px solid #2f6fed; }
.tag-save { color: #d97706; border: 1px solid #f59e0b; }

/* ===================== 弹窗 ===================== */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 999; }
.modal { background: #fff; border-radius: 8px; width: 500px; max-width: 92vw; overflow: hidden; }
.modal-title { padding: 12px 16px; font-weight: 600; background: #f4f6fb; border-bottom: 1px solid #e3e8f2; }
.modal-body { padding: 18px 16px; }
.modal-foot { padding: 10px 16px; display: flex; justify-content: flex-end; gap: 8px; background: #fafbfe; border-top: 1px solid #eef1f6; }

/* 表单（弹窗/卡片） */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; }
.form-grid .full { grid-column: 1 / -1; }
/* 单据头部：字段 40% 宽，优先一排，放不下自动换第二排；保存/审核/打印按钮同排靠右 */
.form-grid.head-fields { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.form-grid.head-fields .field { width: 12%; min-width: 120px; flex-shrink: 0; }
.form-grid.head-fields .field input, .form-grid.head-fields .field select { width: auto; }
.form-grid.head-fields .field .full { width: 100%; min-width: 100%; }
/* 保存/审核/打印/新增/新增一行 与头部第一排同行，悬浮靠右 */
.head-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; align-self: center; flex-shrink: 0; }

/* 货号自动补全下拉：货号+品名+库存 */
.code-ac { position: fixed; background: #fff; border: 1px solid #d5dbe5; border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0,0,0,.18); z-index: 1300; max-height: 260px; overflow: auto; font-size: 13px; }
.code-ac-item { padding: 7px 10px; cursor: pointer; display: flex; gap: 10px; align-items: center; white-space: nowrap; }
.code-ac-item .c { color: #2f6fed; font-weight: 600; min-width: 80px; }
.code-ac-item .n { color: #333; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.code-ac-item .s { color: #888; font-size: 12px; }
.code-ac-item.cur { background: #eef3fe; }
.field label { display: block; font-size: 12px; color: #666; margin-bottom: 4px; }
.field input, .field select {
  width: 100%; height: 34px; border: 1px solid #d5dbe5; border-radius: 5px; padding: 0 9px; font-size: 13px; background: #fff;
}
.field input:focus, .field select:focus { outline: none; border-color: #2f6fed; }
/* 图片上传字段：文件名过长省略号显示，不撑宽弹窗 */
.up-wrap { display: flex; align-items: center; gap: 8px; max-width: 100%; min-width: 0; }
.up-wrap input[type=file] { display: none; }
.up-btn { flex-shrink: 0; }
.up-fname { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: #666; flex-shrink: 1; }
.up-prev { flex-shrink: 0; }
.up-prev img { height: 44px; border: 1px solid #e0e6f0; border-radius: 4px; }

/* 原图查看：50% 黑色遮罩，点击空白关闭 */
.img-mask { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 1200; cursor: zoom-out; }
.img-mask img { max-width: 92%; max-height: 92%; background: #fff; box-shadow: 0 8px 40px rgba(0,0,0,.4); border-radius: 4px; }

/* Toast */
.toast {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 1200;
  padding: 10px 22px; border-radius: 6px; color: #fff; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.25); display: none;
}
.toast.ok { background: #16a34a; }
.toast.err { background: #e0353b; }

.empty-tip { padding: 40px; text-align: center; color: #8a94a6; }

/* 分页 */
.pager { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 13px; color: #666; flex-wrap: wrap; }

/* 打印（A4） */
@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area { position: absolute; left: 0; top: 0; width: 210mm; background: #fff; }
  .print-area table { border-collapse: collapse; width: 100%; }
  .print-area table th, .print-area table td { border: 1px solid #000; padding: 4px 6px; font-size: 12px; }
}

/* 筛选下拉（类别/仓库） */
.toolbar select.f-sel { width: 150px; min-width: 150px; }
/* 分页条 */
.pager { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 13px; color: #444; }
.pager .btn-sm { padding: 12px 12px; }
.pager .btn-sm:disabled { opacity: .5; cursor: not-allowed; }
.pager .pg-total { margin-left: auto; color: #888; }
/* 库存统计行 */
tr.grid-stat td { background: #f0f4ff !important; font-size: 13px; font-weight: 600; color: #1f3b66; padding: 8px 10px; }