/* ==========================================================================
   CARDS & WRAPPERS (Dynamic, Premium & Flex-Aligned)
   ========================================================================== */

/* 1. Dynamic Grid Container */
.dynamic-product-grid {
    display: grid;
    /* DEBUG: Verify file loading */
    /* This is the magic line that allows admin resizing */
    grid-template-columns: repeat(auto-fill, minmax(var(--card-min-width, 250px), 1fr));
    gap: 20px;
    width: 100%;
    align-items: stretch;
    /* Ensure all cards in a row have equal height */
}

/* 2. Product Card - Flex Container for Equal Height */
.product-card {
    display: flex;
    flex-direction: column;
    height: 100%;
    /* Fills the grid cell height */
    background: transparent;
    position: relative;
    transition: transform 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
    margin-bottom: 30px;
    /* Spacing for non-grid contexts */
    border-radius: var(--card-radius, 12px);
    overflow: hidden;
}

/* Remove margin bottom when in dynamic grid to allow gap to handle it */
.dynamic-product-grid .product-card {
    margin-bottom: 0;
}

/* Image Wrapper - Fixed Aspect Ratio */
.product-img-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: var(--img-aspect, 3/4);
    background: #f9f9f9;
    overflow: hidden;
    margin-bottom: 0;
    /* Remove margin, let padding of info handle spacing */
    flex-shrink: 0;
    /* Never shrink image */
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.product-img {
    width: 100%;
    height: 100%;
    object-fit: var(--img-fit, cover);
    transition: transform 0.7s ease;
}

.product-card:hover .product-img {
    transform: scale(1.08);
}

/* 3. Quick Shop Overlay */
.quick-shop-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    padding: 15px 10px;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    z-index: 10;
    text-align: center;
}

.product-card:hover .quick-shop-bar {
    transform: translateY(0);
}

.size-overlay-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--color-muted);
    margin-bottom: 8px;
    font-weight: 500;
}

.size-btn-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 35px;
    height: 35px;
    font-size: 11px;
    color: var(--color-text);
    text-decoration: none;
    font-weight: 600;
    transition: 0.2s;
    border: 1px solid var(--color-text);
    border-radius: 50%;
    padding: 0;
    background: #fff;
}

.size-btn-overlay:hover {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.size-selector-overlay {
    display: flex;
    gap: 8px;
    justify-content: center;
    padding: 10px 0;
}

/* 4. Product Info Styling (Flex Column for Alignment) */
.product-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    /* Take up remaining height */
    padding: var(--card-padding, 10px);
}

.product-brand {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--color-muted);
    margin-bottom: 4px;
    font-weight: 700;
    height: 1.2em;
    /* Fixed height reservation */
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.product-title {
    font-size: var(--card-title-size, 1rem);
    font-weight: 500;
    margin-bottom: 6px;
    line-height: 1.4;

    /* Line Clamp Logic - Critical for alignment */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: calc(1.4em * 2);
    /* Reserve exactly 2 lines height */
}

.product-title a {
    color: var(--color-text);
    text-decoration: none;
    transition: color 0.3s;
}

.product-title a:hover {
    color: var(--color-primary);
}

.product-price {
    font-size: var(--card-price-size, 1.1rem);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    min-height: 1.5em;
    /* Fixed height reservation */
}

.product-price .current {
    color: var(--color-text);
}

.product-price .old {
    font-size: 0.9em;
    color: var(--color-muted);
    text-decoration: line-through;
    font-weight: 400;
}

/* Color Swatches */
.color-selector-row {
    display: flex;
    gap: 5px;
    min-height: 20px;
    /* Reserve space even if empty */
    margin-bottom: 10px;
}

.color-swatch {
    width: 20px;
    height: 20px;
    border-radius: 50px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: 0.2s;
}

.color-swatch:hover {
    transform: scale(1.2);
    border-color: var(--color-primary);
}

/* Buttons (Dynamic & Bottom Aligned) */
.product-action-btns {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: auto;
    /* Pushes button to bottom of card */
    width: 100%;
}

.btn-buy-now {
    flex: 1;
    background: var(--color-primary);
    color: #fff !important;
    text-align: center;
    height: var(--card-btn-height, 40px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    font-size: var(--card-btn-font, 0.9rem);
    font-weight: 700;
    text-transform: uppercase;
    text-decoration: none;
    border-radius: 6px;
    transition: 0.3s;
    border: none;
}

.btn-buy-now:hover {
    background: var(--color-text);
}

.btn-add-cart-outline {
    width: var(--card-btn-height, 40px);
    height: var(--card-btn-height, 40px);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--color-primary);
    color: var(--color-primary) !important;
    border-radius: 6px;
    text-decoration: none;
    transition: 0.3s;
    font-size: calc(var(--card-btn-font, 0.9rem) * 1.2);
    background: transparent;
    flex-shrink: 0;
}

.btn-add-cart-outline:hover {
    background: var(--color-primary);
    color: #fff !important;
}

/* Responsive Overrides */
@media (max-width: 768px) {
    .quick-shop-bar {
        display: none;
    }

    .dynamic-product-grid {
        gap: 10px;
        align-items: stretch;
    }

    /* Keep reserved heights on mobile too? Yes, for nice grid */
    .product-title {
        font-size: var(--card-title-size, 0.85rem);
        min-height: calc(1.4em * 2);
    }
}