/* ===========================================
   Система подарков - Компактный виджет
   =========================================== */

/* Основной виджет - фиксированный над корзиной */
.gifts-widget {
    position: fixed;
    bottom: 80px; /* будет пересчитано JS относительно #mobile-cart-button */
    left: 12px;
    right: 12px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
    z-index: 1001; /* поверх #mobile-cart-button (z-index: 1000) */
    overflow: hidden;
    border: 1px solid rgba(141, 173, 110, 0.25);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 500px;
    margin: 0 auto;
}

.gifts-widget.hidden {
    transform: translateY(200px);
    opacity: 0;
    pointer-events: none;
}

.gifts-widget.all-unlocked {
    border-color: var(--green);
    box-shadow: 0 4px 24px rgba(141, 173, 110, 0.3);
}

/* В состоянии "все разблокировано" прогресс-бар и суммы не несут смысла —
   убираем, оставляем компактную строку "🎁 Подарок доступен" с CTA. */
.gifts-widget.all-unlocked .gifts-widget-progress,
.gifts-widget.all-unlocked .gifts-widget-amounts {
    display: none;
}

.gifts-widget.all-unlocked .gifts-widget-content {
    padding: 10px 36px 10px 10px;
}

.gifts-widget.all-unlocked .gifts-widget-text {
    margin-bottom: 0;
    font-size: 13px;
    color: var(--green);
    font-weight: 600;
}

/* Кнопка закрытия */
.gifts-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.05);
    border: none;
    border-radius: 50%;
    color: #999;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 5;
}

.gifts-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #666;
}

.gifts-close i {
    font-size: 10px;
}

/* Основной контент виджета */
.gifts-widget-content {
    display: flex;
    align-items: center;
    padding: 8px 36px 8px 10px;
    gap: 10px;
    cursor: pointer;
}

/* Иконка подарка */
.gifts-widget-icon {
    position: relative;
    width: 34px;
    height: 34px;
    background: linear-gradient(135deg, var(--green) 0%, #9dbd7e 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    animation: gift-bounce 2s infinite;
}

.gifts-widget-icon i {
    font-size: 16px;
    color: #fff;
}

.gifts-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ff6b6b;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    padding: 2px 5px;
    border-radius: 8px;
    min-width: 20px;
    text-align: center;
}

.gifts-widget.all-unlocked .gifts-badge {
    background: var(--green);
}

@keyframes gift-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

/* Информация о прогрессе */
.gifts-widget-info {
    flex: 1;
    min-width: 0;
}

.gifts-widget-text {
    font-size: 12px;
    color: #555;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.gifts-widget-text strong {
    color: var(--green);
}

/* Прогресс-бар */
.gifts-widget-progress {
    position: relative;
    height: 6px;
    background: #e8efe4;
    border-radius: 3px;
    overflow: visible;
}

.gifts-widget-progress-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--green) 0%, #a5c77a 100%);
    border-radius: 4px;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Маркеры подарков на прогресс-баре */
.gifts-widget-marker {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 12px;
    height: 12px;
    background: #fff;
    border: 2px solid #d4e4c8;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: all 0.3s ease;
}

.gifts-widget-marker i {
    display: none;
}

.gifts-marker-label {
    display: none; /* подписи под баром захламляют виджет, сумма и так в цифрах */
}

.gifts-widget-marker.unlocked .gifts-marker-label {
    color: var(--green);
    font-weight: 600;
}

.gifts-widget-marker.next {
    border-color: var(--green);
    animation: marker-pulse 1.5s infinite;
}

.gifts-widget-marker.unlocked {
    background: var(--green);
    border-color: var(--green);
}

.gifts-widget-marker.unlocked i {
    color: #fff;
}

@keyframes marker-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(141, 173, 110, 0.4); }
    50% { box-shadow: 0 0 0 4px rgba(141, 173, 110, 0); }
}

/* Суммы */
.gifts-widget-amounts {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    font-size: 10.5px;
    line-height: 1.1;
}

.gifts-current {
    color: var(--green);
    font-weight: 600;
}

.gifts-remaining {
    color: #888;
}

.gifts-remaining strong {
    color: #ff9800;
}

/* Развернутый вид */
.gifts-widget-expanded {
    border-top: 1px solid #f0f0f0;
    background: #fafafa;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.gifts-widget-expanded.show {
    max-height: 300px;
}

.gifts-expanded-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px 6px;
    font-size: 12px;
    font-weight: 600;
    color: #525b75;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.gifts-one-hint {
    font-size: 10px;
    color: #aaa;
    font-weight: 400;
    text-transform: none;
    letter-spacing: normal;
    margin-top: 1px;
}

.gifts-widget[data-gifts-count="1"] .gifts-one-hint {
    display: none;
}

.gifts-collapse {
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    color: #888;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.gifts-collapse:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* Мини-карточки подарков */
.gifts-expanded-cards {
    padding: 0 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.gift-mini-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #fff;
    border-radius: 10px;
    border: 1px solid #e8efe4;
    transition: all 0.2s ease;
    cursor: default;
}

.gift-mini-card.unlocked {
    cursor: pointer;
}

.gift-mini-card.unlocked:hover {
    background: #f8fdf5;
    border-color: var(--green);
}

.gift-mini-card.next {
    border-color: var(--green);
    box-shadow: 0 2px 8px rgba(141, 173, 110, 0.15);
}

.gift-mini-card.unlocked {
    background: linear-gradient(135deg, #f8fdf5 0%, #fff 100%);
    border-color: var(--green);
}

.gift-mini-icon {
    width: 36px;
    height: 36px;
    background: #f5f5f5;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.gift-mini-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gift-mini-icon i {
    font-size: 16px;
    color: #bbb;
}

.gift-mini-card.unlocked .gift-mini-icon {
    background: var(--green);
}

.gift-mini-card.unlocked .gift-mini-icon i {
    color: #fff;
}

.gift-mini-info {
    flex: 1;
    min-width: 0;
}

.gift-mini-name {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #333;
    margin-bottom: 2px;
}

.gift-mini-amount {
    font-size: 11px;
    color: #888;
}

.gift-mini-card.unlocked .gift-mini-amount {
    color: var(--green);
}

.gift-mini-card.unlocked .gift-mini-amount::before {
    content: '✓ ';
}

.gift-mini-status {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gift-mini-status .locked {
    color: #ccc;
    font-size: 12px;
}

.gift-mini-status .unlocked {
    color: var(--green);
    font-size: 14px;
}

.gift-mini-card.unlocked .gift-mini-status .locked {
    display: none !important;
}

.gift-mini-card.unlocked .gift-mini-status .unlocked {
    display: block !important;
}

/* Состояние когда все подарки получены */
.gifts-widget.all-unlocked .gifts-widget-text {
    color: var(--green);
}

.gifts-widget.all-unlocked .gifts-remaining {
    color: var(--green);
}

.gifts-widget.all-unlocked .gifts-widget-icon {
    animation: gift-celebrate 0.5s ease;
}

@keyframes gift-celebrate {
    0%, 100% { transform: scale(1) rotate(0deg); }
    25% { transform: scale(1.1) rotate(-5deg); }
    75% { transform: scale(1.1) rotate(5deg); }
}

/* Анимация разблокировки */
.gift-mini-card.just-unlocked {
    animation: card-unlock 0.5s ease;
}

@keyframes card-unlock {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); background: #e8f5e0; }
    100% { transform: scale(1); }
}

/* Конфетти */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10000;
}

@keyframes confetti-fall {
    0% {
        transform: translateY(-100vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

/* FAB-кнопка (минимизированное состояние) */
.gifts-widget-fab {
    position: fixed;
    bottom: 90px;
    right: 16px;
    width: 52px;
    height: 52px;
    background: linear-gradient(135deg, var(--green) 0%, #9dbd7e 100%);
    border: none;
    border-radius: 50%;
    box-shadow: 0 4px 16px rgba(141, 173, 110, 0.5);
    z-index: 1002; /* поверх виджета и cart-button */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: gift-bounce 2s infinite;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
}

.gifts-widget-fab.hidden {
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}

.gifts-widget-fab i {
    font-size: 22px;
    color: #fff;
}

.gifts-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ff6b6b;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    padding: 2px 5px;
    border-radius: 8px;
    min-width: 20px;
    text-align: center;
}

/* Строка подарка в корзине */
.cart-item.cart-item--gift {
    background: linear-gradient(135deg, #f4faef 0%, #fff 100%);
    border: 1px dashed rgba(141, 173, 110, 0.5);
    border-radius: 10px;
    padding: 8px;
}

.cart-item.cart-item--gift .product-name {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.25;
}

/* Индикатор выбора (радио-стиль) */
.gift-select-circle {
    display: none;
    width: 20px;
    height: 20px;
    border: 2px solid #ccc;
    border-radius: 50%;
    flex-shrink: 0;
    transition: border-color 0.2s ease;
}

.gift-mini-card.unlocked .gift-select-circle {
    display: inline-block;
}

.gift-mini-card.unlocked:hover .gift-select-circle {
    border-color: var(--green);
}

.gift-mini-card.selected .gift-select-circle {
    display: none;
}

.gift-selected-icon {
    display: none !important;
    color: var(--green);
    font-size: 18px;
}

.gift-mini-card.selected .gift-selected-icon {
    display: inline-block !important;
}

.gift-mini-card.selected {
    background: linear-gradient(135deg, #e5f3d8 0%, #f6fbef 100%);
    border: 2px solid var(--green);
    box-shadow: 0 2px 12px rgba(141, 173, 110, 0.35);
    padding: 9px 11px; /* компенсируем прирост border-а */
}

.gift-mini-card.selected .gift-mini-name {
    color: var(--green);
}

/* Адаптивность */
@media (min-width: 768px) {
    /* На десктопе — правый нижний угол. bottom пересчитывает JS (positionWidget)
       относительно высоты #mobile-cart-button; не ставим !important, иначе JS не сможет
       поднять виджет над закреплённой внизу панелью корзины. */
    .gifts-widget {
        left: auto;
        right: 20px;
        transform: none;
        width: 340px;
        margin: 0;
    }

    .gifts-widget.hidden {
        transform: translateY(200px);
        opacity: 0;
    }

    .gifts-widget-fab {
        right: 24px;
    }
}

@media (max-width: 380px) {
    .gifts-widget-content {
        padding: 10px 36px 10px 10px;
        gap: 10px;
    }
    
    .gifts-widget-icon {
        width: 38px;
        height: 38px;
    }
    
    .gifts-widget-icon i {
        font-size: 16px;
    }
    
    .gifts-widget-text {
        font-size: 12px;
    }
    
    .gifts-badge {
        font-size: 8px;
        padding: 1px 4px;
    }
}
