/**
 * KKTC Auto Inject Styles
 *
 * Styles for auto-injected recommendation widgets on product pages.
 * Compatible with Woodmart theme and WooCommerce.
 *
 * @package KKTC_Smart_Recommendation
 */

/* ==========================================================================
   Section Wrapper
   ========================================================================== */

.kktc-auto-inject-section {
    margin: 2rem 0;
    padding: 1.5rem 0;
    clear: both;
}

.kktc-section-title {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 15px;
    color: #333;
    text-align: left;
    padding-bottom: 10px;
    border-bottom: 2px solid #e5e7eb;
}

/* ==========================================================================
   Skeleton Loading Animation
   ========================================================================== */

.kktc-skeleton-loader {
    padding: 10px 0;
}

.kktc-skeleton-bundle,
.kktc-skeleton-carousel,
.kktc-skeleton-grid {
    display: flex;
    gap: 15px;
    align-items: center;
}

.kktc-skeleton-grid {
    flex-wrap: wrap;
}

.kktc-skeleton-card {
    width: 181px;
    height: 260px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: kktc-skeleton-pulse 1.5s ease-in-out infinite;
    border-radius: 8px;
    flex-shrink: 0;
}

.kktc-skeleton-plus {
    font-size: 2rem;
    color: #ccc;
    flex-shrink: 0;
}

@keyframes kktc-skeleton-pulse {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ==========================================================================
   FBTG Bundle (Amazon-style)
   ========================================================================== */

.kktc-fbtg-bundle {
    /* Intentionally blank - structured by child elements */
}

.kktc-fbtg-products {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.kktc-fbtg-product-thumb {
    width: 140px;
    height: 140px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
    background: #f8f9fa;
    flex-shrink: 0;
}

.kktc-fbtg-product-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.kktc-fbtg-plus,
.kktc-fbtg-equals {
    font-size: 1.8rem;
    font-weight: 300;
    color: #999;
    flex-shrink: 0;
}

.kktc-fbtg-action {
    display: flex;
    align-items: center;
    gap: 10px;
}

.kktc-fbtg-total {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.kktc-fbtg-total-label {
    font-size: 12px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.kktc-fbtg-total-price {
    font-size: 20px;
    font-weight: 700;
    color: #1e1e1e;
}

/* FBTG Summary - Checkbox list */
.kktc-fbtg-summary {
    border-top: 1px solid #e5e7eb;
    padding-top: 15px;
}

.kktc-fbtg-checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
    color: #333;
}

.kktc-fbtg-checkbox-label:last-of-type {
    border-bottom: none;
}

/* Hide native checkbox */
.kktc-fbtg-checkbox {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

/* Custom checkbox */
.kktc-fbtg-checkbox-custom {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #ccc;
    border-radius: 4px;
    flex-shrink: 0;
    position: relative;
    transition: all 0.2s;
}

.kktc-fbtg-checkbox:checked + .kktc-fbtg-checkbox-custom {
    background: #FF6B35;
    border-color: #FF6B35;
}

.kktc-fbtg-checkbox:checked + .kktc-fbtg-checkbox-custom::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 2px;
    width: 6px;
    height: 10px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.kktc-fbtg-checkbox:disabled + .kktc-fbtg-checkbox-custom {
    opacity: 0.6;
    cursor: not-allowed;
}

.kktc-fbtg-product-name {
    flex: 1;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.kktc-fbtg-product-price {
    font-weight: 600;
    white-space: nowrap;
    color: #1e1e1e;
}

.kktc-fbtg-main-badge {
    font-size: 11px;
    background: #e5e7eb;
    color: #666;
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

/* Add all to cart button */
.kktc-fbtg-add-all {
    display: block;
    width: 100%;
    padding: 12px 20px;
    margin-top: 15px;
    background: #FF6B35;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    text-align: center;
}

.kktc-fbtg-add-all:hover {
    background: #e55a28;
}

.kktc-fbtg-add-all.loading {
    position: relative;
    color: transparent;
    pointer-events: none;
}

.kktc-fbtg-add-all.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: kktc-skeleton-spin 0.8s linear infinite;
}

.kktc-fbtg-add-all.added {
    background: #2ecc71;
    color: #fff;
}

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

/* ==========================================================================
   Cross-sell / Also Viewed Carousel
   - Reuses .kktc-product-carousel styles from shortcodes inline CSS
   - These are fallback/override styles for auto-inject context
   ========================================================================== */

.kktc-auto-inject-section .kktc-product-carousel {
    width: 100%;
}

.kktc-auto-inject-section .kktc-product-carousel .kktc-swiper {
    width: 100%;
    height: auto;
    position: relative;
}

.kktc-auto-inject-section .swiper-slide.kktc-product-item {
    height: 305px;
    width: 181px;
}

.kktc-auto-inject-section .kktc-product-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 305px;
    width: 181px;
}

.kktc-auto-inject-section .kktc-card-link {
    text-decoration: none;
    color: inherit;
    display: block;
    flex: 1;
}

.kktc-auto-inject-section .kktc-card-image {
    height: 170px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #f8f9fa;
}

.kktc-auto-inject-section .kktc-card-image img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    margin: 0 auto;
    display: block;
}

.kktc-auto-inject-section .kktc-card-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 10px;
}

.kktc-auto-inject-section .kktc-card-title {
    font-size: 14px;
    font-weight: 400;
    color: #454545;
    line-height: 1.4;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 40px;
}

.kktc-auto-inject-section .kktc-card-footer {
    padding: 0 10px;
    margin-top: auto;
    height: 40px;
    border-radius: 4px;
    margin: 4px;
    background: #F5F5F5;
    display: flex;
    align-items: center;
    box-sizing: border-box;
}

.kktc-auto-inject-section .kktc-card-footer.has-discount {
    background: #E3F5E1;
}

.kktc-auto-inject-section .kktc-card-price {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.kktc-auto-inject-section .kktc-price-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.kktc-auto-inject-section .kktc-price-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.kktc-auto-inject-section .kktc-regular-price {
    font-size: 12px;
    color: #757575;
    text-decoration: line-through;
}

.kktc-auto-inject-section .kktc-discount-percent {
    font-size: 10px;
    color: #008A0A;
    font-weight: 600;
    background: rgba(0,138,10,0.15);
    padding: 1px 4px;
    border-radius: 3px;
}

.kktc-auto-inject-section .kktc-sale-price {
    font-size: 14px;
    font-weight: 700;
    color: #008A0A;
}

.kktc-auto-inject-section .kktc-normal-price {
    font-size: 14px;
    font-weight: 700;
    color: #1e1e1e;
}

.kktc-auto-inject-section .kktc-add-to-cart {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.kktc-auto-inject-section .kktc-add-to-cart:hover {
    background: rgba(0,0,0,0.05);
}

/* Swiper navigation */
.kktc-auto-inject-section .swiper-button-next,
.kktc-auto-inject-section .swiper-button-prev {
    background: rgba(255,255,255,0.9);
    border: 1px solid #ddd;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    color: #333;
}

.kktc-auto-inject-section .swiper-button-next:after,
.kktc-auto-inject-section .swiper-button-prev:after {
    font-size: 12px;
    font-weight: bold;
}

.kktc-auto-inject-section .swiper-button-next:hover,
.kktc-auto-inject-section .swiper-button-prev:hover {
    background: #000;
    color: #fff;
    border-color: #000;
}

.kktc-auto-inject-section .swiper-pagination {
    position: relative;
    margin-top: 15px;
}

.kktc-auto-inject-section .swiper-pagination-bullet {
    background: #ddd;
    opacity: 1;
}

.kktc-auto-inject-section .swiper-pagination-bullet-active {
    background: #FF6B35;
}

/* ==========================================================================
   Upsell Grid
   ========================================================================== */

.kktc-upsell-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.kktc-upsell-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.3s ease;
}

.kktc-upsell-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.kktc-upsell-card .kktc-product-link {
    text-decoration: none;
    color: inherit;
    flex: 1;
}

.kktc-upsell-card .kktc-product-image {
    aspect-ratio: 1;
    background: #f8f9fa;
    overflow: hidden;
}

.kktc-upsell-card .kktc-product-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.kktc-upsell-card .kktc-product-info {
    padding: 12px;
    flex: 1;
}

.kktc-upsell-card .kktc-product-title {
    font-size: 14px;
    font-weight: 500;
    margin: 0 0 8px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: #333;
}

.kktc-upsell-card .kktc-product-price {
    font-size: 16px;
    font-weight: 700;
    color: #1e1e1e;
    display: block;
}

.kktc-upsell-card .kktc-product-price del {
    color: #999;
    font-size: 13px;
    font-weight: 400;
}

.kktc-upsell-card .kktc-product-price ins {
    text-decoration: none;
    color: #008A0A;
}

.kktc-grid-add-to-cart {
    display: block;
    text-align: center;
    padding: 10px;
    margin: 0 12px 12px;
    background: #333;
    color: #fff !important;
    border-radius: 4px;
    text-decoration: none !important;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.2s;
    border: none;
    cursor: pointer;
}

.kktc-grid-add-to-cart:hover {
    background: #555;
    color: #fff !important;
}

/* ==========================================================================
   Responsive - Tablet (768px)
   ========================================================================== */

@media (max-width: 768px) {
    .kktc-section-title {
        font-size: 18px;
    }

    /* FBTG */
    .kktc-fbtg-product-thumb {
        width: 100px;
        height: 100px;
    }

    .kktc-fbtg-plus,
    .kktc-fbtg-equals {
        font-size: 1.4rem;
    }

    .kktc-fbtg-total-price {
        font-size: 18px;
    }

    /* Carousel */
    .kktc-auto-inject-section .swiper-slide.kktc-product-item {
        width: 165px;
        height: 280px;
    }

    .kktc-auto-inject-section .kktc-product-card {
        width: 165px;
        height: 280px;
    }

    .kktc-auto-inject-section .kktc-card-image {
        height: 150px;
    }

    /* Upsell Grid */
    .kktc-upsell-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Skeleton */
    .kktc-skeleton-card {
        width: 165px;
        height: 230px;
    }
}

/* ==========================================================================
   Responsive - Mobile (480px)
   ========================================================================== */

@media (max-width: 480px) {
    .kktc-auto-inject-section {
        margin: 1rem 0;
        padding: 1rem 0;
    }

    .kktc-section-title {
        font-size: 16px;
        margin-bottom: 10px;
    }

    /* FBTG */
    .kktc-fbtg-products {
        gap: 6px;
    }

    .kktc-fbtg-product-thumb {
        width: 80px;
        height: 80px;
    }

    .kktc-fbtg-plus,
    .kktc-fbtg-equals {
        font-size: 1.2rem;
    }

    .kktc-fbtg-total-price {
        font-size: 16px;
    }

    .kktc-fbtg-checkbox-label {
        font-size: 13px;
        gap: 8px;
    }

    .kktc-fbtg-add-all {
        font-size: 14px;
        padding: 10px 16px;
    }

    /* Carousel */
    .kktc-auto-inject-section .swiper-slide.kktc-product-item {
        width: 150px;
        height: 260px;
    }

    .kktc-auto-inject-section .kktc-product-card {
        width: 150px;
        height: 260px;
    }

    .kktc-auto-inject-section .kktc-card-image {
        height: 130px;
    }

    .kktc-auto-inject-section .kktc-card-title {
        font-size: 13px;
        min-height: 36px;
    }

    /* Upsell Grid */
    .kktc-upsell-grid {
        grid-template-columns: 1fr;
    }

    /* Skeleton */
    .kktc-skeleton-card {
        width: 150px;
        height: 200px;
    }
}
