/* ===== 基础样式 ===== */
* { box-sizing: border-box; }

body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif; }

/* ===== 侧边栏导航 ===== */
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.875rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  color: #9CA3AF;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #E5E7EB; }
.nav-item.active { background: #4F46E5; color: #fff; }

/* ===== 卡片 ===== */
.stat-card {
  background: #fff;
  border-radius: 0.75rem;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  border: 1px solid #F3F4F6;
  transition: box-shadow 0.15s;
}
.stat-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.1); }

/* ===== 表格 ===== */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}
.data-table thead th {
  background: #F9FAFB;
  padding: 0.625rem 0.75rem;
  text-align: left;
  font-weight: 600;
  color: #6B7280;
  border-bottom: 2px solid #E5E7EB;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
  background-clip: padding-box;
  box-shadow: inset 0 -1px 0 #E5E7EB;
}
.data-table tbody td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #F3F4F6;
  color: #374151;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.data-table tbody tr:hover { background: #F9FAFB; }
.data-table tbody tr:nth-child(even) { background: #FAFBFC; }
.data-table tbody tr:nth-child(even):hover { background: #F3F4F6; }

/* 表格容器 - 横向 + 纵向滚动，滚动时表头固定不动 */
.table-container {
  overflow: auto;
  max-height: 70vh;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* 含data-table的卡片容器支持横向滚动 */
@media (max-width: 768px) {
  .bg-white:has(> .data-table) {
    overflow-x: auto;
  }
}

/* ===== 按钮 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  outline: none;
}
.btn-primary { background: #4F46E5; color: #fff; }
.btn-primary:hover { background: #4338CA; }
.btn-success { background: #059669; color: #fff; }
.btn-success:hover { background: #047857; }
.btn-danger { background: #DC2626; color: #fff; }
.btn-danger:hover { background: #B91C1C; }
.btn-outline { background: transparent; border: 1px solid #D1D5DB; color: #374151; }
.btn-outline:hover { background: #F9FAFB; border-color: #9CA3AF; }
.btn-sm { padding: 0.25rem 0.625rem; font-size: 0.75rem; }

/* ===== 表单 ===== */
.form-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #D1D5DB;
  border-radius: 0.5rem;
  font-size: 0.8125rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.form-input:focus { border-color: #818CF8; box-shadow: 0 0 0 3px rgba(99,102,241,0.1); }
.form-label { display: block; font-size: 0.8125rem; font-weight: 500; color: #374151; margin-bottom: 0.25rem; }

/* ===== 标签 ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.6875rem;
  font-weight: 500;
}
.badge-green { background: #D1FAE5; color: #065F46; }
.badge-red { background: #FEE2E2; color: #991B1B; }
.badge-yellow { background: #FEF3C7; color: #92400E; }
.badge-blue { background: #DBEAFE; color: #1E40AF; }
.badge-gray { background: #F3F4F6; color: #4B5563; }
.badge-purple { background: #EDE9FE; color: #5B21B6; }
.badge-amber { background: #FEF3C7; color: #92400E; }

/* ===== 模态框 ===== */
.modal-overlay { animation: fadeIn 0.15s ease; }
.modal-content { animation: slideUp 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Toast ===== */
.toast {
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.8125rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  animation: slideIn 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 360px;
}
.toast-success { background: #059669; color: #fff; }
.toast-error { background: #DC2626; color: #fff; }
.toast-info { background: #4F46E5; color: #fff; }
.toast-warn { background: #D97706; color: #fff; }
@keyframes slideIn { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: translateX(0); } }

/* ===== 文件上传 ===== */
.upload-zone {
  border: 2px dashed #D1D5DB;
  border-radius: 0.75rem;
  padding: 2.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  background: #FAFBFC;
}
.upload-zone:hover, .upload-zone.dragover { border-color: #818CF8; background: #EEF2FF; }

/* ===== 空状态 ===== */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: #9CA3AF;
}
.empty-state svg { margin: 0 auto 1rem; }

/* ===== 运费高亮 ===== */
.freight-total { color: #4F46E5; font-weight: 700; }

/* ===== 滚动条 ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9CA3AF; }

/* ===== 响应式 ===== */

/* 汉堡菜单按钮 - 仅移动端显示 */
.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.5rem;
  border: none;
  background: transparent;
  color: #374151;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  position: relative;
  z-index: 10;
}
.menu-toggle:hover { background: #F3F4F6; }
.menu-toggle:active { background: #E5E7EB; }

/* 侧边栏遮罩层 */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 35;
  animation: fadeIn 0.15s ease;
}

/* 移动端适配 */
@media (max-width: 768px) {
  /* 隐藏汉堡菜单在桌面端，显示在移动端 */
  .menu-toggle { display: inline-flex !important; }

  /* 导航项触摸友好 */
  .nav-item {
    padding: 0.75rem 1rem !important;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  /* 侧边栏 - 移动端默认隐藏 */
  #sidebar {
    width: 0 !important;
    min-width: 0 !important;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    transition: width 0.25s ease, min-width 0.25s ease;
    will-change: width;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
  }
  #sidebar.open {
    width: 16rem !important;
    min-width: 16rem !important;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar-overlay.show { display: block; }

  /* 主内容区全宽 */
  main { width: 100% !important; }

  /* 顶部栏紧凑 */
  header {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
    padding-top: 0.625rem !important;
    padding-bottom: 0.625rem !important;
  }

  /* 内容区减小内边距 */
  #contentArea {
    padding: 0.75rem !important;
  }

  /* 统计卡片 - 单列 */
  .stat-grid, .grid-cols-2, .grid-cols-3, .grid-cols-4 {
    grid-template-columns: 1fr !important;
  }

  /* 表格 - 横向滚动 */
  .table-wrap, .overflow-x-auto {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .data-table {
    min-width: 600px;
  }

  /* 模态框 - 全屏 */
  .modal-content, #modalContent {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    margin: 0 !important;
    height: 100vh;
  }

  /* 弹窗 - 几乎全宽 */
  #changePasswordModal > div {
    width: calc(100% - 2rem) !important;
    max-width: none !important;
  }

  /* Toast - 底部中间 */
  #toastContainer {
    top: auto !important;
    bottom: 1rem !important;
    right: 50% !important;
    transform: translateX(50%);
    left: auto !important;
  }
  .toast {
    max-width: 90vw;
  }

  /* 按钮组 - 换行 */
  .btn-group-wrap {
    flex-wrap: wrap;
  }
  .btn-group-wrap .btn {
    font-size: 0.75rem;
    padding: 0.375rem 0.625rem;
  }

  /* 页面标题缩小 */
  #pageTitle, .page-title {
    font-size: 0.9375rem !important;
  }

  /* 上传区域紧凑 */
  .upload-zone {
    padding: 1.5rem 1rem !important;
  }

  /* 筛选栏换行 */
  .filter-bar {
    flex-direction: column !important;
    gap: 0.5rem !important;
  }
  .filter-bar > * {
    width: 100% !important;
  }

  /* 表单网格单列 */
  .form-grid, .grid.grid-cols-2 {
    grid-template-columns: 1fr !important;
  }
}

/* 小屏手机 (< 375px) */
@media (max-width: 374px) {
  #contentArea {
    padding: 0.5rem !important;
  }
  .stat-card {
    padding: 0.75rem !important;
  }
  .data-table {
    font-size: 0.75rem;
  }
}
