/* ============ 物料生产管理系统 样式 ============ */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --muted: #6b7280;
  --border: #e5e7eb;
  --bg: #f3f4f6;
  --card-bg: #ffffff;
  --text: #111827;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.15);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ===== 顶部栏 ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  min-height: 64px;
  position: sticky;
  top: 0;
  z-index: 50;
  justify-content: space-between;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  flex-shrink: 0;
  min-width: 0;
}
.brand .logo { height: 38px; width: auto; display: block; }
.brand-text { min-width: 0; }
.brand h1 { font-size: 17px; font-weight: 800; letter-spacing: -0.3px; }
.brand p { font-size: 12px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand p .th { font-size: 11px; opacity: 0.7; margin-left: 4px; }

.tabs {
  display: inline-flex;
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin: 0 auto;
  flex-shrink: 1;
  min-width: 0;
}
.tab-btn {
  border: none; background: none; cursor: pointer;
  padding: 7px 14px; border-radius: 6px;
  font-size: 14px; color: var(--muted); font-weight: 500;
  transition: all .15s;
  white-space: nowrap;
}
.tab-btn .th { display: block; font-size: 10px; opacity: 0.75; line-height: 1; margin-top: 2px; }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { background: #fff; color: var(--primary); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.06); }

.topbar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

/* 用户下拉菜单 */
.user-menu { position: relative; }
.user-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: #fff; border: 1px solid var(--border);
  border-radius: 22px; padding: 5px 10px 5px 6px;
  cursor: pointer;
  transition: all .15s;
  font-size: 13px;
}
.user-chip:hover { background: var(--bg); border-color: #d1d5db; }
.user-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--primary-light); color: var(--primary);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.user-info { display: inline-flex; flex-direction: column; align-items: flex-start; line-height: 1.2; }
.user-name { font-weight: 600; color: var(--text); font-size: 13px; }
.user-role { font-size: 11px; color: var(--muted); }
.user-dropdown {
  position: absolute; top: calc(100% + 6px); right: 0;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow-lg);
  min-width: 150px;
  display: none; overflow: hidden;
}
.user-dropdown.open { display: block; }
.user-dropdown a {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; color: var(--text); text-decoration: none;
  font-size: 13px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.user-dropdown a:last-child { border-bottom: none; }
.user-dropdown a:hover { background: var(--bg); }
.user-dropdown .th { font-size: 11px; color: var(--muted); margin-left: auto; }
.user-dropdown .th-icon { font-size: 14px; }

.role-tag {
  display: inline-block; font-size: 11px; color: var(--primary);
  background: var(--primary-light); border-radius: 4px;
  padding: 1px 6px; margin-left: 2px; vertical-align: middle;
}
.muted { color: var(--muted); font-size: 12px; }

/* 小屏适配 */
@media (max-width: 1100px) {
  .brand p { display: none; }
  .tab-btn { padding: 7px 10px; font-size: 13px; }
}
@media (max-width: 880px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .tabs { order: 3; width: 100%; margin: 0; justify-content: center; }
  .brand { order: 1; }
  .topbar-right { order: 2; }
}

/* 登录弹窗 */
.login-modal { width: 380px; max-width: 92vw; }
.login-logo { text-align: center; margin-bottom: 16px; }
.login-logo .logo { height: 56px; width: auto; margin: 0 auto 8px; display: block; }
.login-logo h2 { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.login-logo p { font-size: 12px; color: var(--muted); }

/* ===== 内容区 ===== */
.content { max-width: 1200px; margin: 24px auto; padding: 0 24px; }
.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.card-head h3 { font-size: 15px; }
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 10px; }

/* ===== 按钮 ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent; cursor: pointer;
  padding: 8px 14px; border-radius: 6px;
  font-size: 14px; font-weight: 500; text-decoration: none;
  transition: all .15s; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: #fff; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: .9; }
.btn-danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--danger-light); }
.btn-sm { padding: 4px 10px; font-size: 13px; border-radius: 5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ===== 输入框 ===== */
.input {
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 12px; font-size: 14px; width: 100%;
  background: #fff; color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.input.select { appearance: auto; }
.input::placeholder { color: #9ca3af; }
input[type=search].input { min-width: 260px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 500; color: #374151; }
.field em { color: var(--danger); font-style: normal; }
.field .input { width: 100%; }

.tip { font-size: 12px; color: var(--muted); margin-bottom: 12px; }

/* ===== 表格 ===== */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; min-width: 760px; }
.table th, .table td {
  padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table th {
  font-size: 12px; color: var(--muted); font-weight: 600;
  background: #f9fafb; text-transform: none;
}
.table tbody tr:hover { background: #f9fafb; }
.table tbody tr:last-child td { border-bottom: none; }
.table .th-actions { width: 150px; text-align: right; }
.table td.actions { text-align: right; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table th.num { text-align: right; }

.empty-tip {
  text-align: center; color: var(--muted); padding: 40px 0; font-size: 14px;
}

/* ===== 状态徽标 ===== */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 500; line-height: 1.4;
}
.badge-run { background: var(--primary-light); color: var(--primary); }
.badge-done { background: var(--success-light); color: var(--success); }
.badge-cancel { background: #f3f4f6; color: var(--muted); }
.badge-pending { background: #f3f4f6; color: var(--muted); }
.badge-warn { background: var(--warning-light); color: var(--warning); }
.badge-bad { background: var(--danger-light); color: var(--danger); }

.progress-cell { display: flex; align-items: center; gap: 8px; }
.progress-bar {
  width: 90px; height: 6px; background: #e5e7eb; border-radius: 3px; overflow: hidden;
}
.progress-bar > span { display: block; height: 100%; background: var(--success); border-radius: 3px; }

/* ===== 统计卡片 ===== */
.stat-cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px; margin-bottom: 20px;
}
.stat-card {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.stat-card .label { font-size: 12px; color: var(--muted); }
.stat-card .value { font-size: 26px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat-card .value.ok { color: var(--success); }
.stat-card .value.primary { color: var(--primary); }
.stat-card .value.warn { color: var(--warning); }
.stat-card .value.danger { color: var(--danger); }

/* ===== 弹窗 ===== */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: #fff; border-radius: 10px; box-shadow: var(--shadow-lg);
  border: 1px solid var(--border); min-width: 200px; padding: 6px;
  display: none; z-index: 60;
}
.dropdown-menu.show { display: block; }
.dropdown-menu button {
  display: block; width: 100%; text-align: left; padding: 9px 12px;
  border: none; background: none; border-radius: 8px; cursor: pointer;
  font-size: 14px; color: var(--text);
}
.dropdown-menu button:hover { background: #f3f4f6; }
.dropdown-menu button .th { font-size: 12px; }

.modal-mask {
  position: fixed; inset: 0; background: rgba(17,24,39,.45);
  display: none; align-items: flex-start; justify-content: center;
  z-index: 100; padding: 60px 16px 30px; overflow-y: auto;
}
.modal-mask.show { display: flex; }
.modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 460px;
  box-shadow: var(--shadow-lg); animation: slideUp .2s ease;
}
.modal-lg { max-width: 680px; }
.modal-xl { max-width: 900px; }
@keyframes slideUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 16px; }
.modal-head .detail-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.modal-close {
  border: none; background: none; font-size: 22px; color: var(--muted);
  cursor: pointer; line-height: 1; padding: 0 4px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px 22px; max-height: 65vh; overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 22px; border-top: 1px solid var(--border);
}

/* ===== 工序流转 ===== */
.flow-summary {
  display: flex; align-items: center; gap: 4px;
  padding: 12px 4px 20px; overflow-x: auto;
}
.flow-step {
  display: flex; align-items: center; gap: 4px; flex-shrink: 0;
}
.flow-dot {
  width: 34px; height: 34px; border-radius: 50%;
  background: #f3f4f6; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; border: 2px solid var(--border);
}
.flow-dot.done { background: var(--success); border-color: var(--success); color: #fff; }
.flow-dot.current { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 0 0 4px rgba(37,99,235,.18); }
.flow-dot.wait { background: #fff; }
.flow-dot.bad { background: var(--danger); border-color: var(--danger); color: #fff; }
.flow-name { font-size: 12px; text-align: center; max-width: 72px; overflow: hidden; text-overflow: ellipsis; }
.flow-line { width: 26px; height: 2px; background: var(--border); }
.flow-line.done { background: var(--success); }

.record-item {
  border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 12px; overflow: hidden;
}
.record-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; background: #f9fafb; cursor: pointer;
}
.record-head:hover { background: #f3f4f6; }
.record-head .seq-badge {
  width: 26px; height: 26px; border-radius: 50%; background: var(--primary-light);
  color: var(--primary); font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.record-head .rec-name { font-weight: 600; }
.record-head .rec-meta { color: var(--muted); font-size: 13px; }
.record-head .spacer { flex: 1; }
.record-head .arrow { color: var(--muted); font-size: 12px; }
.record-body {
  padding: 14px 16px; border-top: 1px solid var(--border); display: none;
  background: #fff;
}
.record-body.open { display: block; }
.qty-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 14px;
}
.qty-box {
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  background: #f9fafb; text-align: center;
}
.qty-box .qty-label { font-size: 12px; color: var(--muted); }
.qty-box .qty-value { font-size: 20px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.qty-box.good .qty-value { color: var(--success); }
.qty-box.bad .qty-value { color: var(--danger); }
.qty-box.in .qty-value { color: var(--primary); }
.record-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.record-note { font-size: 12px; color: var(--muted); margin-top: 10px; }
.record-note span { margin-right: 14px; }

/* ===== 工序任务分配（一工序多工人/多机台） ===== */
.task-list {
  border: 1px dashed var(--border); border-radius: 8px;
  padding: 8px 10px; margin-bottom: 12px; background: #fcfcfd;
}
.task-list-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px;
}
.task-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 5px 8px; border-radius: 6px; background: #fff;
  border: 1px solid var(--border); margin-top: 6px; font-size: 12.5px;
}
.task-person { font-weight: 600; color: var(--primary); }
.task-machine { color: var(--muted); }
.task-qty { color: #374151; font-variant-numeric: tabular-nums; margin-left: auto; }
.task-empty { font-size: 12px; color: var(--muted); padding: 4px 2px; }
.btn-xs { padding: 2px 8px; font-size: 12px; border-radius: 6px; }
.btn-xs.btn-primary { background: var(--primary); color: #fff; border: 1px solid var(--primary); }
.btn-xs.btn-ghost { background: #fff; color: var(--muted); border: 1px solid var(--border); }
.btn-xs.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }

/* ===== 工序模板编辑 ===== */
.proc-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
}
.proc-row .proc-seq {
  width: 44px; text-align: center; color: var(--muted); font-weight: 600;
  flex-shrink: 0;
}
.proc-row .input { flex: 1; }
.proc-row .btn-del-row {
  border: none; background: none; color: var(--danger); cursor: pointer;
  font-size: 18px; line-height: 1; padding: 4px; flex-shrink: 0;
}
.proc-row .btn-del-row:hover { opacity: .7; }
.proc-row .proc-drag { color: #d1d5db; cursor: move; user-select: none; flex-shrink: 0; }

/* ===== 多物料订单 ===== */
.order-item-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
}
.order-item-row .order-item-mat { flex: 1; min-width: 0; }
.order-item-row .order-item-qty { width: 100px; flex-shrink: 0; }
.order-item-row .btn-del-row {
  border: none; background: none; color: var(--danger); cursor: pointer;
  font-size: 20px; line-height: 1; padding: 4px 6px; flex-shrink: 0;
}
.order-item-row .btn-del-row:hover { opacity: .7; }

/* 订单表格物料明细列 */
.mat-cell { min-width: 140px; }
.mat-line { white-space: nowrap; line-height: 1.7; }
.mat-line .mat-qty { color: var(--muted); font-size: 12px; }

/* 订单详情：物料切换 tabs */
.item-tabs {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px;
}
.item-tab {
  border: 1px solid var(--border); background: #fff; color: #374151;
  border-radius: 8px; padding: 7px 12px; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.item-tab:hover { border-color: var(--primary); color: var(--primary); }
.item-tab.active {
  background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600;
}
.item-tab .item-tab-qty { font-size: 11px; opacity: .8; }

/* ===== Toast ===== */
.toast-wrap {
  position: fixed; top: 76px; right: 24px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: 13px; box-shadow: var(--shadow-lg); animation: slideIn .2s ease;
  max-width: 340px;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes slideIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }

@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 12px; gap: 10px; }
  .tabs { width: 100%; margin: 0; }
  .topbar-right { width: 100%; }
  .topbar-right .btn { flex: 1; justify-content: center; }
  .content { padding: 12px; }
  .toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .toolbar-left input[type=search].input { width: 100%; }
  .qty-grid { grid-template-columns: 1fr; }
}

/* ===== 车间/班组 双列输入 ===== */
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ===== 弹窗头部操作区 ===== */
.modal-head-actions { display: flex; align-items: center; gap: 8px; }

/* ===== 订单跟踪二维码弹窗 ===== */
#qrcodeList {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px; margin-bottom: 14px;
}
.qr-track {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 16px;
  border: 2px solid var(--primary); border-radius: 10px;
  background: linear-gradient(135deg, #fff, var(--primary-light));
  padding: 14px 16px; margin-bottom: 4px;
}
.qr-track-info { flex: 1; min-width: 0; }
.qr-track-title { font-size: 15px; font-weight: 700; color: var(--primary); margin-bottom: 6px; }
.qr-track-desc { font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.qr-track-link {
  margin-top: 8px; font-size: 11.5px; color: var(--muted);
  word-break: break-all; background: #fff; border: 1px dashed var(--border);
  border-radius: 5px; padding: 5px 8px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.qr-track-img { width: 110px; height: 110px; border: 1px solid var(--border); background: #fff; border-radius: 6px; flex-shrink: 0; }
#qrcodeList .qr-tip { grid-column: 1 / -1; font-size: 12px; color: var(--muted); background: #fff; border: 1px dashed var(--border); border-radius: 6px; padding: 10px 12px; }
#qrcodeList .qr-tip code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }
#qrcodeList .qr-tip b { color: var(--primary); }

/* ===== 中泰双语：泰语文字样式 ===== */
.th { font-weight: 400; color: #9ca3af; margin-left: 2px; }
.btn .th, .tab-btn .th { display: block; font-size: 11px; line-height: 1.35; }
.btn-sm .th { font-size: 10px; }
.table th .th { font-size: 10px; }
.badge .th { font-size: 10px; }
.tab-btn.active .th { color: var(--primary); opacity: .75; }
.btn-primary .th { color: rgba(255,255,255,.82); }
.modal-head h3 .th { font-size: 12px; }
.brand p .th { font-size: 11px; }
.record-note, .rec-meta, .qty-label, .detail-sub { white-space: normal; }
