/**
 * Kannan Product Grid (KP) - Scoped Stylesheet
 * Strictly scoped under .kp-product-grid to prevent any global leakage.
 */

.kp-product-grid {
    position: relative;
    width: 100%;
    margin-bottom: 40px;
    font-family: inherit;
}

/* ============================================================
   1. SECTION HEADING BLOCK (Title, Subtitle, Separator)
   ============================================================ */
.kp-product-grid .kp-heading-block {
    position: relative;
    width: 100%;
    margin-bottom: 20px;
}

.kp-product-grid .kp-heading-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.kp-product-grid .kp-section-title {
    font-size: 26px;
    font-weight: 800;
    line-height: 1.3;
    color: #1a1a1a;
    margin: 0;
    letter-spacing: -0.3px;
    display: block;
    word-break: break-word;
}

/* Disable old absolute pseudo-element that overlapped subtitle */
.kp-product-grid .kp-section-title::after {
    display: none !important;
    content: none !important;
}

.kp-product-grid .kp-section-desc {
    font-size: 14px;
    color: #6b7280;
    margin: 0;
    line-height: 1.5;
    word-break: break-word;
}

/* Responsive Underline / Separator in Normal Document Flow */
.kp-product-grid .kp-heading-separator {
    position: relative;
    width: 100%;
    height: 2px;
    background-color: #f1f3f5;
    border-radius: 2px;
    margin-top: 14px;
    margin-bottom: 0;
    overflow: hidden;
}

.kp-product-grid .kp-separator-accent {
    position: absolute;
    top: 0;
    left: 0;
    width: 60px;
    height: 100%;
    background-color: #c9151b;
    border-radius: 2px;
}

/* ============================================================
   2. CATEGORY NAVIGATION (HORIZONTALLY SCROLLABLE ROW)
   ============================================================ */
.kp-product-grid .kp-category-nav-wrapper {
    position: relative;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    margin-top: 18px;
    margin-bottom: 24px;
}

.kp-product-grid .kp-category-tabs {
    display: flex;
    flex-wrap: nowrap; /* Single horizontal row, NO wrapping */
    align-items: center;
    gap: 8px;
    list-style: none;
    margin: 0;
    padding: 4px 2px 10px 2px;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
    cursor: grab;
}

.kp-product-grid .kp-category-tabs:active {
    cursor: grabbing;
}

/* Visually hide scrollbar */
.kp-product-grid .kp-category-tabs::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

.kp-product-grid .kp-category-tab {
    flex: 0 0 auto; /* Never shrink */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 18px;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
    color: #4b5563;
    background-color: #f3f4f6;
    border: 1px solid transparent;
    border-radius: 25px;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    user-select: none;
    white-space: nowrap;
}

.kp-product-grid .kp-category-tab:hover {
    background-color: #e5e7eb;
    color: #111827;
}

.kp-product-grid .kp-category-tab.active {
    background-color: #c9151b;
    color: #ffffff;
    border-color: #c9151b;
    box-shadow: 0 2px 6px rgba(201, 21, 27, 0.25);
}

.kp-product-grid .kp-header-view-all {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    font-weight: 700;
    color: #c9151b;
    text-decoration: none;
    margin-top: 10px;
    padding: 6px 12px;
    border-radius: 6px;
    transition: color 0.2s ease, transform 0.2s ease;
}

.kp-product-grid .kp-header-view-all:hover {
    color: #991014;
    transform: translateX(2px);
}

/* ============================================================
   3. PRODUCT GRID CONTAINER (Real Responsive CSS Grid)
   ============================================================ */
.kp-product-grid .kp-grid-wrapper {
    display: grid;
    grid-template-columns: repeat(var(--kp-desktop-cols, 5), minmax(0, 1fr));
    gap: 16px;
    width: 100%;
    margin-left: 0;
    margin-right: 0;
    position: relative;
    box-sizing: border-box;
}

/* Fallback class selectors for Desktop columns */
.kp-product-grid .kp-grid-wrapper.kp-col-3 { --kp-desktop-cols: 3; }
.kp-product-grid .kp-grid-wrapper.kp-col-4 { --kp-desktop-cols: 4; }
.kp-product-grid .kp-grid-wrapper.kp-col-5 { --kp-desktop-cols: 5; }
.kp-product-grid .kp-grid-wrapper.kp-col-6 { --kp-desktop-cols: 6; }

.kp-product-grid .kp-grid-item {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0; /* Prevents overflow inside CSS grid cells */
    padding: 0;
    display: flex;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.kp-product-grid .kp-grid-item.kp-hidden {
    display: none !important;
}

/* Tablet Breakpoint (576px - 1024px) */
@media screen and (min-width: 576px) and (max-width: 1024px) {
    .kp-product-grid .kp-grid-wrapper {
        grid-template-columns: repeat(var(--kp-tablet-cols, 3), minmax(0, 1fr));
    }
    .kp-product-grid .kp-grid-wrapper.kp-tab-col-2 { --kp-tablet-cols: 2; }
    .kp-product-grid .kp-grid-wrapper.kp-tab-col-3 { --kp-tablet-cols: 3; }
    .kp-product-grid .kp-grid-wrapper.kp-tab-col-4 { --kp-tablet-cols: 4; }
    .kp-product-grid .kp-grid-wrapper.kp-tab-col-5 { --kp-tablet-cols: 5; }

    .kp-product-grid .kp-category-tab {
        padding: 7px 15px;
        font-size: 12px;
    }
}

/* Mobile Breakpoint (< 576px) */
@media screen and (max-width: 575px) {
    .kp-product-grid .kp-grid-wrapper {
        grid-template-columns: repeat(var(--kp-mobile-cols, 2), minmax(0, 1fr));
        gap: 12px;
    }
    .kp-product-grid .kp-grid-wrapper.kp-mob-col-1 { --kp-mobile-cols: 1; }
    .kp-product-grid .kp-grid-wrapper.kp-mob-col-2 { --kp-mobile-cols: 2; }
    .kp-product-grid .kp-grid-wrapper.kp-mob-col-3 { --kp-mobile-cols: 3; }

    .kp-product-grid .kp-section-title {
        font-size: 20px;
    }
    .kp-product-grid .kp-section-desc {
        font-size: 13px;
    }
    .kp-product-grid .kp-category-nav-wrapper {
        margin-top: 14px;
        margin-bottom: 18px;
    }
    .kp-product-grid .kp-category-tab {
        padding: 6px 14px;
        font-size: 12px;
    }
}

/* ============================================================
   4. PRODUCT CARD STYLING
   ============================================================ */
.kp-product-grid .kp-card {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    background-color: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 12px;
    box-sizing: border-box;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
}

.kp-product-grid .kp-card:hover {
    border-color: #d1d5db;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.07);
    transform: translateY(-3px);
}

/* Badges */
.kp-product-grid .kp-badge-wrapper {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 4;
    display: flex;
    flex-direction: column;
    gap: 4px;
    pointer-events: none;
}

.kp-product-grid .kp-badge {
    display: inline-block;
    padding: 3px 7px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    border-radius: 4px;
    line-height: 1.2;
}

.kp-product-grid .kp-badge-sale {
    background-color: #c9151b;
    color: #ffffff;
}

.kp-product-grid .kp-badge-hot {
    background-color: #f59e0b;
    color: #ffffff;
}

/* Floating Action Buttons (Wishlist, Quickview, Compare) */
.kp-product-grid .kp-card-actions {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 4;
    display: flex;
    flex-direction: column;
    gap: 6px;
    opacity: 0;
    transform: translateX(6px);
    transition: all 0.2s ease;
}

.kp-product-grid .kp-card:hover .kp-card-actions {
    opacity: 1;
    transform: translateX(0);
}

.kp-product-grid .kp-action-btn {
    width: 32px;
    height: 32px;
    background-color: #ffffff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
    color: #4b5563;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s ease;
    border: none;
    text-decoration: none;
}

.kp-product-grid .kp-action-btn:hover {
    background-color: #c9151b;
    color: #ffffff;
}

/* Thumbnail */
.kp-product-grid .kp-thumbnail-wrapper {
    position: relative;
    width: 100%;
    padding-top: 100%; /* 1:1 Aspect Ratio container */
    background-color: #fcfcfc;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 12px;
}

.kp-product-grid .kp-thumbnail-link {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kp-product-grid .kp-thumbnail-img {
    max-width: 88%;
    max-height: 88%;
    width: auto;
    height: auto;
    object-fit: contain;
    transition: transform 0.3s ease;
}

.kp-product-grid .kp-card:hover .kp-thumbnail-img {
    transform: scale(1.05);
}

/* Card Content */
.kp-product-grid .kp-card-content {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.kp-product-grid .kp-card-category {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: #9ca3af;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kp-product-grid .kp-card-title {
    font-size: 13px;
    font-weight: 700;
    line-height: 1.35;
    margin: 0 0 6px 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    height: 35px; /* Stable 2-line height */
}

.kp-product-grid .kp-card-title a {
    color: #1f2937;
    text-decoration: none;
    transition: color 0.15s ease;
}

.kp-product-grid .kp-card-title a:hover {
    color: #c9151b;
}

/* Ratings */
.kp-product-grid .kp-rating-wrapper {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 8px;
    font-size: 12px;
    height: 16px;
}

.kp-product-grid .kp-star-rating {
    color: #f59e0b;
    letter-spacing: 1px;
    display: inline-flex;
    align-items: center;
}

.kp-product-grid .kp-review-count {
    font-size: 11px;
    color: #9ca3af;
    font-weight: 500;
}

/* Price Block */
.kp-product-grid .kp-price-wrapper {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 12px;
    margin-top: auto; /* Push down to align with button */
}

.kp-product-grid .kp-price-wrapper .price {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.kp-product-grid .kp-price-wrapper ins,
.kp-product-grid .kp-sale-price {
    font-size: 15px;
    font-weight: 800;
    color: #c9151b;
    text-decoration: none;
}

.kp-product-grid .kp-price-wrapper del,
.kp-product-grid .kp-regular-price {
    font-size: 12px;
    font-weight: 500;
    color: #9ca3af;
}

/* Add to Cart Button */
.kp-product-grid .kp-card-footer {
    width: 100%;
    margin-top: 4px;
}

.kp-product-grid .kp-add-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 8px 12px;
    background-color: #111827;
    color: #ffffff;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    text-decoration: none;
    box-sizing: border-box;
    transition: all 0.2s ease;
}

.kp-product-grid .kp-add-btn:hover {
    background-color: #c9151b;
    color: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(201, 21, 27, 0.25);
}

.kp-product-grid .kp-add-btn.loading {
    opacity: 0.75;
    pointer-events: none;
}

.kp-product-grid .kp-add-btn.added::after {
    content: ' ✓';
    font-weight: 800;
}

/* Kannan Product Grid - Hide WooCommerce View Cart anchor */
.kp-product-grid .kp-card-footer a.added_to_cart {
    display: none !important;
}

/* ============================================================
   7. VIEW MORE / LOAD MORE BUTTON & SPINNER
   ============================================================ */
.kp-product-grid .kp-view-more-wrap {
    width: 100%;
    margin-top: 35px;
    margin-bottom: 15px;
    text-align: center;
    position: relative;
    clear: both;
}

.kp-product-grid .kp-view-more-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 190px;
    padding: 12px 36px;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.3px;
    color: #ffffff;
    background-color: #c9151b;
    border: 2px solid transparent;
    border-radius: 50px;
    cursor: pointer;
    box-sizing: border-box;
    box-shadow: 0 4px 14px rgba(201, 21, 27, 0.25);
    transition: all 0.25s ease;
    user-select: none;
    outline: none;
}

.kp-product-grid .kp-view-more-btn:hover {
    background-color: #a80f14;
    color: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(201, 21, 27, 0.35);
}

.kp-product-grid .kp-view-more-btn:active {
    transform: translateY(0);
}

.kp-product-grid .kp-view-more-btn.kp-loading {
    opacity: 0.85;
    pointer-events: none;
    cursor: wait;
}

.kp-product-grid .kp-view-more-btn.kp-no-more {
    background-color: #f3f4f6;
    color: #9ca3af;
    border-color: #e5e7eb;
    box-shadow: none;
    cursor: default;
    pointer-events: none;
    transform: none;
}

/* Spinner */
.kp-product-grid .kp-btn-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-radius: 50%;
    border-top-color: #ffffff;
    animation: kp-spin 0.8s linear infinite;
}

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

/* Grid smooth loading and transitions */
.kp-product-grid .kp-grid-wrapper {
    position: relative;
    transition: opacity 0.25s ease;
}

.kp-product-grid .kp-grid-wrapper.kp-grid-loading {
    opacity: 0.5;
    pointer-events: none;
}

.kp-product-grid .kp-grid-item.kp-fade-in {
    animation: kpCardFadeIn 0.35s ease forwards;
}

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