/**
 * AnythingLLM Chat Embed Widget Styles
 * Inline chat widget for embedding in page content
 */

/* Embed Container */
.anythingllm-embed-container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    border: 1px solid #e1e5e9;
    background: white;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Custom dimensions */
.anythingllm-embed-container[data-width] {
    width: var(--embed-width);
    max-width: var(--embed-width);
}

.anythingllm-embed-container[data-height] {
    height: var(--embed-height);
    max-height: var(--embed-height);
}

/* 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;
    flex-shrink: 0;
}

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

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

.anythingllm-header-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.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: 14px;
    transition: background 0.2s;
}

/* Normalize icon sizes for header buttons */
.anythingllm-header-btn svg {
    width: 16px;
    height: 16px;
}
.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;
    line-height: 1;
    display: inline-block;
}

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

.anythingllm-header-btn:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

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

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

.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: 20px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 300px;
}

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

.anythingllm-messages-container::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

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

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

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

.anythingllm-welcome-message .anythingllm-message {
    background: white;
    border: 1px solid #e2e8f0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    max-width: none;
    margin: 0 auto;
}

.anythingllm-welcome-message .anythingllm-message-content {
    font-size: 16px;
    padding: 20px 24px;
}

/* Messages */
.anythingllm-message {
    max-width: 80%;
    margin-bottom: 12px;
    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: 14px 18px;
    border-radius: 20px;
    font-size: 15px;
    line-height: 1.5;
    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: 8px;
}

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

/* Message content formatting */
.anythingllm-message-content h1,
.anythingllm-message-content h2,
.anythingllm-message-content h3,
.anythingllm-message-content h4,
.anythingllm-message-content h5,
.anythingllm-message-content h6 {
    margin: 0 0 8px 0;
    font-weight: 600;
}

.anythingllm-message-content p {
    margin: 0 0 8px 0;
}

.anythingllm-message-content p:last-child {
    margin-bottom: 0;
}

.anythingllm-message-content ul,
.anythingllm-message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.anythingllm-message-content li {
    margin: 4px 0;
}

.anythingllm-message-content code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
}

.anythingllm-user-message .anythingllm-message-content code {
    background: rgba(255, 255, 255, 0.2);
}

.anythingllm-message-content pre {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 12px;
    margin: 8px 0;
    overflow-x: auto;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
}

.anythingllm-message-content pre code {
    background: none;
    padding: 0;
    border-radius: 0;
}

.anythingllm-message-content blockquote {
    border-left: 4px solid #e2e8f0;
    margin: 8px 0;
    padding: 8px 0 8px 16px;
    color: #64748b;
    font-style: italic;
}

/* Loading Message */
.anythingllm-loading .anythingllm-message-content {
    background: white;
    border: 1px solid #e5e7eb;
    padding: 20px;
}

/* Input Area */
.anythingllm-input-area {
    padding: 20px;
    background: white;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.anythingllm-input-container {
    display: flex;
    gap: 12px;
    align-items: center;
    max-width: 100%;
}

.anythingllm-message-input {
    flex: 1;
    border: none;
    background: transparent;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 15px;
    resize: none;
    outline: none;
    transition: border-color 0.2s, box-shadow 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: 8px;
    flex-shrink: 0;
}

.anythingllm-input-btn {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    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 4px 12px 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;
}

/* Fullscreen Mode
   Scope fullscreen layout to the widget containers only to avoid
   host-level or ancestor elements accidentally inheriting these rules.
*/
.anythingllm-embed-widget.anythingllm-fullscreen,
.anythingllm-bubble-widget.anythingllm-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: calc(var(--anythingllm-vh, 1vh) * 100);
    max-width: none;
    max-height: none;
    z-index: 999999;
    border-radius: 0;
    border: none;
}

/* Ensure embed container loses rounding in fullscreen */
.anythingllm-embed-widget.anythingllm-fullscreen .anythingllm-embed-container {
    border-radius: 0 !important;
    box-shadow: none !important;
}

.anythingllm-fullscreen .anythingllm-messages-container {
    /* In grid row (auto 1fr auto), allow the scroll area to shrink */
    min-height: 0;
}

/* Dark Theme */
.anythingllm-dark-theme {
    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-welcome-message .anythingllm-message {
    background: #374151;
    border-color: #4b5563;
}

.anythingllm-dark-theme .anythingllm-welcome-message .anythingllm-message-content {
    color: #f9fafb;
}

.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;
}

.anythingllm-dark-theme .anythingllm-message-content code {
    background: rgba(255, 255, 255, 0.1);
}

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

.anythingllm-dark-theme .anythingllm-message-content blockquote {
    border-left-color: #4b5563;
    color: #ffffff !important;
}

/* Also support dark state when running outside Shadow DOM */
.anythingllm-dark .anythingllm-message-content blockquote {
    border-left-color: #4b5563;
    color: #ffffff !important;
}

.anythingllm-dark-theme .anythingllm-messages-container::-webkit-scrollbar-track {
    background: #374151;
}

.anythingllm-dark-theme .anythingllm-messages-container::-webkit-scrollbar-thumb {
    background: #4b5563;
}

.anythingllm-dark-theme .anythingllm-messages-container::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

/* Responsive Design */
@media (max-width: 768px) {
    .anythingllm-embed-container {
        border-radius: 8px;
        margin: 0;
        height: 70vh !important;
        max-height: 500px !important;
        overflow: hidden !important;
    }
    
    .anythingllm-chat-header {
        padding: 12px 16px;
        flex-shrink: 0 !important;
    }
    
    .anythingllm-chat-title {
        font-size: 16px;
    }
    
    .anythingllm-messages-container {
        padding: 16px;
        gap: 12px;
        min-height: 250px;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        max-height: calc(70vh - 120px) !important;
        flex: 1 !important;
    }
    
    .anythingllm-message {
        max-width: 90%;
    }
    
    .anythingllm-message-content {
        padding: 12px 16px;
        font-size: 14px;
    }
    
    .anythingllm-input-area {
        padding: 16px;
        flex-shrink: 0 !important;
    }
    
    .anythingllm-input-container {
        gap: 8px;
    }
    
    .anythingllm-message-input {
        padding: 10px 16px;
        font-size: 16px !important; /* Prevents zoom on iOS */
        min-height: 44px;
    }
    
    .anythingllm-input-btn {
        width: 44px;
        height: 44px;
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .anythingllm-embed-container {
        border-radius: 6px;
        height: 75vh !important;
        max-height: 450px !important;
    }
    
    .anythingllm-chat-header {
        padding: 10px 12px;
    }
    
    .anythingllm-header-actions {
        gap: 4px;
    }
    
    .anythingllm-header-btn {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
    
    .anythingllm-messages-container {
        padding: 12px;
        min-height: 200px;
        max-height: calc(75vh - 110px) !important;
    }
    
    .anythingllm-message-content {
        padding: 10px 14px;
        font-size: 13px;
    }
    
    .anythingllm-input-area {
        padding: 10px;
    }
    
    .anythingllm-message-input {
        padding: 8px 14px;
        font-size: 16px !important; /* Prevents zoom on iOS */
        min-height: 40px;
    }
    
    .anythingllm-input-btn {
        width: 40px;
        height: 40px;
        font-size: 14px;
    }
}

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

/* High contrast mode */
@media (prefers-contrast: high) {
    .anythingllm-embed-container {
        border-width: 2px;
        border-color: #000;
    }
    
    .anythingllm-message-content {
        border-width: 2px;
    }
    
    .anythingllm-message-input {
        border-width: 3px;
    }
}

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

/* Narrow mobile: widen bubbles and hide avatar for readability */
@media (max-width: 768px) {
    .anythingllm-message { max-width: 95% !important; }
}
@media (max-width: 480px) {
    .anythingllm-message { max-width: calc(100% - 6px) !important; }
    .anythingllm-message-content { width: 100% !important; }
    .anythingllm-message-avatar { display: none !important; }
}

/* Print styles */
@media print {
    .anythingllm-embed-container {
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .anythingllm-chat-header,
    .anythingllm-input-area {
        display: none;
    }
    
    .anythingllm-messages-container {
        background: white;
        padding: 0;
    }
    
    .anythingllm-message-content {
        box-shadow: none;
        border: 1px solid #000;
        break-inside: avoid;
    }
}