/**
 * Main stylesheet for RAG Multi Datasource frontend
 */

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

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #6b7280;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-color: #f9fafb;
    --surface-color: #ffffff;
    --text-color: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    height: 100vh;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent container from expanding */
}

/* Header */
.header {
    background: var(--surface-color);
    padding: 1rem 2rem;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Important for flex scrolling */
}

/* Tenant Selector */
.tenant-selector {
    margin-bottom: 2rem;
    padding: 1rem;
    background: var(--surface-color);
    border-radius: 8px;
    box-shadow: var(--shadow);
    flex-shrink: 0; /* Prevent selector from shrinking */
}

.tenant-selector label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

/* Chat Interface */
.chat-container {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    background: var(--surface-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    position: relative;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-color);
    flex-shrink: 0;
}

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

.chat-messages {
    flex: 1 1 auto;
    padding: 1.5rem;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    /* Allow natural expansion - no max-height constraint */
}

.welcome-message {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

.message {
    margin-bottom: 1.5rem;
    padding: 1rem;
    border-radius: 8px;
}

.message-user {
    background: var(--primary-color);
    color: white;
    margin-left: 20%;
    flex-shrink: 0; /* Prevent messages from shrinking */
}

.message-assistant {
    background: var(--bg-color);
    margin-right: 20%;
    flex-shrink: 0; /* Prevent messages from shrinking */
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    opacity: 0.8;
}

.message-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.copy-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    opacity: 0.6;
    transition: opacity 0.2s, background-color 0.2s;
    display: flex;
    align-items: center;
    font-size: 0.875rem;
}

.copy-btn:hover {
    opacity: 1;
    background-color: rgba(0, 0, 0, 0.05);
}

.copy-btn:active {
    opacity: 0.8;
}

.copy-btn.copied {
    opacity: 1;
    color: var(--success-color);
}

.message-content {
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message-content h2,
.message-content h3 {
    margin: 1rem 0 0.5rem 0;
}

.message-content strong {
    font-weight: 600;
    color: inherit;
}

.message-content em {
    font-style: italic;
}

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

.chat-input-container {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    background: var(--surface-color);
    flex-shrink: 0; /* Prevent input container from shrinking */
}

.query-form {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
}

.query-input-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 0; /* Prevent flex item from overflowing */
}

.query-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
    min-height: 3.5rem; /* Ensure minimum height for 3 rows */
    box-sizing: border-box; /* Include padding in height calculation */
}

.query-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.format-selector-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.format-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.format-select {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.875rem;
    background: var(--surface-color);
    color: var(--text-color);
    cursor: pointer;
}

.format-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

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

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

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

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #4b5563;
}

.btn-block {
    width: 100%;
    justify-content: center;
}

/* Spinner */
.spinner {
    width: 1rem;
    height: 1rem;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.tenant-roles-container {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.5rem;
    background: var(--background-color);
}

.tenant-role-item {
    margin-bottom: 0.75rem;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--surface-color);
}

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

.form-text {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: #6c757d;
}

.input,
.select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
}

.input:focus,
.select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Cards */
.card {
    background: var(--surface-color);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.card h3 {
    margin-bottom: 1rem;
    color: var(--text-color);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.section-header h2 {
    margin: 0;
}

/* List Items */
.list-container {
    max-height: 500px;
    overflow-y: auto;
}

.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--surface-color);
    transition: background 0.2s;
}

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

.list-item:hover {
    background: #f9fafb;
}

.list-item-warning {
    border-left: 4px solid var(--warning-color);
}

.list-item-content {
    flex: 1;
}

.list-item-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.list-item-details {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.list-item-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-left: 1rem;
    margin-right: 1rem;
    white-space: nowrap;
}

.list-item-actions {
    display: flex;
    gap: 0.5rem;
    margin-left: auto;
    flex-shrink: 0;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-superuser {
    background: #7c3aed;
    color: white;
}

.badge-admin {
    background: var(--primary-color);
    color: white;
}

.badge-user {
    background: var(--secondary-color);
    color: white;
}

.badge-inactive {
    background: var(--error-color);
    color: white;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
}

.alert-warning {
    background: #fef3c7;
    border: 1px solid var(--warning-color);
    color: #92400e;
}

/* Text Utilities */
.text-muted {
    color: var(--text-secondary);
}

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

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

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

/* Loading State */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

/* Upload Options */
.upload-options {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-top: 0.5rem;
}

/* File input styling */
#fileInput {
    width: 100%;
    padding: 0.5rem;
    margin-top: 0.5rem;
}

.file-count {
    margin-left: auto;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* File List */
.file-list {
    margin: 1rem 0;
    padding: 1rem;
    background: var(--bg-color);
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
}

.file-list h4 {
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

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

.file-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    margin-bottom: 0.25rem;
    background: var(--surface-color);
    border-radius: 0.25rem;
    font-size: 0.875rem;
}

.file-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 1rem;
}

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

/* Upload Progress */
.upload-progress {
    margin: 1rem 0;
}

.progress-bar {
    width: 100%;
    height: 1.5rem;
    background: var(--bg-color);
    border-radius: 0.75rem;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.progress-bar-fill {
    height: 100%;
    background: var(--primary-color);
    transition: width 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.75rem;
    font-weight: 500;
}

.progress-text {
    margin-top: 0.5rem;
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Category Suggestions */
.category-suggestions {
    margin-top: 0.5rem;
    padding: 0.75rem;
    background: var(--bg-color);
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
}

.suggestion-label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.suggestion-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.suggestion-tag {
    padding: 0.25rem 0.75rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    font-size: 0.875rem;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
}

.suggestion-tag:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

/* File Management */
.files-summary {
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: var(--bg-color);
    border-radius: 0.5rem;
    font-size: 0.875rem;
}

.files-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* File support indicators */
.file-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: 8px;
    vertical-align: middle;
}

.file-badge-supported {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #10b981;
}

.file-badge-unsupported {
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid #f59e0b;
}

.file-badge-ingested {
    background-color: #dbeafe;
    color: #1e40af;
    border: 1px solid #3b82f6;
}

.file-badge-ready {
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid #f59e0b;
}

.file-supported {
    border-left: 3px solid #10b981;
}

.file-unsupported {
    border-left: 3px solid #f59e0b;
    opacity: 0.85;
}

.file-stats {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.stat-supported {
    color: #065f46;
}

.stat-unsupported {
    color: #92400e;
}

.stat-unknown {
    color: var(--text-secondary);
}

.skipped-files {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background-color: #f3f4f6;
    border-radius: 4px;
    color: var(--text-secondary);
}

.file-item-managed {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    transition: all 0.2s ease;
}

.file-item-managed:hover {
    box-shadow: var(--shadow);
    border-color: var(--primary-color);
}

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

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

.file-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.file-size-managed {
    font-weight: 500;
}

.file-date {
    font-size: 0.75rem;
}

/* System Health Dashboard */
.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.status-item {
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
    background: var(--bg-color);
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
}

.status-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.status-value {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-color);
    word-break: break-all;
}

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

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

.collections-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.collection-item {
    padding: 1rem;
    background: var(--bg-color);
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
}

.collection-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.collection-details {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.chunk-type {
    margin-top: 0.25rem;
    padding-left: 1rem;
}

.overview-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.stat-card {
    padding: 1.5rem;
    background: var(--bg-color);
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.error {
    color: var(--error-color);
    padding: 1rem;
}

/* Filter Controls */
.filter-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.filter-controls label {
    margin: 0;
}

/* Button Sizes */
.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-danger {
    background: var(--error-color);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

/* Modal Actions */
.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background-color: var(--surface-color);
    margin: 10% auto;
    padding: 2rem;
    border-radius: 8px;
    width: 90%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    position: relative;
}

.close {
    position: absolute;
    right: 1rem;
    top: 1rem;
    font-size: 2rem;
    font-weight: bold;
    color: var(--text-secondary);
    cursor: pointer;
}

.close:hover {
    color: var(--text-color);
}

/* Sections - override for user management page */
.section {
    background: var(--surface-color);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.section h2 {
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

/* Messages */
.message {
    padding: 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
}

.message-success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid var(--success-color);
}

.message-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid var(--error-color);
}

.error-message {
    color: var(--error-color);
    margin-top: 0.5rem;
    font-size: 0.875rem;
}

/* Jobs */
.jobs-list,
.history-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.job-item,
.history-item {
    padding: 1rem;
    background: var(--bg-color);
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.job-header,
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.job-status,
.history-status {
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-size: 0.875rem;
    font-weight: 500;
}

.job-status-pending,
.history-status-pending {
    background: #fef3c7;
    color: #92400e;
}

.job-status-running,
.history-status-running {
    background: #dbeafe;
    color: #1e40af;
}

.job-status-completed,
.history-status-completed {
    background: #d1fae5;
    color: #065f46;
}

.job-status-failed,
.history-status-failed {
    background: #fee2e2;
    color: #991b1b;
}

/* Navigation */
.nav {
    background: var(--surface-color);
    padding: 1rem;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-shrink: 0; /* Prevent nav from shrinking */
}

.nav-btn {
    padding: 0.75rem 1.5rem;
    border: 2px solid var(--border-color);
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

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

/* Responsive */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 1rem;
    }

    .main-content {
        padding: 1rem;
    }

    .query-form {
        flex-direction: column;
    }

    .message-user {
        margin-left: 0;
    }

    .message-assistant {
        margin-right: 0;
    }
}
