/* ===================================
   Cart Page - Unified Clean Design (Matching Profile Style)
   Colors: #79499c, #784e9a, #584b75, #898e97
   =================================== */

:root {
    --primary: #79499c;
    --primary-dark: #784e9a;
    --accent-gray: #898e97;
    --dark-purple: #584b75;
    --light-bg: #f8f7fa;
    --card-bg: rgba(255, 255, 255, 0.98);
    --shadow-sm: 0 4px 15px rgba(121, 73, 156, 0.08);
    --shadow-md: 0 12px 30px rgba(121, 73, 156, 0.15);
    --shadow-lg: 0 20px 50px rgba(121, 73, 156, 0.2);
    --shadow-hover: 0 16px 40px rgba(121, 73, 156, 0.18);
    --transition: all 0.3s ease;
}

.cart-section {
    padding: 2rem 0;
    background: linear-gradient(135deg, var(--light-bg) 0%, #f2f0f5 100%);
    min-height: 80vh;
}

/* ===== Main Cards - Matching Profile Style ===== */
.cart-items-card,
.order-summary-card {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border-radius: 24px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: var(--transition);
}

.cart-items-card:hover,
.order-summary-card:hover {
    box-shadow: var(--shadow-hover);
}

/* Card Headers - Gradient like Profile */
.cart-items-card .card-header,
.order-summary-card .card-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white !important;
    padding: 1.8rem 2.5rem;
    border: none;
    position: relative;
    overflow: hidden;
}

.cart-items-card .card-header::before,
.order-summary-card .card-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.cart-items-card .card-header h5,
.order-summary-card .card-header h5 {
    font-weight: 700;
    font-size: 1.4rem;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    position: relative;
    z-index: 1;
    color: white !important;
}

.cart-items-card .card-header h5 i,
.order-summary-card .card-header h5 i {
    color: white !important;
}

.cart-items-card .card-header .badge {
    background: rgba(255, 255, 255, 0.2);
    padding: 0.5rem 1.2rem;
    border-radius: 30px;
    font-size: 0.95rem;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white !important;
}

/* ===== Cart Table - Modern Design ===== */
.cart-table {
    margin: 0;
    border-collapse: separate;
    border-spacing: 0 1rem;
}

.cart-table thead {
    display: none;
}

.cart-table tbody tr.modern-cart-row {
    display: block;
    background: white;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
    transition: var(--transition);
}

.cart-table tbody tr.modern-cart-row:hover {
    box-shadow: var(--shadow-md);
    border-left-color: var(--primary);
}

/* Table Cells - Mobile First */
.cart-table tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.3rem 1.8rem;
    border: none;
}

.cart-table tbody td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--primary);
    font-size: 0.95rem;
    min-width: 100px;
}

/* Image Cell */
.cart-table td:first-child {
    justify-content: center;
    background: linear-gradient(135deg, #f5f3f8, #f0edf5);
    padding: 2rem;
}

.cart-item-image-wrapper {
    width: 100px;
    height: 140px;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.cart-item-image-wrapper:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-hover);
}

.cart-item-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Book Details */
.cart-table td:nth-child(2) {
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9), #faf9fc);
}

.cart-item-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--dark-purple);
    margin-bottom: 0.75rem;
    line-height: 1.4;
}

.cart-item-title a {
    color: inherit;
    text-decoration: none;
    transition: var(--transition);
}

.cart-item-title a:hover {
    color: var(--primary);
    text-decoration: underline;
}

.cart-item-details small {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--accent-gray);
    font-size: 0.95rem;
    margin-bottom: 0.3rem;
}

/* Price & Total */
.cart-item-price,
.cart-item-total {
    font-weight: 800;
    font-size: 1.25rem;
    color: var(--dark-purple);
}

.cart-item-total {
    background: linear-gradient(135deg, rgba(121, 73, 156, 0.1), rgba(120, 78, 154, 0.08));
    padding: 0.6rem 1.2rem;
    border-radius: 12px;
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

/* Quantity Controls */
.quantity-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.quantity-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, #f0edf5, #e8e4f0);
    border: 2px solid rgba(121, 73, 156, 0.1);
    color: var(--dark-purple);
    font-size: 1.2rem;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.quantity-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: var(--shadow-md);
    border-color: transparent;
    transform: scale(1.05);
}

.quantity-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.quantity-input {
    width: 70px;
    height: 42px;
    text-align: center;
    border: 2px solid rgba(121, 73, 156, 0.15);
    border-radius: 12px;
    font-weight: 700;
    background: white;
    color: var(--dark-purple);
    transition: var(--transition);
}

.quantity-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(121, 73, 156, 0.15);
    outline: none;
}

.stock-info {
    margin-top: 0.75rem;
    font-size: 0.9rem;
    color: var(--accent-gray);
    background: rgba(121, 73, 156, 0.08);
    padding: 0.5rem 1rem;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

/* Remove Button */
.remove-item {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    color: white;
    border: none;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.remove-item:hover {
    box-shadow: var(--shadow-md);
    transform: scale(1.05) rotate(5deg);
    background: linear-gradient(135deg, #b91c1c, #991b1b);
}

/* Card Footer */
.cart-items-card .card-footer {
    background: linear-gradient(135deg, #f5f3f8, #f0edf5);
    padding: 1.8rem 2.5rem;
    border-top: 1px solid rgba(121, 73, 156, 0.1);
}

#continueShoppingBtn,
#clearCartBtn {
    padding: 0.9rem 2rem;
    border-radius: 14px;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    font-size: 1rem;
}

#continueShoppingBtn {
    background: white;
    color: var(--primary);
    border: 2px solid var(--primary);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

#continueShoppingBtn:hover {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

#clearCartBtn {
    background: white;
    color: #dc2626;
    border: 2px solid #dc2626;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

#clearCartBtn:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    color: white;
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

/* ===== Order Summary ===== */
.order-summary-card {
    position: sticky;
    top: 100px;
    height: fit-content;
}

.cart-totals {
    padding: 1.8rem;
    background: linear-gradient(135deg, #f5f3f8, #f0edf5);
    border-radius: 18px;
    margin: 1rem 0;
}

.cart-totals > div {
    padding: 0.85rem 0;
    border-bottom: 1px dashed rgba(121, 73, 156, 0.15);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.cart-totals .fs-5 {
    font-size: 1.4rem !important;
    color: var(--dark-purple);
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Discount Section */
.discount-section {
    padding: 1.5rem;
    background: linear-gradient(135deg, #f0edf5, #e8e4f0);
    border-radius: 18px;
    margin: 1rem 0;
}

.discount-section .form-label {
    color: var(--dark-purple);
    font-weight: 600;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.discount-section .input-group {
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.discount-section .form-control {
    border: 2px solid rgba(121, 73, 156, 0.15);
    border-right: none;
    padding: 0.85rem 1.2rem;
    font-size: 1rem;
    transition: var(--transition);
}

.discount-section .form-control:focus {
    border-color: var(--primary);
    box-shadow: none;
}

.discount-section .btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    padding: 0.85rem 1.5rem;
    font-weight: 600;
    transition: var(--transition);
}

.discount-section .btn:hover {
    background: linear-gradient(135deg, var(--primary-dark), #584b75);
    box-shadow: var(--shadow-md);
}

/* Checkout Buttons */
.checkout-btn-container .btn {
    border-radius: 16px;
    padding: 1.3rem;
    font-size: 1.1rem;
    font-weight: 700;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
    width: 100%;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.checkout-btn-container a.btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
}

.checkout-btn-container a.btn:hover {
    box-shadow: var(--shadow-hover);
    background: linear-gradient(135deg, var(--primary-dark), #584b75);
}

/* Guest Login Button */
.checkout-btn-container .btn[href*="login"] {
    background: white;
    color: var(--primary);
    border: 2px solid var(--primary);
}

.checkout-btn-container .btn[href*="login"]:hover {
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow-hover);
    transform: translateY(-1px);
}

.checkout-btn-container .alert-info {
    background: linear-gradient(135deg, rgba(121, 73, 156, 0.08), rgba(120, 78, 154, 0.05));
    border: none;
    border-radius: 14px;
    padding: 1.3rem;
    color: var(--dark-purple);
    margin-bottom: 1rem;
}

.checkout-btn-container .alert-info .alert-link {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
}

.checkout-btn-container .alert-info .alert-link:hover {
    text-decoration: underline;
}

/* Payment Methods */
.payment-methods {
    padding: 1.8rem;
    background: linear-gradient(135deg, #f5f3f8, #f0edf5);
    border-radius: 18px;
    margin: 1rem 0;
}

.payment-methods .d-flex.align-items-center {
    padding: 1.2rem;
    background: white;
    border-radius: 14px;
    border: 2px solid rgba(121, 73, 156, 0.1);
    margin-bottom: 1rem;
    transition: var(--transition);
    cursor: pointer;
}

.payment-methods .d-flex.align-items-center:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
    transform: translateX(5px);
}

.payment-methods .fs-4 {
    color: var(--primary);
    margin-left: 1rem;
    font-size: 1.8rem;
}

.payment-methods .fw-bold {
    color: var(--dark-purple);
    margin-bottom: 0.3rem;
}

.payment-methods .text-muted {
    color: var(--accent-gray);
    font-size: 0.9rem;
}

/* Security Badges */
.security-badges {
    padding: 1.5rem;
    text-align: center;
    background: linear-gradient(135deg, #f0edf5, #e8e4f0);
    border-radius: 16px;
    margin-top: 1rem;
}

.security-icons i {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, white, #faf9fc);
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0 0.75rem;
    box-shadow: var(--shadow-sm);
    font-size: 1.4rem;
    transition: var(--transition);
}

.security-icons i:hover {
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow-md);
    transform: scale(1.1);
}

/* ===== Empty Cart State ===== */
.empty-cart-section {
    padding: 3rem 0;
}

.empty-cart-animation {
    margin: 2rem 0;
}

.cart-icon-wrapper {
    position: relative;
    display: inline-block;
}

.cart-icon-wrapper i {
    font-size: 6rem;
    color: var(--primary);
    opacity: 0.3;
    animation: cartFloat 3s ease-in-out infinite;
}

.cart-empty-dots {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.cart-empty-dots span {
    display: block;
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    position: absolute;
    opacity: 0;
    animation: dotPulse 1.5s ease-in-out infinite;
}

.cart-empty-dots span:nth-child(1) {
    top: -30px;
    left: -30px;
    animation-delay: 0s;
}

.cart-empty-dots span:nth-child(2) {
    top: -30px;
    right: -30px;
    animation-delay: 0.5s;
}

.cart-empty-dots span:nth-child(3) {
    bottom: -30px;
    left: 0;
    animation-delay: 1s;
}

/* Related Books Section */
.related-books-section .card {
    background: var(--card-bg);
    border-radius: 24px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.related-books-section .card-body {
    padding: 2rem;
}

/* Animations */
@keyframes cartFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

@keyframes dotPulse {
    0%, 100% { opacity: 0; transform: scale(0); }
    50% { opacity: 1; transform: scale(1); }
}

/* Loading States */
.loading {
    opacity: 0.7;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    z-index: 10;
}

/* Form Input Alignment Fix */
.form-control {
    direction: rtl;
    text-align: right;
    padding-right: 1rem;
}

.form-control::placeholder {
    direction: rtl;
    text-align: right;
}

.discount-section .form-control {
    direction: rtl;
    text-align: right;
}

/* ===== Desktop View ===== */
@media (min-width: 992px) {
    .cart-table thead {
        display: table-header-group;
        background: linear-gradient(135deg, #f5f3f8, #f0edf5);
    }

    .cart-table thead th {
        padding: 1.5rem 1rem;
        font-weight: 700;
        color: var(--dark-purple);
        border-bottom: 3px solid var(--primary);
        font-size: 1.1rem;
    }

    .cart-table tbody tr.modern-cart-row {
        display: table-row;
        box-shadow: var(--shadow-sm);
        background: white;
    }

    .cart-table tbody tr.modern-cart-row:hover {
        box-shadow: var(--shadow-md);
    }

    .cart-table tbody td {
        display: table-cell;
        vertical-align: middle;
        text-align: center;
        padding: 1.5rem 1rem;
    }

    .cart-table tbody td::before { display: none; }

    .cart-table td:first-child { background: none; }
    .cart-table td:nth-child(2) { text-align: right; }

    /* Column widths */
    .cart-table th:nth-child(1), td:nth-child(1) { width: 12%; }
    .cart-table th:nth-child(2), td:nth-child(2) { width: 28%; }
    .cart-table th:nth-child(3), td:nth-child(3) { width: 15%; }
    .cart-table th:nth-child(4), td:nth-child(4) { width: 18%; }
    .cart-table th:nth-child(5), td:nth-child(5) { width: 15%; }
    .cart-table th:nth-child(6), td:nth-child(6) { width: 12%; }
}

/* ===== Mobile Optimizations ===== */
@media (max-width: 768px) {
    /* Card Headers - White text on mobile */
    .cart-items-card .card-header,
    .order-summary-card .card-header {
        padding: 1.2rem 1rem;
    }
    
    .cart-items-card .card-header h5,
    .order-summary-card .card-header h5 {
        color: white !important;
        font-size: 1.1rem;
    }
    
    .cart-items-card .card-header h5 i,
    .order-summary-card .card-header h5 i {
        color: white !important;
    }
    
    .cart-items-card .card-header .badge {
        background: rgba(255, 255, 255, 0.25);
        color: white !important;
        font-size: 0.85rem;
        padding: 0.4rem 0.8rem;
    }
    
    /* Cart Items Layout Improvements */
    .cart-table tbody tr.modern-cart-row {
        border-radius: 16px;
        margin-bottom: 1rem;
    }
    
    .cart-table tbody td {
        padding: 1rem;
        flex-wrap: wrap;
    }
    
    /* Book Image Cell */
    .cart-table td:first-child {
        padding: 1.5rem;
        justify-content: center;
        border-bottom: 1px solid rgba(121, 73, 156, 0.1);
    }
    
    .cart-item-image-wrapper {
        width: 100px;
        height: 140px;
        border-radius: 12px;
    }
    
    /* Book Details Cell */
    .cart-table td:nth-child(2) {
        padding: 1rem 1.5rem;
        align-items: flex-start;
    }
    
    .cart-item-title {
        font-size: 1.1rem;
        line-height: 1.3;
        margin-bottom: 0.5rem;
    }
    
    .cart-item-details small {
        font-size: 0.85rem;
        margin-bottom: 0.2rem;
    }
    
    /* Price & Quantity Row - Combine on mobile */
    .cart-table td:nth-child(3),
    .cart-table td:nth-child(4) {
        flex: 1;
        min-width: 50%;
        padding: 0.8rem 1rem;
        background: rgba(121, 73, 156, 0.03);
    }
    
    .cart-table td:nth-child(3)::before {
        content: "السعر";
    }
    
    .cart-table td:nth-child(4)::before {
        content: "الكمية";
    }
    
    /* Total & Remove Row - Combine on mobile */
    .cart-table td:nth-child(5),
    .cart-table td:nth-child(6) {
        flex: 1;
        min-width: 50%;
        padding: 0.8rem 1rem;
        background: rgba(121, 73, 156, 0.05);
    }
    
    .cart-table td:nth-child(5)::before {
        content: "المجموع";
    }
    
    .cart-table td:nth-child(6)::before {
        content: "الإزالة";
    }
    
    /* Improve Quantity Controls on Mobile */
    .quantity-controls {
        flex-direction: row;
        gap: 0.5rem;
        margin-bottom: 0.5rem;
        justify-content: center;
    }
    
    .quantity-btn {
        width: 36px;
        height: 36px;
        font-size: 1rem;
        border-radius: 10px;
    }
    
    .quantity-input {
        width: 60px;
        height: 36px;
        font-size: 0.95rem;
    }
    
    .stock-info {
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
        display: inline-block;
        width: 100%;
        text-align: center;
    }
    
    /* Improve Remove Button */
    .remove-item {
        width: 40px;
        height: 40px;
        border-radius: 10px;
        margin: 0 auto;
    }
    
    .remove-item i {
        font-size: 0.9rem;
    }
    
    /* Improve Cart Footer Buttons */
    .cart-items-card .card-footer {
        padding: 1.2rem;
    }
    
    #continueShoppingBtn,
    #clearCartBtn {
        flex: 1;
        min-width: 140px;
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
        margin: 0.25rem;
        justify-content: center;
    }
    
    #continueShoppingBtn i,
    #clearCartBtn i {
        margin: 0 0.3rem;
    }
    
    /* Order Summary Mobile Improvements */
    .order-summary-card {
        margin-top: 1.5rem;
    }
    
    .cart-totals {
        padding: 1.2rem;
        margin: 0.5rem 0;
    }
    
    .cart-totals > div {
        padding: 0.6rem 0;
        font-size: 0.95rem;
    }
    
    .cart-totals .fs-5 {
        font-size: 1.2rem !important;
    }
    
    .discount-section {
        padding: 1rem;
        margin: 0.5rem 0;
    }
    
    .discount-section .form-control {
        padding: 0.75rem 1rem;
    }
    
    .checkout-btn-container .btn {
        padding: 1rem;
        font-size: 1rem;
    }
    
    .payment-methods {
        padding: 1.2rem;
        margin: 0.5rem 0;
    }
    
    .payment-methods .d-flex.align-items-center {
        padding: 0.8rem;
    }
    
    /* Empty Cart Mobile Improvements */
    .empty-cart-section {
        padding: 2rem 0;
    }
    
    .cart-icon-wrapper i {
        font-size: 4rem;
    }
    
    .action-buttons-container .d-flex {
        flex-direction: column;
        align-items: stretch;
    }
    
    .action-buttons-container .btn-lg {
        width: 100%;
        margin-bottom: 0.75rem;
    }
}

/* Very Small Screens */
@media (max-width: 480px) {
    .cart-table tbody td:nth-child(3),
    .cart-table tbody td:nth-child(4),
    .cart-table tbody td:nth-child(5),
    .cart-table tbody td:nth-child(6) {
        min-width: 100%;
    }
    
    .cart-table tbody td {
        justify-content: space-between;
    }
    
    .cart-table td::before {
        min-width: 80px;
        font-size: 0.85rem;
    }
    
    .cart-item-image-wrapper {
        width: 80px;
        height: 110px;
    }
    
    .cart-item-title {
        font-size: 1rem;
    }
    
    .quantity-controls {
        flex-direction: column;
        align-items: center;
        gap: 0.3rem;
    }
    
    .quantity-btn,
    .quantity-input {
        width: 50px;
        height: 34px;
    }
    
    #continueShoppingBtn,
    #clearCartBtn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .cart-items-card .card-footer .d-flex {
        flex-direction: column;
        align-items: stretch;
    }
}

/* Ensure text stays white on mobile */
.cart-items-card .card-header,
.order-summary-card .card-header,
.cart-items-card .card-header h5,
.order-summary-card .card-header h5,
.cart-items-card .card-header h5 i,
.order-summary-card .card-header h5 i,
.cart-items-card .card-header .badge,
.order-summary-card .card-header .badge {
    color: white !important;
}

/* Fix for any remaining dark text */
.cart-items-card .card-header *,
.order-summary-card .card-header * {
    color: white !important;
}