/**
 * Flavor Product Showcase - 前端樣式
 * 支援橫式/直式 Tab、響應式商品格線、分頁、載入更多
 */

/* ===== 基礎重置 ===== */
.fps-showcase {
    --fps-primary: #333333;
    --fps-primary-hover: #555555;
    --fps-bg: #ffffff;
    --fps-border: #e5e5e5;
    --fps-text: #333333;
    --fps-text-muted: #999999;
    --fps-price: #e74c3c;
    --fps-sale-bg: #e74c3c;
    --fps-radius: 8px;
    --fps-transition: 0.3s ease;

    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
    width: 100%;
    box-sizing: border-box;
}

.fps-showcase *,
.fps-showcase *::before,
.fps-showcase *::after {
    box-sizing: border-box;
}

/* ===== Tab 導覽 - 共用 ===== */
.fps-tab-nav {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
}
.fps-tab-nav::-webkit-scrollbar {
    display: none; /* Chrome, Safari, etc */
}

.fps-tab-btn {
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    padding: 10px 20px;
    background-color: #f5f5f5;
    color: var(--fps-text);
    transition: all var(--fps-transition);
    white-space: nowrap;
    position: relative;
    outline: none;
    flex-shrink: 0;
}

.fps-tab-btn:hover {
    background-color: #e8e8e8;
}

.fps-tab-btn.fps-tab-active {
    background-color: var(--fps-primary);
    color: #ffffff;
}

.fps-tab-btn:focus,
.fps-tab-btn:active,
.fps-tab-btn:focus-visible {
    outline: none !important;
    box-shadow: none !important;
}

/* ===== 橫式 Tab ===== */
.fps-tabs-horizontal {
    display: flex;
    flex-direction: column;
}

.fps-tabs-horizontal .fps-tab-nav {
    flex-direction: row;
    border-bottom: 2px solid var(--fps-border);
    margin-bottom: 24px;
}

.fps-tabs-horizontal .fps-tab-btn {
    border-radius: 6px 6px 0 0;
    margin-bottom: -2px;
    border-bottom: 2px solid transparent;
}

.fps-tabs-horizontal .fps-tab-btn.fps-tab-active {
    border-bottom-color: var(--fps-primary);
}

/* ===== 直式 Tab ===== */
.fps-tabs-vertical {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 24px;
}

.fps-tabs-vertical .fps-tab-nav {
    flex-direction: column;
    width: 200px;
    min-width: 150px;
    flex-shrink: 0;
    border-right: 2px solid var(--fps-border);
    padding-right: 0;
}

.fps-tabs-vertical .fps-tab-btn {
    text-align: left;
    border-radius: 6px 0 0 6px;
    border-right: 3px solid transparent;
    margin-right: -2px;
    width: 100%;
}

.fps-tabs-vertical .fps-tab-btn.fps-tab-active {
    border-right-color: var(--fps-primary);
}

.fps-tabs-vertical .fps-tab-content {
    flex: 1;
    min-width: 0;
}

/* ===== 排序列 ===== */
.fps-sort-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    padding: 8px 0;
}

.fps-sort-bar label {
    font-size: 14px;
    color: var(--fps-text-muted);
    white-space: nowrap;
}

.fps-sort-select {
    padding: 6px 12px;
    border: 1px solid var(--fps-border);
    border-radius: 4px;
    font-size: 14px;
    color: var(--fps-text);
    background: white;
    cursor: pointer;
    outline: none;
}

.fps-sort-select:focus {
    border-color: var(--fps-primary);
}

/* ===== 商品格線 ===== */
.fps-products-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

.fps-products-grid[data-columns="1"] { grid-template-columns: 1fr; }
.fps-products-grid[data-columns="2"] { grid-template-columns: repeat(2, 1fr); }
.fps-products-grid[data-columns="3"] { grid-template-columns: repeat(3, 1fr); }
.fps-products-grid[data-columns="4"] { grid-template-columns: repeat(4, 1fr); }
.fps-products-grid[data-columns="5"] { grid-template-columns: repeat(5, 1fr); }
.fps-products-grid[data-columns="6"] { grid-template-columns: repeat(6, 1fr); }

/* ===== 商品卡片 ===== */
.fps-product-card {
    background: var(--fps-bg);
    border-radius: var(--fps-radius);
    overflow: hidden;
    transition: transform var(--fps-transition), box-shadow var(--fps-transition);
    border: 1px solid var(--fps-border);
    display: flex;
    flex-direction: column;
}

.fps-product-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

/* 商品圖片 */
.fps-product-image-link {
    display: block;
    text-decoration: none;
}

.fps-product-image {
    position: relative;
    width: 100%;
    padding-bottom: 100%; /* 1:1 預設 */
    overflow: hidden;
    background: #f8f8f8;
}

.fps-product-image img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.fps-product-card:hover .fps-product-image img {
    transform: scale(1.05);
}

/* 特價標籤 */
.fps-sale-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    background: var(--fps-sale-bg);
    color: white;
    padding: 4px 10px;
    border-radius: 3px;
    font-size: 12px;
    font-weight: 600;
    z-index: 2;
    letter-spacing: 1px;
}

/* 商品資訊 */
.fps-product-info {
    padding: 16px;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.fps-product-title {
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 8px;
    line-height: 1.4;
}

.fps-product-title a {
    color: var(--fps-text);
    text-decoration: none;
    transition: color var(--fps-transition);
}

.fps-product-title a:hover {
    color: var(--fps-primary);
}

.fps-product-price {
    font-size: 16px;
    font-weight: 700;
    color: var(--fps-price);
    margin-bottom: 8px;
}

.fps-product-price del {
    color: var(--fps-text-muted);
    font-weight: 400;
    font-size: 13px;
    margin-right: 4px;
}

.fps-product-price ins {
    text-decoration: none;
}

.fps-product-rating {
    margin-bottom: 8px;
}

.fps-product-rating .star-rating {
    font-size: 13px;
}

.fps-product-desc {
    font-size: 13px;
    color: var(--fps-text-muted);
    line-height: 1.5;
    margin-bottom: 12px;
}

/* 購買按鈕 */
.fps-product-actions {
    margin-top: auto;
    padding-top: 8px;
}

.fps-product-actions .button,
.fps-btn-primary {
    display: inline-block;
    width: 100%;
    text-align: center;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: 4px;
    background-color: var(--fps-primary);
    color: #ffffff;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--fps-transition);
}

.fps-product-actions .button:hover,
.fps-btn-primary:hover {
    background-color: var(--fps-primary-hover);
    color: #ffffff;
}

/* ===== 分頁 ===== */
.fps-pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 30px;
    padding: 10px 0;
}

.fps-page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    padding: 0 10px;
    border: 1px solid var(--fps-border);
    background: white;
    color: var(--fps-text);
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    transition: all var(--fps-transition);
}

.fps-page-btn:hover {
    border-color: var(--fps-primary);
    color: var(--fps-primary);
}

.fps-page-btn.fps-page-active {
    background-color: var(--fps-primary);
    border-color: var(--fps-primary);
    color: white;
}

/* 載入更多 */
.fps-load-more-wrap {
    text-align: center;
    margin-top: 30px;
}

.fps-load-more-btn {
    display: inline-block;
    padding: 12px 40px;
    border: 2px solid var(--fps-primary);
    background: transparent;
    color: var(--fps-primary);
    font-size: 15px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--fps-transition);
}

.fps-load-more-btn:hover {
    background: var(--fps-primary);
    color: white;
}

/* ===== Loading ===== */
.fps-loading {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    gap: 12px;
    color: var(--fps-text-muted);
    font-size: 14px;
}

.fps-loading.fps-show {
    display: flex;
}

.fps-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--fps-border);
    border-top-color: var(--fps-primary);
    border-radius: 50%;
    animation: fpsSpinnerRotate 0.8s linear infinite;
}

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

/* 沒有商品 */
.fps-no-products {
    text-align: center;
    padding: 60px 20px;
    color: var(--fps-text-muted);
    font-size: 15px;
}

/* ===== 淡入動畫 ===== */
.fps-products-container {
    animation: fpsFadeIn 0.3s ease;
}

@keyframes fpsFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ===== 響應式 ===== */

/* 平板 */
@media (max-width: 1024px) {
    .fps-products-grid[data-columns="5"],
    .fps-products-grid[data-columns="6"] {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}

/* 平板直式 */
@media (max-width: 768px) {
    .fps-products-grid[data-columns="4"],
    .fps-products-grid[data-columns="5"],
    .fps-products-grid[data-columns="6"] {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    /* 直式 Tab 在平板轉為橫式 */
    .fps-tabs-vertical {
        flex-direction: column;
    }

    .fps-tabs-vertical .fps-tab-nav {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        width: 100% !important;
        min-width: 0;
        border-right: none;
        border-bottom: 2px solid var(--fps-border);
        padding-right: 0;
        padding-bottom: 4px;
        margin-bottom: 16px;
    }
    
    .fps-tabs-vertical .fps-tab-nav::-webkit-scrollbar {
        display: none;
    }

    .fps-tabs-vertical .fps-tab-btn {
        border-radius: 6px 6px 0 0;
        border-right: none;
        border-bottom: 2px solid transparent;
        margin-right: 0;
        margin-bottom: -2px;
        width: auto;
        flex-shrink: 0;
    }

    .fps-tabs-vertical .fps-tab-btn.fps-tab-active {
        border-right-color: transparent;
        border-bottom-color: var(--fps-primary);
    }
}

/* 手機 */
@media (max-width: 576px) {
    .fps-products-grid,
    .fps-products-grid[data-columns="2"],
    .fps-products-grid[data-columns="3"],
    .fps-products-grid[data-columns="4"],
    .fps-products-grid[data-columns="5"],
    .fps-products-grid[data-columns="6"] {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }

    .fps-tab-nav {
        gap: 4px;
        padding-bottom: 4px; /* 防止橫向捲動軸切到文字或陰影 */
    }

    .fps-tab-btn {
        font-size: 13px;
        padding: 8px 14px;
    }

    .fps-product-info {
        padding: 10px;
    }

    .fps-product-title {
        font-size: 13px;
    }

    .fps-product-price {
        font-size: 14px;
    }

    .fps-product-actions .button,
    .fps-btn-primary {
        padding: 8px 12px;
        font-size: 13px;
    }

    .fps-sort-bar {
        flex-wrap: wrap;
    }
}

/* 超小螢幕 */
@media (max-width: 380px) {
    .fps-products-grid,
    .fps-products-grid[data-columns="2"],
    .fps-products-grid[data-columns="3"],
    .fps-products-grid[data-columns="4"],
    .fps-products-grid[data-columns="5"],
    .fps-products-grid[data-columns="6"] {
        grid-template-columns: 1fr;
    }
}
