/**
 * Cart Action Bar Styles
 * Mobile-first CSS for CartActionBar component (sticky bottom)
 * Uses theme variables for B2B/B2C support
 *
 * The bar carries one call to action at a time: a single full-width button that also shows the price
 * before the product is in the cart, and the stepper plus the checkout button once it is. Favourite and
 * share are not here -- they sit beside the price in the product header.
 */

/* CSS Variables - Using Theme Variables */
:root {
    --cart-action-bar-bg: #ffffff;
    --cart-action-bar-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
    --cart-action-bar-touch-target: 44px;
    --cart-action-bar-cta-height: 48px;
    --cart-action-bar-pill-radius: 999px;
    --cart-action-bar-stepper-border: #e0e0e0;
}

/* Main Container - Sticky Bottom */
.cart-action-bar {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background-color: var(--cart-action-bar-bg);
    box-shadow: var(--cart-action-bar-shadow);
    padding: 12px 16px;
    /* No min-height: the two states are a single row and two rows, and padding is what separates them
       from the content above. A floor here only ever showed as empty bar. */
    margin-top: auto;
}

.cart-action-bar--hidden {
    display: none;
}

.cart-action-bar__container {
    max-width: 100%;
    margin: 0 auto;
}

/* Authentication Required State */
.cart-action-bar__auth-required {
    width: 100%;
}

.cart-action-bar__button--register {
    width: 100%;
    min-height: var(--cart-action-bar-cta-height);
    padding: 12px 16px;
    background-color: var(--brand-color); /* Uses B2B GREEN or B2C GRAY */
    color: var(--brand-text-color); /* Uses theme text color */
    border: none;
    border-radius: var(--cart-action-bar-pill-radius);
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s ease;
}

.cart-action-bar__button--register:active {
    transform: scale(0.98);
    background-color: var(--brand-color-dark-8); /* Uses theme hover color */
}

/* Shared button base */
.cart-action-bar__button {
    /* iOS paints its own control chrome behind a button whose appearance is not reset, and it shows
       once the button is disabled. */
    -webkit-appearance: none;
    appearance: none;
    border: none;
    border-radius: var(--cart-action-bar-pill-radius);
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    /* Named properties rather than `all`: the content of this button is swapped for a spinner, and
       transitioning everything makes WebKit animate that swap too. */
    transition: background-color 0.3s ease, transform 0.3s ease;
    cursor: pointer;
}

/* Initial State - Add to Cart, price inside the button */
.cart-action-bar__button--add {
    width: 100%;
    min-height: var(--cart-action-bar-cta-height);
    padding: 12px 16px;
    background-color: var(--brand-color); /* Uses B2B GREEN or B2C GRAY */
    color: var(--brand-text-color); /* Uses theme text color */
    font-size: 1rem;
}

.cart-action-bar__button--add:active:not(:disabled) {
    transform: scale(0.98);
    background-color: var(--brand-color-dark-8); /* Uses theme hover color */
}

.cart-action-bar__button--add:disabled {
    background-color: #6c757d;
    cursor: not-allowed;
    opacity: 0.6;
}

/*
   Adding to the cart disables the button as well, and it keeps the 0.6 while it does -- what changes
   is who owns the compositing layer.

   The spinner animates, so WebKit promotes it and paints the label beside it on a layer of its own,
   which carries the button's background at full strength while the rest of the button sits at 0.6:
   on iOS that reads as a lit box behind the text. Promoting the button itself puts the whole subtree
   -- background, spinner and label -- in one layer, and the opacity then applies to the composited
   result rather than to pieces of it.

   will-change is scoped to this state on purpose: it is a hint for something about to change, and
   leaving it on the resting button would hold a layer the screen never needs.
*/
.cart-action-bar__button--add.cart-action-bar__button--busy:disabled {
    will-change: opacity;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.cart-action-bar__button-price {
    font-weight: 700;
}

.cart-action-bar__button i {
    font-size: 1.125rem;
}

/* Quantity Control State */
.cart-action-bar__quantity-control {
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Total sits on its own line, label left and amount right */
.cart-action-bar__total-info {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}

.cart-action-bar__total-label {
    font-size: 0.9375rem;
    color: #6c757d;
    font-weight: 500;
}

.cart-action-bar__total-price {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--brand-color); /* Uses theme brand color */
}

/* Stepper on the left, checkout on the right */
.cart-action-bar__quantity-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.cart-action-bar__controls {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 4px;
    border: 1px solid var(--cart-action-bar-stepper-border);
    border-radius: var(--cart-action-bar-pill-radius);
    background-color: #fff;
}

.cart-action-bar__control-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: transparent;
    border: none;
    border-radius: 50%;
    color: #212529;
    font-size: 1.125rem;
    transition: all 0.2s ease;
    cursor: pointer;
}

.cart-action-bar__control-btn:active:not(:disabled) {
    transform: scale(0.95);
    background-color: #e9ecef;
}

.cart-action-bar__control-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.cart-action-bar__quantity-display {
    min-width: 44px;
    text-align: center;
}

.cart-action-bar__quantity-input {
    width: 44px;
    text-align: center;
    font-size: 1.25rem;
    font-weight: 700;
    border: none;
    outline: none;
    background: transparent;
    color: #212529;
}

.cart-action-bar__button--checkout {
    flex: 1 1 auto;
    min-width: 0;
    min-height: var(--cart-action-bar-cta-height);
    padding: 12px 16px;
    background-color: var(--brand-color); /* Uses B2B GREEN or B2C GRAY */
    color: var(--brand-text-color); /* Uses theme text color */
    font-size: 0.9375rem;
    white-space: nowrap;
}

.cart-action-bar__button--checkout:active:not(:disabled) {
    transform: scale(0.98);
    background-color: var(--brand-color-dark-8); /* Uses theme hover color */
}

/* Warning Messages */
.cart-action-bar__warning {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    margin-top: 8px;
    background-color: #fff3cd;
    border-radius: 6px;
    color: #856404;
    font-size: 0.875rem;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
    }
    to {
        opacity: 1;
        max-height: 50px;
    }
}

.cart-action-bar__warning i {
    font-size: 1rem;
}

/*
   iOS specific adjustments

   The same @supports probe categories.css, manufacturers.css and the host's app.css already use:
   -webkit-touch-callout is WebKit-only, so Android never enters this block.

   The bar lands directly on the Shell tab bar there and its controls read as glued to it. Padding
   rather than a margin, so the bar still reaches the bottom edge and no strip of page background
   appears between the two.
*/
@supports (-webkit-touch-callout: none) {
    .cart-action-bar {
        padding-bottom: 22px; /* the 12px the bar already had, plus 10px of breathing room */
    }
}

/* Responsive - Tablet and Desktop (Phase 2) */
@media (min-width: 768px) {
    .cart-action-bar {
        padding: 16px 24px;
    }

    .cart-action-bar__container {
        max-width: 1200px;
    }

    .cart-action-bar__button--add,
    .cart-action-bar__button--register,
    .cart-action-bar__button--checkout {
        min-height: 52px;
        font-size: 1.125rem;
    }

    .cart-action-bar__control-btn {
        width: 44px;
        height: 44px;
        min-width: var(--cart-action-bar-touch-target);
        min-height: var(--cart-action-bar-touch-target);
    }
}
