/**
 * ECShop 產品區塊共用樣式
 * index.css
 * 
 * 檔案說明：
 * 此檔案為 ECShop 電商系統首頁及產品展示相關頁面的核心樣式文件，
 * 專門處理產品卡片、產品網格佈局、互動效果等商品展示相關的所有
 * 視覺設計。採用企業文化風格，注重用戶體驗與商業轉換效果。
 * 
 * 主要功能：
 * - 產品卡片設計（商品圖片、名稱、價格、購買按鈕）
 * - 響應式產品網格佈局（桌面4欄、平板3欄、手機2欄）
 * - 展開/收合功能（分頁式產品顯示）
 * - 產品標籤系統（新品、促銷、熱銷等）
 * - 快速檢視功能
 * - 購物車快捷按鈕
 * - 產品排名徽章系統
 * 
 * 設計特色：
 * - 現代企業風格設計
 * - 卡片懸浮效果與陰影
 * - 流暢的動畫過渡
 * - 漸變背景與裝飾元素
 * - 統一的色彩體系應用
 * 
 * 商業功能：
 * - 產品銷售數據顯示
 * - 價格促銷標示（原價、特價）
 * - 一鍵加入購物車
 * - 產品快速預覽
 * - 排行榜視覺標示
 * 
 * 互動體驗：
 * - Hover 懸浮放大效果
 * - 按鈕點擊回饋動畫
 * - 圖片載入狀態處理
 * - 展開按鈕互動設計
 * - 滑入動畫效果
 * 
 * 響應式設計：
 * - 桌面版：4欄網格，完整資訊顯示
 * - 平板版：3欄網格，適度調整間距
 * - 手機版：2欄網格，簡化資訊顯示
 * - 超小螢幕：極簡化設計，保持可用性
 * 
 * 技術亮點：
 * - CSS Grid 現代佈局系統
 * - CSS Transform 硬體加速
 * - 關鍵幀動畫設計
 * - 圖片懶載入狀態處理
 * - 骨架屏載入效果
 * 
 * 效能優化：
 * - 硬體加速動畫
 * - 最小重繪區域
 * - 圖片尺寸自適應
 * - 延遲載入動畫
 * - GPU 加速處理
 * 
 * 無障礙設計：
 * - 語義化 HTML 結構支援
 * - 鍵盤導航友善
 * - 螢幕閱讀器文字
 * - 高對比度模式支援
 * - 減少動畫偏好支援
 * 
 * 瀏覽器兼容：
 * - 現代瀏覽器：完整動畫效果
 * - IE11：基本功能保證
 * - 移動瀏覽器：觸控優化
 * - 漸進式增強設計
 * 
 * 商品展示系統：
 * - 多種卡片尺寸支援
 * - 產品圖片處理機制
 * - 價格顯示邏輯
 * - 庫存狀態處理
 * - 評分星級顯示
 * 
 * 主題色彩應用：
 * - 主色調：企業藍 (#3b82f6)
 * - 輔助色：企業棕 (#8b7355)
 * - 文字色：深灰色系
 * - 背景色：淺灰漸變
 * - 強調色：促銷紅色
 * 
 * 適用版本：PHP 7.3+ / ECShop 4.x / cls_template
 * 版本：1.0
 * 更新：2024
 */

/* CSS 重置和基礎設定 */
* {
    box-sizing: border-box;
}

/* 區塊主體樣式 */
.product-sections-common {
    background: linear-gradient(135deg, #f5f7fa 0%, #e9ecef 100%);
    padding: 60px 0;
    position: relative;
    overflow: hidden;
    will-change: transform; /* 硬體加速 */
}

.product-sections-common::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -10%;
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(139, 115, 85, 0.05) 0%, transparent 70%);
    border-radius: 50%;
    will-change: transform;
}

/* 左側裝飾元素 */
.product-sections-common.left-decoration::before {
    right: auto;
    left: -10%;
}

.product-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* 標題設計 */
.section-header {
    text-align: center;
    margin-bottom: 50px;
    position: relative;
}

.section-title {
    font-size: 36px;
    color: #2c3e50;
    font-weight: 300;
    letter-spacing: 3px;
    margin-bottom: 15px;
    position: relative;
    display: inline-block;
}

.section-title::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 3px;
    background: linear-gradient(90deg, #8b7355, #a08568);
}

.section-subtitle {
    color: #7f8c8d;
    font-size: 16px;
    margin-top: 20px;
    letter-spacing: 1px;
}

.view-more-link {
    display: inline-block;
    margin-top: 20px;
    color: #8b7355;
    text-decoration: none;
    font-size: 14px;
    letter-spacing: 2px;
    transition: all 0.3s ease;
    position: relative;
    padding-bottom: 3px;
}

.view-more-link::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 1px;
    background: #8b7355;
    transition: width 0.3s ease;
}

.view-more-link:hover::after {
    width: 100%;
}

.view-more-link:hover {
    color: #a08568;
    text-decoration: none;
}

/* 產品網格容器 */
.products-grid-wrapper {
    position: relative;
}

.products-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 30px;
    padding: 20px 0;
    transition: max-height 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    will-change: max-height;
}

/* 展開/收合控制 */
.products-grid.collapsed {
    max-height: 500px;
    overflow: hidden;
    min-height: 200px; /* 修正：防止高度計算錯誤 */
}

.products-grid.expanded {
    max-height: none;
}

/* 漸變遮罩效果 - 修正瀏覽器相容性 */
.products-grid.collapsed::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100px;
    background: linear-gradient(
        to bottom, 
        rgba(245, 247, 250, 0) 0%,
        rgba(245, 247, 250, 0.8) 60%,
        rgba(245, 247, 250, 1) 100%
    );
    /* 修正：添加瀏覽器前綴 */
    background: -webkit-linear-gradient(
        top, 
        rgba(245, 247, 250, 0) 0%,
        rgba(245, 247, 250, 0.8) 60%,
        rgba(245, 247, 250, 1) 100%
    );
    pointer-events: none;
    z-index: 10;
}

/* 展開按鈕 */
.expand-button-wrapper {
    text-align: center;
    margin-top: 30px;
    position: relative;
    z-index: 11; /* 確保在遮罩上方 */
}

.expand-button {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: #ffffff;
    color: #8b7355;
    padding: 15px 40px;
    border: 2px solid #8b7355;
    border-radius: 50px;
    font-size: 15px;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 15px rgba(139, 115, 85, 0.1);
    position: relative;
    overflow: hidden;
    /* 修正：添加最小觸控尺寸 */
    min-height: 44px;
    touch-action: manipulation;
    will-change: transform;
}

.expand-button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: linear-gradient(135deg, #8b7355, #a08568);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: -1;
}

.expand-button:hover {
    color: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(139, 115, 85, 0.2);
}

.expand-button:hover::before {
    width: 300px;
    height: 300px;
}

.expand-button:focus {
    outline: 2px solid #8b7355;
    outline-offset: 2px;
}

.expand-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.expand-icon {
    width: 20px;
    height: 20px;
    fill: currentColor;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.expand-button.expanded .expand-icon {
    transform: rotate(180deg);
}

.expand-text {
    font-weight: 500;
}

.product-count-hint {
    display: inline-block;
    margin-left: 10px;
    padding: 2px 10px;
    background: rgba(139, 115, 85, 0.1);
    border-radius: 15px;
    font-size: 13px;
    color: #8b7355;
}

/* 產品卡片 */
.product-card {
    background: #ffffff;
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 2px 15px rgba(44, 62, 80, 0.08);
    position: relative;
    height: 100%;
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* 修正：添加硬體加速 */
    will-change: transform, opacity;
    transform: translateZ(0);
    backface-visibility: hidden;
}

.product-card:hover {
    transform: translateY(-8px) translateZ(0);
    box-shadow: 0 8px 30px rgba(44, 62, 80, 0.15);
}

.product-card.hidden-initially {
    opacity: 0;
    transform: translateY(20px) translateZ(0);
}

.products-grid.expanded .product-card.hidden-initially {
    animation: fadeInUp 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* 排名相關樣式 */
.ranking-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    background: linear-gradient(135deg, #8b7355, #a08568);
    color: #ffffff;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    z-index: 12;
    box-shadow: 0 2px 8px rgba(139, 115, 85, 0.3);
}

.product-card.top-three .ranking-badge {
    background: linear-gradient(135deg, #f39c12, #e67e22);
}

.product-card.top-ten .ranking-badge {
    background: linear-gradient(135deg, #3498db, #2980b9);
}

/* 產品圖片區域 */
.product-image-wrapper {
    position: relative;
    overflow: hidden;
    background: #f8f9fa;
    aspect-ratio: 1 / 1;
}

.product-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    /* 修正：改善圖片載入處理 */
    background-color: #f8f9fa;
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23dee2e6"><path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/></svg>');
    background-repeat: no-repeat;
    background-position: center;
    background-size: 48px 48px;
}

.product-card:hover .product-image {
    transform: scale(1.08);
}

/* 圖片載入狀態 */
.product-image[data-loading="true"] {
    background-color: #e9ecef;
    animation: skeleton-loading 1.5s ease-in-out infinite alternate;
}

.product-image.error-image {
    opacity: 0.5;
}

@keyframes skeleton-loading {
    0% { opacity: 1; }
    100% { opacity: 0.4; }
}

/* 產品標籤 */
.product-badge {
    position: absolute;
    top: 15px;
    right: 15px;
    color: #ffffff;
    padding: 6px 15px;
    border-radius: 20px;
    font-size: 12px;
    letter-spacing: 1px;
    font-weight: 500;
    z-index: 11;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}

/* 不同類型的標籤顏色 */
.product-badge.new {
    background: linear-gradient(135deg, #8b7355, #a08568);
    box-shadow: 0 3px 10px rgba(139, 115, 85, 0.3);
}

.product-badge.promotion {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    box-shadow: 0 3px 10px rgba(231, 76, 60, 0.3);
}

.product-badge.sales {
    background: linear-gradient(135deg, #8b7355, #a08568);
    box-shadow: 0 3px 10px rgba(139, 115, 85, 0.3);
}

/* 快速檢視按鈕 */
.quick-view-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(44, 62, 80, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
}

.product-card:hover .quick-view-overlay {
    opacity: 1;
}

.quick-view-btn {
    background: #ffffff;
    color: #2c3e50;
    padding: 12px 25px;
    border-radius: 25px;
    text-decoration: none;
    font-size: 14px;
    letter-spacing: 1px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateY(10px);
}

.product-card:hover .quick-view-btn {
    transform: translateY(0);
}

.quick-view-btn:hover {
    background: #8b7355;
    color: #ffffff;
    text-decoration: none;
}

/* 產品資訊區域 */
.product-info {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.product-name {
    font-size: 16px;
    color: #34495e;
    margin-bottom: 10px;
    font-weight: 400;
    line-height: 1.4;
    min-height: 44px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-name a {
    color: inherit;
    text-decoration: none;
    transition: color 0.3s ease;
}

.product-name a:hover {
    color: #8b7355;
}

.product-name a:focus {
    outline: 2px solid #8b7355;
    outline-offset: 2px;
}

/* 銷售數據 */
.product-sales {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 15px;
    color: #7f8c8d;
    font-size: 13px;
}

.sales-icon {
    width: 16px;
    height: 16px;
    fill: currentColor;
    flex-shrink: 0;
}

/* 不同類型的銷售圖標顏色 */
.sales-icon.new {
    fill: #8b7355;
}

.sales-icon.promotion {
    fill: #e74c3c;
}

.sales-icon.sales {
    fill: #8b7355;
}

/* 價格與購買區域 */
.product-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 15px;
    border-top: 1px solid #e9ecef;
    margin-top: auto;
}

.product-price {
    font-size: 22px;
    color: #8b7355;
    font-weight: 600;
    letter-spacing: 0.5px;
    flex: 1;
}

/* 促銷價格樣式 */
.promotion-price {
    color: #e74c3c;
    font-weight: 700;
    margin-right: 8px;
}

.original-price {
    font-size: 16px;
    color: #95a5a6;
    text-decoration: line-through;
    font-weight: 400;
}

.buy-button {
    background: linear-gradient(135deg, #2c3e50, #34495e);
    color: #ffffff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 3px 10px rgba(44, 62, 80, 0.2);
    flex-shrink: 0;
    /* 修正：確保足夠的觸控區域 */
    min-width: 40px;
    min-height: 40px;
}

.buy-button:hover {
    background: linear-gradient(135deg, #8b7355, #a08568);
    transform: rotate(10deg) scale(1.1);
    box-shadow: 0 5px 15px rgba(139, 115, 85, 0.3);
}

.buy-button:focus {
    outline: 2px solid #8b7355;
    outline-offset: 2px;
}

.cart-icon {
    width: 18px;
    height: 18px;
    fill: #ffffff;
}

/* 螢幕閱讀器專用文字 */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* 響應式設計 - 修正版本 */
@media (max-width: 1400px) {
    .products-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 25px;
    }
}

@media (max-width: 1200px) {
    .products-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 25px;
    }
}

@media (max-width: 992px) {
    .products-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 20px;
    }
}

@media (max-width: 768px) {
    .product-sections-common {
        padding: 40px 0;
    }
    
    .section-title {
        font-size: 28px;
        letter-spacing: 2px;
    }
    
    .products-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 15px;
    }
    
    .product-info {
        padding: 12px;
    }
    
    .product-name {
        font-size: 14px;
        min-height: 38px;
    }
    
    .product-price {
        font-size: 16px;
    }
    
    .product-sales {
        font-size: 11px;
        gap: 4px;
    }
    
    .sales-icon {
        width: 14px;
        height: 14px;
    }
    
    .expand-button {
        padding: 12px 30px;
        font-size: 14px;
    }
}

/* 修正：小螢幕佈局改為 2 欄 */
@media (max-width: 576px) {
    .product-container {
        padding: 0 10px;
    }
    
    .products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px;
    }
    
    .product-badge {
        font-size: 10px;
        padding: 3px 8px;
        top: 8px;
        right: 8px;
    }
    
    .product-info {
        padding: 10px;
    }
    
    .product-name {
        font-size: 12px;
        min-height: 32px;
        margin-bottom: 6px;
    }
    
    .product-sales {
        display: none; /* 小螢幕隱藏銷售數據節省空間 */
    }
    
    .product-footer {
        padding-top: 10px;
    }
    
    .product-price {
        font-size: 14px;
    }
    
    .buy-button {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
    }
    
    .cart-icon {
        width: 14px;
        height: 14px;
    }
    
    .expand-button-wrapper {
        margin-top: 20px;
    }
    
    .expand-button {
        padding: 10px 25px;
        font-size: 13px;
        min-height: 44px; /* 保持足夠的觸控區域 */
    }
    
    .expand-icon {
        width: 16px;
        height: 16px;
    }
    
    .product-count-hint {
        font-size: 11px;
        padding: 2px 8px;
    }
    
    .ranking-badge {
        width: 24px;
        height: 24px;
        font-size: 10px;
        top: 6px;
        left: 6px;
    }
}

@media (max-width: 480px) {
    .product-sections-common {
        padding: 30px 0;
    }
    
    .section-header {
        margin-bottom: 25px;
    }
    
    .section-title {
        font-size: 24px;
        letter-spacing: 1px;
    }
    
    .section-subtitle {
        font-size: 14px;
    }
    
    .view-more-link {
        font-size: 12px;
        margin-top: 15px;
    }
    
    .products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px;
    }
    
    .product-card {
        border-radius: 6px;
    }
    
    .product-badge {
        font-size: 9px;
        padding: 2px 6px;
        top: 5px;
        right: 5px;
    }
    
    .product-info {
        padding: 8px;
    }
    
    .product-name {
        font-size: 11px;
        min-height: 28px;
        margin-bottom: 5px;
        -webkit-line-clamp: 1; /* 單行顯示 */
    }
    
    .product-footer {
        padding-top: 8px;
    }
    
    .product-price {
        font-size: 13px;
        font-weight: 500;
    }
    
    .buy-button {
        width: 30px;
        height: 30px;
        min-width: 30px;
        min-height: 30px;
    }
    
    .cart-icon {
        width: 13px;
        height: 13px;
    }
    
    .quick-view-btn {
        padding: 8px 15px;
        font-size: 11px;
    }
    
    .ranking-badge {
        width: 20px;
        height: 20px;
        font-size: 9px;
        top: 4px;
        left: 4px;
    }
}

/* 修正：極小螢幕優化 */
@media (max-width: 360px) {
    .product-container {
        padding: 0 8px;
    }
    
    .products-grid {
        gap: 8px;
    }
    
    .product-info {
        padding: 6px;
    }
    
    .product-name {
        font-size: 10px;
        min-height: 24px;
    }
    
    .product-price {
        font-size: 12px;
    }
    
    .buy-button {
        width: 28px;
        height: 28px;
        min-width: 28px;
        min-height: 28px;
    }
    
    .cart-icon {
        width: 12px;
        height: 12px;
    }
}

/* 修正：極小螢幕 (320px) 可讀性優化 */
@media (max-width: 320px) {
    .section-title {
        font-size: 20px !important;
        letter-spacing: 1px;
    }
    
    .product-name {
        font-size: 12px !important;
        line-height: 1.3;
    }
    
    .product-price {
        font-size: 14px !important;
    }
}

/* 載入動畫 */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px) translateZ(0);
    }
    to {
        opacity: 1;
        transform: translateY(0) translateZ(0);
    }
}

.product-card {
    animation: fadeInUp 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    opacity: 0;
}

/* 動畫延遲 */
.product-card:nth-child(1) { animation-delay: 0.05s; }
.product-card:nth-child(2) { animation-delay: 0.1s; }
.product-card:nth-child(3) { animation-delay: 0.15s; }
.product-card:nth-child(4) { animation-delay: 0.2s; }
.product-card:nth-child(5) { animation-delay: 0.25s; }
.product-card:nth-child(6) { animation-delay: 0.3s; }
.product-card:nth-child(7) { animation-delay: 0.35s; }
.product-card:nth-child(8) { animation-delay: 0.4s; }
.product-card:nth-child(n+9) { animation-delay: 0.45s; }

.products-grid.expanded .product-card.hidden-initially {
    animation-delay: 0.1s;
}

/* 高對比度模式支援 */
@media (prefers-contrast: high) {
    .product-card {
        border: 2px solid #000;
    }
    
    .product-badge {
        border: 1px solid #fff;
    }
    
    .expand-button {
        border-width: 3px;
    }
    
    .view-more-link {
        text-decoration: underline;
    }
}

/* 減少動畫偏好支援 */
@media (prefers-reduced-motion: reduce) {
    .product-card,
    .expand-button,
    .buy-button,
    .quick-view-btn,
    .product-image {
        animation: none;
        transition: none;
    }
    
    .products-grid {
        transition: max-height 0.2s ease;
    }
}

/* 深色模式支援（可選） */
@media (prefers-color-scheme: dark) {
    .product-sections-common {
        background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    }
    
    .product-card {
        background: #3a4a5c;
        color: #ecf0f1;
    }
    
    .section-title {
        color: #ecf0f1;
    }
    
    .section-subtitle {
        color: #bdc3c7;
    }
    
    .product-name a {
        color: #ecf0f1;
    }
    
    .product-price {
        color: #f39c12;
    }
}

/* Print 樣式 */
@media print {
    .product-sections-common {
        background: none !important;
        box-shadow: none !important;
    }
    
    .quick-view-overlay,
    .expand-button-wrapper,
    .product-badge {
        display: none !important;
    }
    
    .product-card {
        break-inside: avoid;
        box-shadow: 0 1px 3px rgba(0,0,0,0.3) !important;
    }
}