/**
 * Template Studio / EasyCommerce bridge styles: the slide-over cart
 * drawer, the floating cart button and cart line items. Every color,
 * radius and motion value comes from the template's --ec-* tokens, so
 * the drawer matches whatever preset is active.
 */

/* Floating cart button (fallback trigger) */
.ts-cart-fab {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 1200;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border: 1px solid var(--ec-accent);
    border-radius: 50%;
    background: var(--ec-accent);
    color: var(--ec-accent-fg);
    cursor: pointer;
    box-shadow: var(--ec-shadow);
    transition: transform var(--ec-dur-1) var(--ec-ease);
}

.ts-cart-fab:hover {
    transform: translateY(-2px);
}

.ts-cart-fab__badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 20px;
    height: 20px;
    padding-inline: 5px;
    border-radius: 999px;
    background: var(--ec-fg);
    color: var(--ec-bg);
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
}

/* Drawer */
.ts-drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1290;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--ec-dur-2) var(--ec-ease);
}

.ts-drawer-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
}

.ts-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 1300;
    width: min(26rem, 92vw);
    display: flex;
    flex-direction: column;
    background: var(--ec-surface);
    color: var(--ec-fg);
    border-left: 1px solid var(--ec-border);
    transform: translateX(100%);
    transition: transform var(--ec-dur-3) var(--ec-ease);
}

.ts-drawer.is-open {
    transform: translateX(0);
}

.ts-drawer-lock {
    overflow: hidden;
}

.ts-drawer__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--ec-border);
}

.ts-drawer__title {
    margin: 0;
    font-size: 1.1rem;
}

.ts-drawer__close {
    appearance: none;
    border: none;
    background: none;
    color: var(--ec-fg-2);
    font-size: 1rem;
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
}

.ts-drawer__body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
}

.ts-drawer__foot {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--ec-border);
}

.ts-drawer__subtotal {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.ts-drawer__actions {
    display: flex;
    gap: 0.6rem;
}

.ts-drawer__actions .ts-btn {
    flex: 1;
    text-align: center;
}

/* Cart lines (drawer + cart page) */
.ts-cart-line {
    display: flex;
    gap: 0.85rem;
    padding-block: 0.85rem;
    border-bottom: 1px solid var(--ec-border);
}

.ts-cart-line__img {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: var(--ec-img-radius);
    background: var(--ec-surface-2);
    flex: none;
}

.ts-cart-line__info {
    flex: 1;
    min-width: 0;
}

.ts-cart-line__title {
    margin: 0 0 0.15rem;
    font-weight: 600;
}

.ts-cart-line__price {
    margin: 0 0 0.4rem;
    color: var(--ec-fg-2);
}

.ts-cart-line__qty {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    border: 1px solid var(--ec-border);
    border-radius: var(--ec-btn-radius);
}

.ts-qty-btn {
    appearance: none;
    border: none;
    background: none;
    color: var(--ec-fg);
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
    font-size: 1rem;
    border-radius: var(--ec-btn-radius);
    transition: background-color 120ms ease, transform 120ms ease;
}

.ts-qty-btn:hover {
    background: var(--ec-surface-2);
}

/* Immediate tactile response: the quantity repaints optimistically, so the
   press itself is the only confirmation the shopper needs. */
.ts-qty-btn:active {
    transform: scale(0.9);
}

.ts-qty-value {
    min-width: 1.5rem;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* A line (or subtotal) whose write is still in flight. Deliberately subtle:
   the new value is already shown and is almost always what the server confirms,
   so this hints "settling" rather than "blocked". */
.ts-cart-line.is-pending {
    opacity: 0.72;
}

.ts-drawer__subtotal strong.is-pending {
    opacity: 0.55;
}

.ts-cart-line,
.ts-drawer__subtotal strong {
    transition: opacity 160ms ease;
}

@media (prefers-reduced-motion: reduce) {
    .ts-qty-btn,
    .ts-cart-line,
    .ts-drawer__subtotal strong {
        transition: none;
    }

    .ts-qty-btn:active {
        transform: none;
    }
}

.ts-cart-line__remove {
    appearance: none;
    border: none;
    background: none;
    color: var(--ec-fg-2);
    cursor: pointer;
    font-size: 0.8rem;
    text-decoration: underline;
    align-self: flex-start;
    padding: 0.25rem 0;
}

.ts-cart-line__remove:hover {
    color: var(--ec-fg);
}

.ts-cart-empty,
.ts-cart-loading {
    color: var(--ec-fg-2);
    text-align: center;
    padding-block: 2rem;
}

.ts-cart-loading::after {
    content: '';
    display: block;
    width: 24px;
    height: 24px;
    margin: 0.75rem auto 0;
    border: 2px solid var(--ec-border);
    border-top-color: var(--ec-accent);
    border-radius: 50%;
    animation: ts-spin 0.7s linear infinite;
}

@keyframes ts-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .ts-cart-loading::after {
        animation-duration: 2s;
    }
}

/* Cart page: two-zone layout (line items + sticky order summary) */
.ts-cart-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(18rem, 22rem);
    gap: clamp(1.5rem, 4vw, 3rem);
    align-items: start;
    margin-top: 1.5rem;
}

@media (max-width: 899.98px) {
    .ts-cart-grid {
        grid-template-columns: 1fr;
    }
}

.ts-cart-lines {
    border-top: 1px solid var(--ec-border);
}

/* Roomier line items on the cart page than in the drawer */
.ts-cart-line--page {
    align-items: center;
    gap: 1.25rem;
    padding-block: 1.25rem;
}

.ts-cart-line--page .ts-cart-line__img {
    width: 88px;
    height: 88px;
    object-fit: contain;
    padding: 6px;
    border: 1px solid var(--ec-border);
}

.ts-cart-line--page .ts-cart-line__title {
    font-size: 1.05rem;
}

.ts-cart-line--page .ts-cart-line__qty {
    margin-top: 0.5rem;
}

.ts-cart-line--page .ts-cart-line__remove {
    align-self: center;
}

@media (max-width: 767.98px) {
    .ts-cart-line--page {
        flex-wrap: wrap;
    }
}

/* Order summary card (sticky on desktop) */
.ts-cart-aside {
    position: sticky;
    top: 1.5rem;
}

@media (max-width: 899.98px) {
    .ts-cart-aside {
        position: static;
    }
}

.ts-cart-summary-card {
    padding: 1.5rem;
    background: var(--ec-surface);
    border: 1px solid var(--ec-border);
    border-radius: var(--ec-radius);
    box-shadow: var(--ec-shadow);
}

.ts-cart-summary-card__title {
    margin: 0 0 1rem;
    font-size: 1.15rem;
}

.ts-cart-summary {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 1.1rem;
    font-weight: 600;
}

.ts-cart-summary strong {
    font-size: 1.25rem;
}

.ts-cart-summary__note {
    margin: 0.5rem 0 1.25rem;
    color: var(--ec-fg-2);
    font-size: 0.85rem;
}

.ts-cart-summary__checkout {
    width: 100%;
    justify-content: center;
}

/* Quick-add button loading state (feedback during the cart round-trip). */
[data-ec-quick-add].is-loading {
    pointer-events: none;
    opacity: 0.72;
}
[data-ec-quick-add].is-loading::before {
    content: "";
    display: inline-block;
    width: 0.9em;
    height: 0.9em;
    margin-right: 0.5em;
    vertical-align: -0.12em;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: ec-bridge-spin 0.6s linear infinite;
}
@keyframes ec-bridge-spin {
    to { transform: rotate(360deg); }
}
