/* Стили для модального окна */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.8);
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s ease-out;
    /* Убрано padding и overflow-y */
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

.modal-content {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    margin: 2% auto;
    border-radius: 24px;
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    overflow-y: auto; /* Перенесено сюда */
    position: relative;
    animation: slideUp 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

@keyframes slideUp {
    from { 
        transform: translateY(60px) scale(0.95); 
        opacity: 0; 
    }
    to { 
        transform: translateY(0) scale(1); 
        opacity: 1; 
    }
}

.close {
    position: absolute;
    left: 20px;
    top: 20px;
    font-size: 28px;
    font-weight: 300;
    color: #64748b;
    cursor: pointer;
    z-index: 10;
    background: rgba(255, 255, 255, 0.9);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.close:hover {
    background: #ef4444;
    color: white;
    transform: rotate(90deg) scale(1.1);
}

.modal-product {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    min-height: 500px;
}

.modal-image {
    background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    border-radius: 24px 0 0 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    position: relative;
    overflow: hidden;
}

.modal-image::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at 30% 20%, rgba(120, 119, 198, 0.1) 0%, transparent 50%);
}

.modal-image img {
    width: 100%;
    max-width: 350px;
    height: auto;
    border-radius: 16px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
    position: relative;
    z-index: 2;
}

.modal-image:hover img {
    transform: scale(1.02);
}

.modal-info {
    padding: 3rem 2.5rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.modal-info h2 {
    font-size: 2rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 1rem;
    line-height: 1.3;
}

.modal-description {
    color: #64748b;
    margin-bottom: 2rem;
    line-height: 1.6;
    font-size: 1rem;
}

.modal-price-section {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    padding: 1rem 0;
    border-bottom: 2px solid #f1f5f9;
}

.modal-price {
    font-size: 2.5rem;
    font-weight: 800;
    color: #000000;
    background: linear-gradient(135deg, #ff0000 0%, #ff7d7d 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-currency {
    font-size: 1.4rem;
    color: #64748b;
    font-weight: 600;
}

.stock-info {
    margin-bottom: 2rem;
}

.stock-info span {
    padding: 0.5rem 1.2rem;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.in-stock-modal {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.out-of-stock-modal {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.quantity-selector {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: #f8fafc;
    border-radius: 16px;
    border: 2px solid #e2e8f0;
}

.quantity-selector span {
    font-weight: 600;
    color: #1e293b;
    font-size: 1.1rem;
}

.quantity-controls {
    display: flex;
    align-items: center;
    gap: 1.2rem;
}

.quantity-btn {
    background: linear-gradient(135deg, #64748b 0%, #475569 100%);
    color: white;
    border: none;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(100, 116, 139, 0.3);
}

.quantity-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #475569 0%, #334155 100%);
    transform: scale(1.1) translateY(-2px);
    box-shadow: 0 6px 20px rgba(100, 116, 139, 0.4);
}

.quantity-btn:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.quantity {
    font-size: 1.3rem;
    font-weight: 700;
    min-width: 40px;
    text-align: center;
    color: #1e293b;
}

.add-to-cart-modal {
    width: 100%;
    background: linear-gradient(135deg, #ff0000 0%, #ff6161 100%);
    color: white;
    border: none;
    padding: 1.4rem;
    border-radius: 16px;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 8px 25px rgba(122, 0, 0, 0.4);
    position: relative;
    overflow: hidden;
}

.add-to-cart-modal::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

.add-to-cart-modal:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 12px 35px rgba(63, 0, 0, 0.6);
}

.add-to-cart-modal:hover::before {
    left: 100%;
}

.add-to-cart-modal:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.add-to-cart-modal:disabled::before {
    display: none;
}

.out-of-stock-badge {
    position: absolute;
    top: 20px;
    right: 20px;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 700;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
    z-index: 3;
}

/* Адаптивность для модального окна */
@media (max-width: 968px) {
    .modal-content {
        margin: 5% auto;
        width: 95%;
        max-height: 95vh; /* Увеличено для мобильных */
    }
    
    .modal-product {
        grid-template-columns: 1fr;
        min-height: auto;
    }
    
    .modal-image {
        border-radius: 24px 24px 0 0;
        padding: 2rem 1.5rem;
        min-height: 300px;
    }
    
    .modal-image img {
        max-width: 280px;
    }
    
    .modal-info {
        padding: 2rem 1.5rem;
    }
    
    .modal-info h2 {
        font-size: 1.7rem;
    }
    
    .modal-price {
        font-size: 2rem;
    }
}

@media (max-width: 640px) {
    .modal-content {
        margin: 2% auto; /* Уменьшено для мобильных */
        border-radius: 20px;
        width: 98%; /* Чуть шире на мобильных */
    }
    
    .close {
        right: 15px;
        top: 15px;
        width: 38px;
        height: 38px;
        font-size: 24px;
    }
    
    .modal-info h2 {
        font-size: 1.5rem;
    }
    
    .quantity-selector {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .quantity-controls {
        justify-content: center;
    }
}

/* Анимация закрытия */
.modal.closing {
    animation: fadeOut 0.3s ease-in forwards;
}

.modal.closing .modal-content {
    animation: slideDown 0.3s cubic-bezier(0.55, 0.085, 0.68, 0.53) forwards;
}

@keyframes slideDown {
    from { 
        transform: translateY(0) scale(1); 
        opacity: 1; 
    }
    to { 
        transform: translateY(60px) scale(0.95); 
        opacity: 0; 
    }
}

/* Исправление для body при открытии модального окна */
body.modal-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* Сохраняем позицию скролла */
body.modal-open::before {
    content: '';
    position: fixed;
    top: var(--scroll-top, 0);
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    z-index: -1;
}

/* Улучшения для модального окна */
.modal-content {
    /* Добавляем плавную анимацию закрытия */
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.modal.closing .modal-content {
    transform: scale(0.9);
    opacity: 0;
}

/* Улучшаем доступность */
.quick-view-btn:focus {
    outline: 2px solid #ff3c00;
    outline-offset: 2px;
}

.quantity-btn:focus {
    outline: 2px solid #475569;
    outline-offset: 2px;
}

.add-to-cart-modal:focus {
    outline: 2px solid #ff4757;
    outline-offset: 2px;
}