/**
 * @file
 * 购物车页面样式
 * 基于 design-prototypes/cart.html
 */

/* ========== 购物车主容器 ========== */
.cart-container {
  padding: 24px 16px 120px;
  background: #F5F5F7;
  min-height: 100vh;
}

/* ========== 购物车标题 ========== */
.cart-header {
  margin-bottom: 20px;
}

.cart-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--color-text-primary, #1D1D1F);
}

.cart-count {
  font-size: 15px;
  color: var(--color-text-secondary, #6E6E73);
}

/* ========== 购物车商品卡片 ========== */
.cart-item {
  background: white;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  display: flex;
  gap: 12px;
  position: relative;
  transition: box-shadow 0.2s ease;
}

.cart-item:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* 最后一个商品与结算框的间隔 */
.cart-item:last-child {
  margin-bottom: 48px;
}

/* ========== 商品复选框 ========== */
.item-checkbox {
  position: relative;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 40px;
  transition: all 0.2s ease;
  background: white;
}

.item-checkbox.checked {
  background: #0066CC;
  border-color: #0066CC;
}

.item-checkbox.checked::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 10px;
  height: 10px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='white'%3E%3Cpath fill-rule='evenodd' d='M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z' clip-rule='evenodd'/%3E%3C/svg%3E") no-repeat center;
  background-size: contain;
}

.item-checkbox:focus {
  outline: 2px solid #0066CC;
  outline-offset: 2px;
}

/* ========== 商品图片 ========== */
.item-image {
  width: 100px;
  height: 100px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  background: #F5F5F7;
  position: relative;
}

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

.item-image-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-border, #D2D2D7);
}

/* ========== 商品详情 ========== */
.item-details {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0; /* 防止 flex 子项溢出 */
}

.item-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
  line-height: 1.3;
  color: var(--color-text-primary, #1D1D1F);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* 商品标题链接样式 */
.item-name .cart-item-title-link {
  color: #1D1D1F;
  text-decoration: none;
  transition: text-decoration 0.2s ease;
}

.item-name .cart-item-title-link:hover {
  text-decoration: underline;
  color: #1D1D1F;
}

.item-specs {
  font-size: 13px;
  color: var(--color-text-secondary, #6E6E73);
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-price {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text-primary, #1D1D1F);
  margin-bottom: 8px;
}

.item-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
  gap: 12px;
}

/* ========== 数量控制器 ========== */
.quantity-control {
  display: flex;
  align-items: center;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  overflow: hidden;
  background: white;
}

.quantity-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border: none;
  cursor: pointer;
  transition: background 0.2s ease;
  color: var(--color-text-primary, #1D1D1F);
  font-size: 18px;
  line-height: 1;
}

.quantity-btn:hover {
  background: #F5F5F7;
}

.quantity-btn:active {
  background: #E5E5E7;
}

.quantity-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.quantity-value {
  width: 50px;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-primary, #1D1D1F);
}

/* ========== 删除按钮 ========== */
.item-delete {
  color: #D32F2F;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.2s ease;
  white-space: nowrap;
  user-select: none;
}

.item-delete:hover {
  opacity: 0.7;
}

.item-delete:active {
  opacity: 0.5;
}

/* ========== 底部结算栏 ========== */
.checkout-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  padding: 12px 16px;
  z-index: 101; /* 高于底部导航栏 (z-index: 100) */
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.checkout-bar-inner {
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* ========== 全选区域 ========== */
.select-all-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.select-all-checkbox {
  position: relative;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  background: white;
  flex-shrink: 0;
}

.select-all-checkbox.checked {
  background: #0066CC;
  border-color: #0066CC;
}

.select-all-checkbox.checked::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 10px;
  height: 10px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='white'%3E%3Cpath fill-rule='evenodd' d='M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z' clip-rule='evenodd'/%3E%3C/svg%3E") no-repeat center;
  background-size: contain;
}

.select-all-label {
  font-size: 14px;
  color: var(--color-text-primary, #1D1D1F);
  user-select: none;
}

/* ========== 价格区域 ========== */
.total-wrapper {
  flex: 0 0 auto;
  text-align: right;
}

.total-label {
  font-size: 14px;
  color: var(--color-text-secondary, #6E6E73);
  margin-bottom: 2px;
}

.total-price {
  font-size: 24px;
  font-weight: 700;
  color: var(--color-text-primary, #1D1D1F);
}

/* ========== 结算按钮 ========== */
.checkout-btn {
  display: inline-block;
  padding: 12px 24px;
  background: #0066CC;
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  text-decoration: none;
}

.checkout-btn:hover {
  background: #0052A3;
  text-decoration: none;
}

.checkout-btn:active {
  background: #004080;
}

.checkout-btn:disabled,
.checkout-btn[disabled] {
  background: #D2D2D7;
  cursor: not-allowed;
  opacity: 0.6;
  pointer-events: none;
}

/* ========== 空购物车 ========== */
.empty-cart {
  text-align: center;
  padding: 80px 20px;
  background: white;
  border-radius: 12px;
}

.empty-cart-icon {
  width: 120px;
  height: 120px;
  margin: 0 auto 24px;
  color: #D2D2D7;
}

.empty-cart-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--color-text-primary, #1D1D1F);
}

.empty-cart-text {
  font-size: 15px;
  color: var(--color-text-secondary, #6E6E73);
  margin-bottom: 24px;
}

.empty-cart-btn {
  display: inline-block;
  padding: 14px 32px;
  background: #0066CC;
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.empty-cart-btn:hover {
  background: #0052A3;
}

.empty-cart-btn:active {
  background: #004080;
}

/* ========== 正在加载 ========== */
.cart-loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--color-text-secondary, #6E6E73);
}

.cart-loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(0, 102, 204, 0.2);
  border-top-color: #0066CC;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

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

/* ========== 桌面端适配 ========== */
@media (min-width: 768px) {
  .cart-container {
    padding: 32px 0 120px;
  }

  .cart-title {
    font-size: 32px;
  }

  .checkout-bar {
    bottom: 0;
  }

  .item-image {
    width: 120px;
    height: 120px;
  }

  /* 桌面端：最后商品与结算框的间隔更大 */
  .cart-item:last-child {
    margin-bottom: 64px;
  }

  .item-checkbox {
    margin-top: 50px;
  }

  .checkout-bar-inner {
    padding: 0 16px;
  }
}

/* ========== 移动端优化 ========== */
@media (max-width: 767px) {
  .item-name {
    font-size: 14px;
  }

  .item-specs {
    font-size: 12px;
  }

  .item-price {
    font-size: 16px;
  }

  .total-price {
    font-size: 20px;
  }

  .checkout-btn {
    padding: 10px 20px;
    font-size: 14px;
  }
}

/* ========== 无障碍支持 ========== */
@media (prefers-reduced-motion: reduce) {
  .item-checkbox,
  .quantity-btn,
  .item-delete,
  .checkout-btn,
  .empty-cart-btn {
    transition: none;
  }

  .cart-loading-spinner {
    animation: none;
  }
}

/* ========== 加载动画 ========== */
.loading-spinner {
  display: inline-block;
  animation: spin 1s linear infinite;
  font-size: 16px;
  color: var(--color-primary, #0066CC);
}

.quantity-value .loading-spinner {
  font-size: 14px;
}

/* ========== 消息提示样式 ========== */
.cart-messages {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  max-width: 400px;
}

.cart-message {
  padding: 16px 20px;
  margin-bottom: 12px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  animation: slideIn 0.3s ease;
}

.cart-message.status {
  background: #E8F5E9;
  color: #2E7D32;
  border-left: 4px solid #4CAF50;
}

.cart-message.error {
  background: #FFEBEE;
  color: #C62828;
  border-left: 4px solid #F44336;
}

.cart-message.warning {
  background: #FFF3E0;
  color: #E65100;
  border-left: 4px solid #FF9800;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

/* ========== 高对比度模式 ========== */
@media (prefers-contrast: high) {
  .item-checkbox,
  .select-all-checkbox {
    border-width: 3px;
  }

  .checkout-btn,
  .empty-cart-btn {
    border: 2px solid currentColor;
  }
}

/* ========== 商品折扣价格 ========== */
.item-price-wrapper {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.item-price-discount {
  color: #EA0029;
  font-size: 16px;
  font-weight: 600;
}

.item-price-original {
  font-size: 13px;
  color: #86868B;
  text-decoration: line-through;
}

/* ========== 合计折扣价格 ========== */
.total-price-wrapper {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.total-price-discount {
  color: #EA0029;
  font-size: 20px;
  font-weight: 700;
}

.total-price-original {
  font-size: 14px;
  color: #86868B;
  text-decoration: line-through;
}
