/* Match iframe widget title truncation and wrapping */
.amz-widget .widget-title {
    font-weight: bold;
    margin: 0 0 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: normal;
    max-width: 100%;
    line-height: 1.2em;
    height: 2.4em; /* 2 lines at 1.2em each */
    max-height: 2.4em;
    word-break: break-word;
}

/* Match iframe widget details min-height */
/* .amz-widget .amz-product-details {
} */
iframe {
    border: none !important;
    overflow: visible !important;
    overflow-clip-margin: initial !important;
}
body {
    font-family: sans-serif;
}

.amz-box {
    margin: 1em 0;
    text-align: center;
}

/* Wrapper to prevent single-product anchor areas from visually escaping widget borders */
.amz-widget-wrapper {
    /* Use inline-block so the wrapper shrink-wraps to widget width when embedded in iframes,
       but behaves like a block inside pages (use width:100% on block-level containers if needed). */
    display: inline-block;
    max-width: 100%;
    overflow: hidden; /* clip any accidental overflow from anchors/images */
    box-sizing: border-box;
}

/* Ensure the anchor inside the wrapper occupies the wrapper and doesn't expand beyond it */
.amz-widget-wrapper > a {
    display: block !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

.amz-widget {
    display: flex;
    border: 1px solid #ddd;
    border-radius: 5px;
    overflow: hidden;
    background-color: #fff;
}

.amz-widget a {
    text-decoration: none;
    color: #000;
}

.amz-widget .amz-img-link {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.amz-widget img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain; /* Reverted to contain */
}

.amz-widget.square .widget-image img {
    object-fit: cover; /* Apply cover specifically to square widget image */
}

.amz-widget .amz-product-details {
    padding: 1em;
    display: flex;
    flex-direction: column;
    justify-content: space-between; /* Changed to space-between */
    flex-grow: 1;
    align-items: flex-start;
}
/* Center button for vertical, square, grid, and carousel widgets */
.amz-widget.vertical .amz-product-details,
.amz-widget.square .amz-product-details, /* Added .amz-widget.square .amz-product-details */
.amz-widget.grid-item .amz-product-details,
.amz-widget.carousel-item .amz-product-details {
    justify-content: space-between;
    flex-grow: 1;
    align-items: center;
}

.amz-widget .amz-button {
    display: inline-block;
    background-color: #f0c14b;
    color: #111;
    padding: 0.5em 1em;
    border-radius: 3px;
    text-decoration: none;
    margin-top: 1em;
    text-align: center;
    width: 170px; /* Fixed width based on button text */
    min-width: 170px;
    max-width: 170px;
    box-sizing: border-box;
}

/* Pricing container for both JS and iframe widgets */
.amz-pricing {
    margin-bottom: 0.5em;
}

/* Widget price styling for JS cards and iframe */
.widget-price {
    font-size: 1.2em;
    color: #B12704;
    font-weight: bold;
}
.widget-list-price {
    text-decoration: line-through;
    color: #555;
    margin: 0;
}
.widget-savings {
    color: #B12704;
    margin: 0;
}
.widget-last-updated {
    font-size: 0.75em;
    color: #555;
    margin-top: 5px;
}

/* Align price, list price, and savings horizontally in JS and iframe widgets */
.amz-pricing {
    display: flex;
    flex-direction: row;
    align-items: baseline;
    gap: 0.5em;
    margin-bottom: 0.5em;
}

/* Grid and Carousel Layouts - Last Updated Positioning */
.amz-grid .widget-last-updated,
.amz-carousel .widget-last-updated {
    position: absolute;
    left: 1em;
    bottom: 1em;
    z-index: 2;
    background: rgba(255,255,255,0.85);
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 0.8em;
    color: #555;
}

.amz-grid, .amz-carousel {
    position: relative;
}

/* Horizontal Layout */
.amz-widget.horizontal {
    flex-direction: row;
    /* height: 200px; */
    max-width: 800px;
    margin: 0 auto;
}

.amz-widget.horizontal .amz-img-link {
    width: 200px;
}
/* Ensure horizontal widget titles are left-aligned only for the horizontal layout
   (do not affect vertical, square, grid-item, or carousel-item titles) */
.amz-widget.horizontal .widget-title {
    text-align: left;
}
/* Override for mobile devices (max width 600px) */
@media (max-width: 600px) {
    .amz-widget.horizontal .amz-img-link {
        width: 150px;
    }
}

/* Vertical Layout */
.amz-widget.vertical {
    flex-direction: column;
    width: 250px;
}

.amz-widget.vertical .widget-last-updated {
    text-align: center;
}

.amz-widget.vertical .amz-img-link {
    height: 200px;
}

/* Square Layout */
.amz-widget.square {
    flex-direction: column;
    width: 300px;
    height: auto; /* Allow height to adjust based on content */
    align-items: center;
    justify-content: space-between;
    padding: 10px; /* Add padding around the entire widget */
}

.amz-widget.square .middle-section {
    display: flex;
    flex-direction: row;
    width: 100%;
    align-items: center; /* Changed to center */
}

.amz-widget.square .widget-image {
    width: 50%;
    max-width: 50%;
    margin-right: 10px;
    /* Removed fixed height */
}

.amz-widget.square .widget-details {
    width: calc(50% - 10px);
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    /* Removed padding-top */
    justify-content: flex-end;
}

.amz-widget.square .widget-title {
    width: 100%;
    text-align: center;
    margin-bottom: 10px;
}

.amz-widget.square .amz-button {
    margin-top: auto; /* Pushes the button to the bottom */
    align-self: center; /* Center the button */
    margin-bottom: 5px; /* Space between button and timestamp */
}

.amz-widget.square .widget-last-updated {
    width: 100%;
    text-align: center;
    padding-top: 10px;
}

.amz-widget.square::after {
    content: "";
    display: table;
    clear: both;
}

/* Grid Layout */
.amz-grid {
    display: inline-grid;
    grid-template-columns: repeat(var(--grid-cols, 4), 1fr);
    gap: 1em;
}

/* When there are fewer items than columns, switch the grid container to a
   flex layout so the items can be centered. This only applies when the
   client sets the `amz-grid--center` class (added dynamically). */
.amz-grid--center {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 1em;
    flex-wrap: wrap;
}

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

@media (max-width: 600px) {
    .amz-grid {
        grid-template-columns: 1fr;
    }
}

.amz-widget.grid-item {
    flex-direction: column;
    max-width: 300px; /* Re-added max-width for grid items */
}

.amz-widget.grid-item .amz-img-link {
    height: 150px;
}

/* Carousel Layout */
.amz-carousel {
    display: flex;
    flex-wrap: nowrap; /* prevent items from wrapping onto multiple rows */
    gap: 1em; /* keep consistent spacing between items */
    transition: transform 0.3s ease-in-out;
}

.amz-widget.carousel-item {
    flex: 0 0 auto;
    width: 250px;
    margin-right: 0; /* gap handled by flex gap on container */
    flex-direction: column;
    min-width: 220px; /* ensure min width so items don't collapse */
    box-sizing: border-box;
}

@media (max-width: 600px) {
    .amz-widget.carousel-item {
        width: 100%;
    }
}

.amz-widget.carousel-item .amz-img-link {
    height: 200px;
}

.amz-widget.carousel-item img {
    width: auto;
}

.amz-carousel-container {
    position: relative;
    overflow: hidden;
    max-width: 800px; /* Set a max-width for the carousel */
    margin: 0 auto; /* Center the carousel */
}

.amz-carousel-control {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background-color: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    padding: 10px;
    cursor: pointer;
    z-index: 10;
    display: none;
}

.amz-carousel-control.prev {
    left: 0;
}

.amz-carousel-control.next {
    right: 0;
}