/**
 * AnythingLLM Chat Bubble Widget Styles
 * Floating chat bubble with customizable positioning
 */

/* Bubble Container */
.anythingllm-bubble-container {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Bubble positioning */
.anythingllm-bubble-container.bottom-right {
    bottom: 20px;
    right: 20px;
}

.anythingllm-bubble-container.bottom-left {
    bottom: 20px;
    left: 20px;
}

.anythingllm-bubble-container.top-right {
    top: 20px;
    right: 20px;
}

.anythingllm-bubble-container.top-left {
    top: 20px;
    left: 20px;
}

/* Chat Bubble */
.anythingllm-chat-bubble {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    transition: all 0.3s ease;
    position: relative;
    border: none;
    outline: none;
}

.anythingllm-chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2);
}

.anythingllm-chat-bubble:active {
    transform: scale(0.95);
}

/* Bubble notification dot */
.anythingllm-chat-bubble::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    background: #ff4757;
    border-radius: 50%;
    border: 2px solid white;
    opacity: 0;
    transform: scale(0);
    transition: all 0.3s ease;
}

.anythingllm-chat-bubble.has-notification::after {
    opacity: 1;
    transform: scale(1);
}

/* Chat Window */
.anythingllm-chat-window {
    position: absolute;
    width: 400px !important;
    height: 620px !important;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s ease;
    border: 1px solid #e1e5e9;
    box-sizing: border-box;
}

/* Window positioning based on bubble position */
.anythingllm-bubble-container.bottom-right .anythingllm-chat-window {
    bottom: 80px;
    right: 0;
}

.anythingllm-bubble-container.bottom-left .anythingllm-chat-window {
    bottom: 80px;
    left: 0;
}

.anythingllm-bubble-container.top-right .anythingllm-chat-window {
    top: 80px;
    right: 0;
}

.anythingllm-bubble-container.top-left .anythingllm-chat-window {
    top: 80px;
    left: 0;
}

.anythingllm-chat-window.open {
    display: flex;
    animation: anythingllm-slideIn 0.3s ease-out;
}

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

/* Chat Header */
.anythingllm-chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
  border-radius: 0; /* keep outer window rounding only */
}

.anythingllm-chat-title {
    font-weight: 600;
    font-size: 16px;
    margin: 0;
}

.anythingllm-chat-subtitle {
    font-size: 12px;
    opacity: 0.8;
    margin: 2px 0 0 0;
}

.anythingllm-header-actions {
    display: flex;
    gap: 8px;
}

.anythingllm-header-btn {
    background: transparent;
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: background 0.2s;
}

/* Normalize icon sizes for header buttons */
.anythingllm-header-btn svg {
    width: 16px;
    height: 16px;
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
}
/* Ensure header icons inherit button color against aggressive theme overrides */
.anythingllm-header-btn svg path,
.anythingllm-header-btn svg rect {
    fill: currentColor !important;
}

/* Support Font Awesome header icons */
.anythingllm-header-btn .anythingllm-fa-fallback {
    font-size: 16px !important;
    line-height: 1 !important;
    display: inline-block !important;
    color: currentColor !important;
}

.anythingllm-header-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* Status Indicator */
.anythingllm-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    opacity: 0.9;
}

.anythingllm-status-indicator {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4ade80;
}

.anythingllm-status-indicator.error {
    background: #ef4444;
}

.anythingllm-status-indicator.connecting {
    background: #f59e0b;
    animation: anythingllm-pulse 1.5s infinite;
}

@keyframes anythingllm-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Messages Container */
.anythingllm-messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.anythingllm-messages-container::-webkit-scrollbar {
    width: 6px;
}

.anythingllm-messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.anythingllm-messages-container::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.anythingllm-messages-container::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Welcome Message */
.anythingllm-welcome-message {
    text-align: center;
    padding: 20px;
    color: #64748b;
}

.anythingllm-welcome-message .anythingllm-message {
    background: white;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Messages */
.anythingllm-message {
    max-width: 85%;
    margin-bottom: 8px;
    position: relative;
}

.anythingllm-user-message {
    align-self: flex-end;
    margin-left: auto;
}

.anythingllm-assistant-message {
    align-self: flex-start;
    margin-right: auto;
}

.anythingllm-message-content {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    position: relative;
}

.anythingllm-user-message .anythingllm-message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 6px;
}

.anythingllm-assistant-message .anythingllm-message-content,
.anythingllm-message-assistant .anythingllm-message-content {
    background: transparent;
    color: #1f2937;
    border: none;
    border-bottom-left-radius: 6px;
    box-shadow: none;
}

/* Loading Message */
.anythingllm-loading .anythingllm-message-content {
    background: transparent;
    border: none;
    padding: 16px;
}

/* Input Area */
.anythingllm-input-area {
    padding: 16px;
    background: white;
    border-top: 1px solid #e5e7eb;
  border-radius: 0; /* keep outer window rounding only */
}

.anythingllm-input-container {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.anythingllm-message-input {
    flex: 1;
    border: none;
    background: transparent;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 14px;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
    line-height: 1.4;
    max-height: 120px;
    min-height: 36px;
}

.anythingllm-message-input:focus {
    border-color: transparent;
    box-shadow: none;
}

.anythingllm-message-input::placeholder {
    color: #9ca3af;
}

.anythingllm-input-actions {
    display: flex;
    gap: 4px;
}

.anythingllm-input-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s;
    outline: none;
}

.anythingllm-send-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.anythingllm-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.anythingllm-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.anythingllm-mic-btn {
    background: #f3f4f6;
    color: #6b7280;
}

.anythingllm-mic-btn:hover {
    background: #e5e7eb;
    color: #374151;
}

.anythingllm-mic-btn.recording {
    background: #fef2f2;
    color: #dc2626;
    animation: anythingllm-pulse 1s infinite;
}

/* Dark Theme */
.anythingllm-dark-theme .anythingllm-chat-window {
    background: #1f2937;
    border-color: #374151;
}

.anythingllm-dark-theme .anythingllm-messages-container {
    background: #111827;
}

.anythingllm-dark-theme .anythingllm-assistant-message .anythingllm-message-content,
.anythingllm-dark-theme .anythingllm-message-assistant .anythingllm-message-content {
    background: transparent;
    color: #f9fafb;
    border-color: transparent;
}

.anythingllm-dark-theme .anythingllm-input-area {
    background: #1f2937;
    border-color: #374151;
}

.anythingllm-dark-theme .anythingllm-message-input {
    background: #374151;
    border-color: #4b5563;
    color: #f9fafb;
}

.anythingllm-dark-theme .anythingllm-message-input::placeholder {
    color: #9ca3af;
}

.anythingllm-dark-theme .anythingllm-mic-btn {
    background: #374151;
    color: #9ca3af;
}

.anythingllm-dark-theme .anythingllm-mic-btn:hover {
    background: #4b5563;
    color: #f3f4f6;
}

/* Responsive Design */
@media (max-width: 480px) {
    .anythingllm-chat-window {
        width: calc(100vw - 40px);
        height: calc(100vh - 100px);
        max-width: none;
    }
    
    .anythingllm-bubble-container.bottom-right .anythingllm-chat-window,
    .anythingllm-bubble-container.bottom-left .anythingllm-chat-window {
        bottom: 80px;
        left: 20px;
        right: 20px;
    }
    
    .anythingllm-bubble-container.top-right .anythingllm-chat-window,
    .anythingllm-bubble-container.top-left .anythingllm-chat-window {
        top: 80px;
        left: 20px;
        right: 20px;
    }
}

@media (max-width: 320px) {
    .anythingllm-chat-bubble {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
    
    .anythingllm-chat-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 80px);
    }
    
    .anythingllm-bubble-container.bottom-right .anythingllm-chat-window,
    .anythingllm-bubble-container.bottom-left .anythingllm-chat-window {
        bottom: 70px;
        left: 10px;
        right: 10px;
    }
    
    .anythingllm-bubble-container.top-right .anythingllm-chat-window,
    .anythingllm-bubble-container.top-left .anythingllm-chat-window {
        top: 70px;
        left: 10px;
        right: 10px;
    }
}

/* Accessibility */
.anythingllm-chat-bubble:focus,
.anythingllm-header-btn:focus,
.anythingllm-input-btn:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .anythingllm-chat-bubble {
        border: 2px solid #000;
    }
    
    .anythingllm-message-content {
        border-width: 2px;
    }
    
    .anythingllm-message-input {
        border-width: 2px;
    }
}

/* Mobile responsive styles */
@media (max-width: 768px) {
    /* Scope mobile window sizing only when NOT fullscreen to avoid overriding the overlay */
    .anythingllm-bubble-widget:not(.anythingllm-fullscreen) .anythingllm-chat-window {
        width: calc(100vw - 20px) !important;
        height: 70vh !important;
        max-height: 500px !important;
        bottom: 80px !important;
        right: 10px !important;
        left: 10px !important;
        overflow: hidden !important;
    }
    
    .anythingllm-bubble-container.bottom-left .anythingllm-chat-window,
    .anythingllm-bubble-container.top-left .anythingllm-chat-window,
    .anythingllm-bubble-container.top-right .anythingllm-chat-window {
        right: 10px !important;
        left: 10px !important;
    }
    
    .anythingllm-messages-container {
        padding: 15px !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        max-height: calc(70vh - 120px) !important;
        flex: 1 !important;
    }
    
    .anythingllm-message {
        max-width: 90% !important;
        font-size: 14px !important;
    }
    
    .anythingllm-message-content {
        padding: 10px 14px !important;
    }
    
    .anythingllm-input-container {
        padding: 15px !important;
        flex-shrink: 0 !important;
    }
    
    .anythingllm-message-input {
        font-size: 16px !important; /* Prevents zoom on iOS */
        min-height: 36px !important;
    }
}

@media (max-width: 480px) {
    /* Same scoping: do not restrict layout while fullscreen */
    .anythingllm-bubble-widget:not(.anythingllm-fullscreen) .anythingllm-chat-window {
        height: 75vh !important;
        max-height: 450px !important;
    }
    
    .anythingllm-messages-container {
        padding: 12px !important;
        max-height: calc(75vh - 110px) !important;
    }
    
    .anythingllm-input-container {
        padding: 10px !important;
    }
    
    .anythingllm-message-content {
        padding: 8px 12px !important;
        font-size: 13px !important;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .anythingllm-chat-bubble,
    .anythingllm-chat-window,
    .anythingllm-header-btn,
    .anythingllm-input-btn {
        transition: none;
    }
    
    .anythingllm-chat-bubble:hover {
        transform: none;
    }
    
    @keyframes anythingllm-slideIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
    
    @keyframes anythingllm-pulse {
        0%, 100% { opacity: 1; }
        50% { opacity: 1; }
    }
}

/* Robust fullscreen override for bubble widget to guarantee full-width, full-height */
.anythingllm-bubble-widget.anythingllm-fullscreen {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: calc(var(--anythingllm-vh, 1vh) * 100) !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    z-index: 999999 !important;
    overflow: hidden !important;
}
.anythingllm-bubble-widget.anythingllm-fullscreen .anythingllm-chat-window {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: calc(var(--anythingllm-vh, 1vh) * 100) !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}