.cart-drawer {
    position: fixed;
    z-index: 1000;
    inset-inline-start: 0;
    inset-block-start: 0;
    width: 100vw;
    height: 100%;
    display: flex;
    justify-content: flex-end;
    background-color: rgba(var(--color-mask), 0.5);
    transition: visibility 200ms ease;
}

.cart-drawer {
    visibility: hidden;
}

.cart-drawer.active {
    visibility: visible;
}

.cart-drawer__inner {
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 20px;
    background-color: rgb(var(--color-page-background));
}

.cart-drawer__fixed-checkout {}

.cart-drawer__content-wrapper {
    display: flex;
    height: 100%;
    transform: translateX(100%);
    transition: transform 200ms ease;
}

.cart-drawer.active .cart-drawer__content-wrapper {
    transform: translateX(0);
}

.cart-drawer__inner .cart-drawer__inner-wrapper {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.cart-drawer__warnings {
    display: flex;
    flex-direction: column;
    flex: 1;
    justify-content: center;
}

.cart-drawer.active .cart-drawer__inner,
.cart-drawer.active .cart-drawer__fixed-checkout {
    /* transform: translateX(0); */
}

.cart-drawer__header {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-block-end: 20px;
}

.cart-drawer__header::after {
    content: "";
    position: absolute;
    inset-block-end: 0;
    inset-inline-start: -20px;
    width: calc(100% + 40px);
    height: 1px;
    background-color: rgb(var(--color-entry-line));
}

.cart-drawer__close {
    color: rgb(var(--color-text));
    cursor: pointer;
    width: 24px;
    height: 24px;
    line-height: 0;
    inset-block-start: 2px;
    inset-inline-end: -4px;
    padding: 6px;
    position: absolute;
}

cart-drawer {
    display: block;
    position: fixed;
    inset-block-start: 0;
    inset-inline-start: 0;
    width: 100vw;
    height: 100%;
}

.cart-drawer-container {
    display: flex;
    flex-direction: row;
}

.cart-drawer__overlay {
    position: fixed;
    inset: 0;
}

.cart-drawer__overlay:empty {
    display: block;
}

/* cart-drawer-items {
  overflow: auto;
  flex: 1;
} */

.cart-drawer__inner {
    overflow-y: scroll;
}

@media screen and (max-height: 650px) {
    cart-drawer-items {
        overflow: visible;
    }

    .cart-drawer__inner {
        overflow-y: scroll;
    }
}

@media (max-width: 959px) {
    .cart-drawer__body {
        width: 90%;
    }
}

cart-drawer-items::-webkit-scrollbar {
    width: 3px;
}

cart-drawer-items::-webkit-scrollbar-thumb {
    background-color: rgba(18, 18, 18, 0.7);
    border-radius: 100px;
}

cart-drawer-items::-webkit-scrollbar-track-piece {
    margin-block-start: 20px;
}

/* cart-drawer-footer */

.cart-drawer__footer__container {
    display: flex;
    justify-content: flex-end;
    padding-block: 40px;
}

.cart-drawer__checkout-container {
    width: 100%;
    position: relative;
    padding: 40px 0;
}

.cart-drawer__checkout-container::after {
    content: "";
    position: absolute;
    inset-block-start: 0;
    inset-inline-start: -20px;
    width: calc(100% + 40px);
    height: 1px;
    background-color: rgb(var(--color-entry-line));
}

.cart-drawer__amount-wrapper {
    margin: 0;
    padding: 0;
}

.cart-drawer__amount-wrapper li {
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: rgb(var(--color-text));
    margin-block-end: 8px;
}

.cart-drawer__amount-wrapper li em {
    font-style: normal;
    margin-inline-end: 12px;
}

.cart-drawer__amount-wrapper .cart__discount span {
    color: rgb(var(--color-discount));
}

.cart-drawer__discount span {
    color: rgb(var(--color-discount));
}

#checkout {
    width: 100%;
}

.cart-drawer__checkout {
    margin-block-start: 15px;
}

.cart-drawer__taxes__desc {
    text-align: center;
}

.cart-drawer__body {
    position: relative;
    display: flex;
    height: 100%;
    flex-direction: column;
    width: 440px;
}

/* body 内：inner 占据剩余高度并滚动，fixed-checkout 在底部不遮挡 */
.cart-drawer__body .cart-drawer__inner {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

/* inner-wrapper 按内容高度，和 --below 一起在 inner 里纵向排列、整体滚动 */
.cart-drawer__body .cart-drawer__inner .cart-drawer__inner-wrapper {
    flex: 0 0 auto;
    min-height: 0;
}

.cart-drawer__body .cart-drawer__fixed-checkout,
.cart-drawer__body .cart-fixed-checkout {
    position: static;
    flex-shrink: 0;
}

/* Empty Cart Styles */
.cart-empty div {
    margin-top: 0 !important;
}

.cart__empty-text-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
}

.cart__empty-text {
    margin-bottom: 30px;
    font-size: 24px;
    font-weight: 400;
    color: rgb(var(--color-text));
}

.cart__empty-categories {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    max-width: 300px;
    margin-bottom: 40px;
}

.cart__empty-category-item {
    display: block;
    padding: 16px 24px;
    border: 1px solid rgb(var(--color-entry-line));
    border-radius: 4px;
    text-decoration: none;
    color: rgb(var(--color-text));
    background-color: transparent;
    transition: all 0.2s ease;
    text-align: center;
}

.cart__empty-category-item:hover {
    background-color: rgba(var(--color-text), 0.05);
    border-color: rgb(var(--color-text));
}

.cart__empty-category-item.sale-item {
    color: #e74c3c;
    border-color: #e74c3c;
}

.cart__empty-category-item.sale-item:hover {
    background-color: rgba(231, 76, 60, 0.1);
}

.cart__empty-discounts {
    width: 100%;
    background-color: #8B4513;
    color: white;
    padding: 24px;
    border-radius: 8px;
    margin-top: 20px;
}

.discount-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.discount-item {
    flex: 1;
    text-align: center;
}

.discount-text {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}

.discount-percentage {
    font-size: 18px;
    font-weight: bold;
    color: white;
}

.discount-condition {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.9);
}

.discount-code-label {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.9);
    margin-top: 4px;
}

.discount-code {
    background-color: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 8px 16px;
    border-radius: 4px;
    font-weight: bold;
    color: white;
    font-size: 14px;
}

.discount-divider {
    color: rgba(255, 255, 255, 0.5);
    font-size: 20px;
    font-weight: 300;
}

@media (max-width: 480px) {
    .cart__empty-discounts {
        padding: 16px;
    }

    .discount-row {
        flex-direction: column;
        gap: 16px;
    }

    .discount-divider {
        display: none;
    }

    .cart__empty-categories {
        max-width: 100%;
    }

    .cart__empty-text {
        font-size: 20px;
    }
}

/* The ipad end responds to the mobile end in vertical screen */

/* @custom-media --tablet (max-width: 959px); */

/* @custom-media --gt-mobile (min-width: 751px); */

/* detectingScreen need to consider the configuration of the tablet */

/* Recommend Products Styles */
/* 960px 以下：推荐商品在购物车下方；960px 以上：在右侧 */
.cart-drawer__recommend-products--below {
    display: none;
    flex-shrink: 0;
    width: 100%;
    padding: 12px 15px;
    flex-direction: column;
    overflow: visible;
    background: #f0f0f0;
}

/* 960px 以下：列表随购物车整体滚动，不做内部滚动 */
.cart-drawer__recommend-products--below .cart-drawer__recommend-products-inner {
    display: flex;
    flex-direction: column;
    flex: none;
    overflow: visible;
}

.cart-drawer__recommend-products--below .cart-recommend-list {
    flex: none;
    overflow: visible;
    min-height: 0;
}

.cart-drawer__recommend-products--side {
    display: flex;
    padding: 16px 20px;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    width: 440px;
    background: #f0f0f0;
}

/* 960px 以上：右侧推荐列表内部可滚动 */
.cart-drawer__recommend-products--side .cart-drawer__recommend-products-inner {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.cart-drawer__recommend-products--side .cart-recommend-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

/* 购物车为空时隐藏推荐列表 */
.cart-drawer__content-wrapper:has(.cart-drawer__inner-wrapper.cart-empty) .cart-drawer__recommend-products--side {
    display: none;
}

.cart-drawer__inner:has(.cart-drawer__inner-wrapper.cart-empty) .cart-drawer__recommend-products--below {
    display: none;
}

@media (max-width: 959px) {
    .cart-drawer__recommend-products--below {
        display: flex;
    }

    .cart-drawer__recommend-products--side {
        display: none;
    }

    .cart-recommend-item-desktop {
        display: none;
    }
}

@media (min-width: 960px) {
    .cart-drawer__recommend-products--below {
        display: none;
    }

    .cart-recommend-item-mobile {
        display: none;
    }
}

.cart-recommend-header {
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.cart-recommend-header .title {
    font-size: 18px;
    line-height: 21px;
}

.cart-recommend-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.cart-recommend-item {
    display: flex;
    gap: 8px;
    background: #fff;
    padding: 12px 16px 12px 12px;
}

.cart-recommend-item__image {
    width: 64px;
    flex-shrink: 0;
}

.cart-recommend-item__image img {
    width: 100%;
    aspect-ratio: 3/4;
    height: auto;
    display: block;
    object-fit: cover;
}

.cart-recommend-item__info {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    flex-grow: 1;
    position: relative;
    gap: 12px;
}

.cart-recommend-item__details {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex: 1;
}

.cart-recommend-item__title {
    text-decoration: none;
    color: var(--color-text);
    margin-bottom: 2px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 12px;
    line-height: 18px;
}

.cart-recommend-item__price {
    font-size: 12px;
    line-height: 18px;
    margin-bottom: 8px;
}

.cart-recommend-item__variants {
    padding: 2px 0;
}

.cart-recommend-item__color-swatches {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.color-swatch {
    width: 16px;
    height: 16px;
    display: block;
    cursor: pointer;
    position: relative;
    /* 默认状态：16px 颜色块，无边框 */
    border: none;
    box-sizing: border-box;
}

.color-swatch.active {
    /* 选中状态：12px 颜色块 + 1px padding + 1px 边框 = 16px */
    padding: 1px;
    border: 1px solid #2E2E2E;
    box-sizing: border-box;
    /* 背景色只显示在 padding 内部，即 12px x 12px */
    background-clip: content-box;
    background-origin: content-box;
}


.cart-recommend-item__add-btn {
    position: static;
    right: auto;
    bottom: auto;
    width: 28px;
    height: 28px;
    border-radius: 28px;
    background: #F7F7F7;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: unset;
    border-radius: 50%;
    border: none !important;
    box-shadow: none !important;
    flex-shrink: 0;
}

.cart-recommend-item__add-btn img {
    left: 1px;
    position: relative;
}

.cart-recommend-item__add-btn:before,
.cart-recommend-item__add-btn:after {
    content: none !important;
    display: none !important;
}

.cart-recommend-item__add-btn .loading-overlay__spinner {
    display: none;
}

.cart-recommend-item__add-btn .loading-overlay__spinner svg {
    animation: rotator 1.4s linear infinite;
    color: rgb(var(--color-text));
}

@keyframes rotator {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(270deg);
    }
}

.cart-recommend-item__add-btn.loading>img,
.cart-recommend-item__add-btn.loading .cart-recommend-item__add-text {
    display: none;
}

.cart-recommend-item__add-btn.loading .loading-overlay__spinner {
    display: block !important;
    position: relative;
    inset-inline-start: 5px;
    inset-block-start: 5px;
}

@media (max-width: 959px) {
    .cart-recommend-header .title {
        font-size: 16px;
        line-height: 24px;
    }

    .cart-recommend-list {
        gap: 4px;
    }

    .cart-recommend-item {
        padding: 8px 16px 12px 8px;
    }

    .cart-recommend-item__info {
        align-items: start;
    }

    .cart-recommend-item__title {
        margin-bottom: 8px;
    }

    .cart-recommend-item__price {
        margin-bottom: 0;
        margin-top: 8px;
    }

    .cart-recommend-item__add-btn {
        width: unset;
        height: unset;
        min-width: 55px;
        min-height: 30px;
        margin-top: 4px;
        padding: 6px 16px;
        background: #2E2E2E;
        color: #fff;
        font-size: 12px;
        line-height: 18px;
        border-radius: 0;
    }

    .cart-recommend-item__add-btn .loading-overlay__spinner svg {
        color: #fff;
    }
}