/**
 * BRN Ajax Add To Cart — Styles
 *
 * Design principles:
 *  - Morph-based state transitions (opacity + max-width + transform, no display:none).
 *  - CSS custom properties for style cascade:
 *      Base (Not In Cart) → Trash → In Cart.
 *      If a view-specific style is not set, the base value is inherited.
 *  - SVG spinner shown during the morph transition between views.
 */

/* ============================================================
 * CSS Custom Properties — defaults (can be overridden by Elementor)
 * ============================================================ */

.brn-cart-wrapper {
    --brn-width: 40px;
    --brn-height: 40px;
    /* --brn-icon-color, --brn-icon-color-hover, --brn-icon-size: set by Elementor if configured */
}

/* ============================================================
 * Base wrapper — the single container that morphs between states
 * ============================================================ */

.brn-cart-wrapper {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    position: relative;
    cursor: pointer;
    vertical-align: middle;
    overflow: hidden;
    width: var(--brn-width, 40px);
    height: var(--brn-height, 40px);
    /* fallback transition — the Elementor control overrides with specific durations */
    transition: all 0.3s ease;
}

/* In-cart wrapper: different width default if not explicitly set */
.brn-cart-wrapper.in-cart {
    width: var(--brn-ic-width, auto);
    height: var(--brn-ic-height, var(--brn-height, auto));
    min-width: 100px;
}

/* ============================================================
 * Cart icon (add-to-cart button) — visible when NOT in cart
 * ============================================================ */

.brn-cart-wrapper .brn-cart-icon,
.brn-cart-wrapper .brn-cart-icon:hover,
.brn-cart-wrapper .brn-cart-icon:focus,
.brn-cart-wrapper .brn-cart-icon:active,
.brn-cart-wrapper .brn-cart-icon:visited {
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
    margin: 0;
    line-height: 0;
    color: inherit;
    text-decoration: none;
    box-shadow: none;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    /* morph child */
    transition: opacity 0.3s ease, transform 0.3s ease, max-width 0.3s ease;
    opacity: 1;
    transform: scale(1);
    max-width: 200px;
    overflow: hidden;
}

/* Hidden when in-cart */
.brn-cart-wrapper.in-cart .brn-cart-icon,
.brn-cart-wrapper.in-cart .brn-cart-icon:hover {
    opacity: 0;
    transform: scale(0.4);
    max-width: 0;
    pointer-events: none;
    padding: 0;
    margin: 0;
    overflow: hidden;
}

.brn-cart-wrapper .brn-cart-icon svg {
    width: var(--brn-icon-size, 24px);
    height: var(--brn-icon-size, 24px);
    fill: var(--brn-icon-color, currentColor);
    display: block;
    flex-shrink: 0;
}

.brn-cart-wrapper .brn-cart-icon i {
    font-size: var(--brn-icon-size, 24px);
    color: var(--brn-icon-color, inherit);
    line-height: 1;
    display: block;
    flex-shrink: 0;
}

.brn-cart-wrapper .brn-cart-icon .brn-icon-svg {
    width: var(--brn-icon-size, 24px);
    height: var(--brn-icon-size, 24px);
    display: block;
    object-fit: contain;
    flex-shrink: 0;
}

/* ============================================================
 * Quantity controls — visible when IN cart
 * ============================================================ */

.brn-cart-wrapper .brn-quantity-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    /* morph child */
    transition: opacity 0.3s ease, transform 0.3s ease, max-width 0.3s ease, gap 0.3s ease;
    opacity: 1;
    transform: scale(1);
    max-width: 400px;
    overflow: hidden;
    white-space: nowrap;
}

/* Hidden when not-in-cart */
.brn-cart-wrapper.not-in-cart .brn-quantity-controls {
    opacity: 0;
    transform: scale(0.4);
    max-width: 0;
    pointer-events: none;
    gap: 0;
    overflow: hidden;
}

/* ============================================================
 * Buttons (shared) — cascade icon color / size via CSS vars
 * ============================================================ */

.brn-cart-wrapper .brn-btn,
.brn-cart-wrapper .brn-btn:hover,
.brn-cart-wrapper .brn-btn:focus,
.brn-cart-wrapper .brn-btn:active,
.brn-cart-wrapper .brn-btn:visited {
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 4px;
    margin: 0;
    flex-shrink: 0;
    line-height: 0;
    color: inherit;
    text-decoration: none;
    box-shadow: none;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    transition: opacity 0.15s ease, background-color 0.15s ease;
}

.brn-cart-wrapper .brn-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Icon color cascades from --brn-icon-color (Base / Not In Cart).
   Elementor In Cart + Trash controls override via more-specific selectors. */
.brn-cart-wrapper .brn-btn svg {
    width: var(--brn-icon-size, 20px);
    height: var(--brn-icon-size, 20px);
    fill: var(--brn-icon-color, currentColor);
    display: block;
}

.brn-cart-wrapper .brn-btn i {
    font-size: var(--brn-icon-size, 20px);
    color: var(--brn-icon-color, inherit);
    line-height: 1;
    display: block;
}

.brn-cart-wrapper .brn-btn .brn-icon-svg {
    width: var(--brn-icon-size, 20px);
    height: var(--brn-icon-size, 20px);
    display: block;
    object-fit: contain;
}

/* Hover icon colors: cascade from --brn-icon-color-hover, then --brn-icon-color */
.brn-cart-wrapper .brn-btn:hover:not(:disabled) svg {
    fill: var(--brn-icon-color-hover, var(--brn-icon-color, currentColor));
}

.brn-cart-wrapper .brn-btn:hover:not(:disabled) i {
    color: var(--brn-icon-color-hover, var(--brn-icon-color, inherit));
}

.brn-cart-wrapper .brn-btn:hover:not(:disabled) {
    opacity: 0.8;
    background: transparent;
}

/* ============================================================
 * Quantity number
 * ============================================================ */

.brn-cart-wrapper .brn-quantity-display {
    font-size: 16px;
    font-weight: 600;
    min-width: 30px;
    text-align: center;
    line-height: 1;
    user-select: none;
    transition: opacity 0.15s ease;
}

/* ============================================================
 * Minus ↔ Trash icon toggle
 * ============================================================ */

.brn-cart-wrapper .brn-btn-minus .brn-icon-trash {
    display: none;
}

.brn-cart-wrapper .brn-btn-minus .brn-icon-minus {
    display: flex;
    align-items: center;
    justify-content: center;
}

.brn-cart-wrapper .brn-btn-minus.is-trash .brn-icon-trash {
    display: flex;
    align-items: center;
    justify-content: center;
}

.brn-cart-wrapper .brn-btn-minus.is-trash .brn-icon-minus {
    display: none;
}

/* ============================================================
 * Morph transition spinner — shows during Not-In-Cart ↔ In-Cart
 * ============================================================ */

.brn-cart-wrapper .brn-morph-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.3);
    width: var(--brn-icon-size, 24px);
    height: var(--brn-icon-size, 24px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
    z-index: 5;
    pointer-events: none;
    color: var(--brn-icon-color, currentColor);
}

.brn-cart-wrapper .brn-morph-spinner .brn-spinner-svg {
    width: 100%;
    height: 100%;
    display: block;
}

.brn-cart-wrapper.is-morphing .brn-morph-spinner {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

/* While morphing, dim the cart icon and qty controls so the spinner stands out */
.brn-cart-wrapper.is-morphing .brn-cart-icon,
.brn-cart-wrapper.is-morphing .brn-quantity-controls {
    opacity: 0.15 !important;
}

/* ============================================================
 * Loading state — blocks clicks, dims the widget (add-to-cart only)
 * ============================================================ */

.brn-cart-wrapper.is-loading {
    pointer-events: none;
    opacity: 0.5;
}

.brn-cart-wrapper.is-loading .brn-btn {
    cursor: wait;
}

/* ============================================================
 * Pending state — subtle pulse while debounce timer is running
 * (does NOT disable clicks)
 * ============================================================ */

.brn-cart-wrapper.is-pending .brn-quantity-display {
    animation: brn-pulse 0.6s ease-in-out infinite alternate;
}

@keyframes brn-pulse {
    0%   { opacity: 1; }
    100% { opacity: 0.45; }
}

/* ============================================================
 * Error shake
 * ============================================================ */

.brn-cart-wrapper.has-error {
    animation: brn-shake 0.5s ease-in-out;
}

@keyframes brn-shake {
    0%,
    100% { transform: translateX(0); }
    10%,
    30%,
    50%,
    70%,
    90%  { transform: translateX(-4px); }
    20%,
    40%,
    60%,
    80%  { transform: translateX(4px); }
}

/* ============================================================
 * Mini Cart +/- Controls (WC sidebar widget / Elementor Pro Menu Cart)
 * ============================================================ */

.brn-mini-cart-qty-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
}

.brn-mini-cart-qty.brn-cart-wrapper {
    width: auto !important;
    height: auto !important;
    min-width: unset !important;
    overflow: visible;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    cursor: default;
    transition: opacity 0.2s ease;
}

.brn-mini-cart-qty .brn-quantity-controls {
    display: flex !important;
    align-items: center;
    gap: 2px;
    opacity: 1 !important;
    transform: none !important;
    max-width: none !important;
    overflow: visible;
}

.brn-mini-cart-qty .brn-btn,
.brn-mini-cart-qty .brn-btn:hover,
.brn-mini-cart-qty .brn-btn:focus,
.brn-mini-cart-qty .brn-btn:active {
    padding: 2px !important;
    border: none !important;
    box-shadow: none !important;
    outline: none !important;
    color: inherit;
}

.brn-mini-cart-qty .brn-btn svg {
    width: 14px !important;
    height: 14px !important;
}

.brn-mini-cart-qty .brn-btn:hover:not(:disabled) {
    opacity: 0.6;
}

.brn-mini-cart-qty .brn-quantity-display {
    font-size: 13px;
    min-width: 18px;
    font-weight: 600;
    text-align: center;
}

.brn-mini-cart-price {
    white-space: nowrap;
    font-size: inherit;
}

/* When item is being removed (qty → 0), collapse gracefully */
.brn-mini-cart-qty.not-in-cart {
    opacity: 0 !important;
    pointer-events: none;
}

/* Pending pulse in mini cart */
.brn-mini-cart-qty.is-pending .brn-quantity-display {
    animation: brn-pulse 0.6s ease-in-out infinite alternate;
}

/* Price show/hide via Elementor prefix_class on the Menu Cart wrapper */
.brn-mc-price- .brn-mini-cart-price {
    display: none !important;
}

/* ============================================================
 * Elementor editor placeholder
 * ============================================================ */

.brn-cart-editor-notice {
    padding: 10px;
    background: #f0f0f0;
    border: 1px dashed #ccc;
    text-align: center;
    font-size: 12px;
    color: #666;
}

/* ============================================================
 * Responsive
 * ============================================================ */

@media (max-width: 768px) {
    .brn-cart-wrapper .brn-quantity-controls {
        gap: 4px;
    }

    .brn-cart-wrapper .brn-btn svg {
        width: var(--brn-icon-size, 18px);
        height: var(--brn-icon-size, 18px);
    }

    .brn-cart-wrapper .brn-btn i {
        font-size: var(--brn-icon-size, 18px);
    }

    .brn-cart-wrapper .brn-btn .brn-icon-svg {
        width: var(--brn-icon-size, 18px);
        height: var(--brn-icon-size, 18px);
    }

    .brn-cart-wrapper .brn-quantity-display {
        font-size: 14px;
        min-width: 24px;
    }
}

/* ============================================================
 * Accessibility — focus ring
 * ============================================================ */

.brn-cart-wrapper .brn-btn:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* ============================================================
 * BRN Checkout Order Review — CSS Grid Layout
 * ============================================================ */

.brn-checkout-review-wrap {
    width: 100%;
}

/* Responsive desktop / mobile wrappers (visibility toggled via inline <style>) */
.brn-cor-desktop,
.brn-cor-mobile {
    width: 100%;
}

.brn-checkout-review-table {
    width: 100%;
}

/* Grid row — shared by header + body rows */
.brn-cor-row {
    display: grid;
    grid-template-columns: var(--brn-cor-cols, 1fr);
}

/* Header */
.brn-cor-header {
    /* inherits .brn-cor-row grid */
}

.brn-cor-th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
}

/* Body rows */
.brn-cor-body {
    display: flex;
    flex-direction: column;
}

.brn-review-item {
    transition: background-color 0.2s ease;
    align-items: center;
}

.brn-review-cell {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Alignment helpers */
.brn-align-left   { text-align: left; }
.brn-align-center { text-align: center; }
.brn-align-right  { text-align: right; }

/* Thumbnail */
.brn-cor-thumbnail {
    display: inline-block;
    vertical-align: middle;
    line-height: 0;
}

.brn-cor-thumbnail img {
    width: 60px;
    height: auto;
    display: block;
    border-radius: 4px;
}

/* Product name */
.brn-cor-product-name {
    text-decoration: none;
}
a.brn-cor-product-name:hover {
    text-decoration: underline;
}

/* Inline elements alignment */
.brn-cor-element {
    display: inline;
    vertical-align: middle;
}

.brn-cor-description {
    display: block;
}

/* Orientation: horizontal (default) */
.brn-orient-horizontal .brn-cor-element {
    display: inline;
    vertical-align: middle;
}

/* Orientation: vertical (stacked) */
.brn-orient-vertical {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.brn-orient-vertical .brn-cor-element {
    display: block;
}

.brn-orient-vertical .brn-cor-sep {
    display: block;
    line-height: 1;
}

/* Separators */
.brn-cor-sep {
    display: inline;
    opacity: 0.6;
}

/* Style override wrapper */
.brn-cor-style-wrap {
    display: inline;
    vertical-align: middle;
}
.brn-orient-vertical .brn-cor-style-wrap {
    display: block;
}

/* Quantity plain text */
.brn-cor-quantity {
    font-weight: 600;
}

/* Stock status */
.brn-stock-in-stock { color: #22863a; }
.brn-stock-out-of-stock { color: #cb2431; }

/* Remove button */
.brn-cor-remove-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: none;
    border: none;
    padding: 4px;
    color: #999;
    transition: color 0.2s ease, background-color 0.2s ease;
    border-radius: 4px;
    line-height: 0;
}
.brn-cor-remove-btn:hover {
    color: #cb2431;
}
.brn-cor-remove-btn svg {
    width: 16px;
    height: 16px;
    display: block;
}

/* ---- Checkout quantity controls (compact variant) ---- */
.brn-checkout-qty {
    display: inline-flex !important;
}

.brn-checkout-qty .brn-quantity-controls {
    gap: 4px;
}

.brn-checkout-qty .brn-btn {
    padding: 4px;
}

.brn-checkout-qty .brn-btn svg {
    width: 14px;
    height: 14px;
}

.brn-checkout-qty .brn-quantity-display {
    font-size: 14px;
    min-width: 20px;
    font-weight: 600;
    text-align: center;
}

/* Container for qty controls element */
.brn-cor-qty-controls {
    display: inline-flex;
    vertical-align: middle;
}

/* ---- Totals section ---- */
.brn-checkout-totals {
    display: flex;
    flex-direction: column;
}

.brn-totals-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brn-totals-label {
    padding: 10px 16px;
    text-align: left;
    font-weight: 500;
}

.brn-totals-value {
    padding: 10px 16px;
    text-align: right;
}

.brn-totals-total .brn-totals-label,
.brn-totals-total .brn-totals-value {
    font-weight: 700;
    font-size: 1.1em;
}

/* Empty cart message */
.brn-cor-empty {
    padding: 24px 16px;
    text-align: center;
    color: #666;
}

/* Responsive checkout review */
@media (max-width: 768px) {
    .brn-checkout-review-table {
        font-size: 14px;
    }
    .brn-cor-th,
    .brn-review-cell {
        padding: 8px 10px;
    }
    .brn-cor-thumbnail img {
        width: 48px;
    }
    .brn-totals-label,
    .brn-totals-value {
        padding: 8px 10px;
    }
}

/* ============================================================
 * Free Shipping Bar — Mini Cart
 * ============================================================ */

.brn-free-shipping-bar {
    padding: 10px 16px;
    text-align: center;
    font-size: 14px;
    line-height: 1.4;
    transition: all 0.3s ease;
}

.brn-free-shipping-bar[style*="display:none"] {
    padding: 0;
    margin: 0;
    border: none;
}

.brn-fs-message {
    display: block;
}

.brn-fs-amount {
    font-weight: 700;
}

.brn-fs-achieved {
    font-weight: 600;
}

/* =============================================================================
   BRN Checkout Totals — Standalone Widget
   ============================================================================= */

.brn-checkout-totals-wrap {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.brn-ct-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    transition: background-color 0.15s ease;
}

.brn-ct-row + .brn-ct-row {
    border-top: 1px solid #e5e5e5;
}

.brn-ct-label {
    font-weight: 500;
    color: #333;
}

.brn-ct-value {
    font-weight: 400;
    color: #333;
    text-align: right;
}

/* Total row emphasis */
.brn-ct-row-total {
    font-weight: 700;
    font-size: 1.1em;
}

.brn-ct-row-total .brn-ct-label,
.brn-ct-row-total .brn-ct-value {
    font-weight: 700;
}

/* Coupon discount */
.brn-ct-row-coupon .brn-ct-value {
    color: #4caf50;
}

/* Empty cart */
.brn-ct-empty {
    padding: 24px 16px;
    text-align: center;
    color: #666;
}

/* Responsive */
@media (max-width: 768px) {
    .brn-ct-row {
        padding: 10px 12px;
    }
}
