/**
 * 移动端购物车增强样式
 * 解决滚动、结账按钮固定、数量框背景色和计算信息显示问题
 */

/* 移动端适配 */
@media (max-width: 768px) {
  /* 购物车模态框 - 确保可以滚动 */
  .cart-modal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100vh !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important; /* 整体容器不滚动 */
    z-index: 10000 !important;
    background-color: #f8f9fa !important;
  }
  
  /* 购物车内容容器 */
  .cart-content, .cart-content-wrapper {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 !important;
    width: 100% !important;
    height: 100% !important;
    overflow: hidden !important; /* 内容容器不滚动 */
    position: relative !important;
    padding-bottom: 150px !important; /* 为固定的结账按钮留出空间 */
  }
  
  /* 购物车页面 */
  .cart-page {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 !important;
    width: 100% !important;
    height: 100% !important;
    overflow: hidden !important; /* 页面容器不滚动 */
    position: relative !important;
    padding-bottom: 0 !important; /* 移除底部内边距，由内容容器提供 */
  }
  
  /* 购物车商品列表 - 这里是关键，确保可以滚动 */
  .cart-items {
    flex: 1 !important;
    overflow-y: auto !important; /* 启用垂直滚动 */
    -webkit-overflow-scrolling: touch !important; /* 增强iOS的滚动体验 */
    padding: 10px !important;
    padding-bottom: 20px !important; /* 减少底部内边距，避免与固定结账区域重叠 */
    width: 100% !important;
    position: relative !important;
    display: block !important; /* 确保正确显示 */
    height: auto !important; /* 自动高度 */
    min-height: 100px !important; /* 最小高度 */
    max-height: none !important; /* 移除最大高度限制 */
  }
  
  /* 显示滚动条 */
  .cart-items::-webkit-scrollbar {
    width: 4px !important; /* 滚动条宽度 */
    background: transparent !important;
  }
  
  .cart-items::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.2) !important; /* 滚动条颜色 */
    border-radius: 4px !important;
  }
  
  /* 购物车底部结算区域 - 固定在底部 */
  .cart-footer, .checkout-bar, .cart-summary {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    background-color: #fff !important;
    border-top: 1px solid #eee !important;
    padding: 15px !important;
    z-index: 10001 !important; /* 确保在内容之上 */
    box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.05) !important;
  }
  
  /* 购物车头部 - 固定在顶部 */
  .cart-header {
    position: sticky !important;
    top: 0 !important;
    background-color: #fff !important;
    padding: 15px !important;
    border-bottom: 1px solid #eee !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    z-index: 10001 !important; /* 确保在内容之上 */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05) !important;
  }
  
  /* 购物车商品项 */
  .cart-item {
    margin-bottom: 10px !important;
    background-color: #fff !important;
    border-radius: 8px !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
    padding: 10px !important;
    display: flex !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }
  
  /* 修复数量框背景颜色问题 */
  .quantity-control, 
  .cart-item .quantity-control,
  .cart-item-quantity {
    background-color: #f8f9fa !important; /* 浅灰色背景，与页面协调 */
    border-radius: 4px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 2px !important;
    border: 1px solid #e0e0e0 !important;
    width: 100% !important;
    max-width: 120px !important;
  }
  
  /* 数量按钮样式 */
  .quantity-btn, 
  .cart-item .quantity-btn {
    background-color: #fff !important; /* 白色背景 */
    border: none !important;
    width: 28px !important;
    height: 28px !important;
    border-radius: 4px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 16px !important;
    color: #333 !important;
    cursor: pointer !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1) !important;
  }
  
  /* 数量输入框样式 */
  .quantity-input, 
  .cart-item .quantity-input {
    width: 40px !important;
    text-align: center !important;
    border: none !important;
    background: transparent !important;
    font-size: 14px !important;
    color: #333 !important;
    padding: 0 !important;
  }
  
  /* 修复价格计算信息显示问题 */
  .cart-item-price-calculation,
  .price-calculation {
    font-size: 12px !important;
    color: #666 !important;
    margin-top: 5px !important;
    white-space: normal !important; /* 允许文本换行 */
    word-break: break-word !important; /* 在必要时断词 */
    width: 100% !important;
    display: block !important;
    line-height: 1.4 !important;
    overflow: visible !important; /* 确保内容不被截断 */
  }
  
  /* 优化商品信息布局 */
  .cart-item-details {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    padding-left: 10px !important;
    overflow: visible !important; /* 确保内容不被截断 */
  }
  
  /* 商品名称样式 */
  .cart-item-name {
    font-size: 14px !important;
    font-weight: 500 !important;
    margin-bottom: 5px !important;
    color: #333 !important;
  }
  
  /* 商品价格样式 */
  .cart-item-price {
    font-size: 14px !important;
    color: #ff758c !important; /* 使用网站主题色 */
    margin-bottom: 8px !important;
  }
  
  /* 结账按钮样式 */
  .checkout-button,
  .whatsapp-checkout-button {
    width: 100% !important;
    padding: 12px !important;
    background: linear-gradient(135deg, #ff758c 0%, #ff7eb3 100%) !important; /* 渐变背景 */
    color: white !important;
    border: none !important;
    border-radius: 8px !important;
    font-size: 16px !important;
    font-weight: 500 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    margin-top: 10px !important;
    cursor: pointer !important;
    box-shadow: 0 2px 5px rgba(255, 117, 140, 0.3) !important;
  }
  
  /* WhatsApp图标样式 */
  .whatsapp-icon {
    margin-right: 8px !important;
    font-size: 18px !important;
  }
  
  /* 小计、折扣和总计样式 */
  .subtotal-row,
  .discount-row,
  .total-row {
    display: flex !important;
    justify-content: space-between !important;
    margin-bottom: 5px !important;
    font-size: 14px !important;
  }
  
  .total-row {
    font-weight: bold !important;
    font-size: 16px !important;
    margin-top: 5px !important;
    margin-bottom: 10px !important;
    padding-top: 5px !important;
    border-top: 1px solid #eee !important;
  }
  
  .discount-row {
    color: #ff758c !important; /* 折扣使用主题色 */
  }
  
  /* 空购物车提示 */
  .empty-cart {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    padding: 20px !important;
    text-align: center !important;
  }
  
  /* 优惠券区域样式 */
  .coupons-section {
    margin: 15px 0 !important;
    padding: 15px !important;
    background-color: #fff !important;
    border-radius: 8px !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
  }
  
  .coupon-card {
    background-color: #fff5f7 !important; /* 浅粉色背景 */
    border: 1px dashed #ff758c !important;
    border-radius: 8px !important;
    padding: 10px !important;
    margin-bottom: 10px !important;
  }
  
  .coupon-code {
    font-weight: bold !important;
    font-size: 16px !important;
    text-align: center !important;
    margin-bottom: 5px !important;
  }
  
  .coupon-discount {
    color: #ff758c !important;
    text-align: center !important;
    font-size: 14px !important;
  }
  
  .coupon-buttons {
    display: flex !important;
    justify-content: space-between !important;
    margin-top: 10px !important;
  }
  
  .coupon-button {
    flex: 1 !important;
    padding: 8px !important;
    border-radius: 4px !important;
    border: 1px solid #ddd !important;
    background-color: #fff !important;
    font-size: 14px !important;
    margin: 0 5px !important;
    cursor: pointer !important;
  }
  
  /* 确保底部导航栏不遮挡结账按钮 */
  .cart-footer, .checkout-bar, .cart-summary {
    bottom: 70px !important; /* 为底部导航栏留出空间 */
  }
  
  /* 为iOS设备底部安全区域适配 */
  @supports (padding: env(safe-area-inset-bottom)) {
    .cart-footer, .checkout-bar, .cart-summary {
      bottom: calc(70px + env(safe-area-inset-bottom)) !important;
    }
  }
}
