:root {
    --celo-primary: #9eeb47;
    --celo-dark-bg: #152215;
    --chat-header-bg: #2c3e2c;
    --chat-bg: #ffffff;
    --bot-msg-bg: #f1f1f1;
    --user-msg-bg: #e2f5cb;
    --input-bg: #f9f9f9;
    --border-color: #e0e0e0;
    --text-dark: #333;
    --text-light: #fff;
    --text-secondary: #666;
    --send-btn-gradient: linear-gradient(135deg, #86efac, #69d18c);
    --system-msg-bg: #e9ecef;
    --system-msg-text: #6c757d;
    --danger-color: #dc3545;
}

/* --- Floating Chat Button --- */
#ai-chat-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background-color: var(--celo-primary);
    color: var(--celo-dark-bg);
    border: none;
    border-radius: 50%;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease-in-out, box-shadow 0.2s;
}

#ai-chat-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

/* --- Main Chat Widget Container --- */
#ai-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 90%;
    max-width: 380px;
    height: 70vh;
    max-height: 600px;
    background: var(--chat-bg);
    border-radius: 15px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1000;
    transition: opacity 0.3s, transform 0.3s;
    transform-origin: bottom right;
}

#ai-chat-widget.hidden {
    opacity: 0;
    transform: scale(0.5);
    pointer-events: none;
}

/* --- Chat Header --- */
.chat-header {
    background-color: var(--chat-header-bg);
    color: var(--text-light);
    padding: 12px 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    gap: 10px;
}

.chat-header-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: bold;
}

.header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--celo-primary);
    color: var(--celo-dark-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2em;
    font-weight: bold;
    flex-shrink: 0;
}

.header-agent-info { display: flex; flex-direction: column; }
#header-agent-status { font-size: 0.8em; font-weight: normal; }
#header-agent-status.online { color: #28a745; }
#header-agent-status.offline { color: #6c757d; }
#header-agent-status.reconnecting { color: #ffc107; }

.chat-header-controls { display: flex; align-items: center; gap: 5px; }
.chat-header-controls button {
    background: none; border: none; color: #ccc; font-size: 1.2rem;
    cursor: pointer; padding: 5px; transition: color 0.2s, transform 0.2s;
}
.chat-header-controls button:hover { color: #fff; transform: scale(1.1); }
#close-chat-btn { font-size: 1.8rem; font-weight: 300; }

/* --- Messages Area --- */
.chat-messages {
    flex-grow: 1; padding: 15px; overflow-y: auto;
    display: flex; flex-direction: column; gap: 12px;
}

.chat-message {
    display: flex; align-items: flex-end; gap: 10px;
    max-width: 85%; opacity: 0; transform: translateY(10px);
    animation: message-fade-in 0.3s forwards;
}
@keyframes message-fade-in { to { opacity: 1; transform: translateY(0); } }

.chat-message .message-content {
    padding: 10px 15px; border-radius: 18px; line-height: 1.5; word-wrap: break-word;
}
.bot-message { align-self: flex-start; }
.bot-message .message-content {
    background: var(--bot-msg-bg); color: var(--text-dark); border-bottom-left-radius: 4px;
}
.user-message { align-self: flex-end; flex-direction: row-reverse; }
.user-message .message-content {
    background: var(--user-msg-bg); color: var(--text-dark); border-bottom-right-radius: 4px;
}
.msg-avatar {
    width: 30px; height: 30px; border-radius: 50%; background-color: var(--celo-primary);
    color: var(--celo-dark-bg); display: flex; align-items: center; justify-content: center;
    font-size: 0.9em; font-weight: bold; flex-shrink: 0;
}
.system-message {
    align-self: center; background: var(--system-msg-bg); color: var(--system-msg-text);
    font-size: 0.8em; padding: 5px 12px; border-radius: 15px; max-width: 100%;
}
.chat-message p { margin: 0; }
.message-content img.chat-image-preview, .user-message img.chat-image-preview {
    max-width: 200px; max-height: 150px; border-radius: 10px; cursor: pointer;
    object-fit: cover; transition: transform 0.2s;
}
.message-content img.chat-image-preview:hover { transform: scale(1.05); }
.message-content a.chat-file-link {
    display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px;
    background-color: rgba(0,0,0,0.05); border-radius: 8px; color: inherit;
    text-decoration: none; transition: background-color 0.2s;
}
.message-content a.chat-file-link:hover { background-color: rgba(0,0,0,0.1); }

/* --- Quick Replies --- */
.chat-quick-replies {
    padding: 10px 15px; border-top: 1px solid var(--border-color);
    display: flex; flex-wrap: wrap; gap: 8px;
}
.quick-reply-btn {
    background: none; border: 1px solid var(--celo-primary); color: var(--celo-primary);
    padding: 6px 12px; border-radius: 20px; cursor: pointer; font-size: 0.85em; transition: all 0.2s;
}
.quick-reply-btn:hover { background-color: var(--celo-primary); color: var(--celo-dark-bg); }

/* --- Input Area --- */
.chat-input-area {
    position: relative; padding: 10px; background-color: var(--input-bg);
    border-top: 1px solid var(--border-color);
}
emoji-picker {
    position: absolute; bottom: 65px; right: 10px; z-index: 1001;
}
emoji-picker.hidden { display: none; }
.chat-form { display: flex; align-items: center; gap: 8px; }

/* Live Chat Action Buttons */
.live-chat-actions {
    display: none; /* Hide these buttons by default */
    align-items: center;
}
#ai-chat-widget.live-chat-active .live-chat-actions {
    display: flex; /* Show them when the widget has the 'live-chat-active' class */
}
.live-chat-actions button, .file-upload-btn {
    background: none; border: none; font-size: 1.3em; color: var(--text-secondary);
    cursor: pointer; padding: 8px; transition: color 0.2s; position: relative;
}
.live-chat-actions button:hover, .file-upload-btn:hover { color: var(--celo-primary); }
.end-chat-btn { color: var(--danger-color) !important; }
.end-chat-btn:hover { color: #a52834 !important; }

.file-count {
    position: absolute; top: 0; right: 0; background-color: var(--celo-primary);
    color: var(--celo-dark-bg); font-size: 0.7em; font-weight: bold;
    width: 16px; height: 16px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
}
#chat-input {
    flex-grow: 1; border: none; background: transparent; padding: 10px;
    font-size: 1rem; outline: none; color: var(--text-dark);
}
.send-btn {
    background: var(--send-btn-gradient); border: none; color: white;
    width: 40px; height: 40px; border-radius: 50%; font-size: 1.2em; cursor: pointer;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    transition: transform 0.2s, box-shadow 0.2s;
}
.send-btn:hover { transform: scale(1.1); box-shadow: 0 2px 8px rgba(0,0,0,0.2); }

/* --- Live Chat Registration Form --- */
#live-chat-registration-form {
    display: flex; flex-direction: column; padding: 10px;
    gap: 8px; background-color: #e9f5e9;
}
#live-chat-registration-form input,
#live-chat-registration-form textarea {
    padding: 10px; border: 1px solid #ccc; border-radius: 5px;
    font-size: 0.95rem; font-family: inherit;
}
#live-chat-registration-form textarea { resize: vertical; min-height: 60px; }
#live-chat-registration-form button.submit-btn {
    background-color: var(--celo-primary); color: var(--celo-dark-bg);
    border: none; padding: 12px; border-radius: 5px; font-weight: bold;
    cursor: pointer; transition: background-color 0.2s;
}
#live-chat-registration-form button.submit-btn:hover { background-color: #88d434; }
#live-chat-registration-form button.submit-btn:disabled { background-color: #ccc; cursor: not-allowed; }

/* --- Responsive Adjustments for Mobile --- */
@media (max-width: 768px) {
    #ai-chat-widget {
        bottom: 90px; right: 10px; left: 10px; width: auto;
        max-width: none; height: calc(100vh - 110px); max-height: none;
    }
}
#header-agent-status {
    font-size: 0.8em;
    padding-left: 15px;
    position: relative;
}

#header-agent-status::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #ccc; /* Default grey */
}

#header-agent-status.online::before {
    background-color: #28a745; /* Green */
}

#header-agent-status.offline::before {
    background-color: #dc3545; /* Red */
}

#header-agent-status.reconnecting::before {
    background-color: #fd7e14; /* Orange */
}