/* ============================================
   Страница корзины (Оптимизированный CSS)
   ============================================ */

/* 🔥 Глобальная фиксация для работы position: sticky */
.container,
.content__inner {
    overflow-x: visible !important;
    overflow-y: visible !important;
}

/* ============================================
   1. Основной макет и шапка
   ============================================ */
.cart-page {
    padding: 24px 0 60px;
}

.cart-page__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
    flex-wrap: wrap;
    gap: 16px;
}

.cart-page__title {
    font-size: 32px;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary, #0f172a);
}

.cart-page__count {
    font-size: 20px;
    font-weight: 400;
    color: var(--text-muted, #64748b);
    margin-left: 8px;
}

.cart-page__clear {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted, #64748b);
    transition: all 0.2s ease;
}

.cart-page__clear:hover {
    color: #ef4444;
    border-color: #ef4444;
    background: #fef2f2;
}

/* ============================================
   2. Двухколоночный макет и липкая панель
   ============================================ */
.cart-page__layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 32px;
    align-items: start; /* Критически важно для sticky в grid */
}

.cart-page__summary {
    position: sticky;
    top: 100px; /* Отступ от верха (подстройте под высоту шапки) */
    align-self: start; /* Критически важно: сжимает блок по высоте контента */
    z-index: 10;
}

.cart-page__summary-card {
    background: #fff;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 12px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ============================================
   3. Список товаров и карточка
   ============================================ */
.cart-page__items {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.cart-page__loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    color: var(--text-muted, #64748b);
    gap: 16px;
}

.cart-item {
    display: grid;
    grid-template-columns: 100px 1fr auto;
    gap: 20px;
    padding: 20px;
    background: #fff;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 12px;
    transition: all 0.25s ease;
    align-items: center;
}

.cart-item:hover {
    border-color: var(--primary-light, #93c5fd);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.cart-item__image {
    width: 100px;
    height: 100px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--bg-gray, #f8fafc);
    display: flex;
    align-items: center;
    justify-content: center;
}

.cart-item__image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 8px;
}

.cart-item__info {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0; /* Предотвращает переполнение flex-контейнера */
}

.cart-item__brand {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted, #64748b);
}

.cart-item__name {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary, #0f172a);
    text-decoration: none;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    transition: color 0.2s ease;
}

.cart-item__name:hover {
    color: var(--primary, #3b82f6);
}

.cart-item__sku {
    font-size: 12px;
    color: var(--text-muted, #64748b);
}

/* ============================================
   4. Контролы количества (Исправлено переполнение)
   ============================================ */
.cart-item__controls {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
    min-width: 140px; /* Фиксируем минимальную ширину */
}

.cart-item__quantity {
    display: flex;
    align-items: center;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 8px;
    overflow: hidden;
    width: 100%;
    max-width: 140px; /* Ограничиваем максимальную ширину */
    box-sizing: border-box;
}

.cart-item__qty-btn {
    width: 36px;
    height: 36px;
    flex-shrink: 0; /* Запрещаем сжатие */
    background: var(--bg-light, #f8fafc);
    border: none;
    cursor: pointer;
    font-size: 18px;
    color: var(--text-primary, #0f172a);
    transition: background 0.15s ease, color 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cart-item__qty-btn:hover:not(:disabled) {
    background: var(--primary-bg, #eff6ff);
    color: var(--primary, #3b82f6);
}

.cart-item__qty-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.cart-item__qty-input {
    flex: 1;
    min-width: 40px;
    height: 36px;
    border: none;
    border-left: 1px solid var(--border-color, #e2e8f0);
    border-right: 1px solid var(--border-color, #e2e8f0);
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    background: #fff;
    -moz-appearance: textfield;
    box-sizing: border-box;
}

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

.cart-item__price {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary, #0f172a);
    text-align: right;
}

.cart-item__price-unit {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-muted, #64748b);
    display: block;
    margin-top: 2px;
}

.cart-item__remove {
    background: none;
    border: none;
    color: var(--text-muted, #64748b);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: flex-start;
}

.cart-item__remove:hover {
    background: #fee2e2;
    color: #ef4444;
}

/* Анимация удаления */
.cart-item.is-removing {
    opacity: 0;
    transform: translateX(30px);
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-bottom: -16px;
    border-width: 0;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   5. Блок итога и гарантии
   ============================================ */
.cart-page__summary-title {
    font-size: 20px;
    font-weight: 700;
    margin: 0 0 8px 0;
    color: var(--text-primary, #0f172a);
}

.cart-page__summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    color: var(--text-secondary, #475569);
}

.cart-page__summary-row--total {
    font-size: 18px;
    color: var(--text-primary, #0f172a);
}

.cart-page__summary-row--total strong {
    font-size: 24px;
    font-weight: 700;
}

.text-success { color: #22c55e !important; }
.text-muted { color: var(--text-muted, #64748b) !important; font-style: italic; font-size: 13px; }

.cart-page__summary-divider {
    height: 1px;
    background: var(--border-color, #e2e8f0);
    margin: 8px 0;
}

.cart-page__checkout {
    width: 100%;
    padding: 14px 24px;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 8px;
}

.cart-page__continue {
    display: block;
    text-align: center;
    color: var(--text-muted, #64748b);
    text-decoration: none;
    font-size: 14px;
    padding: 8px;
    transition: color 0.15s ease;
}

.cart-page__continue:hover {
    color: var(--primary, #3b82f6);
}

.cart-page__guarantees {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 20px;
    background: var(--bg-light, #f8fafc);
    border-radius: 12px;
}

.cart-page__guarantee {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--text-secondary, #475569);
}

.cart-page__guarantee svg {
    flex-shrink: 0;
    color: var(--primary, #3b82f6);
}

/* ============================================
   6. Пустое состояние и рекомендации
   ============================================ */
.cart-page__empty {
    text-align: center;
    padding: 80px 20px;
    background: #fff;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 12px;
}

.cart-page__empty-icon {
    color: var(--text-muted, #64748b);
    margin-bottom: 20px;
    opacity: 0.5;
}

.cart-page__empty-title {
    font-size: 24px;
    font-weight: 600;
    margin: 0 0 12px 0;
}

.cart-page__empty-text {
    font-size: 15px;
    color: var(--text-muted, #64748b);
    margin: 0 0 32px 0;
}

.cart-page__recommendations {
    margin-top: 60px;
}

.cart-page__recommendations-title {
    font-size: 24px;
    font-weight: 700;
    margin: 0 0 24px 0;
}

/* ============================================
   7. Адаптивность (Сгруппирована и оптимизирована)
   ============================================ */

/* Планшеты */
@media (max-width: 992px) {
    .cart-page__layout {
        grid-template-columns: 1fr;
    }

    .cart-page__summary {
        position: static; /* Отключаем sticky на мобильных/планшетах */
    }
}

/* Мобильные устройства */
@media (max-width: 768px) {
    .cart-page__title {
        font-size: 24px;
    }

    .cart-item {
        grid-template-columns: 80px 1fr;
        gap: 12px;
        padding: 16px;
    }

    .cart-item__image {
        width: 80px;
        height: 80px;
    }

    .cart-item__controls {
        grid-column: 1 / -1;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        min-width: 0;
        padding-top: 12px;
        border-top: 1px solid var(--border-color, #e2e8f0);
    }

    .cart-item__quantity {
        max-width: 130px;
    }

    .cart-item__price {
        text-align: left;
    }

    .cart-item__remove {
        align-self: center;
    }
}

/* Маленькие мобильные устройства */
@media (max-width: 480px) {
    .cart-page__header {
        flex-direction: column;
        align-items: flex-start;
    }

    .cart-page__title {
        font-size: 22px;
    }

    .cart-item__quantity {
        flex: 1;
    }

    .cart-item__qty-input {
        flex: 1;
    }
}