/* Chat Widget Core Styles */
#chat-widget * {
    box-sizing: border-box;
    font-family: 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

#chat-widget {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 70vh;
    background: white;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -5px 25px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 9999;
    border: 2px solid #005baa;
    border-bottom: none;
}

#chat-widget.active {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
    border-radius: 0;
}

.chat-header {
    background: #005baa;
    color: white;
    padding: 12px 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    z-index: 1;
    transition: all 0.3s ease;
}

.chat-header h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 5px;
    line-height: 1;
}

#chat-messages {
    flex: 1;
    padding: 10px;
    overflow-y: auto;
    background: #f5f5f5;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    transition: all 0.3s ease;
}

.bot-message {
    background: white;
    padding: 8px 12px;
    border-radius: 18px 18px 18px 0;
    margin-bottom: 8px;
    max-width: 90%;
    display: inline-block;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    font-size: 14px;
    line-height: 1.4;
    color: #333;
    border: 1px solid #e0e0e0;
    animation: fadeIn 0.3s ease;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 10px 0;
}

.option-btn {
    background: #005baa;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 18px;
    cursor: pointer;
    font-size: 14px;
    text-align: left;
    transition: background 0.2s;
    width: 100%;
}

.option-btn:hover {
    background: #003d7a;
}

.back-btn {
    background: #6c757d !important;
}

.back-btn:hover {
    background: #5a6268 !important;
}

.chat-input-container {
    padding: 10px;
    background: white;
    border-top: 1px solid #eee;
    display: none;
    position: relative;
    transition: all 0.3s ease;
}

#user-input {
    width: calc(100% - 50px);
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 20px;
    outline: none;
    font-size: 14px;
    -webkit-appearance: none;
    transition: all 0.3s ease;
}

#send-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: #005baa;
    color: white;
    border-radius: 50%;
    margin-left: 5px;
    cursor: pointer;
    font-size: 16px;
    position: absolute;
    right: 10px;
    top: 10px;
    transition: all 0.3s ease;
}

#send-btn:hover {
    background: #003d7a;
}

#chat-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: #005baa;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    z-index: 10000;
    border: none;
    transition: all 0.3s ease;
}

#chat-toggle.hidden {
    display: none;
}

#chat-toggle:hover {
    background: #003d7a;
    transform: scale(1.05);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.mini-dialog {
    position: fixed;
    bottom: 80px;
    left: 10px;
    right: 10px;
    width: calc(100% - 20px);
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    padding: 15px;
    border: 2px solid #005baa;
    z-index: 10001;
    display: none;
    flex-direction: column;
    animation: slideIn 0.3s ease;
}

.mini-dialog-close {
    position: absolute;
    top: 5px;
    right: 5px;
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #666;
    padding: 5px;
}

.mini-dialog-content {
    padding: 10px 0;
    font-size: 14px;
    line-height: 1.4;
}

.mini-dialog-footer {
    margin-top: 10px;
}

.mini-dialog-btn {
    background: #005baa;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 18px;
    cursor: pointer;
    font-size: 14px;
    width: 100%;
    transition: background 0.2s;
}

.mini-dialog-btn:hover {
    background: #003d7a;
}

@keyframes slideIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.error-message {
    color: #ff4444;
    margin: 10px 0;
    text-align: center;
    font-size: 14px;
    animation: fadeIn 0.3s ease-in-out;
}

/* Desktop styles */
@media (min-width: 768px) {
    #chat-widget {
        bottom: 20px;
        right: 20px;
        left: auto;
        width: 350px;
        height: 500px;
        max-height: calc(100vh - 40px);
        border-radius: 12px;
        border-bottom: 2px solid #005baa;
    }
    
    #chat-widget.active {
        border-radius: 12px;
    }
    
    .mini-dialog {
        right: 20px;
        left: auto;
        width: 300px;
        bottom: 90px;
    }
    
    .chat-header {
        padding: 15px;
    }
    
    .bot-message {
        max-width: 80%;
        padding: 10px 15px;
    }
    
    #chat-messages {
        padding: 15px;
    }
}

/* Mobile styles with keyboard adjustments - UPDATED */
@media (max-width: 767px) {
    #chat-widget {
        width: 90%;
        left: 0;
        right: auto;
        border-radius: 12px 12px 0 0;
        transition: all 0.3s ease;
        max-width: 100%;
        margin: 0;
        height: 45vh;
    }
    
    #chat-widget.keyboard-visible {
        height: 50vh !important;
        width: 60% !important;
        left: 50% !important;
        transform: translate(-50%, 0) !important;
        border-radius: 12px 12px 0 0 !important;
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
        border: 2px solid #005baa;
    }
    
    #chat-widget.keyboard-visible .chat-header {
        display: flex;
        border-radius: 10px 10px 0 0;
        padding: 8px 10px;
        font-size: 14px;
    }
    
    #chat-widget.keyboard-visible #chat-messages {
        padding: 8px;
        border-radius: 0;
    }
    
    #chat-widget.keyboard-visible .chat-input-container {
        padding: 8px;
        border-top: 1px solid #eee;
    }
    
    #chat-widget.keyboard-visible #user-input {
        width: calc(100% - 40px);
        padding: 8px 12px;
        font-size: 14px;
    }
    
    #chat-widget.keyboard-visible #send-btn {
        width: 34px;
        height: 34px;
        font-size: 14px;
        right: 8px;
        top: 8px;
    }
    
    /* Адаптация для очень маленьких экранов */
    @media (max-width: 480px) {
        #chat-widget.keyboard-visible {
            width: 85% !important;
        }
        
        #chat-widget.keyboard-visible .chat-header h3 {
            font-size: 14px;
        }
        
        .bot-message {
            font-size: 15px;
            padding: 6px 10px;
        }
        
        .option-btn {
            padding: 8px 12px;
            font-size: 15px;
        }
    }
}

/* Дополнительные мобильные оптимизации */
@media (max-width: 400px) {
    #chat-widget.keyboard-visible {
        width: 90% !important;
    }
    
    #chat-widget.keyboard-visible #user-input {
        font-size: 13px;
    }
    
    .mini-dialog {
        width: calc(100% - 30px);
        left: 15px;
        right: 15px;
    }
}