/* 桌機版浮動購物車樣式 */
.desktop-floating-cart {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: block; /* 始終顯示 */
  cursor: pointer;
  transition: all 0.3s ease;
}

.desktop-floating-cart:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

/* 浮動購物車內容容器 */
.floating-cart-content {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* 向上移動按鈕 */
.scroll-to-top-btn {
  width: 45px;
  height: 45px;
  background: #28a745;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 3px 12px rgba(40, 167, 69, 0.3);
  transition: all 0.3s ease;
  color: white;
  font-size: 18px;
}

.scroll-to-top-btn:hover {
  background: #218838;
  transform: scale(1.05) translateY(-2px);
  box-shadow: 0 5px 18px rgba(40, 167, 69, 0.4);
}

/* 購物車圖示區域 */
.floating-cart-icon {
  position: relative;
  width: 60px;
  height: 60px;
  background: #1976d2;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 15px rgba(25, 118, 210, 0.3);
  transition: all 0.3s ease;
  cursor: pointer;
}

.floating-cart-icon:hover {
  background: #1565c0;
  transform: scale(1.05);
}

/* 購物車 SVG 圖示 */
.floating-cart-svg {
  width: 28px;
  height: 28px;
  filter: brightness(0) saturate(100%) invert(100%);
}

/* 浮動購物車數量徽章 */
.floating-cart-count {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #ff4444;
  color: white;
  border-radius: 50%;
  min-width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
  line-height: 1;
  border: 2px solid white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* 購物車預覽窗口 */
.floating-cart-preview {
  position: fixed; /* 改為 fixed 定位 */
  bottom: 150px; /* 調整底部距離，為兩個按鈕預留空間 */
  right: 20px; /* 調整右側距離 */
  width: 350px;
  max-height: calc(100vh - 180px); /* 確保不會超出螢幕 */
  background: white;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.15);
  border: 1px solid #e0e0e0;
  overflow: hidden;
  transform-origin: bottom right;
  display: flex;
  flex-direction: column; /* 使用 flex 佈局確保結構正確 */
  z-index: 10001; /* 確保在浮動購物車圖示之上 */
}

/* 預覽窗口標題 */
.cart-preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  background: #f8f9fa;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0; /* 防止被壓縮 */
}

.cart-preview-header h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

.cart-preview-close {
  background: none;
  border: none;
  font-size: 20px;
  color: #666;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.cart-preview-close:hover {
  background: #e0e0e0;
  color: #333;
}

/* 購物車項目列表 */
.cart-preview-items {
  flex: 1; /* 佔用剩餘空間 */
  overflow-y: auto;
  padding: 10px 0;
  min-height: 0; /* 允許收縮 */
  max-height: calc(100vh - 340px); /* 預留足夠空間給標題和底部，以及新增的按鈕 */
}

/* 確保有很多項目時的處理 */
.cart-preview-items::-webkit-scrollbar {
  width: 6px;
}

.cart-preview-items::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.cart-preview-items::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

.cart-preview-items::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

.cart-preview-item {
  display: flex;
  padding: 12px 20px;
  border-bottom: 1px solid #f0f0f0;
  transition: background 0.2s ease;
}

.cart-preview-item:hover {
  background: #f8f9fa;
}

.cart-preview-item:last-child {
  border-bottom: none;
}

/* 商品圖片 */
.cart-preview-item .item-image {
  width: 50px;
  height: 50px;
  margin-right: 12px;
  flex-shrink: 0;
}

.cart-preview-item .item-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
}

/* 商品詳情 */
.item-details {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.item-name {
  font-size: 14px;
  font-weight: 500;
  color: #333;
  margin-bottom: 4px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.item-specs {
  font-size: 12px;
  color: #666;
  margin-bottom: 4px;
}

.item-price {
  font-size: 13px;
  font-weight: 600;
  color: #1976d2;
}

/* 空購物車訊息 */
.cart-empty-message {
  text-align: center;
  padding: 40px 20px;
  color: #666;
  font-size: 14px;
}

/* 預覽窗口底部 */
.cart-preview-footer {
  padding: 15px 20px;
  background: #f8f9fa;
  border-top: 1px solid #e0e0e0;
  flex-shrink: 0; /* 防止被壓縮 */
  position: relative; /* 確保在最上層 */
  min-height: 100px; /* 增加最小高度確保按鈕可見 */
  box-sizing: border-box; /* 包含 padding 在內的高度計算 */
}

.cart-total {
  margin-bottom: 12px;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

.cart-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px; /* 與總計區域保持距離 */
}

.cart-actions a {
  flex: 1;
  padding: 12px 16px; /* 增加按鈕內距 */
  text-align: center;
  text-decoration: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  display: block; /* 確保按鈕正確顯示 */
  min-height: 20px; /* 確保按鈕最小高度 */
  line-height: 1.4; /* 改善文字對齊 */
}

.btn-view-cart {
  background: #f0f4fa;
  color: #1976d2;
  border: 1px solid #1976d2;
}

.btn-view-cart:hover {
  background: #1976d2;
  color: white;
}

.btn-checkout {
  background: #1976d2;
  color: white;
  border: 1px solid #1976d2;
}

.btn-checkout:hover {
  background: #1565c0;
  border-color: #1565c0;
}

/* 動畫效果 */
@keyframes cartBounce {
  0% {
    transform: scale(0.8);
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes fadeOutDown {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(20px) scale(0.9);
  }
}

/* 響應式設計 */
@media (max-width: 768px) {
  .desktop-floating-cart {
    display: none !important; /* 手機版完全隱藏 */
  }
}

@media (max-width: 1024px) {
  .floating-cart-preview {
    width: 300px;
    right: 10px; /* 調整位置避免超出螢幕 */
    max-height: calc(100vh - 160px); /* 在較小螢幕上也確保不超出 */
    bottom: 130px; /* 調整位置為兩個按鈕預留空間 */
  }
  
  .cart-preview-items {
    max-height: calc(100vh - 320px); /* 調整項目列表的最大高度 */
  }
}
