/**
 * COUPANG ERP 移动端响应式布局
 * 作者：貂小蝉 💻 为岩哥打造
 * 版本：2.0 - 完整响应式适配
 */

/* ============ CSS 变量 ============ */
:root {
  --primary-color: #667eea;
  --primary-dark: #764ba2;
  --success-color: #11998e;
  --warning-color: #f5576c;
  --text-color: #333;
  --text-light: #888;
  --bg-light: #f8f9fa;
  --border-color: #e0e0e0;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

/* ============ 基础适配 ============ */
* {
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ============ 大屏适配 (>1200px) ============ */
@media (min-width: 1200px) {
  .container { max-width: 1600px; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important; }
  .charts-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============ 平板适配 (768px - 1024px) ============ */
@media (max-width: 1024px) {
  .container { max-width: 100%; padding: 0 16px; }
  
  .header {
    padding: 16px 20px;
  }
  
  .stats {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important;
  }
  
  .charts-grid {
    grid-template-columns: 1fr;
  }
  
  .rankings {
    grid-template-columns: 1fr;
  }
}

/* ============ 移动端适配 (≤768px) ============ */
@media (max-width: 768px) {
  /* 基础布局 */
  body {
    padding: 12px;
    padding-bottom: 80px;
  }
  
  .container {
    max-width: 100%;
    padding: 0;
  }
  
  /* 头部 */
  .header {
    padding: 16px;
    border-radius: var(--radius-md);
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  
  .header h1 {
    font-size: 20px !important;
    gap: 8px;
  }
  
  .header > div:last-child {
    flex-wrap: wrap;
    gap: 8px;
  }
  
  .header .btn {
    flex: 1;
    min-width: calc(50% - 4px);
    justify-content: center;
    font-size: 13px !important;
    padding: 10px 12px !important;
  }
  
  /* 面包屑 */
  .breadcrumb {
    font-size: 12px;
    margin-top: 4px;
  }
  
  /* 统计卡片 */
  .stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
  }
  
  .stat-card {
    padding: 14px;
    border-radius: var(--radius-md);
  }
  
  .stat-card .label {
    font-size: 11px;
    margin-bottom: 6px;
  }
  
  .stat-card .value {
    font-size: 22px;
  }
  
  .stat-card .sub-value {
    font-size: 11px;
  }
  
  /* 筛选栏 */
  .filters {
    padding: 14px;
    border-radius: var(--radius-md);
    margin-bottom: 12px;
  }
  
  .filters h3 {
    font-size: 15px;
    margin-bottom: 12px;
  }
  
  .filters > div:first-child {
    flex-direction: column;
  }
  
  .filter-group {
    width: 100%;
    display: block !important;
    margin-bottom: 10px;
  }
  
  .filter-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 12px;
  }
  
  .filter-input {
    width: 100% !important;
    min-width: auto;
    font-size: 16px; /* 防止 iOS 缩放 */
    padding: 12px 14px;
  }
  
  .filters .btn {
    width: 100%;
    margin-top: 8px;
  }
  
  /* 表格容器 - 横向滚动 */
  .table-container {
    border-radius: var(--radius-md);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  table {
    min-width: 700px;
  }
  
  th, td {
    padding: 12px;
    font-size: 13px;
    white-space: nowrap;
  }
  
  th {
    font-size: 11px;
    padding: 10px 12px;
  }
  
  /* 分页 */
  .pagination {
    padding: 12px 16px;
    flex-direction: column;
    gap: 10px;
  }
  
  .pagination-info {
    text-align: center;
    font-size: 12px;
  }
  
  .pagination-buttons {
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .page-btn {
    padding: 8px 12px;
    font-size: 12px;
    min-width: 40px;
  }
  
  /* 图表 */
  .charts-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .chart-card {
    padding: 16px;
    border-radius: var(--radius-md);
  }
  
  .chart-container {
    height: 250px;
  }
  
  /* 排行榜 */
  .rankings {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .ranking-card {
    padding: 16px;
    border-radius: var(--radius-md);
  }
  
  .ranking-card h3 {
    font-size: 15px;
    margin-bottom: 12px;
  }
  
  .ranking-item {
    padding: 10px 0;
  }
  
  .ranking-name {
    font-size: 13px;
  }
  
  .ranking-value {
    font-size: 12px;
  }
  
  /* 弹窗 */
  .modal-overlay {
    padding: 10px;
    align-items: flex-end;
  }
  
  .modal {
    width: 100%;
    max-width: 100%;
    max-height: 85vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 20px 16px;
  }
  
  .modal h3 {
    font-size: 18px;
    position: sticky;
    top: 0;
    background: white;
    padding-bottom: 12px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--bg-light);
  }
  
  .modal .form-row {
    grid-template-columns: 1fr;
  }
  
  .modal .btn {
    width: 100%;
    justify-content: center;
  }
  
  /* 按钮 */
  .btn {
    padding: 12px 18px;
    font-size: 14px;
    border-radius: var(--radius-sm);
  }
  
  .btn-sm {
    padding: 8px 12px;
    font-size: 12px;
  }
  
  /* 状态标签 */
  .status-badge {
    padding: 4px 10px;
    font-size: 11px;
  }
  
  /* 金额 */
  .amount {
    font-size: 13px;
  }
  
  /* 底部 */
  .footer {
    font-size: 12px;
    padding: 16px;
    margin-top: 24px;
  }
  
  /* 刷新按钮 */
  .refresh-btn {
    width: 48px;
    height: 48px;
    bottom: 80px;
    right: 16px;
    font-size: 20px;
  }
  
  /* 批量操作栏 */
  #batchActionBar {
    padding: 12px 16px;
  }
  
  #batchActionBar > div {
    flex-direction: column;
    gap: 10px;
  }
  
  #batchActionBar .btn {
    flex: 1;
  }
}

/* ============ 小屏手机 (≤480px) ============ */
@media (max-width: 480px) {
  body {
    padding: 8px;
    padding-bottom: 80px;
  }
  
  .header {
    padding: 12px;
    border-radius: var(--radius-md);
  }
  
  .header h1 {
    font-size: 18px !important;
  }
  
  .stats {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  
  .stat-card {
    padding: 12px;
  }
  
  .stat-card .value {
    font-size: 18px;
  }
  
  .stat-card .label {
    font-size: 10px;
  }
  
  .filters {
    padding: 12px;
  }
  
  table {
    min-width: 600px;
  }
  
  th, td {
    padding: 10px;
    font-size: 12px;
  }
  
  .chart-container {
    height: 200px;
  }
  
  .modal {
    padding: 16px 12px;
    max-height: 90vh;
  }
  
  .btn {
    padding: 10px 14px;
    font-size: 13px;
  }
}

/* ============ 超小屏 (≤360px) ============ */
@media (max-width: 360px) {
  .header h1 {
    font-size: 16px !important;
  }
  
  .header .btn {
    font-size: 12px !important;
    padding: 8px 10px !important;
  }
  
  .stats {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  
  .stat-card {
    padding: 10px;
  }
  
  .stat-card .value {
    font-size: 16px;
  }
  
  .stat-card .label {
    font-size: 9px;
  }
}

/* ============ 触摸设备优化 ============ */
@media (hover: none) and (pointer: coarse) {
  /* 增大点击区域 */
  .btn,
  .nav-link,
  .action-btn,
  .page-btn,
  .filter-input {
    min-height: 44px;
  }
  
  /* 禁用双击缩放 */
  * {
    touch-action: manipulation;
  }
  
  /* 移除 hover 效果（移动端无意义） */
  .btn:hover,
  .nav-link:hover,
  .action-btn:hover,
  .page-btn:hover {
    transform: none;
  }
  
  /* 输入框优化 */
  input,
  select,
  textarea {
    font-size: 16px; /* 防止 iOS 自动缩放 */
  }
  
  /* 表格行点击优化 */
  tr {
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.1);
  }
}

/* ============ 横屏模式 ============ */
@media (max-width: 896px) and (orientation: landscape) {
  body {
    padding-bottom: 60px;
  }
  
  .stats {
    grid-template-columns: repeat(4, 1fr);
  }
  
  .charts-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .modal {
    max-height: 80vh;
  }
}

/* ============ 深色模式支持（可选） ============ */
@media (prefers-color-scheme: dark) {
  /* 暂不启用，预留 */
}

/* ============ 打印样式 ============ */
@media print {
  .top-nav,
  .nav-spacer,
  .header-actions,
  .filters,
  .pagination,
  .actions,
  .footer,
  .refresh-btn,
  #batchActionBar {
    display: none !important;
  }
  
  body {
    background: white;
    padding: 0;
  }
  
  .container {
    max-width: 100%;
  }
  
  .card,
  .table-container,
  .stat-card {
    box-shadow: none;
    border: 1px solid #ddd;
  }
}

/* ============ 移动端卡片视图（可选） ============ */
.mobile-card-view {
  display: none;
}

@media (max-width: 600px) {
  /* 如果需要卡片视图，给表格容器添加 .mobile-card-view 类 */
  .mobile-card-view table {
    display: block;
  }
  
  .mobile-card-view thead {
    display: none;
  }
  
  .mobile-card-view tbody {
    display: block;
  }
  
  .mobile-card-view tr {
    display: block;
    background: white;
    border-radius: var(--radius-md);
    padding: 14px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
  }
  
  .mobile-card-view td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--bg-light);
    font-size: 13px;
  }
  
  .mobile-card-view td:last-child {
    border-bottom: none;
    padding-top: 12px;
    justify-content: flex-end;
  }
  
  .mobile-card-view td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-light);
    flex-shrink: 0;
    margin-right: 12px;
  }
}

/* ============ 移动端菜单样式 ============ */
.mobile-menu-btn {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 1000;
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  width: 44px;
  height: 44px;
  font-size: 20px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  transition: transform 0.2s;
}

.mobile-menu-btn:active {
  transform: scale(0.95);
}

@media (max-width: 768px) {
  .mobile-menu-btn {
    display: flex;
  }
}

/* ============ 移动端侧滑菜单 ============ */
#mobileMenu {
  position: fixed;
  top: 0;
  right: -280px;
  width: 280px;
  height: 100vh;
  background: white;
  box-shadow: -4px 0 20px rgba(0,0,0,0.2);
  z-index: 999;
  transition: right 0.3s ease;
  overflow-y: auto;
}

#mobileMenu.open {
  right: 0;
}

#mobileMenu .menu-header {
  padding: 20px;
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
  color: white;
}

#mobileMenu .menu-header h2 {
  margin: 0;
  font-size: 18px;
}

#mobileMenu .menu-header p {
  margin: 4px 0 0;
  opacity: 0.8;
  font-size: 12px;
}

#mobileMenu nav {
  padding: 12px;
}

#mobileMenu nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  color: var(--text-color);
  text-decoration: none;
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  font-size: 14px;
  transition: background 0.2s;
}

#mobileMenu nav a:hover,
#mobileMenu nav a:active {
  background: var(--bg-light);
}

#mobileMenu nav a.active {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
  color: white;
}

/* ============ 遮罩层 ============ */
.menu-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.menu-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

/* ============ 加载动画优化 ============ */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--bg-light);
  border-top: 3px solid var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ============ Toast 提示优化 ============ */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #333;
  color: white;
  padding: 14px 24px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: 14px;
  z-index: 1001;
  opacity: 0;
  transition: all 0.3s ease;
  max-width: calc(100% - 32px);
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

@media (max-width: 768px) {
  .toast {
    bottom: 100px;
    font-size: 13px;
    padding: 12px 20px;
  }
}

/* ============ 表单优化 ============ */
@media (max-width: 768px) {
  .form-row {
    grid-template-columns: 1fr !important;
  }
  
  .form-group {
    margin-bottom: 14px;
  }
  
  .form-group label {
    font-size: 13px;
    margin-bottom: 6px;
  }
  
  .form-group input,
  .form-group select,
  .form-group textarea {
    font-size: 16px;
    padding: 12px;
  }
  
  .shipping-form {
    padding: 16px;
  }
}

/* ============ 详情页优化 ============ */
@media (max-width: 768px) {
  .order-detail-section {
    margin-bottom: 16px;
    padding-bottom: 16px;
  }
  
  .order-detail-section h4 {
    font-size: 14px;
    margin-bottom: 10px;
  }
  
  .detail-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  
  .detail-item {
    padding: 10px;
    background: var(--bg-light);
    border-radius: var(--radius-sm);
  }
  
  .order-items-table {
    font-size: 12px;
  }
  
  .order-items-table th,
  .order-items-table td {
    padding: 10px 8px;
  }
}

/* ============ 底部安全区域（iPhone X+） ============ */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  @media (max-width: 768px) {
    body {
      padding-bottom: calc(80px + env(safe-area-inset-bottom));
    }
    
    #batchActionBar {
      padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
    
    .toast {
      bottom: calc(100px + env(safe-area-inset-bottom));
    }
  }
}