/**
 * 佈局優化樣式
 * Layout Optimization CSS
 * 優化頁首、商品頁、頁尾的響應式設計
 */

/* ========================================
   頁首優化
   ======================================== */

/* 桌面版搜尋框優化 */
@media (min-width: 768px) {
  #desktop-search-form .input-group {
    transition: box-shadow 0.3s ease;
  }

  #desktop-search-form .input-group:focus-within {
    box-shadow: 0 0.5rem 1rem rgba(0, 123, 255, 0.25) !important;
  }

  #desktop-search-form .form-control:focus {
    border-color: #0d6efd;
    box-shadow: none;
  }
}

/* 手機版圖標觸控優化 */
@media (max-width: 767.98px) {
  .btn-icon {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-top-actions {
    gap: 0.25rem;
  }
}

/* 搜尋框動畫 */
#mobileSearchBar {
  transition: all 0.3s ease;
}

#mobileSearchBar.show {
  display: block !important;
}

/* ========================================
   商品頁優化
   ======================================== */

/* 商品圖片區域優化 */
.product-gallery .main-image img {
  transition: transform 0.3s ease;
}

.product-gallery .main-image:hover img {
  transform: scale(1.05);
}

/* 縮圖hover效果 */
.thumbs-gallery a {
  transition: all 0.2s ease;
  opacity: 0.7;
}

.thumbs-gallery a:hover,
.thumbs-gallery a.active {
  opacity: 1;
  border-color: #0d6efd !important;
}

/* 手機版縮圖滑動優化 */
@media (max-width: 767.98px) {
  .thumbs-gallery .overflow-auto {
    scrollbar-width: thin;
    scrollbar-color: #dee2e6 transparent;
  }

  .thumbs-gallery .overflow-auto::-webkit-scrollbar {
    height: 6px;
  }

  .thumbs-gallery .overflow-auto::-webkit-scrollbar-track {
    background: transparent;
  }

  .thumbs-gallery .overflow-auto::-webkit-scrollbar-thumb {
    background: #dee2e6;
    border-radius: 3px;
  }

  .thumbs-gallery .overflow-auto::-webkit-scrollbar-thumb:hover {
    background: #adb5bd;
  }
}

/* 價格區塊優化 */
.product-price {
  transition: all 0.3s ease;
}

.product-price:hover {
  background-color: #fff !important;
  border-color: #dc3545 !important;
  box-shadow: 0 0.25rem 0.75rem rgba(220, 53, 69, 0.15);
}

/* 加入購物車按鈕優化 */
.btn-buy-now,
.btn-add-cart {
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.btn-buy-now:hover,
.btn-add-cart:hover {
  transform: translateY(-2px);
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

.btn-buy-now::before,
.btn-add-cart::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.btn-buy-now:active::before,
.btn-add-cart:active::before {
  width: 300px;
  height: 300px;
}

/* ========================================
   頁尾優化
   ======================================== */

/* 頁尾標題統一樣式 */
.footer-title {
  position: relative;
  padding-bottom: 0.5rem;
}

.footer-title::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 40px;
  height: 2px;
  background: linear-gradient(to right, #0d6efd, transparent);
}

/* 頁尾連結hover效果 */
.footer-links a {
  transition: all 0.2s ease;
  display: inline-block;
}

.footer-links a:hover {
  color: #0d6efd !important;
  transform: translateX(3px);
}

/* 社交媒體按鈕優化 */
.social-links a {
  transition: all 0.3s ease;
}

.social-links a:hover {
  transform: translateY(-3px) scale(1.1);
  box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.15);
}

/* 付款方式圖標優化 */
.payment-methods {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem;
}

.payment-method {
  transition: all 0.3s ease;
}

.payment-method:hover {
  transform: translateY(-3px);
}

.payment-method .payment-icon {
  transition: all 0.3s ease;
}

.payment-method:hover .payment-icon {
  transform: scale(1.1);
}

/* 手機版摺疊優化 */
@media (max-width: 991.98px) {
  .accordion-button:not(.collapsed) {
    background-color: transparent;
    color: inherit;
  }

  .accordion-button:focus {
    box-shadow: none;
    border-color: transparent;
  }

  .accordion-button::after {
    margin-left: auto;
  }
}

/* ========================================
   響應式斷點優化
   ======================================== */

/* 平板優化 (768px - 991px) */
@media (min-width: 768px) and (max-width: 991.98px) {
  /* 頁首搜尋框調整 */
  #desktop-search-form .input-group {
    flex-wrap: nowrap;
  }

  #desktop-search-form .btn {
    white-space: nowrap;
    padding-left: 1rem;
    padding-right: 1rem;
  }

  /* 商品頁圖片調整 */
  .product-gallery .main-image img {
    max-height: 400px;
  }

  /* 頁尾調整 */
  .footer-title {
    font-size: 1rem !important;
  }
}

/* 手機優化 (< 768px) */
@media (max-width: 767.98px) {
  /* 商品價格區塊 */
  .product-price {
    padding: 1rem !important;
  }

  .product-price span[style*="font-size: 2rem"] {
    font-size: 1.75rem !important;
  }

  /* 付款方式精簡顯示 */
  .payment-methods {
    gap: 0.5rem;
  }

  .payment-method span {
    font-size: 0.75rem;
  }

  /* 頁尾間距調整 */
  .footer {
    padding-top: 2rem !important;
  }

  .footer .container {
    padding-top: 2rem !important;
    padding-bottom: 2rem !important;
  }
}

/* ========================================
   通用動畫和過渡效果
   ======================================== */

/* 淡入動畫 */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeIn 0.5s ease-out;
}

/* 滑入動畫 */
@keyframes slideIn {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(0);
  }
}

.slide-in {
  animation: slideIn 0.3s ease-out;
}

/* 脈衝動畫 */
@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

.pulse-animation {
  animation: pulse 2s infinite;
}

/* ========================================
   可訪問性優化
   ======================================== */

/* 聚焦狀態優化 */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid #0d6efd;
  outline-offset: 2px;
}

/* 減少動畫（尊重用戶偏好） */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ========================================
   載入優化
   ======================================== */

/* 圖片延遲載入佔位符 */
img[loading="lazy"] {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}

@keyframes loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

img[loading="lazy"].loaded {
  animation: none;
  background: none;
}
