/* ==================== Optimized Styles - Main Import File ==================== */

/* Import order is important for proper CSS cascade */

/* 1. CSS Variables Foundation */
@import url('./variables.css');

/* 2. Base styles and typography */
@import url('./base.css');

/* 3. Animation system */
@import url('./animations-optimized.css');

/* 4. Layout and component styles */
@import url('./components.css');
@import url('./charts.css');

/* 5. Chat-specific components */
@import url('./chat.css');

/* 6. UI elements (modals, citations, images) */
@import url('./ui-elements.css');

/* 7. Theme system */
@import url('./themes-optimized.css');

/* 8. Responsive design (should be last) */
@import url('./responsive.css');

/* ==================== Critical Inline Styles (Minimal) ==================== */

/* Only the most critical styles that must be inline for performance */
/* Prevent layout shift */
.app-container {
    min-height: 100vh;
}

/* ==================== Legacy Compatibility ==================== */

/* Maintain backwards compatibility with existing class names */

/* Legacy spacing classes */
.spacing-xs { padding: var(--space-1); }
.spacing-sm { padding: var(--space-2); }
.spacing-md { padding: var(--space-4); }
.spacing-lg { padding: var(--space-6); }
.spacing-xl { padding: var(--space-8); }

.margin-xs { margin: var(--space-1); }
.margin-sm { margin: var(--space-2); }
.margin-md { margin: var(--space-4); }
.margin-lg { margin: var(--space-6); }
.margin-xl { margin: var(--space-8); }

/* Legacy color classes */
.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-inverse { color: var(--text-inverse); }

.bg-primary { background: var(--bg-primary); }
.bg-secondary { background: var(--bg-secondary); }
.bg-tertiary { background: var(--bg-tertiary); }
.bg-surface { background: var(--surface); }

/* Legacy border classes */
.border { border: 1px solid var(--border-color); }
.border-hover:hover { border-color: var(--border-color-hover); }

/* ==================== Performance Optimizations ==================== */

/* GPU acceleration for frequently animated elements */
.send-button,
.carousel-btn,
.reference-item,
.prompt-card {
    transform: translateZ(0);
    will-change: transform;
}

/* Remove will-change after animations */
.animation-complete {
    will-change: auto;
}

/* Optimize scrolling performance */
.qa-content,
.references-list {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Optimize font rendering */
body {
    text-rendering: optimizeLegibility;
    font-feature-settings: "kern" 1;
    -webkit-font-feature-settings: "kern" 1;
    -moz-font-feature-settings: "kern" 1;
}

/* ==================== Development Helpers ==================== */

/* Only included in development builds */
@media screen and (min-width: 0px) {
    .debug-grid {
        background-image: 
            linear-gradient(rgba(255, 0, 0, 0.1) 1px, transparent 1px),
            linear-gradient(90deg, rgba(255, 0, 0, 0.1) 1px, transparent 1px);
        background-size: 10px 10px;
    }
    
    .debug-spacing * {
        outline: 1px solid rgba(255, 0, 0, 0.2);
    }
}

/* ==================== Browser Specific Fixes ==================== */

/* Safari fixes */
@supports (-webkit-appearance: none) {
    .input-wrapper {
        -webkit-appearance: none;
    }
    
    .message-input {
        -webkit-appearance: none;
        -webkit-border-radius: 0;
    }
}

/* Firefox fixes */
@-moz-document url-prefix() {
    .reference-item {
        scrollbar-width: thin;
    }
}

/* Edge fixes */
@supports (-ms-ime-align: auto) {
    .chat-layout {
        grid-template-columns: 70% 20px 30%;
    }
}

/* ==================== Accessibility Enhancements ==================== */

/* Focus visible for keyboard navigation */
@media (prefers-reduced-motion: no-preference) {
    .focus-visible {
        outline: 2px solid var(--primary);
        outline-offset: 2px;
    }
}

/* ==================== Inline Citations - Improved Compact Style ==================== */
.inline-citation {
    font-size: 0.8em;
    vertical-align: baseline;
    transform: translateY(-0.2em);
    color: var(--text-primary);
    cursor: pointer;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    padding: 1px 3px;
    margin: 0 1px;
    text-decoration: none;
    font-weight: 500;
    display: inline-block;
    line-height: 1;
    transition: all 0.2s ease;
    position: relative;
    white-space: nowrap;
}

.inline-citation:hover {
    background: var(--primary);
    color: var(--text-on-primary);
    border-color: var(--primary);
    text-decoration: none;
    transform: translateY(-0.3em);
    box-shadow: 0 2px 4px color-mix(in srgb, var(--primary) 20%, transparent);
}

.inline-citation.active-citation {
    background: var(--success);
    color: white;
    border-color: var(--success);
    font-weight: 600;
}

.citation-doc-name {
    font-size: 0.7em;
    font-weight: 400;
    opacity: 0.8;
    margin-left: 0.15rem;
    letter-spacing: 0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 90px;
    display: inline;
    vertical-align: baseline;
    color: inherit;
    line-height: 1;
}

/* Citation Synchronization - Higher Priority */
.inline-citation.hidden-numbers .citation-number,
.reference-number.hidden-numbers {
    opacity: 0 !important;
    visibility: hidden !important;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.citation-number {
    display: inline;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

/* Enhanced Citation Tooltips */
.citation-tooltip {
    position: fixed;
    background: #1f2937;
    color: #d1d5db;
    border: 1px solid #374151;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.8rem;
    font-weight: 400;
    line-height: 1.4;
    z-index: 1000;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3), 0 4px 10px rgba(0, 0, 0, 0.2);
    pointer-events: none;
    max-width: 300px;
    white-space: pre-line;
}

/* Dark theme tooltip adjustments */
body.dark-theme .citation-tooltip {
    background: var(--surface-secondary);
    color: var(--text-secondary);
    border-color: var(--border-color);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5), 0 4px 10px rgba(0, 0, 0, 0.3);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .reference-item,
    .prompt-card,
    .citation-image-container {
        border-width: 2px;
    }

    .inline-citation {
        border: 2px solid currentColor;
    }
}

/* Forced colors mode (Windows High Contrast) */
@media (forced-colors: active) {
    .reference-item,
    .prompt-card {
        border: 1px solid ButtonText;
    }
    
    .inline-citation {
        background: Highlight;
        color: HighlightText;
        border: 1px solid ButtonText;
    }
    
    .send-button {
        background: Highlight;
        color: HighlightText;
        border: 1px solid ButtonText;
    }
}
/* ========================================
   FOLDER FILTER TOOLBAR
   ======================================== */

/* Input Container - relative positioning for dropdown */
.input-container {
    position: relative;
}

.input-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: var(--space-1);
    color: var(--text-tertiary);
    font-size: var(--text-xs);
    text-align: center;
}

/* Filter Toolbar Container */
.filter-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    flex-wrap: wrap;
    min-height: 2rem;
}

/* Filter Pills Container */
.filter-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    flex: 1;
}

/* Individual Filter Pill */
.filter-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.filter-pill i {
    font-size: 0.875rem;
    color: var(--text-tertiary);
}

.filter-pill:hover {
    border-color: var(--text-tertiary);
    background: var(--surface-hover);
}

/* Pill Remove Button */
.pill-remove {
    background: transparent;
    border: none;
    border-radius: 50%;
    width: 1rem;
    height: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    color: var(--text-tertiary);
}

.pill-remove:hover {
    background: var(--surface-hover);
    color: var(--danger-text);
}

.pill-remove i {
    font-size: 0.75rem;
}

/* Add Filter Button */
.add-filter-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    background: transparent;
    border: none;
    border-radius: 0.375rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.add-filter-btn:hover {
    background: var(--surface-hover);
    color: var(--primary);
}

.add-filter-btn i {
    font-size: 1.125rem;
}


/* Folder Selection Dropdown */
.folder-dropdown {
    position: absolute;
    bottom: 100%;
    right: 1rem;
    margin-bottom: 0.5rem;
    width: 320px;
    max-width: calc(100% - 2rem);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    overflow: hidden;
}

/* Dropdown Header */
.dropdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.dropdown-header h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.dropdown-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.dropdown-close:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.dropdown-close i {
    font-size: 1.25rem;
}

/* Dropdown Content */
.dropdown-content {
    padding: 0.5rem;
    max-height: 300px;
    overflow-y: auto;
}

/* Folder Option */
.folder-option {
    border-radius: 0.5rem;
    transition: background 0.2s ease;
}

.folder-option:hover {
    background: var(--surface-hover);
}

.folder-option label {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    cursor: pointer;
    gap: 0.75rem;
    width: 100%;
}

.folder-option input[type="checkbox"] {
    width: 1.125rem;
    height: 1.125rem;
    cursor: pointer;
    accent-color: var(--primary);
}

.folder-name {
    flex: 1;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.folder-count {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 400;
}


/* Dark Mode Support */
[data-theme="dark"] .filter-dropdown {
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .filter-toolbar {
        padding: 0.5rem 0.75rem;
    }
    
    .folder-dropdown {
        left: 0.5rem;
        right: 0.5rem;
        width: auto;
        max-width: none;
    }
    
    .filter-pill {
        font-size: 0.8125rem;
        padding: 0.3125rem 0.625rem;
    }
}
