/* Chat Widget Styles */
#chat-widget {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --bg-color: #ffffff;
    --text-color: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --user-bg: #3b82f6;
    --user-text: #ffffff;
    --bot-bg: #f3f4f6;
    --bot-text: #1f2937;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* Chat Container */
#chat-container {
    display: none; /* Start hidden */
    flex-direction: column;
    width: 100%;
    max-width: 420px; /* Slightly wider default */
    min-width: 320px; /* Minimum width */
    height: 600px;
    max-height: 80vh;
    background: var(--bg-color);
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: all 0.3s ease;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}

#chat-container:not(.hidden) {
    display: flex;
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Chat Header */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
}

.chat-header h3 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
}

.chat-actions {
    display: flex;
    gap: 0.5rem;
}

/* Chat Messages */
#chat-messages {
    flex: 1;
    padding: 1.25rem;
    overflow-y: auto;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Message Styles */
.message {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    line-height: 1.5;
    position: relative;
    animation: fadeIn 0.3s ease-out;
    word-wrap: break-word;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.user-message {
    background-color: var(--user-bg);
    color: var(--user-text);
    margin-left: auto;
    border-bottom-right-radius: 0.25rem;
    align-self: flex-end;
}

.bot-message {
    background-color: var(--bot-bg);
    color: var(--bot-text);
    margin-right: auto;
    border-bottom-left-radius: 0.25rem;
    align-self: flex-start;
}

.message-time {
    font-size: 0.75rem;
    opacity: 0.8;
    margin-top: 0.25rem;
    text-align: right;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    background-color: var(--bot-bg);
    border-radius: 1rem;
    width: fit-content;
    margin-bottom: 0.5rem;
}

.typing-dot {
    height: 8px;
    width: 8px;
    background-color: var(--text-muted);
    border-radius: 50%;
    display: inline-block;
    margin: 0 2px;
    animation: bounce 1.3s linear infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.15s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.3s;
}

/* Chat Input */
.chat-input-container {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-color);
}

.chat-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

#chat-input {
    width: 100%;
    padding: 0.75rem 3rem 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 2rem;
    font-size: 0.9375rem;
    line-height: 1.5;
    outline: none;
    transition: all 0.2s ease;
    background-color: #f9fafb;
}

#chat-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

#send-button {
    position: absolute;
    right: 0.75rem;
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    transition: transform 0.2s ease;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#send-button:hover {
    transform: scale(1.1);
    background-color: rgba(59, 130, 246, 0.1);
}

#send-button:active {
    transform: scale(0.95);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-4px);
    }
}

/* Scrollbar Styling */
#chat-messages::-webkit-scrollbar {
    width: 6px;
}

#chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Message Sources */
.sources {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.sources .source {
    margin-bottom: 0.25rem;
}

.sources .source a {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 0.75rem;
}

.sources .source a:hover {
    text-decoration: underline;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 20px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .toggle-slider {
    background-color: var(--primary-color);
}

input:focus + .toggle-slider {
    box-shadow: 0 0 1px var(--primary-color);
}

input:checked + .toggle-slider:before {
    transform: translateX(18px);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    #chat-widget {
        --bg-color: #1f2937;
        --text-color: #f3f4f6;
        --text-muted: #9ca3af;
        --border-color: #374151;
        --bot-bg: #374151;
        --bot-text: #f3f4f6;
    }
    
    #chat-input {
        background-color: #374151;
        color: #f3f4f6;
        border-color: #4b5563;
    }
    
    #chat-input::placeholder {
        color: #9ca3af;
    }
    
    #chat-messages::-webkit-scrollbar-track {
        background: #374151;
    }
    
    #chat-messages::-webkit-scrollbar-thumb {
        background: #4b5563;
    }
    
    #chat-messages::-webkit-scrollbar-thumb:hover {
        background: #6b7280;
    }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    #chat-container {
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        bottom: 0;
        right: 0;
    }
    
    .message {
        max-width: 90%;
    }
}

/* For larger screens */
@media (min-width: 1200px) {
    #chat-container {
        max-width: 500px;
    }
}