/* ============================================
   CART SIDEBAR - SLIDE-IN DRAWER
   ============================================ */

/* ── Backdrop ── */
.cart-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: opacity .28s ease, visibility .28s ease;
}
.cart-backdrop.active {
    opacity: 1;
    visibility: visible;
}

/* ── Sidebar shell ──
   KEY: use top:0; bottom:0 instead of height:100vh
   so mobile browser chrome is handled automatically */
.cart-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    right: -460px;
    width: 420px;
    max-width: 92vw;
    background: #fff;
    box-shadow: -4px 0 24px rgba(0,0,0,.12);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    transition: right .3s cubic-bezier(.4,0,.2,1);
}
.cart-sidebar.active { right: 0; }

[dir="ltr"] .cart-sidebar {
    right: auto;
    left: -460px;
    box-shadow: 4px 0 24px rgba(0,0,0,.12);
    transition: left .3s cubic-bezier(.4,0,.2,1);
}
[dir="ltr"] .cart-sidebar.active { left: 0; }

@media (max-width: 991px) and (min-width: 769px) {
    .cart-sidebar { width: 380px; }
}
@media (max-width: 768px) {
    .cart-sidebar {
        width: 100vw;
        max-width: 100vw;
        right: -100vw;
    }
    [dir="ltr"] .cart-sidebar { left: -100vw; }
}

/* ── Header (fixed top) ── */
.cart-sidebar-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #ececec;
    background: #fff;
}
.cart-title {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #222;
}
.cart-title svg { width: 20px; height: 20px; }
.cart-count { color: #888; font-size: 14px; font-weight: 400; }

.cart-close-btn {
    background: none;
    border: none;
    font-size: 22px;
    color: #777;
    cursor: pointer;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background .2s, color .2s;
}
.cart-close-btn:hover {
    background: #fef2f2;
    color: #e63946;
}

/* ── Body (scrollable middle) ──
   flex:1 + min-height:0 is the correct pattern
   for a scrollable flex child */
.cart-sidebar-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 20px;
    scrollbar-width: thin;
    scrollbar-color: #ddd #f8f8f8;
}
.cart-sidebar-body::-webkit-scrollbar { width: 5px; }
.cart-sidebar-body::-webkit-scrollbar-track { background: #f8f8f8; }
.cart-sidebar-body::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

/* ── Footer (fixed bottom) ── */
.cart-sidebar-footer {
    flex-shrink: 0;
    padding: 16px 20px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid #ececec;
    background: #fff;
    box-shadow: 0 -4px 12px rgba(0,0,0,.06);
}

/* ── Cart Items ── */
.cart-items-list {
    list-style: none;
    padding: 0;
    margin: 0 0 20px;
}
.cart-item {
    display: flex;
    gap: 12px;
    padding: 14px 0;
    border-bottom: 1px solid #f0f0f0;
    transition: opacity .25s;
    align-items: flex-start;
}
.cart-item:last-child { border-bottom: none; }
.cart-item.removing { opacity: 0; transform: translateX(20px); }

.cart-item-image {
    flex-shrink: 0;
    width: 66px;
    height: 88px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #eee;
}
.cart-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.cart-item-details {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.cart-item-title {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.4;
}
.cart-item-title a {
    color: #222;
    text-decoration: none;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.cart-item-title a:hover { color: #e63946; }

.cart-item-price {
    font-size: 14px;
    font-weight: 700;
    color: #e63946;
}

/* quantity + remove on same row */
.cart-item-price-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.cart-item-remove {
    background: none;
    border: none;
    color: #ccc;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
    border-radius: 6px;
    transition: color .2s, background .2s;
    margin-inline-start: auto;
}
.cart-item-remove:hover {
    color: #e63946;
    background: #fff0f0;
}

/* ── Quantity Controls ── */
.quantity-controls {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f5f5f5;
    border-radius: 20px;
    padding: 3px 8px;
}
.qty-btn {
    background: #fff;
    border: 1px solid #e0e0e0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 10px;
    color: #555;
    transition: all .2s;
    padding: 0;
}
.qty-btn:hover:not(:disabled) {
    background: #e63946;
    border-color: #e63946;
    color: #fff;
}
.qty-btn:disabled { opacity: .4; cursor: not-allowed; }
.qty-display {
    min-width: 26px;
    text-align: center;
    font-weight: 700;
    font-size: 14px;
    color: #222;
}

/* ── Product page quantity controls ── */
.product-cart-action { transition: all .3s ease; }
.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; }

/* ── Subtotal row ── */
.cart-subtotal {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 15px;
    font-weight: 600;
    color: #222;
}
.cart-subtotal-amount { color: #e63946; font-size: 18px; }

/* ── Checkout button ── */
.cart-view-btn {
    display: block;
    width: 100%;
    padding: 13px;
    text-align: center;
    background: #e63946;
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    text-decoration: none;
    margin-bottom: 8px;
    transition: background .2s, transform .15s;
}
.cart-view-btn:hover {
    background: #c62833;
    color: #fff;
    transform: translateY(-1px);
    text-decoration: none;
}

.cart-footer-note {
    text-align: center;
    font-size: 11px;
    color: #aaa;
    margin: 6px 0 0;
}

/* ── Empty state ── */
.cart-empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #bbb;
}
.cart-empty-icon {
    font-size: 56px;
    color: #e0e0e0;
    margin-bottom: 16px;
    display: block;
}
.cart-empty-state h4 {
    font-size: 17px;
    color: #777;
    margin-bottom: 8px;
    font-weight: 600;
}
.cart-empty-state p {
    font-size: 13px;
    color: #aaa;
    margin: 0;
}

/* ── Recommendations ── */
.cart-recommendations {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #f0f0f0;
}
.recommendations-title {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 12px;
    color: #444;
}
.recommendations-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
@media (max-width: 576px) {
    .recommendations-grid { grid-template-columns: 1fr; }
}
.recommendation-item {
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 8px;
    display: block;
    text-decoration: none;
    transition: box-shadow .2s, border-color .2s;
}
.recommendation-item:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,.08);
    border-color: #e63946;
}
.recommendation-item img {
    width: 100%;
    height: 110px;
    object-fit: cover;
    border-radius: 5px;
    margin-bottom: 6px;
}
.recommendation-item-title {
    font-size: 11px;
    color: #333;
    line-height: 1.3;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.recommendation-item-price {
    font-size: 13px;
    font-weight: 700;
    color: #e63946;
}
.recommendation-item-price small {
    text-decoration: line-through;
    color: #bbb;
    font-size: 10px;
    margin-left: 4px;
}

/* ── Loading ── */
.cart-sidebar-body.loading {
    opacity: .6;
    pointer-events: none;
    position: relative;
}
.cart-sidebar-body.loading::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    width: 36px; height: 36px;
    margin: -18px 0 0 -18px;
    border: 3px solid #eee;
    border-top-color: #e63946;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Animations ── */
@keyframes cartBounce {
    0%,100% { transform: scale(1); }
    30%  { transform: scale(1.2); }
    60%  { transform: scale(.9); }
}
.cart-bounce { animation: cartBounce .5s ease; }

@keyframes qtyPulse {
    0%,100% { transform: scale(1); }
    50% { transform: scale(1.25); color: #e63946; }
}
.qty-pulse { animation: qtyPulse .3s ease; }

@keyframes priceUpdate {
    0%,100% { background: transparent; }
    50% { background: #fffbcc; border-radius: 4px; }
}
.price-update { animation: priceUpdate .5s ease; }

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
    .cart-sidebar, .cart-backdrop, .cart-item,
    .qty-btn, .cart-view-btn, .recommendation-item {
        transition: none !important;
        animation: none !important;
    }
}

/* ── Print ── */
@media print {
    .cart-sidebar, .cart-backdrop { display: none; }
}
