/**
 * RAG Modal and Button Styling
 * Knowledge Base functionality for hacka.re
 */

/* RAG Button Icon Styling */
#rag-btn .rag-icon,
header #rag-btn .rag-icon,
.settings #rag-btn .rag-icon,
header .settings #rag-btn .rag-icon {
    font-family: 'Courier New', Monaco, monospace !important;
    font-weight: bold !important;
    font-size: 0.75em !important;
    color: #ffffff !important;
    -webkit-text-fill-color: #ffffff !important;
    text-fill-color: #ffffff !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1) !important;
    letter-spacing: 0.5px !important;
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
    background: none !important;
    -webkit-background-clip: initial !important;
    background-clip: initial !important;
}

#rag-btn:hover .rag-icon {
    color: var(--accent-color) !important;
    -webkit-text-fill-color: var(--accent-color) !important;
    text-fill-color: var(--accent-color) !important;
    text-shadow: 0 0 8px var(--accent-color);
}

/* Ensure RAG icon is visible in all themes - Override any gradient effects */
html .rag-icon,
html.dark-mode .rag-icon,
html.theme-modern .rag-icon,
html.theme-modern.dark-mode .rag-icon,
html.theme-sunset .rag-icon,
html.theme-ocean .rag-icon,
html.theme-forest .rag-icon,
html.theme-midnight .rag-icon,
header .rag-icon,
.settings .rag-icon,
#rag-btn span.rag-icon {
    color: #ffffff !important;
    -webkit-text-fill-color: #ffffff !important;
    text-fill-color: #ffffff !important;
    opacity: 1 !important;
    animation: none !important;
    background: none !important;
    background-image: none !important;
    -webkit-background-clip: initial !important;
    background-clip: initial !important;
}

/* Ultimate override for RAG icon visibility - Maximum specificity */
body header .settings #rag-btn span.rag-icon {
    color: #ffffff !important;
    -webkit-text-fill-color: #ffffff !important;
    text-fill-color: #ffffff !important;
    opacity: 1 !important;
    animation: none !important;
    background: none !important;
    background-image: none !important;
    -webkit-background-clip: initial !important;
    background-clip: initial !important;
    font-family: 'Courier New', Monaco, monospace !important;
    font-weight: bold !important;
    font-size: 0.75em !important;
}

/* RAG Modal Sections */
.rag-section {
    margin-bottom: 20px;
    padding: 15px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--bg-color-secondary);
}

/* RAG Enable/Disable Section */
.rag-enable-section {
    border-color: var(--accent-color);
    background-color: var(--bg-color);
}

.rag-enable-section .checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    margin-bottom: 8px;
}

.rag-enable-section .checkbox-label strong {
    margin-left: 8px;
    color: var(--text-color);
    font-size: 1.1em;
}

.rag-enable-section input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-right: 8px;
}

.rag-enable-section .form-help {
    margin-left: 26px;
    margin-bottom: 0;
    font-style: italic;
}

.rag-section h3 {
    margin: 0 0 10px 0;
    color: var(--text-color);
    font-size: 1.1em;
    font-weight: 600;
}

.rag-section .form-help {
    margin-bottom: 15px;
    font-size: 0.9em;
    color: var(--text-color-secondary);
}

/* RAG Status Bar */
.rag-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 15px;
}

.rag-stats {
    display: flex;
    gap: 15px;
}

.rag-stats span {
    font-size: 0.9em;
    color: var(--text-color-secondary);
    padding: 2px 8px;
    background-color: var(--bg-color-secondary);
    border-radius: 4px;
}

/* RAG Prompts List */
.rag-prompts-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--bg-color);
}

.rag-prompt-item {
    display: flex;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s ease;
}

.rag-prompt-item.indexed {
    background-color: var(--bg-color-success);
    border-left: 3px solid var(--success-color);
}

.rag-prompt-item:last-child {
    border-bottom: none;
}

.rag-prompt-item:hover {
    background-color: var(--bg-color-secondary);
}

.rag-prompt-item input[type="checkbox"] {
    margin-right: 10px;
}

.rag-prompt-item label {
    flex: 1;
    cursor: pointer;
    font-size: 0.9em;
    color: var(--text-color);
}

.rag-prompt-meta {
    font-size: 0.8em;
    color: var(--text-color-secondary);
    margin-left: 10px;
}

/* RAG Indexing Status Indicators */
.rag-indexing-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    font-size: 0.8em;
}

.rag-status-badge {
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.rag-status-badge.indexed {
    background-color: var(--success-color);
    color: white;
}

.rag-status-badge.not-indexed {
    background-color: var(--text-color-secondary);
    color: white;
}

.rag-status-badge.indexing {
    background-color: var(--warning-color);
    color: white;
    animation: pulse 1.5s ease-in-out infinite;
}

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

/* RAG Bundles List */
.rag-bundles-list {
    min-height: 60px;
    padding: 15px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--bg-color);
}

.empty-bundles-state {
    text-align: center;
    color: var(--text-color-secondary);
    font-style: italic;
}

.rag-bundle-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--bg-color-secondary);
    margin-bottom: 10px;
}

.rag-bundle-info {
    flex: 1;
}

.rag-bundle-name {
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 2px;
}

.rag-bundle-stats {
    font-size: 0.8em;
    color: var(--text-color-secondary);
}

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

/* RAG Search Container */
.rag-search-container {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: end;
}

.rag-search-container .form-group {
    margin-bottom: 0;
}

.rag-search-container .form-actions {
    grid-column: 1 / -1;
    margin-top: 10px;
}

/* RAG Search Results */
.rag-search-results {
    margin-top: 15px;
    padding: 15px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--bg-color);
    max-height: 400px;
    overflow-y: auto;
}

.rag-search-header {
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.rag-search-summary {
    font-size: 0.9em;
    color: var(--text-color-secondary);
}

.rag-result-item {
    margin-bottom: 15px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--bg-color-secondary);
}

.rag-result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.rag-result-source {
    font-weight: 600;
    color: var(--text-color);
    font-size: 0.9em;
}

.rag-result-score {
    font-size: 0.8em;
    color: var(--text-color-secondary);
    background-color: var(--bg-color);
    padding: 2px 6px;
    border-radius: 4px;
}

.rag-result-content {
    font-size: 0.9em;
    color: var(--text-color-secondary);
    line-height: 1.4;
    max-height: 100px;
    overflow-y: auto;
}

.rag-result-actions {
    margin-top: 8px;
    display: flex;
    gap: 8px;
}

.rag-result-actions .btn {
    font-size: 0.8em;
    padding: 4px 8px;
}

/* Loading States */
.rag-loading {
    text-align: center;
    padding: 20px;
    color: var(--text-color-secondary);
}

.rag-loading i {
    animation: spin 1s linear infinite;
    margin-right: 8px;
}

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

/* Progress Indicators */
.rag-progress {
    margin: 10px 0;
}

.rag-progress-bar {
    width: 100%;
    height: 6px;
    background-color: var(--bg-color-secondary);
    border-radius: 3px;
    overflow: hidden;
}

.rag-progress-fill {
    height: 100%;
    background-color: var(--accent-color);
    transition: width 0.3s ease;
    border-radius: 3px;
}

.rag-progress-text {
    font-size: 0.8em;
    color: var(--text-color-secondary);
    margin-top: 4px;
}

/* Error States */
.rag-error {
    padding: 12px;
    background-color: #fee;
    border: 1px solid #fcc;
    border-radius: 6px;
    color: #c33;
    font-size: 0.9em;
    margin: 10px 0;
}

.rag-warning {
    padding: 12px;
    background-color: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 6px;
    color: #856404;
    font-size: 0.9em;
    margin: 10px 0;
}

/* Success States */
.rag-success {
    padding: 12px;
    background-color: #d4edda;
    border: 1px solid #c3e6cb;
    border-radius: 6px;
    color: #155724;
    font-size: 0.9em;
    margin: 10px 0;
}

/* Theme-specific adjustments */
.theme-dark .rag-error {
    background-color: rgba(220, 53, 69, 0.1);
    border-color: rgba(220, 53, 69, 0.3);
    color: #f8d7da;
}

.theme-dark .rag-warning {
    background-color: rgba(255, 193, 7, 0.1);
    border-color: rgba(255, 193, 7, 0.3);
    color: #fff3cd;
}

.theme-dark .rag-success {
    background-color: rgba(40, 167, 69, 0.1);
    border-color: rgba(40, 167, 69, 0.3);
    color: #d4edda;
}

/* Responsive Design */
@media (max-width: 768px) {
    .rag-search-container {
        grid-template-columns: 1fr;
    }
    
    .rag-status {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .rag-stats {
        justify-content: center;
    }
    
    .rag-result-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
}

/* RAG Prompts Sections */
.rag-prompts-section {
    margin-bottom: 1.5rem;
}

.rag-section-title {
    margin: 0 0 0.75rem 0;
    font-size: 1em;
    font-weight: 600;
    color: var(--text-color);
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

/* File prompt styling in RAG modal */
.rag-prompts-list .file-prompt-item {
    background-color: rgba(59, 130, 246, 0.03);
    border-left: 3px solid var(--primary-color);
}

.rag-prompts-list .file-prompt-item:hover {
    background-color: rgba(59, 130, 246, 0.06);
}

.rag-prompts-list .file-prompt-item label {
    display: flex;
    align-items: center;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 13px;
}

/* RAG prompt item meta styling for file size info */
.rag-prompt-meta {
    font-size: 0.8em;
    color: var(--text-color-secondary);
    opacity: 0.8;
}

/* Tree structure styles for prompts */
.rag-tree-root {
    margin-bottom: 15px;
}

.rag-tree-header {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background-color: var(--background-color-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-bottom: 2px;
    cursor: pointer;
    user-select: none;
}

.rag-tree-header:hover {
    background-color: var(--background-color-hover);
}

.rag-tree-subsection {
    background-color: var(--background-color);
    font-weight: 600;
    margin-left: 15px;
}

.rag-tree-category-header {
    background-color: var(--background-color-light);
    font-size: 14px;
    font-weight: 500;
    margin-left: 30px;
}

.rag-tree-toggle {
    font-size: 12px;
    margin-right: 8px;
    transition: transform 0.2s;
    min-width: 12px;
    text-align: center;
}

.rag-tree-title {
    font-weight: 500;
}

.rag-tree-content {
    display: none;
    margin-bottom: 5px;
}

.rag-tree-content.expanded {
    display: block;
}

.rag-tree-section {
    margin-bottom: 10px;
}

.rag-tree-category {
    margin-bottom: 5px;
}

/* File upload section styles */
.rag-file-upload-section {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
    padding: 10px;
    background-color: var(--background-color-secondary);
    border-radius: 4px;
}

.file-upload-hint {
    font-size: 12px;
    color: var(--text-color-secondary);
    font-style: italic;
}

/* File list styles */
.rag-files-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--background-color);
}

.rag-file-item {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color-light);
    background-color: var(--background-color);
}

.rag-file-item:last-child {
    border-bottom: none;
}

.rag-file-item.indexed {
    background-color: var(--success-background-color);
}

.rag-file-item input[type="checkbox"] {
    margin-right: 8px;
}

.rag-file-item label {
    flex: 1;
    margin-right: 8px;
    font-weight: 500;
    cursor: pointer;
}

.rag-file-meta {
    font-size: 12px;
    color: var(--text-color-secondary);
    margin-right: 8px;
}

.rag-file-actions {
    display: flex;
    gap: 4px;
}

.rag-file-actions .btn {
    padding: 4px 6px;
    font-size: 12px;
    min-width: auto;
}

.rag-empty-message {
    padding: 20px;
    text-align: center;
    color: var(--text-color-secondary);
    font-style: italic;
}

/* Enhanced prompt item styles for tree structure */
.rag-prompt-item {
    margin-left: 45px;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border-color-light);
}

.rag-prompt-item:last-child {
    border-bottom: none;
}

.rag-prompt-item.file-prompt-item {
    background-color: var(--info-background-color);
}

/* EU Regulatory Documents Section */
.rag-document-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 8px;
    background-color: var(--background-color);
    transition: all 0.2s ease;
}

.rag-document-item:hover {
    background-color: var(--background-color-secondary);
    border-color: var(--primary-color);
}

.rag-document-info {
    display: flex;
    align-items: center;
    flex: 1;
}

.rag-document-info input[type="checkbox"] {
    margin-right: 12px;
}

.rag-document-info label {
    display: flex;
    flex-direction: column;
    cursor: pointer;
    flex: 1;
}

.rag-document-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: 2px;
}

.rag-document-subtitle {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-color-secondary);
    margin-bottom: 4px;
}

.rag-document-status {
    font-size: 12px;
    color: var(--text-color-secondary);
}

.rag-document-status.indexed {
    color: var(--success-color);
}

.rag-document-status.indexing {
    color: var(--warning-color);
}

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

.rag-document-actions .btn {
    padding: 6px 8px;
    min-width: auto;
}

/* Advanced Section */
.rag-advanced-header {
    display: flex;
    align-items: center;
    padding: 8px 0;
    cursor: pointer;
    user-select: none;
    border-bottom: 1px solid var(--border-color-light);
}

.rag-advanced-header:hover {
    background-color: var(--background-color-hover);
}

.rag-advanced-toggle {
    margin-right: 10px;
    font-size: 14px;
    transition: transform 0.2s ease;
    color: var(--text-color-secondary);
    min-width: 16px;
    text-align: center;
}

.rag-advanced-toggle.fa-chevron-down {
    transform: rotate(90deg);
}

.rag-advanced-content {
    padding-top: 15px;
}

.rag-subsection {
    margin-bottom: 20px;
    padding: 15px;
    border: 1px solid var(--border-color-light);
    border-radius: 6px;
    background-color: var(--background-color-secondary);
}

.rag-subsection h4 {
    margin: 0 0 10px 0;
    font-size: 16px;
    color: var(--text-color);
}

/* Document Settings Modal */
.modal-compact {
    max-width: 500px;
}

.rag-settings-info {
    margin-top: 20px;
    padding: 15px;
    background-color: var(--background-color-secondary);
    border-radius: 4px;
    border: 1px solid var(--border-color-light);
}

.info-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.info-item:last-child {
    margin-bottom: 0;
}

.info-label {
    font-weight: 500;
    color: var(--text-color-secondary);
}

/* Animations for refresh button */
.btn .fa-sync-alt.spinning {
    animation: spin 1s linear infinite;
}

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

/* Document Viewer Modal */
.modal-large {
    max-width: 800px;
    max-height: 90vh;
}

.modal-large .modal-body {
    max-height: 70vh;
    overflow-y: auto;
}

.rag-viewer-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background-color: var(--background-color-secondary);
    border-radius: 4px;
    border: 1px solid var(--border-color-light);
    margin-bottom: 20px;
}

.rag-viewer-stats {
    display: flex;
    gap: 20px;
}

.rag-viewer-stats span {
    font-size: 13px;
    color: var(--text-color-secondary);
}

.rag-viewer-stats strong {
    color: var(--text-color);
}

.rag-viewer-legend {
    display: flex;
    align-items: center;
}

.legend-item {
    display: flex;
    align-items: center;
    font-size: 12px;
    color: var(--text-color-secondary);
}

.chunk-overlap-example {
    display: inline-block;
    width: 20px;
    height: 12px;
    background: linear-gradient(90deg, rgba(255, 140, 0, 0.1) 0%, rgba(255, 140, 0, 0.05) 100%);
    border-left: 3px solid rgba(255, 140, 0, 0.3);
    margin-right: 8px;
    border-radius: 2px;
}

.rag-document-content {
    font-family: 'Georgia', 'Times New Roman', serif;
    line-height: 1.6;
    font-size: 14px;
    color: var(--text-color);
    background-color: var(--background-color);
    border: 1px solid var(--border-color-light);
    border-radius: 4px;
    padding: 20px;
    max-height: 400px;
    overflow-y: auto;
}

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

.rag-document-content .chunk-boundary {
    border-top: 3px solid #ff8c00;
    margin: 16px -20px 16px -20px;
    position: relative;
}

.rag-document-content .chunk-boundary::after {
    content: 'Chunk ' attr(data-chunk-number);
    position: absolute;
    top: -12px;
    left: 20px;
    background-color: var(--background-color);
    padding: 2px 8px;
    font-size: 10px;
    color: #ff8c00;
    font-weight: 600;
    text-transform: uppercase;
}

.rag-document-content .chunk-boundary:first-child {
    margin-top: -20px;
}

.rag-document-content .chunk-overlap {
    background: linear-gradient(90deg, rgba(255, 140, 0, 0.1) 0%, rgba(255, 140, 0, 0.05) 100%);
    margin: 0 -20px;
    padding: 8px 20px;
    border-left: 3px solid rgba(255, 140, 0, 0.3);
}

.rag-document-content .chunk-overlap::before {
    content: 'Overlap: Chunk ' attr(data-overlap-chunks);
    display: block;
    font-size: 10px;
    color: #ff8c00;
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 4px;
}