/* Core Chat Window and Overlay */
#kisan-chat-window {
    /* FIX 1: Reverting back to fixed and positioning for desktop */
    position: fixed;
    bottom: 20px;
    right: 20px;
    
    width: 350px; /* Desktop width */
    height: 500px;
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    /* Increased z-index for the chat window as well to ensure it's on top */
    z-index: 10000; 
    transition: all 0.3s ease-in-out;
}

#kisan-chat-window.kisan-chat-hidden {
    transform: scale(0.9);
    opacity: 0;
    pointer-events: none;
}

/* * ========================================
 * MOBILE RESPONSIVENESS FIXES (CRITICAL)
 * ========================================
 */
@media (max-width: 600px) {
    #kisan-chat-window {
        /* Reset full screen properties */
        width: 95%; /* Constrain width */
        max-width: 95%;
        height: auto;
        
        /* FIX 2: Increase max-height and add margin-top to push it down from the phone status bar */
        max-height: 90vh; 
        margin-top: 25px; /* Added margin to clear the status bar/app header */
        
        /* Position relative to the bottom */
        bottom: 10px; 
        right: 2.5%; /* Center it horizontally */
        left: unset; 
        
        border-radius: 12px; /* Restore border radius for floating look */
    }
}


/* Header Styling */
#kisan-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    
    /* FIX 3: Ensure header has space on the left for the floating close button */
    padding: 10px 15px 10px 45px; 
    
    background-color: #4CAF50; /* Primary green */
    color: white;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    
    position: sticky; 
    top: 0; 
    z-index: 10; 
}

/* Styles for the new control group (Lang selector) */
.kisan-header-controls {
    display: flex;
    align-items: center;
}

/* Language Selector Styling */
#kisan-lang-select {
    padding: 5px;
    border-radius: 5px;
    border: 1px solid white;
    background-color: transparent;
    color: white;
    margin-right: 10px;
    font-size: 14px;
    cursor: pointer;
}

#kisan-lang-select option {
    color: #000; /* Ensure options text is visible */
    background-color: #fff;
}


/* Close Button Styling */
#kisan-chat-close {
    /* FIX 4: Styling and positioning for the top-left floating button */
    background: #4CAF50; 
    border: 2px solid white;
    color: white;
    font-size: 16px;
    cursor: pointer;
    
    position: absolute; 
    top: -10px; /* Moves it slightly up and out of the chat window frame */
    left: 10px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    z-index: 1001; /* Ensure it's above the chat window and the header */
    
    /* Centering the X inside the circle */
    display: flex; 
    align-items: center;
    justify-content: center;
    
    /* Clear previous styles */
    margin-left: 0; 
}

/* Chat Body (Messages) */
#kisan-chat-body {
    flex-grow: 1;
    padding: 15px;
    overflow-y: auto; 
    background-color: #f7f7f7;
}

/* Input Area Styling */
#kisan-chat-input-area {
    display: flex;
    padding: 15px;
    border-top: 1px solid #ddd;
    background-color: #fff;
}

#kisan-chat-input {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 20px;
    margin-right: 10px;
    font-size: 14px;
}

#kisan-chat-send, #kisan-chat-mic { /* Unified styling for send and mic buttons */
    background-color: #4CAF50;
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    margin-left: 5px; /* Spacing between send and mic */
}

#kisan-chat-send:hover, #kisan-chat-mic:hover {
    background-color: #388E3C;
}

/* ------------------------------------ */
/* 💬 Chat Message Styles (Requirement 5) */
/* ------------------------------------ */

.message {
    padding: 10px 15px;
    margin-bottom: 10px;
    max-width: 80%;
    border-radius: 18px;
    line-height: 1.4;
    word-wrap: break-word;
}

.message .chat-name { /* Requirement 4: Name tag */
    display: block;
    font-weight: bold;
    font-size: 0.85em;
    margin-bottom: 3px;
    opacity: 0.75;
}

/* User Messages */
.message.user {
    background-color: #DCF8C6; /* Light Green */
    color: #000;
    margin-left: auto; /* Aligns to the right */
    border-bottom-right-radius: 4px; /* Smoother corner near sender */
}
.message.user .chat-name {
    text-align: right;
    color: #388E3C; /* Darker green for user name */
}


/* Assistant Messages */
.message.assistant {
    background-color: #E5E5EA; /* Light Gray/Off-white */
    color: #000;
    margin-right: auto; /* Aligns to the left */
    border-bottom-left-radius: 4px; /* Smoother corner near assistant */
}
.message.assistant .chat-name {
    text-align: left;
    color: #4CAF50; /* Primary green for assistant name */
}

/* Typing Indicator Styling */
#kisan-typing-indicator {
    background-color: #f0f0f0;
    color: #555;
    font-style: italic;
    animation: pulse 1.5s infinite;
}

/* ------------------------------------ */
/* ⬆️ Floating Button Styles (Requirement 1) */
/* ------------------------------------ */

#kisan-ai-fab {
    /* ⭐ FINAL FIX: Use !important to force the correct fixed position and placement */
    position: fixed !important; 
    bottom: 20px !important;
    right: 20px !important;
    left: unset !important; /* Crucial to ensure it leaves the left side */
    
    width: max-content; 
    max-width: 80vw; 
    z-index: 99999 !important; /* Highest possible z-index */
    
    background-color: #4CAF50;
    color: white;
    padding: 10px 15px;
    border-radius: 30px; /* Pill shape */
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    
    display: flex;
    align-items: center;
    transition: all 0.3s;
    animation: glowing-pulse 2s infinite; /* Apply glowing effect */
    position: relative; 
}

#kisan-ai-fab:hover {
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.4);
}

/* New style for the white circle around the face icon */
.kisan-fab-face {
    font-size: 24px;
    margin-right: 10px;
    line-height: 1;
    
    /* Styling the White Circle */
    background-color: white; /* White background */
    color: #4CAF50; /* Green icon color */
    padding: 5px;
    border-radius: 50%;
    width: 24px; /* Ensure circular shape with padding */
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kisan-fab-text {
    font-weight: bold;
    font-size: 16px;
    white-space: nowrap;
}

/* Glowing Animation */
@keyframes glowing-pulse {
    0% { box-shadow: 0 0 5px #4CAF50, 0 0 10px #4CAF50; }
    50% { box-shadow: 0 0 10px #81C784, 0 0 20px #81C784; }
    100% { box-shadow: 0 0 5px #4CAF50, 0 0 10px #4CAF50; }
}

/* Mobile Responsive Styles for "Ask" Text */
@media (max-width: 450px) {
    
    /* 1. Add "Ask" text floating above the button */
    #kisan-ai-fab::before {
        content: "Ask";
        position: absolute;
        top: -20px; /* Adjust position above the button */
        right: 15px; 
        font-size: 14px;
        font-weight: bold;
        color: #4CAF50; /* Green text color */
        background-color: white;
        padding: 2px 5px;
        border-radius: 5px;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        z-index: 99; 
        white-space: nowrap;
    }
    
    /* 2. Ensure mobile button width is properly constrained */
    #kisan-ai-fab {
        padding: 10px 15px; /* Revert padding for pill shape */
        width: max-content; /* Ensure max-content is used here too */
        /* Relying on the global !important right: 20px; and fixed position */
        height: auto;
        border-radius: 30px; 
    }
    
    /* 3. Hide the long descriptive text */
    .kisan-fab-text {
        display: none; 
    }
    
    /* 4. Ensure the face icon is styled correctly for mobile */
    .kisan-fab-face {
        margin: 0; /* Clear margin when text is hidden */
    }
}