/* ============================================================
   WinHoo cart drawer.
   Slides in from the right on every viewport; becomes a bottom
   sheet under 640px, where a right-hand panel reads as cramped.
   Brand tokens are local to the component so it does not depend
   on Tailwind classes surviving a purge.
   ============================================================ */

.wh-drawer-root {
    --wh-drawer-width: 27rem;
    --wh-brand: #ea580c;
    --wh-brand-deep: #c2410c;
    --wh-brand-ink: #7c2d12;
    --wh-surface: #ffffff;
    --wh-surface-sunk: #fff8ee;
    --wh-line: #fed7aa;
    --wh-ink: #292524;
    --wh-ink-muted: #78716c;
    --wh-radius: 16px;
    --wh-ease: cubic-bezier(0.16, 1, 0.3, 1);

    /* Exit is a touch quicker than entry: arriving should feel unhurried,
       leaving should feel prompt. The panel rules below set both. */
    --wh-drawer-in: 0.42s;
    --wh-drawer-out: 0.32s;

    position: fixed;
    inset: 0;
    z-index: 1050;                 /* above the fixed header (z-30) and its overlay (z-40) */
    visibility: hidden;
    pointer-events: none;
    /* visibility cannot tween, so it is stepped at the END of the exit. Without
       the delay it flipped to hidden the instant the drawer closed and the
       slide-out below was never seen: the panel simply vanished. */
    transition: visibility 0s linear var(--wh-drawer-out);
    font-family: 'Poppins-Regular', system-ui, sans-serif;
}

.wh-drawer-root[data-state="open"] {
    visibility: visible;
    pointer-events: auto;
    /* Visible immediately on the way in, or the entry slide is clipped too. */
    transition: visibility 0s linear 0s;
}

/* ---- scrim ---- */
.wh-drawer-scrim {
    position: absolute;
    inset: 0;
    background: rgba(41, 22, 8, 0.45);
    opacity: 0;
    transition: opacity var(--wh-drawer-out) var(--wh-ease);
}

.wh-drawer-root[data-state="open"] .wh-drawer-scrim {
    opacity: 1;
    transition: opacity var(--wh-drawer-in) var(--wh-ease);
}

/* ---- panel ---- */
.wh-drawer-panel {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    width: min(var(--wh-drawer-width), 100vw);
    height: 100%;
    /* dvh so iOS Safari's collapsing address bar cannot clip the footer */
    height: 100dvh;
    background: var(--wh-surface);
    box-shadow: -18px 0 48px rgba(124, 45, 18, 0.18);
    transform: translateX(100%);
    transition: transform var(--wh-drawer-out) var(--wh-ease);
    outline: none;
}

.wh-drawer-root[data-state="open"] .wh-drawer-panel {
    transform: translateX(0);
    transition: transform var(--wh-drawer-in) var(--wh-ease);
}

/* ---- head ---- */
.wh-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid var(--wh-line);
}

.wh-drawer-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    /* Beats the global `body h2 { font-size: 4.5rem }` in custom.css */
    font-family: 'Barlow-Bold', system-ui, sans-serif;
    font-size: 1.25rem;
    line-height: 1.2;
    color: var(--wh-brand-ink);
}

.wh-drawer-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5rem;
    height: 1.5rem;
    padding: 0 0.4rem;
    border-radius: 999px;
    background: var(--wh-brand);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
}

.wh-drawer-close,
.wh-drawer-remove,
.wh-stepper-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    color: var(--wh-ink-muted);
    cursor: pointer;
    border-radius: 999px;
    transition: background-color 0.2s var(--wh-ease), color 0.2s var(--wh-ease),
                transform 0.12s var(--wh-ease);
}

.wh-drawer-close {
    width: 2.5rem;
    height: 2.5rem;
    flex: none;
}

.wh-drawer-close:hover,
.wh-drawer-remove:hover {
    background: var(--wh-surface-sunk);
    color: var(--wh-brand-deep);
}

.wh-drawer-close svg,
.wh-drawer-remove svg,
.wh-stepper-btn svg,
.wh-drawer-empty svg {
    width: 1.25rem;
    height: 1.25rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ---- free delivery meter ---- */
.wh-drawer-ship {
    padding: 0.875rem 1.25rem;
    background: var(--wh-surface-sunk);
    border-bottom: 1px solid var(--wh-line);
}

.wh-drawer-ship-msg {
    margin: 0 0 0.5rem;
    font-size: 0.8125rem;
    line-height: 1.4;
    color: var(--wh-brand-ink);
}

.wh-drawer-ship-msg strong {
    font-weight: 700;
}

.wh-drawer-ship-track {
    height: 0.375rem;
    border-radius: 999px;
    background: #fde8d3;
    overflow: hidden;
}

.wh-drawer-ship-fill {
    display: block;
    height: 100%;
    width: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--wh-brand), #f59e0b);
    transition: width 0.5s var(--wh-ease);
}

.wh-drawer-ship[data-complete="1"] .wh-drawer-ship-fill {
    background: linear-gradient(90deg, #16a34a, #4ade80);
}

/* ---- body ---- */
.wh-drawer-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.wh-drawer-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.wh-drawer-line {
    display: grid;
    grid-template-columns: 4rem 1fr 2rem;
    gap: 0.875rem;
    align-items: start;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #fef3e7;
}

.wh-drawer-line[data-busy="1"] {
    opacity: 0.5;
    pointer-events: none;
}

.wh-drawer-thumb {
    display: block;
    width: 4rem;
    height: 4rem;
    border-radius: 12px;
    overflow: hidden;
    background: var(--wh-surface-sunk);
}

.wh-drawer-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 0.25rem;
}

.wh-drawer-thumb-blank {
    display: block;
    width: 100%;
    height: 100%;
}

.wh-drawer-line-body {
    min-width: 0;
}

.wh-drawer-line-name {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 0.875rem;
    font-weight: 700;
    line-height: 1.35;
    color: var(--wh-ink);
    text-decoration: none;
}

.wh-drawer-line-name:hover {
    color: var(--wh-brand-deep);
    text-decoration: none;
}

.wh-drawer-line-uom {
    display: block;
    margin-top: 0.125rem;
    font-size: 0.75rem;
    color: var(--wh-ink-muted);
}

.wh-drawer-line-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 0.625rem;
}

.wh-drawer-line-amount {
    font-size: 0.9375rem;
    font-weight: 800;
    color: var(--wh-brand-deep);
    white-space: nowrap;
}

/* ---- quantity stepper ---- */
.wh-stepper {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--wh-line);
    border-radius: 999px;
    overflow: hidden;
}

.wh-stepper-btn {
    width: 2rem;
    height: 2rem;
    border-radius: 0;
    color: var(--wh-brand-deep);
}

.wh-stepper-btn:hover {
    background: var(--wh-surface-sunk);
}

.wh-stepper-btn:active {
    transform: scale(0.92);
}

.wh-stepper-btn svg {
    width: 0.875rem;
    height: 0.875rem;
}

.wh-stepper-value {
    min-width: 1.75rem;
    text-align: center;
    font-size: 0.8125rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--wh-ink);
}

.wh-drawer-remove {
    width: 2rem;
    height: 2rem;
    flex: none;
}

.wh-drawer-remove svg {
    width: 1rem;
    height: 1rem;
}

/* ---- empty state ---- */
.wh-drawer-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    height: 100%;
    padding: 2rem 1.5rem;
    text-align: center;
}

.wh-drawer-empty svg {
    width: 3rem;
    height: 3rem;
    color: var(--wh-line);
    stroke-width: 1.5;
    margin-bottom: 0.5rem;
}

.wh-drawer-empty-title {
    margin: 0;
    font-family: 'Barlow-Bold', system-ui, sans-serif;
    font-size: 1.0625rem;
    color: var(--wh-brand-ink);
}

.wh-drawer-empty-sub {
    margin: 0 0 1.25rem;
    font-size: 0.8125rem;
    color: var(--wh-ink-muted);
}

/* ---- loading skeleton ---- */
.wh-drawer-loading {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.wh-drawer-loading span {
    display: block;
    height: 4rem;
    border-radius: 12px;
    background: linear-gradient(90deg, #fdf6ee 25%, #f8ece0 37%, #fdf6ee 63%);
    background-size: 400% 100%;
    animation: whDrawerShimmer 1.4s ease-in-out infinite;
}

@keyframes whDrawerShimmer {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

/* ---- foot ---- */
.wh-drawer-foot {
    flex: none;
    padding: 1rem 1.25rem calc(1rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--wh-line);
    background: var(--wh-surface);
}

.wh-drawer-subtotal {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    font-size: 0.9375rem;
    color: var(--wh-ink);
}

.wh-drawer-subtotal strong {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--wh-brand-deep);
    font-variant-numeric: tabular-nums;
}

.wh-drawer-note {
    margin: 0.25rem 0 0.875rem;
    font-size: 0.75rem;
    color: var(--wh-ink-muted);
}

.wh-drawer-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0.8125rem 1.25rem;
    border-radius: 999px;
    font-size: 0.9375rem;
    font-weight: 700;
    text-decoration: none;
    transition: background-color 0.2s var(--wh-ease), color 0.2s var(--wh-ease),
                transform 0.12s var(--wh-ease);
}

.wh-drawer-btn:active {
    transform: scale(0.985);
}

.wh-drawer-btn-primary {
    background: var(--wh-brand);
    color: #fff;
}

.wh-drawer-btn-primary:hover {
    background: var(--wh-brand-deep);
    color: #fff;
    text-decoration: none;
}

.wh-drawer-btn-ghost {
    margin-top: 0.5rem;
    background: transparent;
    color: var(--wh-brand-deep);
}

.wh-drawer-btn-ghost:hover {
    background: var(--wh-surface-sunk);
    color: var(--wh-brand-deep);
    text-decoration: none;
}

.wh-drawer-error {
    margin: 0;
    padding: 0.75rem 1.25rem;
    background: #fef2f2;
    color: #b91c1c;
    font-size: 0.8125rem;
    border-top: 1px solid #fecaca;
}

/* Keyboard focus has to stay obvious inside a modal surface. */
.wh-drawer-panel :focus-visible {
    outline: 2px solid var(--wh-brand);
    outline-offset: 2px;
}

/* ---- bottom sheet on small screens ---- */
@media (max-width: 639.98px) {
    .wh-drawer-panel {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 88dvh;
        border-radius: var(--wh-radius) var(--wh-radius) 0 0;
        box-shadow: 0 -18px 48px rgba(124, 45, 18, 0.22);
        transform: translateY(100%);
    }

    .wh-drawer-root[data-state="open"] .wh-drawer-panel {
        transform: translateY(0);
    }
}


/* The subtotal is stale from the moment a stepper is tapped until the repaint
   lands. Read it as pending rather than as fact. Matches the Order Summary
   skeleton on the cart page. */
.wh-drawer-foot.is-recalculating [data-drawer-subtotal] {
    color: transparent !important;
    background-image: linear-gradient(90deg, #f6ede1 25%, #fdf8f2 37%, #f6ede1 63%);
    background-size: 400% 100%;
    border-radius: 0.375rem;
    animation: wh-sum-shimmer 1.15s ease-in-out infinite;
    user-select: none;
}

@keyframes wh-sum-shimmer {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}
