:root {
    --ai-chatbot-primary-color: #2c3e50; /* Deep blue/grey */
    --ai-chatbot-accent-color: #3498db;  /* Bright blue */
    --ai-chatbot-widget-bg: #ffffff;
    --ai-chatbot-messages-bg: #f9f9f9;
    --ai-chatbot-user-bg: #3498db;
    --ai-chatbot-user-text: #ffffff;
    --ai-chatbot-ai-bg: #ecf0f1;
    --ai-chatbot-ai-text: #333333;
    --ai-chatbot-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Chat Toggle Button */
#chatToggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background-color: var(--ai-chatbot-primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease-in-out, background-color 0.2s;
}

#chatToggle:hover {
    transform: scale(1.1);
    background-color: var(--ai-chatbot-accent-color);
}

#chatToggle.left {
    right: auto;
    left: 20px;
}

#chatToggle.hidden {
    display: none;
}

/* Chat Window */
.chat-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 370px;
    height: 600px;
    max-height: calc(100vh - 110px);
    background: var(--ai-chatbot-widget-bg);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    z-index: 10000;
    overflow: hidden;
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
    font-family: var(--ai-chatbot-font-family);
}

.chat-window.left {
    right: auto;
    left: 20px;
}

.chat-window.hidden {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

/* Chat Header */
.chat-header {
    background: var(--ai-chatbot-primary-color);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}

.chat-title {
    font-weight: 600;
    font-size: 1.1rem;
}

.chat-controls {
    display: flex;
    gap: 10px;
}

.chat-control-btn {
    background: none;
    border: none;
    color: white;
    opacity: 0.8;
    cursor: pointer;
    font-size: 18px;
    padding: 5px;
    transition: opacity 0.2s;
}

.chat-control-btn:hover {
    opacity: 1;
}

/* Chat Messages Area */
.chat-messages {
    flex: 1;
    min-height: 0;
    padding: 20px;
    overflow-y: scroll;
    overflow-x: hidden;
    background: var(--ai-chatbot-messages-bg);
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
    position: relative;
    isolation: isolate;
}

.chat-message {
    max-width: 85%;
    padding: 10px 15px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-message.ai {
    align-self: flex-start;
    background: var(--ai-chatbot-ai-bg);
    color: var(--ai-chatbot-ai-text);
    border-bottom-left-radius: 4px;
}

.chat-message.ai * {
    color: var(--ai-chatbot-ai-text) !important;
}

/* AI message formatting */
.chat-message.ai p {
    margin: 0 0 8px 0;
}

.chat-message.ai p:last-child {
    margin-bottom: 0;
}

.chat-message.ai ul {
    margin: 8px 0;
    padding-left: 20px;
    list-style: none;
}

.chat-message.ai ul li {
    margin: 6px 0;
    padding-left: 0;
    position: relative;
    line-height: 1.6;
}

.chat-message.ai ul li::before {
    content: '•';
    position: absolute;
    left: -15px;
    color: var(--ai-chatbot-accent-color);
    font-weight: bold;
}

.chat-message.ai h1,
.chat-message.ai h2,
.chat-message.ai h3,
.chat-message.ai h4 {
    margin: 12px 0 8px 0;
    font-weight: 600;
    line-height: 1.3;
}

.chat-message.ai h1 { font-size: 1.4em; }
.chat-message.ai h2 { font-size: 1.3em; }
.chat-message.ai h3 { font-size: 1.2em; }
.chat-message.ai h4 { font-size: 1.1em; }

.chat-message.ai strong {
    font-weight: 600;
}

.chat-message.ai em {
    font-style: italic;
}

/* Streaming cursor */
.streaming-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background-color: var(--ai-chatbot-accent-color);
    margin-left: 2px;
    animation: blink-cursor 1s infinite;
    vertical-align: text-bottom;
}

@keyframes blink-cursor {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

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

/* Chat Input Area */
.chat-input-area {
    padding: 15px;
    background: var(--ai-chatbot-widget-bg);
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 10px;
}

#chatInput {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid #ccc;
    border-radius: 20px;
    outline: none;
    font-size: 1rem;
    transition: border-color 0.2s;
}

#chatInput:focus {
    border-color: var(--ai-chatbot-accent-color);
}

.chat-send-btn {
    background: var(--ai-chatbot-accent-color);
    color: white;
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    transition: background-color 0.2s;
}

.chat-send-btn:hover {
    background-color: var(--ai-chatbot-primary-color);
}

/* Suggested Questions */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 0;
}

.suggestion-btn {
    background: none;
    border: 1px solid var(--ai-chatbot-accent-color);
    color: var(--ai-chatbot-accent-color);
    padding: 8px 12px;
    border-radius: 16px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.suggestion-btn:hover {
    background: var(--ai-chatbot-accent-color);
    color: white;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 10px 15px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #ccc;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

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

    #chatToggle {
        bottom: 10px;
        right: 10px;
    }
}
