/**
 * Skeleton Screen Styles
 * 骨架屏樣式 - 用於改善載入體驗和防止 CLS
 * 
 * @package Tixteel
 * @since 1.3.0
 */

/* ========================================
   骨架屏基礎樣式
   ======================================== */

/**
 * 骨架屏動畫
 * 使用漸層背景模擬載入效果
 */
@keyframes skeleton-loading {
    0% {
        background-position: -200px 0;
    }
    100% {
        background-position: calc(200px + 100%) 0;
    }
}

/**
 * 骨架屏基礎類別
 * 灰色漸層背景 + 動畫效果
 */
.skeleton {
    background: linear-gradient(
        90deg,
        #f0f0f0 0%,
        #e0e0e0 20%,
        #e0e0e0 40%,
        #f0f0f0 100%
    );
    background-size: 200px 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 4px;
}

/**
 * 內容淡入動畫
 * 當實際內容載入後使用
 */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.content-loaded {
    animation: fadeIn 0.3s ease-in;
}

/* ========================================
   首頁輪播骨架屏
   ======================================== */

/**
 * 輪播容器骨架
 * 使用 aspect-ratio 預留空間，避免 CLS
 */
.indexSlide-skeleton {
    width: 100%;
    aspect-ratio: 16 / 9; /* 桌機版比例 */
    background: #e8e8e8;
    position: relative;
    overflow: hidden;
    margin-bottom: 0; /* 與下方區塊緊密連接 */
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05); /* 輕微邊框增加層次 */
}

/**
 * 輪播骨架動畫層
 */
.indexSlide-skeleton::before {
    content: '';
    position: absolute;
    top: 0;
    left: -200px;
    width: 200px;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.4),
        transparent
    );
    animation: skeleton-slide 1.5s ease-in-out infinite;
    z-index: 1;
}

@keyframes skeleton-slide {
    0% {
        left: -200px;
    }
    100% {
        left: 100%;
    }
}

/**
 * 輪播控制按鈕骨架
 */
.indexSlide-skeleton .skeleton-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 50%;
}

.indexSlide-skeleton .skeleton-nav.prev {
    left: 20px;
}

.indexSlide-skeleton .skeleton-nav.next {
    right: 20px;
}

/**
 * 輪播分頁指示器骨架
 */
.indexSlide-skeleton .skeleton-pagination {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
}

.indexSlide-skeleton .skeleton-pagination span {
    width: 12px;
    height: 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
}

/**
 * 手機版輪播比例
 */
@media (max-width: 768px) {
    .indexSlide-skeleton {
        aspect-ratio: 9 / 16; /* 手機版比例 */
    }
}

/* ========================================
   活動橫幅骨架屏
   ======================================== */

/**
 * 活動橫幅容器骨架
 * 模擬 .indexBoxLine 的布局
 */
.indexBoxLine-skeleton {
    display: flex;
    gap: 0;
    width: 100%;
    margin: 0;
    background: #fff; /* 白色背景區隔 */
}

/**
 * 單一橫幅骨架
 * 使用 aspect-ratio 預留空間，避免 CLS
 */
.indexBoxLine-skeleton .banner-skeleton {
    flex: 1;
    width: 50%;
    aspect-ratio: 16 / 9; /* 桌機版比例 */
    background: #f5f5f5;
    position: relative;
    overflow: hidden;
}

/**
 * 橫幅骨架動畫層
 */
.indexBoxLine-skeleton .banner-skeleton::before {
    content: '';
    position: absolute;
    top: 0;
    left: -200px;
    width: 200px;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.5),
        transparent
    );
    animation: skeleton-slide 1.5s ease-in-out infinite;
    z-index: 1;
}

/**
 * 橫幅之間的分隔線
 */
.indexBoxLine-skeleton .banner-skeleton:first-child::after {
    content: '';
    position: absolute;
    right: 0;
    top: 10%;
    height: 80%;
    width: 1px;
    background: rgba(0, 0, 0, 0.08);
    z-index: 2;
}

/**
 * 手機版橫幅布局
 * 對應 basic.css 中 .indexBoxLine 的手機版樣式
 */
@media (max-width: 1140px) {
    .indexBoxLine-skeleton {
        flex-direction: column;
    }
    
    .indexBoxLine-skeleton .banner-skeleton {
        width: 100%;
        aspect-ratio: 2 / 1; /* 手機版比例 */
    }
    
    /**
     * 手機版：橫幅之間的水平分隔線
     */
    .indexBoxLine-skeleton .banner-skeleton:first-child::after {
        right: auto;
        left: 10%;
        top: auto;
        bottom: 0;
        width: 80%;
        height: 1px;
    }
}

/* ========================================
   精選產品骨架屏
   ======================================== */

/**
 * 產品列表容器骨架
 * 完全繼承 .indexProList 的樣式，避免衝突
 */
.indexProList-skeleton {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 30px;
    width: 90%;
    max-width: 1440px;
    margin: 50px auto 0;
    list-style: none;
    padding: 0;
    background: transparent; /* 透明背景，與活動橫幅區隔 */
}

/**
 * 單一產品卡片骨架
 */
.indexProList-skeleton .product-card-skeleton {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #fff;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

/**
 * 產品圖片骨架
 * 使用 aspect-ratio 預留空間
 */
.indexProList-skeleton .skeleton-image {
    width: 100%;
    aspect-ratio: 1 / 1; /* 正方形 */
    background: #f8f8f8;
    border-radius: 6px;
    margin: -15px -15px 0 -15px; /* 延伸到卡片邊緣 */
    width: calc(100% + 30px);
}

/**
 * 產品標題骨架
 */
.indexProList-skeleton .skeleton-title {
    width: 100%;
    height: 20px;
    background: #f0f0f0;
    border-radius: 4px;
}

/**
 * 產品副標題骨架
 */
.indexProList-skeleton .skeleton-subtitle {
    width: 80%;
    height: 16px;
    background: #f0f0f0;
    border-radius: 4px;
}

/**
 * 產品特色骨架
 */
.indexProList-skeleton .skeleton-features {
    width: 90%;
    height: 14px;
    background: #f0f0f0;
    border-radius: 4px;
}

/**
 * 產品價格骨架
 */
.indexProList-skeleton .skeleton-price {
    width: 60%;
    height: 24px;
    background: #f0f0f0;
    border-radius: 4px;
    margin-top: 8px;
}

/**
 * 手機版布局（2 欄）
 * 對應 basic.css 中 .indexProList 的手機版樣式
 */
@media (max-width: 1140px) {
    .indexProList-skeleton {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        width: 98%;
    }
    
    .indexProList-skeleton .skeleton-features {
        display: none; /* 手機版隱藏特色 */
    }
}

/* ========================================
   載入狀態控制
   ======================================== */

/**
 * 隱藏骨架屏
 * 當內容載入完成後使用
 */
.skeleton-hidden {
    display: none !important;
}

/**
 * 顯示實際內容
 * 配合淡入動畫
 */
.content-visible {
    display: block;
    animation: fadeIn 0.3s ease-in;
}
