/* ===================================================
   ERP 系统 UI 增强样式表
   中国风审美优化 + 移动端自适应
   =================================================== */

/* --- 中文优先字体方案 --- */
:root {
  --font-cn: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Noto Sans SC", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-bg: #dbeafe;
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
  --sidebar-bg: #1e293b;
  --sidebar-hover: #334155;
  --sidebar-active: #3b82f6;
  --border: #e5e7eb;
  --border-light: #f1f5f9;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --bg: #f1f5f9;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --card-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
}

/* --- Base 优化 --- */
body {
  font-family: var(--font-cn);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-size: 14px;
  line-height: 1.6;
}

/* --- Layout 优化 --- */
.content {
  background: var(--bg);
}

.content section {
  padding: 24px;
}

/* --- 滚动条美化 --- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* --- Sidebar 优化 --- */
.sidebar {
  background: var(--sidebar-bg);
  width: 240px;
  min-width: 240px;
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.08);
}

.sidebar-header {
  padding: 20px 20px;
  border-bottom-color: #334155;
}

.sidebar-header h2 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
}

.sidebar .nav-group summary {
  font-size: 13px;
  padding: 11px 20px;
  color: #94a3b8;
  letter-spacing: 0.3px;
}

.sidebar .nav-group summary:hover {
  background: var(--sidebar-hover);
  color: #e2e8f0;
}

.sidebar .nav-item {
  padding: 9px 20px 9px 44px;
  color: #94a3b8;
  font-size: 13px;
  position: relative;
}

.sidebar .nav-item:hover {
  background: var(--sidebar-hover);
  color: #f1f5f9;
}

.sidebar .nav-item.active {
  background: rgba(59, 130, 246, 0.12);
  color: #60a5fa;
  border-left: 3px solid var(--sidebar-active);
}

.sidebar .nav-single {
  padding: 11px 20px;
  color: #94a3b8;
  font-size: 13px;
}

.sidebar .nav-single:hover {
  background: var(--sidebar-hover);
  color: #e2e8f0;
}

.sidebar .nav-single.active {
  background: rgba(59, 130, 246, 0.12);
  color: #60a5fa;
  border-left: 3px solid var(--sidebar-active);
}

/* --- Card 优化 --- */
.card {
  background: #fff;
  border: none;
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--card-shadow);
  transition: box-shadow var(--transition);
}

.card:hover {
  box-shadow: var(--card-shadow-hover);
}

.card-header {
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom-color: var(--border-light);
}

.card-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

/* --- Page Header 优化 --- */
.page-header {
  padding: 20px 28px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-header h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.5px;
}

/* --- Stat Cards 优化 --- */
.stat-cards {
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background: #fff;
  border: none;
  border-radius: var(--radius-lg);
  padding: 20px 16px;
  box-shadow: var(--card-shadow);
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--primary);
  opacity: 0.6;
}

.stat-card:hover {
  box-shadow: var(--card-shadow-hover);
  transform: translateY(-2px);
}

.stat-card .stat-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--primary);
  font-family: var(--font-mono);
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
}

.stat-card.warning::before { background: var(--warning); }
.stat-card.danger::before { background: var(--danger); }
.stat-card.success::before { background: var(--success); }

/* --- Buttons 优化 --- */
.btn {
  padding: 8px 18px;
  font-size: 13px;
  font-family: var(--font-cn);
  border-radius: var(--radius-sm);
  border: 1px solid #d1d5db;
  background: #fff;
  color: var(--text);
  transition: all var(--transition);
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.btn:hover {
  background: #f8fafc;
  border-color: #9ca3af;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 1px 3px rgba(37, 99, 235, 0.3);
}

.btn.primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.4);
}

.btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  box-shadow: 0 1px 3px rgba(239, 68, 68, 0.3);
}

.btn.danger:hover {
  background: #dc2626;
  border-color: #dc2626;
  box-shadow: 0 2px 6px rgba(239, 68, 68, 0.4);
}

.btn.success {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
  box-shadow: 0 1px 3px rgba(16, 185, 129, 0.3);
}

.btn.success:hover {
  background: #059669;
  border-color: #059669;
  box-shadow: 0 2px 6px rgba(16, 185, 129, 0.4);
}

.btn.warning {
  background: var(--warning);
  border-color: var(--warning);
  color: #fff;
}

.btn.warning:hover {
  background: #d97706;
  border-color: #d97706;
}

.btn.sm {
  padding: 5px 12px;
  font-size: 12px;
}

.btn:active {
  transform: translateY(0);
}

/* --- Tables 优化 --- */
.table-wrapper {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

table {
  font-size: 13px;
}

table th {
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 600;
  padding: 12px 14px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

table tr:last-child td {
  border-bottom: none;
}

table tr:hover {
  background: #f8fafc;
}

/* --- Forms 优化 --- */
.form-grid {
  gap: 20px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.form-group label .required {
  color: var(--danger);
  margin-left: 2px;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="date"],
.form-group input[type="tel"],
.form-group select,
.form-group textarea {
  padding: 9px 14px;
  border: 1.5px solid #d1d5db;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font-cn);
  color: var(--text);
  background: #fff;
  transition: all var(--transition);
}

.form-group input:hover,
.form-group select:hover,
.form-group textarea:hover {
  border-color: #9ca3af;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* --- Filter Bar 优化 --- */
.filter-bar {
  background: #fff;
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow);
  margin-bottom: 20px;
  gap: 16px;
}

.filter-bar select,
.filter-bar input[type="text"],
.filter-input {
  padding: 7px 14px;
  border: 1.5px solid #d1d5db;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-cn);
  transition: border-color var(--transition);
}

.filter-bar select:focus,
.filter-bar input[type="text"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
  outline: none;
}

.filter-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

/* --- Pagination 优化 --- */
.pagination {
  gap: 6px;
  margin-top: 24px;
}

.pagination a,
.pagination span {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  background: #fff;
  transition: all var(--transition);
}

.pagination a:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.pagination .active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* --- Tags / Status Pills 优化 --- */
.tag {
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

/* --- Modal 优化 --- */
.modal-overlay {
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  display: flex;
  animation: modalFadeIn 0.2s ease;
}

/* 修复：确保 .modal-overlay.active 内部的 .modal 容器可见 */
.modal-overlay.active > .modal {
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: var(--radius-lg);
  width: 95vw;
  max-width: 700px;
  max-height: 85vh;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  animation: modalSlideIn 0.25s ease;
  position: static;
  inset: auto;
  z-index: auto;
  padding: 0;
}

/* 修复：.modal 内部 .modal-body 在修复后保持正确显示 */
.modal-overlay.active > .modal > .modal-body {
  width: 100%;
  max-width: 100%;
  border-radius: 0;
  box-shadow: none;
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

/* modal 内部的 header/footer */
.modal-overlay.active > .modal > .modal-header {
  padding: 20px 24px 16px;
  margin-bottom: 0;
}

.modal-overlay.active > .modal > .modal-footer {
  padding: 16px 24px 20px;
  margin-top: 0;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-body {
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  padding: 28px;
  animation: modalSlideIn 0.25s ease;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  padding-bottom: 16px;
  margin-bottom: 0;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 600;
}

.modal-close {
  font-size: 28px;
  color: var(--text-light);
  transition: color var(--transition);
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-footer {
  padding-top: 16px;
  margin-top: 16px;
}

/* --- Alerts 优化 --- */
.alert {
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  border: none;
  box-shadow: var(--card-shadow);
}

/* --- Tabs 优化 --- */
.tabs {
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  gap: 0;
}

.tabs a {
  padding: 10px 20px;
  font-size: 14px;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition);
  font-weight: 500;
}

.tabs a:hover {
  color: var(--primary);
}

.tabs a.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* --- Detail View 优化 --- */
.detail-grid {
  gap: 16px;
}

.detail-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  transition: all var(--transition);
  box-shadow: var(--card-shadow);
}

.detail-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--card-shadow-hover);
  border-color: #cbd5e1;
}

.detail-item .label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

.detail-item .value {
  font-size: 16px;
  color: var(--text);
  font-weight: 600;
}

/* --- BOM Tree 优化 --- */
.bom-tree .bom-item {
  transition: background var(--transition);
}

/* ===================================================
   移动端自适应 - 增强版
   =================================================== */

/* 平板（≤1280px） */
@media (max-width: 1280px) {
  .content section {
    padding: 20px;
  }

  .page-header {
    padding: 16px 20px;
  }

  .stat-cards {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }

  .form-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .detail-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* 小屏（≤1024px） */
@media (max-width: 1024px) {
  .sidebar:not(.collapsed) {
    width: 260px;
    min-width: 260px;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
  }

  .sidebar.collapsed {
    width: 0 !important;
    min-width: 0 !important;
  }

  .sidebar.collapsed ~ .content,
  .sidebar.collapsed + .content {
    margin-left: 0;
  }

  .sidebar-toggle {
    display: block;
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 101;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
  }

  .sidebar-toggle:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
  }

  .sidebar.collapsed .sidebar-toggle {
    left: 14px;
  }

  .sidebar-overlay {
    display: none;
  }

  .sidebar-overlay.active {
    display: block;
    animation: fadeIn 0.2s ease;
  }

  @keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }
}

/* 手机（≤768px）— 全管理端适配 */
@media (max-width: 768px) {
  /* ========== 基础 ========== */
  .content section {
    padding: 14px !important;
  }

  .page-header {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 6px;
  }

  .page-header h1 {
    font-size: 16px;
  }

  .page-header .actions {
    width: 100%;
    justify-content: flex-end;
  }

  /* ========== 卡片 ========== */
  .card {
    padding: 14px;
    border-radius: 10px;
    margin-bottom: 12px;
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .card-header h3 {
    font-size: 14px;
  }

  /* ========== 统计卡片 ========== */
  .stat-cards {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px;
  }

  .stat-card {
    padding: 14px 12px;
  }

  .stat-card .stat-value {
    font-size: 22px;
  }

  .stat-card .stat-label {
    font-size: 12px;
  }

  /* ========== 表格 ========== */
  .table-wrapper {
    border: none;
    border-radius: 0;
    overflow-x: auto;
    margin: 0 -4px;
  }

  table {
    font-size: 12px;
  }

  table th,
  table td {
    padding: 8px 10px;
    white-space: nowrap;
  }

  table .actions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
  }

  table .actions .btn.sm {
    padding: 4px 8px;
    font-size: 11px;
  }

  /* ========== 表单 ========== */
  .form-grid {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  .form-group {
    margin-bottom: 12px;
  }

  .form-group input,
  .form-group select,
  .form-group textarea {
    font-size: 15px;
    padding: 10px 12px;
  }

  /* ========== 筛选栏 ========== */
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 14px;
  }

  .filter-group {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-group label {
    margin-bottom: 2px;
  }

  .filter-bar select,
  .filter-bar input[type="text"],
  .filter-input {
    width: 100%;
    min-width: 0;
    padding: 8px 12px;
  }

  .filter-form {
    flex-wrap: wrap;
  }

  /* ========== 按钮 ========== */
  .btn {
    padding: 9px 14px;
    font-size: 13px;
    min-height: 38px;
  }

  .btn.sm {
    padding: 6px 10px;
    font-size: 12px;
    min-height: 32px;
  }

  /* ========== 分页 ========== */
  .pagination {
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
  }

  .pagination a,
  .pagination span {
    padding: 7px 11px;
    font-size: 12px;
    min-width: 34px;
    text-align: center;
  }

  /* ========== 标签（Tabs） ========== */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
    white-space: nowrap;
    gap: 0;
  }

  .tabs::-webkit-scrollbar {
    display: none;
  }

  .tabs a {
    padding: 8px 12px;
    font-size: 13px;
    flex-shrink: 0;
  }

  /* ========== 详情网格 ========== */
  .detail-grid {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  .detail-item {
    padding: 14px;
  }

  .detail-item .value {
    font-size: 15px;
  }

  /* ========== 弹窗 ========== */
  .modal-overlay {
    padding: 12px;
    align-items: center;
  }

  .modal-body {
    width: 100%;
    max-width: 100%;
    max-height: 85vh;
    border-radius: 10px;
    padding: 16px;
  }

  .modal-header {
    padding: 16px 16px 12px;
  }

  .modal-header h3 {
    font-size: 16px;
  }

  /* ========== 提示 ========== */
  .alert {
    padding: 10px 12px;
    font-size: 12px;
  }

  /* ========== 通用多列布局 ========== */
  .info-grid,
  .info-grid-2,
  .info-grid-3,
  .info-grid-4,
  .info-grid-5 {
    grid-template-columns: 1fr 1fr !important;
  }

  .cost-row {
    grid-template-columns: 1fr 1fr !important;
  }

  .cost-cell {
    padding: 12px 14px;
  }

  .cost-cell .value {
    font-size: 16px;
  }

  /* 内联 3~5 列网格 → 2列 */
  [style*="grid-template-columns: repeat(3" i],
  [style*="grid-template-columns: repeat(4" i],
  [style*="grid-template-columns: repeat(5" i] {
    grid-template-columns: 1fr 1fr !important;
  }

  /* 双栏 `1fr 1fr` → 单列 */
  [style*="display:grid"][style*="1fr 1fr"]:not(.stat-cards):not(.form-grid):not(.detail-grid):not(.info-grid) {
    grid-template-columns: 1fr !important;
  }

  /* 内联 1fr 1fr 1fr → 单列 */
  [style*="grid-template-columns: 1fr 1fr 1fr"] {
    grid-template-columns: 1fr 1fr !important;
  }

  /* ========== 状态筛选卡片（订单管理） ========== */
  [style*="grid-template-columns: repeat(3" i][style*="margin-bottom"] {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px;
  }

  /* ========== 修复 min-width 溢出 ========== */
  [style*="min-width:300px"],
  [style*="min-width: 300px"] {
    min-width: 0 !important;
    width: 100% !important;
  }

  /* ========== auto-fill/minmax 网格强制单列 ========== */
  [style*="grid-template-columns: repeat(auto-fill"],
  [style*="grid-template-columns: repeat(auto-fit"] {
    grid-template-columns: 1fr !important;
  }

  /* ========== 表格内图片 ========== */
  table img {
    max-width: 50px;
    height: auto;
  }

  /* ========== 面包屑 ========== */
  [style*="font-size:13px;color:#9ca3af"] {
    font-size: 12px !important;
    flex-wrap: wrap;
  }

  /* ========== 产品分析条形图 ========== */
  .spec-bar {
    flex-wrap: wrap;
  }
  .spec-bar .label {
    width: 100%;
    margin-bottom: 2px;
  }
  .spec-bar .stat {
    width: auto;
  }

  /* ========== 空状态 ========== */
  .empty-state {
    padding: 32px 16px;
  }

  .empty-state .icon {
    font-size: 40px;
  }

  /* ========== 侧边栏 ========== */
  .sidebar:not(.collapsed) {
    width: 280px;
    min-width: 280px;
    z-index: 100;
  }

  .sidebar.collapsed {
    width: 0 !important;
    min-width: 0 !important;
  }

  .sidebar:not(.collapsed) ~ .content {
    margin-left: 0;
  }

  .sidebar-toggle {
    display: flex !important;
  }

  /* ========== 底部版权跟随侧边栏 ========== */
  [style*="margin-left:240px"] {
    margin-left: 0 !important;
  }

  /* ========== 强制 Flex 元素不溢出 ========== */
  [style*="flex:1"][style*="min-width"] {
    min-width: 0 !important;
    flex: 1 1 100% !important;
  }

  /* ========== 卡片内 grid 3col → 1col ========== */
  .card [style*="grid-template-columns:repeat(3"] {
    grid-template-columns: 1fr 1fr !important;
  }

  /* ========== 财务汇总卡片 ========== */
  .invoice-summary {
    grid-template-columns: 1fr 1fr !important;
  }

  /* ========== 堆叠信息网格 ========== */
  [style*="display:grid"][style*="gap:0"] {
    grid-template-columns: 1fr !important;
  }

  /* ========== flex 布局防止溢出 ========== */
  [style*="display:flex"][style*="align-items:flex-start"] {
    flex-direction: column !important;
  }

  /* ========== 图表水平条自适应 ========== */
  [style*="max-width:80px"] {
    max-width: 60px !important;
  }

  /* ========== 在卡片内的内联2列flex换行 ========== */
  [style*="display:flex"][style*="justify-content:space-between"] {
    flex-wrap: wrap;
    gap: 4px;
  }

  /* ========== 防止表格内长文本溢出 ========== */
  table td {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  table td[style*="max-width"] {
    max-width: 120px !important;
  }
}

/* 超小屏（≤480px） */
@media (max-width: 480px) {
  .content section {
    padding: 10px !important;
  }

  .page-header {
    padding: 10px 12px;
  }

  .page-header h1 {
    font-size: 14px;
  }

  .card {
    padding: 12px;
  }

  .btn {
    padding: 7px 12px;
    font-size: 12px;
  }

  .stat-card {
    padding: 12px 10px;
  }

  .stat-card .stat-value {
    font-size: 18px;
  }

  .stat-cards {
    gap: 8px;
  }
}

/* ===================================================
   辅助改善
   =================================================== */

/* --- 选中文字颜色 --- */
::selection {
  background: rgba(37, 99, 235, 0.2);
  color: var(--text);
}

/* --- 响应式表格容器（水平滚动提示） --- */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
  padding: 0 4px;
}

/* --- Loading 状态 --- */
.loading {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- 分割线 --- */
.divider {
  height: 1px;
  background: var(--border-light);
  margin: 20px 0;
}

/* --- 点击反馈 --- */
.clickable {
  cursor: pointer;
  transition: all var(--transition);
}

.clickable:active {
  transform: scale(0.98);
}

/* --- 页面加载淡入 --- */
.content section {
  animation: pageIn 0.3s ease;
}

@keyframes pageIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --- 数字等宽 --- */
.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* --- 空状态美化 --- */
.empty-state {
  padding: 48px 24px;
}

.empty-state .icon {
  font-size: 56px;
  margin-bottom: 16px;
  opacity: 0.6;
}

.empty-state p {
  font-size: 15px;
  color: var(--text-muted);
}

/* --- Badge / 角标 --- */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  background: var(--danger);
  color: #fff;
}

/* --- 搜索框增强 --- */
.search-box {
  position: relative;
}

.search-box input {
  padding-left: 34px !important;
}

.search-box::before {
  content: '🔍';
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  opacity: 0.5;
}

/* --- 响应式表格增强（小屏转卡片） --- */
@media (max-width: 640px) {
  .table-card-view table,
  .table-card-view thead,
  .table-card-view tbody,
  .table-card-view th,
  .table-card-view td,
  .table-card-view tr {
    display: block;
  }

  .table-card-view thead {
    display: none;
  }

  .table-card-view tr {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 10px;
    box-shadow: var(--card-shadow);
  }

  .table-card-view td {
    padding: 6px 0;
    border: none;
    text-align: right;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
  }

  .table-card-view td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 12px;
    text-align: left;
  }
}

/* --- 品牌色顶部条（专业感） --- */
.page-header::after {
  display: none;
}

/* --- 详情页订单卡片特殊优化 --- */
.detail-item.order-number {
  background: linear-gradient(135deg, #4f6ef7 0%, #7c3aed 100%);
}

.detail-item.amount {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

/* ===================================================
   分类颜色系统（12色）
   用法：.cat-{n}   设置文字色
         .cat-bg-{n} 设置背景色
         .cat-light-{n} 设置浅背景色
   =================================================== */
:root {
  --cat-1: #2563eb; --cat-light-1: #eff6ff;  /* 蓝 */
  --cat-2: #10b981; --cat-light-2: #ecfdf5;  /* 绿 */
  --cat-3: #8b5cf6; --cat-light-3: #f5f3ff;  /* 紫 */
  --cat-4: #f59e0b; --cat-light-4: #fffbeb;  /* 橙 */
  --cat-5: #14b8a6; --cat-light-5: #f0fdfa;  /* 青 */
  --cat-6: #ec4899; --cat-light-6: #fdf2f8;  /* 粉 */
  --cat-7: #6366f1; --cat-light-7: #eef2ff;  /* 靛蓝 */
  --cat-8: #ef4444; --cat-light-8: #fef2f2;  /* 红 */
  --cat-9: #06b6d4; --cat-light-9: #ecfeff;  /* 天蓝 */
  --cat-10: #d97706; --cat-light-10: #fef3c7; /* 琥珀 */
  --cat-11: #059669; --cat-light-11: #f0fdf4; /* 翡翠 */
  --cat-12: #e11d48; --cat-light-12: #fff1f2; /* 玫红 */
}

.cat-1  { color: var(--cat-1); }
.cat-2  { color: var(--cat-2); }
.cat-3  { color: var(--cat-3); }
.cat-4  { color: var(--cat-4); }
.cat-5  { color: var(--cat-5); }
.cat-6  { color: var(--cat-6); }
.cat-7  { color: var(--cat-7); }
.cat-8  { color: var(--cat-8); }
.cat-9  { color: var(--cat-9); }
.cat-10 { color: var(--cat-10); }
.cat-11 { color: var(--cat-11); }
.cat-12 { color: var(--cat-12); }

.cat-bg-1  { background: var(--cat-1); }
.cat-bg-2  { background: var(--cat-2); }
.cat-bg-3  { background: var(--cat-3); }
.cat-bg-4  { background: var(--cat-4); }
.cat-bg-5  { background: var(--cat-5); }
.cat-bg-6  { background: var(--cat-6); }
.cat-bg-7  { background: var(--cat-7); }
.cat-bg-8  { background: var(--cat-8); }
.cat-bg-9  { background: var(--cat-9); }
.cat-bg-10 { background: var(--cat-10); }
.cat-bg-11 { background: var(--cat-11); }
.cat-bg-12 { background: var(--cat-12); }

.cat-light-1  { background: var(--cat-light-1); }
.cat-light-2  { background: var(--cat-light-2); }
.cat-light-3  { background: var(--cat-light-3); }
.cat-light-4  { background: var(--cat-light-4); }
.cat-light-5  { background: var(--cat-light-5); }
.cat-light-6  { background: var(--cat-light-6); }
.cat-light-7  { background: var(--cat-light-7); }
.cat-light-8  { background: var(--cat-light-8); }
.cat-light-9  { background: var(--cat-light-9); }
.cat-light-10 { background: var(--cat-light-10); }
.cat-light-11 { background: var(--cat-light-11); }
.cat-light-12 { background: var(--cat-light-12); }

.stocktake-card .tag {
  border: 1px solid transparent;
}

.stocktake-card .cat-tag {
  font-weight: 600;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 12px;
  flex-shrink: 0;
}

/* ===================================================
   库存盘点 - 卡片布局
   =================================================== */
.stocktake-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.stocktake-card {
  display: flex;
  flex-direction: column;
  transition: all var(--transition);
}

.stocktake-card:hover {
  box-shadow: var(--card-shadow-hover);
  transform: translateY(-2px);
}

.stocktake-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 16px;
}

.stocktake-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  line-height: 1.4;
  flex: 1;
  min-width: 0;
  word-break: break-all;
}

.stocktake-stock {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 14px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.stocktake-label {
  font-size: 13px;
  color: var(--text-muted);
}

.stocktake-qty {
  font-size: 32px;
  font-weight: 800;
  font-family: var(--font-mono);
  line-height: 1;
}

.stocktake-unit {
  font-size: 12px;
  color: var(--text-light);
}

.stocktake-action {
  margin-top: auto;
}

.stocktake-action .btn {
  width: 100%;
  justify-content: center;
}

/* 差异显示样式 */
.diff-positive {
  color: var(--success) !important;
}

.diff-negative {
  color: var(--danger) !important;
}

.diff-zero {
  color: var(--text) !important;
}

/* 移动端 */
@media (max-width: 640px) {
  .stocktake-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .stocktake-qty {
    font-size: 26px;
  }

  .stocktake-stock {
    padding: 12px 14px;
  }
}

/* ===================================================
   客户价格对比表
   =================================================== */
.compare-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  overflow: hidden;
}

.compare-table thead th {
  padding: 10px 12px;
  font-weight: 600;
  color: #475569;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
  text-align: left;
  background: #f8fafc;
}

.compare-table thead th:first-child {
  position: sticky;
  left: 0;
  background: #f8fafc;
  z-index: 2;
}

.compare-table thead th .sub {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: #94a3b8;
  margin-top: 2px;
}

.compare-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.compare-table tr:last-child td {
  border-bottom: none;
}

.compare-table tr:hover td,
.compare-table tr:hover td:first-child {
  background: #f8fafc;
}

.compare-table td:first-child {
  position: sticky;
  left: 0;
  background: #fff;
  font-weight: 600;
  color: #1e293b;
  z-index: 1;
  border-right: 1px solid #e2e8f0;
  min-width: 100px;
}

.compare-table .std-price {
  font-family: "SFMono-Regular", Consolas, monospace;
  color: #64748b;
}

.compare-table .price-cell {
  position: relative;
  white-space: nowrap;
}

.compare-table .price-input {
  width: 90px;
  padding: 6px 10px;
  border: 1.5px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  transition: all 0.2s;
  text-align: right;
}

.compare-table .price-input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.compare-table .price-input::placeholder {
  color: #cbd5e1;
  text-align: center;
  font-size: 11px;
}

.compare-table .price-currency {
  display: inline-block;
  width: 20px;
  font-size: 11px;
  color: #94a3b8;
  text-align: center;
}

/* 新增价格弹窗 - 颜色类型价格表格 */
.price-entry-table {
  width: 100%;
  font-size: 13px;
  border-collapse: collapse;
}

.price-entry-table th {
  padding: 8px 10px;
  background: #f8fafc;
  font-weight: 600;
  color: #475569;
  border-bottom: 2px solid #e2e8f0;
  text-align: left;
  font-size: 12px;
}

.price-entry-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.price-entry-table td:last-child {
  text-align: right;
}

.price-entry-table .entry-price-input {
  width: 120px;
  padding: 6px 10px;
  border: 1.5px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  text-align: right;
  transition: border-color 0.2s;
}

.price-entry-table .entry-price-input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.price-entry-table .entry-price-input::placeholder {
  color: #cbd5e1;
}

/* 移动端价格表 */
@media (max-width: 768px) {
  .compare-table {
    font-size: 12px;
    border-radius: 6px;
  }

  .compare-table th,
  .compare-table td {
    padding: 8px;
  }

  .compare-table .price-input {
    width: 70px;
    padding: 5px 8px;
    font-size: 12px;
  }

  .compare-table td:first-child {
    min-width: 70px;
    font-size: 12px;
  }
}

/* ===================================================
   发票管理
   =================================================== */
.inv-table td.num {
  font-family: var(--font-mono);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.inv-table th:nth-child(4),
.inv-table th:nth-child(5),
.inv-table th:nth-child(6) {
  text-align: right;
}

/* 上传拖拽区 */
.upload-dropzone {
  border: 2px dashed #d1d5db;
  border-radius: 12px;
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.upload-dropzone:hover,
.upload-dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}

/* 识别预览表 */
.parse-preview {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.parse-preview td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-light);
}

.parse-preview td:first-child {
  background: #f8fafc;
  font-weight: 600;
  width: 100px;
  color: var(--text-muted);
}

.parse-preview td:last-child {
  font-weight: 500;
}

.parse-preview .amount {
  font-weight: 700;
  color: var(--primary);
  font-size: 16px;
}

/* ===================================================
   客户门户 - 全局增强
   =================================================== */

/* 门户内容区 */
.portal-layout .content {
  background: #f8fafc;
}

/* 门户卡片 */
.portal-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  border: 1px solid #f1f5f9;
  transition: box-shadow 0.2s;
}

.portal-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}

/* 门户标题 */
.portal-section-title {
  font-size: 17px;
  font-weight: 700;
  color: #1e293b;
  margin: 0 0 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.portal-section-title::before {
  content: '';
  width: 4px;
  height: 18px;
  background: #2563eb;
  border-radius: 2px;
  flex-shrink: 0;
}

/* 门户表格 */
.portal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.portal-table th {
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid #e2e8f0;
  background: transparent;
  text-align: left;
  white-space: nowrap;
}

.portal-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.portal-table tr:last-child td {
  border-bottom: none;
}

.portal-table tr:hover td {
  background: #f8fafc;
}

/* 门户属性标签 */
.portal-tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 6px;
  font-size: 12px;
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
  margin: 1px 3px 1px 0;
}

/* 门户空状态 */
.portal-empty {
  text-align: center;
  padding: 48px 20px;
  color: #94a3b8;
}

.portal-empty .icon { font-size: 48px; margin-bottom: 12px; }
.portal-empty p { font-size: 14px; }

/* === 手机端门户导航增强 === */
@media (max-width: 768px) {
  /* 门户内容区边距 */
  .content section {
    padding: 14px !important;
  }

  /* 门户卡片 */
  .portal-card {
    padding: 16px;
    border-radius: 10px;
  }

  /* 门户表格滚动 */
  .table-wrapper {
    margin: 0 -4px;
    padding: 0 4px;
  }

  .portal-table {
    font-size: 13px;
  }

  .portal-table th,
  .portal-table td {
    padding: 8px 10px;
    white-space: nowrap;
  }

  /* 门户标题 */
  .page-header h1 {
    font-size: 17px;
  }

  /* 按钮移动端适配 */
  .btn {
    padding: 8px 14px;
    font-size: 13px;
    min-height: 38px;
  }

  /* 手机端内容区全宽 */
  .content {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* 手机端底部版权条全宽 */
  [style*="margin-left:240px"] {
    margin-left: 0 !important;
  }

  /* 手机端侧边栏全屏覆盖 */
  .sidebar:not(.collapsed) {
    width: 280px;
    min-width: 280px;
    z-index: 100;
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }

  .sidebar.collapsed {
    width: 0 !important;
    min-width: 0 !important;
  }

  .sidebar-toggle {
    display: flex !important;
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 101;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 6px;
    background: #2563eb;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(37,99,235,0.3);
    align-items: center;
    justify-content: center;
  }
}

/* === 门户产品卡片网格 === */
@media (max-width: 640px) {
  .product-grid {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  .stat-cards {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 14px 16px;
  }

  .filter-group {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-bar select,
  .filter-bar input[type="text"] {
    width: 100%;
    min-width: 0;
  }
}
