/* AIM8 — Чат-виджет с ИИ */
.chat-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6c5ce7, #a29bfe);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(108,92,231,0.4);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-size: 28px;
    color: white;
}
.chat-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 28px rgba(108,92,231,0.6);
}
.chat-btn:active {
    transform: scale(0.95);
}

.chat-widget {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 360px;
    max-height: 520px;
    background: #1a1a2e;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
    z-index: 9998;
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(108,92,231,0.3);
    animation: slideUp 0.3s ease;
}
.chat-widget.open {
    display: flex;
}

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

.chat-header {
    background: linear-gradient(135deg, #6c5ce7, #5a4bd1);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.chat-header-title {
    font-weight: 600;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.chat-header-title .pulse-dot {
    width: 8px;
    height: 8px;
    background: #00e676;
    border-radius: 50%;
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0% { opacity: 1; box-shadow: 0 0 0 0 rgba(0,230,118,0.4); }
    70% { opacity: 0.8; box-shadow: 0 0 0 6px rgba(0,230,118,0); }
    100% { opacity: 1; box-shadow: 0 0 0 0 rgba(0,230,118,0); }
}
.chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
    opacity: 0.8;
    transition: opacity 0.2s;
}
.chat-close:hover { opacity: 1; }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 200px;
    max-height: 340px;
    scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar {
    width: 4px;
}
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: #6c5ce7;
    border-radius: 4px;
}

.chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: msgIn 0.25s ease;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-msg.bot {
    align-self: flex-start;
    background: #16213e;
    color: #e0e0e0;
    border-bottom-left-radius: 4px;
}
.chat-msg.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #6c5ce7, #5a4bd1);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 10px 16px;
    background: #16213e;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    animation: msgIn 0.25s ease;
}
.chat-typing span {
    width: 7px;
    height: 7px;
    background: #6c5ce7;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

.chat-msg-time {
    font-size: 10px;
    opacity: 0.5;
    margin-top: 4px;
    text-align: right;
}

/* Мигающий курсор во время стриминга */
.cursor-blink {
    animation: blink 0.8s step-end infinite;
    color: #a29bfe;
    font-weight: bold;
}
@keyframes blink {
    50% { opacity: 0; }
}

.chat-msg.streaming {
    border-left: 2px solid #a29bfe;
    padding-left: 12px;
}

.chat-input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: #0f0f23;
    border-top: 1px solid rgba(108,92,231,0.2);
    flex-shrink: 0;
}
.chat-input {
    flex: 1;
    background: #1a1a2e;
    border: 1px solid rgba(108,92,231,0.3);
    border-radius: 24px;
    padding: 10px 16px;
    color: white;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}
.chat-input:focus {
    border-color: #6c5ce7;
}
.chat-input::placeholder {
    color: #666;
}
.chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6c5ce7, #a29bfe);
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}
.chat-send:hover {
    transform: scale(1.1);
}
.chat-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.chat-greeting {
    text-align: center;
    padding: 20px 16px;
    color: #888;
    font-size: 13px;
    line-height: 1.5;
}
.chat-greeting strong {
    color: #a29bfe;
}

/* Адаптив для мобильных */
@media (max-width: 480px) {
    .chat-widget {
        width: calc(100vw - 32px);
        right: 16px;
        bottom: 88px;
        max-height: 60vh;
    }
    .chat-btn {
        width: 52px;
        height: 52px;
        bottom: 20px;
        right: 20px;
        font-size: 24px;
    }
}