/* The module reads the storefront palette (--alfa-*) and never a template's own
   variables: a module cannot know which template it lands in, but every Alfa
   storefront ships this palette, and a template retheming it moves the cart too.
   Each fallback is the module's previous literal, so a page that loads the cart
   without com_alfa's CSS looks exactly as it did. */
.mod-alfa-cart {
    --alfa-cart-surface: var(--alfa-surface, #fff);
    --alfa-cart-surface-color: var(--alfa-surface-color, inherit);
    --alfa-cart-muted: var(--alfa-muted-color, #777);
    --alfa-cart-hairline: var(--alfa-hairline, #eaeaea);
    /* Header and footer sit above the panel. Mixed from the text colour rather
       than fixed, so the lift survives a dark panel instead of inverting. */
    --alfa-cart-raised: color-mix(in srgb, currentColor 4%, var(--alfa-cart-surface));
    --alfa-cart-danger: var(--alfa-error-color, #e60000);
    /* The checkout CTA, in priority order: what the merchant picked for this
       module, else the storefront's primary action, else the shipped literal. */
    --alfa-cart-cta-bg: var(--mod-alfa-cart-checkout-color, var(--alfa-action-primary-bg, #333));
    --alfa-cart-cta-color: var(--mod-alfa-cart-checkout-text-color, var(--alfa-action-primary-color, #fff));
    /* Radius lives here and nowhere else. A fallback repeated at each use site is
       invisible duplication: the panel said 4px, the close button 3px and the CTA
       none, so the module disagreed with itself about its own shape. One base, and
       the small controls take a ratio of it. */
    --alfa-cart-radius: var(--alfa-radius, 4px);
    --alfa-cart-radius-panel: var(--alfa-radius-panel, 4px);
    --alfa-cart-radius-sm: calc(var(--alfa-cart-radius) * 0.75);
}

.mod-alfa-cart-no-scroll{
    height: 100%;
    overflow: hidden;
}

/* header */
.mod-alfa-cart .cart-header{
    padding: 30px 15px;
    background-color: var(--alfa-cart-raised);
    border-bottom: 1px solid var(--alfa-cart-hairline);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

/* CLOSE BUTTON*/
.mod-alfa-cart .close-btn {
    cursor: pointer;
    color: var(--alfa-cart-muted);
    border: 1px solid var(--alfa-cart-hairline);
    width: 30px;
    height: 30px;
    background: var(--alfa-cart-surface);
    border-radius: var(--alfa-cart-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    aspect-ratio: 1/1;
    transition: color .2s ease,background-color .2s ease;
}

.mod-alfa-cart .close-btn:hover {
    color: var(--alfa-cart-surface-color);
    background-color: var(--alfa-cart-raised);
}

/* body */
.mod-alfa-cart .cart-body{
    height:100%;
    overflow-y: auto;
}

.mod-alfa-cart .cart-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.mod-alfa-cart .cart-quantity {
    font-weight: bold;
    display: inline-flex;
    gap:5px;
}

.mod-alfa-cart .cart-item-outer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid var(--alfa-cart-hairline);
}
.mod-alfa-cart .cart-item-details{
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex-grow: 1;
}
.mod-alfa-cart .cart-item-name {
    font-size: 1.125rem;
    color: var(--alfa-cart-surface-color);
}

.mod-alfa-cart .cart-item-remove {
    background: none;
    border: none;
    width: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--alfa-cart-surface-color);
    transition: color 0.2s ease;
}

.mod-alfa-cart .cart-item-remove:hover {
    color: var(--alfa-cart-danger);
}

.mod-alfa-cart .cart-list > li:last-child {
    border-bottom: unset;
}

/* Quantity controls. The stepper itself is com_alfa's shared component
   (stepper.css), the same one the item page uses, so the two agree on shape and
   follow --alfa-radius together. This row only places it beside the remove button. */
.mod-alfa-cart .item-quantity-controls-wrapper {
    display: flex;
    align-items: center;
    gap: var(--alfa-cart-gap, 0.5rem);
}

/* Complete Order Button (checkout CTA, no Bootstrap; colours from module params) */
.mod-alfa-cart .cart-checkout {
    display: block;
    text-align: center;
    padding: 12px;
    background-color: var(--alfa-cart-cta-bg);
    color: var(--alfa-cart-cta-color);
    border-radius: var(--alfa-cart-radius);
    text-decoration: none;
    transition: filter 0.15s ease;
}

.mod-alfa-cart .cart-checkout:hover {
    filter: brightness(0.9);
}

.mod-alfa-cart .cart-empty {
    justify-content: center;
    display: flex;
    align-items: center;
    height: 100%;
}
/* footer */
.mod-alfa-cart .cart-footer{
    box-shadow: 0 -5px 10px #00000029;
    padding: 30px 40px;
    background-color: var(--alfa-cart-raised);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.mod-alfa-cart .cart-footer .totals-row{
    display: flex;
    gap: 5px;
}

/* toggler */
.mod-alfa-cart .cart-toggler{
    position:relative;
    color:var(--mod-alfa-cart-toggler-color, currentColor);
}

.mod-alfa-cart .cart-toggler::after {
  background-color: var(--mod-alfa-cart-counter-color, #FF0000);
  font-size: .75rem;
  width: 18px;
  line-height: 18px;
  text-align: center;
  color: #fff;
  z-index: 2;
  border-radius: 50%;
  position: absolute;
  right: -4px;
  top: -3px;
  content: attr(data-counter);
}

/* main wrapper */
.mod-alfa-cart .mod-alfa-cart-data {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
    scrollbar-width: none;
    -ms-overflow-style: none;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 60000;
}

.mod-alfa-cart .cart--visible {
    pointer-events: auto;
    overflow: auto;
}

/* main wrapper inner */
.mod-alfa-cart .mod-alfa-cart-data-inner {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    pointer-events: none;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-width: 800px;
    z-index: 60001;
    background-color: var(--alfa-cart-surface);
    color: var(--alfa-cart-surface-color);
    border: 1px solid var(--alfa-cart-hairline);
}


/* OVERLAY*/
/* we use after so the animation we apply will not affect the inner items */
.mod-alfa-cart .mod-alfa-cart-data:after {
    content: '';
    display: block;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    opacity: 0;
    will-change: opacity;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0,0,0.3,1);
}

.mod-alfa-cart .cart--visible.mod-alfa-cart-data:after {
    opacity: 1;
    pointer-events: auto;
}


/* CART OPEN ANIMATIONS */

/* ZOOM IN */
.zoomIn.mod-alfa-cart .mod-alfa-cart-data-inner {
    max-height: 600px;
    border-radius: var(--alfa-cart-radius-panel);
    transform: scale(0.5);
    opacity: 0;
    will-change: transform;
}
.zoomIn.mod-alfa-cart .cart--animatable .mod-alfa-cart-data-inner {
    transition: transform 130ms ease-in, opacity 130ms ease-in;
}

.zoomIn.mod-alfa-cart .cart--visible.cart--animatable .mod-alfa-cart-data-inner {
    transition: all 330ms ease-out;
}

.zoomIn.mod-alfa-cart .cart--visible .mod-alfa-cart-data-inner {
    opacity: 1;
}
.zoomIn.mod-alfa-cart .cart--visible .mod-alfa-cart-data-inner {
    pointer-events: auto;
    transform: none;
}

/* FROM TOP */
.fromTop.mod-alfa-cart .mod-alfa-cart-data-inner {
    max-height: 600px;
    border-radius: var(--alfa-cart-radius-panel);
    transform: translateY(-150%);
    opacity: 0;
    will-change: transform;
}
.fromTop.mod-alfa-cart .cart--animatable .mod-alfa-cart-data-inner {
    transition: transform 130ms ease-in,opacity 130ms ease-in;
}
.fromTop.mod-alfa-cart .cart--visible.cart--animatable .mod-alfa-cart-data-inner {
    transition: all 330ms ease-out;
}
.fromTop.mod-alfa-cart .cart--visible .mod-alfa-cart-data-inner {
    opacity: 1;
}

.fromTop.mod-alfa-cart .cart--visible .mod-alfa-cart-data-inner {
    pointer-events: auto;
    transform: none;
}

/* FROM LEFT */
.fromLeft.mod-alfa-cart .mod-alfa-cart-data-inner {
    border-radius: 0 var(--alfa-cart-radius-panel) var(--alfa-cart-radius-panel) 0;
    transform: translateX(-150%);
    will-change: transform;
}
.fromLeft.mod-alfa-cart .mod-alfa-cart-data-inner{
    max-height: 100%;
}
.fromLeft.mod-alfa-cart .mod-alfa-cart-data{
    justify-content: flex-start;
}
.fromLeft.mod-alfa-cart .cart--animatable .mod-alfa-cart-data-inner {
    transition: transform 130ms ease-in;
}
.fromLeft.mod-alfa-cart .cart--visible.cart--animatable .mod-alfa-cart-data-inner {
    transition: all 330ms ease-out;
}
.fromLeft.mod-alfa-cart .cart--visible .mod-alfa-cart-data-inner {
    pointer-events: auto;
    transform: none;
}

/* FROM RIGHT */
.fromRight.mod-alfa-cart .mod-alfa-cart-data-inner {
    border-radius: var(--alfa-cart-radius-panel) 0 0 var(--alfa-cart-radius-panel);
    transform: translateX(150%);
    will-change: transform;
}

.fromRight.mod-alfa-cart .mod-alfa-cart-data-inner{
    max-height: 100%;
}
.fromRight.mod-alfa-cart .mod-alfa-cart-data{
    justify-content: flex-end;
}

.fromRight.mod-alfa-cart .cart--animatable .mod-alfa-cart-data-inner {
    transition: transform 130ms ease-in;
}
.fromRight.mod-alfa-cart .cart--visible.cart--animatable .mod-alfa-cart-data-inner {
    transition: all 330ms ease-out;
}
.fromRight.mod-alfa-cart .cart--visible .mod-alfa-cart-data-inner {
    pointer-events: auto;
    transform: none;
}
.fromRight.mod-alfa-cart .close-btn {
    order:-1;
}

.fromRight .cart-header{
    justify-content: flex-start;
}

/*
   Dark
   The module's own dark values, so it is correct in both modes on its own: a page
   that never loads com_alfa's palette still gets a readable panel instead of dark
   text on a dark ground. Where the palette IS loaded it wins, so a merchant who
   themes the shop still themes this module; these are the floor, not the ceiling.

   Keyed on what the PAGE declares, never on the device alone: a visitor who picks
   light on a dark laptop must get light. The third selector is the case where no
   Alfa template is installed: neither attribute exists, so the device decides.
   */
:is(:root[data-theme="dark"], :root[data-theme-default="dark"]:not([data-theme]))
.mod-alfa-cart {
    --alfa-cart-surface: var(--alfa-surface, #1f2937);
    --alfa-cart-surface-color: var(--alfa-surface-color, #e5e7eb);
    --alfa-cart-muted: var(--alfa-muted-color, #9ca3af);
    --alfa-cart-hairline: var(--alfa-hairline, #374151);
    --alfa-cart-danger: var(--alfa-error-color, #f87171);
    --alfa-cart-cta-bg: var(--mod-alfa-cart-checkout-color, var(--alfa-action-primary-bg, #e5e7eb));
    --alfa-cart-cta-color: var(--mod-alfa-cart-checkout-text-color, var(--alfa-action-primary-color, #111827));
}

@media (prefers-color-scheme: dark) {
    :is(:root[data-theme="auto"],
        :root[data-theme-default="auto"]:not([data-theme]),
        :root:not([data-theme]):not([data-theme-default]))
    .mod-alfa-cart {
        --alfa-cart-surface: var(--alfa-surface, #1f2937);
        --alfa-cart-surface-color: var(--alfa-surface-color, #e5e7eb);
        --alfa-cart-muted: var(--alfa-muted-color, #9ca3af);
        --alfa-cart-hairline: var(--alfa-hairline, #374151);
        --alfa-cart-danger: var(--alfa-error-color, #f87171);
        --alfa-cart-cta-bg: var(--mod-alfa-cart-checkout-color, var(--alfa-action-primary-bg, #e5e7eb));
        --alfa-cart-cta-color: var(--mod-alfa-cart-checkout-text-color, var(--alfa-action-primary-color, #111827));
    }
}
