/* ==========================================================================
   AIDAI.PRO — ИНТЕРАКТИВНЫЙ AI-АССИСТЕНТ «ЛЯСЯ» (СТИЛИ И АНИМАЦИИ)
   Полная репликация физики полета с t.vibeees.pro:
   - Левитация, зависания и покачивание (aiFlight)
   - Кивок (aiNodAnim) и отскок при подлете к блокам (aiBounceAnim)
   - Резкое моргание и слежение
   - Темный оверлей с blur
   ========================================================================== */

/* Обертка для перетаскивания и позиционирования по экрану */
.ai-bot,
#ai-companion {
    position: absolute !important;
    width: 80px;
    height: 80px;
    z-index: 9995;
    cursor: grab;
    pointer-events: auto;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    transition: transform 0.2s ease-out;
}

.ai-bot:active,
#ai-companion:active {
    cursor: grabbing;
}

/* Тело Ляси с анимацией полета и левитации */
.ai-body,
.ai-character-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: #ffffff;
    border: 3px solid #ffffff;
    box-shadow: 0 8px 24px rgba(196, 85, 43, 0.35), 0 0 0 2.5px #c4552b;
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: aiFlight 8s infinite ease-in-out, aiPulseGlow 3s infinite ease-in-out;
    transform-style: preserve-3d;
    transition: transform 0.25s ease;
}

.ai-body:hover,
.ai-character-avatar:hover {
    transform: scale(1.08);
}

.ai-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.ai-online-dot {
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 14px;
    height: 14px;
    background-color: #22c55e;
    border: 2px solid #ffffff;
    border-radius: 50%;
    z-index: 5;
}

/* Пульсация свечения */
@keyframes aiPulseGlow {
    0%, 100% {
        box-shadow: 0 8px 24px rgba(196, 85, 43, 0.35), 0 0 0 2.5px #c4552b;
    }
    50% {
        box-shadow: 0 12px 32px rgba(196, 85, 43, 0.6), 0 0 0 3.5px #e06638;
    }
}

/* Плавный полет, покачивание и левитация в пространстве */
@keyframes aiFlight {
    0%   { transform: translate(0, 0) rotate(0deg); }
    20%  { transform: translate(-10px, -14px) rotate(-3deg); }
    40%  { transform: translate(12px, -7px) rotate(4deg) scale(1.02); }
    55%  { transform: translate(15px, 10px) rotate(2deg); }
    75%  { transform: translate(-10px, 8px) rotate(-2deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}

/* Спец-анимация: Кивок */
.ai-nod {
    animation: aiNodAnim 0.8s ease-in-out !important;
}
@keyframes aiNodAnim {
    0%, 100% { transform: rotateX(0deg) translateY(0) scale(1.05); }
    30% { transform: rotateX(20deg) translateY(8px) scale(1.05); }
    60% { transform: rotateX(-6deg) translateY(-3px) scale(1.05); }
}

/* Спец-анимация: Отскок при приземлении/подлете к блоку */
.ai-bounce {
    animation: aiBounceAnim 0.5s ease-in-out !important;
}
@keyframes aiBounceAnim {
    0%, 100% { transform: scale(1, 1) translateY(0); }
    30% { transform: scale(1.15, 0.85) translateY(6px); }
    60% { transform: scale(0.92, 1.1) translateY(-8px); }
    80% { transform: scale(1.04, 0.96) translateY(2px); }
}

/* Всплывающее облачко (Speech Bubble) с эффектом печати */
.ai-speech-bubble {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(10px) scale(0.85);
    background: #ffffff;
    border: 1px solid #ebd5c1;
    border-radius: 16px;
    padding: 12px 18px;
    color: #1e1b18;
    font-family: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1.4;
    white-space: pre-wrap;
    min-width: 220px;
    max-width: 280px;
    box-shadow: 0 12px 30px rgba(196, 85, 43, 0.15), 0 4px 12px rgba(0, 0, 0, 0.05);
    opacity: 0;
    transform-origin: bottom center;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.25s ease;
    pointer-events: none;
    z-index: 10;
    margin-bottom: 14px;
    text-align: left;
    display: none;
}

.ai-speech-bubble.show {
    display: block !important;
    transform: translateX(-50%) translateY(0) scale(1);
    opacity: 1;
    pointer-events: auto;
}

.ai-speech-bubble::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 7px;
    border-style: solid;
    border-color: #ffffff transparent transparent transparent;
}

.ai-speech-close {
    position: absolute;
    top: 4px;
    right: 8px;
    background: transparent;
    border: none;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    color: #999;
    padding: 2px 5px;
}
.ai-speech-close:hover {
    color: #c4552b;
}

.ai-speech-text::after {
    content: '|';
    animation: aiBlinkCursor 0.8s step-start infinite;
    color: #c4552b;
    margin-left: 2px;
    font-weight: 700;
}

@keyframes aiBlinkCursor {
    50% { opacity: 0; }
}

/* Полупрозрачный темный оверлей с эффектом размытия заднего плана */
.ai-chat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9990;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.ai-chat-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

/* Окно чата Ляси */
.ai-chat-container {
    position: absolute;
    width: 370px;
    max-width: calc(100vw - 30px);
    height: 500px;
    background: #ffffff;
    border: 1px solid #ebd5c1;
    border-radius: 20px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(196, 85, 43, 0.1);
    z-index: 10001;
    display: none;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.ai-chat-container.open {
    display: flex !important;
    opacity: 1;
    transform: scale(1);
}

.ai-chat-header {
    background: linear-gradient(135deg, #fdfbf7 0%, #fff7ed 100%);
    border-bottom: 1px solid #ebd5c1;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ai-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #c4552b;
}

.ai-header-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background: #22c55e;
    border: 2px solid #fff;
    border-radius: 50%;
}

.ai-header-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: #1e1b18;
}

.ai-header-status {
    font-size: 0.72rem;
    color: #64748b;
}

.ai-chat-close-btn {
    background: transparent;
    border: none;
    font-size: 24px;
    line-height: 1;
    color: #64748b;
    cursor: pointer;
    transition: color 0.2s;
    padding: 0 4px;
}
.ai-chat-close-btn:hover {
    color: #c4552b;
}

.ai-chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: #faf8f5;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.45;
    word-break: break-word;
}

.ai-msg-bot {
    align-self: flex-start;
    background: #ffffff;
    color: #1e1b18;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
}

.ai-msg-user {
    align-self: flex-end;
    background: linear-gradient(135deg, #c4552b 0%, #b44b22 100%);
    color: #ffffff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(196, 85, 43, 0.25);
}

.ai-typing {
    font-style: italic;
    color: #64748b;
    font-size: 0.85rem;
}

.ai-dots {
    animation: aiDots 1.4s infinite;
}

@keyframes aiDots {
    0%, 20% { opacity: 0; }
    40% { opacity: 0.5; }
    60%, 100% { opacity: 1; }
}

.ai-chat-input-area {
    padding: 12px 16px;
    background: #ffffff;
    border-top: 1px solid #ebd5c1;
    display: flex;
    gap: 8px;
    align-items: center;
}

.ai-chat-input {
    flex: 1;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    padding: 9px 14px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}
.ai-chat-input:focus {
    border-color: #c4552b;
}

.ai-chat-send-btn {
    background: linear-gradient(135deg, #c4552b, #b44b22);
    color: #ffffff;
    border: none;
    border-radius: 12px;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s, opacity 0.15s;
}
.ai-chat-send-btn:hover {
    opacity: 0.92;
    transform: scale(1.04);
}

/* Мобильная адаптация */
@media (max-width: 768px) {
    .ai-bot,
    #ai-companion {
        width: 68px !important;
        height: 68px !important;
    }
    .ai-body,
    .ai-character-avatar {
        width: 68px !important;
        height: 68px !important;
    }
    .ai-speech-bubble {
        min-width: 170px !important;
        max-width: 220px !important;
        padding: 9px 13px !important;
        font-size: 0.78rem !important;
        margin-bottom: 8px;
    }
    .ai-chat-container {
        position: fixed !important;
        top: 15px !important;
        left: 50% !important;
        transform: translateX(-50%) scale(0.95) !important;
        width: calc(100vw - 24px) !important;
        max-width: 380px !important;
        height: 420px !important;
        min-height: 340px !important;
        border-radius: 16px !important;
    }
    .ai-chat-container.open {
        transform: translateX(-50%) scale(1) !important;
    }
}
