/* Chat-specific Styles */

/* Chat Container */
.chat-container {
    display: flex;
    height: calc(100vh - 4rem);
    overflow: hidden;
}

/* Messages Container */
#messages-container {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
    padding: 1rem;
    width: 100%;
}

#messages-list {
    width: 100%;
    max-width: none;
}

/* Message Items */
.message-item {
    display: flex;
    margin-bottom: 1rem;
    animation: fadeIn 0.3s ease-in;
}

.message-item.own {
    justify-content: flex-end;
}

.message-bubble {
    max-width: 90%;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    word-wrap: break-word;
    position: relative;
}

.message-bubble.own {
    background: linear-gradient(135deg, var(--chat-bubble-own-gradient-from) 0%, var(--chat-bubble-own-gradient-to) 100%);
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.message-bubble.other {
    background: var(--chat-bubble-other);
    color: var(--text-primary);
    border-bottom-left-radius: 0.25rem;
    border: 1px solid var(--border-color);
}

/* Message Content Formatting */
.message-content {
    line-height: 1.5;
}

.message-content p {
    margin-bottom: 0.5rem;
}

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

.message-content ul,
.message-content ol {
    margin-left: 1.5rem;
    margin-bottom: 0.5rem;
}

.message-content blockquote {
    border-left: 3px solid var(--primary-color);
    padding-left: 1rem;
    margin: 0.5rem 0;
    font-style: italic;
    opacity: 0.9;
}

.message-content code {
    background: rgba(0, 0, 0, 0.1);
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

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

.message-content pre {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 1rem;
    overflow-x: auto;
    margin: 0.5rem 0;
}

.message-bubble.own .message-content pre {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
}

/* LaTeX Styles */
.latex-inline {
    display: inline-block;
    margin: 0 0.25rem;
}

.latex-block {
    display: block;
    margin: 1rem 0;
    text-align: center;
    overflow-x: auto;
}

/* Message Actions */
.message-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s;
}

.message-item:hover .message-actions {
    opacity: 1;
}

.message-actions button {
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-secondary);
    transition: all 0.2s;
}

.message-actions button:hover {
    background: rgba(0, 0, 0, 0.1);
    color: var(--text-primary);
}

/* Reactions */
.reactions-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.5rem;
}

.reaction-btn {
    padding: 0.125rem 0.5rem;
    border-radius: 1rem;
    background: var(--bg-secondary);
    font-size: 0.875rem;
    transition: all 0.2s;
    cursor: pointer;
}

.reaction-btn:hover {
    transform: scale(1.1);
    background: var(--primary-color);
    color: white;
}

.reaction-btn.active {
    background: var(--primary-color);
    color: white;
}

/* Typing Indicator */
#typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-style: italic;
}

.typing-dots {
    display: flex;
    gap: 0.25rem;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: typingPulse 1.4s infinite;
}

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

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

@keyframes typingPulse {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: scale(1);
    }
    30% {
        opacity: 1;
        transform: scale(1.2);
    }
}

/* Message Input Area */
.message-input-container {
    padding: 1rem;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
}

#message-input {
    width: 100%;
    min-height: 44px;
    max-height: 200px;
    padding: 0.625rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 1.5rem;
    resize: none;
    outline: none;
    transition: all 0.2s;
    background: var(--bg-primary);
    color: var(--text-primary);
}

#message-input:focus {
    border-color: var(--primary-color);
}

/* File Upload Preview */
#file-preview {
    gap: 0.5rem;
    padding: 0.5rem;
    overflow-x: auto;
}

.file-preview-item {
    position: relative;
    padding: 0.5rem;
    background: var(--bg-secondary);
    border-radius: 0.5rem;
    min-width: 100px;
}

.file-preview-item img {
    max-width: 100px;
    max-height: 100px;
    object-fit: cover;
    border-radius: 0.25rem;
}

.file-preview-remove {
    position: absolute;
    top: -0.25rem;
    right: -0.25rem;
    width: 20px;
    height: 20px;
    background: var(--danger-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.75rem;
}

/* Upload Progress */
.upload-progress {
    position: relative;
    background: var(--bg-secondary);
    border-radius: 0.5rem;
    overflow: hidden;
}

.upload-progress-bar {
    height: 4px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    transition: width 0.3s;
}

/* Sidebar Styles */
#sidebar {
    width: 320px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s;
}

#sidebar.collapsed {
    transform: translateX(-100%);
    margin-left: -320px;
}

/* Conversation List */
.conversation-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.conversation-item:hover {
    background: var(--bg-primary);
}

.conversation-item.active {
    background: var(--primary-color);
    color: white;
}

.conversation-item.active .text-secondary {
    color: rgba(255, 255, 255, 0.8);
}

.conversation-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

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

.conversation-name {
    font-weight: 500;
    margin-bottom: 0.125rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-last-message {
    font-size: 0.875rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
}

.conversation-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.unread-badge {
    background: var(--primary-color);
    color: white;
    font-size: 0.75rem;
    padding: 0.125rem 0.375rem;
    border-radius: 9999px;
    min-width: 20px;
    text-align: center;
}

/* Search Highlight */
.search-highlight {
    background: linear-gradient(120deg, #ffeb3b 0%, #ffc107 100%);
    color: #000;
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    animation: highlightPulse 0.3s ease-in-out;
}

.dark .search-highlight {
    background: linear-gradient(120deg, #fbbf24 0%, #f59e0b 100%);
    color: #000;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

/* Message container highlighting */
.message-has-highlight {
    background-color: rgba(255, 235, 59, 0.1);
    border-left: 3px solid #ffc107;
    padding-left: 0.5rem;
    margin-left: -0.5rem;
    border-radius: 0.25rem;
    transition: all 0.3s ease;
}

.dark .message-has-highlight {
    background-color: rgba(251, 191, 36, 0.1);
    border-left-color: #fbbf24;
}

/* Current search result highlighting */
.current-search-result {
    background-color: rgba(59, 130, 246, 0.15);
    border: 2px solid #3b82f6;
    border-radius: 0.5rem;
    padding: 0.5rem;
    margin: 0.25rem 0;
    box-shadow: 0 4px 6px rgba(59, 130, 246, 0.1);
    animation: currentResultPulse 0.5s ease-in-out;
}

.dark .current-search-result {
    background-color: rgba(59, 130, 246, 0.2);
    border-color: #60a5fa;
    box-shadow: 0 4px 6px rgba(59, 130, 246, 0.2);
}

/* Search results indicator */
.search-results-indicator {
    margin-top: 0.5rem;
    padding: 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    text-align: center;
    transition: all 0.3s ease;
}

.search-results-indicator.success {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.dark .search-results-indicator.success {
    background-color: #064e3b;
    color: #a7f3d0;
    border-color: #047857;
}

.search-results-indicator.no-results {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.dark .search-results-indicator.no-results {
    background-color: #7f1d1d;
    color: #fecaca;
    border-color: #dc2626;
}

/* Search suggestions */
.search-suggestions {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background-color: #f8fafc;
    border-radius: 0.5rem;
    border: 1px solid #e2e8f0;
}

.dark .search-suggestions {
    background-color: #1e293b;
    border-color: #374151;
}

.search-suggestion-btn {
    background-color: #e2e8f0;
    color: #475569;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid #cbd5e1;
    cursor: pointer;
    transition: all 0.2s ease;
}

.search-suggestion-btn:hover {
    background-color: #cbd5e1;
    color: #1e293b;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.dark .search-suggestion-btn {
    background-color: #374151;
    color: #d1d5db;
    border-color: #4b5563;
}

.dark .search-suggestion-btn:hover {
    background-color: #4b5563;
    color: #f9fafb;
}

/* Search hint tooltip */
.search-hint-tooltip {
    animation: slideInUp 0.3s ease-out;
    transition: all 0.3s ease;
}

.search-hint-tooltip kbd {
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    font-size: 0.6rem;
    font-family: monospace;
}

/* Highlight animation */
@keyframes highlightPulse {
    0% {
        background-color: transparent;
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes currentResultPulse {
    0% {
        transform: scale(1);
        box-shadow: 0 4px 6px rgba(59, 130, 246, 0.1);
    }
    50% {
        transform: scale(1.02);
        box-shadow: 0 8px 15px rgba(59, 130, 246, 0.2);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 4px 6px rgba(59, 130, 246, 0.1);
    }
}

@keyframes slideInUp {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(10px);
    }
    100% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Emoji Picker */
.emoji-picker {
    position: absolute;
    bottom: 100%;
    right: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.5rem;
    box-shadow: var(--shadow-lg);
    max-width: 320px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 100;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 0.25rem;
}

.emoji-btn {
    padding: 0.5rem;
    border-radius: 0.25rem;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 1.25rem;
}

.emoji-btn:hover {
    background: var(--bg-secondary);
}

/* Citation Styles */
.citation {
    display: inline-block;
    padding: 0.125rem 0.25rem;
    background: var(--primary-color);
    color: white;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    cursor: pointer;
    vertical-align: super;
}

.citation:hover {
    background: var(--primary-hover);
}

.citation-popup {
    position: absolute;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 1rem;
    box-shadow: var(--shadow-lg);
    max-width: 400px;
    z-index: 100;
}

/* Drag and Drop */
.drag-over {
    background: rgba(100, 116, 139, 0.1);
    border: 2px dashed var(--primary-color);
}

.drop-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.drop-overlay-content {
    background: var(--bg-primary);
    padding: 2rem;
    border-radius: 1rem;
    text-align: center;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .chat-container {
        flex-direction: column;
    }
    
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 1000;
        width: 280px;
    }
    
    #sidebar.collapsed {
        transform: translateX(-100%);
    }
    
    .message-bubble {
        max-width: 95%;
    }
    
    #messages-container {
        padding: 0.5rem;
    }
    
    .conversation-item {
        padding: 0.625rem 0.75rem;
    }
}

/* Dark Mode Adjustments */
.dark .message-bubble.other {
    background: var(--chat-bubble-other);
    border: 1px solid var(--border-color);
}

.dark .message-content pre {
    background: #1f2937;
    border-color: #4b5563;
}

.dark #message-input {
    background: var(--bg-secondary);
    border-color: var(--border-color);
}

.dark #message-input:focus {
    border-color: var(--primary-color);
}

.dark .conversation-item:hover {
    background: #374151;
}

.dark .emoji-picker {
    background: #1f2937;
    border-color: #4b5563;
}

.dark .citation-popup {
    background: #1f2937;
    border-color: #4b5563;
}

/* Accessibility */
.message-item:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.conversation-item:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: -2px;
}

/* Loading States */
.message-skeleton {
    display: flex;
    gap: 0.75rem;
    padding: 1rem;
    animation: pulse 2s infinite;
}

.message-skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-secondary);
}

.message-skeleton-content {
    flex: 1;
}

.message-skeleton-bubble {
    width: 60%;
    height: 60px;
    border-radius: 1rem;
    background: var(--bg-secondary);
    margin-bottom: 0.5rem;
}

.message-skeleton-meta {
    width: 100px;
    height: 16px;
    border-radius: 0.25rem;
    background: var(--bg-secondary);
}