/**
 * woocommerce/mini-cart block styles.
 *
 * Hand-written plain CSS -- the same shape as assets/css/blocks/woocommerce/cart.css: no
 * Tailwind source, no `@apply`, no build step. The file is enqueued as-is for
 * the mini-cart block from inc/class-groceria.php, so edit it directly and do
 * not add it to the `css:*` scripts in package.json. Values come from
 * theme.json presets (`var(--wp--preset--color--...)`) and literal rems, so it
 * stands on its own without the Tailwind variables output.css defines.
 *
 * WooCommerce ships the rules this file argues with in
 * assets/client/blocks/mini-cart.css (trigger, drawer chrome, panel frame) and
 * mini-cart-contents.css (the items table). Their deepest frontend selectors
 * reach four classes plus an element -- e.g.
 * `.is-mobile table.wc-block-cart-items .wc-block-cart-items__row .wc-block-cart-item__image`
 * -- and load order between two block stylesheets is not guaranteed. So every
 * override is rooted one class deeper than its core counterpart: panel chrome
 * at `.wp-block-woocommerce-mini-cart-contents`, the items table at that plus
 * `table.wc-block-cart-items.wc-block-mini-cart-items`. Keep those roots when
 * adding rules; that is what lands each rule above core on specificity alone.
 *
 * There are exactly two `!important` declarations, both unavoidable, both
 * commented where they sit: one beats an inline style WooCommerce writes onto
 * <body>, the other beats core's own `!important` on the close button's
 * padding. Add no others.
 *
 * Sections:
 *   1. Page scroll lock
 *   2. Header trigger
 *   3. Drawer shell
 *   4. Panel: title and close
 *   5. Panel: items list
 *   6. Panel: one item
 *   7. Panel: footer
 *   8. Panel: empty cart
 */

/* --------------------------------------------------------------------------
 * 1. Page scroll lock
 *
 * While the drawer is open WooCommerce writes
 * `body { overflow: hidden; padding-right: <scrollbar width>px }` inline. That
 * keeps the *body* box the same width, but the viewport itself grows by the
 * scrollbar it just removed, so everything measured against the viewport --
 * fixed elements, `100vw`, centred backgrounds -- jumps sideways as the drawer
 * slides in and jumps back as it slides out.
 *
 * Reserving the scrollbar's column permanently removes the cause rather than
 * paying it back: hiding the scrollbar no longer changes any width. The
 * repayment then has nothing to repay and would itself become the shift, so it
 * is zeroed -- and since it is an inline style, only `!important` reaches it.
 * The theme puts no padding on <body> of its own (root padding lives on
 * .wp-site-blocks), so nothing else is caught by this.
 * ----------------------------------------------------------------------- */

html {
    scrollbar-gutter: stable;
}

body {
    /* stylelint-disable-next-line declaration-no-important -- beats WooCommerce's inline body style. */
    padding-right: 0 !important;
}

/* --------------------------------------------------------------------------
 * 2. Header trigger
 *
 * The button that opens the drawer. Each header pattern (patterns/header.php
 * and header-v2..v5) wraps it in `.header.v1` ... `.header.v5`, and the five
 * differ enough that the shared rules are worth stating once. `lg` here is the
 * 64rem breakpoint the header patterns are built around.
 * ----------------------------------------------------------------------- */

.header.v2 .wc-block-mini-cart__badge,
.header.v3 .wc-block-mini-cart__badge,
.header.v4 .wc-block-mini-cart__badge,
.header.v5 .wc-block-mini-cart__badge {
    width: 1.125rem;
    height: 1.125rem;
    font-size: 0.5rem;
}

.header.v2 .wc-block-mini-cart__badge {
    color: var(--wp--preset--color--primary);
}

.header.v2 .wc-block-mini-cart__button {
    padding-block: 0;
}

.header.v2 .wc-block-mini-cart__amount,
.header.v3 .wc-block-mini-cart__amount,
.header.v4 .wc-block-mini-cart__amount {
    margin-left: 0.25rem;
}

@media (max-width: 63.999rem) {
    .header.v2 .mini-cart-outer {
        padding: 0;
        border: 0;
    }

    .header.v2 .wc-block-mini-cart__button .wc-block-mini-cart__amount,
    .header.v3 .wc-block-mini-cart__button .wc-block-mini-cart__amount,
    .header.v4 .wc-block-mini-cart__button .wc-block-mini-cart__amount,
    .header.v5 .wc-block-mini-cart__button .wc-block-mini-cart__amount {
        display: none;
    }
}

@media (min-width: 64rem) {
    .header.v1 .wc-block-mini-cart.wp-block-woocommerce-mini-cart {
        display: flex;
        width: 3.125rem;
        height: 3.125rem;
        align-items: center;
        justify-content: center;
        border: 1px solid var(--wp--preset--color--pale-gray);
        border-radius: 0.5rem;
    }

    .header.v1 .wc-block-mini-cart__badge {
        top: -0.625rem;
        width: 1.125rem;
        height: 1.125rem;
        margin-left: 0;
        font-size: 0.5rem;
    }

    .header.v5 .wc-block-mini-cart__button {
        flex-direction: column;
    }
}

/* --------------------------------------------------------------------------
 * 3. Drawer shell
 *
 * The design floats the panel as a rounded card rather than butting it against
 * the viewport edges, so the drawer itself is only a transparent frame: it
 * keeps core's slide-in transform and hands the white, rounded surface to
 * .wc-block-mini-cart__template-part inside it.
 *
 * --drawer-width is set on the drawer element, not on :root. WooCommerce
 * prints `:root { --drawer-width: ... }` inline from the block's own width
 * attribute (MiniCartContents::get_styles), and an inline <style> later in the
 * document would win the :root tie; a declaration on the element cannot lose
 * it. 32.5rem is the design's 500px panel plus the 20px frame either side.
 * ----------------------------------------------------------------------- */

.wc-block-mini-cart__drawer.wc-block-components-drawer {
    --drawer-width: 32.5rem;
    --neg-drawer-width: calc(var(--drawer-width) * -1);

    padding: 1.25rem;
    background: transparent;
}

/* Above 48rem the drawer is narrower than the viewport, so it needs no gutter
 * on the side it slides in from -- dropping it leaves the design's 500px
 * panel inside the 520px drawer. */
@media (min-width: 48rem) {
    .wc-block-mini-cart__drawer.wc-block-components-drawer {
        padding-left: 0;
    }
}

.wc-block-components-drawer__screen-overlay--with-slide-in {
    backdrop-filter: blur(5px);
}

.wc-block-mini-cart__drawer .wc-block-components-drawer__content {
    height: calc(100dvh - 2.5rem);
}

.admin-bar .wc-block-mini-cart__drawer .wc-block-components-drawer__content {
    height: calc(100dvh - var(--wp-admin--admin-bar--height, 0px) - 2.5rem);
    margin-top: var(--wp-admin--admin-bar--height, 0);
}

.wc-block-mini-cart__drawer .wc-block-mini-cart__template-part {
    overflow: hidden;
    border-radius: 0.75rem;
}

/* --------------------------------------------------------------------------
 * 4. Panel: title and close
 *
 * Core gives the title `font-size: 2em`, a 16px margin box and a
 * -32px/+32px margin/padding pair masked with a gradient, which fades whatever
 * scrolls under it. The design has no such overlap -- the title sits in the
 * panel's 30px/40px padding and the list starts below it -- so the mask and
 * both offsets go.
 * ----------------------------------------------------------------------- */

.wc-block-mini-cart__drawer .wp-block-woocommerce-mini-cart-contents {
    color: var(--wp--preset--color--primary);
}

.wp-block-woocommerce-mini-cart-contents h2.wc-block-mini-cart__title {
    align-items: center;
    margin: 0;
    padding: 1.875rem 5rem 0 2.5rem;
    font-size: var(--wp--preset--font-size--xl);
    font-weight: 600;
    line-height: 1.4;
    color: var(--wp--preset--color--primary);
    text-transform: capitalize;
    mask-image: none;
}

.wc-block-mini-cart__drawer .wp-block-woocommerce-mini-cart-contents .wc-block-components-button.wc-block-components-drawer__close {
    top: 1.875rem;
    right: 1.6875rem;
    display: flex;
    width: 2.1875rem;
    height: 2.1875rem;

    /* Core gives every button `min-height: 3em` on themes without
     * `woocommerce-block-theme-has-button-styles`, at one class more than the
     * root above; hence the extra `.wc-block-mini-cart__drawer`. */
    min-height: 0;
    align-items: center;
    justify-content: center;
    margin: 0;

    /* stylelint-disable-next-line declaration-no-important -- core sets `padding: 1em !important`. */
    padding: 0 !important;
    border-radius: 3.75rem;
    box-shadow: none;
    opacity: 1;
}

.wc-block-mini-cart__drawer .wp-block-woocommerce-mini-cart-contents .wc-block-components-drawer__close svg {
    width: 0.875rem;
    height: 0.875rem;
}

/* --------------------------------------------------------------------------
 * 5. Panel: items list
 *
 * The scroll container runs the full width of the panel so its scrollbar sits
 * against the panel edge, the way the design draws it; the 40px gutter the
 * items need is padding inside it, less the 6px the bar occupies.
 * ----------------------------------------------------------------------- */

.wp-block-woocommerce-mini-cart-contents .wc-block-mini-cart__items {
    padding: 2.5rem 2.125rem 0 2.5rem;
    scrollbar-color: rgb(118 118 118 / 70%) transparent;
    scrollbar-width: thin;
}

.wp-block-woocommerce-mini-cart-contents .wc-block-mini-cart__items::-webkit-scrollbar {
    width: 0.375rem;
}

.wp-block-woocommerce-mini-cart-contents .wc-block-mini-cart__items::-webkit-scrollbar-thumb {
    border-radius: 0.375rem;
    background: rgb(118 118 118 / 70%);
}

.wp-block-woocommerce-mini-cart-contents .wc-block-mini-cart__items::-webkit-scrollbar-track {
    background: transparent;
}

/* --------------------------------------------------------------------------
 * 6. Panel: one item
 *
 * Core lays the row out as a two-column grid (image, then everything else) and
 * already nests the quantity selector and the remove control inside the
 * product cell, so the design's shape needs only new column widths -- and the
 * per-line total column, which the design does not show, taken out.
 * ----------------------------------------------------------------------- */

.wp-block-woocommerce-mini-cart-contents table.wc-block-cart-items.wc-block-mini-cart-items {
    .wc-block-cart-items__row {
        grid-template-columns: 6.25rem 1fr;
        padding: 0 0 1.25rem;
        column-gap: 1.25rem;
    }

    .wc-block-cart-items__row:last-child {
        padding-bottom: 0;
    }

    .wc-block-cart-item__total {
        display: none;
    }

    .wc-block-cart-items__row .wc-block-cart-item__image {
        padding: 0;
    }

    /*
     * The thumbnail sits in a bordered 100x110 well. Core prints two images in
     * this cell -- a bare one for products hidden from the catalogue, a linked
     * one for the rest -- and hides whichever does not apply, so the well goes
     * on both. `:not([hidden])` is what stops an author `display` from
     * un-hiding the one that is off, and it is also why the linked thumbnail's
     * rule has to be stated first: it is the less specific of the two, and
     * stylelint reads a lower specificity arriving later as a mistake.
     */

    /* Linked: a 70px thumbnail centred in the well. */
    .wc-block-cart-items__row .wc-block-cart-item__image > a > img {
        width: 4.375rem;
        height: 4.375rem;
        object-fit: contain;
    }

    .wc-block-cart-items__row .wc-block-cart-item__image > a,
    .wc-block-cart-items__row .wc-block-cart-item__image > img:not([hidden]) {
        display: flex;
        width: 6.25rem;
        height: 6.875rem;
        box-sizing: border-box;
        align-items: center;
        justify-content: center;
        border: 1px solid var(--wp--preset--color--pale-gray);
        border-radius: 0.5rem;
    }

    /* Bare: the image *is* the well, so it keeps the same optical inset. */
    .wc-block-cart-items__row .wc-block-cart-item__image > img:not([hidden]) {
        padding: 1.25rem 0.9375rem;
        object-fit: contain;
    }

    .wc-block-cart-items__row .wc-block-cart-item__wrap {
        justify-content: center;
        gap: 0.9375rem;
    }

    .wc-block-cart-items__row .wc-block-components-product-name {
        max-width: none;
        font-size: var(--wp--preset--font-size--sm-plus);
        font-weight: 600;
        line-height: 1.6;
        color: var(--wp--preset--color--primary);
        text-decoration: none;
    }

    .wc-block-cart-items__row .wc-block-cart-item__prices {
        gap: 0.625rem;
    }

    .wc-block-cart-item__prices .wc-block-components-product-price__value {
        font-size: var(--wp--preset--font-size--sm);
        font-weight: 500;
        color: var(--wp--preset--color--primary);
        text-decoration: none;
    }

    /*
     * Core prints <del> before <ins>; the design reads the other way round.
     * `.price` is already a flex row, so ordering is enough -- and screen
     * readers keep following the source, where each amount still sits after
     * the "Previous price:"/"Discounted price:" label that introduces it.
     */
    .wc-block-cart-item__prices .wc-block-components-product-price__regular {
        order: 1;
        font-size: 0.6875rem;
        font-weight: 400;
        color: var(--wp--preset--color--charcoal);
    }

    .wc-block-components-product-metadata,
    .wc-block-components-product-metadata .wc-block-components-product-metadata__description > p,
    .wc-block-components-product-metadata .wc-block-components-product-metadata__variation-data {
        font-size: var(--wp--preset--font-size--xs-plus);
        line-height: 1.4;
        color: var(--wp--preset--color--charcoal);
    }

    /* Quantity stepper and remove control share the row's last line. */
    .wc-block-cart-items__row .wc-block-cart-item__quantity {
        width: 100%;
        padding: 0;
        gap: 0.9375rem;
    }

    .wc-block-components-quantity-selector {
        width: 5rem;
        height: 2.1875rem;
        border: 1px solid var(--wp--preset--color--pearl);
        border-radius: 0.5rem;
    }

    .wc-block-components-quantity-selector input.wc-block-components-quantity-selector__input {
        min-width: 0;
        padding: 0;
        font-size: var(--wp--preset--font-size--xs-plus);
        font-weight: 400;
        color: var(--wp--preset--color--contrast);
    }

    .wc-block-components-quantity-selector input.wc-block-components-quantity-selector__input:focus {
        box-shadow: none;
    }

    .wc-block-components-quantity-selector .wc-block-components-quantity-selector__button {
        min-width: 1.5625rem;
        color: var(--wp--preset--color--contrast);
        opacity: 1;
    }

    /*
     * The design labels this control "Remove" rather than showing core's bin
     * glyph. The label is content, so it stays translatable: PHP hands it over
     * in --groceria-mini-cart-remove-label (see Groceria::add_mini_cart_labels()),
     * and only the styling lives here. The button keeps its own aria-label
     * either way, so the swap costs nothing in the accessibility tree.
     */
    .wc-block-cart-items__row .wc-block-cart-item__quantity .wc-block-cart-item__remove-link {
        width: auto;
        height: auto;
        margin-left: auto;
        font-size: var(--wp--preset--font-size--xs);
        font-weight: 500;
        line-height: 1.8333;
        color: var(--wp--preset--color--contrast);
        text-decoration: underline;
    }

    .wc-block-cart-item__quantity .wc-block-cart-item__remove-link svg {
        display: none;
    }

    .wc-block-cart-item__quantity .wc-block-cart-item__remove-link::after {
        content: var(--groceria-mini-cart-remove-label, "");
    }
}

/* --------------------------------------------------------------------------
 * 7. Panel: footer
 * ----------------------------------------------------------------------- */

.wp-block-woocommerce-mini-cart-contents .wc-block-mini-cart__footer {
    padding: 1.5rem 2.5rem 1.875rem;
    border-top: 1px solid var(--wp--preset--color--pearl);
}

.wp-block-woocommerce-mini-cart-contents .wc-block-mini-cart__footer .wc-block-components-totals-item.wc-block-mini-cart__footer-subtotal {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.9375rem;
    margin-bottom: 1.25rem;
    font-size: var(--wp--preset--font-size--xl);
    font-weight: 600;
    line-height: 1.4;
    color: var(--wp--preset--color--primary);
    text-transform: capitalize;
}

/*
 * "Shipping, taxes, and discounts calculated at checkout." Core shows it from
 * 480px up; the design has no line under the subtotal.
 */
.wp-block-woocommerce-mini-cart-contents .wc-block-mini-cart__footer .wc-block-components-totals-item.wc-block-mini-cart__footer-subtotal .wc-block-components-totals-item__description {
    display: none;
}

.wp-block-woocommerce-mini-cart-contents .wc-block-mini-cart__footer .wc-block-mini-cart__footer-actions {
    flex-direction: column;
    gap: 0.625rem;
}

.wp-block-woocommerce-mini-cart-contents .wc-block-mini-cart__footer .wc-block-mini-cart__footer-actions .wc-block-components-button {
    height: 3.375rem;
    box-sizing: border-box;
    padding: 1rem 1.875rem;
    border-radius: 0.5rem;
    font-size: var(--wp--preset--font-size--sm);
    font-weight: 500;
    line-height: 1;
    text-transform: uppercase;
}

/*
 * View cart -- outlined. Core paints `.is-style-outline` with an inset
 * currentColor ring and turns it near-black on hover, both at four classes
 * (`:not()` counts its argument), so these carry five.
 */
.wp-block-woocommerce-mini-cart-contents .wc-block-mini-cart__footer .wc-block-mini-cart__footer-actions .wc-block-components-button.wc-block-mini-cart__footer-cart {
    border: 1px solid var(--wp--preset--color--secondary);
    background: transparent;
    box-shadow: 0 4px 10px 0 rgb(14 137 63 / 20%);
    color: var(--wp--preset--color--primary);
}

.wp-block-woocommerce-mini-cart-contents .wc-block-mini-cart__footer .wc-block-mini-cart__footer-actions .wc-block-components-button.wc-block-mini-cart__footer-cart:hover,
.wp-block-woocommerce-mini-cart-contents .wc-block-mini-cart__footer .wc-block-mini-cart__footer-actions .wc-block-components-button.wc-block-mini-cart__footer-cart:focus,
.wp-block-woocommerce-mini-cart-contents .wc-block-mini-cart__footer .wc-block-mini-cart__footer-actions .wc-block-components-button.wc-block-mini-cart__footer-cart:active {
    background: var(--wp--preset--color--secondary);
    color: var(--wp--preset--color--white);
}

/* Checkout -- filled. */
.wp-block-woocommerce-mini-cart-contents .wc-block-mini-cart__footer .wc-block-mini-cart__footer-actions .wc-block-components-button.wc-block-mini-cart__footer-checkout {
    border: 1px solid var(--wp--preset--color--secondary);
    background: var(--wp--preset--color--secondary);
    box-shadow: 0 4px 5px 0 rgb(14 137 63 / 20%);
    color: var(--wp--preset--color--white);
}

.wp-block-woocommerce-mini-cart-contents .wc-block-mini-cart__footer .wc-block-mini-cart__footer-actions .wc-block-components-button.wc-block-mini-cart__footer-checkout:hover,
.wp-block-woocommerce-mini-cart-contents .wc-block-mini-cart__footer .wc-block-mini-cart__footer-actions .wc-block-components-button.wc-block-mini-cart__footer-checkout:focus,
.wp-block-woocommerce-mini-cart-contents .wc-block-mini-cart__footer .wc-block-mini-cart__footer-actions .wc-block-components-button.wc-block-mini-cart__footer-checkout:active {
    border-color: var(--wp--preset--color--primary);
    background: var(--wp--preset--color--primary);
}

/* --------------------------------------------------------------------------
 * 8. Panel: empty cart
 * ----------------------------------------------------------------------- */

/*
 * Only the gutter: core's 48px/16px box is squared up with the 40px the filled
 * panel uses either side, and the paragraphs inside keep their own margins.
 */
.wp-block-woocommerce-empty-mini-cart-contents-block .wc-block-mini-cart__empty-cart-wrapper {
    padding: 1.875rem 2.5rem;
}
