/* ===== 工易云服 ERP 系统样式 ===== */
:root {
  --primary: #1a3a6b;
  --primary-light: #2355a0;
  --gold: #c8a94a;
  --gold-light: #e8c96a;
  --bg: #f0f2f7;
  --sidebar-bg: #0f2347;
  --white: #ffffff;
  --text: #2d3748;
  --text-light: #718096;
  --border: #e2e8f0;
  --success: #48bb78;
  --warning: #ed8936;
  --danger: #e53e3e;
  --info: #4299e1;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --radius: 10px;
  --radius-lg: 16px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif; background: var(--bg); color: var(--text); }

/* 布局 */
.app { display: flex; height: 100vh; overflow: hidden; }

/* 侧边栏 */
.sidebar {
  width: 240px; min-width: 240px; background: var(--sidebar-bg);
  display: flex; flex-direction: column; overflow-y: auto;
  box-shadow: 4px 0 20px rgba(0,0,0,0.2);
}
.sidebar-logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-logo .logo-title {
  color: var(--gold); font-size: 18px; font-weight: 700; letter-spacing: 1px;
}
.sidebar-logo .logo-sub {
  color: rgba(255,255,255,0.5); font-size: 11px; margin-top: 4px;
}
.sidebar-menu { padding: 12px 0; flex: 1; }
.menu-group-title {
  color: rgba(255,255,255,0.35); font-size: 10px; letter-spacing: 1.5px;
  padding: 16px 20px 6px; text-transform: uppercase;
}
.menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 20px; cursor: pointer; transition: all 0.2s;
  color: rgba(255,255,255,0.65); font-size: 14px; border-radius: 0;
  border-left: 3px solid transparent; margin: 1px 0;
}
.menu-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.menu-item.active {
  background: rgba(200,169,74,0.18); color: var(--gold-light);
  border-left-color: var(--gold);
}
.menu-item .icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-footer {
  padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.4); font-size: 12px;
}

/* 主内容 */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* 顶栏 */
.topbar {
  height: 60px; background: var(--white); display: flex; align-items: center;
  justify-content: space-between; padding: 0 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06); z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.page-title { font-size: 18px; font-weight: 600; color: var(--primary); }
.page-subtitle { font-size: 13px; color: var(--text-light); }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-btn {
  padding: 7px 16px; border-radius: 8px; border: none; cursor: pointer;
  font-size: 13px; font-weight: 500; transition: all 0.2s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); transform: translateY(-1px); }
.btn-gold { background: var(--gold); color: white; }
.btn-gold:hover { background: var(--gold-light); transform: translateY(-1px); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; border-radius: 10px; font-size: 11px; font-weight: 600; padding: 0 6px; }
.badge-danger { background: #fed7d7; color: var(--danger); }
.badge-warn { background: #feebc8; color: var(--warning); }
.badge-success { background: #c6f6d5; color: #276749; }
.badge-info { background: #bee3f8; color: #2a69ac; }
.badge-gold { background: #fef3c7; color: #92400e; }

/* 内容区 */
.content { flex: 1; overflow-y: auto; padding: 24px; }
.page { display: none; }
.page.active { display: block; }

/* 统计卡片 */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--white); border-radius: var(--radius-lg); padding: 20px 22px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
  border-left: 4px solid transparent; transition: transform 0.15s, box-shadow 0.15s;
}
.stat-card[onclick]:hover {
  transform: translateY(-3px); box-shadow: var(--shadow-lg);
}
.stat-card.blue { border-left-color: var(--info); }
.stat-card.green { border-left-color: var(--success); }
.stat-card.gold { border-left-color: var(--gold); }
.stat-card.red { border-left-color: var(--danger); }
.stat-card.purple { border-left-color: #9f7aea; }
.stat-label { font-size: 12px; color: var(--text-light); margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text); }
.stat-sub { font-size: 12px; color: var(--text-light); margin-top: 6px; }
.stat-icon {
  position: absolute; right: 18px; top: 50%; transform: translateY(-50%);
  font-size: 36px; opacity: 0.1;
}

/* 卡片 */
.card {
  background: var(--white); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); margin-bottom: 20px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-title { font-size: 15px; font-weight: 600; color: var(--text); }
.card-body { padding: 20px; }

/* 表格 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead tr { background: #f7f9fc; }
th {
  padding: 10px 14px; text-align: left; font-weight: 600;
  color: var(--text-light); font-size: 12px; letter-spacing: 0.3px;
  border-bottom: 2px solid var(--border); white-space: nowrap;
}
td { padding: 12px 14px; border-bottom: 1px solid #f0f2f7; color: var(--text); }
tr:hover td { background: #f7f9fc; }
tr:last-child td { border-bottom: none; }

/* 搜索栏 */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search-input {
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px;
  font-size: 13px; outline: none; width: 220px;
  transition: border-color 0.2s;
}
.search-input:focus { border-color: var(--primary); }
.filter-select {
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px;
  font-size: 13px; outline: none; cursor: pointer; background: white;
}

/* 表单 */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.span2 { grid-column: span 2; }
label { font-size: 13px; font-weight: 500; color: var(--text); }
input, select, textarea {
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px;
  font-size: 13px; outline: none; transition: border-color 0.2s;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,58,107,0.08); }
textarea { resize: vertical; min-height: 80px; }

/* 模态框 */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 1000;
  align-items: center; justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
  background: white; border-radius: var(--radius-lg); width: 680px; max-width: 95vw;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  color: white;
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; color: white; font-size: 20px; cursor: pointer; opacity: 0.7; }
.modal-close:hover { opacity: 1; }
.modal-body { padding: 22px; }
.modal-footer {
  padding: 16px 22px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* 标签页 */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab-item {
  padding: 10px 20px; font-size: 14px; cursor: pointer;
  color: var(--text-light); border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: all 0.2s;
}
.tab-item:hover { color: var(--primary); }
.tab-item.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* 进度条 */
.progress-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 3px; transition: width 0.3s; }

/* AI 对话框 */
.ai-chat {
  display: flex; flex-direction: column; height: 500px;
  border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden;
}
.ai-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; background: #f7f9fc; }
.ai-msg { display: flex; gap: 10px; align-items: flex-start; max-width: 85%; }
.ai-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.ai-avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.ai-avatar.bot { background: linear-gradient(135deg, var(--primary), var(--primary-light)); color: white; }
.ai-avatar.user { background: var(--gold); color: white; }
.ai-bubble {
  background: white; border-radius: 12px; padding: 10px 14px;
  font-size: 13px; line-height: 1.6; box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  color: var(--text);
}
.ai-msg.user .ai-bubble { background: var(--primary); color: white; }
.ai-input-bar {
  display: flex; gap: 8px; padding: 12px 16px; background: white;
  border-top: 1px solid var(--border);
}
.ai-input {
  flex: 1; border: 1px solid var(--border); border-radius: 20px;
  padding: 8px 16px; font-size: 13px; outline: none;
}
.ai-input:focus { border-color: var(--primary); }
.ai-send-btn {
  background: var(--primary); color: white; border: none; border-radius: 20px;
  padding: 8px 20px; cursor: pointer; font-size: 13px; font-weight: 500;
}

/* 库存颜色警示 */
.stock-low { color: var(--danger); font-weight: 600; }
.stock-warn { color: var(--warning); font-weight: 600; }
.stock-ok { color: var(--success); }

/* 货币标签 */
.currency-thb { color: #c05621; font-weight: 600; }
.currency-usd { color: #2b6cb0; font-weight: 600; }
.currency-rmb { color: #276749; font-weight: 600; }

/* 通知容器 - 垂直堆叠 */
#toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  padding: 12px 20px; border-radius: 10px; font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg); animation: toastIn 0.3s ease;
  display: flex; align-items: center; gap: 8px;
}
@keyframes toastIn { from { transform: translateX(60px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast-success { background: #f0fff4; color: #276749; border: 1px solid #9ae6b4; }
.toast-error { background: #fff5f5; color: #c53030; border: 1px solid #feb2b2; }
.toast-info { background: #ebf8ff; color: #2a69ac; border: 1px solid #90cdf4; }

/* 仪表盘快捷操作 */
.quick-actions { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; margin-bottom: 24px; }
.quick-btn {
  background: white; border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px; text-align: center; cursor: pointer; transition: all 0.2s;
}
.quick-btn:hover { border-color: var(--gold); box-shadow: var(--shadow); transform: translateY(-2px); }
.quick-btn .q-icon { font-size: 24px; margin-bottom: 8px; }
.quick-btn .q-label { font-size: 13px; font-weight: 500; color: var(--text); }

/* 客户标签 */
.customer-tag {
  display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600;
}
.ct-jd { background: #e8f4fd; color: #1a56db; }
.ct-gsa { background: #fef3c7; color: #92400e; }
.ct-snbc { background: #ede9fe; color: #6d28d9; }
.ct-kbank { background: #d1fae5; color: #065f46; }
.ct-cts { background: #fee2e2; color: #991b1b; }
.ct-other { background: #f3f4f6; color: #374151; }

/* 响应式 */
@media (max-width: 1200px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .sidebar { width: 200px; min-width: 200px; }
  .stat-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ===== 新增样式：图片缩略图（hover 改为灯箱预览） ===== */
.item-thumb {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  flex-shrink: 0;
  cursor: pointer;
  transition: border-color 0.2s;
}
.item-thumb:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(26,58,107,0.18);
}

/* ===== 图片灯箱预览 ===== */
.img-lightbox-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 10000;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  animation: fadeIn 0.15s ease;
}
.img-lightbox-overlay.show {
  display: flex;
}
.img-lightbox-overlay img {
  max-width: 75vw;
  max-height: 75vh;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: bounceIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  background: white;
  padding: 6px;
  object-fit: contain;
}
@keyframes bounceIn {
  0%   { transform: scale(0.3); opacity: 0; }
  50%  { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

/* 图片上传预览区 */
#prod-img-preview {
  transition: all 0.2s;
}
#prod-img-preview img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
}

/* 入库/出库/发票明细行 */
.item-row {
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 表格内图片居中 */
table td:first-child img,
table td img.item-thumb {
  vertical-align: middle;
}

/* 搜索框聚焦效果 */
.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 58, 107, 0.08);
}

/* 让 modal 中 form-grid 的 label 更紧凑 */
.modal-body .form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* 表头中操作列居中 */
th:last-child,
td:last-child {
  text-align: center;
}

/* 按钮在表格内更紧凑 */
table .topbar-btn {
  padding: 4px 10px;
  font-size: 12px;
}

/* ===== 入库/出库管理明细 ===== */

/* 汇总条 */
.wh-summary-bar {
  display: flex;
  gap: 24px;
  padding: 14px 24px;
  background: linear-gradient(135deg, #eef4ff 0%, #f7f9fc 100%);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.wh-summary-bar.out {
  background: linear-gradient(135deg, #fef7ee 0%, #f7f9fc 100%);
}
.wh-summary-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.wh-summary-label {
  font-size: 11px;
  color: var(--text-light);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.wh-summary-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
}
.wh-summary-bar.out .wh-summary-value {
  color: #b7791f;
}

/* 日期分组 */
.wh-date-group {
  border-bottom: 1px solid var(--border);
}
.wh-date-group:last-child {
  border-bottom: none;
}

.wh-date-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: #fafbfe;
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}
.wh-date-header:hover {
  background: #f0f3fa;
}

.wh-date-label {
  display: flex;
  align-items: center;
  gap: 10px;
}
.wh-date-icon {
  font-size: 18px;
}
.wh-date-icon.out {
  /* 出库图标 */
}
.wh-date-text {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
}
.wh-date-weekday {
  font-size: 12px;
  color: var(--text-light);
  background: #eef2f7;
  padding: 2px 8px;
  border-radius: 10px;
}
.wh-date-count {
  font-size: 12px;
  color: var(--gold);
  background: #fef9ed;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}

.wh-date-summary {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
  color: var(--text-light);
}
.wh-date-amount {
  font-weight: 600;
  color: var(--text);
}
.wh-date-customers {
  font-weight: 500;
}
.wh-date-toggle {
  font-size: 11px;
  color: var(--text-light);
  transition: transform 0.2s;
}

/* 折叠状态 */
.wh-date-group.collapsed .wh-date-body {
  display: none;
}
.wh-date-group.collapsed .wh-date-toggle {
  transform: rotate(-90deg);
}

/* 日期分组内容区 */
.wh-date-body {
  padding: 0;
  animation: slideDown 0.2s ease;
}
@keyframes slideDown {
  from { opacity: 0; max-height: 0; }
  to { opacity: 1; max-height: 800px; }
}

/* 明细表格 */
.wh-detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.wh-detail-table thead {
  background: #f4f6fa;
}
.wh-detail-table thead th {
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.wh-detail-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid #f0f2f5;
  vertical-align: middle;
}
.wh-detail-table tbody tr:hover {
  background: #f8faff;
}
.wh-detail-table tbody tr:last-child td {
  border-bottom: none;
}

/* 币种颜色 */
.currency-rmb { color: #c53030; font-weight: 600; }

/* 可搜索下拉选择组件 */
.search-select {
  position: relative;
  flex: 1;
  display: inline-block;
}
.ss-input {
  width: 100%;
  height: 34px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  font-size: 13px;
  box-sizing: border-box;
  background: #fff;
}
.ss-input:focus {
  outline: none;
  border-color: #1a3a6b;
  box-shadow: 0 0 0 2px rgba(26,58,107,0.15);
}
.ss-options {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 220px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 999;
  margin-top: 2px;
}
.ss-options.show { display: block; }
.ss-option {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid #f0f2f5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ss-option:last-child { border-bottom: none; }
.ss-option:hover { background: #f0f2f7; }
.ss-option.selected { background: #e8f4ff; font-weight: 600; }
.ss-no-results {
  padding: 12px;
  text-align: center;
  color: #718096;
  font-size: 12px;
}
.order-qty-input {
  height: 34px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  font-size: 13px;
  box-sizing: border-box;
  width: 100%;
}
.order-qty-input:focus {
  outline: none;
  border-color: #1a3a6b;
  box-shadow: 0 0 0 2px rgba(26,58,107,0.15);
}

/* 搜索下拉增强 */
.ss-option mark { background: #fff3cd; color: inherit; padding: 0; border-radius: 2px; }
.ss-option.ss-hl { background: #e8f4ff; }

/* ===== 通用表头排序样式 ===== */
th.th-sort {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  position: relative;
  padding-right: 20px !important;
  transition: background 0.15s;
}
th.th-sort:hover { background: rgba(255,255,255,0.15); }
th.th-sort::after {
  content: '⇅';
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  opacity: 0.45;
}
th.th-sort.sort-asc::after  { content: '↑'; opacity: 1; }
th.th-sort.sort-desc::after { content: '↓'; opacity: 1; }
