/* ═══════════════════════════════════════════════════════════
   Scientific Multimodal RAG — Design System
   Dark-mode, glassmorphism, premium aesthetics
   ═══════════════════════════════════════════════════════════ */

/* ── Reset & Base ──────────────────────────────────────────── */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Surface colors */
    --bg-primary: #F2F4F7;
    --bg-secondary: #FFFFFF;
    --bg-tertiary: #E5E7EB;
    --bg-card: rgba(255, 255, 255, 0.8);
    --bg-glass: rgba(0, 0, 0, 0.03);

    /* Accent */
    --accent-indigo: #99BFA7;
    /* Sage Green from image */
    --accent-blue: #5A8DBA;
    --accent-cyan: #4BAEBD;
    --accent-purple: #8B7DC7;
    --accent-green: #99BFA7;
    --accent-amber: #D97706;
    --accent-red: #DC2626;

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #99BFA7, #7A9F88);
    --gradient-accent: linear-gradient(135deg, #99BFA7, #5A8DBA);
    --gradient-surface: linear-gradient(180deg, rgba(0, 0, 0, 0.02) 0%, rgba(0, 0, 0, 0.04) 100%);

    /* Text */
    --text-primary: #1F2937;
    --text-secondary: #4B5563;
    --text-tertiary: #9CA3AF;
    --text-accent: #7A9F88;

    /* Borders */
    --border-subtle: rgba(0, 0, 0, 0.08);
    --border-light: rgba(0, 0, 0, 0.12);
    --border-accent: rgba(153, 191, 167, 0.4);

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
    --shadow-glow: 0 0 20px rgba(153, 191, 167, 0.2);

    /* Spacing */
    --sidebar-width: 300px;
    --source-panel-width: 380px;
    --header-height: 56px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-smooth: 350ms cubic-bezier(0.4, 0, 0.2, 1);
}

[hidden] {
    display: none !important;
}

html,
body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ── Header ────────────────────────────────────────────────── */
#app-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
    position: relative;
    z-index: 100;
}

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

.logo-mark {
    display: flex;
    align-items: center;
    filter: drop-shadow(0 0 8px rgba(153, 191, 167, 0.3));
}

#app-header h1 {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.3px;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-badge {
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--accent-cyan);
    background: rgba(0, 212, 255, 0.1);
    padding: 3px 8px;
    border-radius: 20px;
    border: 1px solid rgba(0, 212, 255, 0.2);
}

.btn-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-icon:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--border-accent);
}

/* ── Main Layout ───────────────────────────────────────────── */
#app-main {
    display: flex;
    height: calc(100vh - var(--header-height));
    overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────── */
#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-light) transparent;
}

.sidebar-section {
    padding: 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-tertiary);
    margin-bottom: 12px;
}

/* Dropzone */
.dropzone {
    border: 2px dashed var(--border-light);
    border-radius: var(--radius-md);
    padding: 28px 16px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-normal);
    background: var(--bg-glass);
}

.dropzone:hover,
.dropzone.drag-over {
    border-color: var(--accent-indigo);
    background: rgba(153, 191, 167, 0.05);
    box-shadow: var(--shadow-glow);
}

.dropzone.drag-over {
    transform: scale(1.01);
}

.dropzone-icon {
    color: var(--text-tertiary);
    margin-bottom: 8px;
    transition: color var(--transition-normal);
}

.dropzone:hover .dropzone-icon {
    color: var(--accent-indigo);
}

.dropzone-text {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.dropzone-hint {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 4px;
}

/* Progress */
.progress-container {
    margin-top: 16px;
    animation: fadeIn 0.3s ease;
}

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

.progress-filename {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

.progress-status {
    font-size: 11px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 20px;
}

.progress-status.active {
    color: var(--accent-cyan);
    background: rgba(0, 212, 255, 0.1);
}

.progress-status.complete {
    color: var(--accent-green);
    background: rgba(52, 211, 153, 0.1);
}

.progress-status.error {
    color: var(--accent-red);
    background: rgba(239, 68, 68, 0.1);
}

.progress-bar-track {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: var(--gradient-accent);
    border-radius: 3px;
    transition: width 0.4s ease;
    position: relative;
}

.progress-bar-fill.active::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.3) 50%, transparent 100%);
    animation: shimmer 1.5s infinite;
}

.progress-message {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 8px;
}

/* Documents List */
.documents-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.empty-state {
    font-size: 12px;
    color: var(--text-tertiary);
    text-align: center;
    padding: 20px 0;
    font-style: italic;
}

.doc-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    border: 1px solid var(--border-subtle);
    transition: all var(--transition-fast);
    cursor: default;
}

.doc-item:hover {
    border-color: var(--border-accent);
    background: rgba(153, 191, 167, 0.05);
}

.doc-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: var(--gradient-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

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

.doc-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-pages {
    font-size: 10px;
    color: var(--text-tertiary);
}

.doc-delete {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    opacity: 0;
}

.doc-item:hover .doc-delete {
    opacity: 1;
}

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

/* ── Chat Area ─────────────────────────────────────────────── */
#chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-primary);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 32px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scrollbar-width: thin;
    scrollbar-color: var(--border-light) transparent;
}

/* Messages */
.message {
    display: flex;
    max-width: 720px;
    animation: fadeSlideUp 0.3s ease;
}

.message-user {
    align-self: flex-end;
}

.message-ai {
    align-self: flex-start;
}

.message-system {
    align-self: center;
    max-width: 560px;
}

.message-content {
    padding: 14px 18px;
    border-radius: var(--radius-md);
    font-size: 13.5px;
    line-height: 1.7;
}

.message-user .message-content {
    background: var(--accent-indigo);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-ai .message-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.message-system .message-content {
    text-align: center;
    background: var(--bg-glass);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 32px;
}

.message-system h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.message-system p {
    color: var(--text-secondary);
    font-size: 13px;
}

.welcome-features {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    justify-content: center;
}

.feature-card {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    background: rgba(153, 191, 167, 0.1);
    border: 1px solid rgba(153, 191, 167, 0.2);
    font-size: 12px;
    color: var(--text-accent);
}

.feature-icon {
    font-size: 16px;
}

/* AI message extras */
.ai-citation-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 12px;
    padding: 4px 10px;
    border-radius: 20px;
    background: rgba(52, 211, 153, 0.1);
    border: 1px solid rgba(52, 211, 153, 0.2);
    font-size: 11px;
    color: var(--accent-green);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.ai-citation-badge:hover {
    background: rgba(52, 211, 153, 0.15);
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 14px 18px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-tertiary);
    animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

/* Chat Input */
.chat-input-area {
    padding: 16px 32px 24px;
    display: flex;
    justify-content: center;
    background: var(--bg-primary);
    border-top: 1px solid rgba(0, 0, 0, 0.04);
}

.chat-input-wrapper {
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 950px;
    background: var(--bg-secondary);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 9999px;
    padding: 6px 6px 6px 24px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.03), 0 1px 2px rgba(0, 0, 0, 0.02);
    transition: all var(--transition-normal);
}

.chat-input-wrapper:focus-within {
    border-color: var(--accent-indigo);
    box-shadow: 0 4px 20px rgba(153, 191, 167, 0.15), 0 1px 2px rgba(0, 0, 0, 0.02);
}

#chat-input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 8px 12px 8px 0;
    margin: 0;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 120px;
    display: block;
    box-shadow: none !important;
}

#chat-input::placeholder {
    color: var(--text-tertiary);
}

.btn-send {
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: #E8EBF0;
    color: #475569;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

#chat-input:not(:placeholder-shown) ~ .btn-send {
    background: var(--accent-indigo);
    color: white;
}

.btn-send:hover:not(:disabled) {
    background: #DCE1E8;
    color: #1E293B;
    transform: scale(1.05);
}

#chat-input:not(:placeholder-shown) ~ .btn-send:hover:not(:disabled) {
    background: #87ad95;
    color: white;
}

.btn-send:active:not(:disabled) {
    transform: scale(0.95);
}

.btn-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: #F1F5F9;
    color: var(--text-tertiary);
    transform: none;
}

/* ── Source Panel ───────────────────────────────────────────── */
.source-panel {
    width: var(--source-panel-width);
    min-width: var(--source-panel-width);
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideInRight 0.3s ease;
}

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

.source-panel-header h2 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.source-chunks {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scrollbar-width: thin;
    scrollbar-color: var(--border-light) transparent;
}

.source-chunk-card {
    border-radius: var(--radius-md);
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    overflow: hidden;
    transition: all var(--transition-fast);
    backdrop-filter: blur(8px);
}

.source-chunk-card:hover {
    border-color: var(--border-accent);
    box-shadow: var(--shadow-md);
}

.chunk-body {
    padding: 12px 14px;
}

.chunk-meta {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.chunk-tag {
    font-size: 10px;
    font-weight: 500;
    font-family: 'JetBrains Mono', monospace;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(153, 191, 167, 0.1);
    color: var(--accent-indigo);
    border: 1px solid rgba(153, 191, 167, 0.2);
}

.chunk-tag.page {
    background: rgba(59, 130, 246, 0.1);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.chunk-tag.source-id {
    background: rgba(139, 92, 246, 0.1);
    color: #a78bfa;
    border: 1px solid rgba(139, 92, 246, 0.2);
    font-weight: 600;
}

.chunk-distance-inline {
    font-size: 9px;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-tertiary);
    margin-left: auto;
}

.chunk-text {
    font-size: 11.5px;
    line-height: 1.6;
    color: var(--text-secondary);
    max-height: 200px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-light) transparent;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Conditional thumbnail for visual chunks in source panel */
.chunk-thumb {
    width: 100%;
    max-height: 200px;
    object-fit: contain;
    border-top: 1px solid var(--border-subtle);
    margin-top: 10px;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    background: var(--bg-tertiary);
    cursor: pointer;
    transition: opacity var(--transition-fast);
}

.chunk-thumb:hover {
    opacity: 0.85;
}

.supplementary {
    border-color: rgba(52, 211, 153, 0.25) !important;
    background: rgba(52, 211, 153, 0.03) !important;
}

/* Caption block in source panel for figure chunks */
.chunk-caption {
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 6px;
    padding: 5px 8px;
    border-left: 2px solid rgba(153, 191, 167, 0.4);
    background: rgba(153, 191, 167, 0.04);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    word-break: break-word;
}

/* ── Chat Inline Images ──────────────────────────────────── */
.chat-inline-images {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 14px;
}

.chat-inline-image {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border-subtle);
    cursor: pointer;
    transition: all var(--transition-fast);
    background: var(--bg-tertiary);
}

.chat-inline-image:hover {
    border-color: var(--border-accent);
    box-shadow: var(--shadow-md);
}

.chat-inline-image img {
    width: 100%;
    display: block;
    object-fit: contain;
    max-height: 400px;
}

.chat-inline-image-label {
    font-size: 10px;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    backdrop-filter: blur(4px);
}

/* Footer row inside each inline image (badge + caption) */
.chat-inline-image-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(6px);
    flex-wrap: wrap;
}

/* Visual type badge e.g. 📊 chart */
.chat-visual-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    padding: 2px 7px;
    border-radius: 4px;
    background: rgba(99, 102, 241, 0.25);
    color: #a5b4fc;
    border: 1px solid rgba(99, 102, 241, 0.3);
    flex-shrink: 0;
}

/* Caption text below inline image */
.chat-inline-image-caption {
    font-size: 10.5px;
    color: rgba(255, 255, 255, 0.85);
    line-height: 1.4;
    flex: 1;
}

/* ── Telemetry Overlay ─────────────────────────────────────── */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.overlay-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 720px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: scaleIn 0.25s ease;
}

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

.overlay-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.telemetry-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    padding: 20px 24px;
}

.telemetry-card {
    padding: 16px;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    border: 1px solid var(--border-subtle);
}

.telemetry-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-tertiary);
    margin-bottom: 6px;
}

.telemetry-value {
    font-size: 22px;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    background: var(--gradient-accent);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.telemetry-unit {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 2px;
}

/* Categorized Sections */
.telemetry-section {
    margin-bottom: 24px;
}

.telemetry-section:last-child {
    margin-bottom: 0;
}

.telemetry-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-accent);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 24px;
}

.telemetry-section-title::before {
    content: '';
    display: block;
    width: 4px;
    height: 14px;
    background: var(--gradient-primary);
    border-radius: 2px;
}

.telemetry-formula {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed var(--border-subtle);
    font-size: 9.5px;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-tertiary);
    line-height: 1.4;
}

.formula-label {
    font-weight: 600;
    color: var(--text-secondary);
    margin-right: 4px;
}

/* ── Animations ────────────────────────────────────────────── */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes fadeSlideUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes scaleIn {
    from {
        transform: scale(0.95);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(100%);
    }
}

@keyframes typingBounce {

    0%,
    80%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-6px);
    }
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 260px;
        --source-panel-width: 320px;
    }
}

@media (max-width: 768px) {
    #sidebar {
        display: none;
    }

    .source-panel {
        display: none;
    }

    .chat-messages {
        padding: 16px;
    }

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

    .welcome-features {
        flex-direction: column;
    }
}