/* Product Grid - Modern Design */

/* CSS Variables */
:root {
    --pge-primary: #000;
    --pge-primary-hover: #333;
    --pge-secondary: #666;
    --pge-light: #f8f8f8;
    --pge-border: #e0e0e0;
    --pge-success: #4CAF50;
    --pge-danger: #e74c3c;
    --pge-radius: 12px;
    --pge-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Wrapper */
.pge-wrapper {
    position: relative;
}

/* Grid */
.pge-grid {
    display: grid;
    gap: 30px;
    width: 100%;
}

/* Grid Columns */
.pge-grid-1 .pge-grid { grid-template-columns: repeat(1, 1fr); }
.pge-grid-2 .pge-grid { grid-template-columns: repeat(2, 1fr); }
.pge-grid-3 .pge-grid { grid-template-columns: repeat(3, 1fr); }
.pge-grid-4 .pge-grid { grid-template-columns: repeat(4, 1fr); }
.pge-grid-5 .pge-grid { grid-template-columns: repeat(5, 1fr); }
.pge-grid-6 .pge-grid { grid-template-columns: repeat(6, 1fr); }

/* Responsive */
@media (max-width: 1024px) {
    .pge-grid-tablet-1 .pge-grid { grid-template-columns: repeat(1, 1fr); }
    .pge-grid-tablet-2 .pge-grid { grid-template-columns: repeat(2, 1fr); }
    .pge-grid-tablet-3 .pge-grid { grid-template-columns: repeat(3, 1fr); }
    .pge-grid-tablet-4 .pge-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 767px) {
    .pge-grid-mobile-1 .pge-grid { grid-template-columns: repeat(1, 1fr); }
    .pge-grid-mobile-2 .pge-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Product Item */
.pge-product-item {
    position: relative;
    background: #fff;
    overflow: hidden;
    transition: var(--pge-transition);
    border-radius: var(--pge-radius);
}

/* Out of stock items styling - ONLY apply to items with outofstock status */
.pge-product-item[data-stock-status="outofstock"] {
    opacity: 0.7;
}

.pge-product-item[data-stock-status="outofstock"] .pge-product-image::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.5);
    pointer-events: none;
    z-index: 1;
}

.pge-wrapper.has-hover-shadow .pge-product-item:hover {
    transform: translateY(-8px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

.pge-product-link {
    display: block;
    text-decoration: none;
    color: inherit;
}

/* Product Image */
.pge-product-image {
    position: relative;
    overflow: hidden;
    background: var(--pge-light);
}

.pge-product-image img {
    width: 100%;
    height: auto;
    display: block;
    transition: opacity 0.3s;
}

/* Eye Icon */
.pge-eye-icon {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 48px;
    height: 48px;
    background: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transform: scale(0.8) translateY(10px);
    transition: var(--pge-transition);
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.pge-product-item:hover .pge-eye-icon {
    opacity: 1;
    transform: scale(1) translateY(0);
}

.pge-eye-icon:hover {
    transform: scale(1.1) translateY(0);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.pge-eye-icon svg {
    width: 24px;
    height: 24px;
    fill: var(--pge-primary);
}

/* Product Content */
.pge-product-content {
    padding: 20px;
}

.pge-product-title {
    font-size: 16px;
    font-weight: 500;
    margin: 0 0 8px;
    color: var(--pge-primary);
    line-height: 1.4;
}

.pge-product-author,
.pge-product-category {
    font-size: 13px;
    color: var(--pge-secondary);
    margin-bottom: 8px;
}

.pge-product-price {
    font-size: 18px;
    font-weight: 600;
    color: var(--pge-primary);
    margin-top: 12px;
}

.pge-product-price del {
    color: #999;
    font-weight: normal;
    margin-right: 8px;
    font-size: 16px;
}

/* Badges */
.pge-sale-badge,
.pge-stock-badge {
    position: absolute;
    top: 16px;
    left: 16px;
    padding: 6px 12px;
    background: var(--pge-danger);
    color: white;
    font-size: 12px;
    font-weight: 600;
    border-radius: 20px;
    z-index: 5;
}

.pge-stock-badge {
    background: var(--pge-primary);
    top: auto;
    bottom: 16px;
}

/* Header */
.pge-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--pge-border);
}

.pge-product-count {
    font-size: 14px;
    color: var(--pge-secondary);
}

.pge-sort-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.pge-sort-select {
    padding: 8px 16px;
    border: 1px solid var(--pge-border);
    background: white;
    cursor: pointer;
    border-radius: 8px;
    font-size: 14px;
    transition: var(--pge-transition);
}

.pge-sort-select:hover {
    border-color: var(--pge-primary);
}

/* Image Ratios */
.pge-wrapper[data-ratio="1-1"] .pge-product-image {
    padding-bottom: 100%;
}

.pge-wrapper[data-ratio="3-4"] .pge-product-image {
    padding-bottom: 133.33%;
}

.pge-wrapper[data-ratio="4-3"] .pge-product-image {
    padding-bottom: 75%;
}

.pge-wrapper[data-ratio="16-9"] .pge-product-image {
    padding-bottom: 56.25%;
}

.pge-wrapper[data-ratio]:not([data-ratio="original"]) .pge-product-image img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Modern Popup Design */
#pge-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

#pge-popup.pge-popup-hidden {
    display: none;
}

#pge-popup.pge-popup-visible .pge-popup-backdrop {
    opacity: 1;
}

#pge-popup.pge-popup-visible .pge-popup-container {
    opacity: 1;
    transform: scale(1);
}

.pge-popup-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.pge-popup-container {
    position: relative;
    background: white;
    max-width: 1200px;
    width: 100%;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

#pge-popup.pge-popup-visible .pge-popup-container {
    transform: scale(1);
}

/* Popup Close Button - Forced visibility */
.pge-popup-close {
    position: absolute !important;
    top: 20px !important;
    right: 20px !important;
    width: 48px !important;
    height: 48px !important;
    background: rgba(255, 255, 255, 0.9) !important;
    backdrop-filter: blur(10px);
    border: none !important;
    border-radius: 50% !important;
    cursor: pointer !important;
    z-index: 20 !important;
    transition: var(--pge-transition);
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
    color: #333 !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.pge-popup-close svg {
    width: 24px !important;
    height: 24px !important;
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.pge-popup-close svg path {
    stroke: #333 !important;
    stroke-width: 2 !important;
    fill: none !important;
}

.pge-popup-close:hover {
    transform: rotate(90deg) !important;
    background: #fff !important;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15) !important;
}

.pge-popup-close:hover svg path {
    stroke: #000 !important;
}

.pge-popup-content {
    display: flex;
    height: 100%;
    background: white;
    overflow: hidden;
}

/* Gallery Section */
.pge-popup-gallery {
    flex: 0 0 50%;
    background: #fafafa;
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 40px;
    min-height: 0; /* Important for flex children */
}

.pge-gallery-main {
    flex: 1 1 auto; /* Allow to grow and shrink */
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    background: white;
    border-radius: 8px;
    min-height: 300px; /* Minimum height */
    max-height: calc(100vh - 300px); /* Maximum height */
}

.pge-gallery-track {
    display: flex;
    height: 100%;
    width: 100%;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.pge-gallery-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    flex-shrink: 0;
    display: block;
}

/* Gallery Navigation Arrows - Simplified and forced visibility */
.pge-gallery-nav {
    position: absolute !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    width: 48px !important;
    height: 48px !important;
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(10px);
    border: none !important;
    border-radius: 50% !important;
    cursor: pointer !important;
    transition: var(--pge-transition);
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
    z-index: 10 !important;
    color: #333 !important;
    opacity: 1 !important;
    visibility: visible !important;
    padding: 0 !important; /* Critical fix for SVG visibility */
}

.pge-gallery-nav svg {
    width: 24px !important;
    height: 24px !important;
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    color: #333 !important;
}

.pge-gallery-nav svg path,
.pge-gallery-nav svg polyline {
    stroke: #333 !important;
    stroke-width: 2px !important;
    fill: none !important;
    stroke-linecap: round !important;
    stroke-linejoin: round !important;
}

.pge-gallery-nav:hover {
    background: #fff !important;
    transform: translateY(-50%) scale(1.1) !important;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2) !important;
}

.pge-gallery-nav:hover svg path,
.pge-gallery-nav:hover svg polyline {
    stroke: #000 !important;
}

.pge-gallery-prev {
    left: 20px !important;
}

.pge-gallery-next {
    right: 20px !important;
}

/* Thumbnail Strip - Maximum 6 thumbnails visible */
.pge-gallery-thumbs {
    display: flex;
    gap: 10px;
    justify-content: center;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 10px 0;
    flex: 0 0 auto; /* Don't grow or shrink */
    max-width: 100%;
    position: relative;
    height: 90px; /* Fixed height */
}

/* FORCE: Hide any thumbnails beyond the 6th */
.pge-gallery-thumbs .pge-gallery-thumb:nth-child(n+7) {
    display: none !important;
}

/* Hide scrollbar but keep functionality */
.pge-gallery-thumbs::-webkit-scrollbar {
    height: 4px;
}

.pge-gallery-thumbs::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.pge-gallery-thumbs::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 2px;
}

/* More thumbnails indicator */
.pge-gallery-thumbs.has-more {
    position: relative;
}

/* Remove the more indicator element - we'll use CSS pseudo-elements instead */
.pge-more-indicator {
    display: none !important;
}

.pge-gallery-thumb {
    width: 80px;
    height: 80px;
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    overflow: hidden;
    flex-shrink: 0;
    transition: all 0.2s;
    position: relative;
}

.pge-gallery-thumb:hover {
    border-color: #ddd;
}

.pge-gallery-thumb.active {
    border-color: #333;
}

.pge-gallery-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Show subtle shadow on edge thumbnails when scrollable */
.pge-gallery-thumbs.has-more {
    position: relative;
}

.pge-gallery-thumbs.has-more::before,
.pge-gallery-thumbs.has-more::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30px;
    z-index: 1;
    pointer-events: none;
}

.pge-gallery-thumbs.has-more::before {
    left: 0;
    background: linear-gradient(to right, rgba(255,255,255,0.8), transparent);
}

.pge-gallery-thumbs.has-more::after {
    right: 0;
    background: linear-gradient(to left, rgba(255,255,255,0.8), transparent);
}

/* Product Details */
.pge-popup-details {
    flex: 0 0 50%;
    padding: 60px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.pge-popup-meta {
    font-size: 14px;
    color: #999;
    margin-bottom: 10px;
    font-weight: 400;
}

.pge-popup-title {
    font-size: 36px;
    font-weight: 300;
    margin: 0 0 30px;
    color: #000;
    line-height: 1.3;
    letter-spacing: -0.5px;
}

.pge-popup-price {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 40px;
    color: #000;
}

.pge-popup-description {
    font-size: 16px;
    line-height: 1.6;
    color: #666;
    margin-bottom: 50px;
}

/* Improved Action Buttons for Popup */
.pge-popup-actions {
    display: flex;
    gap: 15px;
    margin-bottom: 40px;
    flex-wrap: wrap;
}

.pge-btn {
    padding: 14px 28px;
    border: 2px solid #000;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 160px;
    position: relative;
    overflow: hidden;
    text-transform: none;
    letter-spacing: 0.25px;
    line-height: 1.2;
    white-space: nowrap;
    flex: 1;
    max-width: 200px;
    min-height: 48px;
    box-sizing: border-box;
}

.pge-btn-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Add to Cart Button */
.pge-btn-cart {
    background: #8B4513;
    color: white;
    border-color: #8B4513;
    position: relative;
}

.pge-btn-cart::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
    transition: left 0.6s;
}

.pge-btn-cart:hover:not(:disabled)::before {
    left: 100%;
}

.pge-btn-cart:hover:not(:disabled) {
    background: #A0522D;
    border-color: #A0522D;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(139, 69, 19, 0.3);
}

.pge-btn-cart:hover:not(:disabled) .pge-btn-icon {
    transform: scale(1.1);
}

.pge-btn-cart:disabled,
.pge-btn-cart.disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
    background: #ccc;
    border-color: #ccc;
    color: #666;
}

/* More Information Button */
.pge-btn-view {
    background: transparent;
    color: #000;
    border-color: #000;
    position: relative;
    overflow: hidden;
}

.pge-btn-view::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 100%;
    background: #000;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 0;
}

.pge-btn-view:hover::before {
    width: 100%;
}

.pge-btn-view:hover {
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

.pge-btn-view:hover .pge-btn-icon {
    fill: white;
    transform: scale(1.1);
}

.pge-btn-view span,
.pge-btn-view .pge-btn-icon {
    position: relative;
    z-index: 1;
}

/* View Details Link - Improved */
.pge-view-details-link {
    color: #666;
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-top: 20px;
    position: relative;
    padding-bottom: 2px;
}

.pge-view-details-link::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 1px;
    background: #666;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.pge-view-details-link:hover {
    color: #000;
    gap: 12px;
}

.pge-view-details-link:hover::after {
    width: 100%;
}

.pge-view-details-link .pge-arrow {
    display: inline-block;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 16px;
}

.pge-view-details-link:hover .pge-arrow {
    transform: translateX(4px);
}

/* Loading state improvements */
.pge-btn .loader {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top: 2px solid white;
    border-radius: 50%;
    animation: pge-spin 0.8s linear infinite;
    display: inline-block;
}

/* Success state */
.pge-btn.success {
    background: #4CAF50 !important;
    border-color: #4CAF50 !important;
    color: white !important;
}

/* Loading state */
.pge-loader-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
}

.pge-loader {
    width: 48px;
    height: 48px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #333;
    border-radius: 50%;
    animation: pge-spin 1s linear infinite;
}

.loader {
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #333;
    border-radius: 50%;
    animation: pge-spin 0.8s linear infinite;
    display: inline-block;
}

@keyframes pge-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Body when popup is open */
body.pge-popup-open {
    overflow: hidden;
}

/* Animations */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive Popup */
@media (max-width: 1024px) {
    .pge-popup-container {
        max-width: 900px;
    }
    
    .pge-popup-gallery {
        padding: 30px;
    }
    
    .pge-popup-details {
        padding: 40px;
    }
}

@media (max-width: 768px) {
    #pge-popup {
        padding: 0;
    }
    
    .pge-popup-container {
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }
    
    .pge-popup-content {
        flex-direction: column;
    }
    
    .pge-popup-gallery {
        flex: none;
        height: 50vh;
        padding: 20px;
    }
    
    .pge-popup-details {
        flex: 1;
        padding: 30px;
    }
    
    .pge-popup-actions {
        flex-direction: column;
        gap: 12px;
    }
    
    .pge-btn {
        width: 100%;
        max-width: none;
        min-width: auto;
        padding: 16px 24px;
        font-size: 15px;
        min-height: 52px;
    }
    
    .pge-btn-icon {
        width: 18px;
        height: 18px;
    }
    
    .pge-popup-title {
        font-size: 28px;
    }
    
    .pge-gallery-nav {
        width: 40px;
        height: 40px;
    }
    
    .pge-gallery-nav svg {
        width: 20px;
        height: 20px;
    }
    
    .pge-popup-close {
        width: 40px;
        height: 40px;
        top: 10px;
        right: 10px;
    }
    
    .pge-popup-close svg {
        width: 20px;
        height: 20px;
    }
    
    .pge-view-details-link {
        justify-content: center;
        margin-top: 15px;
        font-size: 16px;
    }
}

/* Ensure text never wraps */
.pge-btn,
.pge-btn span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Special handling for very long text */
@media (max-width: 400px) {
    .pge-btn {
        font-size: 13px;
        padding: 14px 20px;
    }
    
    .pge-btn-cart .pge-btn-text,
    .pge-btn-view .pge-btn-text {
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* Focus states for accessibility */
.pge-btn:focus {
    outline: 3px solid rgba(74, 144, 226, 0.5);
    outline-offset: 2px;
}

.pge-view-details-link:focus {
    outline: 2px solid rgba(74, 144, 226, 0.5);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Animation for button press effect */
.pge-btn:active {
    transform: translateY(0) scale(0.98);
}

/* No products */
.pge-no-products {
    text-align: center;
    padding: 60px 20px;
    color: var(--pge-secondary);
    font-size: 16px;
}

/* Loading states */
.pge-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

/* Accessibility */
.pge-eye-icon:focus,
.pge-gallery-nav:focus,
.pge-gallery-thumb:focus,
.pge-popup-close:focus {
    outline: 3px solid rgba(74, 144, 226, 0.5);
    outline-offset: 2px;
}

/* Print styles */
@media print {
    #pge-popup,
    .pge-eye-icon,
    .pge-header {
        display: none !important;
    }
}

/* Dynamic icon position styles */
.icon-bottom-left .pge-eye-icon {
    right: auto;
    left: 20px;
}

.icon-center .pge-eye-icon {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    opacity: 0;
    bottom: auto;
    right: auto;
}

.icon-center .pge-product-item:hover .pge-eye-icon {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

/* Ensure hover images work properly */
.pge-hover-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.pge-product-item.has-hover-image:hover .pge-hover-image {
    opacity: 1;
}

.pge-product-item.has-hover-image:hover .pge-primary-image {
    opacity: 0;
}

/* Disable hover effect when specified */
.pge-wrapper.disable-image-hover .pge-hover-image {
    display: none !important;
}

/* Instant transition */
.pge-wrapper.instant-transition .pge-primary-image,
.pge-wrapper.instant-transition .pge-hover-image {
    transition: none !important;
}

/* FORCE HIDE: A final failsafe to hide any thumbnails beyond the 6th */
.pge-gallery-thumbs .pge-gallery-thumb:nth-child(n+7) {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    position: absolute !important;
    left: -9999px !important;
}