/**
 * Professional WooCommerce Shop Enhancement - FINAL VERSION
 * ==========================================================
 * Clean, tested, production-ready styling
 * Fixes all issues: scrollbar, button wrapping, layout
 * 
 * @version 2.0.0 FINAL
 * @author Coastline Solutions
 */

/* ========================================
   SHOP PAGE - PRODUCT GRID
   (Your shop page works perfectly, keeping it as-is)
   ======================================== */

.woocommerce .products,
.woocommerce ul.products {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 30px;
    margin: 0 auto;
    padding: 20px 0;
    list-style: none;
}

.woocommerce ul.products li.product {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: visible;
    position: relative;
    margin: 0;
    width: 100%;
    float: none;
    padding-bottom: 30px;
    display: flex;
    flex-direction: column;
}

.woocommerce ul.products li.product:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
}

/* ========================================
   SINGLE PRODUCT PAGE - RELATED PRODUCTS
   (Targeted fixes for your issues)
   ======================================== */

/* Main container - prevent overflow */
.single-product .related.products,
body.single-product .related.products,
section.related.products {
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
    margin: 40px 0 !important;
    padding: 0 !important;
    clear: both !important;
    display: block !important;
}

/* Title - full width with border */
.single-product .related.products > h2,
body.single-product .related.products > h2,
.related.products > h2,
section.related.products > h2 {
    width: 100% !important;
    max-width: 100% !important;
    font-size: 24px !important;
    font-weight: 700 !important;
    color: #1a1a1a !important;
    text-align: left !important;
    margin: 0 0 25px 0 !important;
    padding: 0 0 12px 0 !important;
    border-bottom: 2px solid #e0e0e0 !important;
    display: block !important;
}

/* Product grid - 4 columns, no overflow */
.single-product .related.products ul.products,
body.single-product .related.products ul.products,
.related.products ul.products,
section.related.products ul.products {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 20px !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    list-style: none !important;
    overflow: visible !important;
}

/* Individual product cards */
.single-product .related.products ul.products li.product,
body.single-product .related.products ul.products li.product,
.related.products ul.products li.product,
section.related.products ul.products li.product {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden !important;
    position: relative !important;
    margin: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    float: none !important;
    clear: none !important;
    padding-bottom: 30px !important;
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
}

.single-product .related.products ul.products li.product:hover,
.related.products ul.products li.product:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
}

/* Remove clearfix */
.related.products ul.products::before,
.related.products ul.products::after,
section.related.products ul.products::before,
section.related.products ul.products::after {
    display: none !important;
    content: none !important;
}

/* ========================================
   PRODUCT IMAGES
   ======================================== */

.woocommerce ul.products li.product .woocommerce-loop-product__link,
.related.products ul.products li.product .woocommerce-loop-product__link,
section.related.products ul.products li.product .woocommerce-loop-product__link {
    display: block;
    position: relative;
    overflow: hidden;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px 8px 0 0;
}

.woocommerce ul.products li.product img,
.related.products ul.products li.product img,
section.related.products ul.products li.product img {
    transition: transform 0.4s ease;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: 200px !important;
    min-height: 180px !important;
    object-fit: contain !important;
    margin: 0 auto !important;
    display: block !important;
}

.woocommerce ul.products li.product:hover img,
.related.products ul.products li.product:hover img {
    transform: scale(1.05);
}

/* ========================================
   PRODUCT CONTENT
   ======================================== */

.woocommerce ul.products li.product .woocommerce-loop-product__title,
.related.products ul.products li.product .woocommerce-loop-product__title,
.related.products ul.products li.product h2,
section.related.products ul.products li.product h2 {
    font-size: 14px !important;
    font-weight: 600 !important;
    color: #1a1a1a !important;
    margin: 12px 15px 8px !important;
    line-height: 1.3 !important;
    min-height: 38px !important;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-align: center !important;
    text-overflow: ellipsis !important;
}

.woocommerce ul.products li.product .price,
.related.products ul.products li.product .price,
section.related.products ul.products li.product .price {
    font-size: 20px !important;
    font-weight: 700 !important;
    color: #2c3e50 !important;
    margin: 0 15px 12px !important;
    display: block !important;
    text-align: center !important;
}

.woocommerce ul.products li.product .price del,
.related.products ul.products li.product .price del {
    opacity: 0.5;
    font-size: 16px !important;
    margin-right: 8px;
}

.woocommerce ul.products li.product .price ins,
.related.products ul.products li.product .price ins {
    text-decoration: none;
    color: #e74c3c !important;
}

/* ========================================
   QUANTITY INPUT
   ======================================== */

/* Horizontal layout container for quantity + button */
.woocommerce ul.products li.product form.cart,
.related.products ul.products li.product form.cart,
section.related.products ul.products li.product form.cart {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 15px 12px !important;
    box-sizing: border-box !important;
}

.woocommerce ul.products li.product .quantity,
.related.products ul.products li.product .quantity,
section.related.products ul.products li.product .quantity {
    margin: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
}

.woocommerce ul.products li.product .quantity input[type="number"],
.related.products ul.products li.product .quantity input[type="number"],
section.related.products ul.products li.product .quantity input[type="number"] {
    width: 50px !important;
    max-width: 50px !important;
    padding: 8px 6px !important;
    text-align: center !important;
    border: 2px solid #e0e0e0 !important;
    border-radius: 4px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    transition: border-color 0.3s ease !important;
}

.woocommerce ul.products li.product .quantity input[type="number"]:focus,
.related.products ul.products li.product .quantity input[type="number"]:focus {
    outline: none !important;
    border-color: #2980b9 !important;
}

/* ========================================
   ADD TO CART BUTTON - HORIZONTAL LAYOUT
   ======================================== */

.woocommerce ul.products li.product .button,
.related.products ul.products li.product .button,
section.related.products ul.products li.product .button,
.single-product .related.products ul.products li.product .button {
    background: linear-gradient(135deg, #1e5a8e 0%, #2980b9 100%) !important;
    color: #ffffff !important;
    padding: 10px 16px !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    border-radius: 6px !important;
    border: none !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    margin: 0 !important;
    box-shadow: 0 4px 12px rgba(30, 90, 142, 0.3) !important;
    flex: 1 !important;
    min-width: 0 !important;
    text-decoration: none !important;
    white-space: nowrap !important;
    text-overflow: ellipsis !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
}

.woocommerce ul.products li.product .button:hover,
.related.products ul.products li.product .button:hover,
section.related.products ul.products li.product .button:hover {
    background: linear-gradient(135deg, #164a73 0%, #1f6fa0 100%) !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 16px rgba(30, 90, 142, 0.4) !important;
}

/* Cart icon in button */
.woocommerce ul.products li.product .button .cart-icon,
.related.products ul.products li.product .button .cart-icon {
    width: 14px !important;
    height: 14px !important;
    stroke: currentColor !important;
    fill: none !important;
    flex-shrink: 0 !important;
}

/* ========================================
   VIEW CART BUTTON
   ======================================== */

.woocommerce ul.products li.product .added_to_cart,
.related.products ul.products li.product .added_to_cart,
section.related.products ul.products li.product .added_to_cart {
    background: transparent !important;
    color: #2980b9 !important;
    border: 2px solid #2980b9 !important;
    padding: 8px 16px !important;
    font-size: 9px !important;
    font-weight: 600 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.3px !important;
    border-radius: 6px !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    display: block !important;
    text-align: center !important;
    text-decoration: none !important;
    margin: 0 auto 16px auto !important;
    max-width: 180px !important;
    white-space: nowrap !important;
}

.woocommerce ul.products li.product .added_to_cart:hover,
.related.products ul.products li.product .added_to_cart:hover {
    background: #2980b9 !important;
    color: #ffffff !important;
    transform: translateY(-1px) !important;
}

/* Hide view cart if needed */
.added_to_cart.hide-view-cart {
    display: none !important;
}

/* ========================================
   FORM CONTAINERS
   ======================================== */

.woocommerce ul.products li.product form.cart,
.related.products ul.products li.product form.cart,
section.related.products ul.products li.product form.cart {
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* ========================================
   SINGLE PRODUCT PAGE - MAIN ADD TO CART
   ======================================== */

.single-product div.product form.cart .single_add_to_cart_button {
    background: linear-gradient(135deg, #1e5a8e 0%, #2980b9 100%) !important;
    color: #ffffff !important;
    padding: 12px 24px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    border-radius: 6px !important;
    border: none !important;
    transition: all 0.3s ease !important;
    box-shadow: 0 4px 12px rgba(30, 90, 142, 0.3) !important;
}

.single-product div.product form.cart .single_add_to_cart_button:hover {
    background: linear-gradient(135deg, #164a73 0%, #1f6fa0 100%) !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 16px rgba(30, 90, 142, 0.4) !important;
}

/* ========================================
   SUCCESS MESSAGES
   ======================================== */

.woocommerce-message,
.woocommerce-info {
    background: #f0f8ff !important;
    border-top: 3px solid #2980b9 !important;
    padding: 15px 20px !important;
    margin: 20px 0 !important;
    border-radius: 6px !important;
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
}

.woocommerce-message::before,
.woocommerce-info::before {
    content: "✓";
    background: #2980b9;
    color: #ffffff;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}

.woocommerce-message a.button,
.woocommerce-info a.button {
    background: #2980b9 !important;
    color: #ffffff !important;
    padding: 8px 16px !important;
    border-radius: 4px !important;
    text-decoration: none !important;
    font-size: 13px !important;
    margin-left: auto !important;
}

/* ========================================
   NOTIFICATION POPUP
   ======================================== */

.product-added-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    padding: 20px;
    min-width: 380px;
    max-width: 450px;
    z-index: 999999;
    transform: translateX(120%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    border-left: 4px solid #27ae60;
}

.product-added-notification.show {
    transform: translateX(0);
}

.product-added-notification .icon {
    position: absolute;
    top: 20px;
    left: 20px;
    background: #27ae60;
    color: #ffffff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 700;
}

.product-added-notification .content {
    margin-left: 55px;
}

.product-added-notification h4 {
    margin: 0 0 8px 0;
    font-size: 18px;
    font-weight: 700;
    color: #1a1a1a;
}

.product-added-notification p {
    margin: 0 0 16px 0;
    font-size: 14px;
    color: #666;
    line-height: 1.5;
}

.product-added-notification .actions {
    display: flex;
    gap: 10px;
}

.product-added-notification .view-cart {
    background: #2980b9;
    color: #ffffff;
    padding: 10px 20px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.3s ease;
    flex: 1;
    text-align: center;
    white-space: nowrap;
    min-width: 110px;
}

.product-added-notification .view-cart:hover {
    background: #1f6fa0;
}

.product-added-notification .continue {
    background: #ecf0f1;
    color: #2c3e50;
    padding: 10px 20px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.3s ease;
    flex: 1;
    text-align: center;
    white-space: nowrap;
    min-width: 140px;
}

.product-added-notification .continue:hover {
    background: #d5dbdb;
}

.product-added-notification .close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: transparent;
    border: none;
    color: #95a5a6;
    font-size: 24px;
    cursor: pointer;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.product-added-notification .close:hover {
    background: #ecf0f1;
    color: #2c3e50;
}

/* ========================================
   FLOATING CART WIDGET
   ======================================== */

.floating-cart-widget {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 99999;
}

.floating-cart-button {
    background: linear-gradient(135deg, #1e5a8e 0%, #2980b9 100%);
    color: #ffffff;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(30, 90, 142, 0.4);
    transition: all 0.3s ease;
    position: relative;
    text-decoration: none;
}

.floating-cart-button:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 8px 32px rgba(30, 90, 142, 0.5);
}

.floating-cart-button svg {
    width: 28px;
    height: 28px;
    fill: #ffffff;
}

.floating-cart-button .cart-count {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #e74c3c;
    color: #ffffff;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(231, 76, 60, 0.4);
}

.cart-count.updated {
    animation: cartPulse 0.3s ease;
}

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

/* ========================================
   LOADING STATE
   ======================================== */

.woocommerce ul.products li.product.adding-to-cart,
.related.products ul.products li.product.adding-to-cart {
    pointer-events: none;
    opacity: 0.6;
}

.woocommerce ul.products li.product.adding-to-cart::after,
.related.products ul.products li.product.adding-to-cart::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

/* Large desktop (1400px+) - Optional 5th column */
@media screen and (min-width: 1400px) {
    /* Uncomment below if you want 5 columns on very large screens */
    /*
    .single-product .related.products ul.products {
        grid-template-columns: repeat(5, 1fr) !important;
    }
    */
}

/* Desktop (1200px - 1399px) - 4 columns */
@media screen and (min-width: 1200px) and (max-width: 1399px) {
    .woocommerce .products,
    .related.products ul.products,
    section.related.products ul.products {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}

/* Small desktop/Large tablet (992px - 1199px) - 3 columns */
@media screen and (min-width: 992px) and (max-width: 1199px) {
    .woocommerce .products,
    .related.products ul.products,
    section.related.products ul.products {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

/* Tablet (768px - 991px) - 2 columns */
@media screen and (min-width: 768px) and (max-width: 991px) {
    .woocommerce .products,
    .related.products ul.products,
    section.related.products ul.products {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 20px;
    }
}

/* Mobile (below 768px) - 1 column */
@media screen and (max-width: 767px) {
    .woocommerce .products,
    .related.products ul.products,
    section.related.products ul.products {
        grid-template-columns: 1fr !important;
        gap: 16px;
        padding: 15px 0;
    }
    
    .related.products > h2,
    section.related.products > h2 {
        font-size: 20px !important;
        margin-bottom: 20px !important;
    }
    
    .product-added-notification {
        min-width: 280px;
        top: 10px;
        right: 10px;
        left: 10px;
    }
    
    .floating-cart-widget {
        bottom: 20px;
        right: 20px;
    }
    
    .floating-cart-button {
        width: 56px;
        height: 56px;
    }
    
    /* Keep horizontal layout on mobile for better UX */
    .related.products ul.products li.product form.cart {
        flex-direction: row !important;
        gap: 8px !important;
    }
    
    /* Larger button text on mobile */
    .related.products ul.products li.product .button {
        font-size: 11px !important;
    }
    
    /* Adjust quantity input on mobile */
    .related.products ul.products li.product .quantity input {
        width: 50px !important;
        max-width: 50px !important;
    }
}

/* Small mobile (below 480px) - Optimizations */
@media screen and (max-width: 480px) {
    .woocommerce ul.products li.product .woocommerce-loop-product__title,
    .related.products ul.products li.product .woocommerce-loop-product__title {
        font-size: 13px !important;
        min-height: 36px !important;
    }
    
    .woocommerce ul.products li.product .price,
    .related.products ul.products li.product .price {
        font-size: 18px !important;
    }
    
    .woocommerce ul.products li.product img,
    .related.products ul.products li.product img {
        max-height: 160px !important;
        min-height: 140px !important;
    }
    
    /* Keep horizontal layout but optimize spacing */
    .related.products ul.products li.product form.cart {
        padding: 0 10px 10px !important;
        gap: 6px !important;
    }
    
    .related.products ul.products li.product .quantity input {
        width: 45px !important;
        max-width: 45px !important;
        font-size: 13px !important;
    }
    
    .related.products ul.products li.product .button {
        font-size: 10px !important;
        padding: 8px 12px !important;
    }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */

.woocommerce ul.products li.product .button:focus,
.woocommerce ul.products li.product .added_to_cart:focus,
.related.products ul.products li.product .button:focus,
.related.products ul.products li.product .added_to_cart:focus {
    outline: 3px solid rgba(41, 128, 185, 0.4);
    outline-offset: 2px;
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
    .floating-cart-widget,
    .product-added-notification {
        display: none !important;
    }
}

/* ========================================
   END OF STYLES
   ======================================== */
/* Horizontal form layout */
.woocommerce ul.products li.product form.cart,
.related.products ul.products li.product form.cart,
section.related.products ul.products li.product form.cart {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 15px 12px !important;
    box-sizing: border-box !important;
}

/* Quantity input styling */
.related.products ul.products li.product .quantity,
section.related.products ul.products li.product .quantity {
    margin: 0 !important;
    flex-shrink: 0 !important;
}

.related.products ul.products li.product .quantity input[type="number"],
section.related.products ul.products li.product .quantity input[type="number"] {
    width: 50px !important;
    max-width: 50px !important;
    padding: 8px 6px !important;
    font-size: 14px !important;
    text-align: center !important;
    border: 2px solid #e0e0e0 !important;
    border-radius: 4px !important;
    font-weight: 600 !important;
}

/* Button takes remaining space */
.related.products ul.products li.product .button,
section.related.products ul.products li.product .button {
    font-size: 11px !important;
    padding: 10px 16px !important;
    margin: 0 !important;
    flex: 1 !important;
    min-width: 0 !important;
    white-space: nowrap !important;
}

/* ────────────────────────────────────────────
   MODIFICATION 2: Wider Popup Buttons
   ──────────────────────────────────────────── */

/* Wider popup container */
.product-added-notification {
    min-width: 380px !important;
    max-width: 450px !important;
}

/* Wider buttons with no text wrapping */
.product-added-notification .view-cart,
.product-added-notification .continue {
    padding: 10px 20px !important;
    white-space: nowrap !important;
}

.product-added-notification .view-cart {
    min-width: 110px !important;
}

.product-added-notification .continue {
    min-width: 140px !important;
}

/* ────────────────────────────────────────────
   MOBILE RESPONSIVE
   ──────────────────────────────────────────── */

/* Keep horizontal layout on mobile */
@media screen and (max-width: 767px) {
    .related.products ul.products li.product form.cart {
        flex-direction: row !important;
        gap: 8px !important;
    }
    
    .related.products ul.products li.product .quantity input {
        width: 50px !important;
    }
    
    .related.products ul.products li.product .button {
        font-size: 11px !important;
    }
}

/* Optimize for small mobile */
@media screen and (max-width: 480px) {
    .related.products ul.products li.product form.cart {
        padding: 0 10px 10px !important;
        gap: 6px !important;
    }
    
    .related.products ul.products li.product .quantity input {
        width: 45px !important;
        font-size: 13px !important;
    }
    
    .related.products ul.products li.product .button {
        font-size: 10px !important;
        padding: 8px 12px !important;
    }
}