/**
 * 统一购物车样式
 * 包含购物车的基础样式，减少重复和冲突
 */

/* 购物车页面基础样式 */
.cart-page {
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  padding: 0 15px;
  max-width: 100%;
  box-sizing: border-box;
  background-color: #f8f9fa;
}

/* 购物车模态框覆盖层 - 通用样式 */
.cart-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 9000;
}

/* 购物车模态框 - 通用样式 */
.cart-modal {
  position: fixed;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: #f8f9fa;
  z-index: 9001;
}

/* 购物车头部 - 通用样式 */
.cart-header {
  position: sticky;
  top: 0;
  background-color: #fff;
  padding: 15px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 5;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.cart-header h3 {
  margin: 0;
  font-weight: 600;
  font-size: 18px;
}

/* 关闭按钮 */
.close-cart {
  background: none;
  border: none;
  font-size: 24px;
  color: #666;
  cursor: pointer;
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 购物车商品列表 - 通用样式 */
.cart-items {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 15px;
  padding-bottom: 150px; /* 为底部留出足够空间 */
  /* Chrome滚动优化 */
  transform: translateZ(0);
  will-change: scroll-position;
  touch-action: pan-y;
}

/* 购物车商品项目 - 通用样式 */
.cart-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px;
  margin-bottom: 15px;
  border-radius: 8px;
  width: 100%;
  box-sizing: border-box;
  background-color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* 购物车商品左侧 */
.cart-item-left {
  display: flex;
  flex: 1;
  min-width: 0;
}

/* 购物车商品右侧 */
.cart-item-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  min-width: 100px;
  margin-left: 10px;
}

/* 购物车商品图片 */
.cart-item-image {
  width: 80px;
  height: 80px;
  margin-right: 15px;
  border-radius: 4px;
  overflow: hidden;
  flex-shrink: 0;
}

.cart-item-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 购物车商品内容 */
.cart-item-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* 购物车商品名称 */
.cart-item-name {
  font-weight: 600;
  margin-bottom: 5px;
  font-size: 16px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  word-wrap: break-word;
  word-break: break-word;
  hyphens: auto;
  max-height: 2.6em; /* 限制最大高度为两行 */
}

/* 购物车商品价格 - 桌面端 */
.cart-item-price-desktop {
  color: #ff758c;
  font-weight: 500;
  margin-bottom: 5px;
  white-space: nowrap;
}

/* 购物车商品价格 - 移动端 */
.cart-item-price-mobile {
  color: #ff758c;
  font-weight: 500;
  margin-bottom: 10px;
  white-space: nowrap;
  display: none;
}

/* 购物车商品总价 */
.cart-item-total {
  background-color: #f8f9fa;
  padding: 5px 10px;
  border-radius: 4px;
  text-align: right;
  margin-top: 5px;
}

.total-label {
  font-size: 12px;
  color: #666;
  display: block;
}

.total-value {
  font-weight: 700;
  color: #ff758c;
  font-size: 16px;
}

/* 购物车商品控制区 */
.cart-item-controls {
  display: flex;
  align-items: center;
  margin-top: 10px;
}

/* 数量控制 */
.quantity-control {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  margin-right: 15px;
}

/* 数量按钮 */
.quantity-btn {
  width: 30px;
  height: 30px;
  border: 1px solid #ddd;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  font-size: 16px;
  border-radius: 4px;
}

/* 减号按钮 */
.minus-btn {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

/* 加号按钮 */
.plus-btn {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

/* 数量显示 */
.quantity-display {
  width: 30px;
  text-align: center;
  font-weight: 600;
  flex-shrink: 0;
  border-top: 1px solid #ddd;
  border-bottom: 1px solid #ddd;
  height: 30px;
  line-height: 30px;
}

/* 删除按钮 */
.remove-item-btn {
  background: none;
  border: none;
  color: #999;
  cursor: pointer;
  padding: 5px 10px;
  flex-shrink: 0;
  font-size: 16px;
  border-radius: 4px;
  transition: all 0.2s;
}

.remove-item-btn:hover {
  color: #e74c3c;
  background-color: #f8f9fa;
}

/* 购物车底部 */
.cart-footer {
  position: fixed;
  bottom: 0;
  background-color: #fff;
  padding: 15px;
  box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1);
  border-top: 1px solid #eee;
  z-index: 5;
}

/* 购物车总结区域 */
.cart-summary {
  background-color: #fff;
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 15px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

/* 购物车小计 */
.cart-subtotal,
.cart-discount,
.cart-total {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}

/* 购物车总计 */
.cart-total {
  font-weight: bold;
  font-size: 18px;
  border-top: 1px solid #eee;
  padding-top: 10px;
  margin-top: 5px;
}

/* 购物车折扣 */
.cart-discount {
  color: #e74c3c;
}

/* 购物车操作区 */
.cart-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* 结账按钮 */
.checkout-btn {
  padding: 12px;
  background-color: #ff758c;
  color: white;
  border: none;
  border-radius: 4px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* 继续购物按钮 */
.continue-shopping-btn {
  padding: 12px;
  border: 1px solid #ddd;
  background-color: #fff;
  color: #555;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* 空购物车状态 */
.empty-cart {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 50px 20px;
  height: 60vh;
}

.empty-cart-icon {
  font-size: 60px;
  color: #ddd;
  margin-bottom: 20px;
}

.empty-cart p {
  color: #777;
  margin-bottom: 20px;
}

/* 优惠券部分 */
.cart-coupon-section {
  padding: 0 20px;
  margin-bottom: 20px;
}

/* 响应式断点 */
/*
 * 统一媒体查询断点:
 * - 桌面端: >= 992px
 * - 平板端: >= 768px 且 < 992px
 * - 移动端: < 768px
 * - 小屏幕移动端: < 576px
 * - 超小屏幕: < 360px
 */

/* 桌面端特定样式 */
@media (min-width: 992px) {
  .cart-modal-overlay {
    display: flex;
    justify-content: flex-end;
    z-index: 100000;
  }

  .cart-modal {
    top: 0;
    right: 0;
    width: 100%;
    max-width: 480px;
    height: 100vh;
    z-index: 100001;
  }

  .cart-header {
    padding: 15px 20px;
    z-index: 100002;
  }

  .cart-footer {
    left: auto;
    right: 0;
    width: 480px;
  }

  .close-cart {
    z-index: 100003;
  }

  /* 购物车打开时降低导航栏z-index */
  body.cart-open .navbar {
    z-index: 999;
  }
}

/* 平板端特定样式 */
@media (min-width: 768px) and (max-width: 991px) {
  .cart-modal-overlay {
    display: flex;
    justify-content: flex-end;
    z-index: 100000;
  }

  .cart-modal {
    top: 0;
    right: 0;
    width: 100%;
    max-width: 400px;
    height: 100vh;
    z-index: 100001;
  }

  .cart-header {
    padding: 15px;
    z-index: 100002;
  }

  .cart-footer {
    left: auto;
    right: 0;
    width: 400px;
  }

  .close-cart {
    z-index: 100003;
  }

  /* 购物车打开时降低导航栏z-index */
  body.cart-open .navbar {
    z-index: 999;
  }
}

/* 移动端特定样式 */
@media (max-width: 767px) {
  .cart-modal-overlay {
    z-index: 9999;
  }

  .cart-modal {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100vh;
    z-index: 10000;
  }

  .cart-header {
    z-index: 10001;
  }

  .cart-footer {
    left: 0;
    right: 0;
    width: 100%;
    z-index: 10001;
  }

  .cart-item {
    flex-direction: column;
    align-items: stretch;
  }

  .cart-item-left {
    margin-bottom: 15px;
  }

  .cart-item-right {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    margin-left: 0;
    width: 100%;
  }

  .cart-item-price-desktop {
    display: none;
  }

  .cart-item-price-mobile {
    display: block;
  }

  .cart-item-total {
    margin-top: 0;
  }

  .cart-items {
    padding: 10px;
  }

  .cart-summary {
    padding: 0 10px;
  }
}

/* 小屏幕移动设备 */
@media (max-width: 575px) {
  .cart-page {
    padding: 0 10px;
  }

  .cart-items {
    padding: 5px;
  }

  .cart-item {
    padding: 12px;
    margin-bottom: 10px;
  }

  .cart-item-image {
    width: 60px;
    height: 60px;
    margin-right: 10px;
  }

  .cart-item-name {
    font-size: 14px;
  }

  .cart-item-price-mobile {
    font-size: 14px;
    margin-bottom: 5px;
  }

  .quantity-btn {
    width: 28px;
    height: 28px;
  }

  .quantity-display {
    width: 28px;
    font-size: 14px;
    height: 28px;
    line-height: 28px;
  }

  .remove-item-btn {
    padding: 3px 8px;
    font-size: 14px;
  }

  .cart-item-total {
    padding: 3px 8px;
  }

  .total-label {
    font-size: 11px;
  }

  .total-value {
    font-size: 14px;
  }

  .cart-coupon-section {
    padding: 0 10px;
  }
}

/* 超小屏幕设备 */
@media (max-width: 359px) {
  .cart-item-image {
    width: 50px;
    height: 50px;
    margin-right: 8px;
  }

  .cart-item-name {
    font-size: 13px;
  }

  .cart-item-price-mobile {
    font-size: 13px;
  }

  .cart-item-controls {
    flex-wrap: wrap;
  }

  .quantity-control {
    margin-bottom: 8px;
    margin-right: 0;
  }

  .quantity-btn {
    width: 26px;
    height: 26px;
    font-size: 14px;
  }

  .quantity-display {
    width: 26px;
    height: 26px;
    line-height: 26px;
    font-size: 13px;
  }

  .remove-item-btn {
    font-size: 13px;
    padding: 3px 6px;
    width: 100%;
    text-align: center;
  }

  .cart-item-right {
    flex-direction: column;
    align-items: flex-start;
  }

  .cart-item-total {
    width: 100%;
    margin-top: 8px;
    text-align: left;
  }
}

/* iOS安全区域适配 */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .cart-footer {
    padding-bottom: calc(15px + env(safe-area-inset-bottom));
  }

  .cart-items {
    padding-bottom: calc(150px + env(safe-area-inset-bottom));
  }
}
