/* ============================================
   MODERN CART SIDEBAR - SLIDE-IN DRAWER
   BooksLibrary E-commerce Cart Enhancements
   ============================================ */

/* ============================================
   BACKDROP OVERLAY
   ============================================ */
.cart-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.cart-backdrop.active {
    opacity: 1;
    visibility: visible;
}

/* ============================================
   SIDEBAR CONTAINER
   ============================================ */
.cart-sidebar {
    position: fixed;
    top: 0;
    right: -450px; /* Hidden off-screen for RTL */
    width: 420px;
    max-width: 90vw;
    height: 100vh;
    background: #fff;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

/* LTR Support */
[dir="ltr"] .cart-sidebar {
    right: auto;
    left: -450px;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[dir="ltr"] .cart-sidebar.active {
    left: 0;
}

.cart-sidebar.active {
    right: 0;
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */
@media (max-width: 576px) {
    .cart-sidebar {
        width: 100vw;
        max-width: 100vw;
        right: -100vw;
    }

    [dir="ltr"] .cart-sidebar {
        left: -100vw;
    }
}

/* Tablet breakpoint */
@media (max-width: 991px) {
    .cart-sidebar {
        width: 380px;
    }
}

/* ============================================
   SIDEBAR HEADER
   ============================================ */
.cart-sidebar-header {
    padding: 20px;
    border-bottom: 1px solid #e5e5e5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
    flex-shrink: 0;
}

.cart-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #333;
}

.cart-title svg {
    width: 20px;
    height: 20px;
}

.cart-count {
    color: #666;
    font-size: 14px;
    font-weight: 400;
}

.cart-close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: #666;
    cursor: pointer;
    padding: 5px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease, transform 0.2s ease;
    border-radius: 4px;
}

.cart-close-btn:hover {
    color: #ef3139;
    background: #f5f5f5;
    transform: rotate(90deg);
}

.cart-close-btn:focus {
    outline: 2px solid #ef3139;
    outline-offset: 2px;
}

/* ============================================
   SIDEBAR BODY - SCROLLABLE AREA
   ============================================ */
.cart-sidebar-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;

    /* Custom scrollbar */
    scrollbar-width: thin;
    scrollbar-color: #ccc #f5f5f5;
}

.cart-sidebar-body::-webkit-scrollbar {
    width: 6px;
}

.cart-sidebar-body::-webkit-scrollbar-track {
    background: #f5f5f5;
}

.cart-sidebar-body::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.cart-sidebar-body::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* ============================================
   CART ITEMS LIST
   ============================================ */
.cart-items-list {
    list-style: none;
    padding: 0;
    margin: 0 0 30px 0;
}

.cart-item {
    display: flex;
    gap: 15px;
    padding: 15px 0;
    border-bottom: 1px solid #e5e5e5;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.cart-item:last-child {
    border-bottom: none;
}

/* Item removal animation */
.cart-item.removing {
    opacity: 0;
    transform: translateX(20px);
}

/* ============================================
   CART ITEM COMPONENTS
   ============================================ */
.cart-item-image {
    flex-shrink: 0;
    width: 80px;
    height: 100px;
}

.cart-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #e5e5e5;
}

.cart-item-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0; /* Prevents overflow */
}

.cart-item-title {
    margin: 0;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
}

.cart-item-title a {
    color: #333;
    text-decoration: none;
    transition: color 0.2s ease;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.cart-item-title a:hover {
    color: var(--primary-hover, #ef3139);
}

.cart-item-price-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.cart-item-price {
    font-size: 16px;
    font-weight: 600;
    color: var(--primary-hover, #ef3139);
}

.cart-item-remove {
    background: none;
    border: none;
    color: #999;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 0;
    transition: color 0.2s ease;
    align-self: flex-start;
}

.cart-item-remove:hover {
    color: #ef3139;
}

.cart-item-remove:focus {
    outline: 2px solid #ef3139;
    outline-offset: 2px;
}

/* ============================================
   QUANTITY CONTROLS
   ============================================ */
.quantity-controls {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #f5f5f5;
    border-radius: 20px;
    padding: 4px 8px;
}

.qty-btn {
    background: #fff;
    border: 1px solid #ddd;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 10px;
    color: #666;
    padding: 0;
}

.qty-btn:hover:not(:disabled) {
    background: var(--primary-hover, #ef3139);
    border-color: var(--primary-hover, #ef3139);
    color: #fff;
    transform: scale(1.1);
}

.qty-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.qty-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.qty-btn:focus {
    outline: 2px solid var(--primary-hover, #ef3139);
    outline-offset: 2px;
}

.qty-display {
    min-width: 30px;
    text-align: center;
    font-weight: 600;
    font-size: 14px;
    color: #333;
}

/* Quantity pulse animation */
@keyframes qtyPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
        color: var(--primary-hover, #ef3139);
    }
}

.qty-pulse {
    animation: qtyPulse 0.3s ease;
}

/* ============================================
   PRODUCT QUANTITY CONTROLS (ON PRODUCT PAGE)
   ============================================ */
.product-cart-action {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.product-quantity-controls {
    display: inline-flex;
    background: #f5f5f5;
    border-radius: 25px;
    padding: 8px 15px;
    align-items: center;
    gap: 12px;
}

.product-quantity-controls .qty-btn {
    width: 28px;
    height: 28px;
    font-size: 12px;
}

.product-quantity-controls .qty-display {
    font-size: 16px;
    min-width: 35px;
}

/* ============================================
   EMPTY CART STATE
   ============================================ */
.cart-empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}

.cart-empty-icon {
    font-size: 64px;
    color: #ddd;
    margin-bottom: 20px;
}

.cart-empty-state h4 {
    font-size: 18px;
    color: #666;
    margin-bottom: 10px;
    font-weight: 600;
}

.cart-empty-state p {
    font-size: 14px;
    color: #999;
    margin: 0;
}

/* ============================================
   RECOMMENDATIONS SECTION
   ============================================ */
.cart-recommendations {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 2px solid #e5e5e5;
}

.recommendations-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 15px;
    color: #333;
}

.recommendations-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

@media (max-width: 576px) {
    .recommendations-grid {
        grid-template-columns: 1fr;
    }
}

.recommendation-item {
    text-align: center;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    padding: 10px;
    transition: all 0.2s ease;
    cursor: pointer;
    text-decoration: none;
    display: block;
}

.recommendation-item:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
    border-color: var(--primary-hover, #ef3139);
}

.recommendation-item img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 8px;
}

.recommendation-item-title {
    font-size: 12px;
    line-height: 1.3;
    margin-bottom: 5px;
    color: #333;
    max-height: 2.6em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.recommendation-item-price {
    font-size: 14px;
    font-weight: 600;
    color: var(--primary-hover, #ef3139);
}

.recommendation-item-price small {
    text-decoration: line-through;
    color: #999;
    font-size: 11px;
    margin-left: 5px;
}

.recommendation-item .btn {
    margin-top: 8px;
}

/* ============================================
   SIDEBAR FOOTER
   ============================================ */
.cart-sidebar-footer {
    padding: 20px;
    border-top: 1px solid #e5e5e5;
    background: #f8f9fa;
    flex-shrink: 0;
}

.cart-subtotal {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
    font-size: 16px;
    font-weight: 600;
}

.cart-subtotal-amount {
    color: var(--primary-hover, #ef3139);
}

/* Price update animation */
@keyframes priceUpdate {
    0%, 100% {
        background-color: transparent;
    }
    50% {
        background-color: #fffbcc;
        padding: 2px 6px;
        border-radius: 4px;
    }
}

.price-update {
    animation: priceUpdate 0.5s ease;
}

.cart-view-btn {
    width: 100%;
    padding: 14px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 4px;
    margin-bottom: 10px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.cart-view-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.cart-footer-note {
    text-align: center;
    font-size: 12px;
    color: #999;
    margin: 0;
}

/* ============================================
   LOADING STATES
   ============================================ */
.cart-sidebar-body.loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.cart-sidebar-body.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary-hover, #ef3139);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ============================================
   CART ICON ANIMATION
   ============================================ */
@keyframes cartBounce {
    0%, 100% { transform: scale(1); }
    25% { transform: scale(1.2); }
    50% { transform: scale(0.9); }
    75% { transform: scale(1.1); }
}

.cart-bounce {
    animation: cartBounce 0.6s ease;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes slideIn {
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.cart-sidebar.active {
    animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.cart-backdrop.active {
    animation: fadeIn 0.3s ease;
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
.cart-sidebar:focus {
    outline: none;
}

/* Skip link for keyboard users */
.cart-skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #000;
    color: #fff;
    padding: 8px;
    text-decoration: none;
    border-radius: 4px;
    z-index: 100;
}

.cart-skip-link:focus {
    top: 10px;
}

/* ============================================
   REDUCED MOTION PREFERENCE
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .cart-sidebar,
    .cart-backdrop,
    .cart-item,
    .qty-btn,
    .cart-view-btn,
    .recommendation-item {
        transition: none !important;
        animation: none !important;
    }

    .cart-sidebar.active {
        animation: none;
    }

    .cart-backdrop.active {
        animation: none;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .cart-sidebar,
    .cart-backdrop {
        display: none;
    }
}
