/*
 * Free gift (#1339): the second bar stage after free shipping (#1326) in the mini cart, on the cart page and in the
 * add-to-cart panel, and the gift row price ("Geschenk · struck value · Gratis"). Mobile first, theme tokens only.
 */
popy-gift,
.popy-product-gift {
    --gift-fg: var(--color-fg, #0a0a0a);
    --gift-muted: var(--color-fg-secondary, #666666);
    --gift-accent: var(--color-primary, #0a0a0a);
    --gift-on-accent: var(--color-on-primary, #ffffff);
    --gift-ok: var(--color-ok, var(--color-primary, #0a0a0a));
    --gift-line: var(--color-line, rgb(10 10 10 / 0.1));
    --gift-surface: var(--color-surface, #ffffff);
}

popy-gift {
    display: block;
    color: var(--gift-fg);
}

popy-gift[hidden],
popy-gift:not(:defined) {
    display: none;
}

popy-gift[data-context="drawer"] {
    padding: 0.25rem 0 0.5rem;
}

popy-gift[data-context="added"] {
    padding: 0.5rem 0 0;
}

popy-gift[data-context="cart"] {
    margin: 0 0 1.25rem;
    padding: 0.875rem 1rem;
    border: 1px solid var(--gift-line);
    border-radius: var(--radius-lg, 0.75rem);
    background: var(--gift-surface);
}

/* Directly under the free-shipping box on the cart page: one box with two stages. */
popy-freeship[data-context="cart"]:not([hidden]) + popy-gift[data-context="cart"] {
    margin-top: -1.25rem;
    border-top: 0;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

popy-freeship[data-context="cart"]:not([hidden]):has(+ popy-gift[data-context="cart"]:not([hidden])) {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    padding-bottom: 0.5rem;
}

.popy-gift__msg {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin: 0 0 0.5rem;
    font-size: 0.875rem;
    line-height: 1.35;
}

popy-gift[data-state="teaser"] .popy-gift__msg {
    margin: 0;
    color: var(--gift-muted);
    font-size: 0.8125rem;
}

.popy-gift__msg strong {
    font-weight: 700;
    white-space: nowrap;
}

.popy-gift__teaser-name {
    font-weight: 600;
    color: var(--gift-fg);
}

/* Long product names never push the stage beyond three (teaser) or two (name) lines on a phone. */
popy-gift[data-state="teaser"] .popy-gift__text,
.popy-gift__title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
}

.popy-gift__title {
    -webkit-line-clamp: 2;
}

.popy-gift__icon {
    flex: none;
    width: 1.125rem;
    height: 1.125rem;
    margin-top: 0.0625rem;
    fill: none;
    stroke: var(--gift-accent);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

popy-gift[data-state="reached"] .popy-gift__msg {
    font-weight: 600;
}

popy-gift[data-state="reached"] .popy-gift__icon {
    stroke: var(--gift-ok);
}

.popy-gift__track {
    position: relative;
    height: 0.5rem;
    overflow: hidden;
    border-radius: 999px;
    background: var(--gift-line);
}

.popy-gift__fill {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: var(--gift-accent);
    transform-origin: left center;
    transition: transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

[dir="rtl"] .popy-gift__fill {
    transform-origin: right center;
}

.popy-gift__item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin-top: 0.625rem;
    font-size: 0.8125rem;
    line-height: 1.3;
}

.popy-gift__item img {
    flex: none;
    width: 2.5rem;
    height: 2.5rem;
    object-fit: contain;
    border-radius: var(--radius-md, 0.5rem);
    background: var(--gift-surface);
    border: 1px solid var(--gift-line);
}

.popy-gift__name {
    display: grid;
    gap: 0.125rem;
    min-width: 0;
}

.popy-gift__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.5rem;
}

.popy-gift__free {
    display: inline-block;
    padding: 0.0625rem 0.4375rem;
    border-radius: 999px;
    background: var(--gift-accent);
    color: var(--gift-on-accent);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    vertical-align: 0.0625rem;
}

.popy-gift__was {
    color: var(--gift-muted);
    white-space: nowrap;
}

/* Gift choice (#1340): every gift side by side, "1 of N" below, then the button to the native popup. */
.popy-gift__choices {
    display: grid;
    gap: 0.375rem;
    margin-top: 0.625rem;
}

.popy-gift__options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.popy-gift__option {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    overflow: hidden;
    border: 1px solid var(--gift-line);
    border-radius: var(--radius-md, 0.5rem);
    background: var(--gift-surface);
}

.popy-gift__option img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.popy-gift__option-name {
    padding: 0.125rem;
    font-size: 0.5625rem;
    line-height: 1.1;
    text-align: center;
    overflow: hidden;
}

.popy-gift__choice,
.popy-gift__swap {
    color: var(--gift-muted);
    font-size: 0.8125rem;
    line-height: 1.3;
}

.popy-gift__swap {
    margin: 0.5rem 0 0;
}

.popy-gift__choose {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 2.75rem;
    margin-top: 0.75rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-lg, 0.75rem);
    background: var(--gift-accent);
    color: var(--gift-on-accent);
    font-weight: 700;
    text-align: center;
    text-decoration: none;
}

.popy-gift__choose:hover,
.popy-gift__choose:focus-visible {
    color: var(--gift-on-accent);
    text-decoration: underline;
}

popy-gift[data-state="choose"] .popy-gift__msg {
    font-weight: 600;
}

/* The stage asks in the store language; Amasty's own English line ("Select your FREE GIFT!") then steps back.
   The popup itself (sibling dialog) stays; the stage button opens it. */
body:has(popy-gift[data-state="choose"]:not([hidden])) .free-gift-button {
    display: none !important;
}

/* The one moment the gift is won (never under reduced motion; gift.js only sets the class on that transition). */
popy-gift.is-celebrating .popy-gift__icon {
    animation: popy-gift-pop 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

popy-gift.is-celebrating .popy-gift__item,
popy-gift.is-celebrating .popy-gift__options {
    animation: popy-gift-in 0.5s ease-out;
}

@keyframes popy-gift-pop {
    0% { transform: scale(0.6) rotate(-12deg); }
    55% { transform: scale(1.25) rotate(8deg); }
    100% { transform: none; }
}

@keyframes popy-gift-in {
    from { opacity: 0; transform: translateY(0.25rem); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .popy-gift__fill { transition: none; }
    popy-gift.is-celebrating .popy-gift__icon,
    popy-gift.is-celebrating .popy-gift__item,
    popy-gift.is-celebrating .popy-gift__options { animation: none; }
}

@media (min-width: 768px) {
    popy-gift[data-context="cart"] {
        padding: 1rem 1.25rem;
    }

    popy-gift[data-context="cart"] .popy-gift__item img {
        width: 3rem;
        height: 3rem;
    }
}

/* Gift row price in the mini cart and on the cart page. */
.popy-gift-price {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.5rem;
    font-size: 0.875rem;
    line-height: 1.3;
}

.popy-gift-price__badge {
    display: inline-flex;
    align-items: center;
    padding: 0.0625rem 0.5rem;
    border-radius: 999px;
    background: var(--color-primary, #0a0a0a);
    color: var(--color-on-primary, #ffffff);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.popy-gift-price__was {
    color: var(--color-fg-secondary, #666666);
    white-space: nowrap;
}

.popy-gift-price__free {
    font-weight: 700;
    color: var(--color-ok, var(--color-primary, #0a0a0a));
}

/* Cart page gift row: neither configurable nor a quantity choice; the remove action stays. */
.popy-gift-row .control.qty,
.popy-gift-row .action-edit,
.popy-gift-row a[href*="/checkout/cart/configure/"] {
    display: none;
}

/* Gift with a product (#1341): "+ Gratis: <gift>" on the product page, the category tile and the cart row. */
.popy-product-gift {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--gift-fg);
    font-size: 0.875rem;
    line-height: 1.3;
}

.popy-product-gift[hidden] {
    display: none;
}

.popy-product-gift__icon {
    width: 1.125rem;
    height: 1.125rem;
    flex-shrink: 0;
    fill: none;
    stroke: var(--gift-ok);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.popy-product-gift__label {
    font-weight: 700;
    color: var(--gift-ok);
}

.popy-product-gift__name {
    font-weight: 600;
}

.popy-product-gift__was {
    color: var(--gift-muted);
    white-space: nowrap;
}

.popy-product-gift__note {
    display: block;
    color: var(--gift-muted);
    font-size: 0.8125rem;
}

.popy-product-gift--pdp {
    margin: 0.75rem 0;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--gift-line);
    border-radius: 0.75rem;
    background: var(--gift-surface);
}

.popy-product-gift__img {
    width: 3.5rem;
    height: 3.5rem;
    flex-shrink: 0;
    object-fit: contain;
}

.popy-product-gift--tile {
    position: absolute;
    z-index: 1;
    left: 0.375rem;
    right: 0.375rem;
    bottom: 0.375rem;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    background: var(--gift-surface);
    box-shadow: 0 0 0 1px var(--gift-line);
    font-size: 0.75rem;
}

.popy-product-gift--tile .popy-product-gift__icon {
    width: 0.875rem;
    height: 0.875rem;
}

.popy-product-gift--tile .popy-product-gift__text {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.popy-product-gift--cart {
    margin-top: 0.25rem;
}
