/* Widget Container */
.bos-chat-widget {
    position: fixed;
    z-index: 10000;
    font-family: 'Overpass', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.bos-chat-widget.bottom-right {
    bottom: 20px;
    right: 20px;
}

.bos-chat-widget.bottom-left {
    bottom: 20px;
    left: 20px;
}

/* Chat Button */
.bos-chat-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    
    /* Fallback background image if no icon configured */
    background-size: 65px 65px;
    background-repeat: no-repeat;
    background-position: center;
}

/* Chat icon image styling */
.bos-chat-icon {
    width: 65px;
    height: 65px;
    object-fit: contain;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-touch-callout: none;
    -webkit-user-drag: none;
    z-index: 1;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border: none;
    outline: none;
    background: none;
    transition: none;
}

/* Ensure no hover/active/focus effects on the image */
.bos-chat-icon:hover,
.bos-chat-icon:active,
.bos-chat-icon:focus {
    transform: translate(-50%, -50%);
    filter: none;
    opacity: 1;
    outline: none;
    border: none;
}

/* Hide background image when using icon element */
.bos-chat-button:has(.bos-chat-icon) {
    background-image: none;
}

/* Fallback for browsers that don't support :has() */
.bos-chat-button img.bos-chat-icon {
    position: relative;
    z-index: 2;
}

.bos-chat-button img.bos-chat-icon ~ * {
    background-image: none;
}

.bos-chat-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

/* Chat Window */
.bos-chat-window {
    width: 400px;
    height: 650px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 20px;
    border: 1px solid #e1e5e9;
    
    /* FIXED: Absolute height constraints to prevent layout issues */
    position: relative;
    box-sizing: border-box;
}

/* Chat Header */
.bos-chat-header {
    background: linear-gradient(135deg, #0157FF 0%, #0F3070 100%);
    color: white;
    padding: 20px;
    position: relative;
    z-index: 10;
    flex: none;
    min-height: 80px;
    box-sizing: border-box;
}

.bos-header-content {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    width: 100%;
    padding-right: 40px; /* Add space for absolutely positioned close button */
}

.bos-logo-section {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.bos-logo-placeholder {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.bos-logo-img {
    width: 68px;
    height: 68px;
    border-radius: 8px;
    object-fit: cover;
}

.bos-poweredbylogo-img {
    width: 40px;
    height: 10px;
    border-radius: 8px;
    object-fit: cover;
}


.bos-title-section {
    flex: 1;
}

.bos-title {
    margin: 0;
    font-size: 18px;
    font-weight: 450;
    line-height: 1.2;
}

.bos-subtitle {
    margin: 2px 0 0 0;
    font-size: 17px;
    opacity: 0.9;
    font-weight: 300;
    line-height: 1.3;
}

.bos-chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background-color 0.2s ease;
    position: absolute;
    top: 20px;
    right: 20px;
}

.bos-chat-close:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Chat Content Container */
.bos-chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

/* Welcome Screen */
.bos-welcome-screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: white;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
    overflow-y: auto;
}

.bos-welcome-main {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    gap: 20px;
}

.bos-welcome-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding-bottom: 40px;
}

.bos-welcome-icon {
    margin-bottom: 24px;
    display: flex;
    justify-content: center;
}

/* AI Logo styling in welcome screen */
.bos-welcome-icon img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border: 3px solid #e5e7eb;
    transition: all 0.3s ease;
}

.bos-welcome-icon img:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.bos-welcome-title {
    margin: 0 0 8px 0;
    font-size: 20px;
    font-weight: 700;
    color: #003DA5;
    line-height: 1.3;
    text-align: center;
}

.bos-welcome-subtext {
    margin: 0 0 0 0;
    font-size: 12px;
    color: #A0A7B4;
    line-height: 1.4;
    text-align: center;
}

.bos-faq-section {
    width: 100%;
    padding: 15px 0 0 0;
    margin: 0;
}

.bos-faq-section h4 {
    margin: 0 0 16px 0;
    font-size: 14px;
    font-weight: 600;
    color: #003DA5;
    text-align: left;
    width: 100%;
}

.bos-faq-item {
    background: #f8fafc;
    border: 1px solid #003DA5;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    font-size: 13px;
    color: #003DA5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
}

.bos-faq-item:hover {
    background: #e2e8f0;
    border-color: #667eea;
    color: #667eea;
}

.bos-faq-count {
    background: #667eea;
    color: white;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 8px;
    flex-shrink: 0;
}

.bos-faq-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: #6b7280;
    font-size: 13px;
    width: 100%;
}

.bos-loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e5e7eb;
    border-top: 2px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 8px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.bos-faq-container {
    display: none;
    width: 100%;
}

.bos-faq-error {
    display: none;
    width: 100%;
}

/* Chat Footer */
.bos-chat-footer {
    background: white;
    /*border-top: 1px solid #e5e7eb;*/
    padding: 6px; /* Reduced from 20px */
    flex-shrink: 0;
}

.bos-chat-input {
    display: flex;
    align-items: center;
    gap: 8px; /*Adjusted from 12px to 8px for better spacing*/
    margin-bottom: 16px;
}

.bos-voice-button {
   /* background: #f3f4f6;
    border: 2px solid #e2e8f0;
    border-radius: 20px;
    width: 40px;*/
    background: #0156FC; /* Orange background like in reference */
    border: none; /* Removed border for cleaner look */
    border-radius: 50%; /* Make it circular */
    width: 40px; /* Slightly larger for better touch target */
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #ffffff;
    transition: all 0.2s ease;
}

.bos-voice-button:hover {
    /*background: #e5e7eb;
    color: #374151;*/
    background: #0131B4;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(1, 86, 252, 0.3);

}

.bos-voice-button:disabled {
    background: #d1d5db;
    color: #9ca3af;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Voice button listening state */
.bos-voice-button.bos-voice-listening {
    background: #7C3AED; /* Purple background for listening state */
    animation: pulse-mic 1.5s infinite;
}

@keyframes pulse-mic {
    0% { 
        box-shadow: 0 0 0 0 rgba(1, 86, 252, 0.7); /* #0156FC */
    }
    70% { 
        box-shadow: 0 0 0 8px rgba(1, 86, 252, 0); 
    }
    100% { 
        box-shadow: 0 0 0 0 rgba(1, 86, 252, 0); 
    }
}

/* Input Field Styling */
.bos-chat-input input {
    /*flex: 1;
    padding: 14px 18px;
    border: 2px solid #e2e8f0;
    border-radius: 24px;*/
    flex: 1;
    padding: 12px 16px; /* Reduced vertical padding */
    border: 1px solid #d1d5db; /* Thinner border */
    border-radius: 25px; /* More rounded */
    font-size: 14px;
    outline: none;
    background: #f8fafc;
    color: #374151;
    transition: all 0.2s ease;
    font-family: inherit;
    line-height: 1.4;
    font-weight: 400;
    height: 44px; /* Fixed height to match buttons */
    box-sizing: border-box;
}

.bos-chat-input input:focus {
    /*border-color: #667eea;
    background: white;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.08);*/
    border-color: #2563EB;
    box-shadow: 0 0 0 3px rgba(8, 145, 178, 0.1);
}

.bos-chat-input input::placeholder {
    color: #9ca3af;
    font-weight: 400;
}

/* Send Button Styling */
.bos-send-button {
    /*background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);*/
    background: #003DA5;
    border: none;
    /*border-radius: 20px;*/
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.bos-send-button:hover {
    background: #0156FC;
    transform: translateY(-1px);
    /*box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);*/
    box-shadow: 0 4px 8px rgba(8, 145, 178, 0.3);

}

.bos-send-button:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Powered By Footer */
.bos-powered-by {
    text-align: right;
    font-size: 10px;
    color: #9ca3af;
    font-weight: 400;
    /*margin-top: 4px;*/
    margin: 0; /* Remove top margin */
    padding: 0;
    opacity: 0.8;
}

.bos-powered-by strong {
    color: #0891b2; /* Changed to match new theme from 667eea*/
    font-weight: 600;
}

/* Chat Input Area - Bottom */
.bos-chat-input-area {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-top: 1px solid #e5e7eb;
    background: #ffffff;
    position: relative;
    z-index: 10;
}

/* Messages Container */
.bos-chat-messages {
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8f9fa;
    flex: 1;
    position: relative;
    
    /* Enable smooth scrolling */
    scroll-behavior: smooth;
    
    /* Better mobile scrolling */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    
    /* Ensure proper box model */
    box-sizing: border-box;
    
    /* Hidden by default - shown when welcome screen is hidden */
    display: none;
}

.bos-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.bos-chat-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
}

.bos-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.3);
    border-radius: 3px;
}

.bos-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.5);
}

/* Message Styling */
.bos-message {
    max-width: 75%;
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 16px;
    
    /* CRITICAL: Ensure proper text wrapping */
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.bos-message-user {
    align-self: flex-end;
    align-items: flex-start;
    display: flex;
    flex-direction: row;
    gap: 8px;
    max-width: 75%; /* Reduced from 100% for better chat bubble appearance */
    margin-left: auto; /* Ensure right alignment */
    min-width: 0; /* Allow shrinking */
    overflow: hidden; /* Prevent overflow */
}

.bos-message-assistant {
    align-self: flex-start;
    align-items: flex-start;
    display: flex;
    flex-direction: row;
    gap: 8px;
    max-width: 90%; /* Reduced from 93% for better chat bubble appearance */
    margin-right: auto; /* Ensure left alignment */
    min-width: 0; /* Allow shrinking */
    overflow: hidden; /* Prevent overflow */
}

.bos-message-user-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: flex-start;
    order: 2; /* Avatar on the right for user messages */
    margin-top: 3px;
    margin-left: 8px; /* Add space between content and avatar */
}

.bos-message-assistant-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: flex-start;
    order: 1; /* Avatar on the left for assistant messages */
    margin-top: 3px;
    margin-right: 8px; /* Add space between avatar and content */
}

.bos-message-user-content-wrapper {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    align-items: flex-end;
    order: 1; /* Content comes before avatar for user messages */
    text-align: right;
    min-width: 0; /* Allow flex item to shrink */
    overflow: hidden; /* Prevent content from breaking out */
}

.bos-message-assistant-content-wrapper {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    align-items: flex-start;
    order: 2; /* Content comes after avatar for assistant messages */
    text-align: left;
    min-width: 0; /* Allow flex item to shrink */
    overflow: hidden; /* Prevent content from breaking out */
}

.bos-message-content {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    
    /* CRITICAL: Comprehensive overflow prevention */
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    white-space: pre-wrap;
    max-width: 100%;
    min-width: 0; /* Allow flex item to shrink below content size */
    box-sizing: border-box;
    text-align: left; /* Default left alignment for content */
    
    /* Handle very long URLs and unbreakable content */
    hyphens: auto;
    -webkit-hyphens: auto;
    -moz-hyphens: auto;
    -ms-hyphens: auto;
    
    /* Prevent horizontal scrolling */
    overflow-x: hidden;
    overflow-y: visible;
}

.bos-message-user .bos-message-content {
    background: #3170dc;
    color: white;
    text-align: left; /* Keep text left-aligned within the bubble */
}

.bos-message-assistant .bos-message-content {
    background: #f5f5f5; /* Added background for better visibility */
    border: 1px solid #C1CADC;
    color: #003DA5;
    text-align: left; /* Keep text left-aligned within the bubble */
}

/* Handle specific content types that commonly cause overflow */
.bos-message-content a,
.bos-message-content a:visited {
    color: inherit;
    text-decoration: underline;
    word-break: break-all; /* Force break on URLs */
    overflow-wrap: break-word;
}

.bos-message-content code,
.bos-message-content pre {
    font-family: 'Courier New', monospace;
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 13px;
    word-break: break-all;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    max-width: 100%;
    overflow-x: auto;
    display: inline-block;
}

.bos-message-content pre {
    display: block;
    padding: 8px;
    margin: 4px 0;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 6px;
    max-width: 100%;
    overflow-x: auto;
}

/* Handle tables if they appear in content */
.bos-message-content table {
    max-width: 100%;
    overflow-x: auto;
    display: block;
    white-space: nowrap;
}

/* Handle images in content */
.bos-message-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 4px 0;
    border-radius: 4px;
}

/* Handle blockquotes */
.bos-message-content blockquote {
    border-left: 3px solid #ddd;
    padding-left: 12px;
    margin: 8px 0;
    font-style: italic;
    color: #666;
}

.bos-message-time {
    font-size: 11px;
    color: #666;
    margin: 0 8px;
}

.bos-message-user .bos-message-time {
    text-align: right;
    margin: 0;
}

.bos-message-assistant .bos-message-time {
    text-align: left;
    margin: 0;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .bos-chat-window {
        width: 100vw;
        height: 100vh;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        margin: 0;
        border-radius: 0;
        z-index: 10000;
    }
    
    .bos-chat-messages {
        /* FIXED: Recalculate for mobile viewport */
        height: calc(100vh - 56px - 72px);
        /* CRITICAL: Better mobile scrolling */
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    
    .bos-chat-widget.bottom-right,
    .bos-chat-widget.bottom-left {
        bottom: 20px;
        right: 20px;
    }
    
    /* Mobile-specific overflow handling */
    .bos-message-user,
    .bos-message-assistant {
        max-width: 95%; /* Increase max width on mobile for better space utilization */
        margin-left: 5px;
        margin-right: 5px;
    }
    
    .bos-message-content {
        font-size: 13px; /* Slightly smaller text on mobile */
        padding: 10px 12px; /* Reduced padding for mobile */
        /* Enhanced word breaking for mobile */
        word-break: break-word;
        overflow-wrap: anywhere; /* More aggressive wrapping on mobile */
    }
    
    /* Handle very long content on mobile */
    .bos-message-content pre,
    .bos-message-content code {
        font-size: 11px; /* Smaller code text on mobile */
        overflow-x: auto;
        white-space: pre-wrap;
    }
}

/* Loading animation */
.bos-message-assistant .bos-message-content:has-text("Thinking...") {
    position: relative;
}

.bos-message-assistant .bos-message-content:has-text("Thinking...")::after {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid #ccc;
    border-top: 2px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 8px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Alternative Layout Support for older browsers */
@supports not (height: calc(500px - 56px - 72px)) {
    .bos-chat-messages {
        height: 372px; /* Fallback: 500 - 56 - 72 */
    }
    
    @media (max-width: 768px) {
        .bos-chat-messages {
            height: calc(100vh - 128px); /* Fallback for mobile */
        }
    }
}

/* Ensure no content gets clipped */
.bos-chat-window * {
    box-sizing: border-box;
}

/* Additional safety measures */
.bos-chat-header,
.bos-chat-input {
    min-height: fit-content;
    position: relative;
}

.bos-chat-messages {
    min-height: 200px; /* Minimum usable height */
}

/* Dark theme support */
.bos-chat-widget.dark .bos-chat-window {
    background: #2d3748;
    border-color: #4a5568;
}

.bos-chat-widget.dark .bos-message-assistant .bos-message-content {
    background: #4a5568;
    color: #e2e8f0;
}

.bos-chat-widget.dark .bos-chat-input {
    background: #2d3748;
    border-color: #4a5568;
}

.bos-chat-widget.dark .bos-chat-input input {
    background: #374151;
    border-color: #4b5563;
    color: #e2e8f0;
}

.bos-chat-widget.dark .bos-chat-input input:focus {
    background: #4b5563;
    border-color: #0891b2;/*#667eea;*/
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.15);
}

.bos-chat-widget.dark .bos-chat-input input::placeholder {
    color: #9ca3af;
}

.bos-chat-widget.dark .bos-powered-by {
    color: #9ca3af;
}

.bos-chat-widget.dark .bos-powered-by strong {
    color: #34d399;
}

/* Web Sources and Fallback Indicators */
.bos-fallback-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding: 6px 10px;
    background: #f0f8ff;
    border: 1px solid #b3d9ff;
    border-radius: 6px;
    font-size: 12px;
    color: #0066cc;
}

.bos-fallback-indicator svg {
    width: 16px;
    height: 16px;
    opacity: 0.7;
}

/* Unified Sources Container */
.bos-sources,
.bos-web-sources {
    margin-top: 8px;
    padding: 8px 0;
    border-top: 1px solid #e1e5e9;
}

.bos-sources-title {
    font-size: 11px;
    font-weight: 600;
    color: #003DA5;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Web Source Links (clickable) */
.bos-source-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    margin: 2px 0;
    border-radius: 4px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    color: #003DA5;
    text-decoration: none;
    font-size: 12px;
    transition: all 0.2s ease;
}

.bos-source-link:hover {
    background: #e2e8f0;
    border-color: #cbd5e0;
    color: #1f2937;
}

.bos-source-link svg {
    width: 12px;
    height: 12px;
    opacity: 0.6;
}

/* Web-specific styling */
.bos-web-source {
    border-left: 3px solid #3b82f6;
}

.bos-web-source:hover {
    border-left-color: #1d4ed8;
}

/* Document Source Items */
.bos-document-source {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    margin: 2px 0;
    border-radius: 4px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-left: 3px solid #10b981;
    color: #003DA5;
    font-size: 12px;
}

/* Clickable document sources (with S3 URLs) */
.bos-document-source.bos-source-link {
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.bos-document-source.bos-source-link:hover {
    background: #f3f4f6;
    border-color: #10b981;
    transform: translateX(2px);
}

/* Unavailable documents */
.bos-document-unavailable {
    opacity: 0.6;
    border-left-color: #9ca3af;
}

.bos-unavailable-text {
    font-style: italic;
    color: #6b7280;
}

/* Dark theme support for new elements */
.bos-chat-widget.dark .bos-fallback-indicator {
    background: #2d3748;
    border-color: #4a5568;
    color: #81c5ff;
}

.bos-chat-widget.dark .bos-sources,
.bos-chat-widget.dark .bos-web-sources {
    border-top-color: #4a5568;
}

.bos-chat-widget.dark .bos-sources-title {
    color: #9ca3af;
}

.bos-chat-widget.dark .bos-source-link {
    background: #374151;
    border-color: #4b5563;
    color: #e5e7eb;
}

.bos-chat-widget.dark .bos-source-link:hover {
    background: #4b5563;
    border-color: #6b7280;
    color: #f9fafb;
}

.bos-chat-widget.dark .bos-web-source {
    border-left-color: #60a5fa;
}

.bos-chat-widget.dark .bos-web-source:hover {
    border-left-color: #93c5fd;
}

.bos-chat-widget.dark .bos-document-source {
    background: #374151;
    border-color: #4b5563;
    border-left-color: #34d399;
    color: #e5e7eb;
}

.bos-chat-widget.dark .bos-document-source.bos-source-link:hover {
    background: #4b5563;
    border-color: #34d399;
}

.bos-chat-widget.dark .bos-document-unavailable {
    opacity: 0.5;
    border-left-color: #6b7280;
}

.bos-chat-widget.dark .bos-unavailable-text {
    color: #9ca3af;
}

.bos-chat-widget.dark .bos-web-sources {
    border-color: #4a5568;
}

.bos-chat-widget.dark .bos-sources-title {
    color: #a0aec0;
}

.bos-chat-widget.dark .bos-source-link {
    background: #2d3748;
    border-color: #4a5568;
    color: #e2e8f0;
}

.bos-chat-widget.dark .bos-source-link:hover {
    background: #4a5568;
    border-color: #718096;
    color: #f7fafc;
}

/* Follow-up Questions */
.bos-follow-up-questions {
    margin-top: 12px;
    padding: 12px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border-left: 3px solid #0157FF;
}

.bos-follow-up-title {
    font-size: 12px;
    font-weight: 600;
    color: #0F3070;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.bos-follow-up-question {
    display: block;
    width: 100%;
    margin-bottom: 6px;
    padding: 8px 12px;
    background-color: white;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-size: 13px;
    color: #495057;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    font-family: inherit;
    line-height: 1.4;
}

.bos-follow-up-question:hover {
    background: linear-gradient(135deg, #0157FF 0%, #0F3070 100%);
    color: white;
    border-color: #0157FF;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(1, 87, 255, 0.2);
}

.bos-follow-up-question:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(1, 87, 255, 0.3);
}

.bos-follow-up-question:last-child {
    margin-bottom: 0;
}

/* Dark theme support for follow-up questions */
.bos-chat-widget.dark .bos-follow-up-questions {
    background-color: #374151;
    border-left-color: #0157FF;
}

.bos-chat-widget.dark .bos-follow-up-title {
    color: #9ca3af;
}

.bos-chat-widget.dark .bos-follow-up-question {
    background-color: #2d3748;
    border-color: #4a5568;
    color: #e2e8f0;
}

.bos-chat-widget.dark .bos-follow-up-question:hover {
    background: linear-gradient(135deg, #0157FF 0%, #0F3070 100%);
    color: white;
    border-color: #0157FF;
}

/* Enhanced dark theme support for new content elements */
.bos-chat-widget.dark .bos-message-content code,
.bos-chat-widget.dark .bos-message-content pre {
    background: rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
}

.bos-chat-widget.dark .bos-message-content blockquote {
    border-left-color: #4a5568;
    color: #cbd5e0;
}

.bos-chat-widget.dark .bos-message-content a {
    color: #63b3ed;
}

/* Performance optimization: reduce reflows */
.bos-message-content * {
    max-width: 100%;
    box-sizing: border-box;
}

/* Handle extremely long words (like very long URLs or strings) */
.bos-message-content {
    /* CSS property for extremely long content */
    overflow-wrap: anywhere;
    /* Fallback for older browsers */
    word-wrap: break-word;
    word-break: break-word;
}

/* Ensure no horizontal scrolling in the chat window */
.bos-chat-window,
.bos-chat-messages,
.bos-message-user,
.bos-message-assistant,
.bos-message-user-content-wrapper,
.bos-message-assistant-content-wrapper {
    overflow-x: hidden;
}

/* Special handling for emoji and special characters */
.bos-message-content {
    /* Prevent emoji from breaking layout */
    font-variant-emoji: text;
    /* Ensure proper line breaking with mixed content */
    line-break: anywhere;
}

/* Accessibility improvements */
.bos-message-content:focus-visible {
    outline: 2px solid #0157FF;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .bos-message-content {
        border-width: 2px;
    }
    
    .bos-message-user .bos-message-content {
        background: #000;
        color: #fff;
        border: 2px solid #fff;
    }
    
    .bos-message-assistant .bos-message-content {
        background: #fff;
        color: #000;
        border: 2px solid #000;
    }
}

/* Additional safety measures for extreme content */
.bos-message-content table {
    table-layout: fixed;
    width: 100%;
}

.bos-message-content td,
.bos-message-content th {
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 0;
}

/* Handle very wide content in iframes or embedded content */
.bos-message-content iframe,
.bos-message-content embed,
.bos-message-content object {
    max-width: 100%;
    height: auto;
}

/* Force break on very long continuous text */
.bos-message-content {
    /* This is the most aggressive word breaking available */
    word-break: break-all;
    /* But we still want to respect word boundaries when possible */
    overflow-wrap: break-word;
    /* And use hyphens when breaking words */
    hyphens: auto;
}

/* Final fallback for any remaining overflow issues */
.bos-chat-widget * {
    max-width: 100% !important;
    box-sizing: border-box !important;
}

/* Specific handling for content that might still overflow */
.bos-message-content span,
.bos-message-content div,
.bos-message-content p {
    max-width: 100%;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

/* Ensure proper behavior in all browsers */
.bos-message-content {
    /* Modern browsers */
    overflow-wrap: anywhere;
    word-break: break-word;
    /* Safari fallback */
    -webkit-line-break: after-white-space;
    line-break: after-white-space;
    /* IE fallback */
    word-wrap: break-word;
    /* Ultimate fallback */
    white-space: pre-wrap;
}

/* Debug helper (can be removed in production) */
/*
.bos-message-content {
    border: 1px dashed red;
    overflow: visible;
}
*/

/* Message Feedback Styles */
.bos-message-feedback {
    margin-top: 12px;
}

.bos-feedback-separator {
    border: none;
    border-top: 1px solid #e1e8ed;
    margin: 8px 0;
}

.bos-feedback-question {
    font-size: 13px;
    color: #657786;
    margin-bottom: 8px;
    font-weight: 500;
}

.bos-feedback-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
}

.bos-feedback-btn {
    background: none;
    border: 1px solid #e1e8ed;
    border-radius: 20px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    outline: none;
    color: #657786;
}

.bos-feedback-btn:hover {
    /*background-color: #f7f9fa;
    border-color: #c1c9d0;*/
    transform: translateY(-1px);
}

.bos-feedback-btn:active {
    transform: translateY(0);
}

.bos-feedback-btn.selected {
    cursor: default;
    transform: none;
    border-color: #c1c9d0;
    background-color: #f7f9fa;
}

.bos-feedback-btn.selected:hover {
    transform: none;
    /*background-color: #f7f9fa;
    border-color: #c1c9d0;*/
}

.bos-feedback-btn:disabled {
    cursor: not-allowed;
}

.bos-feedback-thumbs-up.selected {
    background: #0056fc99;
    color: #ffffff;
}

.bos-feedback-thumbs-down.selected {
    background: #0056fc99;
    color: #ffffff;
}

.bos-feedback-icon {
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.bos-feedback-label {
    font-weight: 500;
}

.bos-feedback-message {
    font-size: 12px;
    color: #27ae60;
    font-style: italic;
    margin-top: 8px;
    padding: 4px 8px;
    background-color: #f0f8f0;
    border-radius: 4px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-2px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Ensure feedback buttons work well on mobile */
@media (max-width: 480px) {
    .bos-feedback-btn {
        padding: 8px 14px;
        font-size: 14px;
        gap: 8px;
    }
    
    .bos-feedback-buttons {
        gap: 12px;
    }
    
    .bos-feedback-question {
        font-size: 14px;
        margin-bottom: 10px;
    }
}