/* Chat Header Button */
.chat-header-btn {
    background: linear-gradient(135deg, #1e3a8a, #3b82f6);
    color: white;
    border: none;
    padding: 0 20px;
    height: 40px;
    /* Match theme toggle height */
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 6px rgba(30, 58, 138, 0.3);
    transition: all 0.3s ease;
    text-decoration: none;
    font-size: 0.9rem;
    margin-left: 0;
    /* Remove margin as parent has gap */
}

.chat-header-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(30, 58, 138, 0.4);
    background: linear-gradient(135deg, #3b82f6, #1e3a8a);
}

.chat-header-btn i {
    font-size: 1rem;
}

/* --- CHATBOT TOKENS --- */
:root {
    --chat-primary: #1e3a8a;
    /* Deep Blue */
    --chat-secondary: #f3f4f6;
    --chat-accent: #10b981;
    /* Green for Agriculture */
    --chat-text: #1f2937;
    --chat-user-bg: #e0e7ff;
    --chat-bot-bg: #ffffff;
}

/* --- TOGGLE BUTTON --- */
.chatbot-toggle {
    position: fixed;
    bottom: 25px;
    right: 25px;
    width: 60px;
    height: 60px;
    background: var(--chat-primary);
    border-radius: 50%;
    box-shadow: 0 4px 15px rgba(30, 58, 138, 0.3);
    border: none;
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chatbot-toggle:hover {
    transform: scale(1.1) rotate(5deg);
}

.chatbot-toggle i {
    font-size: 28px;
    color: white;
}

.chatbot-toggle .badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    border: 2px solid white;
}

/* --- CHAT WINDOW --- */
.chatbot-window {
    position: fixed;
    top: auto;
    /* Undo header positioning */
    bottom: 100px;
    /* Floating above button */
    right: 25px;
    width: 350px;
    height: 500px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    z-index: 999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    /* Animate from button */
    transform: scale(0);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
}

.chatbot-window.active {
    transform: scale(1);
    opacity: 1;
    pointer-events: all;
}

.voice-toggle {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    font-size: 16px;
    padding: 5px;
    transition: color 0.3s;
}

.voice-toggle:hover {
    color: white;
}

/* Header */
.chat-header {
    background: linear-gradient(135deg, var(--chat-primary), #3b82f6);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-avatar {
    width: 32px;
    height: 32px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--chat-primary);
    font-size: 18px;
}

.chat-controls button {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    font-size: 16px;
}

.chat-controls button:hover {
    color: white;
}

/* Messages Area */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f9fafb;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scroll-behavior: smooth;
}

.message {
    max-width: 80%;
    padding: 10px 15px;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
}

.message.bot {
    align-self: flex-start;
    background: var(--chat-bot-bg);
    color: var(--chat-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.message.user {
    align-self: flex-end;
    background: var(--chat-user-bg);
    color: #1e40af;
    border-bottom-right-radius: 4px;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    background: white;
    border-radius: 12px;
    width: fit-content;
    display: none;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

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

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

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-4px);
    }
}

/* Suggestions */
.chat-suggestions {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    max-height: 180px;
    border-top: 1px solid #f3f4f6;
    /* Clean scrollbar */
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

.chat-suggestions::-webkit-scrollbar {
    width: 6px;
    display: block;
}

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

.chat-suggestions::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.suggestion-chip {
    background: white;
    border: 1px solid #e5e7eb;
    padding: 8px 12px;
    border-radius: 12px;
    /* Slightly less rounded for multi-line */
    font-size: 0.85rem;
    color: var(--chat-primary);
    cursor: pointer;
    white-space: normal;
    /* Allow wrapping */
    text-align: left;
    transition: all 0.2s;
    width: fit-content;
    max-width: 100%;
}

.suggestion-chip:hover {
    background: var(--chat-primary);
    color: white;
    border-color: var(--chat-primary);
}

/* Input Area */
.chat-input-area {
    padding: 15px;
    background: white;
    border-top: 1px solid #f3f4f6;
    display: flex;
    gap: 10px;
    align-items: center;
}

.chat-input {
    flex: 1;
    border: 1px solid #e5e7eb;
    border-radius: 24px;
    padding: 10px 15px;
    outline: none;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: var(--chat-primary);
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    background: var(--chat-primary);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.chat-send-btn:hover {
    background: #1e40af;
}

/* Language Selector in Header */
.lang-select {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 0.8rem;
    padding: 2px 5px;
    border-radius: 4px;
    margin-left: auto;
    margin-right: 10px;
    cursor: pointer;
}

.lang-select option {
    background: white;
    color: #333;
}

/* Mobile Responsiveness */
@media screen and (max-width: 480px) {
    .chatbot-window {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }
}