/**
 * RoeschStudio Widgets - Minicart Styles
 * @package RoeschStudio_Widgets
 * 
 * IMPORTANT: Overlay and Sidebar use position:fixed to appear above all content.
 * They are placed inside the widget wrapper for Elementor {{WRAPPER}} selectors
 * to work correctly, but CSS position:fixed makes them escape the wrapper flow.
 */

/* Minicart Wrapper */
.rsw-minicart {
    display: inline-block;
}

/* Trigger Button - Uses CSS custom properties from Elementor */
.rsw-minicart-trigger {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    /* CSS variables set by Elementor via inline style on parent */
    background-color: var(--rsw-trigger-bg, transparent);
    color: var(--rsw-trigger-color, inherit);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 150ms ease;
}

.rsw-minicart-trigger:hover {
    background-color: var(--rsw-trigger-hover-bg, var(--rsw-trigger-bg, transparent));
    color: var(--rsw-trigger-hover-color, var(--rsw-trigger-color, inherit));
    opacity: 0.95;
}

.rsw-minicart-icon {
    width: 24px;
    height: 24px;
}

/* Badge - Uses CSS custom properties from Elementor */
.rsw-minicart-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    /* CSS variables set by Elementor via inline style on parent */
    background-color: var(--rsw-badge-bg, #2196F3);
    color: var(--rsw-badge-color, #ffffff);
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 999px;
}

.rsw-minicart-total {
    font-weight: 600;
    color: inherit;
}

/* Overlay */
.rsw-minicart-overlay {
    position: fixed !important;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: 999998 !important; /* Very high z-index to be above everything */
    transition: opacity 0.3s ease, visibility 0.3s ease;
    will-change: opacity;
    display: block;
}

.rsw-minicart-overlay.is-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Sidebar - Uses CSS custom properties from Elementor */
.rsw-minicart-sidebar {
    position: fixed !important;
    top: 0;
    bottom: 0;
    width: 380px;
    max-width: 90vw;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    /* CSS variable set by Elementor via inline style on parent */
    background: var(--rsw-sidebar-bg, #ffffff);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.15);
    z-index: 999999 !important; /* Very high z-index to be above overlay */
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
    overflow: hidden;
    pointer-events: none;
    
    /* Base styles */
    font-family: inherit;
    font-size: 16px;
    line-height: 1.5;
    color: #333333;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.rsw-minicart-sidebar.rsw-minicart--right {
    right: 0;
    left: auto;
    transform: translateX(100%);
}

.rsw-minicart-sidebar.rsw-minicart--left {
    left: 0;
    right: auto;
    transform: translateX(-100%);
}

.rsw-minicart-sidebar.is-visible {
    transform: translateX(0);
    pointer-events: auto;
}

/* Header */
.rsw-minicart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
    background: #ffffff;
}

.rsw-minicart-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: #333333;
}

.rsw-minicart-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: 4px;
    transition: all 150ms ease;
    color: #666666;
}

.rsw-minicart-close:hover {
    background: #f5f5f5;
    color: #333333;
}

/* Free Shipping Bar - Uses CSS custom properties from Elementor */
.rsw-minicart-fs-wrapper {
    padding: 15px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
}

.rsw-minicart-fs-message {
    font-size: 0.85rem;
    margin-bottom: 8px;
    font-weight: 500;
    color: #555555;
}

.rsw-minicart-fs-progress {
    height: 8px;
    /* CSS variable set by Elementor via inline style on parent */
    background: var(--rsw-fs-bar-bg, #e0e0e0);
    border-radius: 999px;
    overflow: hidden;
}

.rsw-minicart-fs-fill {
    height: 100%;
    /* CSS variable set by Elementor via inline style on parent */
    background: var(--rsw-fs-fill-bg, #2196F3);
    width: 0%;
    transition: width 0.5s ease-out;
}

.rsw-minicart-fs-wrapper.is-complete .rsw-minicart-fs-fill {
    background: #4caf50;
}

.rsw-minicart-fs-wrapper.is-complete .rsw-minicart-fs-message {
    color: #4caf50;
    font-weight: 600;
}

/* Content */
.rsw-minicart-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    /* Smooth scrolling */
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Prevent overscroll bounce on mobile */
.rsw-minicart-content {
    overscroll-behavior: contain;
}

/* Cart Items */
.rsw-minicart-item {
    display: flex;
    gap: 16px;
    padding: 16px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 12px;
    transition: all 150ms ease;
}

.rsw-minicart-item.is-updating {
    opacity: 0.6;
    /* pointer-events: none; REMOVED to allow smart queuing during sync */
    cursor: progress;
}

.rsw-minicart-item.is-removing {
    animation: rsw-slide-out 0.3s ease-out forwards;
}

@keyframes rsw-slide-out {
    to {
        opacity: 0;
        transform: translateX(20px);
        max-height: 0;
        padding: 0;
        margin: 0;
    }
}

/* Item Image */
.rsw-minicart-item__image {
    flex-shrink: 0;
    width: 60px;
    height: 60px;
    border-radius: 4px;
    overflow: hidden;
}

.rsw-minicart-item__image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Item Content */
.rsw-minicart-item__content {
    flex: 1;
    min-width: 0;
}

.rsw-minicart-item__name {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    /* CSS variable set by Elementor via inline style on parent */
    color: var(--rsw-item-name-color, #333333);
    text-decoration: none;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rsw-minicart-item__name:hover {
    color: var(--rsw-item-name-hover-color, #2196F3);
}

.rsw-minicart-item__price {
    font-size: 0.875rem;
    font-weight: 600;
    color: #2196F3;
    margin-bottom: 8px;
}

/* Quantity Controls */
.rsw-minicart-item__quantity {
    display: inline-flex;
    align-items: center;
    gap: 0;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
}

.rsw-minicart-qty-minus,
.rsw-minicart-qty-plus {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: #ffffff;
    border: none;
    cursor: pointer;
    font-size: 16px;
    transition: all 150ms ease;
}

.rsw-minicart-qty-minus:hover,
.rsw-minicart-qty-plus:hover {
    background: #2196F3;
    color: white;
}

.rsw-minicart-qty-value {
    min-width: 32px;
    text-align: center;
    font-size: 0.875rem;
    font-weight: 500;
}

/* Remove Button */
.rsw-minicart-item__remove {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #666666;
    transition: all 150ms ease;
}

.rsw-minicart-item__remove:hover {
    color: #f44336;
}

/* Empty State */
.rsw-minicart-empty {
    text-align: center;
    padding: 32px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.rsw-minicart-empty-image {
    max-width: 150px;
    margin-bottom: 12px;
    opacity: 0.6;
}

.rsw-minicart-empty-image img {
    width: 100%;
    height: auto;
}

.rsw-minicart-empty-text {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 500;
    color: #666666;
}

.rsw-minicart-empty-btn {
    margin-top: 12px;
}

/* Footer */
.rsw-minicart-footer {
    padding: 20px;
    border-top: 1px solid #e0e0e0;
    background: #f8f9fa;
}

.rsw-minicart-subtotal {
    display: flex;
    justify-content: space-between;
    margin-bottom: 16px;
    font-size: 1rem;
    /* CSS variable set by Elementor via inline style on parent */
    color: var(--rsw-subtotal-color, inherit);
}

.rsw-minicart-subtotal-amount {
    font-weight: 700;
    font-size: 1.125rem;
    color: var(--rsw-subtotal-color, inherit);
}

.rsw-minicart-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Base button styles - layout only, colors controlled by Elementor */
.rsw-minicart-viewcart,
.rsw-minicart-checkout {
    width: 100%;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none !important;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 150ms ease;
}

/* View Cart Button - Uses CSS variables that Elementor sets via inline style */
.rsw-minicart-viewcart {
    color: var(--rsw-viewcart-color, #333333);
    background-color: var(--rsw-viewcart-bg, #f0f0f0);
    border-color: var(--rsw-viewcart-border, #e0e0e0);
}

.rsw-minicart-viewcart:hover {
    color: var(--rsw-viewcart-hover-color, var(--rsw-viewcart-color, #333333));
    background-color: var(--rsw-viewcart-hover-bg, #e0e0e0);
}

/* Checkout Button - Uses CSS variables that Elementor sets via inline style */
.rsw-minicart-checkout {
    color: var(--rsw-checkout-color, #ffffff);
    background-color: var(--rsw-checkout-bg, #333333);
    border-color: var(--rsw-checkout-border, transparent);
}

.rsw-minicart-checkout:hover {
    color: var(--rsw-checkout-hover-color, var(--rsw-checkout-color, #ffffff));
    background-color: var(--rsw-checkout-hover-bg, #555555);
}

/* Body scroll lock */
body.rsw-minicart-active {
    overflow: hidden;
    /* Prevent content shift when scrollbar disappears */
    padding-right: 0;
}

/* Calculate scrollbar width (set via JS) */
body.rsw-minicart-active:not(.rsw-scrollbar-calculated) {
    padding-right: 0;
}

/* Prevent main content from being pushed */
.rsw-minicart-sidebar,
.rsw-minicart-overlay {
    /* Ensure they don't affect document flow */
    margin: 0 !important;
}

/* Ensure wrapper doesn't affect layout or stacking context */
.rsw-minicart {
    position: relative;
    /* Don't create stacking context - this allows fixed children to escape */
    contain: layout style;
    isolation: auto; /* Prevent isolation context */
}

/* When sidebar is open, ensure it doesn't create new stacking context */
.rsw-minicart.is-open {
    /* Allow sidebar to be on top - don't set z-index here */
    contain: none; /* Remove containment to allow fixed children to escape */
}



/* Responsive */
@media (max-width: 480px) {
    .rsw-minicart-sidebar {
        width: 100vw;
        max-width: none;
    }
}

/* Performance optimizations */
.rsw-minicart-sidebar,
.rsw-minicart-overlay {
    /* GPU acceleration */
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Prevent sidebar from affecting page layout */
.rsw-minicart-sidebar::before,
.rsw-minicart-sidebar::after,
.rsw-minicart-overlay::before,
.rsw-minicart-overlay::after {
    content: none !important;
}

/* Ensure proper isolation */
.rsw-minicart {
    contain: layout style;
}

/* Loading State */
.rsw-minicart-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: #666666;
}

.rsw-spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-left-color: #2196F3;
    border-radius: 50%;
    animation: rsw-spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes rsw-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error State */
.rsw-minicart-error {
    padding: 20px;
    background: #fee;
    border: 2px solid #f00;
    border-radius: 4px;
    margin: 20px;
    color: #c00;
    font-weight: 600;
}

.rsw-minicart-error p {
    margin: 0;
    line-height: 1.6;
}

.rsw-minicart-error strong {
    display: block;
    font-size: 1.1em;
    margin-bottom: 8px;
}

/* Elementor Editor Adjustments */
.elementor-editor-active .rsw-minicart-sidebar {
    z-index: 999999 !important; /* Above editor handle */
}

.elementor-editor-active .rsw-minicart-overlay {
    z-index: 999998 !important;
}

/* Fix for potential clipping in editor containers */
.elementor-editor-active .elementor-widget-minicart {
    z-index: 10;
}

/* Elementor {{WRAPPER}} Compatibility */
/* These selectors allow Elementor's dynamic styles (via {{WRAPPER}}) to override
   default styles even though sidebar/overlay are position:fixed */
.elementor-widget-container .rsw-minicart-sidebar,
.elementor-widget-container .rsw-minicart-overlay {
    /* Ensure proper specificity for Elementor override */
    pointer-events: inherit;
}

/* Ensure Elementor element wrapper doesn't create new stacking context */
.elementor-element {
    /* Preserve default stacking behavior */
    transform: none;
}

.elementor-element.elementor-widget-minicart {
    /* Allow fixed children to escape to correct layer */
    contain: none;
    isolation: auto;
}
