/**
 * Стили кнопки "Купить" и модалки выбора вариантов
 * /new/assets/css/buy-button.css
 */

/* ==========================================================================
   Кнопка "Купить"
   ========================================================================== */

/* Скрываем кнопку до инициализации JS (убирает мигание) */
.buy-btn-wrapper:not(.buy-btn-ready) .buy-btn,
.buy-btn-wrapper:not(.buy-btn-ready) .qty-control {
    opacity: 0;
    transition: opacity 0.15s ease;
}
.buy-btn-wrapper.buy-btn-ready .buy-btn,
.buy-btn-wrapper.buy-btn-ready .qty-control {
    opacity: 1;
}

.buy-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, #0066cc 0%, #0047b1 100%);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    min-width: 80px;
}

.buy-btn:hover {
    background: linear-gradient(135deg, #0077ee 0%, #0055cc 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 102, 204, 0.35);
}

.buy-btn:active {
    transform: translateY(0);
}

.buy-btn:disabled,
.buy-btn.loading {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

/* Большая кнопка для страницы товара */
.buy-btn--large {
    padding: 14px 32px;
    font-size: 16px;
    min-width: 160px;
    border-radius: 10px;
}

.buy-btn--large:hover {
    box-shadow: 0 6px 16px rgba(0, 102, 204, 0.4);
}

/* Кнопка "В корзине" — приглушённый стиль */
.buy-btn--in-cart {
    background: linear-gradient(135deg, #6b9dc4 0%, #4a7fa8 100%);
    color: #fff;
    cursor: pointer;
}

.buy-btn--in-cart:hover {
    background: linear-gradient(135deg, #5a8cb3 0%, #3a6f98 100%);
    box-shadow: 0 4px 12px rgba(74, 127, 168, 0.3);
}

/* Qty-control большой размер */
.buy-btn-wrapper .qty-control {
    padding: 4px;
}

.buy-btn-wrapper .qty-btn {
    width: 40px;
    height: 40px;
    font-size: 18px;
}

.buy-btn-wrapper .qty-value {
    min-width: 50px;
    font-size: 18px;
    padding: 8px 12px;
}

.buy-btn.loading::after {
    content: '';
    width: 14px;
    height: 14px;
    margin-left: 8px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ==========================================================================
   Qty Control (количество в корзине)
   ========================================================================== */

.qty-control {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    background: #f0f4f8;
    border-radius: 8px;
    padding: 2px;
}

.qty-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    font-size: 16px;
    font-weight: 600;
    color: #333;
    background: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.qty-btn:hover {
    background: #e8f4ff;
    color: #0066cc;
}

.qty-btn:active {
    transform: scale(0.95);
}

.qty-btn--plus {
    color: #0066cc;
}

.qty-btn--plus:hover {
    background: #0066cc;
    color: #fff;
}

.qty-btn--minus {
    color: #666;
}

.qty-btn--remove {
    color: #e53935;
}

.qty-btn--remove:hover {
    background: #ffebee;
    color: #c62828;
}

.qty-value {
    min-width: 32px;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    padding: 0 4px;
}

/* ==========================================================================
   Модалка
   ========================================================================== */

.buy-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: all 0.25s ease;
}

.buy-modal.active {
    opacity: 1;
    visibility: visible;
}

.buy-modal__content {
    position: relative;
    width: 100%;
    max-width: 480px;
    max-height: calc(100vh - 40px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    transition: transform 0.25s ease;
}

.buy-modal.active .buy-modal__content {
    transform: translateY(0) scale(1);
}

.buy-modal__close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #666;
    background: rgba(0, 0, 0, 0.05);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.15s ease;
    z-index: 10;
}

.buy-modal__close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #333;
}

.buy-modal__body {
    padding: 24px;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
}

.buy-modal__loading,
.buy-modal__error,
.buy-modal__empty {
    text-align: center;
    padding: 40px 20px;
    color: #666;
    font-size: 15px;
}

.buy-modal__error {
    color: #e53935;
}

/* Header модалки */
.buy-modal__header {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.buy-modal__photo {
    flex-shrink: 0;
    width: 100px;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f7fa;
    border-radius: 12px;
    overflow: hidden;
}

.buy-modal__photo img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.buy-modal__info {
    flex: 1;
    min-width: 0;
}

.buy-modal__title {
    margin: 0 0 8px 0;
    font-size: 18px;
    font-weight: 600;
    color: #1a1a1a;
    line-height: 1.3;
}

.buy-modal__form {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: #666;
    margin-bottom: 4px;
}

.buy-modal__vendor {
    font-size: 13px;
    color: #888;
}

/* Иконка формы выпуска */
.form-icon-img {
    width: 16px;
    height: 16px;
    opacity: 0.7;
}

/* Дропдауны */
.buy-modal__dropdowns {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.dropdown {
    position: relative;
}

.dropdown__toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    font-size: 13px;
    color: #0066cc;
    background: #e8f4ff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.dropdown__toggle:hover {
    background: #d0e8ff;
}

.dropdown__arrow {
    font-size: 10px;
    transition: transform 0.2s ease;
}

.dropdown.open .dropdown__arrow {
    transform: rotate(180deg);
}

.dropdown__menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 200px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s ease;
    z-index: 100;
}

.dropdown.open .dropdown__menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown__item {
    display: block;
    padding: 10px 14px;
    font-size: 13px;
    color: #333;
    text-decoration: none;
    transition: background 0.15s ease;
}

.dropdown__item:first-child {
    border-radius: 10px 10px 0 0;
}

.dropdown__item:last-child {
    border-radius: 0 0 10px 10px;
}

.dropdown__item:hover {
    background: #f5f7fa;
    color: #0066cc;
}

/* Разделитель */
.buy-modal__divider {
    height: 1px;
    background: #e8e8e8;
    margin: 16px 0;
}

/* Варианты — список */
.buy-modal__variants-label {
    font-size: 14px;
    font-weight: 500;
    color: #666;
    margin-bottom: 12px;
}

.buy-modal__variants-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.variant-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 10px;
    transition: background 0.15s ease;
}

.variant-row:hover {
    background: #f0f4f8;
}

.variant-row__label {
    flex: 1;
    font-size: 14px;
    color: #333;
}

.variant-row__price {
    font-size: 15px;
    font-weight: 600;
    color: #1a1a1a;
    min-width: 80px;
    text-align: right;
}

.variant-row__action {
    flex-shrink: 0;
}

/* Варианты — селекторы (≥8 комбинаций) */
.buy-modal__selectors {
    /* контейнер */
}

.selector-group {
    margin-bottom: 16px;
}

.selector-group__label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #666;
    margin-bottom: 8px;
}

.selector-group__options {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.selector-btn {
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    color: #333;
    background: #f0f4f8;
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.selector-btn:hover {
    background: #e8f4ff;
    border-color: #b3d9ff;
}

.selector-btn.active {
    background: #e8f4ff;
    border-color: #0066cc;
    color: #0066cc;
}

.buy-modal__selected-variant {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px;
    background: linear-gradient(135deg, #f8fbff 0%, #f0f7ff 100%);
    border-radius: 12px;
}

.selected-variant__price {
    font-size: 22px;
    font-weight: 700;
    color: #1a1a1a;
}

.selected-variant__action {
    flex-shrink: 0;
}

/* Аналоги */
.buy-modal__analogs {
    margin-top: 8px;
}

.buy-modal__analogs-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 12px;
    font-size: 14px;
    font-weight: 500;
    color: #666;
    background: #f8f9fa;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.buy-modal__analogs-toggle:hover {
    background: #f0f4f8;
    color: #333;
}

.buy-modal__analogs-list {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.analog-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    text-decoration: none;
    background: #fff;
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    transition: all 0.15s ease;
}

.analog-item:hover {
    border-color: #0066cc;
    background: #f8fbff;
}

.analog-item__name {
    flex: 1;
    font-size: 14px;
    color: #333;
}

.analog-item__vendor {
    font-size: 12px;
    color: #888;
}

.analog-item__price {
    font-size: 14px;
    font-weight: 600;
    color: #0066cc;
}

/* ==========================================================================
   Карточка товара (дополнения)
   ========================================================================== */

.product-card {
    position: relative;
}

.product-card .form-icon {
    position: absolute;
    top: 8px;
    left: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 6px;
    font-size: 11px;
    color: #666;
    z-index: 2;
}

.product-card .form-icon img {
    width: 14px;
    height: 14px;
    opacity: 0.7;
}

.product-card .variant-info {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 8px;
    background: rgba(0, 102, 204, 0.1);
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    color: #0066cc;
    z-index: 2;
}

.product-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: auto;
    padding-top: 12px;
}

.product-card-price {
    font-size: 16px;
    font-weight: 700;
    color: #1a1a1a;
}

.product-card-action {
    flex-shrink: 0;
}

.product-card-vendor {
    font-size: 12px;
    color: #888;
    margin-top: 4px;
}

/* ==========================================================================
   Toast уведомления
   ========================================================================== */

.buy-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 14px 24px;
    font-size: 14px;
    font-weight: 500;
    color: #fff;
    background: #43a047;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 10001;
    animation: toast-in 0.3s ease;
}

.buy-toast--error {
    background: #e53935;
}

.buy-toast.fade-out {
    animation: toast-out 0.3s ease forwards;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toast-out {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(20px);
    }
}

/* ==========================================================================
   Адаптив
   ========================================================================== */

@media (max-width: 540px) {
    .buy-modal {
        padding: 0;
        align-items: flex-end;
    }
    
    .buy-modal__content {
        max-width: 100%;
        max-height: 90vh;
        border-radius: 20px 20px 0 0;
    }
    
    .buy-modal.active .buy-modal__content {
        transform: translateY(0);
    }
    
    .buy-modal__header {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
    
    .buy-modal__photo {
        width: 120px;
        height: 120px;
    }
    
    .buy-modal__dropdowns {
        justify-content: center;
    }
    
    .variant-row {
        flex-wrap: wrap;
    }
    
    .variant-row__label {
        width: 100%;
        margin-bottom: 8px;
    }
    
    .variant-row__price {
        text-align: left;
    }
    
    .buy-modal__selected-variant {
        flex-direction: column;
        text-align: center;
    }
    
    .selected-variant__price {
        margin-bottom: 12px;
    }
    
    .buy-btn {
        width: 100%;
    }
    
    .qty-control {
        width: 100%;
        justify-content: center;
    }
}

/* Карточки в каталоге — компактная кнопка */
.catalog-v2-card .buy-btn {
    padding: 6px 12px;
    font-size: 13px;
    min-width: 70px;
}

.catalog-v2-card .qty-control {
    transform: scale(0.9);
    transform-origin: right center;
}

.catalog-v2-card .qty-btn {
    width: 28px;
    height: 28px;
    font-size: 14px;
}

.catalog-v2-card .qty-value {
    min-width: 24px;
    font-size: 13px;
}
