/* Cart Sidebar Styles */
.cart-sidebar {
    position: fixed;
    top: 0;
    right: -400px;
    width: 400px;
    height: 100vh;
    background: white;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    transition: right 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.cart-sidebar.open {
    right: 0;
}

/* Cart Header */
.cart-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e8e8e8;
    background: #f8f9fa;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.cart-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: #333;
    font-weight: 600;
}

.cart-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #666;
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    transition: all 0.3s ease;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cart-close:hover {
    background: #f0f0f0;
    color: #333;
}

/* Cart Content */
.cart-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

/* Empty Cart */
.empty-cart {
    text-align: center;
    padding: 3rem 1rem;
    color: #666;
}

.empty-cart-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-cart p {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: #333;
}

.empty-cart small {
    color: #999;
}

/* Cart Items */
.cart-item {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
    border: 1px solid #e8e8e8;
    transition: all 0.3s ease;
}

.cart-item:hover {
    background: #f0f0f0;
    border-color: #ddd;
}

.cart-item-layout {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

.cart-item-image {
    flex-shrink: 0;
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    background: linear-gradient(135deg, #ff8c42, #ffa726);
    display: flex;
    align-items: center;
    justify-content: center;
}

.cart-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.cart-item-image:hover img {
    transform: scale(1.05);
}

.cart-item-no-image {
    color: white;
    font-size: 1.5rem;
    opacity: 0.8;
}

.cart-item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 0;
}

.cart-item-title {
    font-weight: 600;
    color: #333;
    font-size: 1rem;
    line-height: 1.4;
}

.cart-item-price {
    font-size: 0.9rem;
    color: #ff8c42;
    font-weight: 500;
}

/* Quantity Controls */
.quantity-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.qty-btn {
    width: 32px;
    height: 32px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    color: #666;
}

.qty-btn:hover {
    border-color: #ff8c42;
    color: #ff8c42;
    background: rgba(255, 140, 66, 0.05);
}

.qty-btn:active {
    transform: scale(0.95);
}

.qty-btn.qty-remove {
    border-color: #e74c3c;
    color: #e74c3c;
}

.qty-btn.qty-remove:hover {
    background: rgba(231, 76, 60, 0.1);
}

.qty-display {
    min-width: 40px;
    text-align: center;
    font-weight: 600;
    color: #333;
    font-size: 1rem;
}

.cart-item-subtotal {
    font-weight: 600;
    color: #333;
    font-size: 0.95rem;
    text-align: right;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid #e8e8e8;
}

/* Cart Total */
.cart-total {
    padding: 1.5rem;
    border-top: 2px solid #e8e8e8;
    background: #f8f9fa;
    flex-shrink: 0;
}

.total-amount {
    font-size: 1.5rem;
    font-weight: bold;
    color: #333;
    text-align: center;
    margin-bottom: 1rem;
}

.checkout-btn {
    width: 100%;
    background: linear-gradient(135deg, #ff8c42, #ffa726);
    color: white;
    border: none;
    padding: 15px 20px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1.1rem;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(255, 140, 66, 0.3);
}

.checkout-btn:hover {
    background: linear-gradient(135deg, #e67e22, #ff9800);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 140, 66, 0.4);
}

.checkout-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(255, 140, 66, 0.3);
}

/* Cart Summary */
.cart-summary {
    margin-bottom: 1rem;
    padding: 1rem;
    background: white;
    border-radius: 8px;
    border: 1px solid #e8e8e8;
}

.cart-summary-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 0.5rem;
}

.cart-summary-line:last-child {
    margin-bottom: 0;
    font-weight: 600;
    color: #333;
    font-size: 1rem;
    border-top: 1px solid #e8e8e8;
    padding-top: 0.5rem;
}

/* Cart Count Badge */
.cart-count {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #e74c3c;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 0.75rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    transform: scale(1);
}

.cart-count.updated {
    animation: cartBounce 0.3s ease;
}

@keyframes cartBounce {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* Cart Button */
.cart-button {
    position: relative;
    background: none;
    border: none;
    color: #333;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cart-button:hover {
    background: rgba(255, 140, 66, 0.1);
    color: #ff8c42;
}

/* Add to Cart Button Animation */
.add-to-cart-btn {
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.add-to-cart-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: all 0.3s ease;
}

.add-to-cart-btn:active::before {
    width: 300px;
    height: 300px;
}

.add-to-cart-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none !important;
}

/* Notification Toast */
.cart-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #ff8c42;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    z-index: 10000;
    font-weight: 500;
    transition: all 0.3s ease;
    transform: translateX(100%);
    opacity: 0;
}

.cart-notification.show {
    transform: translateX(0);
    opacity: 1;
}

.cart-notification.hide {
    transform: translateX(100%);
    opacity: 0;
}

/* Loading State */
.cart-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

.cart-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid #f0f0f0;
    border-top: 3px solid #ff8c42;
    border-radius: 50%;
    animation: cartSpin 1s linear infinite;
}

@keyframes cartSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive Design */
@media (max-width: 480px) {
    .cart-sidebar {
        width: 100%;
        right: -100%;
    }
    
    .cart-sidebar.open {
        right: 0;
    }
    
    .cart-header {
        padding: 1rem;
    }
    
    .cart-content {
        padding: 0.75rem;
    }
    
    .cart-item {
        padding: 0.75rem;
        margin-bottom: 0.75rem;
    }
    
    .cart-total {
        padding: 1rem;
    }
    
    .quantity-controls {
        justify-content: center;
    }
    
    .qty-btn {
        width: 36px;
        height: 36px;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .cart-sidebar {
        background: #2c3e50;
        color: #ecf0f1;
    }
    
    .cart-header {
        background: #34495e;
        border-bottom-color: #4a5a6a;
    }
    
    .cart-header h3 {
        color: #ecf0f1;
    }
    
    .cart-close {
        color: #bdc3c7;
    }
    
    .cart-close:hover {
        background: #4a5a6a;
        color: #ecf0f1;
    }
    
    .cart-item {
        background: #34495e;
        border-color: #4a5a6a;
    }
    
    .cart-item:hover {
        background: #3d566e;
    }
    
    .cart-item-title {
        color: #ecf0f1;
    }
    
    .cart-item-subtotal {
        color: #ecf0f1;
        border-top-color: #4a5a6a;
    }
    
    .cart-total {
        background: #34495e;
        border-top-color: #4a5a6a;
    }
    
    .total-amount {
        color: #ecf0f1;
    }
    
    .qty-btn {
        background: #4a5a6a;
        border-color: #5a6a7a;
        color: #bdc3c7;
    }
    
    .qty-btn:hover {
        border-color: #ff8c42;
        background: rgba(255, 140, 66, 0.1);
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .cart-sidebar {
        border: 2px solid #000;
    }
    
    .cart-item {
        border: 2px solid #333;
    }
    
    .qty-btn {
        border: 2px solid #333;
    }
    
    .checkout-btn {
        border: 2px solid #000;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .cart-sidebar,
    .cart-count,
    .add-to-cart-btn,
    .qty-btn,
    .checkout-btn {
        transition: none;
    }
    
    .cart-count.updated {
        animation: none;
    }
    
    @keyframes cartBounce {
        0%, 100% { transform: scale(1); }
    }
}
/* ========================================
   เพิ่มลงท้าย cart-styles.css - เฉพาะสิ่งที่จำเป็น
   ======================================== */

/* ✅ รองรับ loading state ของ add-to-cart button */
.add-to-cart-btn.loading {
    opacity: 0.7;
    cursor: wait;
    position: relative;
}

.add-to-cart-btn.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    margin: auto;
    border: 2px solid transparent;
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: buttonSpin 1s linear infinite;
}

@keyframes buttonSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ✅ Success state ของ add-to-cart button */
.add-to-cart-btn.success {
    background: #27ae60 !important;
    animation: successPulse 0.3s ease;
}

@keyframes successPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* ✅ ปรับปรุงการแสดงรูปภาพใน cart-item-image ให้เรียบขึ้น */
.cart-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease, opacity 0.3s ease;
    background: #f0f0f0;
}

/* ✅ ปรับปรุง cart-item-no-image ให้รองรับการใช้เป็น fallback */
.cart-item-no-image {
    color: white;
    font-size: 1.5rem;
    opacity: 0.8;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #ff8c42, #ffa726);
    border-radius: 8px;
    transition: all 0.3s ease;
}
/* Cart Total */
.cart-total {
    padding: 1.5rem;
    border-top: 2px solid #e8e8e8;
    background: #f8f9fa;
    flex-shrink: 0;
}

.total-amount {
    font-size: 1.5rem;
    font-weight: bold;
    color: #333;
    text-align: center;
    margin-bottom: 1rem;
}

/* Cart Actions */
.cart-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1rem;
}

/* ✅ ให้แน่ใจว่าปุ่มทั้งสองแสดงเสมอ */
.cart-actions > * {
    flex-shrink: 0;
    width: 100%;
}

.checkout-btn {
    width: 100%;
    background: linear-gradient(135deg, #ff8c42, #ffa726);
    color: white;
    border: none;
    padding: 15px 20px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1.1rem;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(255, 140, 66, 0.3);
    order: 2;
}

.checkout-btn:hover {
    background: linear-gradient(135deg, #e67e22, #ff9800);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 140, 66, 0.4);
}

.checkout-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(255, 140, 66, 0.3);
}

.clear-cart-btn,
.order-btn {
    width: 100%;
    background: linear-gradient(135deg, #27ae60, #2ecc71);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 500;
    font-size: 1rem;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(39, 174, 96, 0.3);
    order: 1;
}

.clear-cart-btn:hover,
.order-btn:hover {
    background: linear-gradient(135deg, #229954, #27ae60);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(39, 174, 96, 0.4);
}

.clear-cart-btn:active,
.order-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(39, 174, 96, 0.3);
}

.clear-cart-btn:disabled,
.order-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}