/* Phase 4 Stage B - Sticky/Footer Cart + Mini Cart (docs/CART.md "Approved
   UX"). Presentation only - every count/amount here is WooCommerce's own,
   read through RM_Cart_ViewModel, never calculated in CSS/JS. The Mini Cart's
   close button, quantity buttons, scroll lock, skeleton pulse and
   visually-hidden helper are shared with the other overlays in ui.css; colours
   are the Theme tokens (class-rm-theme.php) with the earlier literal as the
   fallback. */

.rm-sticky-cart {
    position: fixed;
    right: 16px;
    bottom: 16px;
    left: auto;
    z-index: 90000;
    display: flex;
    align-items: stretch;
    gap: 1px;
    border-radius: 999px;
    overflow: hidden;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
    font-size: .95em;
}

.rm-sticky-cart[hidden] {
    display: none;
}

/* The bar is fixed, so while it is shown the page reserves its height at the bottom:
   the theme's last lines (a footer credit, its links) stay readable and reachable
   below it instead of being covered. cart.js measures the real bar (height + its
   bottom offset) into --rm-sticky-cart-space and sets the class; the :has() twin
   covers the first paint before the script runs and a page without it. 76px is the
   same fallback the toast uses above the bar (ui.css). */
html.rm-has-sticky-cart {
    scroll-padding-bottom: calc(var(--rm-sticky-cart-space, 76px) + env(safe-area-inset-bottom, 0px));
}

html.rm-has-sticky-cart body {
    padding-bottom: calc(var(--rm-sticky-cart-space, 76px) + env(safe-area-inset-bottom, 0px)) !important;
}

html:has(.rm-sticky-cart:not([hidden])) {
    scroll-padding-bottom: calc(var(--rm-sticky-cart-space, 76px) + env(safe-area-inset-bottom, 0px));
}

html:has(.rm-sticky-cart:not([hidden])) body {
    padding-bottom: calc(var(--rm-sticky-cart-space, 76px) + env(safe-area-inset-bottom, 0px)) !important;
}

/* Hardened against theme `button`/`a` styles - same floor as the other RM overlay controls. */
.rm-sticky-cart-open,
.rm-sticky-cart-checkout {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-sizing: border-box;
    margin: 0;
    border: 0 !important;
    box-shadow: none !important;
    padding: 12px 16px;
    background: var(--rm-primary, #2563eb) !important;
    color: #fff !important;
    text-decoration: none !important;
    cursor: pointer;
    font: inherit;
    font-weight: 600;
    appearance: none;
    -webkit-appearance: none;
}

.rm-sticky-cart-checkout {
    background: var(--rm-success, #15803d) !important;
}

.rm-sticky-cart-open:hover,
.rm-sticky-cart-open:focus-visible,
.rm-sticky-cart-checkout:hover,
.rm-sticky-cart-checkout:focus-visible {
    color: #fff !important;
    text-decoration: none !important;
    filter: brightness(1.1);
}

/* Inside the pill: its overflow:hidden clips an outer ring, so this one ring is
   drawn inside. White is visible on both the primary and the success button
   (3:1 or better on each) and survives forced-colors mode (an outline, not a
   shadow). Every other RM control uses the focus token instead. */
.rm-sticky-cart-open:focus-visible,
.rm-sticky-cart-checkout:focus-visible {
    outline: 2px solid #fff;
    outline-offset: -5px;
}

.rm-sticky-cart-icon {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.rm-sticky-cart-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .25);
    font-size: .85em;
}

@media (max-width: 640px) {
    .rm-sticky-cart {
        left: 12px;
        right: 12px;
        bottom: 12px;
        border-radius: 12px;
    }

    .rm-sticky-cart-open,
    .rm-sticky-cart-checkout {
        flex: 1 1 50%;
        justify-content: center;
    }
}

/* -----------------------------------------------------------------------
 * Mini Cart - same backdrop/dialog chrome pattern as Quick View
 * (assets/quick-view.css), drawer on desktop, bottom sheet on mobile.
 * --------------------------------------------------------------------- */
.rm-mini-cart-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, .55);
    z-index: 100000;
    display: flex;
    justify-content: flex-end;
}

.rm-mini-cart-backdrop[hidden] {
    display: none;
}

.rm-mini-cart-drawer {
    background: var(--rm-surface, #ffffff);
    color: var(--rm-text, #1f2933);
    width: min(420px, 100%);
    height: 100%;
    display: flex;
    flex-direction: column;
    box-shadow: -20px 0 40px rgba(0, 0, 0, .2);
}

.rm-mini-cart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--rm-border, #e5e7eb);
    flex: 0 0 auto;
}

.rm-mini-cart-header h2 {
    margin: 0;
    font-size: 1.1em;
}

.rm-mini-cart-scroll {
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 12px 20px 20px;
    flex: 1 1 auto;
}

.rm-mini-cart-empty {
    padding: 32px 0;
    text-align: center;
    opacity: .7;
}

.rm-mini-cart-lines {
    list-style: none;
    margin: 0 0 12px;
    padding: 0;
    display: flex;
    flex-direction: column;
}

/* Compact line (live fix): name + price, muted variation/option rows, then
   one controls row. Nothing is dropped - only the vertical rhythm is tighter. */
.rm-mini-cart-line {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 0;
    border-bottom: 1px solid #f3f4f6;
}

.rm-mini-cart-line-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.rm-mini-cart-line-name {
    min-width: 0;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.rm-mini-cart-line-total {
    flex: 0 0 auto;
    font-weight: 600;
    font-size: .9em;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.rm-mini-cart-line-meta {
    display: flex;
    flex-direction: column;
    gap: 1px;
    font-size: .85em;
    line-height: 1.35;
    opacity: .75;
}

.rm-mini-cart-line-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 2px;
}

.rm-mini-cart-qty {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.rm-mini-cart-qty-value {
    min-width: 24px;
    text-align: center;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* The quantity [-] and [+] buttons are shared with Quick View (ui.css). Remove
   is the Mini Cart's own icon button, hardened like them: 36x36, 44x44 on touch. */
.rm-mini-cart-drawer .rm-mini-cart-remove {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    box-sizing: border-box !important;
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 8px !important;
    background: transparent !important;
    background-image: none !important;
    box-shadow: none !important;
    color: var(--rm-muted, #4b5563) !important;
    line-height: 1 !important;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
}

.rm-mini-cart-drawer .rm-mini-cart-remove:hover {
    background: var(--rm-danger-tint, #fef2f2) !important;
    color: var(--rm-danger, #b91c1c) !important;
}

.rm-mini-cart-drawer .rm-mini-cart-remove:focus-visible {
    outline: 2px solid var(--rm-focus, #2563eb) !important;
    outline-offset: 1px;
}

.rm-mini-cart-remove-icon {
    display: block;
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Compact order-method block (RM_Mini_Cart::render_method_html()): one row
   "Delivery to 1784 ... Switch to Pickup", Pickup adds one wrapping address row. */
.rm-mini-cart-method {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0 0 12px;
    padding: 8px 12px;
    border-radius: 8px;
    background: #f9fafb;
    font-size: .92em;
}

.rm-mini-cart-method-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px 12px;
}

.rm-mini-cart-method-title {
    font-weight: 600;
}

.rm-mini-cart-method-actions {
    display: inline-flex;
    gap: 12px;
    margin-left: auto;
}

.rm-mini-cart-method-address {
    margin: 0;
    opacity: .8;
    overflow-wrap: anywhere;
}

/* Why the method cannot switch for this cart (RM_Method_Switch) - calm, not an error. */
.rm-mini-cart-method-note {
    margin: 4px 0 0;
    font-size: .92em;
    line-height: 1.4;
    color: var(--rm-muted, #4b5563);
}

/* Text-link style actions, hardened like every other RM control. */
.rm-mini-cart-drawer .rm-mini-cart-method-change,
.rm-mini-cart-drawer .rm-mini-cart-method-postcode {
    display: inline-flex !important;
    align-items: center;
    box-sizing: border-box !important;
    width: auto !important;
    min-width: 0 !important;
    min-height: 36px !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 2px !important;
    border: 0 !important;
    border-radius: 4px !important;
    background: transparent !important;
    background-image: none !important;
    box-shadow: none !important;
    color: var(--rm-primary, #2563eb) !important;
    font: inherit;
    font-weight: 600 !important;
    line-height: 1.2 !important;
    text-decoration: underline !important;
    text-transform: none !important;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
}

.rm-mini-cart-drawer .rm-mini-cart-method-change:hover,
.rm-mini-cart-drawer .rm-mini-cart-method-postcode:hover {
    color: var(--rm-primary-hover, #1d4ed8) !important;
    background: transparent !important;
}

.rm-mini-cart-drawer .rm-mini-cart-method-change:focus-visible,
.rm-mini-cart-drawer .rm-mini-cart-method-postcode:focus-visible {
    outline: 2px solid var(--rm-focus, #2563eb) !important;
    outline-offset: 2px;
}

.rm-mini-cart-drawer .rm-mini-cart-method-change:disabled {
    opacity: .6;
    cursor: progress;
}

/* The error does not push the cart down: its slot is zero-height and sticky at the top of the scroll area, and the message is
   drawn over the content until the next action or answer clears it. It never takes a click, so what is under it stays usable. */
.rm-mini-cart-error-slot {
    position: sticky;
    top: 0;
    z-index: 2;
    height: 0;
    overflow: visible;
    pointer-events: none;
}

.rm-mini-cart-error {
    margin: 0;
    padding: 10px 12px;
    border-radius: 6px;
    background: var(--rm-danger-tint, #fef2f2);
    color: var(--rm-danger, #b91c1c);
    box-shadow: 0 4px 12px rgba(0, 0, 0, .12);
}

/* The drawer is refreshing or changing a line: the line controls are locked (aria-disabled, so focus stays) and look it. */
.rm-mini-cart-drawer.is-updating [aria-disabled="true"] {
    opacity: .5;
    cursor: progress;
}

/* Loading skeleton (RM_Sticky_Cart::skeleton_html()) - shown instead of an
   empty drawer whenever no fresh cached Mini Cart HTML exists yet. The pulse
   is in ui.css. */
.rm-mini-cart-skeleton {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 4px 0;
}

.rm-mini-cart-skeleton-line {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f3f4f6;
}

.rm-mini-cart-skeleton .rm-skeleton-block {
    display: block;
    height: 12px;
    border-radius: 6px;
    background: #eceff3;
}

.rm-mini-cart-skeleton .rm-skeleton-w60 { width: 60%; height: 14px; }
.rm-mini-cart-skeleton .rm-skeleton-w40 { width: 40%; }
.rm-mini-cart-skeleton .rm-skeleton-tall { height: 44px; border-radius: 8px; }
.rm-mini-cart-skeleton .rm-skeleton-button { height: 48px; border-radius: 8px; }

.rm-mini-cart-total {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 0 16px;
    padding: 12px;
    border-radius: 8px;
    background: var(--rm-primary-tint, #eff6ff);
    font-weight: 600;
}

/* Delivery totals (RM_Delivery::totals_view()): Subtotal and Delivery lines above the Total, every amount from WooCommerce. */
.rm-mini-cart-subtotal,
.rm-mini-cart-delivery-cost {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 0 6px;
    padding: 0 12px;
    color: var(--rm-text, #1f2933);
}

.rm-mini-cart-delivery-cost.is-free .rm-mini-cart-total-amount {
    color: var(--rm-success, #15803d);
    font-weight: 600;
}

.rm-mini-cart-progress.is-free .rm-mini-cart-progress-bar {
    accent-color: var(--rm-success, #15803d);
}

.rm-mini-cart-checkout {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: 14px 20px calc(14px + env(safe-area-inset-bottom, 0px));
    border-radius: 8px;
    background: var(--rm-success, #15803d) !important;
    color: #fff !important;
    text-align: center;
    text-decoration: none !important;
    font-weight: 600;
    border: 0 !important;
    box-shadow: none !important;
}

.rm-mini-cart-checkout:hover,
.rm-mini-cart-checkout:focus-visible {
    color: #fff !important;
    text-decoration: none !important;
    filter: brightness(1.1);
}

.rm-mini-cart-checkout:focus-visible {
    outline: 2px solid var(--rm-focus, #2563eb);
    outline-offset: 2px;
}

/* The server says this cart may not proceed (RM_Cart_Eligibility): an inert, clearly inactive action. */
.rm-mini-cart-checkout.is-blocked,
.rm-sticky-cart-checkout.is-blocked {
    opacity: .55;
    cursor: not-allowed;
    filter: none;
}

/* Canonical ordering message and cart-eligibility blockers, above the total. */
.rm-mini-cart-ordering {
    margin: 0 0 12px;
    padding: 8px 12px;
    border-radius: 8px;
    background: #f9fafb;
    font-size: .92em;
    line-height: 1.4;
}

.rm-mini-cart-ordering.is-error {
    color: var(--rm-danger, #b91c1c);
}

.rm-mini-cart-eligibility {
    list-style: none;
    margin: 0 0 12px;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--rm-danger, #b91c1c);
    background: var(--rm-danger-tint, #fef2f2);
    color: var(--rm-danger, #b91c1c);
    font-size: .92em;
    line-height: 1.4;
}

.rm-mini-cart-blocker + .rm-mini-cart-blocker {
    margin-top: 4px;
}

/* Delivery information (RM_Delivery): the "postcode decides" note and the minimum order's progress. Text and percentage come from the server. */
.rm-mini-cart-delivery {
    margin: 0 0 12px;
    color: var(--rm-muted, #4b5563);
    font-size: .92em;
    line-height: 1.4;
}

.rm-mini-cart-delivery-note {
    margin: 0;
}

.rm-mini-cart-progress {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.rm-mini-cart-progress-bar {
    width: 100%;
    height: 8px;
    accent-color: var(--rm-primary, #2563eb);
}

.rm-mini-cart-progress-text {
    color: var(--rm-text, #1f2933);
}

/* Touch: Remove and the text-link actions grow to a 44px target (the close and
   quantity buttons do the same in ui.css). */
@media (pointer: coarse) {
    .rm-mini-cart-drawer .rm-mini-cart-remove {
        width: 44px !important;
        height: 44px !important;
        min-width: 44px !important;
        min-height: 44px !important;
    }

    .rm-mini-cart-drawer .rm-mini-cart-method-change,
    .rm-mini-cart-drawer .rm-mini-cart-method-postcode {
        min-height: 44px !important;
    }
}

@media (max-width: 640px) {
    .rm-mini-cart-backdrop {
        align-items: flex-end;
        justify-content: center;
    }

    .rm-mini-cart-drawer {
        width: 100%;
        height: auto;
        max-height: 85vh;
        border-radius: 16px 16px 0 0;
    }
}
