/*
 * components/cart-mini.css
 *
 * What:  The header dropdown mini-cart — a panel anchored under the header on
 *        desktop, a bottom sheet on mobile.
 * Why:   Legacy webordering's basket dropdown (style.css .cart-sidebar) in
 *        marketplace clothing: same content, but a sheet on phones instead of
 *        a full-width slab, so it sits naturally above the bottom nav.
 * Notes: Desktop and mobile forms live together here — they are two shapes of
 *        ONE component, and splitting them across desktop.css / mobile.css
 *        would mean editing two files to change one panel. This matches how
 *        components/bottom-nav.css and components/header.css already work;
 *        desktop.css / mobile.css stay for page-level layout.
 * Used:  views/partials/cart-mini.ejs + views/partials/cart/mini.ejs.
 */

/* ── Shell ─────────────────────────────────────────────────────────────
   The shell spans the viewport so the backdrop and the outside-click area
   cover everything; the panel inside is what the customer sees. */
.cart-mini {
    position: fixed;
    inset: 0;
    /* Above the header and bottom nav, below the confirm dialog + toasts —
       both of which are fired FROM this panel and must land on top of it. */
    z-index: var(--z-cart-mini, 1100);
}

.cart-mini[hidden] { display: none; }

.cart-mini__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 17, 17, 0.45);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.cart-mini.is-open .cart-mini__backdrop { opacity: 1; }

/* ── Panel ─────────────────────────────────────────────────────────────
   Desktop default: a dropdown under the header, right-aligned with the
   header's quick-links cluster. Height is capped so a long basket scrolls
   inside the panel instead of running off the screen. */
.cart-mini__panel {
    position: absolute;
    top: calc(var(--header-height-desktop, 72px) + 8px);
    right: 24px;
    width: 420px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - var(--header-height-desktop, 72px) - 32px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.18);
    padding: 18px 18px 16px;
    /* Slides down + fades in from just under the header. */
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.cart-mini.is-open .cart-mini__panel {
    opacity: 1;
    transform: translateY(0);
}

/* Mobile drag affordance — hidden on desktop, shown on the sheet. */
.cart-mini__grab { display: none; }

.cart-mini__close {
    position: absolute;
    top: 12px;
    right: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: #f3f4f6;
    color: #111;
    cursor: pointer;
}

.cart-mini__close:hover { background: #e5e7eb; }

/* ── First-load skeleton ───────────────────────────────────────────── */
.cart-mini__loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 40px 0;
    color: #6b7280;
    font-size: 0.92rem;
}

.cart-mini__spinner {
    width: 18px;
    height: 18px;
    border: 2px solid #e5e7eb;
    border-top-color: var(--color-primary, #ff5a1f);
    border-radius: 50%;
    animation: cart-mini-spin 0.7s linear infinite;
}

@keyframes cart-mini-spin { to { transform: rotate(360deg); } }

/* ── Greeting ──────────────────────────────────────────────────────── */
.cart-mini__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding-right: 36px;        /* clears the close button */
    margin-bottom: 12px;
}

.cart-mini__welcome {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-primary, #ff5a1f);
}

.cart-mini__count {
    margin: 0;
    font-size: 0.82rem;
    color: #6b7280;
    white-space: nowrap;
}

/* ── Empty state ───────────────────────────────────────────────────── */
.cart-mini__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 26px 0 18px;
    text-align: center;
    color: #6b7280;
}

.cart-mini__empty-icon { color: #d1d5db; }

.cart-mini__empty-title {
    margin: 0;
    font-size: 0.95rem;
    color: #374151;
}

.cart-mini__empty-cta { margin-top: 4px; }

/* ── Restaurant chip ───────────────────────────────────────────────── */
.cart-mini__rest {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    margin-bottom: 10px;
    border-radius: 12px;
    background: #f9fafb;
    text-decoration: none;
    color: #111;
}

.cart-mini__rest-media {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    overflow: hidden;
    background: #f3f4f6;
    flex: 0 0 auto;
}

.cart-mini__rest-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cart-mini__rest-initial {
    font-weight: 700;
    color: #6b7280;
}

.cart-mini__rest-name {
    font-size: 0.9rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Items ─────────────────────────────────────────────────────────── */
.cart-mini__items {
    list-style: none;
    margin: 0 0 8px;
    padding: 0;
}

.cart-mini__item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid #f1f2f4;
}

.cart-mini__item-main { min-width: 0; }

.cart-mini__item-name {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: #111;
}

.cart-mini__item-mods,
.cart-mini__item-bogo {
    margin: 3px 0 0;
    font-size: 0.78rem;
    color: #6b7280;
}

.cart-mini__item-bogo {
    color: #d92d20;
    font-weight: 600;
}

.cart-mini__free-tag {
    display: inline-block;
    margin-top: 8px;
    padding: 3px 8px;
    border-radius: 999px;
    background: #ecfdf3;
    color: #067647;
    font-size: 0.74rem;
    font-weight: 600;
}

.cart-mini__item-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}

/* The stepper reuses .cart-stepper from components/cart-page.css so the
   control looks and behaves identically in both places; only the scale
   differs here. */
.cart-mini__stepper { transform-origin: left center; }

.cart-mini__bin {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid #e5e7eb;
    border-radius: 50%;
    background: #fff;
    color: #6b7280;
    cursor: pointer;
}

.cart-mini__bin:hover {
    border-color: #fda29b;
    color: #d92d20;
}

.cart-mini__item-side {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    white-space: nowrap;
}

.cart-mini__item-was {
    font-size: 0.76rem;
    color: #9ca3af;
    text-decoration: line-through;
}

.cart-mini__item-price {
    font-size: 0.95rem;
    font-weight: 700;
    color: #111;
}

/* ── Totals ────────────────────────────────────────────────────────── */
.cart-mini__totals {
    margin: 4px 0 14px;
    padding-top: 10px;
}

.cart-mini__row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 7px 0;
    font-size: 0.9rem;
    color: #374151;
    border-bottom: 1px solid #f1f2f4;
}

.cart-mini__row dt,
.cart-mini__row dd { margin: 0; }

.cart-mini__row dd { font-weight: 600; color: #111; }

.cart-mini__row--minus dd { color: #067647; }

.cart-mini__free { color: #067647; font-weight: 700; }

.cart-mini__row--total {
    border-bottom: 0;
    padding-top: 10px;
    font-size: 1.02rem;
    font-weight: 700;
    color: #111;
}

.cart-mini__row--total dd { font-size: 1.08rem; }

/* ── Actions ───────────────────────────────────────────────────────── */
.cart-mini__actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cart-mini__checkout,
.cart-mini__clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 46px;
    border-radius: 10px;
    font-size: 0.98rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
}

.cart-mini__checkout {
    border: 0;
    background: var(--color-primary, #ff5a1f);
    color: #fff;
}

.cart-mini__checkout:hover { filter: brightness(0.95); }

.cart-mini__clear {
    border: 0;
    background: #111;
    color: #fff;
}

.cart-mini__clear:hover { background: #2b2b2b; }

/* ── Mobile: bottom sheet ──────────────────────────────────────────────
   Slides up from the bottom, full width, rounded top. Capped at 85vh so the
   page behind stays visible, and padded past the always-visible bottom nav
   plus the iOS home indicator. */
@media (max-width: 767px) {
    .cart-mini__panel {
        top: auto;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        max-height: 85vh;
        border-radius: 20px 20px 0 0;
        /* 52px = the bottom nav's height (components/bottom-nav.css), so the
           Checkout / Clear buttons never sit under it. */
        padding: 10px 16px calc(16px + 52px + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.22);
        transform: translateY(100%);
        transition: opacity 0.22s ease, transform 0.22s ease;
    }

    .cart-mini.is-open .cart-mini__panel { transform: translateY(0); }

    .cart-mini__grab {
        display: block;
        width: 42px;
        height: 4px;
        margin: 2px auto 10px;
        border-radius: 999px;
        background: #e5e7eb;
    }

    .cart-mini__close {
        top: 14px;
        right: 14px;
    }

    /* Page behind the sheet must not scroll — the sheet owns the gesture. */
    body.has-cart-mini-open { overflow: hidden; }
}
