/**
 * CartPopup - Shopping Cart Popup Styles
 *
 * Modern, clean design with smooth animations.
 * Fully responsive with mobile-first approach.
 */

/* ========== CSS VARIABLES ========== */
.cart-popup {
    --cart-popup-width: 420px;
    --cart-popup-width-wide: 580px;
    --cart-popup-max-height: calc(100vh - 40px);
    --cart-popup-bg: #ffffff;
    --cart-popup-border-radius: 16px;
    --cart-popup-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --cart-popup-overlay-bg: rgba(0, 0, 0, 0.5);

    /* Colors - inherit from page accent or use defaults */
    --cart-popup-primary: var(--btn-primary-bg, var(--accent-color, #ca000f));
    --cart-popup-primary-hover: var(--btn-primary-hover-bg, var(--accent-color-dark, #a80000));
    --cart-popup-success: #10b981;
    --cart-popup-danger: #ef4444;
    --cart-popup-text: #1f2937;
    --cart-popup-text-muted: #6b7280;
    --cart-popup-border: #e5e7eb;

    /* Spacing */
    --cart-popup-padding: 1.25rem;
    --cart-popup-gap: 1rem;

    /* Animation */
    --cart-popup-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Wide variant for items with many options */
.cart-popup--wide {
    --cart-popup-width: var(--cart-popup-width-wide);
}

/* ========== BODY LOCK ========== */
body.cart-popup-body-lock {
    overflow: hidden;
    padding-right: var(--scrollbar-width, 0);
}

/* ========== MAIN CONTAINER ========== */
.cart-popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    pointer-events: none;
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
    padding: 20px;
}

.cart-popup--center {
    justify-content: center;
    align-items: center;
}

/* ========== OVERLAY ========== */
.cart-popup__overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--cart-popup-overlay-bg);
    opacity: 0;
    transition: opacity var(--cart-popup-transition);
    pointer-events: none;
}

.cart-popup--open .cart-popup__overlay {
    opacity: 1;
    pointer-events: auto;
}

/* ========== POPUP CONTAINER ========== */
.cart-popup__container {
    position: relative;
    width: var(--cart-popup-width);
    max-width: calc(100vw - 40px);
    max-height: var(--cart-popup-max-height);
    background: var(--cart-popup-bg);
    border-radius: var(--cart-popup-border-radius);
    box-shadow: var(--cart-popup-shadow);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    opacity: 0;
    transition: transform var(--cart-popup-transition), opacity var(--cart-popup-transition);
    pointer-events: none;
    overflow: hidden;
}

.cart-popup--center .cart-popup__container {
    transform: translateY(-30px) scale(0.95);
}

.cart-popup--open .cart-popup__container {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}

.cart-popup--center.cart-popup--open .cart-popup__container {
    transform: translateY(0) scale(1);
}

/* ========== HEADER ========== */
.cart-popup__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--cart-popup-padding);
    border-bottom: 1px solid var(--cart-popup-border);
    flex-shrink: 0;
}

.cart-popup__title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--cart-popup-text);
}

.cart-popup__title i {
    font-size: 1.125rem;
    color: var(--cart-popup-primary);
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25em;
    height: 1.25em;
    transform: translateY(-1px);
}

.cart-popup__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: 8px;
    color: var(--cart-popup-text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

.cart-popup__close:hover {
    background: var(--cart-popup-border);
    color: var(--cart-popup-text);
}

/* ========== SUCCESS MESSAGE ========== */
.cart-popup__success-message {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem var(--cart-popup-padding);
    background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
    color: #065f46;
    font-size: 0.875rem;
    font-weight: 500;
    transform: translateY(-100%);
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transition: all var(--cart-popup-transition);
}

.cart-popup__success-message--visible {
    transform: translateY(0);
    opacity: 1;
    max-height: 60px;
}

.cart-popup__success-message i {
    font-size: 1rem;
    color: var(--cart-popup-success);
}

/* ========== CONTENT AREA ========== */
.cart-popup__content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 100px;
    max-height: 50vh;
}

/* Loading state */
.cart-popup__loading {
    display: none;
    justify-content: center;
    align-items: center;
    padding: 3rem;
}

.cart-popup--loading .cart-popup__loading {
    display: flex;
}

.cart-popup--loading .cart-popup__items,
.cart-popup--loading .cart-popup__empty {
    display: none !important;
}

/* Empty state */
.cart-popup__empty {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem var(--cart-popup-padding);
    text-align: center;
    color: var(--cart-popup-text-muted);
}

.cart-popup--empty .cart-popup__empty {
    display: flex;
}

.cart-popup--empty .cart-popup__items,
.cart-popup--empty .cart-popup__footer {
    display: none !important;
}

.cart-popup__empty i {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: var(--cart-popup-text-muted);
}

/* Empty state button - use theme primary color (stronger specificity to override Bootstrap) */
.cart-popup .cart-popup__empty .btn-outline-primary,
.cart-popup .cart-popup__empty .btn.btn-outline-primary,
.cart-popup__empty .btn-outline-primary {
    --bs-btn-color: var(--cart-popup-primary, #ca000f) !important;
    --bs-btn-border-color: var(--cart-popup-primary, #ca000f) !important;
    --bs-btn-hover-bg: var(--cart-popup-primary, #ca000f) !important;
    --bs-btn-hover-border-color: var(--cart-popup-primary, #ca000f) !important;
    --bs-btn-active-bg: var(--cart-popup-primary, #ca000f) !important;
    --bs-btn-active-border-color: var(--cart-popup-primary, #ca000f) !important;
    color: var(--cart-popup-primary, #ca000f) !important;
    border-color: var(--cart-popup-primary, #ca000f) !important;
    background: transparent !important;
}

.cart-popup .cart-popup__empty .btn-outline-primary:hover,
.cart-popup .cart-popup__empty .btn.btn-outline-primary:hover,
.cart-popup__empty .btn-outline-primary:hover {
    background: var(--cart-popup-primary, #ca000f) !important;
    border-color: var(--cart-popup-primary, #ca000f) !important;
    color: #fff !important;
}

.cart-popup__empty p {
    margin-bottom: 1.5rem;
    font-size: 1rem;
}

/* ========== CART ITEMS ========== */
.cart-popup__items {
    padding: var(--cart-popup-padding);
    display: flex;
    flex-direction: column;
    gap: var(--cart-popup-gap);
}

.cart-popup__item {
    display: grid;
    grid-template-columns: 70px 1fr;
    gap: 0.75rem;
    align-items: start;
    padding: 0.75rem;
    background: #f9fafb;
    border-radius: 12px;
    transition: all 0.2s ease;
}

.cart-popup__item:hover {
    background: #f3f4f6;
}

/* Item image */
.cart-popup__item-image {
    width: 70px;
    height: 70px;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--cart-popup-border);
    flex-shrink: 0;
}

.cart-popup__item-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Item info container - right side */
.cart-popup__item-info {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Item header - name and remove button */
.cart-popup__item-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
}

.cart-popup__item-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--cart-popup-text);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    flex: 1;
}

/* Options container */
.cart-popup__item-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

/* Horizontal 2-column grid layout for many options (>3) */
.cart-popup__item-options--grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.25rem 0.5rem;
}

.cart-popup__item-option {
    font-size: 0.7rem;
    color: var(--cart-popup-text-muted);
    background: #fff;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    border: 1px solid var(--cart-popup-border);
    line-height: 1.3;
    display: inline-flex;
    gap: 0.2rem;
    max-width: 100%;
}

/* In grid mode, options stack vertically (label above, value below) */
.cart-popup__item-options--grid .cart-popup__item-option {
    min-width: 0;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.1rem;
}

.cart-popup__item-option-label {
    font-weight: 600;
    color: var(--cart-popup-text);
    white-space: nowrap;
    flex-shrink: 0;
}

.cart-popup__item-option-value {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* In grid mode, allow value to wrap */
.cart-popup__item-options--grid .cart-popup__item-option-value {
    white-space: normal;
    word-break: break-word;
    line-height: 1.4;
}

/* Item footer - quantity and total */
.cart-popup__item-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 0.25rem;
}

/* Item quantity */
.cart-popup__item-quantity {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.cart-popup__quantity-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--cart-popup-border);
    background: #fff;
    border-radius: 6px;
    color: var(--cart-popup-text);
    cursor: pointer;
    transition: all 0.2s ease;
}

.cart-popup__quantity-btn:hover:not(:disabled) {
    border-color: var(--cart-popup-primary);
    color: var(--cart-popup-primary);
}

.cart-popup__quantity-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.cart-popup__quantity-input {
    width: 40px;
    height: 28px;
    text-align: center;
    border: 1px solid var(--cart-popup-border);
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    -moz-appearance: textfield;
}

.cart-popup__quantity-input::-webkit-outer-spin-button,
.cart-popup__quantity-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.cart-popup__quantity-input:focus {
    outline: none;
    border-color: var(--cart-popup-primary);
}

/* Item total */
.cart-popup__item-total {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--cart-popup-text);
    white-space: nowrap;
    min-width: 70px;
    text-align: right;
}

/* Remove button */
.cart-popup__item-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: 6px;
    color: var(--cart-popup-text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 0.6;
}

.cart-popup__item-remove:hover {
    background: #fee2e2;
    color: var(--cart-popup-danger);
    opacity: 1;
}

/* ========== FOOTER ========== */
.cart-popup__footer {
    border-top: 1px solid var(--cart-popup-border);
    padding: var(--cart-popup-padding);
    flex-shrink: 0;
    background: var(--cart-popup-bg);
}

/* Summary */
.cart-popup__summary {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.cart-popup__summary-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    color: var(--cart-popup-text-muted);
}

.cart-popup__summary-row--discount {
    color: var(--cart-popup-success);
}

.cart-popup__summary-row--total {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--cart-popup-text);
    padding-top: 0.5rem;
    border-top: 1px solid var(--cart-popup-border);
    margin-top: 0.25rem;
}

/* Actions */
.cart-popup__actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.cart-popup__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.cart-popup__btn--secondary {
    background: #f3f4f6;
    color: var(--cart-popup-text);
}

.cart-popup__btn--secondary:hover {
    background: #e5e7eb;
}

.cart-popup__btn--primary {
    background: var(--cart-popup-primary);
    color: #fff;
}

.cart-popup__btn--primary:hover {
    background: var(--cart-popup-primary-hover);
    color: #fff;
    text-decoration: none;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 640px) {
    .cart-popup {
        padding: 0;
    }

    .cart-popup__container {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile browsers */
        max-height: none;
        border-radius: 0;
        transform: translateY(100%);
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .cart-popup--open .cart-popup__container {
        transform: translateY(0);
    }

    /* Hide footer when cart is closed (since it's position: fixed) */
    .cart-popup:not(.cart-popup--open) .cart-popup__footer {
        transform: translateY(100%);
        opacity: 0;
        pointer-events: none;
    }

    .cart-popup--open .cart-popup__footer {
        transform: translateY(0);
        opacity: 1;
        pointer-events: auto;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    }

    .cart-popup__content {
        flex: 1;
        max-height: none;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        /* Space for fixed footer - must be larger than footer height */
        /* Footer has: summary (~100px) + 2 stacked buttons (~110px) + padding (32px) = ~250px */
        padding-bottom: 280px;
    }

    /*
     * MOBILE FOOTER - Fixed at bottom like product page sticky bar
     * This ensures the buttons are always visible above browser UI
     */
    .cart-popup__footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 10000;
        background: var(--cart-popup-bg, #ffffff);
        border-top: 1px solid var(--cart-popup-border, #e5e7eb);
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
        padding: 1rem;
    }

    /* Simplified item layout for mobile */
    .cart-popup__item {
        grid-template-columns: 60px 1fr;
        gap: 0.5rem;
    }

    .cart-popup__item-image {
        width: 60px;
        height: 60px;
    }

    /* Stack options in single column on mobile */
    .cart-popup__item-options--grid {
        grid-template-columns: 1fr;
    }

    .cart-popup__item-footer {
        flex-wrap: wrap;
    }

    .cart-popup__actions {
        grid-template-columns: 1fr;
    }

    .cart-popup__btn {
        padding: 0.875rem 1rem;
    }
}

/* ========== SCROLLBAR STYLING ========== */
.cart-popup__content::-webkit-scrollbar {
    width: 6px;
}

.cart-popup__content::-webkit-scrollbar-track {
    background: transparent;
}

.cart-popup__content::-webkit-scrollbar-thumb {
    background: var(--cart-popup-border);
    border-radius: 3px;
}

.cart-popup__content::-webkit-scrollbar-thumb:hover {
    background: #d1d5db;
}

/* ========== ANIMATION HELPERS ========== */
@keyframes cart-popup-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.cart-popup__item--removing {
    animation: cart-popup-shake 0.3s ease;
    opacity: 0.5;
}
