/*
 * Cart — header badge, slide-in mini-cart, cart page.
 * Ported from the Figma Make prototype's CartDrawer/CartPage. Reuses the
 * site-wide tokens from dehai-common's main.css rather than a second palette.
 */

/* ── Shared buttons ─────────────────────────────────────────── */

.cart-button--primary,
.cart-button--ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-xl);
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.cart-button--primary {
    border: none;
    background: var(--accent);
    color: #fff;
}

.cart-button--primary:hover:not(:disabled) {
    background: var(--accent-dark);
}

.cart-button--primary:disabled {
    background: var(--line);
    color: var(--muted);
    cursor: not-allowed;
}

.cart-button--ghost {
    border: 1px solid var(--line);
    background: transparent;
    color: var(--ink);
}

.cart-button--ghost:hover {
    border-color: var(--ink);
}

.cart-button--block {
    width: 100%;
}

/* ── Header button + badge ──────────────────────────────────── */

.cart-button {
    position: relative;
}

.cart-button__badge {
    position: absolute;
    top: -0.125rem;
    right: -0.125rem;
    min-width: 1rem;
    height: 1rem;
    padding: 0 0.125rem;
    border-radius: var(--radius-full);
    background: var(--accent);
    color: #fff;
    font-size: 0.5625rem;
    font-weight: 700;
    line-height: 1rem;
    text-align: center;
}

.cart-button__badge.is-empty {
    display: none;
}

/* ── Toast ──────────────────────────────────────────────────── */

/* Centred on the viewport, not tucked at an edge: this only ever appears to
   say a click could not be honoured, and at the bottom it went unnoticed. */
.cart-toast {
    position: fixed;
    left: 50%;
    top: 50%;
    z-index: 70;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    max-width: min(28rem, calc(100vw - 2rem));
    padding: 1rem 1.35rem;
    border-radius: var(--radius-lg);
    background: var(--ink);
    color: var(--paper);
    font-size: 1rem;
    font-weight: 500;
    text-align: left;
    box-shadow: var(--shadow-card);
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.94);
    transition: opacity 0.18s ease, transform 0.18s ease;
}

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

.cart-toast.is-visible {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.cart-toast__icon {
    flex-shrink: 0;
    width: 1.35rem;
    height: 1.35rem;
    color: var(--accent);
}

/* Kept clickable on purpose — see syncStepper() in cart.js. */
.cart-qty__btn.is-maxed {
    opacity: 0.35;
    cursor: not-allowed;
}

/* ── Slide-in mini-cart ─────────────────────────────────────── */

.cart-drawer {
    position: fixed;
    inset: 0;
    z-index: 60;
}

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

.cart-drawer__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(13, 12, 10, 0.4);
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.cart-drawer__panel {
    position: absolute;
    inset-block: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    width: 380px;
    max-width: 95vw;
    background: var(--surface);
    box-shadow: var(--shadow-card);
    transform: translateX(100%);
    transition: transform 0.3s ease-out;
}

.cart-drawer.is-open .cart-drawer__backdrop {
    opacity: 1;
}

.cart-drawer.is-open .cart-drawer__panel {
    transform: translateX(0);
}

.cart-drawer__body {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-height: 0;
}

.cart-drawer__head {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--line);
}

.cart-drawer__title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.cart-drawer__title h2 {
    margin: 0;
    font-family: var(--font-display, inherit);
    font-weight: 400;
    font-size: 1.125rem;
    color: var(--ink);
}

.cart-drawer__count {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: var(--radius-full);
    background: var(--accent);
    color: #fff;
    font-size: 0.625rem;
    font-weight: 700;
}

.cart-drawer__close {
    display: flex;
    padding: 0.5rem;
    border: none;
    border-radius: var(--radius-xl);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.cart-drawer__close:hover {
    background: var(--paper);
    color: var(--ink);
}

.cart-drawer__close svg {
    width: 1.25rem;
    height: 1.25rem;
}

.cart-drawer__empty {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1.5rem;
    text-align: center;
}

.cart-drawer__empty svg {
    width: 3rem;
    height: 3rem;
    color: var(--line);
}

.cart-drawer__empty-title {
    margin: 0;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ink);
}

.cart-drawer__empty-text {
    margin: 0;
    font-size: 0.75rem;
    color: var(--muted);
}

.cart-drawer__items {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    overflow-y: auto;
}

.cart-drawer__foot {
    display: flex;
    flex-shrink: 0;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--line);
}

.cart-drawer__rows {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.cart-drawer__row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8125rem;
    color: var(--muted);
}

.cart-drawer__row span:last-child {
    color: var(--ink);
}

/* "calculated at checkout" — the cart cannot know which carrier is coming. */
.cart-drawer__pending,
.cart-summary__pending {
    font-size: 0.75rem;
    color: var(--muted);
    text-align: right;
}

.cart-drawer__total {
    padding-top: 0.75rem;
    border-top: 1px solid var(--line);
    display: flex;
    align-items: baseline;
    justify-content: space-between;
}

.cart-drawer__total span {
    font-size: 0.875rem;
    color: var(--muted);
}

.cart-drawer__total strong {
    font-family: var(--font-display, inherit);
    font-size: 1.25rem;
    font-weight: 400;
    color: var(--ink);
}

/* ── One cart line, shared by the drawer and the page ───────── */

.cart-line {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    background: var(--surface);
}

.cart-line--compact {
    gap: 0.75rem;
    padding: 0.75rem;
    border: none;
    border-radius: var(--radius-lg);
    background: var(--paper);
}

.cart-line.is-busy {
    opacity: 0.5;
    pointer-events: none;
}

/* A quantity changes instantly, its price a moment later — the amounts fade
   for that moment instead of standing as a figure that no longer matches. */
.is-stale {
    opacity: 0.4;
}

[data-cart-line-total],
[data-cart-subtotal],
[data-cart-total],
[data-cart-items-label],
[data-cart-page-count],
[data-cart-drawer-count] {
    transition: opacity 0.15s ease;
}

.cart-line__media {
    display: block;
    flex-shrink: 0;
    width: 6rem;
    height: 6rem;
    overflow: hidden;
    border-radius: var(--radius-lg);
    background: var(--paper);
    font-size: 2rem;
    color: var(--muted);
}

.cart-line--compact .cart-line__media {
    width: 4rem;
    height: 4rem;
    font-size: 1.5rem;
    background: var(--surface-2);
}

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

.cart-line__body {
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: space-between;
    gap: 0.5rem;
    min-width: 0;
}

.cart-line__title {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.35;
    color: var(--ink);
    text-decoration: none;
}

.cart-line--compact .cart-line__title {
    font-size: 0.75rem;
}

.cart-line__title:hover {
    color: var(--accent);
}

.cart-line__brand {
    margin: 0.125rem 0 0;
    font-size: 0.75rem;
    color: var(--muted);
}

.cart-line__variant {
    font-size: 0.625rem;
    color: var(--muted);
}

.cart-line__variant-chip {
    display: inline-block;
    margin-top: 0.25rem;
    padding: 0.125rem 0.5rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-full);
    background: var(--paper);
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--muted);
}

.cart-line__controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.cart-line__price {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-family: var(--font-display, inherit);
    font-size: 1rem;
    color: var(--ink);
}

.cart-line--compact .cart-line__price {
    gap: 0.5rem;
    font-size: 0.875rem;
}

.cart-line__remove {
    display: flex;
    padding: 0.375rem;
    border: none;
    border-radius: var(--radius-lg);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.cart-line__remove:hover {
    background: var(--paper);
    color: var(--accent);
}

.cart-line__remove svg {
    width: 1rem;
    height: 1rem;
}

.cart-qty {
    display: flex;
    align-items: center;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
}

.cart-qty__btn {
    display: flex;
    padding: 0.5rem 0.625rem;
    border: none;
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.cart-qty__btn:hover {
    background: var(--paper);
}

.cart-qty__btn svg {
    width: 0.875rem;
    height: 0.875rem;
}

.cart-qty__value {
    min-width: 2rem;
    font-size: 0.875rem;
    font-weight: 600;
    text-align: center;
}

/* ── Cart page ──────────────────────────────────────────────── */

/* No container of its own: a plugin renders inside .site-content, which already
   centres at 1280px and holds the page gutter. A second box here made the cart
   2rem narrower than every other page, which shows most on a phone. */

.cart-page__breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin-bottom: 1.5rem;
    font-size: 0.75rem;
    color: var(--muted);
}

.cart-page__breadcrumb a {
    color: inherit;
    text-decoration: none;
}

.cart-page__breadcrumb a:hover {
    color: var(--ink);
}

.cart-page__breadcrumb svg {
    width: 0.75rem;
    height: 0.75rem;
}

.cart-page__breadcrumb span {
    font-weight: 500;
    color: var(--ink);
}

.cart-page__title {
    margin: 0 0 2rem;
    font-family: var(--font-display, inherit);
    font-size: 1.75rem;
    font-weight: 400;
    color: var(--ink);
}

.cart-page__count {
    margin-left: 0.75rem;
    font-family: inherit;
    font-size: 1rem;
    color: var(--muted);
}

.cart-page__grid {
    display: grid;
    gap: 2rem;
    align-items: start;
}

/* A grid item's automatic minimum is its content, so a track can never come out
   narrower than the longest thing inside it — a product name that does not wrap
   would push the whole page past the screen. See .checkout__grid, where it did. */
.cart-page__grid > * {
    min-width: 0;
}

@media (min-width: 1024px) {
    .cart-page__grid {
        grid-template-columns: 1fr 360px;
    }
}

.cart-page__lines {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.cart-page__continue {
    display: inline-flex;
    align-self: flex-start;
    align-items: center;
    gap: 0.375rem;
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: var(--muted);
    text-decoration: none;
}

.cart-page__continue:hover {
    color: var(--ink);
}

.cart-page__continue svg {
    width: 1rem;
    height: 1rem;
}

.cart-page__empty {
    max-width: 32rem;
    margin: 0 auto;
    padding: 5rem 1rem;
    text-align: center;
}

.cart-page__empty-icon {
    margin-bottom: 1.5rem;
    font-size: 3.75rem;
}

.cart-page__empty-title {
    margin: 0 0 0.75rem;
    font-family: var(--font-display, inherit);
    font-size: 1.5rem;
    font-weight: 400;
    color: var(--ink);
}

.cart-page__empty-text {
    margin: 0 0 2rem;
    font-size: 0.875rem;
    color: var(--muted);
}

.cart-summary {
    position: sticky;
    top: 5rem;
    padding: 1.5rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    background: var(--surface);
}

.cart-summary__heading {
    margin: 0 0 1.25rem;
    font-family: var(--font-display, inherit);
    font-size: 1.125rem;
    font-weight: 400;
    color: var(--ink);
}

.cart-summary__rows {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.cart-summary__row {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
    color: var(--muted);
}

.cart-summary__row span:last-child {
    color: var(--ink);
}

.cart-summary__total {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding-top: 1rem;
    margin-bottom: 1.5rem;
    border-top: 1px solid var(--line);
}

.cart-summary__total span {
    font-weight: 600;
    color: var(--ink);
}

.cart-summary__total strong {
    font-family: var(--font-display, inherit);
    font-size: 1.5rem;
    font-weight: 400;
    color: var(--ink);
}

.cart-summary__trust {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
    font-size: 0.75rem;
    color: var(--muted);
}
