/*
 * Free-shipping bar (#1326): mini cart, cart page and the add-to-cart panel.
 * Colours and radii come from the theme tokens (popy-csp, asgano-csp); asgano's
 * --color-ok/--color-line are used where they exist, popy falls back to primary.
 */
popy-freeship {
    --fs-fg: var(--color-fg, #0a0a0a);
    --fs-muted: var(--color-fg-secondary, #666666);
    --fs-accent: var(--color-primary, #0a0a0a);
    --fs-on-accent: var(--color-on-primary, #ffffff);
    --fs-ok: var(--color-ok, var(--color-primary, #0a0a0a));
    --fs-line: var(--color-line, rgb(10 10 10 / 0.1));
    --fs-surface: var(--color-surface, #ffffff);
    --fs-radius: var(--radius-md, 0.5rem);
    display: block;
    color: var(--fs-fg);
}

popy-freeship[hidden] {
    display: none;
}

/* Cart page: keep the bar's height while the script loads, so the items do not jump. */
popy-freeship[data-context="cart"]:not(:defined) {
    display: block;
    min-height: 3.5rem;
}

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

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

.popy-fs__msg {
    margin: 0 0 0.5rem;
    font-size: 0.875rem;
    line-height: 1.35;
}

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

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

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

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

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

popy-freeship[data-state="reached"] .popy-fs__fill {
    background: var(--fs-ok);
}

.popy-fs__check {
    display: inline-block;
    flex: none;
    margin-right: 0.25rem;
    vertical-align: -0.15em;
    width: 1rem;
    height: 1rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

popy-freeship[data-state="reached"] .popy-fs__msg .popy-fs__check {
    color: var(--fs-ok);
}

popy-freeship.is-celebrating .popy-fs__track {
    animation: popy-fs-pulse 0.9s ease-out 1;
}

@keyframes popy-fs-pulse {
    0% { box-shadow: 0 0 0 0 var(--fs-ok); }
    100% { box-shadow: 0 0 0 0.5rem transparent; }
}

/* Suggestions: up to three cards side by side, also on a phone. */
.popy-fs__sugs {
    margin-top: 0.875rem;
}

.popy-fs__sugs[hidden],
.popy-fs-drawer-sugs[hidden] {
    display: none;
}

.popy-fs__h {
    margin: 0 0 0.5rem;
    color: var(--fs-muted, var(--color-fg-secondary, #666666));
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.popy-fs__list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.popy-fs__card {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
    padding: 0.5rem;
    border: 1px solid var(--fs-line, rgb(10 10 10 / 0.1));
    border-radius: var(--fs-radius, 0.5rem);
    background: var(--fs-surface, #ffffff);
}

.popy-fs__img {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 4.5rem;
    overflow: hidden;
    border-radius: var(--radius-sm, 0.25rem);
}

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

.popy-fs__name {
    display: -webkit-box;
    overflow: hidden;
    color: inherit;
    font-size: 0.75rem;
    line-height: 1.3;
    text-decoration: none;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    min-height: 2.6em;
}

.popy-fs__name:hover,
.popy-fs__name:focus-visible {
    text-decoration: underline;
}

.popy-fs__price {
    font-size: 0.8125rem;
    font-weight: 700;
    white-space: nowrap;
}

.popy-fs__add {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    min-height: 2.75rem;
    margin-top: auto;
    padding: 0 0.5rem;
    border: 0;
    border-radius: var(--radius-xl, 999px);
    background: var(--fs-accent, var(--color-primary, #0a0a0a));
    color: var(--fs-on-accent, var(--color-on-primary, #ffffff));
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.1;
    text-align: center;
    hyphens: auto;
    cursor: pointer;
}

/* Narrow cards (three side by side on a phone): label only, a little smaller, so long words fit. */
.popy-fs__card {
    container-type: inline-size;
}

@container (max-width: 8.5rem) {
    .popy-fs__add {
        padding: 0 0.25rem;
        font-size: 0.75rem;
    }

    .popy-fs__plus {
        display: none;
    }
}

.popy-fs__add:focus-visible {
    outline: 2px solid var(--fs-accent, #0a0a0a);
    outline-offset: 2px;
}

.popy-fs__add[data-state="busy"] {
    opacity: 0.6;
    cursor: progress;
}

.popy-fs__add[data-state="done"] {
    background: var(--fs-ok, var(--color-primary, #0a0a0a));
    cursor: default;
}

.popy-fs__add[data-state="error"] {
    background: transparent;
    color: var(--fs-fg, #0a0a0a);
    box-shadow: inset 0 0 0 1px currentColor;
    font-size: 0.6875rem;
}

.popy-fs__plus {
    font-size: 1rem;
    line-height: 1;
}

.popy-fs__plus:empty {
    display: none;
}

/* Mini cart: the cards are the last row of the scrolling item list. */
.popy-fs-drawer-sugs {
    list-style: none;
    padding: 0.25rem 1rem 1rem;
}

.popy-fs-drawer-sugs .popy-fs__sugs {
    margin-top: 0.5rem;
}

/* Add-to-cart panel: top right on every viewport, clear of the sticky buy bar and the chat button. */
.popy-fs-panel {
    position: fixed;
    top: 0.75rem;
    right: 0.75rem;
    z-index: 60;
    width: min(26rem, calc(100% - 1.5rem));
    max-height: calc(100% - 1.5rem);
    overflow-y: auto;
    padding: 1rem;
    border-radius: var(--radius-lg, 0.75rem);
    background: var(--color-surface, #ffffff);
    color: var(--color-fg, #0a0a0a);
    box-shadow: 0 24px 64px -16px rgb(10 10 10 / 0.35), 0 2px 8px rgb(10 10 10 / 0.08);
    animation: popy-fs-in 0.25s ease-out;
}

.popy-fs-panel[hidden] {
    display: none;
}

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

.popy-fs-panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.popy-fs-panel__title {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 700;
}

.popy-fs-panel__title .popy-fs__check {
    color: var(--color-ok, var(--color-primary, #0a0a0a));
}

.popy-fs-panel__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    margin: -0.5rem -0.5rem -0.5rem 0;
    border: 0;
    background: transparent;
    color: inherit;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}

.popy-fs-panel popy-freeship {
    padding-top: 0.5rem;
}

.popy-fs-panel__cart {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 2.75rem;
    margin-top: 0.875rem;
    border-radius: var(--radius-xl, 999px);
    box-shadow: inset 0 0 0 1px var(--color-primary, #0a0a0a);
    color: var(--color-primary, #0a0a0a);
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
}

@media (prefers-reduced-motion: reduce) {
    .popy-fs__fill,
    .popy-fs-panel {
        transition: none;
        animation: none;
    }
}
