/*
 * Copyright (c) 2026 Sohrab Modi. All rights reserved.
 * No parts of this code can be copied or reused in other environments
 * without the explicit written permission of Sohrab Modi (smodi@i20.io).
 */

/* ============================================================
   COMPONENTS STYLESHEET — Dashboard, Documents, Chat, AI, MCP, Users
   ============================================================ */

/* ---------- DASHBOARD GRID ---------- */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.dash-card {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.dash-card::before {
    content: '';
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.card-documents::before { background: var(--gradient-card-documents); }
.card-chat::before      { background: var(--gradient-card-chat); }
.card-ai::before        { background: var(--gradient-card-ai); }
.card-kg::before        { background: var(--gradient-card-kg); }
.card-mcp::before       { background: var(--gradient-card-mcp); }
.card-users::before     { background: var(--gradient-card-users); }

.dash-card:hover {
    border-color: var(--border-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.dash-card:hover::before {
    opacity: 1;
}

.dash-card-icon {
    position: relative;
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    background: var(--gradient-glow);
}

.dash-card-icon svg {
    width: 24px;
    height: 24px;
    color: var(--primary-400);
}

.card-chat .dash-card-icon svg { color: var(--info); }
.card-ai .dash-card-icon svg { color: var(--accent-400); }
.card-kg .dash-card-icon svg { color: var(--success); }
.card-mcp .dash-card-icon svg { color: var(--warning); }
.card-users .dash-card-icon svg { color: var(--danger); }

.dash-card-content {
    position: relative;
    flex: 1;
}

.dash-card-content h3 {
    font-size: 0.9375rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.dash-card-stat {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 4px;
}

.dash-card-desc {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.dash-card-desc.kg-model-mismatch {
    color: var(--warning);
    font-weight: 500;
}

/* ---------- DOCUMENTS ---------- */
.documents-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.doc-type-tabs {
    display: flex;
    gap: 2px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.tab-btn {
    padding: 6px 16px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition-fast);
}

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

.tab-btn.active {
    color: var(--primary-300);
    background: rgba(99,102,241,0.1);
    border-color: rgba(99,102,241,0.2);
}

.documents-list {
    min-height: 300px;
    max-height: max(300px, calc(100vh - 520px));
    overflow-y: auto;
    padding: 8px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: var(--text-muted);
}

.empty-icon {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.4;
}

.empty-state h3 {
    font-size: 1.125rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 0.875rem;
    max-width: 400px;
}

/* Document row */
.doc-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.doc-row:hover {
    background: var(--bg-card-hover);
}

.doc-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    flex-shrink: 0;
}

.doc-icon.pdf  { background: rgba(239,68,68,0.15); color: #ef4444; }
.doc-icon.img  { background: rgba(59,130,246,0.15); color: #3b82f6; }
.doc-icon.docx { background: rgba(99,102,241,0.15); color: #6366f1; }
.doc-icon.pptx { background: rgba(245,158,11,0.15); color: #f59e0b; }
.doc-icon.csv  { background: rgba(16,185,129,0.15); color: #10b981; }
.doc-icon.txt  { background: rgba(148,163,184,0.15); color: #94a3b8; }
.doc-icon.html { background: rgba(236,72,153,0.15); color: #ec4899; }
.doc-icon.json { background: rgba(168,85,247,0.15); color: #a855f7; }

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

.doc-name {
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.doc-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.doc-row:hover .doc-actions {
    opacity: 1;
}

.doc-actions .icon-btn {
    width: 28px;
    height: 28px;
}

.doc-actions .icon-btn svg {
    width: 14px;
    height: 14px;
}

/* ---------- CHAT ---------- */
.chat-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 0;
    height: calc(100vh - var(--topbar-height));
    margin: -32px;
}

.chat-main {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
}

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

.chat-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.chat-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-sm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.8125rem;
    font-family: inherit;
    transition: all var(--transition-fast);
}

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

.btn-sm svg {
    width: 16px;
    height: 16px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 40px;
}

.welcome-icon {
    width: 72px;
    height: 72px;
    margin-bottom: 20px;
    opacity: 0.8;
}

.welcome-icon svg {
    width: 100%;
    height: 100%;
}

.chat-welcome h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.chat-welcome p {
    color: var(--text-secondary);
    font-size: 0.9375rem;
    margin-bottom: 24px;
}

.example-queries {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.example-query {
    padding: 8px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.example-query:hover {
    border-color: var(--primary-500);
    color: var(--primary-300);
    background: rgba(99,102,241,0.05);
}

/* Chat messages */
.message {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    animation: fadeIn 0.3s ease;
}

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

.message.user .message-avatar {
    background: var(--gradient-primary);
    color: white;
}

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

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

.message-sender {
    font-size: 0.8125rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.message-text {
    font-size: 0.9375rem;
    line-height: 1.7;
    color: var(--text-secondary);
}

.message-text pre {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin: 8px 0;
    overflow-x: auto;
    font-size: 0.8125rem;
}

.message-text code {
    background: var(--bg-input);
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.85em;
}

.message-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 8px;
    display: flex;
    gap: 12px;
}

/* Chat image gallery — displayed inline within assistant messages */
.chat-image-gallery {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.chat-image-card {
    flex: 0 0 auto;
    width: 220px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.chat-image-card:hover {
    border-color: var(--primary-500);
    box-shadow: 0 4px 16px rgba(99,102,241,0.15);
}

.chat-image-card a {
    display: block;
    line-height: 0;
}

.chat-image-card img {
    width: 100%;
    height: 160px;
    object-fit: cover;
    background: var(--bg-input);
    cursor: pointer;
}

.chat-image-caption {
    padding: 8px 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 8px;
    align-items: center;
}

.chat-image-name {
    font-size: 0.75rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 180px;
}

.img-similarity {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--success);
    background: rgba(34,197,94,0.1);
    padding: 1px 6px;
    border-radius: var(--radius-sm);
}

.img-type-badge {
    font-size: 0.625rem;
    color: var(--text-muted);
    background: rgba(100,116,139,0.15);
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    text-transform: capitalize;
}

/* Responsive: stack images on small screens */
@media (max-width: 640px) {
    .chat-image-card {
        width: 100%;
    }
    .chat-image-card img {
        height: 200px;
    }
}

/* Chat input */
.chat-input-area {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    transition: border-color var(--transition-fast);
}

.chat-input-wrapper:focus-within {
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

.chat-input-wrapper textarea {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9375rem;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 120px;
}

.btn-send {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-primary);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    cursor: pointer;
    flex-shrink: 0;
    transition: all var(--transition-fast);
}

.btn-send:hover {
    filter: brightness(1.15);
    transform: scale(1.05);
}

.btn-send svg {
    width: 16px;
    height: 16px;
}

.chat-input-hints {
    display: flex;
    gap: 4px;
    margin-top: 8px;
    font-size: 0.6875rem;
    color: var(--text-muted);
}

.chat-input-hints .sep {
    margin: 0 4px;
}

/* Chat sidebar */
.chat-sidebar {
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    overflow-y: auto;
}

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

.chat-sidebar-header h3 {
    font-size: 0.875rem;
    font-weight: 600;
}

.chat-sources {
    padding: 16px 20px;
    font-size: 0.8125rem;
}

.chat-sources .muted {
    color: var(--text-muted);
    font-style: italic;
}

.source-item {
    padding: 10px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    font-size: 0.8125rem;
}

.source-item .source-name {
    font-weight: 500;
    color: var(--primary-300);
    margin-bottom: 4px;
}

.source-item .source-snippet {
    color: var(--text-muted);
    font-size: 0.75rem;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ---------- GENERATIVE AI ---------- */
.ai-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 20px;
}

.ai-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    transition: border-color var(--transition-normal);
}

.ai-card:hover {
    border-color: var(--border-light);
}

.ai-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.ai-card-header svg {
    width: 22px;
    height: 22px;
    color: var(--primary-400);
    flex-shrink: 0;
}

.ai-card-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.ai-card-desc {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.ai-card-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.output-format-row {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.radio-group {
    display: flex;
    gap: 16px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.radio-label input[type="radio"] {
    accent-color: var(--primary-500);
}

.slider-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.slider-row input[type="range"] {
    width: 100%;
    accent-color: var(--primary-500);
}

.btn-row {
    display: flex;
    gap: 8px;
}

.ai-result {
    margin-top: 16px;
    padding: 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    line-height: 1.6;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    font-family: 'JetBrains Mono', monospace;
}

/* Template action buttons (Download / Save) */
.template-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.template-actions .btn-sm {
    font-size: 0.8rem;
    padding: 6px 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Saved Documents Browser */
.saved-docs-section {
    margin-top: 20px;
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.saved-docs-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.saved-docs-header h4 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.saved-docs-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
}

.saved-docs-list .muted {
    padding: 12px 14px;
    margin: 0;
    font-size: 0.8rem;
}

.saved-doc-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition-fast);
    font-size: 0.8125rem;
}

.saved-doc-item:last-child {
    border-bottom: none;
}

.saved-doc-item:hover {
    background: rgba(99, 102, 241, 0.08);
}

.saved-doc-item.active {
    background: rgba(99, 102, 241, 0.15);
    border-left: 3px solid var(--primary-500);
}

.saved-doc-icon {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    color: var(--text-muted);
}

.saved-doc-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
    font-weight: 500;
}

.saved-doc-meta {
    flex-shrink: 0;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: right;
    line-height: 1.4;
}

.saved-doc-delete {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    line-height: 1;
    transition: color var(--transition-fast), background var(--transition-fast);
}

.saved-doc-delete:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

/* Document Viewer */
.saved-doc-viewer {
    margin-top: 12px;
    border: 1px solid var(--primary-500);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    overflow: hidden;
}

.saved-doc-viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: rgba(99, 102, 241, 0.08);
    border-bottom: 1px solid var(--border);
}

.saved-doc-viewer-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--primary-400);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.saved-doc-viewer-content {
    padding: 14px;
    margin: 0;
    max-height: 400px;
    overflow-y: auto;
    font-size: 0.8rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-secondary);
}

/* ---- Saved Documents Panel (top-level, two-column layout) ---- */

.saved-docs-panel-body {
    display: flex;
    gap: 16px;
    height: calc(100vh - 220px);
    min-height: 300px;
}

.saved-docs-panel-sidebar {
    flex: 0 0 340px;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    overflow: hidden;
}

.saved-docs-panel-list {
    flex: 1;
    overflow-y: auto;
}

.saved-docs-panel-list .muted {
    padding: 12px 14px;
    margin: 0;
    font-size: 0.8rem;
}

.saved-docs-panel-viewer {
    flex: 1;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    overflow: hidden;
}

.saved-docs-panel-viewer-area {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.saved-docs-panel-viewer-area .saved-doc-viewer-content {
    flex: 1;
    max-height: none;
}

.saved-docs-panel-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-muted);
    text-align: center;
    padding: 40px 20px;
}

.saved-docs-panel-empty .empty-icon {
    width: 48px;
    height: 48px;
    opacity: 0.4;
}

.saved-docs-panel-empty h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.saved-docs-panel-empty p {
    margin: 0;
    font-size: 0.8125rem;
}

@media (max-width: 768px) {
    .saved-docs-panel-body {
        flex-direction: column;
        height: auto;
    }
    .saved-docs-panel-sidebar {
        flex: 0 0 auto;
        max-height: 250px;
    }
    .saved-docs-panel-viewer {
        min-height: 300px;
    }
}

/* ---- Binary-file download button (shown in viewer when a .docx/.pdf/etc. is selected) ---- */

.binary-download-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 48px 32px;
    text-align: center;
}

.binary-download-wrap p {
    margin: 0;
    font-size: 0.875rem;
    color: var(--text-muted);
    max-width: 380px;
    line-height: 1.5;
}

.btn-binary-download {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 11px 22px;
    min-width: 160px;
    max-width: 520px;
    background: linear-gradient(135deg, var(--primary-600), var(--accent-500));
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.4;
    letter-spacing: 0.01em;
    word-break: break-word;
    overflow-wrap: anywhere;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), opacity var(--transition-fast);
}

.btn-binary-download:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(99, 102, 241, 0.45);
    opacity: 0.95;
}

.btn-binary-download:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.3);
}

.btn-binary-download svg {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
}

.btn-binary-download .btn-download-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 360px;
}

/* When the filename is very long, allow it to wrap on the second line */
@media (max-width: 600px) {
    .btn-binary-download {
        max-width: 100%;
        padding: 10px 16px;
        font-size: 0.875rem;
    }
    .btn-binary-download .btn-download-name {
        max-width: 220px;
    }
}

.ontology-info {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.info-row {
    display: flex;
    gap: 8px;
    font-size: 0.8125rem;
}

.info-label {
    color: var(--text-muted);
    white-space: nowrap;
}

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

/* ---------- MCP TOOLS ---------- */
.mcp-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.mcp-connection {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
}

.mcp-transport {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.mcp-tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.mcp-tool-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: border-color var(--transition-normal);
}

.mcp-tool-card:hover {
    border-color: var(--border-light);
}

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

.tool-header h3 {
    font-size: 0.9375rem;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    color: var(--primary-300);
}

.tool-badge {
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    background: rgba(99,102,241,0.15);
    color: var(--primary-400);
}

.tool-badge.badge-danger {
    background: rgba(239,68,68,0.15);
    color: var(--danger);
}

.mcp-tool-card > p {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.tool-params {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.tool-result {
    margin-top: 12px;
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    display: none;
}

.tool-result.visible {
    display: block;
}

/* ---------- USERS ---------- */
.users-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.user-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all var(--transition-normal);
}

.user-card:hover {
    border-color: var(--border-light);
}

.user-card-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--gradient-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    font-weight: 600;
    flex-shrink: 0;
}

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

.user-card-name {
    font-weight: 600;
    font-size: 0.9375rem;
}

.user-card-role {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.user-card-actions {
    display: flex;
    gap: 4px;
}

/* ---------- LOADING SPINNER ---------- */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--primary-500);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.spinner-lg {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

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

/* ---------- RESPONSIVE OVERRIDES ---------- */
@media (max-width: 1024px) {
    .chat-layout {
        grid-template-columns: 1fr;
    }

    .chat-sidebar {
        display: none;
    }

    .ai-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .mcp-tools-grid {
        grid-template-columns: 1fr;
    }
}

/* ==============================================================
   DATABASE CONNECTIONS SECTION  (v64)
   Rendered inside the Manage Input Documents panel, below the
   documents list.  Provides registration, testing, deletion, and
   KG indexing for relational (SQLite / MySQL / PostgreSQL) and
   NoSQL (MongoDB / Cassandra / Hive / Redis / DynamoDB) databases.
   ============================================================== */

/* --- Section container & header --- */
.db-connections-section {
    margin-top: 24px;
    border-top: 1px solid var(--border);
    padding-top: 20px;
}

.db-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.db-section-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.db-section-title h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.db-section-title svg {
    color: var(--primary);
    flex-shrink: 0;
}

.db-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: var(--primary);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
}

/* --- Database list (cards) --- */
.db-connections-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 320px;
    overflow-y: auto;
    padding-right: 4px;
}

.db-connections-list .empty-state-sm {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.db-connections-list .empty-state-sm svg {
    width: 36px;
    height: 36px;
    margin: 0 auto 10px;
    display: block;
    opacity: 0.4;
}

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

/* --- Individual database card row --- */
.db-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color 0.15s, background 0.15s;
    cursor: pointer;
}

.db-row:hover {
    background: var(--bg-card-hover);
    border-color: var(--primary);
}

/* Dialect icon badge */
.db-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
}

/* Color coding per dialect */
.db-icon.sqlite    { background: rgba(59,130,246,0.15);  color: #3b82f6; }
.db-icon.mysql     { background: rgba(245,158,11,0.15);  color: #f59e0b; }
.db-icon.postgres  { background: rgba(99,102,241,0.15);  color: #6366f1; }
.db-icon.mongodb   { background: rgba(16,185,129,0.15);  color: #10b981; }
.db-icon.cassandra { background: rgba(168,85,247,0.15);  color: #a855f7; }
.db-icon.hive      { background: rgba(236,72,153,0.15);  color: #ec4899; }
.db-icon.redis     { background: rgba(239,68,68,0.15);   color: #ef4444; }
.db-icon.dynamodb  { background: rgba(245,158,11,0.15);  color: #f59e0b; }

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

.db-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.db-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Action buttons on hover */
.db-actions {
    display: flex;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.15s;
    flex-shrink: 0;
}

.db-row:hover .db-actions {
    opacity: 1;
}

.db-actions .icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}

.db-actions .icon-btn:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.06);
}

.db-actions .icon-btn.btn-danger-icon:hover {
    color: var(--danger);
    background: rgba(239,68,68,0.1);
}

.db-actions .icon-btn svg {
    width: 16px;
    height: 16px;
}

/* --- Add-database modal form --- */
.form-control {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input, var(--bg-card));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: border-color 0.15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99,102,241,0.2);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.form-hint {
    display: block;
    margin-top: 4px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.input-group-password {
    position: relative;
    display: flex;
}

.input-group-password .form-control {
    padding-right: 40px;
}

.btn-toggle-pw {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
}

.btn-toggle-pw:hover {
    color: var(--text-primary);
}

/* --- Test connection result banner --- */
.db-test-result {
    margin-top: 16px;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    line-height: 1.5;
}

.db-test-result.test-success {
    background: rgba(16,185,129,0.1);
    border: 1px solid rgba(16,185,129,0.3);
    color: #10b981;
}

.db-test-result.test-error {
    background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.3);
    color: #ef4444;
}

.db-test-result.test-loading {
    background: rgba(59,130,246,0.1);
    border: 1px solid rgba(59,130,246,0.3);
    color: #3b82f6;
}

/* --- Database details modal --- */
.db-details-grid {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 8px 16px;
    font-size: 0.875rem;
    margin-bottom: 20px;
}

.db-details-grid dt {
    color: var(--text-muted);
    font-weight: 500;
}

.db-details-grid dd {
    color: var(--text-primary);
    margin: 0;
    word-break: break-all;
}

.db-tables-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 0;
}

.db-tables-list .db-table-item {
    padding: 6px 14px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.db-tables-list .db-table-item:hover {
    background: rgba(255,255,255,0.04);
}

/* Responsive adjustments */
@media (max-width: 640px) {
    .db-section-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .db-details-grid {
        grid-template-columns: 1fr;
    }

    .db-row .db-actions {
        opacity: 1;
    }
}
