:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --sidebar: #1f2d3d;
  --sidebar-text: #c8d2e0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --danger: #dc2626;
  --success: #16a34a;
  --warn: #d97706;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 210px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  flex-shrink: 0;
}
.brand {
  padding: 18px 16px;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
  line-height: 1.4;
}
.nav-group { margin-top: 10px; }
.nav-group-title {
  padding: 8px 16px 4px;
  font-size: 12px;
  color: #8fa0b5;
  text-transform: none;
}
.nav-item {
  display: block;
  padding: 9px 16px 9px 24px;
  color: var(--sidebar-text);
  font-size: 13.5px;
}
.nav-item:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar-left { font-weight: 600; color: var(--muted); font-size: 13px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-info em { font-style: normal; color: var(--muted); font-size: 12px; }
.todo-badge {
  display: inline-block;
  background: #fef3c7;
  color: #92400e;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid #fcd34d;
  transition: background .15s, transform .1s;
}
.todo-badge:hover {
  background: #fde68a;
  text-decoration: none;
  color: #92400e;
}
.todo-badge:active { transform: scale(0.97); }
.todo-badge b { font-weight: 700; }
.content { padding: 20px; flex: 1; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}
.page-title { font-size: 20px; font-weight: 700; margin: 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 16px;
}
.card h3 { margin: 0 0 12px; font-size: 15px; }

table.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
}
table.table th, table.table td {
  border: 1px solid var(--border);
  padding: 9px 10px;
  text-align: center;
  vertical-align: middle;
  word-break: keep-all;
  overflow-wrap: break-word;
}
table.table th { background: #f8fafc; font-weight: 600; font-size: 13px; text-align: center; }
table.table tr:hover td { background: #f9fafb; }
table.table .num { text-align: right; font-variant-numeric: tabular-nums; }
table.table .center { text-align: center; }

.btn {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  line-height: 1.4;
}
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-link { border: none; background: none; color: var(--primary); padding: 0 4px; cursor: pointer; font-size: 13px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #e5e7eb;
  color: #374151;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-warn { background: #fef3c7; color: #92400e; }
.badge-muted { background: #e5e7eb; color: #4b5563; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }

.flash {
  margin: 12px 20px 0;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
}
.flash-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.flash-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.flash-info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px 16px;
}
.form-item label {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
  color: var(--muted);
}
.form-item input, .form-item select, .form-item textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
}
.form-item input[type="checkbox"], .form-item input[type="radio"] {
  width: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  flex: 0 0 auto;
}
.form-item input:focus, .form-item select:focus, .form-item textarea:focus {
  outline: 2px solid #bfdbfe;
  border-color: var(--primary);
}
.form-item textarea { min-height: 70px; resize: vertical; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.form-actions { margin-top: 16px; display: flex; gap: 8px; }

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}
.filters input, .filters select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1f2d3d 0%, #2b4a6f 100%);
}
.login-box {
  background: #fff;
  padding: 36px 40px;
  border-radius: 12px;
  width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
.login-box h1 { margin: 0 0 6px; font-size: 20px; }
.login-box .sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-box .form-item { margin-bottom: 14px; }
.login-box .btn { width: 100%; padding: 10px; font-size: 14px; }
.login-err { background: #fee2e2; color: #991b1b; padding: 8px 10px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; }

.captcha-row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.captcha-row input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
  font-family: inherit;
}
.captcha-row input:focus {
  outline: 2px solid #bfdbfe;
  border-color: var(--primary);
}
.captcha-row img {
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  background: #f1f5f9;
  flex-shrink: 0;
  vertical-align: middle;
}
.captcha-row img:hover { border-color: var(--primary); }

/* 商品下拉：输入框外观 + 面板内搜索（仅过滤） */
.combo {
  position: relative;
  min-width: 0;
  width: 100%;
}
.combo-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 36px;
  padding: 7px 10px 7px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
  cursor: text;
  user-select: none;
  font-size: 13.5px;
  line-height: 1.4;
  box-sizing: border-box;
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, .03);
}
.combo-control:hover { border-color: #9ca3af; }
.combo-control:focus,
.combo.is-open .combo-control {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
.combo-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  text-align: left;
  font-size: 13.5px;
}
.combo-label.is-placeholder { color: #9ca3af; }
.combo-caret {
  display: inline-flex;
  align-items: center;
  color: #9ca3af;
  flex-shrink: 0;
  transition: transform .15s ease;
  pointer-events: none;
}
.combo.is-open .combo-caret { transform: rotate(180deg); color: var(--primary); }

/* 原生 select 仅保留表单提交 */
.combo-native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.combo-dropdown {
  position: absolute;
  z-index: 60;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, .14);
  overflow: visible; /* 列表内部自行滚动，面板本身不裁切 */
  min-width: 240px;
}
.combo-list {
  max-height: 260px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px;
  background: #fff;
  border-radius: 0 0 10px 10px;
}
.combo-search {
  width: 100%;
  box-sizing: border-box;
  border: 0;
  border-bottom: 1px solid #eef2f7;
  padding: 11px 14px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  background: #fff;
  color: var(--text);
}
.combo-search::placeholder { color: #9ca3af; }
.combo-search:focus {
  background: #f8fafc;
  border-bottom-color: var(--primary);
}
.combo-item {
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--text);
}
.combo-item:hover,
.combo-item.is-cursor { background: #f1f5f9; }
.combo-item.is-active {
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 600;
}
.combo-empty {
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* 表格内压缩 */
#items-table .combo-control {
  min-height: 34px;
  padding: 6px 8px 6px 10px;
  font-size: 13px;
  border-radius: 6px;
}
#items-table .combo-search { padding: 10px 12px; font-size: 13px; }
#items-table .combo-dropdown { min-width: 200px; }

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 14px; }
.tabs a, .tabs button {
  padding: 8px 16px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  text-decoration: none;
}
.tabs a.active, .tabs button.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.progress-track {
  background: #e5e7eb;
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
  min-width: 80px;
}
.progress-fill { height: 100%; background: var(--primary); border-radius: 999px; }
.progress-fill.ok { background: var(--success); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}
.stat-card .label { color: var(--muted); font-size: 12px; }
.stat-card .value { font-size: 22px; font-weight: 700; margin-top: 4px; }

.modal-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal-mask.show { display: flex; }
.modal {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  width: min(560px, 92vw);
  max-height: 90vh;
  overflow: auto;
}
.modal h3 { margin: 0 0 14px; }
.modal-actions { margin-top: 16px; display: flex; justify-content: flex-end; gap: 8px; }

.hint { color: var(--muted); font-size: 12.5px; margin-top: 6px; }
.diff-warn {
  background: #fff7ed;
  border: 1px solid #fdba74;
  color: #9a3412;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin: 8px 0;
}
.print-area { display: none; }
.doc-sheet {
  border: 1px solid #333;
  padding: 24px;
  margin-bottom: 20px;
  background: #fff;
  color: #000;
  min-width: 700px;
}
.doc-sheet ~ .doc-sheet { page-break-before: always; }
.doc-sheet.xh-doc { border: none; padding: 20px 0; }
.doc-sheet h2 { text-align: center; margin: 0 0 4px; font-size: 20px; }
.doc-sheet .doc-meta { display: flex; justify-content: space-between; margin: 12px 0; font-size: 13px; }
.doc-sheet table { width: 100%; border-collapse: collapse; }
.doc-sheet table th, .doc-sheet table td { border: 1px solid #333; padding: 6px 8px; font-size: 13px; }
.doc-sheet .sign { display: flex; justify-content: space-between; margin-top: 28px; font-size: 13px; }

.bar-chart { display: flex; align-items: flex-end; gap: 10px; height: 160px; padding: 10px 0; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar-col .bar { width: 70%; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar-col .bar.alt { background: #0ea5e9; }
.bar-col .bar-label { font-size: 11px; color: var(--muted); margin-top: 4px; text-align: center; }
.bar-col .bar-val { font-size: 11px; margin-bottom: 2px; }

.empty { padding: 30px; text-align: center; color: var(--muted); }
.mt { margin-top: 14px; }
.right { text-align: right; }
.mono { font-family: Consolas, monospace; font-size: 12.5px; }

/* 主页：部门待办 */
.dept-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}
.dept-card { margin-bottom: 0; padding: 14px 0 8px; }
.dept-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.dept-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
}
.todo-list { list-style: none; margin: 0; padding: 0; }
.todo-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px dashed #f0f2f5;
  font-size: 13px;
}
.todo-item:last-child { border-bottom: none; }
.todo-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.todo-time { color: var(--muted); font-size: 12px; flex-shrink: 0; }
a.stat-card:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(37,99,235,.12); text-decoration: none; }

/* ========== 出入库开单页 ========== */
.stock-form .form-grid {
  grid-template-columns: repeat(4, 1fr);
  gap: 14px 16px;
}
@media (max-width: 1100px) {
  .stock-form .form-grid { grid-template-columns: repeat(2, 1fr); }
}
.stock-form .form-item.remark-full { grid-column: 1 / -1; }
.stock-form .form-item.remark-full textarea { min-height: 56px; }

.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 22px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.section-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.section-head .section-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.section-head .section-desc {
  color: var(--muted);
  font-size: 12.5px;
  margin-left: auto;
}

/* 合同自动匹配信息卡 */
.contract-banner {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  background: linear-gradient(135deg, #eff6ff 0%, #f0f9ff 100%);
  border: 1px solid #bfdbfe;
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 14px 16px;
  margin-top: 4px;
}
.contract-banner .cb-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}
.contract-banner .cb-body { flex: 1; min-width: 0; }
.contract-banner .cb-title {
  font-weight: 600;
  font-size: 13.5px;
  color: #1e40af;
  margin-bottom: 6px;
}
.contract-banner .cb-title b { color: #1e3a8a; }
.contract-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
.contract-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid #dbeafe;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12.5px;
  color: #1f2937;
}
.contract-chip .chip-name { font-weight: 600; }
.contract-chip .chip-remain {
  color: var(--warn);
  font-weight: 700;
}
.contract-chip .chip-ok { color: var(--success); font-weight: 700; }

/* 录入提示（压缩） */
.entry-tips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 12px;
}
.entry-tips b { color: var(--text); }
.entry-tips .tip-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  margin-right: 4px;
}
.entry-tips .tag-normal { background: #e5e7eb; color: #374151; }
.entry-tips .tag-chem { background: #dbeafe; color: #1e40af; }

/* 明细表格内控件 —— 不要用 overflow:hidden，否则会裁掉绝对定位的下拉面板 */
#items-table { border-radius: 8px; }
#items-table .col-spec { display: none; }
#items-table .col-spec.shown { display: table-cell; }
#items-table th { white-space: nowrap; }
#items-table th {
  background: #f1f5f9;
  font-size: 12.5px;
  padding: 10px 8px;
  white-space: nowrap;
}
#items-table th:first-child { border-top-left-radius: 8px; }
#items-table th:last-child { border-top-right-radius: 8px; }
#items-table td {
  padding: 8px;
  background: #fff;
  /* 允许下拉溢出单元格 */
  overflow: visible;
}
#items-table input,
#items-table select {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
}
#items-table input:focus,
#items-table select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
#items-table .cell-result {
  background: #f0fdf4 !important;
  border-color: #bbf7d0 !important;
  color: #166534;
  font-weight: 700;
  text-align: center;
  cursor: default;
}
#items-table .cell-type .badge { white-space: nowrap; }
#items-table .col-del {
  width: 52px;
  text-align: center;
}
.row-del {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: var(--danger);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.row-del:hover { background: #fee2e2; }

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}
.table-toolbar .hint { margin: 0; }

.stock-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  gap: 12px;
}
.stock-actions .left-hint { color: var(--muted); font-size: 12.5px; }
.stock-actions .btn-group { display: flex; gap: 10px; }
.stock-actions .btn-primary,
.stock-actions .btn-success {
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
}
.stock-actions .btn {
  padding: 10px 18px;
  font-size: 14px;
  border-radius: 8px;
}

/* 录入步骤说明（页头） */
.page-subtitle {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
  margin-left: 10px;
}

/* 出入库页待办窗口 */
.todo-panel { padding: 0; overflow: hidden; }
.todo-panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: #fffbeb;
  border-bottom: 1px solid #fde68a;
}
.todo-panel .todo-item { padding: 9px 14px; }
.todo-panel .todo-title { color: var(--text); }
.todo-panel .todo-title:hover { color: var(--primary); text-decoration: underline; }
.todo-panel .btn-sm { flex-shrink: 0; }

/* ========== 悬浮 AI 助手 ========== */
.ai-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 9000;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(37, 99, 235, .4);
  transition: transform .15s, box-shadow .15s;
  border: none;
}
.ai-fab:hover { transform: scale(1.06); box-shadow: 0 10px 28px rgba(37, 99, 235, .5); }
.ai-fab.is-open { opacity: 0; pointer-events: none; }

.ai-panel {
  position: fixed;
  right: 22px;
  bottom: 86px;
  z-index: 9001;
  width: min(380px, calc(100vw - 32px));
  height: min(520px, calc(100vh - 120px));
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 16px 48px rgba(15, 23, 42, .22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.ai-panel[hidden] { display: none !important; }

.ai-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: linear-gradient(135deg, #1e3a8a, #4f46e5);
  color: #fff;
  flex-shrink: 0;
}
.ai-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
}
.ai-title em {
  font-style: normal;
  font-size: 11px;
  opacity: .8;
  font-weight: 400;
}
.ai-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 6px #4ade80;
}
.ai-close {
  border: none;
  background: rgba(255, 255, 255, .15);
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.ai-close:hover { background: rgba(255, 255, 255, .28); }

.ai-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ai-msg { display: flex; }
.ai-msg-user { justify-content: flex-end; }
.ai-msg-bot { justify-content: flex-start; }
.ai-bubble {
  max-width: 88%;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.ai-msg-bot .ai-bubble {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.ai-msg-user .ai-bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-bubble.is-thinking { color: var(--muted); font-style: italic; }

.ai-input-row {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--border);
  background: #fff;
  flex-shrink: 0;
  align-items: flex-end;
}
.ai-input-row textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13.5px;
  font-family: inherit;
  max-height: 96px;
  min-height: 40px;
}
.ai-input-row textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.ai-send { border-radius: 10px; padding: 8px 16px; }
.ai-send:disabled { opacity: .6; cursor: wait; }

/* 常州朱禧出入库单模板 */
.xh-doc { max-width: 820px; margin: 0 auto; border: none; font-family: "Microsoft YaHei","微软雅黑",sans-serif; line-height: 1.5; }
.xh-title { text-align: center; font-size: 24px; font-weight: 700; letter-spacing: 3px; padding: 10px 0 28px; font-family: "Microsoft YaHei","微软雅黑",sans-serif; }
.xh-meta { display: flex; justify-content: space-between; align-items: baseline; padding: 2px 28px 6px; font-size: 15px; }
.xh-meta2 { display: flex; justify-content: space-between; align-items: baseline; gap: 24px; padding: 2px 28px 14px; font-size: 14px; color: #222; }
.xh-meta2 > span:first-child { flex: 1; }
.xh-meta2 > span:last-child:not(:first-child) { flex: 1; text-align: right; }
.xh-table { border-collapse: collapse; margin: 0 24px; width: calc(100% - 48px); }
.xh-doc .xh-table { width: calc(100% - 48px); margin: 0 24px; }
.xh-doc .xh-meta, .xh-doc .xh-foot, .xh-doc .xh-note { padding-left: 24px; padding-right: 24px; }
.xh-table th, .xh-table td { border: 1px solid #333; padding: 8px 6px; font-size: 13px; height: 28px; text-align: center; vertical-align: middle; }
.xh-table th { background: #f0f0f0; text-align: center; font-weight: 600; }
.xh-table .center { text-align: center; }
.xh-table .num { text-align: center; font-variant-numeric: tabular-nums; }
.xh-table .right { text-align: center; }
.xh-foot { display: flex; justify-content: space-between; align-items: center; padding: 28px 24px 12px; font-size: 16px; gap: 20px; }
.xh-foot .xh-sign-right { margin-left: auto; text-align: right; min-width: 45%; }
.xh-note { padding: 12px 24px 18px; font-size: 13px; color: #666; line-height: 1.7; }

/* ========== 手机端适配 ========== */
html { -webkit-text-size-adjust: 100%; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.nav-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
  padding: 6px 10px;
  margin-right: 10px;
  cursor: pointer;
  color: var(--text);
}
.sidebar-mask { display: none; }

@media (max-width: 820px) {
  .nav-toggle { display: inline-block; }

  /* 侧栏 → 抽屉 */
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 60;
    width: 220px;
    transform: translateX(-100%);
    transition: transform .2s ease;
    overflow-y: auto;
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .sidebar-mask {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(0,0,0,.35);
    visibility: hidden;
    opacity: 0;
    transition: opacity .2s;
  }
  body.nav-open .sidebar-mask { visibility: visible; opacity: 1; }

  /* 顶栏与内容 */
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-left { display: flex; align-items: center; min-width: 0; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-right { gap: 8px; }
  .content { padding: 12px; }
  .page-title { font-size: 17px; }

  /* 表格：容器内横向滚动，保持列可读 */
  .card { padding: 12px; overflow-x: auto; }
  table.table { min-width: 560px; }
  /* 列最小宽度：防中文逐字竖排（宁可横滑不可压扁） */
  table.table th, table.table td { min-width: 84px; }
  table.table th.mono, table.table td.mono { min-width: 130px; }

  /* 栅格堆叠 */
  .two-col { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .dept-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .stock-form .form-grid { grid-template-columns: 1fr; }

  /* 筛选与操作区 */
  .filters { gap: 8px; }
  .filters input, .filters select { flex: 1 1 130px; min-width: 0; }
  .stock-actions { flex-direction: column; align-items: stretch; gap: 8px; }
  .stock-actions .btn-group { display: flex; gap: 8px; }
  .stock-actions .btn-group .btn { flex: 1; text-align: center; }
  .table-toolbar { flex-wrap: wrap; gap: 8px; }

  /* 登录页 */
  .login-box { width: min(380px, calc(100vw - 32px)); padding: 28px 22px; }
}

@media (max-width: 480px) {
  .user-info { display: none; }
  .topbar-left .brand-text { display: none; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}