.tm-product-labels {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 8px 0;
}

.tm-product-labels-image-wrap,
.tm-product-labels-gallery-wrap {
    position: relative;
    display: block;
    max-width: 100%;
    overflow: visible;
    line-height: 0;
}

.tm-product-labels-gallery-wrap .tm-product-label {
    display: none;
}

.bw-pdp-media {
    position: relative;
}

.tm-product-labels-image-wrap > img,
.tm-product-labels-gallery-wrap > img {
    display: block;
    max-width: 100%;
    height: auto;
}

/*
 * Overlay mode: place .tm-product-labels--overlay inside a position:relative
 * product-image container. Position modifiers pin labels to the 9-cell grid.
 *
 * --tm-product-label-inset insets the overlay box itself (listing 14px, PDP 22px)
 * so absolute pins and flex-stack (position: static) both keep breathing room —
 * even when a theme zeros padding on gallery children.
 */
.tm-product-labels--overlay {
    --tm-product-label-inset: 14px;
    position: absolute;
    top: var(--tm-product-label-inset);
    right: var(--tm-product-label-inset);
    bottom: var(--tm-product-label-inset);
    left: var(--tm-product-label-inset);
    margin: 0;
    padding: 0;
    pointer-events: none;
    z-index: 5;
    display: block;
    overflow: visible;
    box-sizing: border-box;
}

.tm-product-labels--product_view.tm-product-labels--overlay {
    --tm-product-label-inset: 22px;
}

.tm-product-labels--overlay .tm-product-label {
    position: absolute;
    pointer-events: auto;
    box-sizing: border-box;
    line-height: 1;
    max-width: 100%;
}

.tm-product-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    max-width: calc(100% - 16px);
    border-radius: 6px;
    padding: 8px 14px;
    background: #1f2937;
    color: #ffffff;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.04em;
    line-height: 1;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
    white-space: nowrap;
}

.tm-product-label__image {
    max-height: 42px;
    max-width: min(100%, 120px);
    width: auto;
    height: auto;
    display: block;
    object-fit: contain;
}

.tm-product-label__text {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    line-height: 1;
    white-space: nowrap;
}

.tm-product-label__text:has(br) {
    display: inline-block;
    white-space: pre-line;
    line-height: 1.2;
    text-align: center;
}

/* Category / listing cards */
.tm-product-labels--category_item .tm-product-label,
.tm-product-labels--related_item .tm-product-label,
.tm-product-labels--upsell_item .tm-product-label,
.tm-product-labels--crosssell_item .tm-product-label,
.tm-product-labels-image-wrap .tm-product-labels--overlay .tm-product-label {
    font-size: 13px;
    padding: 7px 12px;
    min-height: 28px;
}

.tm-product-labels--category_item .tm-product-label__image,
.tm-product-labels--related_item .tm-product-label__image,
.tm-product-labels--upsell_item .tm-product-label__image,
.tm-product-labels--crosssell_item .tm-product-label__image,
.tm-product-labels-image-wrap .tm-product-label__image {
    max-height: 40px;
    max-width: min(100%, 100px);
}

/* PDP gallery — larger, more Amasty-like presence */
.tm-product-labels--product_view .tm-product-label {
    font-size: 16px;
    padding: 10px 18px;
    min-height: 36px;
    box-shadow: 0 3px 14px rgba(0, 0, 0, 0.28);
}

.tm-product-labels--product_view .tm-product-label__image {
    max-height: 64px;
    max-width: min(100%, 160px);
}

/* Pin to the inset overlay edges — all nine grid cells */
.tm-product-labels--overlay .tm-product-label--pos-top-left { top: 0; left: 0; }
.tm-product-labels--overlay .tm-product-label--pos-top-center { top: 0; left: 50%; transform: translateX(-50%); }
.tm-product-labels--overlay .tm-product-label--pos-top-right { top: 0; right: 0; }
.tm-product-labels--overlay .tm-product-label--pos-middle-left { top: 50%; left: 0; transform: translateY(-50%); }
.tm-product-labels--overlay .tm-product-label--pos-middle-center { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.tm-product-labels--overlay .tm-product-label--pos-middle-right { top: 50%; right: 0; transform: translateY(-50%); }
.tm-product-labels--overlay .tm-product-label--pos-bottom-left { bottom: 0; left: 0; }
.tm-product-labels--overlay .tm-product-label--pos-bottom-center { bottom: 0; left: 50%; transform: translateX(-50%); }
.tm-product-labels--overlay .tm-product-label--pos-bottom-right { bottom: 0; right: 0; }

/* Shapes */
.tm-product-label--shape-rectangle { border-radius: 0; }
.tm-product-label--shape-rounded { border-radius: 8px; }
.tm-product-label--shape-circle {
    border-radius: 50%;
    min-width: 56px;
    min-height: 56px;
    padding: 12px;
    white-space: normal;
}
.tm-product-label--shape-oval {
    border-radius: 999px;
    padding: 9px 18px;
}
.tm-product-label--shape-pill {
    border-radius: 999px;
    padding: 8px 16px;
}
.tm-product-label--shape-ribbon {
    border-radius: 0;
    clip-path: polygon(0 0, 100% 0, 100% 70%, 50% 100%, 0 70%);
    padding: 8px 12px 16px;
    box-shadow: none;
}
.tm-product-label--shape-flag {
    border-radius: 0;
    clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 0 100%);
    padding: 7px 16px 7px 10px;
}

.tm-product-labels--product_view .tm-product-label--shape-circle {
    min-width: 72px;
    min-height: 72px;
}

.tm-product-labels--product_view .tm-product-label--shape-oval,
.tm-product-labels--product_view .tm-product-label--shape-pill {
    padding: 10px 20px;
}

/* Hyvä / listing: avoid card overflow clipping the badge */
.product-item-photo:has(.tm-product-labels-image-wrap),
.product.photo:has(.tm-product-labels-image-wrap),
.product-item-info .product-image-wrapper:has(.tm-product-labels-image-wrap) {
    overflow: visible !important;
}

.tm-product-labels--cart_item,
.tm-product-labels--minicart_item,
.tm-product-labels--checkout_item {
    margin: 4px 0 0;
}

.tm-product-labels:not(.tm-product-labels--overlay) .tm-product-label {
    position: relative;
}

.tm-product-label__tooltip {
    display: none;
    position: absolute;
    left: 50%;
    bottom: calc(100% + 8px);
    transform: translateX(-50%);
    z-index: 5;
    min-width: 120px;
    max-width: 240px;
    padding: 8px 10px;
    border-radius: 4px;
    background: #111827;
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: normal;
    line-height: 1.35;
    text-align: left;
    white-space: normal;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
    pointer-events: none;
}

.tm-product-label__tooltip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -6px;
    border: 6px solid transparent;
    border-top-color: #111827;
}

.tm-product-label--has-tooltip:hover .tm-product-label__tooltip,
.tm-product-label--has-tooltip:focus-within .tm-product-label__tooltip {
    display: block;
}

@media (max-width: 767px) {
    .tm-product-label--tooltip-desktop .tm-product-label__tooltip {
        display: none !important;
    }

    .tm-product-label {
        font-size: 12px;
        padding: 6px 11px;
    }

    .tm-product-labels--product_view .tm-product-label {
        font-size: 14px;
        padding: 8px 14px;
    }

    .tm-product-label__image {
        max-height: 36px;
    }

    .tm-product-labels--product_view .tm-product-label__image {
        max-height: 52px;
    }

    .tm-product-labels--overlay {
        --tm-product-label-inset: 12px;
    }

    .tm-product-labels--product_view.tm-product-labels--overlay {
        --tm-product-label-inset: 14px;
    }
}
