/* ==========================================================================
   Shopping Cart Sidebar (Slide-out Drawer)
   Faithful recreation of approved reference design.
   Supports English (LTR) and Arabic (RTL), Desktop and Mobile.
   ========================================================================== */

:root {
    --cart-brand: #3e386b;
    --cart-brand-hover: #322d56;
    --cart-accent-purple: #4338ca;
    --cart-accent-light: #f5f3ff;
    --cart-accent-border: #c7d2fe;
    --cart-text-dark: #0f172a;
    --cart-text-muted: #64748b;
    --cart-text-subtle: #94a3b8;
    --cart-card-border: #eef0f4;
    --cart-divider: #f1f5f9;
    --cart-bg: #ffffff;
    --cart-stepper-bg: #f8fafc;
    --cart-stepper-border: #e2e8f0;
    --cart-green-bg: #f0faf5;
    --cart-green-border: #d1fae5;
    --cart-green-accent: #10b981;
    --cart-green-text: #065f46;
    --cart-danger: #ef4444;
    --cart-danger-bg: #fee2e2;
    --cart-drawer-width: 430px;
    --cart-shadow: 0 20px 45px -10px rgba(15, 23, 42, 0.22);
    --cart-ease: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── Overlay / Backdrop ─────────────────────────────────────────────────── */
.cart-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.52);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 999990;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.cart-drawer-overlay.is-active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* ── Main Drawer Sidebar ────────────────────────────────────────────────── */
.cart-drawer {
    position: fixed;
    top: 0;
    bottom: 0;
    width: var(--cart-drawer-width);
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: var(--cart-bg);
    z-index: 999995;
    display: flex;
    flex-direction: column;
    box-shadow: var(--cart-shadow);
    visibility: hidden;
    transition: transform 0.35s var(--cart-ease), visibility 0.35s var(--cart-ease);
    will-change: transform;
    font-family: inherit;
    color: var(--cart-text-dark);
    box-sizing: border-box;
    overflow: hidden;
}

.cart-drawer *,
.cart-drawer *::before,
.cart-drawer *::after {
    box-sizing: border-box;
}

/* LTR Placement (Slide in from Right) */
html[dir="ltr"] .cart-drawer,
html:not([dir="rtl"]) .cart-drawer {
    right: 0;
    left: auto;
    transform: translateX(105%);
}

/* RTL Placement (Slide in from Left) */
html[dir="rtl"] .cart-drawer {
    left: 0;
    right: auto;
    transform: translateX(-105%);
}

/* Open State */
.cart-drawer.is-active {
    transform: translateX(0) !important;
    visibility: visible;
}

/* Body Scroll Lock */
body.cart-drawer-open {
    overflow: hidden !important;
    touch-action: none;
}

/* ── Drawer Header ──────────────────────────────────────────────────────── */
.cart-drawer__header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    background: #ffffff;
    border-bottom: 1px solid var(--cart-divider);
    position: relative;
    z-index: 2;
}

.cart-drawer__title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.cart-drawer__header-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--cart-accent-light);
    color: var(--cart-accent-purple);
    flex-shrink: 0;
}

.cart-drawer__title {
    margin: 0;
    font-size: 1.18rem;
    font-weight: 700;
    color: var(--cart-text-dark);
    line-height: 1.25;
    letter-spacing: -0.01em;
}

.cart-drawer__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--cart-brand);
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1;
}

.cart-drawer__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: #f3f4f6;
    color: var(--cart-text-muted);
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
    padding: 0;
}

.cart-drawer__close:hover,
.cart-drawer__close:focus-visible {
    background: #e5e7eb;
    color: var(--cart-text-dark);
    outline: none;
}

/* ── Free Shipping Progress Bar (Drawer Variant) ────────────────────────── */
.free-shipping-progress {
    --free-shipping-progress: 0%;
    color: var(--cart-text-dark);
    direction: inherit;
}

.free-shipping-progress--drawer {
    flex-shrink: 0;
    margin: 16px 20px 6px;
    padding: 13px 16px 14px;
    background: var(--cart-green-bg);
    border: 1px solid var(--cart-green-border);
    border-radius: 12px;
}

.free-shipping-progress__header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.free-shipping-progress__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--cart-green-accent);
    flex-shrink: 0;
}

.free-shipping-progress__message {
    margin: 0;
    color: var(--cart-green-text);
    font-size: 0.86rem;
    font-weight: 600;
    line-height: 1.35;
}

.free-shipping-progress__track {
    position: relative;
    width: 100%;
    height: 6px;
    background: var(--cart-green-border);
    border-radius: 999px;
    margin-top: 14px;
    margin-bottom: 4px;
}

.free-shipping-progress__fill {
    position: absolute;
    inset-block: 0;
    inset-inline-start: 0;
    width: var(--free-shipping-progress);
    border-radius: inherit;
    background: var(--cart-green-accent);
    transition: width 0.45s var(--cart-ease);
}

.free-shipping-progress__truck {
    position: absolute;
    inset-block-start: 50%;
    inset-inline-start: 0;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: inset-inline-start 0.45s var(--cart-ease);
    pointer-events: none;
    z-index: 2;
}

.free-shipping-progress__sparkles {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--cart-green-accent);
    margin-bottom: 2px;
    line-height: 1;
}

.free-shipping-progress__truck-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #ffffff;
    border: 2px solid var(--cart-green-accent);
    color: var(--cart-green-accent);
    box-shadow: 0 2px 7px rgba(16, 185, 129, 0.28);
}

/* Home variant compatibility */
.free-shipping-progress--home {
    width: min(1170px, calc(100% - 40px));
    margin: 18px auto 4px;
    padding: 16px 22px 18px;
    background: #ffffff;
    border: 1px solid var(--cart-card-border);
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

.free-shipping-progress--home .free-shipping-progress__message {
    text-align: center;
    color: var(--cart-text-dark);
}

/* ── Drawer Body ────────────────────────────────────────────────────────── */
.cart-drawer__body {
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px 20px 20px;
    background: #ffffff;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

.cart-drawer__body::-webkit-scrollbar {
    width: 5px;
}

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

.cart-drawer__body::-webkit-scrollbar-thumb {
    background: #e2e8f0;
    border-radius: 999px;
}

.cart-drawer__body::-webkit-scrollbar-thumb:hover {
    background: #cbd5e1;
}

/* ── Empty State ────────────────────────────────────────────────────────── */
.cart-drawer__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 48px 16px;
    min-height: 280px;
    margin: auto 0;
}

.cart-drawer__empty-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 88px;
    height: 88px;
    border-radius: 50%;
    background: var(--cart-accent-light);
    color: var(--cart-brand);
    margin-bottom: 20px;
}

.cart-drawer__empty-title {
    margin: 0 0 8px;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--cart-text-dark);
}

.cart-drawer__empty-desc {
    margin: 0 0 24px;
    font-size: 0.92rem;
    color: var(--cart-text-muted);
    max-width: 270px;
    line-height: 1.5;
}

.cart-drawer__btn--start {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: 10px;
    background: var(--cart-brand);
    color: #ffffff !important;
    font-size: 0.92rem;
    font-weight: 700;
    text-decoration: none;
    transition: background-color 0.2s ease, transform 0.15s ease;
}

.cart-drawer__btn--start:hover {
    background: var(--cart-brand-hover);
    transform: translateY(-1px);
    color: #ffffff !important;
}

html[dir="rtl"] .cart-drawer__btn--start svg {
    transform: scaleX(-1);
}

/* ── Items List ─────────────────────────────────────────────────────────── */
.cart-drawer__items-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ── Product Card ───────────────────────────────────────────────────────── */
.cart-drawer-item {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px;
    background: #ffffff;
    border: 1px solid var(--cart-card-border);
    border-radius: 14px;
    position: relative;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.25s ease;
}

.cart-drawer-item:hover {
    border-color: #dbe0ea;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}

.cart-drawer-item.is-updating {
    opacity: 0.55;
    pointer-events: none;
}

.cart-drawer-item.is-removing {
    opacity: 0;
    transform: scale(0.95);
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-bottom: 0;
    border-width: 0;
    overflow: hidden;
    transition: all 0.28s var(--cart-ease);
}

/* Product Thumbnail */
.cart-drawer-item__image {
    flex-shrink: 0;
    width: 76px;
    height: 76px;
    border-radius: 10px;
    background: var(--cart-stepper-bg);
    border: 1px solid var(--cart-divider);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    text-decoration: none;
}

.cart-drawer-item__image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 4px;
    display: block;
}

/* Item Content */
.cart-drawer-item__content {
    flex-grow: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.cart-drawer-item__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.cart-drawer-item__title {
    margin: 0;
    font-size: 0.92rem;
    font-weight: 700;
    line-height: 1.35;
    color: var(--cart-text-dark);
}

.cart-drawer-item__title a {
    color: inherit;
    text-decoration: none;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    transition: color 0.15s ease;
}

.cart-drawer-item__title a:hover {
    color: var(--cart-accent-purple);
}

/* Minimal Outline Trash Delete Button */
.cart-drawer-item__delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--cart-text-subtle);
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    transition: background-color 0.18s ease, color 0.18s ease;
}

.cart-drawer-item__delete:hover,
.cart-drawer-item__delete:focus-visible {
    background: var(--cart-danger-bg);
    color: var(--cart-danger);
    outline: none;
}

/* Variant Tags (Color, Size) */
.cart-drawer-item__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.cart-drawer-item__tag {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 5px;
    background: #f1f5f9;
    color: var(--cart-text-muted);
    font-size: 0.72rem;
    font-weight: 600;
}

/* Secondary Unit Price */
.cart-drawer-item__unit-price {
    font-size: 0.8rem;
    color: var(--cart-text-muted);
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.cart-drawer-item__unit-price strong {
    color: var(--cart-text-dark);
    font-weight: 600;
}

.cart-drawer-item__warning {
    font-size: 0.74rem;
    color: var(--cart-danger);
    font-weight: 600;
}

/* Footer Row: Stepper + Line Total */
.cart-drawer-item__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
    padding-top: 2px;
}

/* Segmented Stepper Pill [ - ] [ 2 ] [ + ] */
.cart-drawer-qty {
    display: inline-flex;
    align-items: center;
    background: var(--cart-stepper-bg);
    border: 1px solid var(--cart-stepper-border);
    border-radius: 8px;
    overflow: hidden;
    height: 32px;
}

.cart-drawer-qty__btn {
    width: 28px;
    height: 100%;
    border: none;
    background: transparent;
    color: #475569;
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: background-color 0.15s ease, color 0.15s ease;
    user-select: none;
}

.cart-drawer-qty__btn:hover:not(:disabled) {
    background: #e2e8f0;
    color: var(--cart-text-dark);
}

.cart-drawer-qty__btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.cart-drawer-qty__input {
    width: 32px;
    height: 100%;
    border: none;
    border-inline: 1px solid var(--cart-stepper-border);
    background: transparent;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--cart-text-dark);
    padding: 0;
    -moz-appearance: textfield;
}

.cart-drawer-qty__input::-webkit-outer-spin-button,
.cart-drawer-qty__input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.cart-drawer-qty__input:focus {
    outline: none;
    background: #ffffff;
}

/* Bold Brand Purple Line Total */
.cart-drawer-item__line-total {
    font-size: 0.96rem;
    font-weight: 700;
    color: var(--cart-accent-purple);
    white-space: nowrap;
}

/* ── Sticky Drawer Footer ───────────────────────────────────────────────── */
.cart-drawer__footer {
    flex-shrink: 0;
    padding: 18px 24px 22px;
    background: #ffffff;
    border-top: 1px solid var(--cart-divider);
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 2;
}

.cart-drawer__footer[hidden] {
    display: none !important;
}

.cart-drawer__subtotal {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2px;
}

.cart-drawer__subtotal-label {
    font-size: 0.94rem;
    font-weight: 600;
    color: #475569;
}

.cart-drawer__subtotal-value {
    font-size: 1.16rem;
    font-weight: 800;
    color: var(--cart-text-dark);
    letter-spacing: -0.01em;
}

.cart-drawer__notice {
    margin: 0 0 16px;
    font-size: 0.78rem;
    color: var(--cart-text-subtle);
    line-height: 1.35;
}

.cart-drawer__actions {
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.cart-drawer__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    border-radius: 10px;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    font-family: inherit;
}

/* Primary Button: Solid Brand Purple */
.cart-drawer__btn--checkout {
    height: 48px;
    background: var(--cart-brand);
    color: #ffffff !important;
    font-size: 0.96rem;
    font-weight: 700;
    border: 1px solid transparent;
}

.cart-drawer__btn--checkout:hover {
    background: var(--cart-brand-hover);
    color: #ffffff !important;
}

.cart-drawer__btn-arrow {
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

/* RTL Arrow Flipping */
html[dir="rtl"] .cart-drawer__btn-arrow {
    transform: scaleX(-1);
}

.cart-drawer__btn--checkout:hover .cart-drawer__btn-arrow {
    transform: translateX(3px);
}

html[dir="rtl"] .cart-drawer__btn--checkout:hover .cart-drawer__btn-arrow {
    transform: scaleX(-1) translateX(3px);
}

/* Secondary Button: Lavender Outlined */
.cart-drawer__btn--view {
    height: 44px;
    background: #ffffff;
    color: var(--cart-accent-purple) !important;
    border: 1px solid var(--cart-accent-border);
    font-size: 0.92rem;
    font-weight: 600;
}

.cart-drawer__btn--view:hover {
    background: var(--cart-accent-light);
    color: var(--cart-brand-hover) !important;
    border-color: #a5b4fc;
}

/* ── Spinner Loader ─────────────────────────────────────────────────────── */
.cart-drawer__loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 220px;
    width: 100%;
}

.cart-drawer__spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #edf0f7;
    border-top-color: var(--cart-brand);
    border-radius: 50%;
    animation: cartDrawerSpin 0.75s linear infinite;
}

@keyframes cartDrawerSpin {
    to { transform: rotate(360deg); }
}

/* ── Toast Notifications ────────────────────────────────────────────────── */
.cart-drawer-toast {
    position: fixed;
    top: 24px;
    right: 24px;
    left: auto;
    bottom: auto;
    transform: translateY(-16px);
    background: #1e2029;
    color: #ffffff;
    padding: 11px 20px;
    border-radius: 10px;
    font-size: 0.88rem;
    font-weight: 600;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
    z-index: 9999999;
    opacity: 0;
    pointer-events: none;
    transition: transform 0.25s ease, opacity 0.25s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.cart-drawer-toast.is-visible {
    transform: translateY(0);
    opacity: 1;
}

[dir="rtl"] .cart-drawer-toast {
    right: auto;
    left: 24px;
}

.cart-drawer-toast.is-error {
    background: #dc2626;
}

/* ── Responsive Mobile ──────────────────────────────────────────────────── */
@media (max-width: 640px) {
    :root {
        --cart-drawer-width: 100vw;
    }

    .cart-drawer {
        width: 100vw;
    }

    .cart-drawer-toast,
    [dir="rtl"] .cart-drawer-toast {
        top: 14px;
        right: 14px;
        left: 14px;
        justify-content: center;
    }

    .cart-drawer__header {
        padding: 16px 18px;
    }

    .free-shipping-progress--drawer {
        margin: 12px 16px 4px;
        padding: 11px 14px 12px;
    }

    .cart-drawer__body {
        padding: 12px 16px 18px;
    }

    .cart-drawer__footer {
        padding: 16px 18px;
        padding-bottom: max(18px, env(safe-area-inset-bottom));
    }

    .cart-drawer-item {
        padding: 12px;
        gap: 12px;
    }

    .cart-drawer-item__image {
        width: 68px;
        height: 68px;
    }

    .cart-drawer-item__title {
        font-size: 0.88rem;
    }

    .cart-drawer-item__line-total {
        font-size: 0.92rem;
    }

    .cart-drawer-qty {
        height: 30px;
    }

    .cart-drawer-qty__btn {
        width: 26px;
    }

    .cart-drawer-qty__input {
        width: 30px;
        font-size: 0.82rem;
    }
}

/* Neutralize legacy dropdown */
.wpda-builder-cart .wpda-cart-inner {
    display: none !important;
}

@media (prefers-reduced-motion: reduce) {
    .cart-drawer,
    .cart-drawer-overlay,
    .free-shipping-progress__fill,
    .free-shipping-progress__truck {
        transition: none !important;
    }
}
