/**
 * EC Shop - 共享產品卡片樣式
 * 路徑：assets/css/product-card.css
 *
 * 適用：首頁、分類頁、品牌頁、全部產品頁、推介頁、搜尋頁、產品詳情（相關商品）
 * 載入方式：在 front-header.php <head> 加入
 *   <link rel="stylesheet" href="/assets/css/product-card.css">
 */

/* ══════════════════════════════════════════════
   產品網格佈局
   ══════════════════════════════════════════════ */

/* 自適應網格（分類、品牌、搜尋、全部產品、推介） */
.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
}

/* 固定 4 欄網格（首頁用） */
.products-grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

/* 列表模式 */
.products-grid.list-view {
    grid-template-columns: 1fr;
}
.products-grid.list-view .product-card {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 20px;
}

/* ══════════════════════════════════════════════
   產品卡片 - 容器
   ══════════════════════════════════════════════ */
.product-card {
    background: var(--white);
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--border);
    transition: all var(--transition);
    /* flex 直欄：令「加入購物車」掣可以釘喺卡片底部對齊（唔同卡優惠/會員價行數唔同都齊） */
    display: flex;
    flex-direction: column;
}
.product-card:hover {
    border-color: var(--primary-light);
    box-shadow: 0 8px 32px rgba(0, 0, 0, .06);
    transform: translateY(-4px);
}

/* ══════════════════════════════════════════════
   產品卡片 - 圖片區域
   ══════════════════════════════════════════════ */
.pc-image {
    display: block;
    overflow: hidden;
    background: #f8fafc;
    position: relative;
}
.pc-image.pc-fit-contain {
    background: #f8fafc;
}
.pc-image.pc-fit-contain img {
    background: #f8fafc;
}

/* 圖片比例 */
.pc-image.pc-ratio-1-1 {
    aspect-ratio: 1 / 1;
}
.pc-image.pc-ratio-3-4 {
    aspect-ratio: 3 / 4;
}
.pc-image.pc-ratio-4-3 {
    aspect-ratio: 4 / 3;
}
.pc-image.pc-ratio-auto {
    aspect-ratio: auto;
}

/* 原圖比例時，圖片高度自動 */
.pc-image.pc-ratio-auto img {
    width: 100%;
    height: auto;
    display: block;
}

/* 非原圖比例時，圖片填滿容器 */
.pc-image:not(.pc-ratio-auto) img {
    width: 100%;
    height: 100%;
    transition: transform .4s ease;
}

/* 顯示方式 */
.pc-image.pc-fit-cover img {
    object-fit: cover;
}
.pc-image.pc-fit-contain img {
    object-fit: contain;
}

/* 裁剪焦點 */
.pc-image.pc-pos-center img {
    object-position: center center;
}
.pc-image.pc-pos-top img {
    object-position: center top;
}
.product-card:hover .pc-image img {
    transform: scale(1.06);
}

.product-card:hover .pc-image.pc-fit-contain img,
.product-card:hover .pc-image.pc-ratio-auto img {
    transform: none;
}

/* ══════════════════════════════════════════════
   產品卡片 - Badge 系統
   ══════════════════════════════════════════════ */

/* 折扣 Badge（紅色） */
.pc-badge {
    position: absolute;
    background: var(--danger);
    color: #fff;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    z-index: 2;
    box-shadow: 0 2px 8px rgba(239, 68, 68, .3);
}

/* 自訂 Badge（後台設定顏色） */
.pc-badge-custom {
    position: absolute;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    z-index: 2;
}

/* Badge 四角定位 */
.badge-pos-top-left     { top: 10px; left: 10px; }
.badge-pos-top-right    { top: 10px; right: 10px; }
.badge-pos-bottom-left  { bottom: 10px; left: 10px; }
.badge-pos-bottom-right { bottom: 10px; right: 10px; }

/* 售罄遮罩 */
.pc-sold-out {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .45);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 1px;
}

/* ══════════════════════════════════════════════
   產品卡片 - 資訊區
   ══════════════════════════════════════════════ */
.pc-info {
    padding: 14px 16px 18px;
    /* 撐高內容區，配合 .pc-flex-spacer 將底部嘅「加入購物車」掣推到卡片底 */
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
}

/* flex spacer：吸走卡片內容區多出嘅垂直空間，令各卡按鈕底部對齊 */
.pc-flex-spacer {
    flex: 1 1 auto;
    min-height: 6px;
}

/* 品牌名 */
.pc-brand {
    font-size: 11px;
    color: var(--text-light);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .3px;
    margin-bottom: 4px;
}

/* 產品名（最多兩行截斷） */
.pc-name {
    display: -webkit-box;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.4;
    margin-bottom: 8px;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-decoration: none;
}
.pc-name:hover {
    color: var(--primary);
}

/* ══════════════════════════════════════════════
   產品卡片 - 價格
   ══════════════════════════════════════════════ */
.pc-price {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
}
.pc-price-now {
    font-size: 17px;
    font-weight: 800;
    color: var(--primary);
}
.pc-price-was {
    font-size: 13px;
    color: var(--text-light);
    text-decoration: line-through;
}

/* 會員價 */
.pc-member-price {
    font-size: 12px;
    color: var(--accent);
    font-weight: 600;
    margin-top: 4px;
}

/* 自動優惠標籤（受 admin 開關控制，價格下方搶眼 badge） */
.pc-promo-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
    max-width: 100%;
    padding: 3px 10px;
    font-size: 11.5px;
    font-weight: 800;
    line-height: 1.6;
    color: #fff;
    background: linear-gradient(135deg, #f97316, #ef4444);
    border-radius: 999px;
    box-shadow: 0 2px 7px rgba(239, 68, 68, .28);
    position: relative;
    overflow: hidden;
    vertical-align: middle;
}
.pc-promo-label .pc-promo-ico {
    font-size: 12px;
    line-height: 1;
    flex-shrink: 0;
}
.pc-promo-label .pc-promo-txt {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* 微微閃光掃過，吸睛但唔搶 */
.pc-promo-label::after {
    content: '';
    position: absolute;
    top: 0;
    left: -65%;
    width: 45%;
    height: 100%;
    background: linear-gradient(120deg, transparent, rgba(255, 255, 255, .55), transparent);
    transform: skewX(-20deg);
    animation: pcPromoShine 3.4s ease-in-out infinite;
    pointer-events: none;
}
@keyframes pcPromoShine {
    0%, 55%  { left: -65%; }
    100%     { left: 135%; }
}

/* 類型配色：一眼分得出邊種優惠 */
.pc-promo-label.pc-promo-gift     { background: linear-gradient(135deg, #ec4899, #ef4444); box-shadow: 0 2px 7px rgba(236, 72, 153, .3); }
.pc-promo-label.pc-promo-flash    { background: linear-gradient(135deg, #f59e0b, #ef4444); box-shadow: 0 2px 7px rgba(245, 158, 11, .32); }
.pc-promo-label.pc-promo-discount { background: linear-gradient(135deg, #f97316, #e11d48); }
.pc-promo-label.pc-promo-bundle   { background: linear-gradient(135deg, #8b5cf6, #6366f1); box-shadow: 0 2px 7px rgba(139, 92, 246, .3); }
.pc-promo-label.pc-promo-shipping { background: linear-gradient(135deg, #0ea5e9, #2563eb); box-shadow: 0 2px 7px rgba(14, 165, 233, .3); }

/* 尊重使用者「減少動態」偏好 */
@media (prefers-reduced-motion: reduce) {
    .pc-promo-label::after { animation: none; display: none; }
}

/* ══════════════════════════════════════════════
   產品卡片 - 加入購物車按鈕
   ══════════════════════════════════════════════ */
.pc-add-cart-btn {
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 8px 12px;
    border-radius: 10px;
    border: none;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}
.product-card:hover .pc-add-cart-btn {
    background: var(--primary);
    color: #fff;
}
.pc-add-cart-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

/* ══════════════════════════════════════════════
   動畫
   ══════════════════════════════════════════════ */
@keyframes pcFadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: none; }
}
@keyframes pcSpin {
    to { transform: rotate(360deg); }
}

.fade-in {
    animation: pcFadeIn .5s ease both;
}
.stagger-1 { animation-delay: .05s; }
.stagger-2 { animation-delay: .10s; }
.stagger-3 { animation-delay: .15s; }
.stagger-4 { animation-delay: .20s; }
.stagger-5 { animation-delay: .25s; }
.stagger-6 { animation-delay: .30s; }
.stagger-7 { animation-delay: .35s; }
.stagger-8 { animation-delay: .40s; }

/* ══════════════════════════════════════════════
   RWD 響應式
   ══════════════════════════════════════════════ */
@media (max-width: 768px) {
    .products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    .products-grid-4 {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    .pc-info {
        padding: 10px 12px 14px;
    }
    .pc-name {
        font-size: 13px;
    }
    .pc-price-now {
        font-size: 15px;
    }
}

@media (max-width: 480px) {
    .products-grid,
    .products-grid-4 {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
}
/* ── [QTY DISCOUNT] 數量折扣階梯 ── */
.pi-qty-discount {
    margin: 12px 0;
    border: 1px solid #e8f5e9;
    border-radius: 10px;
    overflow: hidden;
    background: #f6fbf6;
}
.pi-qty-discount-title {
    font-size: 13px;
    font-weight: 700;
    padding: 8px 14px;
    background: #e8f5e9;
    color: #2e7d32;
}
.pi-qty-discount-tiers {
    padding: 6px 14px 10px;
}
.pi-qty-tier {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 13px;
    transition: background 0.2s, box-shadow 0.2s;
}
.pi-qty-tier + .pi-qty-tier {
    border-top: 1px dashed #c8e6c9;
}
.pi-qty-tier.active {
    background: #c8e6c9;
    font-weight: 600;
    box-shadow: inset 3px 0 0 #43a047;
}
.pi-qty-tier .tier-qty {
    min-width: 60px;
    font-weight: 600;
    color: #2e7d32;
}
.pi-qty-tier .tier-discount {
    flex: 1;
    color: #d32f2f;
}
.pi-qty-tier .tier-unit-price {
    font-size: 12px;
    color: var(--text-light);
    white-space: nowrap;
}

/* ══════════════════════════════════════════════
   產品卡片風格(後台「主題設定 → 版面 → 商品卡片風格」)
   由 includes/components/product-card.php 加上 .pc-style-* class,
   全站共用,所有模版一齊生效。default 無額外規則,維持原狀。
   ══════════════════════════════════════════════ */

/* Hover：平時收起「加入購物車」按鈕,懸停先浮現(觸控裝置維持顯示) */
.product-card.pc-style-hover .pc-add-cart-btn {
    opacity: 0;
    transform: translateY(6px);
    transition: opacity .25s ease, transform .25s ease;
}
.product-card.pc-style-hover:hover .pc-add-cart-btn {
    opacity: 1;
    transform: none;
}
@media (hover: none) {
    .product-card.pc-style-hover .pc-add-cart-btn {
        opacity: 1;
        transform: none;
    }
}

/* 極簡：大圖小字,隱藏品牌/額外標籤,保留價格與購買按鈕 */
.product-card.pc-style-minimal .pc-brand {
    display: none;
}
.product-card.pc-style-minimal .pc-name {
    font-size: .85rem;
    font-weight: 500;
}
.product-card.pc-style-minimal .pc-info {
    gap: 4px;
}

/* 詳細：加細框與陰影,放大價格,按鈕長駐顯示 */
.product-card.pc-style-detailed {
    border: 1px solid var(--border, #e2e8f0);
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(0,0,0,.05));
}
.product-card.pc-style-detailed .pc-price-now {
    font-size: 1.05rem;
    font-weight: 700;
}
.product-card.pc-style-detailed .pc-add-cart-btn {
    opacity: 1;
}

/* ══════════════════════════════════════════════
   快速預覽 / 商品比較(全部模版通用)
   按鈕由 includes/components/product-card.php 喺對應開關開咗先輸出;
   顏色用 CSS 變數,會自動跟每個模版主色。
   ══════════════════════════════════════════════ */

/* 卡片右上角動作按鈕(位置需要 .product-card 為 relative;badge 喺 .pc-image 內,不受影響) */
.product-card { position: relative; }
.pc-actions {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 3;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity .2s ease, transform .2s ease;
}
.product-card:hover .pc-actions { opacity: 1; transform: none; }
@media (hover: none) {
    .pc-actions { opacity: 1; transform: none; }
}
.pc-action {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: #fff;
    color: var(--text, #1e293b);
    box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: background .2s ease, color .2s ease;
}
.pc-action:hover { background: var(--primary, #0d9488); color: #fff; }
.pc-action svg { width: 18px; height: 18px; }
.pc-compare-btn.active { background: var(--primary, #0d9488); color: #fff; }

/* 快速預覽 modal */
.qv-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.qv-overlay[hidden] { display: none; }
.qv-box {
    background: #fff;
    border-radius: var(--radius, 12px);
    width: 100%;
    max-width: 760px;
    max-height: 88vh;
    overflow: auto;
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
}
.qv-close {
    position: absolute;
    top: 8px;
    right: 12px;
    border: none;
    background: transparent;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    color: #64748b;
    z-index: 2;
}
.qv-media { background: #f8fafc; display: flex; align-items: center; justify-content: center; }
.qv-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.qv-info { padding: 28px 24px; }
.qv-brand { font-size: 12px; color: var(--text-light, #94a3b8); margin-bottom: 6px; }
.qv-name { font-size: 20px; font-weight: 600; margin: 0 0 12px; color: var(--text, #1e293b); }
.qv-priceline { margin-bottom: 14px; }
.qv-price { font-size: 20px; font-weight: 700; color: var(--price, #ef4444); }
.qv-orig { font-size: 14px; color: var(--text-light, #94a3b8); text-decoration: line-through; margin-left: 8px; }
.qv-desc { font-size: 14px; color: var(--text-mid, #475569); line-height: 1.6; margin-bottom: 18px; }
.qv-actions { margin-bottom: 12px; }
.qv-btn {
    display: block;
    width: 100%;
    box-sizing: border-box;
    text-align: center;
    padding: 13px 24px;
    border: none;
    border-radius: var(--radius, 12px);
    background: var(--btn-bg, var(--primary, #0d9488));
    color: var(--btn-text, #fff);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: filter .2s ease;
}
.qv-btn:hover { filter: brightness(.94); }
.qv-status { color: var(--text-light, #94a3b8); font-weight: 600; }
.qv-full {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    box-sizing: border-box;
    padding: 12px 24px;
    border: 1.5px solid var(--primary, #0d9488);
    border-radius: var(--radius, 12px);
    background: #fff;
    color: var(--primary, #0d9488);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: background .2s ease, color .2s ease;
}
.qv-full::after {
    content: "→";
    font-size: 15px;
    line-height: 1;
    transition: transform .2s ease;
}
.qv-full:hover {
    background: var(--primary, #0d9488);
    color: #fff;
}
.qv-full:hover::after { transform: translateX(3px); }
@media (max-width: 640px) {
    .qv-box { grid-template-columns: 1fr; }
    .qv-media { max-height: 240px; }
}

/* 比較 floating bar */
.compare-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9998;
    background: #fff;
    box-shadow: 0 -2px 14px rgba(0, 0, 0, .12);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    flex-wrap: wrap;
}
.compare-bar[hidden] { display: none; }
.cmp-bar-label { font-weight: 600; color: var(--text, #1e293b); }
.cmp-bar-view {
    padding: 9px 22px;
    border-radius: var(--radius, 12px);
    background: var(--btn-bg, var(--primary, #0d9488));
    color: var(--btn-text, #fff);
    text-decoration: none;
    font-weight: 600;
}
.cmp-bar-clear {
    border: 1px solid var(--border, #e2e8f0);
    background: #fff;
    color: var(--text-mid, #475569);
    padding: 8px 16px;
    border-radius: var(--radius, 12px);
    cursor: pointer;
}

/* 比較頁表格 */
.compare-page { padding: 24px 0 80px; }
.compare-title { font-size: 24px; font-weight: 700; margin: 12px 0 20px; }
.compare-empty { text-align: center; padding: 60px 0; color: var(--text-mid, #475569); }
.compare-empty .btn-primary {
    display: inline-block;
    margin-top: 16px;
    padding: 12px 26px;
    border-radius: var(--radius, 12px);
    background: var(--btn-bg, var(--primary, #0d9488));
    color: var(--btn-text, #fff);
    text-decoration: none;
}
.compare-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
.compare-table {
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
    margin: 0 auto;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: var(--radius, 12px);
    overflow: hidden;
}
.compare-table th,
.compare-table td {
    border-bottom: 1px solid var(--border, #e2e8f0);
    border-right: 1px solid var(--border, #e2e8f0);
    padding: 14px 16px;
    text-align: center;
    vertical-align: middle;
    font-size: 14px;
    width: 240px;
}
.compare-table tr:last-child th,
.compare-table tr:last-child td { border-bottom: none; }
.compare-table th:last-child,
.compare-table td:last-child { border-right: none; }
.compare-rowhead {
    background: var(--bg, #f8fafc);
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
    width: 120px;
    color: var(--text, #1e293b);
}
/* 斑馬間色,易睇 */
.compare-table tbody tr:nth-child(even) td { background: #fafbfc; }

.compare-row-product td { position: relative; vertical-align: top; padding-top: 18px; }
.compare-img { display: flex; justify-content: center; }
.compare-img img {
    width: 100%;
    max-width: 160px;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 10px;
    background: var(--bg, #f8fafc);
}
.compare-name {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-top: 12px;
    min-height: 2.8em;
    font-weight: 600;
    line-height: 1.4;
    color: var(--text, #1e293b);
    text-decoration: none;
}
.compare-name:hover { color: var(--primary, #0d9488); }
.compare-price { color: var(--price, #ef4444); font-weight: 700; font-size: 16px; }
.compare-original { text-decoration: line-through; color: var(--text-light, #94a3b8); }
.compare-instock { color: #10b981; font-weight: 600; }
.compare-oos { color: #ef4444; font-weight: 600; }
.compare-sku { color: var(--text-mid, #475569); font-size: 13px; }
.compare-desc {
    text-align: left;
    vertical-align: top;
    color: var(--text-mid, #475569);
    line-height: 1.6;
    font-size: 13px;
}
.compare-remove {
    position: absolute;
    top: 6px;
    right: 8px;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, .9);
    box-shadow: 0 1px 4px rgba(0, 0, 0, .12);
    font-size: 18px;
    line-height: 1;
    color: #64748b;
    cursor: pointer;
    transition: background .2s ease, color .2s ease;
}
.compare-remove:hover { background: #ef4444; color: #fff; }
.compare-cart-btn {
    display: inline-block;
    width: 100%;
    box-sizing: border-box;
    padding: 11px 16px;
    border: none;
    border-radius: var(--radius, 12px);
    background: var(--btn-bg, var(--primary, #0d9488));
    color: var(--btn-text, #fff);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    transition: filter .2s ease;
}
.compare-cart-btn:hover { filter: brightness(.94); }
.compare-cart-view { background: #64748b; }

@media (max-width: 640px) {
    .compare-table th,
    .compare-table td { width: 160px; padding: 12px 10px; }
    .compare-rowhead { width: 84px; font-size: 13px; }
    .compare-img img { max-width: 110px; }
}