/* SAOS AI Chat Widget Styles */

/* Chat Button */
.saos-chat-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    min-width: 110px;
    height: 50px;
    background: linear-gradient(135deg, #4A90E2 0%, #3B82F6 100%);
    border-radius: 25px;
    box-shadow: 0 4px 20px rgba(74, 144, 226, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease, z-index 0s ease 0.3s;
    z-index: 9998;
    border: none;
    outline: none;
    padding: 0 16px;
    gap: 8px;
}

/* Mobile optimizations for chat button */
@media (max-width: 768px) {
    .saos-chat-button {
        bottom: 16px;
        right: 16px;
        min-width: 100px;
        height: 46px;
        font-size: 13px;
        z-index: 9999; /* Higher z-index on mobile */
    }
}

.saos-chat-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 30px rgba(74, 144, 226, 0.6);
}

.saos-chat-button.active {
    transform: rotate(90deg) translateY(-15px) scale(0.9) !important;
    transform-origin: center !important;
    right: 50px !important; /* Смещаем влево чтобы не уходило за экран */
    bottom: 30px !important; /* Оптимальная высота - не перекрывает интерфейс */
    opacity: 0.8 !important; /* Плавное затухание */
    z-index: 9997 !important; /* Под окном чата с задержкой */
    transition: all 0.3s ease 0.1s !important; /* Задержка для z-index эффекта */
}

/* Chat Button Text */
.saos-chat-text {
    color: white;
    font-weight: 600;
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* BETA Badge for Chat Button */
.saos-beta-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #ef4444;
    color: white;
    font-size: 9px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Badge for unread messages */
.saos-chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: white;
    font-size: 12px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

/* Chat Window */
.saos-chat-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 350px;
    height: 500px;
    background: #111111;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s ease;
    visibility: hidden;
    z-index: 9999;
    overflow: hidden;
}

.saos-chat-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    visibility: visible;
}

/* Chat Header */
.saos-chat-header {
    background: linear-gradient(135deg, #4A90E2 0%, #3B82F6 100%);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white;
}

.saos-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.saos-chat-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 18px;
}

.saos-chat-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.saos-chat-subtitle {
    font-size: 12px;
    opacity: 0.9;
    margin: 0;
}

/* Header Title Area with Badge and Help */
.saos-chat-header-title-area {
    display: flex;
    align-items: center;
    gap: 8px;
}

.saos-header-beta-badge {
    background: #ef4444;
    color: white;
    font-size: 9px;
    font-weight: 700;
    padding: 2px 5px;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.4);
}

.saos-help-icon {
    position: relative;
    width: 18px;
    height: 18px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    cursor: help;
    transition: all 0.2s ease;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.saos-help-icon:hover {
    background: rgba(255, 255, 255, 0.4);
}

.saos-tooltip {
    position: fixed;
    top: 40px;
    right: 40px;
    width: 240px;
    background: #1e1e2e;
    color: #ffffff;
    text-align: center;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 11px;
    line-height: 1.4;
    z-index: 999999;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    display: none;
}

.saos-help-icon:hover .saos-tooltip {
    display: block;
}


.saos-chat-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.saos-chat-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.saos-chat-close svg {
    width: 20px;
    height: 20px;
}

/* Chat Messages */
.saos-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.saos-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.saos-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.saos-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.saos-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Individual Messages */
.saos-message {
    display: flex;
    gap: 12px;
    animation: messageSlide 0.3s ease;
}

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

.saos-message.user {
    flex-direction: row-reverse;
}

.saos-message-avatar {
    width: 32px;
    height: 32px;
    background: rgba(74, 144, 226, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
    font-weight: bold;
}

.saos-message.user .saos-message-avatar {
    background: rgba(245, 158, 11, 0.2);
}

.saos-message-content {
    max-width: 75%;
    background: rgba(255, 255, 255, 0.05);
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #e5e5e5;
    font-size: 14px;
    line-height: 1.5;
}

.saos-message.user .saos-message-content {
    background: rgba(245, 158, 11, 0.1);
    border-color: rgba(245, 158, 11, 0.3);
}

/* Typing Indicator */
.saos-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 16px;
}

.saos-typing-dot {
    width: 8px;
    height: 8px;
    background: #4A90E2;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.saos-typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.saos-typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Chat Input */
.saos-chat-input-container {
    padding: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.3);
}

.saos-chat-input-form {
    display: flex;
    gap: 8px;
}

.saos-chat-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    padding: 10px 16px;
    color: white;
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease;
}

.saos-chat-input:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(74, 144, 226, 0.5);
}

.saos-chat-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.saos-chat-send {
    background: linear-gradient(135deg, #4A90E2 0%, #3B82F6 100%);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.saos-chat-send:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.4);
}

.saos-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.saos-chat-send svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* Quick Actions */
.saos-quick-actions {
    padding: 8px 16px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
}

.saos-quick-actions::-webkit-scrollbar {
    display: none;
}

.saos-quick-action {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 6px 12px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.saos-quick-action:hover {
    background: rgba(74, 144, 226, 0.2);
    border-color: rgba(74, 144, 226, 0.5);
    color: white;
}

/* Error Message */
.saos-error-message {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #f87171;
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
    margin: 16px;
    text-align: center;
}

/* Rate Limit Warning */
.saos-rate-limit-warning {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: #fbbf24;
    padding: 8px 16px;
    font-size: 12px;
    text-align: center;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .saos-chat-window {
        width: calc(100vw - 32px);
        height: 60vh;
        bottom: 80px;
        right: 16px;
        left: 16px;
        max-width: 400px;
    }
}

@media (max-width: 480px) {
    .saos-chat-window {
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100vh;
        border-radius: 0;
        max-height: 100vh;
    }
    
    .saos-chat-button {
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
    }
    
    .saos-chat-button.active {
        transform: translateX(-50%) rotate(90deg) translateY(-20px) scale(0.9) !important;
        transform-origin: center !important;
        bottom: 35px !important; /* Оптимальная высота для мобильных */
        opacity: 0.8 !important; /* Плавное затухание */
        z-index: 9998 !important; /* Под окном чата с задержкой */
        transition: all 0.3s ease 0.1s !important; /* Задержка для z-index эффекта */
    }
}
