/* Container for the product grid */
#productList {
    display: grid;
    /* Responsive grid: Adjust minmax(250px, ...) based on desired min card width */
    /* Starts with 1 column, then 2, then 3, then 4 as screen widens */
    grid-template-columns: repeat(auto-fit, minmax(235px, 1fr));
    gap: 25px 20px;
    /* Row gap, Column gap */
    padding: 20px 40px;
    /* Add some padding around the grid */
    box-sizing: border-box;
    /* Include padding in width calculations */
}

/* Individual product card */
.product-card {
    text-align: left;
    background-color: #fff;
    position: relative;
    display: flex;
    flex-direction: column; /* Stack elements vertically */
    border: 1px solid #eee; /* Existing style */
    border-radius: 5px; /* Existing style */
    padding: 15px; /* Existing style */
    /* REMOVED: margin-bottom: 20px; -> handled by grid gap */
}

/* Ensure the product image container has relative positioning */
.product-image-container {
    position: relative;
    overflow: hidden;
    margin-bottom: 10px;
    background-color: #f8f8f8;
    text-align: center; /* Center image */
}

.product-image-link {
    display: block;
    text-decoration: none;
}

.product-card img {
    display: block;
    width: 100%; /* Make image fill container width */
    height: auto;
    aspect-ratio: 3 / 4; /* Force a consistent aspect ratio (adjust as needed) */
    object-fit: contain; /* Fit image within bounds, preserving aspect ratio */
    transition: transform 0.3s ease;
    /* Limit max-width to make smaller images consistent */
    max-width: 200px; /* NEW: Adjust this based on your desired image size */
    margin: 0 auto; /* NEW: Center the image within its container */
}

.product-card:hover img {
    transform: scale(1.05);
}

/* Removed .wishlist-button and related styles */

/* Product info container */
.product-info {
    padding: 0 5px;
    flex-grow: 1; /* Allows info to take remaining space */
    display: flex; /* NEW: Use flexbox inside product-info */
    flex-direction: column; /* NEW: Stack its children vertically */
    justify-content: space-between; /* NEW: Pushes last item (actions) to bottom */
    text-align: center; /* Center text within product info */
}

/* Product Brand */
.product-brand {
    display: block;
    font-size: 0.8em;
    color: #777;
    margin-bottom: 2px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Product Title */
.product-title {
    font-size: 0.95em;
    font-weight: 500;
    margin: 0 0 5px 0;
    line-height: 1.3;
    /* NEW: Ensure title doesn't overflow */
    display: -webkit-box;
    -webkit-line-clamp: 2; /* Limit to 2 lines */
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 2.6em; /* Approx height for 2 lines based on line-height */
}

.product-title a {
    text-decoration: none;
    color: #333;
    transition: color 0.2s ease;
}

.product-title a:hover {
    color: #007bff;
}

/* Product Description (optional: add height limit if descriptions vary wildly) */
.product-description {
    font-size: 0.85em;
    color: #555;
    margin-bottom: 5px;
    /* NEW: Ensure description doesn't overflow too much */
    display: -webkit-box;
    -webkit-line-clamp: 3; /* Limit to 3 lines */
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 3.8em; /* Approx height for 3 lines */
}

/* Product Inventory */
.product-inventory {
    font-size: 0.85em;
    color: #666;
    margin-bottom: 5px;
}

/* Product Price container */
.product-price {
    font-size: 1em;
    /* Base size for price */
    /* REMOVED: margin-top: auto; -> Now handled by flex-grow on product-info */
    padding-top: 5px;
    /* Space above price */
    margin-bottom: 10px; /* NEW: Add space before buttons */
}

.product-price .original-price {
    text-decoration: line-through;
    color: #999;
    font-size: 0.85em;
    margin-right: 8px;
}

.product-price .current-price {
    font-weight: bold;
    color: #333;
}

.product-price .current-price.discounted {
    color: #e74c3c;
}

/* Product Actions (buttons) */
.product-actions {
    margin-top: auto; /* Pushes buttons to the bottom of the flex container */
    padding-top: 10px; /* Space above buttons */
    border-top: 1px solid #eee; /* Optional: separator line */
    text-align: center; /* Center the button */
    /* NEW: Ensure button takes full width if desired, or center it */
    width: 100%;
}

.product-actions .view-details-btn {
    width: calc(100% - 10px); /* Adjust to fit padding/margin */
    padding: 10px 15px;
    background-color: black; /* Example button color */
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease;
}

.product-actions .view-details-btn:hover {
    background-color: lightslategray;
}


/* --- Responsive Adjustments --- */

/* Example: Adjust grid columns for smaller screens */
@media (max-width: 768px) {
    #productList {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
        gap: 20px 15px;
    }

    .product-title {
        font-size: 0.9em;
    }

    .product-price {
        font-size: 0.95em;
    }
}

@media (max-width: 480px) {
    #productList {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px 10px;
    }

    .product-title {
        font-size: 0.85em;
    }
}

/* Style the main product card when it's sold out */
.product-card.sold-out {
    opacity: 0.6;
}

/* Style the image container specifically if needed */
.product-card.sold-out .product-image-container {
    position: relative;
}

/* Style the image itself when sold out */
.product-card.sold-out .product-image-container img {
    opacity: 0.7;
}

/* Style for the SOLD OUT overlay text */
.sold-out-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 15px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 1.2em;
    text-align: center;
    z-index: 10;
    pointer-events: none;
}

/* Ensure disabled buttons look clearly disabled */
.product-card.sold-out button:disabled,
.product-card button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
    background-color: #cccccc;
    border-color: #aaaaaa;
    color: #666666;
}

.product-card.sold-out .add-to-cart:disabled:hover {
    background-color: #cccccc;
    border-color: #aaaaaa;
    color: #666666;
}

/* Style for the discount badge */
.discount-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    background-color: #dc3545;
    color: white;
    padding: 3px 8px;
    font-size: 0.8em;
    font-weight: bold;
    border-radius: 3px;
    z-index: 5;
}

/* Style for original vs discounted price */
.product-price .original-price {
    text-decoration: line-through;
    color: grey;
    margin-right: 10px;
    font-size: 0.9em;
}

.product-price .discounted-price {
    color: #dc3545;
    font-weight: bold;
}

.product-card.sold-out .product-price .current-price,
.sold-out-price {
    color: #666666;
}

/* Optional: Disable link visually and prevent click */
.product-image-link.disabled-link {
    cursor: default;
}