/**
 * Cart Drawer Styles
 * Modern, clean design with smooth animations for both desktop and mobile.
 */

/* ═══════════════════════════════════════════════════════════════════════════
   Overlay
   ═══════════════════════════════════════════════════════════════════════════ */

.cart-drawer-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 300ms ease, visibility 300ms ease;
}

.cart-drawer-overlay-visible {
    opacity: 1;
    visibility: visible;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Drawer Container
   ═══════════════════════════════════════════════════════════════════════════ */

.cart-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--drawer-width, 420px);
    max-width: 100%;
    background: #ffffff;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
}

.cart-drawer-open {
    transform: translateX(0);
}

/* Mobile full-screen mode */
@media (max-width: 768px) {
    .cart-drawer-mobile-fullscreen {
        width: 100%;
        left: 0;
        right: 0;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Header
   ═══════════════════════════════════════════════════════════════════════════ */

.cart-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.cart-drawer-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #111827;
    margin: 0;
}

.cart-drawer-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    background: transparent;
    border: none;
    border-radius: 0.5rem;
    color: #6b7280;
    cursor: pointer;
    transition: background-color 150ms ease, color 150ms ease;
}

.cart-drawer-close:hover {
    background-color: #f3f4f6;
    color: #111827;
}

.cart-drawer-close:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Content Area
   ═══════════════════════════════════════════════════════════════════════════ */

.cart-drawer-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    position: relative;
}

/* Custom scrollbar */
.cart-drawer-content::-webkit-scrollbar {
    width: 6px;
}

.cart-drawer-content::-webkit-scrollbar-track {
    background: transparent;
}

.cart-drawer-content::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.cart-drawer-content::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Empty State
   ═══════════════════════════════════════════════════════════════════════════ */

.cart-drawer-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem 1.5rem;
    min-height: 300px;
}

.cart-drawer-empty-icon {
    color: #e5e7eb;
    margin-bottom: 1.5rem;
}

.cart-drawer-empty-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #111827;
    margin: 0 0 0.5rem 0;
}

.cart-drawer-empty-text {
    font-size: 0.875rem;
    color: #6b7280;
    margin: 0 0 2rem 0;
}

.cart-drawer-empty-btn {
    display: inline-block;
    padding: 0.75rem 2rem;
    background: #111827;
    color: #ffffff;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 9999px;
    text-decoration: none;
    transition: background-color 150ms ease, transform 150ms ease;
}

.cart-drawer-empty-btn:hover {
    background: #1f2937;
    transform: translateY(-1px);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Cart Items
   ═══════════════════════════════════════════════════════════════════════════ */

.cart-drawer-items {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.cart-drawer-item {
    display: flex;
    gap: 1rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid #f3f4f6;
    transition: opacity 200ms ease, transform 200ms ease;
}

.cart-drawer-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

/* Item Image */
.cart-drawer-item-image {
    width: 80px;
    height: 80px;
    flex-shrink: 0;
    background-color: #f3f4f6;
    border-radius: 0.5rem;
    overflow: hidden;
    position: relative;
}

.cart-drawer-item-image img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Item Details */
.cart-drawer-item-details {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.cart-drawer-item-header {
    display: flex;
    gap: 0.5rem;
    justify-content: space-between;
}

.cart-drawer-item-info {
    flex: 1;
    min-width: 0;
}

.cart-drawer-item-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: #111827;
    text-decoration: none;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
    transition: color 150ms ease;
}

.cart-drawer-item-title:hover {
    color: #3b82f6;
}

.cart-drawer-item-options {
    font-size: 0.75rem;
    color: #6b7280;
    margin: 0.25rem 0 0 0;
}

.cart-drawer-item-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    flex-shrink: 0;
    background: transparent;
    border: none;
    border-radius: 0.375rem;
    color: #9ca3af;
    cursor: pointer;
    transition: background-color 150ms ease, color 150ms ease;
}

.cart-drawer-item-remove:hover {
    background-color: #fef2f2;
    color: #ef4444;
}

/* Item Footer (Quantity + Price) */
.cart-drawer-item-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.cart-drawer-item-qty {
    display: flex;
    align-items: center;
    border: 1px solid #e5e7eb;
    border-radius: 0.375rem;
    overflow: hidden;
}

.cart-drawer-qty-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    background: transparent;
    border: none;
    color: #374151;
    cursor: pointer;
    transition: background-color 150ms ease;
}

.cart-drawer-qty-btn:hover:not(.disabled) {
    background-color: #f3f4f6;
}

.cart-drawer-qty-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.cart-drawer-qty-value {
    width: 2.5rem;
    text-align: center;
    font-size: 0.875rem;
    font-weight: 500;
    color: #111827;
    user-select: none;
}

.cart-drawer-item-price {
    font-size: 0.9375rem;
    font-weight: 700;
    color: #111827;
    margin: 0;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Footer (Summary + Actions)
   ═══════════════════════════════════════════════════════════════════════════ */

.cart-drawer-footer {
    flex-shrink: 0;
    padding: 1.5rem;
    border-top: 1px solid #e5e7eb;
    background: #ffffff;
    display: none; /* Hidden when empty */
    flex-direction: column;
    gap: 1.25rem;
}

/* Coupon Section (Optional) */
.cart-drawer-coupon {
    display: flex;
    gap: 0.5rem;
}

.cart-drawer-coupon-input {
    flex: 1;
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    outline: none;
    transition: border-color 150ms ease;
}

.cart-drawer-coupon-input:focus {
    border-color: #3b82f6;
}

.cart-drawer-coupon-btn {
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    background: #f3f4f6;
    color: #111827;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background-color 150ms ease;
}

.cart-drawer-coupon-btn:hover {
    background: #e5e7eb;
}

/* Summary */
.cart-drawer-summary {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.cart-drawer-summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.875rem;
}

.cart-drawer-summary-label {
    color: #6b7280;
}

.cart-drawer-summary-value {
    color: #111827;
    font-weight: 500;
}

.cart-drawer-summary-shipping {
    color: #10b981;
}

.cart-drawer-summary-total-row {
    padding-top: 0.75rem;
    border-top: 1px solid #e5e7eb;
    font-size: 1rem;
}

.cart-drawer-summary-total-label {
    color: #111827;
    font-weight: 700;
}

.cart-drawer-summary-total-value {
    color: #111827;
    font-weight: 700;
    font-size: 1.125rem;
}

/* Action Buttons */
.cart-drawer-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.cart-drawer-checkout-btn {
    display: block;
    width: 100%;
    padding: 0.875rem 1.5rem;
    background: #111827;
    color: #ffffff;
    font-size: 0.875rem;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    border-radius: 9999px;
    transition: background-color 150ms ease, transform 150ms ease;
}

.cart-drawer-checkout-btn:hover {
    background: #1f2937;
    transform: translateY(-1px);
}

.cart-drawer-view-cart-btn {
    display: block;
    width: 100%;
    padding: 0.75rem 1.5rem;
    background: transparent;
    color: #374151;
    font-size: 0.875rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    border: 1px solid #d1d5db;
    border-radius: 9999px;
    transition: background-color 150ms ease, border-color 150ms ease;
}

.cart-drawer-view-cart-btn:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Loading Overlay
   ═══════════════════════════════════════════════════════════════════════════ */

.cart-drawer-loading {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    opacity: 0;
    visibility: hidden;
    transition: opacity 200ms ease, visibility 200ms ease;
}

.cart-drawer-loading-visible {
    opacity: 1;
    visibility: visible;
}

.cart-drawer-spinner {
    width: 2.5rem;
    height: 2.5rem;
    border: 3px solid #e5e7eb;
    border-top-color: #111827;
    border-radius: 50%;
    animation: cart-drawer-spin 0.7s linear infinite;
}

@keyframes cart-drawer-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Responsive Adjustments
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
    .cart-drawer-header {
        padding: 1rem 1.25rem;
    }

    .cart-drawer-title {
        font-size: 1.125rem;
    }

    .cart-drawer-content {
        padding: 1.25rem;
    }

    .cart-drawer-footer {
        padding: 1.25rem;
    }

    .cart-drawer-item-image {
        width: 70px;
        height: 70px;
    }

    .cart-drawer-item-title {
        font-size: 0.8125rem;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Accessibility
   ═══════════════════════════════════════════════════════════════════════════ */

.cart-drawer:focus-within {
    outline: none;
}

/* Focus visible styles for keyboard navigation */
.cart-drawer-close:focus-visible,
.cart-drawer-item-remove:focus-visible,
.cart-drawer-qty-btn:focus-visible,
.cart-drawer-checkout-btn:focus-visible,
.cart-drawer-view-cart-btn:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Animation Enhancements
   ═══════════════════════════════════════════════════════════════════════════ */

/* Smooth fade-in for items */
.cart-drawer-item {
    animation: cart-drawer-item-fade-in 300ms ease-out;
}

@keyframes cart-drawer-item-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Prevent animation on initial page load */
.cart-drawer:not(.cart-drawer-open) .cart-drawer-item {
    animation: none;
}
