/* CSS Variables */
:root {
    --chatbot-primary-color: #007bff;
    --chatbot-text-dark: #2c2c2e;
    --chatbot-text-light: #ffffff;
    --chatbot-bg-light: #f9f9f9;
    --chatbot-border: #e0e0e0;
    --chatbot-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    --chatbot-shadow-hover: 0 6px 24px rgba(0, 0, 0, 0.25);
}

/* Container */
#chatbot-widget-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Chat Bubble Button */
#chatbot-open-btn {
    width: 60px;
    height: 60px;
    background-color: var(--chatbot-primary-color);
    color: var(--chatbot-text-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--chatbot-shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: none;
    outline: none;
}

#chatbot-open-btn:hover,
#chatbot-open-btn:focus {
    transform: scale(1.1);
    box-shadow: var(--chatbot-shadow-hover);
}

#chatbot-open-btn:focus {
    outline: 2px solid var(--chatbot-primary-color);
    outline-offset: 2px;
}

#chatbot-open-btn svg {
    width: 28px;
    height: 28px;
}

/* Chat Window */
#chatbot-window {
    display: none;
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 120px);
    flex-direction: column;
    border-radius: 16px;
    background: var(--chatbot-text-light);
    box-shadow: var(--chatbot-shadow);
    overflow: hidden;
}

/* Animations */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes slideOut {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
}

.chatbot-slide-in {
    animation: slideIn 0.3s ease forwards;
}

.chatbot-slide-out {
    animation: slideOut 0.3s ease forwards;
}

/* Header */
#chatbot-header {
    background: var(--chatbot-primary-color);
    color: var(--chatbot-text-light);
    padding: 1rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#chatbot-header h2 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

#chatbot-close-btn {
    background: none;
    border: none;
    color: var(--chatbot-text-light);
    font-size: 1.8rem;
    cursor: pointer;
    opacity: 0.9;
    transition: opacity 0.2s ease;
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#chatbot-close-btn:hover {
    opacity: 1;
}

/* Chat Box */
#chat-box {
    flex-grow: 1;
    padding: 1rem;
    overflow-y: auto;
    background-color: var(--chatbot-bg-light);
    scroll-behavior: smooth;
}

/* Custom scrollbar */
#chat-box::-webkit-scrollbar {
    width: 6px;
}

#chat-box::-webkit-scrollbar-track {
    background: transparent;
}

#chat-box::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

#chat-box::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* Messages */
.message {
    margin-bottom: 0.75rem;
    display: flex;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-message {
    margin-left: auto;
    justify-content: flex-end;
}

.bot-message {
    margin-right: auto;
    justify-content: flex-start;
}

.message-content {
    padding: 0.7rem 1rem;
    border-radius: 1.25rem;
    line-height: 1.5;
    word-wrap: break-word;
    font-size: 0.95rem;
}

.user-message .message-content {
    background: var(--chatbot-primary-color);
    color: var(--chatbot-text-light);
    border-bottom-right-radius: 0.25rem;
}

.bot-message .message-content {
    background: var(--chatbot-text-light);
    color: var(--chatbot-text-dark);
    border-bottom-left-radius: 0.25rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Bot message links */
.bot-message .message-content a {
    color: var(--chatbot-primary-color);
    text-decoration: underline;
}

.bot-message .message-content a:hover {
    text-decoration: none;
}

/* Error messages */
.error-message .message-content {
    background: #fee;
    color: #c33;
    border-left: 3px solid #c33;
}

/* Typing Indicator */
.typing-indicator .message-content {
    display: flex;
    gap: 4px;
    padding: 0.7rem 1rem;
}

.typing-indicator .message-content span {
    width: 8px;
    height: 8px;
    background: #888;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite;
}

.typing-indicator .message-content span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator .message-content span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-8px);
    }
}

/* Input Area */
#input-area {
    display: flex;
    border-top: 1px solid var(--chatbot-border);
    background: var(--chatbot-text-light);
    padding: 0.5rem;
    gap: 0.5rem;
}

#user-input {
    flex-grow: 1;
    border: 1px solid var(--chatbot-border);
    border-radius: 20px;
    padding: 0.7rem 1rem;
    outline: none;
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s ease;
}

#user-input:focus {
    border-color: var(--chatbot-primary-color);
}

#user-input:disabled {
    background: #f5f5f5;
    cursor: not-allowed;
}

#send-btn {
    background: var(--chatbot-primary-color);
    color: var(--chatbot-text-light);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, transform 0.1s ease;
    flex-shrink: 0;
}

#send-btn:hover:not(:disabled) {
    background: color-mix(in srgb, var(--chatbot-primary-color) 85%, black);
    transform: scale(1.05);
}

#send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

#send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

#send-btn.sending {
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

/* Mobile Responsive */
@media (max-width: 768px) {
    #chatbot-widget-container {
        bottom: 10px;
        right: 10px;
    }
    
    #chatbot-window {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
    
    #chatbot-open-btn {
        width: 56px;
        height: 56px;
    }
    
    #chatbot-open-btn svg {
        width: 24px;
        height: 24px;
    }
    
    .message {
        max-width: 90%;
    }
    
    #user-input {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* Small mobile devices */
@media (max-width: 375px) {
    #chatbot-header {
        padding: 0.75rem 1rem;
    }
    
    #chatbot-header h2 {
        font-size: 1rem;
    }
    
    #chat-box {
        padding: 0.75rem;
    }
    
    .message-content {
        font-size: 0.9rem;
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
    #chatbot-window {
        height: 100vh;
    }
    
    #chat-box {
        padding: 0.5rem;
    }
}

/* Accessibility - High Contrast Mode */
@media (prefers-contrast: high) {
    #chatbot-window {
        border: 2px solid var(--chatbot-text-dark);
    }
    
    .message-content {
        border: 1px solid var(--chatbot-text-dark);
    }
}

/* Accessibility - Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}