/* =============================================================================
   RAG UI - Main Stylesheet (Fancy Mode)
   ============================================================================= */

/* CSS Variables */
:root {
    /* Colors - Light Mode */
    --bg-primary: #ffffff;
    --bg-secondary: #f5f7fa;
    --bg-tertiary: #e8ecf1;
    --text-primary: #1a1a2e;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --border-color: #e2e8f0;
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;

    /* Spacing */
    --header-height: 56px;
    --sidebar-width: 280px;
    --source-panel-width: 560px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

/* Dark Mode Variables */
body.dark {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --text-primary: #e2e8f0;
    --text-secondary: #a0aec0;
    --text-muted: #718096;
    --border-color: #2d3748;
    --accent-color: #60a5fa;
    --accent-hover: #3b82f6;
}

/* =============================================================================
   Base Styles
   ============================================================================= */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
}

body {
    /* min-height: 100%; */
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* =============================================================================
   Header
   ============================================================================= */

.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-center {
    display: flex;
    align-items: center;
}

.server-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
}

.status-dot.online {
    background: var(--success-color);
    box-shadow: 0 0 8px var(--success-color);
}

.status-dot.offline {
    background: var(--error-color);
}

.status-dot.initializing {
    background: var(--warning-color);
    animation: pulse 1.5s infinite;
}

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

.config-dropdown {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
}

/* =============================================================================
   Buttons
   ============================================================================= */

.btn-primary {
    padding: 8px 16px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    padding: 8px 16px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-tertiary);
}

.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 18px;
}

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

.btn-toggle {
    padding: 6px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-toggle.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.btn-small {
    padding: 4px 8px;
    font-size: 12px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

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

/* =============================================================================
   Main Layout
   ============================================================================= */

.main-container {
    display: flex;
    height: calc(100vh - var(--header-height));
    margin-top: var(--header-height);
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.sidebar-section {
    flex: 1;
    min-height: 0;  /* Required for flex children to shrink below content size */
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-section:last-child {
    border-bottom: none;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 16px 12px 16px;
    flex-shrink: 0;
}

.section-header h3 {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

/* Conversation List */
.conversation-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    padding: 0 16px 16px 16px;
    flex: 1;
    min-height: 0;
}

.conversation-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

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

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

.conversation-content {
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

.conversation-item .title {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.conversation-item .meta {
    font-size: 11px;
    color: var(--text-muted);
}

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

/* Conversation Action Buttons */
.conversation-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

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

.action-btn {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    transition: all var(--transition-fast);
}

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

.conversation-item.active .action-btn {
    color: rgba(255, 255, 255, 0.7);
}

.conversation-item.active .action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

/* Star button states */
.star-btn.starred {
    color: var(--warning-color);
    opacity: 1;
}

.conversation-item:not(:hover) .star-btn.starred {
    opacity: 1;
}

.conversation-item:not(:hover) .conversation-actions {
    opacity: 0;
}

.conversation-item:not(:hover) .star-btn.starred {
    opacity: 1;
}

/* Show starred button even when not hovering */
.conversation-item .conversation-actions:has(.star-btn.starred) {
    opacity: 1;
}

.conversation-item:not(:hover) .conversation-actions:has(.star-btn.starred) .action-btn:not(.star-btn) {
    opacity: 0;
}

/* Delete button hover color */
.delete-btn:hover {
    color: var(--error-color) !important;
}

/* Folder List */
.folder-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.folder-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.folder-item:hover {
    background: var(--bg-tertiary);
}

.folder-item .name {
    display: flex;
    align-items: center;
    gap: 8px;
}

.folder-item .status {
    font-size: 12px;
}

.folder-item .status.ready {
    color: var(--success-color);
}

.folder-item .status.unprocessed {
    color: var(--warning-color);
}

.folder-item .status.processing {
    color: var(--accent-color);
}

/* Empty State */
.empty-state {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* =============================================================================
   Main Content
   ============================================================================= */

.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-secondary);
}

/* Mode Selector */
.mode-selector {
    display: flex;
    justify-content: center;
    padding: 16px;
    gap: 4px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
}

.mode-btn {
    padding: 8px 20px;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.mode-btn:first-child {
    border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.mode-btn:last-child {
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    border-left: none;
}

.mode-btn.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: white;
}

/* Chat Container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.welcome-message {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.welcome-message h2 {
    font-size: 24px;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

/* Message Bubbles */
.message {
    max-width: 800px;
    margin: 0 auto 20px;
    padding: 16px 20px;
    border-radius: var(--radius-lg);
}

.message.user {
    background: var(--accent-color);
    color: white;
    margin-left: 20%;
}

.message.assistant {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
}

.message-content {
    white-space: pre-wrap;
    word-break: break-word;
}

/* Confidence Indicator */
.confidence-indicator {
    display: inline-block;
    margin-top: 12px;
    padding: 4px 10px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}

/* Sources Loading Indicator */
.sources-loading {
    margin-top: 12px;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
}

/* Query Progress Indicator */
.query-progress {
    max-width: 800px;
    margin: 0 auto 20px;
    padding: 12px 20px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    gap: 12px;
}

.query-progress .progress-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

.query-progress .progress-text {
    color: var(--text-secondary);
    font-size: 13px;
}

/* Source Chips */
.source-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.source-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.source-chip:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.source-chip .number {
    font-weight: 600;
}

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

#query-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
    min-height: 60px;
    transition: border-color var(--transition-fast);
}

#query-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

#query-input:disabled {
    background: var(--bg-secondary);
    cursor: not-allowed;
}

.input-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
}

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

.hint {
    font-size: 12px;
    color: var(--text-muted);
}

/* Voice Input Group */
.voice-input-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.voice-language-select {
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 12px;
    cursor: pointer;
    transition: border-color var(--transition-fast);
}

.voice-language-select:focus {
    outline: none;
    border-color: var(--accent-color);
}

.voice-language-select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Microphone Button */
.btn-mic {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    padding: 0;
}

.btn-mic:hover:not(:disabled) {
    background: var(--bg-tertiary);
    border-color: var(--accent-color);
}

.btn-mic:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-mic img {
    width: 24px;
    height: 24px;
    opacity: 0.7;
    transition: opacity var(--transition-fast);
}

.btn-mic:hover:not(:disabled) img {
    opacity: 1;
}

.btn-mic.recording {
    background: var(--error-color);
    border-color: var(--error-color);
}

.btn-mic.recording img {
    opacity: 1;
    filter: brightness(0) invert(1);
}

/* Recording Popup */
.recording-popup {
    position: fixed;
    bottom: 140px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    z-index: 150;
}

.recording-popup.hidden {
    display: none;
}

.recording-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
}

.recording-dot {
    width: 12px;
    height: 12px;
    background: var(--error-color);
    border-radius: 50%;
    animation: recording-pulse 1s ease-in-out infinite;
}

@keyframes recording-pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(0.8);
    }
}

.recording-text {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

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

.btn-recording {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-recording.btn-cancel {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-recording.btn-cancel:hover {
    background: var(--error-color);
    color: white;
    border-color: var(--error-color);
}

.btn-recording.btn-confirm {
    background: var(--success-color);
    color: white;
}

.btn-recording.btn-confirm:hover {
    filter: brightness(1.1);
}

/* Textarea Wrapper (for spinner positioning) */
.textarea-wrapper {
    position: relative;
}

/* Transcription Loading State */
.input-area.transcribing .textarea-wrapper::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin-centered 0.8s linear infinite;
    pointer-events: none;
    z-index: 10;
}

.input-area.transcribing #query-input {
    background: var(--bg-tertiary);
    opacity: 0.7;
}

/* Loading Spinner */
.loading-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-spinner.hidden {
    display: none;
}

/* Basic spin - for inline elements */
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Centered spin - for absolutely positioned centered elements */
@keyframes spin-centered {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* =============================================================================
   Source Panel
   ============================================================================= */

.source-panel {
    width: var(--source-panel-width);
    background: var(--bg-primary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform var(--transition-normal);
}

.source-panel.hidden {
    display: none;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.panel-header h3 {
    font-size: 14px;
    font-weight: 600;
}

.source-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.source-meta {
    padding: 12px 14px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    font-size: 13px;
}

.source-meta .meta-row {
    margin-bottom: 8px;
}

.source-meta .meta-row:last-of-type {
    margin-bottom: 12px;
}

.source-meta .meta-document {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: baseline;
}

.source-meta .meta-document .value {
    word-break: break-word;
}

.source-meta .meta-split {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
}

.source-meta .meta-left,
.source-meta .meta-right {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.source-meta .meta-right {
    text-align: right;
    flex-shrink: 0;
}

.source-meta .label {
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.source-meta .value {
    font-weight: 500;
    color: var(--text-primary);
}

.source-meta .view-document-btn {
    width: 100%;
    margin-top: 4px;
}

.source-preview {
    padding: 20px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.7;
    max-height: none;
    overflow-y: auto;
}

/* Markdown styling for source preview */
.source-preview h1,
.source-preview h2,
.source-preview h3,
.source-preview h4,
.source-preview h5,
.source-preview h6 {
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
}

.source-preview h1:first-child,
.source-preview h2:first-child,
.source-preview h3:first-child {
    margin-top: 0;
}

.source-preview h1 { font-size: 1.5em; }
.source-preview h2 { font-size: 1.3em; }
.source-preview h3 { font-size: 1.15em; }
.source-preview h4 { font-size: 1em; }

.source-preview p {
    margin-bottom: 1em;
}

.source-preview ul,
.source-preview ol {
    margin: 0.5em 0 1em 1.5em;
    padding: 0;
}

.source-preview li {
    margin-bottom: 0.3em;
}

.source-preview code {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 3px;
}

.source-preview pre {
    background: var(--bg-tertiary);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin: 1em 0;
}

.source-preview pre code {
    background: none;
    padding: 0;
    font-size: 13px;
    line-height: 1.5;
}

.source-preview table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
    font-size: 13px;
}

.source-preview th,
.source-preview td {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    text-align: left;
}

.source-preview th {
    background: var(--bg-tertiary);
    font-weight: 600;
}

.source-preview tr:nth-child(even) {
    background: var(--bg-primary);
}

.source-preview blockquote {
    margin: 1em 0;
    padding: 0.5em 1em;
    border-left: 4px solid var(--accent-color);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.source-preview hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1.5em 0;
}

.source-preview strong {
    font-weight: 600;
}

.source-preview em {
    font-style: italic;
}


/* View document button is now styled within .source-meta */

/* =============================================================================
   Modals
   ============================================================================= */

.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    width: 90%;
    max-width: 700px;
    max-height: 85vh;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
}

.modal-wide {
    max-width: 900px;
}

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

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

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

.modal-close {
    font-size: 24px;
    line-height: 1;
}

/* Document Viewer */
.document-content {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.7;
}

.document-content h1,
.document-content h2,
.document-content h3 {
    margin-top: 24px;
    margin-bottom: 12px;
}

.document-content p {
    margin-bottom: 12px;
}

.document-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
}

.document-content th,
.document-content td {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    text-align: left;
}

.document-content th {
    background: var(--bg-secondary);
    font-weight: 600;
}

.chunk-highlight {
    border: 2px solid var(--accent-color);
    background: rgba(59, 130, 246, 0.1);
    border-radius: var(--radius-md);
    padding: 12px;
    margin: 16px 0;
}

/* =============================================================================
   PDF Viewer Modal
   ============================================================================= */

.modal-pdf-viewer {
    width: 95%;
    max-width: 1200px;
    height: 90vh;
    max-height: 90vh;
}

.modal-pdf-viewer .modal-body {
    flex: 1;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Loading state */
.pdf-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 16px;
}

.pdf-loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: pdf-spin 1s linear infinite;
}

@keyframes pdf-spin {
    to { transform: rotate(360deg); }
}

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

.pdf-cancel-btn {
    margin-top: 8px;
}

/* PDF.js Controls */
.pdf-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    margin-right: 16px;
}

.pdf-controls .btn-icon {
    padding: 4px 8px;
    min-width: 32px;
    font-size: 16px;
    font-weight: bold;
}

.pdf-controls .btn-icon:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#pdf-page-info,
#pdf-zoom-level {
    font-size: 13px;
    color: var(--text-muted);
    min-width: 80px;
    text-align: center;
}

#pdf-zoom-level {
    min-width: 50px;
}

/* PDF.js Scrollable Container */
.pdf-container {
    flex: 1;
    width: 100%;
    overflow: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    gap: 20px;
    background: var(--bg-secondary);
}

.pdf-page-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.pdf-page-label {
    font-size: 12px;
    color: var(--text-muted);
    padding: 2px 8px;
    background: var(--bg-primary);
    border-radius: 4px;
}

.pdf-page-canvas {
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    background: white;
}

/* Mobile/Tablet: full screen PDF viewer */
@media (max-width: 1024px) {
    .modal-pdf-viewer {
        width: 100%;
        height: 100%;
        max-width: none;
        max-height: none;
        border-radius: 0;
    }

    .pdf-controls {
        gap: 4px;
    }

    .pdf-controls .btn-icon {
        padding: 4px 6px;
        min-width: 28px;
    }

    #pdf-page-info {
        min-width: 70px;
        font-size: 12px;
    }

    #pdf-zoom-level {
        min-width: 40px;
        font-size: 12px;
    }
}

/* =============================================================================
   Utility Classes
   ============================================================================= */

.hidden {
    display: none !important;
}

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

.text-center {
    text-align: center;
}

.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }

/* =============================================================================
   Responsive
   ============================================================================= */

@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: var(--header-height);
        bottom: 0;
        transform: translateX(-100%);
        z-index: 50;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .source-panel {
        position: fixed;
        right: 0;
        top: var(--header-height);
        bottom: 0;
        transform: translateX(100%);
        z-index: 50;
        box-shadow: var(--shadow-lg);
    }

    .source-panel:not(.hidden) {
        transform: translateX(0);
    }
}

@media (max-width: 640px) {
    .header-left .toggle-label,
    .header-right .btn-secondary {
        display: none;
    }

    .mode-selector {
        padding: 12px;
    }

    .mode-btn {
        padding: 8px 12px;
        font-size: 12px;
    }

    .chat-container {
        padding: 16px;
    }

    .input-area {
        padding: 12px 16px 16px;
    }

    .message {
        padding: 12px 16px;
    }

    .message.user {
        margin-left: 10%;
    }
}

/* ==========================================================================
   FOLDER LIST STYLES
   ========================================================================== */

.folder-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    padding: 0 16px 16px 16px;
    flex: 1;
    min-height: 0;
}

.folder-item {
    padding: 8px 10px;
    margin-bottom: 6px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

.folder-item:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-color);
}

.folder-item.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: white;
}

.folder-item.active .folder-meta,
.folder-item.active .folder-status {
    color: rgba(255, 255, 255, 0.8);
}

.folder-item.processing {
    border-color: var(--warning-color);
}

/* Icon on the left, vertically centered */
.folder-icon {
    font-size: 20px;
    flex-shrink: 0;
}

/* Right side content */
.folder-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

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

.folder-name {
    flex: 1;
    font-weight: 500;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.folder-status {
    font-size: 10px;
    font-weight: 600;
    flex-shrink: 0;
}

.folder-status.ready {
    color: var(--success-color);
}

.folder-status.unprocessed {
    color: var(--warning-color);
}

.folder-status.processing {
    color: var(--accent-color);
    animation: pulse 1.5s infinite;
}

.folder-meta {
    display: flex;
    gap: 8px;
    font-size: 10px;
    color: var(--text-muted);
}

.folder-meta .count {
    background: var(--bg-primary);
    padding: 1px 5px;
    border-radius: var(--radius-sm);
}

.folder-item.active .folder-meta .count {
    background: rgba(255, 255, 255, 0.2);
}

.folder-actions {
    margin-top: 2px;
}

.folder-actions .btn-use-rag,
.folder-actions .btn-process {
    width: 100%;
    padding: 4px 8px;
    font-size: 10px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
}

.folder-actions .btn-use-rag {
    background: var(--accent-color);
    color: white;
}

.folder-actions .btn-use-rag:hover {
    background: var(--accent-hover);
}

.folder-actions .btn-process {
    background: var(--warning-color);
    color: white;
}

.folder-actions .btn-process:hover {
    opacity: 0.9;
}

.folder-actions .active-badge {
    display: block;
    width: 100%;
    padding: 4px 8px;
    font-size: 10px;
    font-weight: 500;
    text-align: center;
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-sm);
}

/* Folder Progress Bar */
.folder-progress {
    margin-top: 6px;
}

.folder-progress .progress-bar {
    height: 4px;
    background: var(--bg-primary);
    border-radius: 2px;
    overflow: hidden;
}

.folder-progress .progress-fill {
    height: 100%;
    background: var(--accent-color);
    transition: width 0.3s ease;
}

.folder-progress .progress-text {
    margin-top: 4px;
    font-size: 10px;
    color: var(--text-muted);
}

/* Folder Detail Panel (in source panel) */
.folder-detail {
    padding: 8px 0;
}

.folder-detail h3 {
    font-size: 18px;
    margin-bottom: 12px;
}

.folder-detail .folder-status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 16px;
}

.folder-detail .folder-status-badge.ready {
    background: var(--success-color);
    color: white;
}

.folder-detail .folder-status-badge.unprocessed {
    background: var(--warning-color);
    color: white;
}

.folder-detail .folder-status-badge.processing {
    background: var(--accent-color);
    color: white;
}

.folder-detail .folder-section {
    margin-bottom: 16px;
}

.folder-detail .folder-section h4 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.folder-detail .file-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 200px;
    overflow-y: auto;
}

.folder-detail .file-list li {
    padding: 4px 8px;
    font-size: 12px;
    font-family: monospace;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
}

.folder-detail .file-list li.muted {
    color: var(--text-muted);
    font-style: italic;
    font-family: inherit;
}

.folder-detail .folder-actions-panel {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.folder-detail .folder-actions-panel .btn-primary {
    width: 100%;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    background: var(--accent-color);
    color: white;
    cursor: pointer;
    transition: background 0.15s ease;
}

.folder-detail .folder-actions-panel .btn-primary:hover {
    background: var(--accent-hover);
}

.folder-detail .active-indicator {
    text-align: center;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--success-color);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

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

/* =============================================================================
   Markdown Images
   ============================================================================= */

.md-image {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    margin: 12px 0;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.md-image:hover {
    border-color: var(--accent-color);
    cursor: pointer;
}

.image-placeholder {
    display: inline-block;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 12px;
    font-style: italic;
}

/* =============================================================================
   Source Panel Segment Highlighting
   ============================================================================= */

/* Center segment (the retrieved chunk) - green */
.segment-center {
    background-color: rgba(74, 222, 128, 0.15);
    border-left: 4px solid #22c55e;
    padding: 1rem;
    margin: 0.5rem 0;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

/* Neighbor segment (context padding) - yellow */
.segment-neighbor {
    background-color: rgba(250, 204, 21, 0.1);
    border-left: 4px solid #eab308;
    padding: 1rem;
    margin: 0.5rem 0;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    opacity: 0.85;
}

/* Segment labels */
.segment-label {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
}

.segment-center .segment-label {
    background-color: rgba(74, 222, 128, 0.3);
    color: #166534;
}

.segment-neighbor .segment-label {
    background-color: rgba(250, 204, 21, 0.3);
    color: #854d0e;
}

/* Segment content styling */
.segment-content {
    font-size: 13px;
    line-height: 1.6;
}

.segment-content p:first-child {
    margin-top: 0;
}

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

/* Source preview scroll behavior */
.source-preview {
    max-height: 60vh;
    overflow-y: auto;
    scroll-behavior: smooth;
}

/* Dark mode segment styles */
body.dark .segment-center {
    background-color: rgba(74, 222, 128, 0.1);
    border-left-color: #4ade80;
}

body.dark .segment-center .segment-label {
    background-color: rgba(74, 222, 128, 0.2);
    color: #86efac;
}

body.dark .segment-neighbor {
    background-color: rgba(250, 204, 21, 0.08);
    border-left-color: #fbbf24;
}

body.dark .segment-neighbor .segment-label {
    background-color: rgba(250, 204, 21, 0.15);
    color: #fcd34d;
}
