/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* CSS Custom Properties for Theming */
:root {
    /* Dark theme (default) */
    --bg-primary: #0f0f23;
    --bg-secondary: #171717;
    --bg-tertiary: #212121;
    --bg-quaternary: #2d2d2d;
    --text-primary: #ffffff;
    --text-secondary: #b4b4b4;
    --text-muted: #8e8ea0;
    --text-accent: #4cdb74;
    --text-white: #ffffff;
    --text-danger: #dc2626;
    --text-info: #1976D2;
    --text-success: #4CAF50;
    --text-warning: #FF9800;
    --text-disabled: #9E9E9E;
    --border-primary: #2d2d2d;
    --border-secondary: #565869;
    --accent-primary: #4cdb74;
    --accent-hover: #0d8f6c;
    --user-message-bg: #4cdb74;
    --bot-message-bg: #171717;
    --input-bg: #2d2d2d;
    --sidebar-bg: #171717;
    --shadow-color: rgba(0, 0, 0, 0.3);
}

/* Light theme */
[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #ffffff;
    --bg-quaternary: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #495057;
    --text-muted: #6c757d;
    --text-accent: #28a745;
    --text-white: #ffffff;
    --text-danger: #dc3545;
    --text-info: #0d6efd;
    --text-success: #198754;
    --text-warning: #fd7e14;
    --text-disabled: #adb5bd;
    --border-primary: #dee2e6;
    --border-secondary: #ced4da;
    --accent-primary: #28a745;
    --accent-hover: #218838;
    --user-message-bg: #007bff;
    --bot-message-bg: #f8f9fa;
    --input-bg: #ffffff;
    --sidebar-bg: #f8f9fa;
    --shadow-color: rgba(0, 0, 0, 0.1);
}

/* Light theme specific adjustments */
[data-theme="light"] .sidebar {
    box-shadow: 2px 0 4px var(--shadow-color);
}

[data-theme="light"] .input-wrapper {
    box-shadow: 0 2px 4px var(--shadow-color);
}

[data-theme="light"] .message-text {
    box-shadow: 0 1px 3px var(--shadow-color);
}

[data-theme="light"] .source-item {
    box-shadow: 0 2px 4px var(--shadow-color);
}

[data-theme="light"] .welcome-message {
    box-shadow: 0 2px 4px var(--shadow-color);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    overflow: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
    /* Prevent zooming on input focus in iOS */
    -webkit-text-size-adjust: 100%;
}

/* App Container */
.app-container {
    display: flex;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    background-color: var(--bg-primary);
}

/* Sidebar */
.sidebar {
    width: 450px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-primary);
    display: flex;
    flex-direction: column;
    position: relative;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-primary);
}

.sidebar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.logo img {
    filter: brightness(0) invert(1);
    opacity: 0.9;
}

[data-theme="light"] .logo img {
    filter: brightness(0) invert(0);
    opacity: 0.8;
}

.logo i {
    font-size: 24px;
    color: var(--accent-primary);
}

.new-chat-btn {
    width: 100%;
    padding: 12px 16px;
    background-color: transparent;
    border: 1px solid var(--border-secondary);
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    transition: all 0.2s ease;
}

.new-chat-btn:hover {
    background-color: var(--bg-quaternary);
    border-color: var(--accent-primary);
}

.chat-history {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden; /* Add this to prevent horizontal scroll */
}

.chat-history h3{
    padding-bottom: 20px;
}

.chat-item {
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    margin-bottom: 8px;
    transition: all 0.2s ease;
}

.chat-item:hover {
    background-color: var(--bg-quaternary);
}

.chat-item.active {
    background-color: var(--accent-primary);
    color: var(--text-white);
}

.conversation-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.conversation-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.chat-item:hover .conversation-actions {
    opacity: 1;
}

.delete-conversation-btn {
    background: none;
    border: none;
    color: var(--text-danger);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
    font-size: 14px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.delete-conversation-btn:hover {
    color: #ff4444;
    transform: scale(1.1);
}

.chat-item.active .delete-conversation-btn {
    color: rgba(220, 38, 38, 0.8);
}

.chat-item.active .delete-conversation-btn:hover {
    color: #ff4444;
    transform: scale(1.1);
}

.conversation-title {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
    max-width: 250px; /* Ensure conversation titles don't take too much space */
}

.conversation-meta {
    font-size: 12px;
    opacity: 0.7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-muted);
}

.chat-item.active .conversation-meta {
    opacity: 0.9;
    color: rgba(255, 255, 255, 0.9);
}

.conversations-list {
    max-height: calc(100%-50px);
    overflow-y: auto;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border-primary);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 32px;
    height: 32px;
    background-color: var(--accent-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-tertiary);
}

.chat-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--sidebar-bg);
}

.header-left {
    display: flex;
    align-items: center;
    width: 40px; /* Match width of header-actions for symmetry */
}

.chat-title {
    flex: 1;
    text-align: center;
}

.chat-title h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.chat-title .powered-by {
    font-size: 11px;
    color: var(--text-muted);
    display: block;
    margin-top: 2px;
    opacity: 0.7;
}

.status {
    font-size: 12px;
    color: var(--accent-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.status::before {
    content: '';
    width: 8px;
    height: 8px;
    background-color: var(--accent-primary);
    border-radius: 50%;
}

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

.action-btn, .theme-toggle-btn, .mobile-menu-btn {
    width: 40px;
    height: 40px;
    background-color: transparent;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 16px;
}

.action-btn:hover, .theme-toggle-btn:hover, .mobile-menu-btn:hover {
    background-color: var(--bg-quaternary);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

/* Hide mobile menu button on desktop */
.mobile-menu-btn {
    display: none;
}

/* Messages Container */
.messages-container {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    scroll-behavior: smooth;
}

.welcome-message {
    display: flex;
    gap: 16px;
    margin-bottom: 32px;
    padding: 24px;
    background-color: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border-primary);
}

.bot-avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-hover));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.welcome-content h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.welcome-content p {
    color: var(--text-secondary);
    line-height: 1.5;
}

.message {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    max-width: 100%;
}

.user-message {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.user-message .message-avatar {
    background-color: var(--border-secondary);
    color: var(--text-white);
}

.bot-message .message-avatar {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-hover));
    color: var(--text-white);
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-text {
    background-color: var(--bg-secondary);
    padding: 16px 20px;
    border-radius: 16px;
    line-height: 1.6;
    word-wrap: break-word;
    border: 1px solid var(--border-primary);
    margin-bottom: 8px;
    color: var(--text-primary);
    font-size: 14px;
}

/* Document links styling within message text */
.message-text a {
    color: var(--accent-primary);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: all 0.2s ease;
    font-weight: 500;
}

.message-text a:hover {
    color: var(--accent-hover);
    border-bottom-color: var(--accent-primary);
    background-color: rgba(76, 219, 116, 0.1);
    padding: 2px 4px;
    border-radius: 4px;
    margin: -2px -4px;
}

/* Ensure links are clickable and have proper cursor */
.message-text a:visited {
    color: var(--accent-primary);
}

/* Style for document reference links specifically */
.message-text a[href^="/pdf/"] {
    background: rgba(76, 219, 116, 0.15);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid rgba(76, 219, 116, 0.3);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 14px;
}

.message-text a[href^="/pdf/"]:hover {
    background: rgba(76, 219, 116, 0.25);
    border-color: var(--accent-primary);
    transform: translateY(-1px);
}

/* External link icon styling for PDF links */
.message-text a[href^="/pdf/"] .fa-external-link-alt {
    font-size: 11px;
    margin-left: 2px;
    color: #ffffff;
    background: var(--accent-primary);
    padding: 3px 5px;
    border-radius: 3px;
    transition: all 0.2s ease;
}

.message-text a[href^="/pdf/"]:hover .fa-external-link-alt {
    background: var(--accent-hover);
    transform: scale(1.1);
}

/* Light theme adjustments for external link icon */
[data-theme="light"] .message-text a[href^="/pdf/"] .fa-external-link-alt {
    color: #ffffff;
    background: #28a745;
}

[data-theme="light"] .message-text a[href^="/pdf/"]:hover .fa-external-link-alt {
    background: #218838;
}

.user-message .message-text {
    background-color: var(--user-message-bg);
    color: var(--text-white);
    margin-left: auto;
    max-width: 70%;
}

.bot-message .message-text {
    background-color: var(--bot-message-bg);
    color: var(--text-primary);
    max-width: 85%;
    border: 1px solid var(--border-primary);
}

.message-time {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 5px;
    padding: 0 8px;
}

.user-message .message-time {
    text-align: right;
}

.bot-message .message-time {
    text-align: left;
}

/* Input Container */
.input-container {
    padding: 24px;
    background-color: var(--sidebar-bg);
    border-top: 1px solid var(--border-primary);
}

.input-wrapper {
    position: relative;
    background-color: var(--input-bg);
    border-radius: 12px;
    border: 1px solid var(--border-secondary);
    transition: all 0.2s ease;
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
}

.input-wrapper:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.1);
}

.attachment-btn {
    position: absolute;
    left: 16px;
    bottom: 16px;
    width: 32px;
    height: 32px;
    background-color: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s ease;
    z-index: 2;
}

.attachment-btn:hover {
    background-color: var(--border-secondary);
    color: var(--accent-primary);
}

#messageInput {
    flex: 1;
    padding: 16px 60px 16px 56px;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 16px; /* Prevent zoom on iOS */
    font-family: inherit;
    line-height: 1.5;
    resize: none;
    min-height: 56px;
    max-height: 120px;
    /* iOS specific fixes */
    -webkit-appearance: none;
    appearance: none;
    -webkit-border-radius: 0;
    border-radius: 0;
}

#messageInput::placeholder {
    color: var(--text-muted);
}

.send-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    background-color: var(--accent-primary);
    border: none;
    border-radius: 8px;
    color: var(--text-white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.send-btn:disabled {
    background-color: var(--border-secondary);
    cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
    background-color: var(--accent-hover);
    transform: translateY(-50%) scale(1.05);
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    font-size: 12px;
    color: var(--text-muted);
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
    padding: 0 4px;
}

.language-selector {
    display: flex;
    align-items: center;
    gap: 6px;
}

.language-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.language-label i {
    font-size: 11px;
}

.language-select {
    background: var(--input-bg);
    border: 1px solid var(--border-secondary);
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 11px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 70px;
}

.language-select:hover {
    border-color: var(--accent-primary);
}

.language-select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(76, 219, 116, 0.1);
}

/* Dark mode styling for select dropdown options */
.language-select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23565869' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6,9 12,15 18,9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 6px center;
    background-size: 12px;
    padding-right: 24px;
    color-scheme: dark;
}

[data-theme="light"] .language-select {
    color-scheme: light;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23495057' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6,9 12,15 18,9'%3e%3c/polyline%3e%3c/svg%3e");
}

.language-select option {
    background-color: var(--input-bg);
    color: var(--text-primary);
    padding: 4px 8px;
}

/* Webkit browsers specific styling */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    .language-select option {
        background: var(--input-bg);
        color: var(--text-primary);
    }
    
    .language-select option:hover {
        background: var(--bg-quaternary) !important;
        color: var(--text-primary) !important;
    }
    
    .language-select option:checked {
        background: var(--accent-primary) !important;
        color: var(--text-white) !important;
    }
}

/* Firefox specific styling */
@-moz-document url-prefix() {
    .language-select option {
        background-color: var(--input-bg) !important;
        color: var(--text-primary) !important;
    }
    
    .language-select option:hover {
        background-color: var(--bg-quaternary) !important;
        color: var(--text-primary) !important;
    }
    
    .language-select option:checked {
        background-color: var(--accent-primary) !important;
        color: var(--text-white) !important;
    }
}

.char-count {
    color: var(--text-muted);
}

/* Loading Spinner */
.loading-spinner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-primary);
    border-top: 3px solid var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}


/* Scrollbar Styling */
.messages-container::-webkit-scrollbar,
.chat-history::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-track,
.chat-history::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb,
.chat-history::-webkit-scrollbar-thumb {
    background: var(--border-secondary);
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover,
.chat-history::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

/* Additional scrollbar styling for consistency */
.sidebar::-webkit-scrollbar,
.conversations-list::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track,
.conversations-list::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb,
.conversations-list::-webkit-scrollbar-thumb {
    background: var(--border-secondary);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover,
.conversations-list::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}


/* Responsive Design */
@media (max-width: 900px) {
    .app-container {
        position: relative;
        /* Fix for mobile browsers with dynamic viewport */
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for modern browsers */
        max-height: 100vh;
        max-height: 100dvh;
    }
    
    .sidebar {
        width: 80%;
        max-width: 350px;
        position: fixed;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height */
        top: 0;
        left: 0;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    
    /* Mobile backdrop overlay */
    .mobile-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height */
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
        pointer-events: none;
    }
    
    .mobile-backdrop.active {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }
    
    .main-content {
        width: 100%;
        margin-left: 0;
        /* Ensure main content fills available space properly */
        height: 100vh;
        height: 100dvh;
        display: flex;
        flex-direction: column;
    }

    /* Show mobile menu button */
    .mobile-menu-btn {
        display: flex !important;
    }

    /* Center the chat title on mobile */
    .chat-title {
        text-align: center;
    }

    /* Ensure header-left has same width as header-actions for symmetry */
    .header-left {
        width: 40px;
    }
    
    .user-message .message-text,
    .bot-message .message-text {
        max-width: 90%;
    }
    
    /* Fix input container for mobile - key fix for iPhone 11 */
    .input-container {
        padding: 12px 16px; /* Reduced padding for mobile */
        margin-left: 0;
        /* Ensure it stays at bottom and is always visible */
        position: sticky;
        bottom: 0;
        flex-shrink: 0; /* Prevent shrinking */
        /* Add safe area padding for iPhone notch/home indicator */
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
    
    /* Ensure messages container takes available space */
    .messages-container {
        flex: 1;
        min-height: 0; /* Allow flex item to shrink below content size */
        padding: 16px; /* Reduced padding for mobile */
        overflow-y: auto;
    }
    
    /* Make input wrapper more mobile-friendly */
    .input-wrapper {
        max-width: 100%;
        margin: 0;
    }
    
    .sidebar-actions {
        align-items: stretch;
    }
    
    .new-chat-btn {
        margin-bottom: 0;
    }
    
    /* Make delete button more accessible on mobile */
    .conversation-actions {
        opacity: 1; /* Always show on mobile */
    }
    
    .delete-conversation-btn {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
}

/* Animation for new messages */
@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.new {
    animation: messageSlideIn 0.3s ease-out;
}

/* Additional mobile fixes for smaller screens (iPhone 11 and similar) */
@media (max-width: 480px) {
    .input-container {
        padding: 8px 12px;
        /* Ensure input is always visible on smaller screens */
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
        /* Force the container to stay at bottom */
        position: sticky;
        bottom: 0;
        z-index: 10;
    }
    
    .input-wrapper {
        border-radius: 8px; /* Smaller border radius for mobile */
    }
    
    .messages-container {
        padding: 12px; /* Even more reduced padding */
        /* Ensure proper scrolling behavior on mobile */
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }
    
    .chat-header {
        padding: 16px 20px; /* Reduced header padding */
    }
    
    /* Ensure text area doesn't get too small */
    .message-input, #messageInput {
        min-height: 44px; /* iOS recommended touch target size */
        font-size: 16px; /* Prevent zoom on focus */
    }
    
    /* Fix for iOS Safari viewport issues */
    .app-container {
        min-height: 100vh;
        min-height: 100dvh;
    }
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
}

.typing-indicator .message-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-hover));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: var(--text-white);
}

.typing-dots {
    background-color: var(--bg-secondary);
    padding: 16px 20px;
    border-radius: 16px;
    border: 1px solid var(--border-primary);
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background-color: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    30% {
        transform: scale(1);
        opacity: 1;
    }
}

/* PDF Upload Section */
.pdf-upload-section {
    padding: 20px;
    border-bottom: 1px solid var(--border-primary);
}

.pdf-upload-section h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.pdf-upload-section h3 i {
    color: var(--text-danger);
}

.upload-area {
    border: 2px dashed var(--border-secondary);
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 16px;
}

.upload-area:hover,
.upload-area.drag-over {
    border-color: var(--accent-primary);
    background-color: rgba(16, 163, 127, 0.1);
}

.upload-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.upload-content i {
    font-size: 24px;
    color: var(--border-secondary);
}

.upload-content p {
    font-size: 12px;
    color: var(--text-muted);
    margin: 0;
}

.upload-btn {
    padding: 8px 16px;
    background-color: var(--accent-primary);
    border: none;
    border-radius: 6px;
    color: var(--text-white);
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    margin-top: 8px;
}

.upload-btn:hover {
    background-color: var(--accent-hover);
}

.pdf-list {
    max-height: 200px;
    overflow-y: auto;
}

.pdf-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    background-color: var(--bg-quaternary);
    transition: all 0.2s ease;
}

.pdf-item:hover {
    background-color: var(--border-secondary);
}

.pdf-item.new-upload {
    border: 1px solid var(--accent-primary);
    background-color: rgba(16, 163, 127, 0.1);
}

.pdf-item i {
    color: var(--text-danger);
    font-size: 16px;
}

.pdf-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.pdf-title {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px; /* Ensure reasonable width limit */
}

.pdf-date {
    font-size: 10px;
    color: var(--text-muted);
}

.pdf-size {
    font-size: 10px;
    color: var(--accent-primary);
    margin-top: 2px;
}

/* Search Results Styling */
.search-results {
    max-width: 100%;
    margin: 0;
}

.search-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    padding: 12px;
    background: rgba(16, 163, 127, 0.1);
    border-radius: 8px;
    border-left: 4px solid var(--accent-primary);
    font-size: 13px;
}

.low-relevance-query{
    display: inline-block;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    padding: 12px;
    background: rgba(16, 163, 127, 0.1);
    border-radius: 8px;
    border-left: 4px solid var(--accent-primary);
}

.search-header i {
    color: var(--accent-primary);
}

/* ...existing code... */

/* Summary Styling
.summary-content {
    margin: 16px 0;
    padding: 16px;
    background: rgba(33, 150, 243, 0.1);
    border-radius: 8px;
    border-left: 4px solid #2196F3;
} */

.summary-bullet {
    margin: 8px 0;
    padding: 6px 0;
    line-height: 1.5;
    font-size: 14px;
}

.summary-bullet.primary {
    color: var(--text-primary);
}

.summary-bullet.secondary {
    color: var(--text-secondary);
    margin-left: 16px;
}

.summary-bullet.tertiary {
    color: var(--text-muted);
    margin-left: 32px;
}

.summary-bullet:first-child {
    margin-top: 0;
}

.summary-bullet:last-child {
    margin-bottom: 0;
}

/* Enhanced message text for summaries */
.message-text .summary-content {
    background: rgba(76, 219, 116, 0.1);
    border-left: 4px solid #4cdb74;
}

.bot-message .message-text .summary-content {
    background: rgba(33, 150, 243, 0.15);
    border-left: 4px solid #2196F3;
}

/* ...existing code... */

.search-summary {
    margin-bottom: 20px;
    padding: 16px;
    background: rgba(33, 150, 243, 0.1);
    border-radius: 8px;
    border-left: 4px solid #2196F3;
    font-size: 14px;
}

.search-summary h4 {
    margin: 0 0 8px 0;
    color: var(--text-info);
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.search-summary p {
    margin: 0;
    color: var(--text-primary);
    line-height: 1.5;
    font-size: 14px;
}

.search-sources {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.source-item {
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    padding: 16px;
    background: var(--bg-secondary);
    transition: all 0.2s ease;
}

.source-item:hover {
    background: var(--bg-quaternary);
    border-color: var(--accent-primary);
}

.source-item.high {
    border-left: 4px solid #4CAF50;
}

.source-item.medium {
    border-left: 4px solid #FF9800;
}

.source-item.low {
    border-left: 4px solid #9E9E9E;
}

.source-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.source-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.source-info i {
    color: var(--text-danger);
    font-size: 16px;
}

.source-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px; /* Limit width for better layout */
}

.source-date {
    color: var(--text-muted);
    font-size: 12px;
    background: var(--bg-quaternary);
    padding: 2px 8px;
    border-radius: 12px;
}

.source-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.pdf-link {
    display: inline;
    align-items: center;
    justify-content: center;
    width: 55px;
    padding-left: 2px;
    padding-right: 2px;
    margin-left: 2px;
    margin-right: 2px;
    height: 8px;
    background: var(--accent-primary);
    color: white;
    border-radius: 6px;
    text-decoration: none;
    transition: all 0.2s ease;
}

.pdf-link-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--accent-primary);
    color: white;
    border-radius: 6px;
    text-decoration: none;
    transition: all 0.2s ease;
}

.pdf-link:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.relevance-score {
    background: rgba(16, 163, 127, 0.2);
    color: var(--text-accent);
    padding: 4px 8px;
    margin-left: 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.source-item.high .relevance-score {
    background: rgba(76, 175, 80, 0.2);
    color: var(--text-success);
}

.source-item.medium .relevance-score {
    background: rgba(255, 152, 0, 0.2);
    color: var(--text-warning);
}

.source-item.low .relevance-score {
    background: rgba(158, 158, 158, 0.2);
    color: var(--text-disabled);
}

.source-excerpt {
    color: var(--text-secondary);
    line-height: 1.6;
    font-style: italic;
    font-size: 12px;
    background: var(--bg-tertiary);
    padding: 12px;
    border-radius: 8px;
    border-left: 3px solid var(--border-primary);
}

.no-results {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
}

.no-results i {
    font-size: 24px;
    margin-bottom: 12px;
    color: var(--border-secondary);
}

.no-results p {
    margin: 0;
    line-height: 1.5;
}

/* Sidebar Progress Bar */
.sidebar-progress-container {
    margin-top: 10px;
    padding: 0 15px;
}

.progress-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.progress-bar-wrapper {
    width: 100%;
    background-color: var(--border-secondary);
    border-radius: 4px;
    height: 8px;
}

.progress-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary) 0%, #2196F3 100%);
    border-radius: 4px;
    transition: width 0.3s ease-in-out;
}

/* PDF Info Section */
.pdf-info-section {
    margin-top: 16px;
}

.pdf-count-display {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: var(--bg-quaternary);
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
    color: var(--text-primary);
}

.pdf-count-display i {
    color: var(--accent-primary);
}

.recent-uploads {
    margin-top: 16px;
}

.recent-uploads h4 {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.recent-uploads h4 i {
    color: var(--accent-primary);
}

/* Top Progress Bar */
.top-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 4px;
    background: transparent;
    z-index: 2000;
}
.top-progress-bar-inner {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent-primary) 0%, #2196F3 100%);
    transition: width 0.5s cubic-bezier(0.4,0,0.2,1);
}

/* Upload Progress Bar */
.upload-progress-bar {
    width: 100%;
    height: 8px;
    background-color: var(--border-primary);
    border-radius: 4px;
    margin: 10px 0;
    overflow: hidden;
}

.upload-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary) 0%, #2196F3 100%);
    border-radius: 4px;
    transition: width 0.5s ease-out;
    width: 0%;
}

.upload-content small {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
}

.upload-content p {
    margin: 8px 0;
    font-size: 13px;
    color: var(--text-primary);
    max-width: 250px;
    word-wrap: break-word;
    line-height: 1.4;
}

/* Document Management Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.document-modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal-overlay.active .document-modal {
    transform: scale(1);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 12px;
}

.modal-title i {
    color: var(--text-danger);
}

.modal-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: all 0.2s ease;
    font-size: 18px;
}

.modal-close-btn:hover {
    background: var(--bg-quaternary);
    color: var(--text-primary);
}

.modal-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.documents-stats {
    padding: 16px 24px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    color: var(--text-secondary);
}

.documents-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px;
}

.document-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    margin-bottom: 12px;
    background: var(--bg-tertiary);
    transition: all 0.2s ease;
}

.document-item:hover {
    background: var(--bg-quaternary);
    border-color: var(--accent-primary);
}

.document-icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--text-danger), #ff6b6b);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: white;
}

.document-info {
    flex: 1;
    min-width: 0;
}

.document-title {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 300px; /* Ensure reasonable width for modal display */
}

.document-meta {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--text-muted);
}

.document-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

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

.view-document-btn, .delete-document-btn {
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.view-document-btn {
    background: var(--accent-primary);
    color: white;
}

.view-document-btn:hover {
    background: var(--accent-hover);
}

.delete-document-btn {
    background: transparent;
    color: var(--text-danger);
    border: 1px solid var(--text-danger);
}

.delete-document-btn:hover {
    background: var(--text-danger);
    color: white;
}

.empty-documents {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-documents i {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-primary);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.modal-btn {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.modal-btn-secondary {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-secondary);
}

.modal-btn-secondary:hover {
    background: var(--bg-quaternary);
    color: var(--text-primary);
}

/* Document management button in sidebar */
.document-management-btn {
    width: 100%;
    padding: 12px 16px;
    background-color: transparent;
    border: 1px solid var(--border-secondary);
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    transition: all 0.2s ease;
    margin-top: 8px;
}

.document-management-btn:hover {
    background-color: var(--bg-quaternary);
    border-color: var(--text-danger);
    color: var(--text-danger);
}

.document-management-btn i {
    color: var(--text-danger);
}

/* Mobile improvements for document management modal */
@media (max-width: 900px) {
    .modal-overlay {
        padding: 0;
        align-items: center;
        justify-content: center;
    }
    
    .document-modal {
        width: 95%;
        max-width: none;
        max-height: 90vh;
        margin: 16px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    }
    
    /* Reduce source title width on mobile for better layout */
    .source-title {
        max-width: 80px; /* Reduced from 200px for mobile */
    }
    
    .modal-header {
        padding: 16px 20px;
    }
    
    .modal-title {
        font-size: 18px;
        gap: 8px;
    }
    
    .modal-title i {
        font-size: 16px;
    }
    
    .modal-close-btn {
        padding: 12px;
        font-size: 20px;
        min-width: 44px;
        min-height: 44px;
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .modal-close-btn:hover, .modal-close-btn:active {
        background: var(--bg-quaternary);
        color: var(--text-primary);
        transform: scale(0.95);
    }
    
    .modal-title i {
        font-size: 16px;
    }
    
    .documents-stats {
        padding: 12px 20px;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        font-size: 13px;
    }
    
    .documents-list {
        padding: 12px 20px;
    }
    
    .document-item {
        padding: 12px;
        gap: 12px;
        flex-direction: row;
        align-items: flex-start;
        position: relative;
    }
    
    .document-item-header {
        display: flex;
        align-items: flex-start;
        gap: 12px;
        width: 100%;
        margin-bottom: 8px;
    }
    
    .document-icon {
        width: 32px;
        height: 32px;
        font-size: 14px;
        flex-shrink: 0;
    }
    
    .document-info {
        flex: 1;
        min-width: 0;
    }
    
    .document-title {
        max-width: 100%;
        white-space: normal;
        line-height: 1.4;
        margin-bottom: 8px;
        word-break: break-word;
    }
    
    .document-meta {
        flex-wrap: wrap;
        gap: 8px 12px;
        font-size: 11px;
        margin-bottom: 8px;
    }
    
    .document-meta span {
        white-space: nowrap;
        background: var(--bg-quaternary);
        padding: 2px 6px;
        border-radius: 4px;
        font-size: 10px;
    }
    
    .document-actions {
        display: flex;
        justify-content: flex-end;
        gap: 8px;
        width: 100%;
    }
    
    .view-document-btn, .delete-document-btn {
        flex: 1;
        justify-content: center;
        padding: 10px 12px;
        font-size: 13px;
        min-height: 44px; /* iOS touch target size */
        border-radius: 6px;
        font-weight: 600;
    }
    
    .view-document-btn {
        background: var(--accent-primary);
        color: white;
        border: 2px solid var(--accent-primary);
    }
    
    .view-document-btn:hover, .view-document-btn:active {
        background: var(--accent-hover);
        border-color: var(--accent-hover);
        transform: scale(0.98);
    }
    
    .delete-document-btn {
        background: transparent;
        color: var(--text-danger);
        border: 2px solid var(--text-danger);
    }
    
    .delete-document-btn:hover, .delete-document-btn:active {
        background: var(--text-danger);
        color: white;
        transform: scale(0.98);
    }
    
    .modal-footer {
        padding: 12px 20px;
    }
    
    .modal-btn {
        padding: 12px 20px;
        font-size: 16px;
        min-height: 44px; /* iOS touch target size */
    }
}

@media (max-width: 480px) {
    .modal-overlay {
        padding: 0;
        align-items: stretch;
        justify-content: stretch;
    }
    
    .document-modal {
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
        box-shadow: none;
    }
    
    /* Further reduce source title width on small mobile screens */
    .source-title {
        max-width: 100px; /* Even smaller for small screens */
    }
    
    .modal-header {
        padding: 12px 16px;
        position: sticky;
        top: 0;
        z-index: 10;
        background: var(--bg-secondary);
        border-bottom: 2px solid var(--border-primary);
    }
    
    .modal-title {
        font-size: 16px;
    }
    
    .documents-stats {
        padding: 10px 16px;
        position: sticky;
        top: 60px; /* Adjust based on header height */
        z-index: 9;
        background: var(--bg-tertiary);
        border-bottom: 2px solid var(--border-primary);
    }
    
    .documents-list {
        padding: 8px 16px;
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        overscroll-behavior: contain;
        padding-bottom: 16px; /* Extra space at bottom */
    }
    
    .document-item:last-child {
        margin-bottom: 0;
    }
    
    .document-item {
        padding: 10px;
        border-radius: 6px;
        margin-bottom: 8px;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    
    .document-item-header {
        display: flex;
        align-items: center;
        gap: 10px;
        margin-bottom: 6px;
    }
    
    .document-icon {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
    
    .document-title {
        font-size: 14px;
        font-weight: 600;
        line-height: 1.3;
        margin-bottom: 6px;
        word-break: break-word;
    }
    
    .document-meta {
        font-size: 10px;
        gap: 6px 8px;
        margin-bottom: 8px;
    }
    
    .document-meta span {
        background: var(--bg-quaternary);
        padding: 1px 4px;
        border-radius: 3px;
        font-size: 9px;
    }
    
    .document-actions {
        gap: 6px;
        margin-top: 0;
        flex-direction: row;
        justify-content: space-between;
    }
    
    .view-document-btn, .delete-document-btn {
        padding: 8px 10px;
        font-size: 12px;
        border-radius: 4px;
    }
    
    .modal-footer {
        padding: 10px 16px;
        position: sticky;
        bottom: 0;
        background: var(--bg-secondary);
        border-top: 2px solid var(--border-primary);
    }
    
    .modal-btn {
        padding: 10px 16px;
        font-size: 14px;
        width: 100%;
    }
    
    /* Improve empty state for mobile */
    .empty-documents {
        padding: 20px 16px;
    }
    
    .empty-documents i {
        font-size: 32px;
        margin-bottom: 12px;
    }
    
    .empty-documents p {
        font-size: 14px;
        line-height: 1.4;
    }
    
    .empty-documents small {
        font-size: 12px;
        margin-top: 8px;
        display: block;
    }
}
