/**
 * 前台樣式：加價購區塊
 * 顏色透過 CSS 變數定義；主題 / 子主題可在 .wbt-buy-together-section 覆寫
 * 預設先嘗試吃 WordPress 6+ 全站樣式 token，若沒有則 fallback 到現有深色設計
 */

/* 主區塊 - 在產品內容後 */
.wbt-buy-together-section {
    /* === 主題色彩 tokens — 可由主題覆寫以套用品牌色 === */
    --wbt-bg:            var(--wp--preset--color--background, #4a3737);
    --wbt-text:          var(--wp--preset--color--foreground, #fff);
    --wbt-accent:        var(--wp--preset--color--primary, #ffeb3b);
    --wbt-text-muted:    rgba(255, 255, 255, 0.5);
    --wbt-card-bg:       rgba(255, 255, 255, 0.08);
    --wbt-card-bg-hover: rgba(255, 255, 255, 0.14);
    --wbt-card-border:   rgba(255, 255, 255, 0.18);
    --wbt-input-bg:      rgba(255, 255, 255, 0.92);
    --wbt-input-text:    #333;
    --wbt-image-bg:      #fff;

    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    border-radius: 12px;
    color: var(--wbt-text);
    clear: both;
    overflow: hidden;
}

.wbt-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--wbt-text);
    text-align: left;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--wbt-card-border);
}

/* 產品網格佈局 */
.wbt-products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
    width: 100%;
    box-sizing: border-box;
}

/* 產品卡片 */
.wbt-product-card {
    background: var(--wbt-card-bg);
    border: 1px solid var(--wbt-card-border);
    border-radius: 10px;
    padding: 15px;
    transition: all 0.3s ease;
    position: relative;
    min-height: 280px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

.wbt-product-card:hover {
    background: var(--wbt-card-bg-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}

/* 產品圖片 */
.wbt-card-image {
    margin-bottom: 12px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--wbt-image-bg);
    padding: 10px;
    flex-shrink: 0;
}

.wbt-card-image img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    display: block;
}

/* 產品內容區（右側） */
.wbt-card-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

/* 產品資訊 - 桌面版保持原樣式 */
.wbt-card-info {
    margin-bottom: 15px;
    flex-grow: 1;
}

.wbt-product-name {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--wbt-text);
    margin-bottom: 5px;
    line-height: 1.4;
    min-height: 40px;
}

.wbt-add-on-price {
    display: block;
    font-size: 16px;
    font-weight: 700;
    color: var(--wbt-accent);
}

.wbt-add-on-price .woocommerce-Price-amount {
    color: var(--wbt-accent);
}

.wbt-add-on-price del {
    color: var(--wbt-text-muted);
    font-size: 12px;
}

.wbt-add-on-price ins {
    color: var(--wbt-accent);
    text-decoration: none;
}

/* 數量控制 */
.wbt-product-card .wbt-quantity {
    margin: 0 auto 12px;
    display: flex;
    justify-content: center;
}

.wbt-product-card .wbt-quantity.buttons_added {
    display: inline-flex;
    align-items: center;
    background: transparent;
    border: 1px solid var(--wbt-card-border);
    border-radius: 4px;
    overflow: hidden;
}

.wbt-product-card .wbt-quantity.buttons_added .minus,
.wbt-product-card .wbt-quantity.buttons_added .plus {
    background: transparent;
    border: none;
    color: var(--wbt-text);
    width: 32px;
    height: 32px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.wbt-product-card .wbt-quantity.buttons_added .minus:hover,
.wbt-product-card .wbt-quantity.buttons_added .plus:hover {
    background: var(--wbt-card-bg-hover);
}

.wbt-product-card .wbt-quantity.buttons_added .qty,
.wbt-product-card .wbt-qty-input {
    width: 50px;
    text-align: center;
    background: transparent;
    border: none;
    border-left: 1px solid var(--wbt-card-border);
    border-right: 1px solid var(--wbt-card-border);
    color: var(--wbt-text);
    padding: 5px;
    height: 32px;
    -moz-appearance: textfield;
}

.wbt-product-card .wbt-quantity.buttons_added .qty::-webkit-outer-spin-button,
.wbt-product-card .wbt-quantity.buttons_added .qty::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* 變體選擇器 */
.wbt-variation-selector {
    margin-bottom: 12px;
}

.wbt-variation-select {
    width: 100%;
    padding: 8px 12px;
    font-size: 13px;
    border: 1px solid var(--wbt-card-border);
    border-radius: 6px;
    background: var(--wbt-input-bg);
    color: var(--wbt-input-text);
    cursor: pointer;
}

.wbt-variation-select:disabled {
    background: rgba(255, 255, 255, 0.5);
    cursor: not-allowed;
    opacity: 0.6;
}

/* 加入購物車按鈕 - 使用主題預設樣式 */
.wbt-product-card .wbt-add-to-cart-btn {
    width: 100%;
    margin-top: auto;
    padding-top: 8px !important;
    padding-right: 10px !important;
    padding-bottom: 8px !important;
    padding-left: 10px !important;
}

.wbt-product-card .wbt-add-to-cart-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.wbt-product-card .wbt-add-to-cart-btn.loading {
    pointer-events: none;
    opacity: 0.8;
}

/* 底部區域 - 隱藏總價，只保留按鈕（已移除） */
.wbt-footer {
    display: none;
}

/* 訊息（語意色保留 hardcode） */
.wbt-message {
    margin-top: 15px;
    padding: 12px 20px;
    border-radius: 6px;
    font-weight: 500;
    text-align: center;
}

.wbt-message-success {
    background: rgba(76, 175, 80, 0.9);
    color: #fff;
}

.wbt-message-error {
    background: rgba(244, 67, 54, 0.9);
    color: #fff;
}

/* 載入動畫 */
.wbt-add-to-cart.loading {
    position: relative;
    pointer-events: none;
    opacity: 0.8;
}

.wbt-add-to-cart.loading::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    top: 50%;
    left: 50%;
    margin-left: -10px;
    margin-top: -10px;
    border: 3px solid rgba(102, 126, 234, 0.3);
    border-top-color: #667eea;
    border-radius: 50%;
    animation: wbt-spin 0.8s linear infinite;
}

@keyframes wbt-spin {
    to {
        transform: rotate(360deg);
    }
}

/* === Horizontal 樣式（shortcode style="horizontal"）=== */
/* 每張卡片改成「圖左 + 文右」橫排，卡片本身仍走 grid 多欄排列 */
.wbt-buy-together-section[data-wbt-style="horizontal"] .wbt-product-card {
    flex-direction: row;
    align-items: stretch;
    gap: 12px;
    min-height: auto;
    padding: 12px;
}

.wbt-buy-together-section[data-wbt-style="horizontal"] .wbt-card-image {
    flex: 0 0 90px;
    width: 90px;
    height: 90px;
    margin: 0;
    padding: 5px;
    align-self: flex-start;
}

.wbt-buy-together-section[data-wbt-style="horizontal"] .wbt-card-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.wbt-buy-together-section[data-wbt-style="horizontal"] .wbt-card-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.wbt-buy-together-section[data-wbt-style="horizontal"] .wbt-product-name {
    min-height: auto;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.wbt-buy-together-section[data-wbt-style="horizontal"] .wbt-add-on-price,
.wbt-buy-together-section[data-wbt-style="horizontal"] .wbt-variation-selector {
    margin: 0;
}

.wbt-buy-together-section[data-wbt-style="horizontal"] .wbt-product-card .wbt-quantity {
    margin: 0;
    justify-content: flex-start;
}

.wbt-buy-together-section[data-wbt-style="horizontal"] .wbt-product-card .wbt-add-to-cart-btn {
    margin-top: auto;
}

/* 響應式設計 */
@media (max-width: 768px) {
    .wbt-products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .wbt-product-card {
        padding: 10px;
        min-height: 240px;
    }

    .wbt-card-image img {
        height: 80px;
    }

    .wbt-product-name {
        font-size: 12px;
        min-height: 34px;
    }

    .wbt-add-on-price {
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .wbt-buy-together-section {
        border-radius: 8px !important;
    }

    .wbt-buy-together-section .wbt-title {
        font-size: 16px !important;
        margin-bottom: 12px !important;
        padding-bottom: 10px !important;
    }

    .wbt-buy-together-section .wbt-products-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 0 !important;
        margin-bottom: 0 !important;
    }

    /* 手機版：圖片左側 + 內容右側垂直排列 */
    .wbt-buy-together-section .wbt-product-card {
        display: flex !important;
        flex-direction: row !important;
        align-items: flex-start !important;
        gap: 12px !important;
        padding: 12px 0 !important;
        min-height: auto !important;
        background: transparent !important;
        border: none !important;
        border-bottom: 1px solid var(--wbt-card-border) !important;
        border-radius: 0 !important;
    }

    .wbt-buy-together-section .wbt-product-card:last-child {
        border-bottom: none !important;
    }

    .wbt-buy-together-section .wbt-product-card:hover {
        background: transparent !important;
        transform: none !important;
        box-shadow: none !important;
    }

    /* 手機版圖片：左側固定 */
    .wbt-buy-together-section .wbt-card-image {
        flex: 0 0 70px !important;
        width: 70px !important;
        height: 70px !important;
        margin: 0 !important;
        padding: 5px !important;
        border-radius: 6px !important;
    }

    .wbt-buy-together-section .wbt-card-image img {
        width: 100% !important;
        height: 100% !important;
        object-fit: contain !important;
    }

    /* 手機版內容區：右側垂直排列 */
    .wbt-buy-together-section .wbt-card-content {
        flex: 1 !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 6px !important;
        margin: 0 !important;
    }

    .wbt-buy-together-section .wbt-product-name {
        font-size: 13px !important;
        min-height: auto !important;
        margin: 0 !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 2 !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
        line-height: 1.3 !important;
    }

    .wbt-buy-together-section .wbt-add-on-price {
        font-size: 14px !important;
        color: var(--wbt-accent) !important;
        margin: 0 !important;
    }

    .wbt-buy-together-section .wbt-add-on-price .woocommerce-Price-amount {
        color: var(--wbt-accent) !important;
    }

    .wbt-buy-together-section .wbt-add-on-price del {
        display: none !important;
    }

    .wbt-buy-together-section .wbt-add-on-price ins {
        text-decoration: none !important;
    }

    /* 手機版：隱藏數量選擇器 */
    .wbt-buy-together-section .wbt-quantity,
    .wbt-buy-together-section .wbt-product-card .wbt-quantity,
    .wbt-buy-together-section .wbt-product-card .quantity,
    .wbt-buy-together-section .quantity.buttons_added {
        display: none !important;
    }

    /* 手機版變體選擇器 */
    .wbt-buy-together-section .wbt-variation-selector {
        display: block !important;
        margin: 0 !important;
    }

    .wbt-buy-together-section .wbt-variation-select {
        width: 100% !important;
        padding: 8px 10px !important;
        font-size: 12px !important;
        border-radius: 4px !important;
        background: var(--wbt-input-bg) !important;
    }

    /* 手機版按鈕 */
    .wbt-buy-together-section .wbt-add-to-cart-btn {
        width: 100% !important;
        padding: 10px 12px !important;
        font-size: 13px !important;
        margin: 0 !important;
        background: transparent !important;
        border: 1px solid var(--wbt-accent) !important;
        color: var(--wbt-accent) !important;
        border-radius: 20px !important;
        text-align: center !important;
    }

    .wbt-buy-together-section .wbt-add-to-cart-btn:hover,
    .wbt-buy-together-section .wbt-add-to-cart-btn:active {
        background: var(--wbt-accent) !important;
        color: var(--wbt-bg) !important;
    }

    .wbt-buy-together-section .wbt-add-to-cart-btn:disabled {
        opacity: 0.6 !important;
        cursor: not-allowed !important;
        border-color: #999 !important;
        color: #999 !important;
    }
}

/* 產品名稱連結 */
a.wbt-product-name {
    text-decoration: none;
    color: var(--wbt-text);
    transition: color 0.2s ease;
}

a.wbt-product-name:hover {
    color: var(--wbt-accent);
}
