/* 瑞达排单系统 - 简洁企业内部风格（浅色） */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  font-size: 14px; color: #1f2937; background: #f3f4f6;
}
.hidden { display: none !important; }
a { color: #2563eb; text-decoration: none; cursor: pointer; }

/* ---------- 登录 ---------- */
.login-wrap { display: flex; align-items: center; justify-content: center; height: 100vh; background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%); }
.login-card { background: #fff; border-radius: 12px; padding: 40px 36px; width: 360px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-logo { font-size: 22px; font-weight: 700; text-align: center; color: #1e3a8a; }
.login-sub { font-size: 11px; color: #9ca3af; text-align: center; letter-spacing: 2px; margin: 6px 0 24px; }
.login-card label { display: block; font-size: 13px; color: #6b7280; margin: 14px 0 6px; }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px; }
.login-card input:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.login-msg { color: #dc2626; font-size: 13px; min-height: 20px; margin-top: 10px; }

/* ---------- 布局 ---------- */
.app { display: flex; height: 100vh; }
.sidebar { width: 190px; background: #1e3a8a; color: #cbd5e1; display: flex; flex-direction: column; flex-shrink: 0; }
.brand { padding: 20px 16px; font-size: 17px; font-weight: 700; color: #fff; line-height: 1.4; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand span { font-size: 10px; font-weight: 400; color: #93a5c8; letter-spacing: 1px; }
.sidebar nav { flex: 1; padding: 10px 0; overflow-y: auto; }
.sidebar nav a { display: block; padding: 10px 18px; color: #cbd5e1; font-size: 14px; }
.sidebar nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar nav a.active { background: #2563eb; color: #fff; }
.sidebar-foot { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.12); font-size: 12px; }
.sidebar-foot #whoami { color: #fff; margin-bottom: 8px; }
.sidebar-foot a { display: inline-block; color: #93a5c8; margin-right: 12px; }
.sidebar-foot a:hover { color: #fff; }
.main { flex: 1; overflow-y: auto; padding: 22px 26px; }

/* ---------- 通用 ---------- */
.page-title { font-size: 19px; font-weight: 700; margin-bottom: 16px; color: #111827; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.stat-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 4px; }
.stat { background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 7px 14px; font-size: 13px; color: #6b7280; }
.stat b { font-size: 16px; color: #1e3a8a; margin: 0 2px; }
.stat.warn { background: #fffbeb; border-color: #fde68a; }
.stat.warn b { color: #b45309; }
.chk { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: #374151; white-space: nowrap; }
.chk input { width: auto; margin: 0; }
.sum-row:hover { background: #f8fafc; }
.card { background: #fff; border-radius: 10px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.07); margin-bottom: 16px; }

table.grid { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.07); }
table.grid th { background: #f8fafc; color: #475569; font-size: 13px; font-weight: 600; text-align: left; padding: 10px 12px; border-bottom: 1px solid #e5e7eb; white-space: nowrap; }
table.grid td { padding: 9px 12px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
table.grid tr:hover td { background: #f8fafc; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.grid.nums td { white-space: nowrap; }
/* 订单表列多（含勾选列/操作列），保底宽度让客户名、产品、时间不折行，窄屏改为横向滚动 */
table.grid.grid-orders {
  min-width: 1200px;
  /* table 上的 border-collapse:collapse + overflow:hidden 会让 td 的 position:sticky 失效，这里显式覆盖 */
  border-collapse: separate;
  border-spacing: 0;
  overflow: visible;
}
/* 订单号/客户/业务员/日期不折行，避免被挤成竖排；产品明细列允许多行 */
table.grid.grid-orders td { white-space: nowrap; }
table.grid.grid-orders td.muted { white-space: normal; }
/* 订单表操作列固定在右侧：横向滚动时「删除」始终可见 */
table.grid.grid-orders th:last-child,
table.grid.grid-orders td:last-child {
  position: sticky; right: 0; background: #fff;
  box-shadow: -6px 0 8px -6px rgba(15, 23, 42, .18);
}
table.grid.grid-orders tr:hover td:last-child { background: #f8fafc; }

input, select, textarea { font-family: inherit; font-size: 14px; padding: 7px 10px; border: 1px solid #d1d5db; border-radius: 7px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
textarea { width: 100%; resize: vertical; }

.btn { display: inline-block; padding: 7px 16px; font-size: 14px; border: none; border-radius: 7px; cursor: pointer; background: #e5e7eb; color: #374151; white-space: nowrap; }
.btn:hover { filter: brightness(.96); }
.btn-primary { background: #2563eb; color: #fff; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-success { background: #059669; color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; white-space: nowrap; }
.st-pending   { background: #fef3c7; color: #92400e; }
.st-scheduled { background: #dbeafe; color: #1e40af; }
.st-producing { background: #e0e7ff; color: #4338ca; }
.st-completed { background: #d1fae5; color: #065f46; }
.st-shipped   { background: #e5e7eb; color: #374151; }
.st-cancelled { background: #fee2e2; color: #991b1b; }
.pr-urgent { background: #fee2e2; color: #b91c1c; font-weight: 600; }
.pr-normal { background: #f3f4f6; color: #6b7280; }

/* 仪表盘 */
.dash-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.dash-card { background: #fff; border-radius: 10px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.07); }
.dash-card .num { font-size: 26px; font-weight: 700; color: #1e3a8a; }
.dash-card .lbl { font-size: 13px; color: #6b7280; margin-top: 4px; }

/* 表单 */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-bottom: 14px; }
.form-item label { display: block; font-size: 13px; color: #6b7280; margin-bottom: 5px; }
.form-item input, .form-item select { width: 100%; }
.form-full { grid-column: 1 / -1; }

/* 弹窗 */
.modal-mask { position: fixed; inset: 0; background: rgba(17,24,39,.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-box { background: #fff; border-radius: 12px; padding: 22px; width: 520px; max-width: 94vw; max-height: 88vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* 提示 */
.toast { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 22px; border-radius: 8px; font-size: 14px; z-index: 99; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast.err { background: #dc2626; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; font-size: 13px; color: #6b7280; }
.muted { color: #9ca3af; }
.mt8 { margin-top: 8px; }
.mt16 { margin-top: 16px; }
.err-list { background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; padding: 10px 14px; margin-top: 10px; font-size: 13px; color: #991b1b; max-height: 220px; overflow-y: auto; }
.ok-list { background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 8px; padding: 10px 14px; margin-top: 10px; font-size: 13px; color: #065f46; }

/* ---------- 订单明细：类型 / 粒径 / 包装克重 / 数量 ---------- */
.section-title { font-size: 15px; font-weight: 700; margin: 16px 0 10px; color: #111827; }
.warn-box { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-bottom: 10px; line-height: 1.6; }
.item-card { border: 1px solid #e5e7eb; border-radius: 10px; padding: 12px; margin-bottom: 12px; background: #fcfdff; }
.item-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.item-no { font-size: 13px; font-weight: 700; color: #1e3a8a; }
.item-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.if { display: block; min-width: 0; }
.if > span:first-child { display: block; font-size: 12px; color: #6b7280; margin-bottom: 4px; }
.if select, .if input { width: 100%; }
.qty-wrap { display: flex; gap: 6px; align-items: stretch; }
.qty-wrap input { flex: 1; min-width: 0; }
.qty-wrap select { width: 64px; flex-shrink: 0; }
.item-fields .if:nth-child(7) { grid-column: span 2; }
.item-calc { margin-top: 10px; padding-top: 10px; border-top: 1px dashed #e5e7eb; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 6px 16px; font-size: 13px; }
.item-calc .kv { display: flex; gap: 8px; align-items: baseline; }
.item-calc .kv > span { color: #9ca3af; flex-shrink: 0; width: 64px; }
.item-calc .kv > b { color: #111827; font-weight: 600; word-break: break-word; }
.item-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.sum-bar { display: flex; flex-wrap: wrap; gap: 8px 22px; background: #f8fafc; border: 1px solid #e5e7eb; border-radius: 8px; padding: 10px 14px; font-size: 13px; }
.sum-bar > div { display: flex; align-items: baseline; gap: 5px; }
.sum-bar span { color: #6b7280; }
.sum-bar b { font-size: 15px; color: #1e3a8a; }
.sum-bar i { font-style: normal; font-size: 12px; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 4px; background: #eef2ff; color: #4338ca; font-size: 11.5px; vertical-align: middle; white-space: nowrap; }
.stock-short { color: #dc2626 !important; font-weight: 700; }

@media (max-width: 760px) {
  /* 手机：侧边栏改为顶部横向导航条，正文纵向滚动 */
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .brand { display: none; }
  .sidebar nav { display: flex; flex: 1; padding: 0; overflow: visible; }
  .sidebar nav a { white-space: nowrap; padding: 13px 15px; font-size: 13.5px; }
  .sidebar-foot { display: flex; align-items: center; gap: 10px; border-top: none; border-left: 1px solid rgba(255,255,255,.12); padding: 0 12px; white-space: nowrap; }
  .sidebar-foot #whoami { display: none; }
  .sidebar-foot a { margin-right: 0; }
  .main { padding: 12px; }
  .card { padding: 13px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .form-grid .form-full { grid-column: 1 / -1; }
  #modalBox .form-grid { grid-template-columns: 1fr; }
  .item-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .item-fields .if:nth-child(3) { grid-column: 1 / -1; }  /* 所需包装袋整行显示 */
  .item-fields .if:nth-child(7) { grid-column: 1 / -1; }
  .item-calc { grid-template-columns: 1fr; }
  .item-calc .kv > span { width: 72px; }
  .sum-bar { gap: 6px 14px; }
  table.grid.nums { min-width: 640px; }
  /* 手机端表格：不压缩列，改为横向滚动，避免文字被挤成竖排 */
  table.grid { min-width: 720px; }
  table.grid.grid-orders { min-width: 900px; }
  table.grid th, table.grid td { white-space: nowrap; }
  /* 手机端工具栏：搜索框占满一行，筛选/按钮自动换行 */
  .toolbar input#cusQ, .toolbar input#suQ { flex: 1 1 100%; width: auto !important; }
  .page-title { font-size: 17px; }
}
