/**
 * Cart Drawer — premium jewellery cart panel.
 *
 * EVERY rule here is scoped to .cart-drawer. The base drawer styles in
 * menu-drawer.css (.opsim-drawer, .drawer-overlay, .drawer-content,
 * .drawer-header, .drawer-close) are shared with the menu drawer and the
 * categories drawer, so overriding them unscoped would restyle both. The
 * heavy black header and the 50%-opacity page overlay come from there and are
 * neutralised for the cart drawer only.
 *
 * Visual identity matches the product card (product-card.css): warm ivory
 * image ground, hairline borders, var(--opsim-radius), ink type, brand colour
 * reserved for the CTA. Item rows are separated by hairlines rather than boxed
 * into cards — lighter, and it stops the panel reading as a stack of tiles.
 *
 * Markup contract used by assets/js/modules/cart.js (do not rename):
 *   #opsim-cart-drawer, .is-active, .is-loading, .drawer-overlay,
 *   .drawer-close, .cart-item[data-cart-key], .cart-item-remove,
 *   .qty-btn[data-action], .qty-input
 */

.cart-drawer {
    --cd-ink: #1a1a1a;
    --cd-muted: #776f67; /* 4.9:1 on white, 4.5:1 on #f5f5f5 (WCAG AA); was #8a8279, 3.8:1. */
    --cd-hairline: rgba(26, 26, 26, 0.09);
    --cd-ground: #f6f3f0;          
    --cd-pad: clamp(14px, 4vw, 18px);
}

.cart-drawer .drawer-content {
    left: auto;
    right: 0;
    /* Controlled width: 400px on desktop, full width on every phone in the
       320–430px range, and never wider than the viewport, so the drawer can
       never introduce horizontal scrolling. */
    width: min(100%, 400px);
    max-width: none;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
    background: #fff;
    border-left: 1px solid var(--cd-hairline);
    /* The shared rule casts its shadow to the right (2px 0), i.e. off-screen
       for a right-hand drawer. Replaced with a whisper to the left. */
    box-shadow: -1px 0 3px rgba(26, 26, 26, 0.04);
}

.opsim-drawer.cart-drawer.is-active .drawer-content {
    transform: translateX(0);
}

/* Light backdrop: enough to lift the panel off the page, not enough to black
   the site out. The element stays clickable — cart.js closes the drawer on
   .drawer-overlay clicks — so no pointer-events change here. */
.cart-drawer .drawer-overlay {
    background: rgba(26, 26, 26, 0.15);
}

.cart-drawer .drawer-header {
    background: #fff;
    color: var(--cd-ink);
    height: auto;
    min-height: 52px;
    padding: 14px var(--cd-pad);
    border-bottom: 1px solid var(--cd-hairline);
}

.cart-drawer .drawer-title {
    font-family: var(--opsim-font-primary, inherit);
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--cd-ink);
    margin: 0;
}

.cart-drawer .cart-drawer-count {
    font-size: 0.78rem;
    font-weight: 400;
    letter-spacing: 0.06em;
    color: var(--cd-muted);
    opacity: 1;
    margin-left: 4px;
}

.cart-drawer .drawer-close {
    color: var(--cd-ink);
    opacity: 0.55;
    padding: 4px;
    margin-right: -4px;
}

.cart-drawer .drawer-close:hover {
    opacity: 1;
}

.cart-drawer .drawer-close svg {
    width: 17px;
    height: 17px;
}

.cart-drawer .cart-drawer-items-wrapper {
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 0;
}

.cart-drawer .cart-drawer-items {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.cart-drawer .cart-item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 14px var(--cd-pad);
    border: 0;
    border-bottom: 1px solid var(--cd-hairline);
    border-radius: 0;
    background: transparent;
    position: relative;
}

.cart-drawer .cart-item:last-child {
    border-bottom: 0;
}

.cart-drawer .cart-item-image {
    display: block;
    width: 64px;
    flex-shrink: 0;
    aspect-ratio: 1 / 1;
    height: auto;
    overflow: hidden;
    background: var(--cd-ground);
    border: 1px solid var(--cd-hairline);
    border-radius: var(--opsim-radius);
}

.cart-drawer .cart-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.cart-drawer .cart-item-details {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.cart-drawer .cart-item-info {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    width: 100%;
}

.cart-drawer .cart-item-title {
    flex: 1;
    min-width: 0;
    max-width: none;
    margin: 0;
    font-family: var(--opsim-font-primary, inherit);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    line-height: 1.4;
    color: var(--cd-ink);
}

.cart-drawer .cart-item-title a {
    color: inherit;
    text-decoration: none;
}

/* WooCommerce variation / item meta, when a variable product is in the cart. */
.cart-drawer .cart-item-details .variation {
    margin: 4px 0 0;
    font-size: 0.66rem;
    line-height: 1.4;
    color: var(--cd-muted);
}

.cart-drawer .cart-item-details .variation dt,
.cart-drawer .cart-item-details .variation dd {
    display: inline;
    margin: 0;
    font-weight: 400;
}

.cart-drawer .cart-item-details .variation dd + dt::before {
    content: " · ";
}

.cart-drawer .cart-item-details .variation p {
    margin: 0;
    display: inline;
}

.cart-drawer .cart-item-price {
    margin: 5px 0 0;
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    /* Ink, not brand: brand colour stays reserved for the CTA. */
    color: var(--cd-ink);
}

.cart-drawer .cart-item-price .amount,
.cart-drawer .cart-item-price bdi {
    color: inherit;
    font-weight: inherit;
}

.cart-drawer .cart-item-actions {
    display: flex;
    align-items: center;
    margin-top: 8px;
}

.cart-drawer .cart-item-remove {
    flex-shrink: 0;
    background: none;
    border: none;
    /* Padding, not icon size, carries the tap target: the glyph stays 15px and
       visually quiet while the hit area is 25px desktop / 33px mobile. The
       matching negative margin keeps the icon optically on the row's edge. */
    padding: 5px;
    margin: -5px -5px 0 0;
    cursor: pointer;
    color: var(--cd-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    /* No transition: the brief asks for no hover animation on this control. */
}

.cart-drawer .cart-item-remove:hover {
    color: var(--cd-ink);
}

.cart-drawer .cart-item-remove svg {
    width: 15px;
    height: 15px;
    display: block;
}

.cart-drawer .quantity-control {
    display: flex;
    align-items: center;
    height: 28px;
    border: 1px solid var(--cd-hairline);
    border-radius: var(--opsim-radius);
    overflow: hidden;
    background: #fff;
}

.cart-drawer .qty-btn {
    width: 28px;
    height: 100%;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1;
    color: var(--cd-ink);
}

.cart-drawer .qty-btn:hover {
    background: var(--cd-ground);
}

.cart-drawer .qty-input {
    width: 30px;
    height: 100%;
    border: none;
    border-left: 1px solid var(--cd-hairline);
    border-right: 1px solid var(--cd-hairline);
    border-radius: 0;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--cd-ink);
    background: #fff;
    -moz-appearance: textfield;
    appearance: textfield;
    padding: 0;
}

.cart-drawer .qty-input::-webkit-outer-spin-button,
.cart-drawer .qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.cart-drawer .drawer-footer {
    padding: 14px var(--cd-pad) calc(var(--cd-pad) + 2px);
    background: #fff;
    border-top: 1px solid var(--cd-hairline);
    margin-top: auto;
}

.cart-drawer .cart-total-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 12px;
}

.cart-drawer .total-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--cd-muted);
}

.cart-drawer .total-amount {
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--cd-ink);
}

.cart-drawer .total-amount .amount,
.cart-drawer .total-amount bdi {
    color: inherit;
    font-weight: inherit;
}

/* ── Totals block ─────────────────────────────────────────────────────
   Its own wrapper because inc/woocommerce/coupons/ replaces the inner HTML of
   .opsim-cart-totals when a coupon changes, instead of swapping the whole
   drawer — which would close the customer's keyboard and lose the scroll
   position of a long basket.

   With no coupon applied there is exactly one row inside and the block is
   indistinguishable from the single .cart-total-row this replaced. The tighter
   6px rhythm below only ever applies once there is more than one. */

.cart-drawer .opsim-cart-totals .cart-total-row {
    margin-bottom: 6px;
}

.cart-drawer .opsim-cart-totals .cart-total-row:last-child {
    margin-bottom: 12px;
}

.cart-drawer .cart-total-row--discount .total-label,
.cart-drawer .cart-total-row--discount .total-amount {
    color: #15803d;
}

.cart-drawer .cart-total-row--discount .total-amount {
    font-size: 0.85rem;
}

/* The real total, once a discount has moved it away from the subtotal. */
.cart-drawer .cart-total-row--total {
    padding-top: 8px;
    border-top: 1px solid var(--cd-hairline);
}

.cart-drawer .cart-total-row--total .total-amount {
    font-size: 1.02rem;
    font-weight: 700;
    color: var(--opsim-brand, #531628);
}

/* Colour, border, radius and shadow come from the button contract in
   assets/css/base.css; only the drawer-specific width is set here. */
.cart-drawer .checkout-button {
    width: 100%;
}

.cart-drawer .empty-cart-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 32px 24px 40px;
    text-align: center;
}

.cart-drawer .empty-cart-icon {
    width: 34px;
    height: 34px;
    color: var(--cd-muted);
    opacity: 0.75;
    margin: 0 0 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cart-drawer .empty-cart-icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

.cart-drawer .empty-cart-message {
    margin: 0 0 18px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    line-height: 1.5;
    color: var(--cd-ink);
}

.cart-drawer .return-to-shop {
    font-size: 0.72rem;
    letter-spacing: 0.1em;
}

@media (max-width: 767px) {
    .cart-drawer .drawer-content {
        /* Full width at 320–430px; the min() above already prevents overflow. */
        border-left: 0;
    }

    .cart-drawer .cart-item {
        gap: 11px;
        padding-top: 12px;
        padding-bottom: 12px;
    }

    .cart-drawer .cart-item-image {
        width: 56px;
    }

    .cart-drawer .cart-item-title {
        font-size: 0.7rem;
    }

    /* Bigger tap targets than desktop, without growing the visual weight. */
    .cart-drawer .quantity-control {
        height: 32px;
    }

    .cart-drawer .qty-btn {
        width: 32px;
        font-size: 0.9rem;
    }

    .cart-drawer .qty-input {
        width: 32px;
    }

    .cart-drawer .cart-item-remove {
        padding: 9px;
        margin: -9px -9px 0 0;
    }

    .cart-drawer .empty-cart-container {
        padding: 28px 20px 36px;
    }
}

.cart-drawer.is-loading .drawer-content {
    pointer-events: none;
}

.cart-drawer.is-loading .drawer-footer {
    pointer-events: auto; 
}

.cart-drawer.is-loading .drawer-content::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 2px solid var(--cd-hairline);
    border-top-color: var(--opsim-brand, #531628);
    border-radius: 50%;
    animation: cart-drawer-spin 0.8s linear infinite;
    z-index: 100;
}

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

.cart-drawer.is-loading .drawer-body,
.cart-drawer.is-loading .drawer-footer {
    opacity: 0.5;
    transition: opacity 0.2s;
}

/* Row being removed.
   assets/js/modules/cart.js used to write these two declarations as inline
   styles on the element; a class keeps presentation in the stylesheet and
   lets the fade be animated. The row is replaced by the fragment response a
   moment later, so this state is short-lived by design. */
.cart-drawer .cart-item.is-removing {
    opacity: 0.45;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

@media (prefers-reduced-motion: reduce) {
    .cart-drawer .cart-item.is-removing {
        transition: none;
    }
}
