/* ------------------------------------------------------------------ */
/* 1. Chatbot Container and Toggle Button Styles */
/* ------------------------------------------------------------------ */

.chatbot-container {
    position: fixed;
    bottom: 120px; /* Lifted higher off the page edge */
    right: 20px;
    z-index: 1000;
    font-family: Arial, sans-serif;
}

.chatbot-toggle {
    background-color: #4CAF50; /* Shamba Direct Green */
    color: white;
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    font-size: 2.5em;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease, background-color 0.2s;
}

.chatbot-toggle:hover {
    transform: scale(1.05);
    background-color: #45a049;
}

/* Ensure Boxicons or other icons are styled correctly */
.chatbot-toggle .bxr {
    font-size: 1.2em;
}

/* ------------------------------------------------------------------ */
/* 2. Chatbot Window (Panel) Styles */
/* ------------------------------------------------------------------ */

.chatbot-window {
    background-color: #f0f2f5; /* Light grey background */
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    width: min(350px, 90vw); /* Desktop/Large screen constrained size */
    height: min(450px, 70vh);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: absolute;
    bottom: calc(100% + 20px); /* Position 20px above the toggle button */
    right: 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px); /* Off-screen preparation for animation */
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    z-index: 1001;
}

.chatbot-window.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0); /* Final state: moves into view */
}

/* ------------------------------------------------------------------ */
/* 3. Internal Component Styles */
/* ------------------------------------------------------------------ */

.chatbot-header {
    background-color: #4CAF50;
    color: white;
    padding: 15px;
    font-size: 1.1em;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
}

.close-chat {
    cursor: pointer;
    font-size: 1.2em;
    opacity: 0.8;
}

.close-chat:hover {
    opacity: 1;
}

.chatbot-messages {
    flex-grow: 1;
    padding: 15px;
    overflow-y: auto;
    background-color: #e5ddd5; /* WhatsApp-like chat background */
    border-bottom: 1px solid #ddd;
}

/* Individual Message Styles */
.user-msg, .bot-msg {
    max-width: 80%;
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    line-height: 1.4;
    word-wrap: break-word;
}

.user-msg {
    background-color: #dcf8c6; /* Light green for user messages */
    align-self: flex-end;
    margin-left: auto;
    color: #333;
}

.bot-msg {
    background-color: #ffffff; /* White for bot messages */
    align-self: flex-start;
    margin-right: auto;
    color: #333;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* Typing Indicator */
#typingIndicator {
    font-style: italic;
    color: #666;
    animation: fadeinout 1.5s ease-in-out infinite;
    padding: 10px 12px;
    margin-bottom: 8px;
}

.hidden {
    display: none !important;
}

/* Chat Form (Input Area) */
#chatForm {
    display: flex;
    padding: 10px 15px;
    background-color: #f0f2f5;
    border-top: 1px solid #ddd;
}

#chatInput {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 20px;
    margin-right: 10px;
    font-size: 0.9em;
    outline: none;
    transition: border-color 0.2s ease;
}

#chatInput:focus {
    border-color: #4CAF50;
}

#chatForm button[type="submit"] {
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 20px;
    padding: 10px 15px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background-color 0.2s ease;
    white-space: nowrap;
}

#chatForm button[type="submit"]:hover {
    background-color: #45a049;
}

/* Chatbot Footer */
.chatbot-footer {
    background-color: #f0f2f5;
    padding: 8px 15px;
    font-size: 0.75em;
    color: #777;
    text-align: center;
    border-top: 1px solid #ddd;
}

/* Optional: Animation for typing indicator */
@keyframes fadeinout {
    0% { opacity: 0.5; }
    50% { opacity: 1; }
    100% { opacity: 0.5; }
}

/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
/* 4. Responsive Adjustments (Final Mobile Fix) */
/* ------------------------------------------------------------------ */

/* Small Screens (up to 480px - mobile phones) */
@media (max-width: 480px) {
    /* Step 1: Reposition the main container (the toggle button) */
    .chatbot-container {
        /* Keep it higher */
        bottom: 100px;
        right: 15px;
        left: auto;
        transform: none; 
    }
    
    /* Step 2: STRICTLY Constrain and Position the Chat Window */
    .chatbot-window {
        /* Use absolute fixed sizes (max 300px width, 400px height)
           This prevents it from consuming 60vh or 90vw on larger phones. */
        width: 300px; 
        height: 400px;
        
        /* Ensure it remains positioned relative to the container (bottom-right) */
        position: absolute;
        top: auto; 
        left: auto;
        
        /* This is the key that makes the panel "come up" 
           This value (100% + 15px) sits it 15px above the 60px toggle button. */
        bottom: calc(100% + 15px); 
        right: 0;
        
        /* Reset transform properties */
        transform: translateY(10px); 
        margin: 0;
    }
    
    .chatbot-window.active {
        transform: translateY(0); 
    }
    
    /* Optional: Shrink the toggle button slightly for tiny screens */
    .chatbot-toggle {
        width: 50px;
        height: 50px;
        font-size: 2em;
    }
}