/* AI Chat Widget */
#ai-chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 100000;
    font-family: 'Segoe UI', sans-serif;
}

.ai-chat-toggle {
    display: flex !important;
    align-items: center;
    gap: 8px;
    padding: 16px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.5);
    font-size: 16px;
    font-weight: 600;
}

.ai-chat-toggle:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 30px rgba(102, 126, 234, 0.6);
}

.ai-chat-toggle:active {
    transform: translateY(0) scale(0.98);
}

.chat-icon { font-size: 20px; }
.chat-label { font-size: 13px; font-weight: 600; }

.ai-chat-window {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 350px;
    height: 480px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    cursor: grab;
    flex-shrink: 0;
    gap: 10px;
}

.ai-chat-header .ai-chat-title {
    flex: 1;
    justify-content: center;
}

.ai-chat-header:active {
    cursor: grabbing;
}

.ai-chat-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-avatar {
    width: 38px;
    height: 38px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.ai-chat-title-text {
    display: flex;
    flex-direction: column;
}

.ai-name { font-size: 16px; font-weight: 600; }
.ai-status { font-size: 12px; opacity: 0.9; }

.ai-chat-close {
    width: 28px;
    height: 28px;
    background: rgba(255,255,255,0.2);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 18px;
    cursor: pointer;
}

/* Кнопка назад для мобильных */
.ai-chat-back {
    display: none;
    width: 36px;
    height: 36px;
    background: rgba(255,255,255,0.2);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 20px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    padding-right: 2px; /* optical adjustment for arrow */
    flex-shrink: 0;
}

.ai-chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background: #f5f5f5;
}

.ai-message {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.ai-message.user {
    flex-direction: row-reverse;
}

.ai-message .avatar {
    width: 32px;
    height: 32px;
    background: #e0e0e0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.ai-message.user .avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.ai-message .text {
    max-width: 250px;
    padding: 12px 16px;
    border-radius: 15px;
    font-size: 15px;
    line-height: 1.5;
}

.ai-message.assistant .text {
    background: white;
    border-bottom-left-radius: 4px;
}

.ai-message.user .text {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-chat-input-area {
    padding: 12px;
    background: white;
    border-top: 1px solid #eee;
}

#ai-chat-form {
    display: flex;
    gap: 8px;
}

#ai-chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #eee;
    border-radius: 20px;
    font-size: 15px;
    outline: none;
}

#ai-chat-input:focus { border-color: #667eea; }

#ai-chat-send {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
}

.ai-chat-footer {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: #f9f9f9;
    border-top: 1px solid #eee;
}

.ai-clear-history {
    padding: 5px 10px;
    background: #eee;
    border: none;
    border-radius: 12px;
    font-size: 11px;
    cursor: pointer;
}

.ai-hint { font-size: 10px; color: #999; }

/* Typing indicator */
.typing-text {
    font-size: 12px;
    color: #666;
}

.typing-dots {
    display: inline-flex;
    gap: 3px;
    margin-left: 2px;
}

.typing-dots .dot {
    font-size: 16px;
    line-height: 1;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots .dot:nth-child(1) { animation-delay: 0s; }
.typing-dots .dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dots .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* Pulse animation for avatar */
.typing .avatar {
    animation: avatarPulse 1s ease-in-out infinite;
}

@keyframes avatarPulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.4);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 8px rgba(102, 126, 234, 0);
    }
}

/* Resize handle */
.ai-chat-resize {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 16px;
    height: 16px;
    cursor: se-resize;
    background: linear-gradient(135deg, transparent 50%, rgba(102, 126, 234, 0.3) 50%);
    border-radius: 0 0 15px 0;
}

.ai-chat-resize:hover {
    background: linear-gradient(135deg, transparent 50%, rgba(102, 126, 234, 0.5) 50%);
}

@media (max-width: 768px) {
    .ai-chat-window {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: calc(100vh - 80px);
        border-radius: 20px 20px 0 0;
    }
    
    .ai-chat-container {
        bottom: 15px;
        right: 15px;
    }
    
    .ai-chat-toggle {
        padding: 16px 24px;
        font-size: 15px;
        box-shadow: 0 6px 25px rgba(102, 126, 234, 0.6);
    }
    
    .chat-label {
        display: none;
    }
    
    .ai-message .text {
        max-width: 85%;
        font-size: 15px;
        padding: 12px 16px;
    }
    
    .ai-chat-messages {
        padding: 16px;
    }
    
    #ai-chat-input {
        padding: 14px 18px;
        font-size: 16px;
    }
    
    .ai-chat-input-area {
        padding: 16px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
    
    #ai-chat-send {
        width: 48px;
        height: 48px;
    }
    
    .ai-chat-header {
        padding: 16px 20px;
    }
    
    /* Показываем кнопку назад на мобильных */
    .ai-chat-back {
        display: flex !important;
    }
    
    .ai-chat-title {
        padding-left: 0;
    }
    
    .ai-avatar {
        width: 44px;
        height: 44px;
        font-size: 24px;
    }
    
    .ai-name {
        font-size: 18px;
    }
    
    .ai-chat-close {
        width: 36px;
        height: 36px;
        font-size: 20px;
    }
    
    .ai-clear-history {
        padding: 8px 14px;
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .ai-chat-window {
        height: calc(100vh - 70px);
        border-radius: 16px 16px 0 0;
    }
    
    .ai-chat-container {
        bottom: 10px;
        right: 10px;
    }
    
    .ai-chat-toggle {
        padding: 14px 20px;
        font-size: 14px;
    }
    
    .ai-chat-header {
        padding: 14px 16px;
    }
    
    .ai-message .text {
        font-size: 14px;
        padding: 10px 14px;
    }
    
    .ai-chat-messages {
        padding: 12px;
    }
    
    #ai-chat-input {
        padding: 12px 16px;
    }
    
    .ai-chat-footer {
        padding: 10px 12px;
    }
}

/* Touch improvements for mobile */
@media (hover: none) and (pointer: coarse) {
    .ai-chat-toggle {
        min-height: 48px;
        min-width: 48px;
    }
    .ai-chat-close {
        min-width: 44px;
        min-height: 44px;
    }
    .ai-chat-back {
        min-width: 44px;
        min-height: 44px;
    }
    #ai-chat-send {
        min-width: 44px;
        min-height: 44px;
    }
    #ai-chat-input {
        min-height: 44px;
    }
    .ai-clear-history {
        padding: 8px 14px;
        font-size: 12px;
    }
}
