/* Category Top Products - Modern Ranking Cards Styles */

/* CSS Variables - Applied globally */
:root {
    --ctp-primary-color: #DCACAC !important;
    --ctp-primary-dark: #C99999 !important;
    --ctp-primary-light: #E8BEBE !important;
    --ctp-primary-pale: #F4E6E6 !important;
}

/* Force colors on mobile */
body .ctp-ranking-cards-container,
.woocommerce .ctp-ranking-cards-container {
    --ctp-primary-color: #DCACAC !important;
    --ctp-primary-dark: #C99999 !important;
    --ctp-primary-light: #E8BEBE !important;
    --ctp-primary-pale: #F4E6E6 !important;
}

.ctp-ranking-cards-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin: 30px 0;
    max-width: 100%;
    order: 999; /* Force to appear after header content */
    z-index: 1;
    position: relative;
    clear: both;
}

/* Force positioning after various header elements */
.woocommerce-products-header + * .ctp-ranking-cards-container,
.page-header + * .ctp-ranking-cards-container,
.archive-header + * .ctp-ranking-cards-container,
.woocommerce-archive-description + .ctp-ranking-cards-container {
    margin-top: 40px !important;
}

/* Ranking Card Styles */
.ctp-ranking-card {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.ctp-ranking-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.ctp-ranking-card.ctp-card-expanded {
    border-color: var(--ctp-primary-color) !important;
    border-color: #DCACAC !important; /* Fallback */
}

/* Card Header */
.ctp-card-header {
    display: flex;
    align-items: center;
    padding: 20px 24px;
    cursor: pointer;
    position: relative;
    background: linear-gradient(90deg, rgba(220, 172, 172, 0.05) 0%, rgba(220, 172, 172, 0.08) 100%) !important;
}

.ctp-card-header:hover {
    background: linear-gradient(90deg, rgba(220, 172, 172, 0.1) 0%, rgba(220, 172, 172, 0.15) 100%) !important;
}

.ctp-card-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 16px;
    transition: all 0.3s ease;
}

/* Animated icon styling */
/* Animated icon styles */
.ctp-animated-icon {
    width: 24px;
    height: 24px;
    display: inline-block;
    filter: brightness(0) invert(1); /* Makes icon white */
    object-fit: contain;
}

/* CSS-based animated icons */
.ctp-animated-trophy {
    animation: trophy-glow 2s ease-in-out infinite alternate;
}

.ctp-animated-fire {
    animation: fire-flicker 1.5s ease-in-out infinite;
}

/* Trophy glow animation */
@keyframes trophy-glow {
    0% {
        filter: brightness(0) invert(1) drop-shadow(0 0 3px rgba(255, 255, 255, 0.5));
        transform: scale(1);
    }
    50% {
        filter: brightness(0) invert(1) drop-shadow(0 0 8px rgba(255, 255, 255, 0.8));
        transform: scale(1.05);
    }
    100% {
        filter: brightness(0) invert(1) drop-shadow(0 0 12px rgba(255, 255, 255, 1));
        transform: scale(1.1);
    }
}

/* Sparkle animation for trophy */
.ctp-sparkle {
    animation: sparkle 1.5s ease-in-out infinite;
    transform-origin: center;
}

@keyframes sparkle {
    0%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    50% {
        opacity: 1;
        transform: scale(1.2);
    }
}

/* Fire flicker animation */
@keyframes fire-flicker {
    0%, 100% {
        filter: brightness(0) invert(1);
        transform: scale(1) rotate(-1deg);
    }
    25% {
        filter: brightness(0) invert(1) drop-shadow(0 0 5px rgba(255, 255, 255, 0.6));
        transform: scale(1.02) rotate(1deg);
    }
    50% {
        filter: brightness(0) invert(1) drop-shadow(0 0 8px rgba(255, 255, 255, 0.8));
        transform: scale(1.05) rotate(-0.5deg);
    }
    75% {
        filter: brightness(0) invert(1) drop-shadow(0 0 6px rgba(255, 255, 255, 0.7));
        transform: scale(1.03) rotate(0.5deg);
    }
}

/* Fire inner flame animation */
.ctp-fire-inner {
    animation: inner-flame 1s ease-in-out infinite alternate;
}

@keyframes inner-flame {
    0% {
        opacity: 0.8;
    }
    100% {
        opacity: 1;
    }
}

/* Fire main flame animation */
.ctp-fire-main {
    animation: main-flame 2s ease-in-out infinite;
}

@keyframes main-flame {
    0%, 100% {
        transform: scaleY(1);
    }
    50% {
        transform: scaleY(1.02);
    }
}

.ctp-icon-trophy {
    background: linear-gradient(135deg, var(--ctp-primary-color), var(--ctp-primary-dark)) !important;
    color: white !important;
}

.ctp-icon-fire {
    background: linear-gradient(135deg, var(--ctp-primary-color), var(--ctp-primary-dark)) !important;
    color: white !important;
}

.ctp-card-title {
    font-size: 20px;
    font-weight: 700;
    color: #1e293b;
    margin: 0;
    flex-grow: 1;
    letter-spacing: -0.025em;
}

.ctp-card-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #64748b;
    font-weight: 500;
    font-size: 14px;
}

.ctp-toggle-arrow {
    width: 20px;
    height: 20px;
    transition: transform 0.3s ease;
    color: #94a3b8;
}

.ctp-ranking-card.ctp-card-expanded .ctp-toggle-arrow {
    transform: rotate(180deg);
}

/* Card Content */
.ctp-card-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.ctp-ranking-card.ctp-card-expanded .ctp-card-content {
    max-height: 1000px;
}

/* Loading Spinner */
.ctp-loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    color: #64748b;
    gap: 12px;
}

.ctp-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #e2e8f0;
    border-top: 3px solid #DCACAC !important;
    border-top: 3px solid var(--ctp-primary-color) !important;
    border-radius: 50%;
    animation: ctpSpin 1s linear infinite;
}

@keyframes ctpSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Badge Animations */
@keyframes ctpShake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-2px); }
    20%, 40%, 60%, 80% { transform: translateX(2px); }
}

@keyframes ctpBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

@keyframes ctpPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Products Grid */
.ctp-products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
    padding: 24px;
    background: var(--ctp-primary-pale);
}

/* Product Item Link (makes whole card clickable) */
.ctp-product-item-link {
    text-decoration: none;
    color: inherit;
    display: block;
    transition: all 0.3s ease;
}

.ctp-product-item-link:hover {
    text-decoration: none;
    color: inherit;
}

/* Product Item */
.ctp-product-item {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    transition: all 0.3s ease;
    position: relative;
    display: flex;
    flex-direction: row; /* Horizontal layout for rectangular cards */
    min-height: 160px; /* Increased height for better proportions */
    cursor: pointer;
}

.ctp-product-item-link:hover .ctp-product-item {
    transform: translateY(-4px);
    box-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* Rank Badge - Made Bigger */
.ctp-rank-badge {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 56px; /* Increased from 44px */
    height: 56px; /* Increased from 44px */
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 24px; /* Increased from 18px */
    z-index: 2;
    background: linear-gradient(135deg, #1e293b, #334155);
    color: white;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.ctp-rank-1 { 
    background: linear-gradient(135deg, var(--ctp-primary-color), var(--ctp-primary-dark)); 
    animation: ctpShake 2s infinite;
}
.ctp-rank-2 { 
    background: linear-gradient(135deg, #94a3b8, #64748b); 
    animation: ctpBounce 2s infinite;
}
.ctp-rank-3 { 
    background: linear-gradient(135deg, #cd7c2f, #a16207); 
    animation: ctpPulse 2s infinite;
}

/* Product Image - Adjusted for rectangular layout */
.ctp-product-image {
    width: 140px; /* Slightly wider for better proportions */
    min-width: 140px;
    height: 160px; /* Match card height */
    overflow: hidden;
    position: relative;
    background: #f8fafc;
    flex-shrink: 0;
}

.ctp-product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.ctp-product-item-link:hover .ctp-product-image img {
    transform: scale(1.05);
}

.ctp-no-image {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    background: linear-gradient(135deg, #f1f5f9, #e2e8f0);
}

/* Product Info - Optimized for rectangular layout */
.ctp-product-info {
    padding: 16px 20px; /* More generous padding */
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 8px; /* Slightly more space */
    justify-content: space-between;
    min-width: 0; /* Prevent overflow */
}

.ctp-product-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.3; /* Tighter line height */
    color: #1e293b;
    transition: color 0.2s ease;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2; /* Limit to 2 lines */
    line-clamp: 2; /* Standard property for compatibility */
    -webkit-box-orient: vertical;
}

.ctp-product-item-link:hover .ctp-product-title {
    color: var(--ctp-primary-dark);
}

.ctp-product-price {
    font-size: 18px; /* Slightly larger */
    font-weight: 700;
    color: var(--ctp-primary-dark);
    margin: 4px 0;
}

.ctp-product-price del {
    color: #94a3b8;
    font-weight: 400;
    font-size: 14px;
}

/* Rating */
.ctp-product-rating {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ctp-stars {
    display: flex;
    gap: 2px;
}

.ctp-star {
    color: var(--ctp-primary-color);
}

.ctp-star-empty {
    color: #e5e7eb;
}

.ctp-rating-count {
    font-size: 12px;
    color: #64748b;
    margin-left: 4px;
}

/* Metric Display - Enhanced for rectangular layout */
.ctp-product-metric {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px; /* Slightly more padding */
    border-radius: 8px;
    font-size: 14px; /* Slightly larger font */
    font-weight: 500;
    margin-top: auto;
    margin-bottom: 4px;
}

.ctp-metric-sales {
    background: linear-gradient(90deg, rgba(34, 197, 94, 0.1), rgba(22, 163, 74, 0.1));
    color: #166534;
    border: 1px solid rgba(34, 197, 94, 0.2);
}

.ctp-metric-viral {
    background: linear-gradient(90deg, rgba(239, 68, 68, 0.1), rgba(220, 38, 38, 0.1));
    color: #991b1b;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.ctp-metric-value {
    font-weight: 700;
    font-size: 16px; /* Larger number display */
}

/* Stock Status */
.ctp-stock-status {
    font-size: 12px;
    font-weight: 500;
    padding: 4px 8px;
    border-radius: 6px;
    text-align: center;
}

.ctp-out-of-stock {
    background: #f8fafc;
    color: #64748b;
    border: 1px solid #e2e8f0;
}

.ctp-low-stock {
    background: #fefbf2;
    color: #92400e;
    border: 1px solid #fed7aa;
}

/* Product Actions */
.ctp-product-actions {
    padding: 8px 12px 12px;
    align-self: flex-end;
}

.ctp-view-product-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 12px;
    background: linear-gradient(135deg, var(--ctp-primary-color), var(--ctp-primary-dark));
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 500;
    font-size: 12px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.ctp-view-product-btn:hover {
    background: linear-gradient(135deg, var(--ctp-primary-dark), var(--ctp-primary-color));
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(220, 172, 172, 0.3);
    color: white;
}

/* No Products Message */
.ctp-no-products {
    text-align: center;
    padding: 60px 24px;
    color: #64748b;
    font-size: 16px;
}

/* Responsive Design */
@media (max-width: 768px) {
    /* Ensure CSS variables are properly defined for mobile */
    :root {
        --ctp-primary-color: #DCACAC !important;
        --ctp-primary-dark: #C99999 !important;
        --ctp-primary-light: #E8BEBE !important;
        --ctp-primary-pale: #F4E6E6 !important;
    }
    
    .ctp-ranking-cards-container {
        margin: 20px 0;
        gap: 32px; /* Increased gap for better separation on mobile */
        position: relative;
        clear: both;
        /* Force positioning after header content */
        display: block !important;
    }
    
    /* Ensure cards appear after page header */
    .page-header + .ctp-ranking-cards-container,
    .woocommerce-archive-description + .ctp-ranking-cards-container,
    .term-description + .ctp-ranking-cards-container {
        margin-top: 30px;
    }
    
    /* Use lighter brand colors on mobile to match product cards */
    .ctp-card-header {
        background: var(--ctp-primary-pale) !important;
        color: #666 !important;
    }
    
    .ctp-expand-btn {
        background: #DCACAC !important;
        background: var(--ctp-primary-color) !important;
    }
    
    .ctp-expand-btn:hover {
        background: #C99999 !important;
        background: var(--ctp-primary-dark) !important;
    }
    
    .ctp-view-product-btn {
        background: linear-gradient(135deg, #DCACAC, #C99999) !important;
        background: linear-gradient(135deg, var(--ctp-primary-color), var(--ctp-primary-dark)) !important;
    }
    
    .ctp-view-product-btn:hover {
        background: linear-gradient(135deg, #C99999, #DCACAC) !important;
        background: linear-gradient(135deg, var(--ctp-primary-dark), var(--ctp-primary-color)) !important;
        box-shadow: 0 4px 8px rgba(220, 172, 172, 0.3) !important;
    }
    
    .ctp-rank-1 { 
        background: linear-gradient(135deg, #DCACAC, #C99999) !important;
        background: linear-gradient(135deg, var(--ctp-primary-color), var(--ctp-primary-dark)) !important;
    }
    
    .ctp-card-header {
        padding: 16px 20px;
    }
    
    .ctp-card-icon {
        width: 40px;
        height: 40px;
        margin-right: 12px;
    }
    
    .ctp-card-title {
        font-size: 18px;
    }
    
    .ctp-products-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 20px;
    }
    
    .ctp-product-item {
        min-height: 140px; /* Maintain rectangular proportions on mobile */
        flex-direction: row; /* Keep horizontal layout */
    }
    
    .ctp-product-image {
        width: 110px; /* Slightly larger for mobile */
        min-width: 110px;
        height: 140px;
    }
    
    .ctp-rank-badge {
        width: 48px; /* Bigger badges on mobile too */
        height: 48px;
        font-size: 20px; /* Larger font for mobile */
        top: 8px;
        left: 8px;
    }
    
    .ctp-product-info {
        padding: 12px 16px;
        gap: 6px;
    }
    
    .ctp-product-title {
        font-size: 15px; /* Slightly larger on mobile */
        line-height: 1.3;
    }
    
    .ctp-product-price {
        font-size: 16px; /* Keep price prominent */
    }
    
    .ctp-product-metric {
        padding: 8px 10px;
        font-size: 13px;
    }
    
    .ctp-metric-value {
        font-size: 15px; /* Keep numbers readable */
    }
}

@media (max-width: 480px) {
    .ctp-ranking-cards-container {
        gap: 40px; /* Even more separation on very small screens */
    }
    
    .ctp-products-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 16px;
    }
    
    .ctp-card-header {
        padding: 14px 16px;
    }
    
    .ctp-toggle-text {
        font-size: 12px;
    }
    
    .ctp-product-item {
        min-height: 110px;
    }
    
    .ctp-product-image {
        width: 90px;
        min-width: 90px;
        height: 110px;
    }
    
    .ctp-rank-badge {
        width: 32px;
        height: 32px;
        font-size: 14px;
        top: 4px;
        left: 4px;
    }
}