/* ============================================
   AI Чат-виджет - ВЕРХНЕЕ РАСПОЛОЖЕНИЕ
   ============================================ */

#ai-chat-widget {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 99999;
    font-family: system-ui, -apple-system, sans-serif;
    opacity: 0;
    transition: opacity 0.5s ease;
}

/* Кнопка-иконка (компактная) */
.ai-chat-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: linear-gradient(135deg, #e94560, #c5303f);
    color: #fff;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 4px 20px rgba(233, 69, 96, 0.35);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.ai-chat-toggle:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 8px 30px rgba(233, 69, 96, 0.5);
}

.ai-chat-toggle .ai-chat-icon {
    font-size: 20px;
}

.ai-chat-toggle .ai-chat-label {
    font-size: 13px;
}

.ai-chat-toggle .ai-chat-badge {
    background: rgba(255, 255, 255, 0.25);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

/* Попап чата (открывается вниз) */
.ai-chat-popup {
    position: absolute;
    top: 60px;
    right: 0;
    width: 380px;
    max-height: 480px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.ai-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 18px;
    background: linear-gradient(135deg, #1a365d, #2a4a7f);
    color: #fff;
    font-weight: 600;
    font-size: 14px;
}

.ai-chat-header button {
    background: none;
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    padding: 0 6px;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.ai-chat-header button:hover {
    opacity: 1;
}

.ai-chat-body {
    padding: 14px 18px;
    height: 260px;
    overflow-y: auto;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-message {
    padding: 8px 14px;
    border-radius: 12px;
    max-width: 85%;
    line-height: 1.5;
    font-size: 13px;
    word-wrap: break-word;
}

.ai-message.user {
    background: linear-gradient(135deg, #e94560, #c5303f);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.ai-message.bot {
    background: #ffffff;
    color: #1a365d;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    border: 1px solid #e2e8f0;
}

.ai-message.bot strong {
    color: #e94560;
}

.ai-message .loading-dots {
    display: inline-block;
}

.ai-message .loading-dots span {
    animation: dotPulse 1.4s infinite;
    display: inline-block;
}

.ai-message .loading-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-message .loading-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes dotPulse {
    0%, 80%, 100% { opacity: 0; }
    40% { opacity: 1; }
}

.ai-chat-footer {
    display: flex;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid #e2e8f0;
    background: #ffffff;
}

.ai-chat-footer input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    outline: none;
    font-size: 13px;
    transition: border-color 0.2s ease;
}

.ai-chat-footer input:focus {
    border-color: #e94560;
}

.ai-chat-footer button {
    padding: 8px 16px;
    background: linear-gradient(135deg, #e94560, #c5303f);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    transition: background 0.2s ease;
}

.ai-chat-footer button:hover {
    background: #c5303f;
}

/* Быстрые ответы */
.ai-quick-reply {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.ai-quick-reply button {
    padding: 4px 12px;
    background: #edf2f7;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    font-size: 11px;
    color: #1a365d;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ai-quick-reply button:hover {
    background: #e94560;
    color: #fff;
    border-color: #e94560;
}

/* ============================================ */
/* АДАПТИВНОСТЬ */
/* ============================================ */

@media (max-width: 768px) {
    #ai-chat-widget {
        top: 10px;
        right: 10px;
    }

    .ai-chat-popup {
        width: calc(100vw - 40px);
        right: -10px;
        top: 50px;
        max-height: 400px;
    }

    .ai-chat-toggle {
        padding: 8px 14px;
        font-size: 12px;
    }

    .ai-chat-toggle .ai-chat-label {
        display: none;
    }

    .ai-chat-toggle .ai-chat-badge {
        display: none;
    }

    .ai-chat-body {
        height: 200px;
    }
}

@media (max-width: 480px) {
    .ai-chat-popup {
        width: calc(100vw - 20px);
        right: -5px;
        top: 48px;
        max-height: 350px;
        border-radius: 12px;
    }

    .ai-chat-body {
        height: 180px;
        padding: 10px 14px;
    }

    .ai-message {
        font-size: 12px;
        padding: 6px 12px;
    }

    .ai-chat-header {
        font-size: 13px;
        padding: 10px 14px;
    }
}