/* ==========================================================================
   Import Global CSS Variables & Design System
   ========================================================================== */
@import url('./global.css');

/* ==========================================================================
   Base & General Layout Styles
   ========================================================================== */
html {
    height: 100%;
    /* Ensure html takes full height */
}

body {
    font-family: var(--font-family-base);
    margin: 0;
    padding: 0;
    background-color: var(--color-bg-primary);
    color: var(--color-text-primary);
    line-height: var(--line-height-normal);
    display: flex;
    /* Enable flexbox */
    flex-direction: column;
    /* Stack children vertically */
    min-height: 100vh;
    /* Minimum height of the viewport */
}

header {
    background-color: var(--color-primary);
    /* flex-shrink: 0; */
    /* Prevent header from shrinking if content is too large */
    color: var(--color-text-inverse);
    padding: 1em 0;
    text-align: center;
    border-bottom: 3px solid var(--color-accent);
}

header h1 {
    margin: 0;
    font-size: 1.8em;
}

header h1 a {
    color: var(--color-text-inverse);
    text-decoration: none;
}

nav {
    margin-top: 0.5em;
}

nav a {
    color: var(--color-text-inverse);
    margin: 10px 15px;
    text-decoration: none;
    font-size: 0.95em;
}

nav a:hover,
nav a:focus {
    text-decoration: underline;
    color: var(--color-accent);
}

main {
    padding: 0;
    width: 100vw;
    max-width: none;
    margin: 0;
    box-sizing: border-box;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

/* Container for centered content within main, if needed for other pages */
.content-container {
    max-width: 1100px;
    margin-left: auto;
    margin-right: auto;
}

.content-container.login {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}


footer {
    text-align: center;
    padding: var(--spacing-lg);
    width: 100%;
    /* margin-top: 40px; */
    /* Removed fixed margin-top, flexbox will handle positioning */
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter : blur(20px) saturate(180%);
    border-radius: 24px;
    font-size: var(--font-size-sm);
    /* flex-shrink: 0; */
    /* Prevent footer from shrinking */
}

footer p {
    color: var(--color-text-primary);
}

/* ==========================================================================
   Utility Classes (Messages, Errors)
   ========================================================================== */
.message,
.error {
    padding: 12px 15px;
    margin-bottom: 20px;
    border-radius: 5px;
    text-align: center;
    font-size: 0.95em;
}

.message {
    background-color: var(--color-success-bg);
    color: var(--color-success-text);
    border: 1px solid var(--color-success-border);
}

.error {
    background-color: var(--color-error-bg);
    color: var(--color-error-text);
    border: 1px solid var(--color-error-border);
}

.success,
.message.success {
    background-color: var(--color-success-bg) !important;
    color: var(--color-success-text) !important;
    border: 1px solid var(--color-success-border) !important;
}

/* ==========================================================================
   Content Sections & Containers
   ========================================================================== */
.section,
.form-container,
.query-section {
    /* Common container styling */
    background-color: var(--color-bg-primary);
    padding: var(--spacing-xl) var(--spacing-2xl);
    /* More padding */
    margin-bottom: var(--spacing-xl);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    /* Softer shadow */
}

/* Apply max-width to .section and .form-container by default, but allow override */
.section,
.form-container {
    max-width: 1100px;
    /* Default max-width for sections */
    margin-left: auto;
    /* Center them if they are narrower than main */
    margin-right: auto;
}


.section h2,
.form-container h2,
.query-section h2 {
    margin-top: 0;
    margin-bottom: var(--spacing-lg);
    font-size: var(--font-size-2xl);
    color: var(--color-primary);
    border-bottom: 1px solid var(--color-accent);
    padding-bottom: var(--spacing-sm);
}

.section h3 {
    font-size: 1.2em;
    color: #34495e;
    margin-top: 25px;
    margin-bottom: 15px;
}

/* Specific for auth forms */
.form-container {
    max-width: 400px;
    width: 100%;
    margin: 60px auto;
    background: var(--color-bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    padding: var(--spacing-2xl) var(--spacing-xl);
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

/* ==========================================================================
   Forms (Login, Register, Upload)
   ========================================================================== */
.form-group {
    margin-bottom: 22px;
}

.form-group label {
    font-size: var(--font-size-base);
    color: var(--color-primary);
    margin-bottom: var(--spacing-sm);
    font-weight: var(--font-weight-medium);
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="file"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.8125rem 0.875rem;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    background: var(--color-bg-primary);
    transition: border-color var(--transition-base);
}

.form-group input[type="text"]:focus,
.form-group input[type="password"]:focus {
    border-color: var(--color-primary);
    outline: none;
    background: var(--color-bg-secondary);
}

.form-group input[type="file"] {
    padding: 8px 0;
    /* Adjust file input padding */
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

/* General Button Styling */
.button,
.form-group button,
.query-section button,
.action-button {
    display: inline-block;
    padding: 0.625rem 1.125rem;
    color: var(--color-text-inverse);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: center;
    font-size: var(--font-size-base);
    transition: background-color var(--transition-base);
    background-color: var(--color-primary);
}

.form-group button {
    /* Full width for form buttons */
    width: 100%;

    .button-admin-action {
        background-color: #f0ad4e;
        /* Orange for admin actions */
    }

    .button-admin-action:hover {
        background-color: #ec971f;
    }
}

/* Specific Button Colors & Styles */
#loginForm .form-group button,
.upload-form button {
    /* Login & Upload are green */
    background-color: var(--color-success);
    /* Greener */
}

#loginForm .form-group button:hover,
.upload-form button:hover {
    background-color: var(--color-success-dark);
}

#registerForm .form-group button,
.query-section button {
    /* Register & Query are blue */
    background-color: var(--color-info);
    /* Brighter blue */
}

#registerForm .form-group button:hover,
.query-section button:hover {
    background-color: var(--color-info-dark);
}

.action-button {
    font-size: 0.85em;
    padding: 6px 12px;
    margin-right: 5px;
}

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

/* Red */
.delete-btn:hover {
    background-color: var(--color-error-dark);
}

.view-btn {
    background-color: var(--color-info-light);
}

/* Info blue */
.view-btn:hover {
    background-color: var(--color-info);
}


/* ==========================================================================
   Query Interface (Homepage)
   ========================================================================== */
/* Make #publicQuerySection specifically wider if it's directly in main */
#publicQuerySection {
    max-width: 1200px;
    /* Or a percentage like 90%, or remove max-width to use main's full width */
    margin-left: auto;
    /* Add this */
    margin-right: auto;
    /* Add this */
    /* If main has no padding and you want padding here: */
    /* padding-left: 20px; padding-right: 20px; */
}

.query-section form {
    display: flex;
    gap: 10px;
}

.query-section input[type="text"] {
    /* Input within query form */
    flex-grow: 1;
}

#publicQueryResultArea .answer {
    /* ID specific for homepage query results */
    background-color: #e9f5ff;
    padding: 15px;
    border-radius: 5px;
    margin-bottom: 15px;
    white-space: pre-wrap;
    border-left: 4px solid #3498db;
}

#publicQueryResultArea .sources h4 {
    margin-top: 20px;
    margin-bottom: 8px;
    font-size: 1.1em;
    color: #34495e;
}

#publicQueryResultArea .sources ul {
    list-style-type: none;
    padding-left: 0;
}

#publicQueryResultArea .sources li {
    background-color: #f9f9f9;
    border: 1px solid #ecf0f1;
    padding: 12px;
    margin-bottom: 10px;
    border-radius: 4px;
    font-size: 0.9em;
}

#publicQueryResultArea .sources li strong {
    display: block;
    margin-bottom: 5px;
    color: #2c3e50;
}

/* ==========================================================================
   Chat Interface Styles
   ========================================================================== */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 70vh;
    /* Adjust as needed */
    border: 1px solid #E4D9FF;
    border-radius: 8px;
    overflow: hidden;
}

.chat-history {
    flex-grow: 1;
    padding: 10px;
    overflow-y: scroll;
    background-color: #FAFAFF;
}

.chat-message {
    padding: 16px 20px;
    border-radius: 16px;
    word-wrap: break-word;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    line-height: 1.6;
}

.chat-message.user {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #ffffff;
    border: none;
}

.chat-message.bot {
    background-color: #ffffff;
    color: #374151;
    border: 1px solid #e5e7eb;
}

.chat-input-area {
    padding: 10px;
    border-top: 1px solid #E4D9FF;
    background-color: #FAFAFF;
}

/* Inline model selector - small and to the left of input */
.model-selector-inline {
    padding: 0.4rem 0.5rem;
    border: 1px solid #ced4da;
    border-radius: 6px;
    font-size: 0.75rem;
    background: white;
    cursor: pointer;
    color: #495057;
    min-width: 100px;
    max-width: 140px;
    margin-right: 0.5rem;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23495057' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.4rem center;
    background-size: 0.75rem;
    padding-right: 1.75rem;
    height: 40px;
}

.model-selector-inline:hover {
    border-color: #667eea;
    background-color: #f8f9ff;
}

.model-selector-inline:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 0.15rem rgba(102, 126, 234, 0.2);
    background-color: white;
}

.model-selector-inline option {
    font-size: 0.85rem;
    padding: 0.5rem;
}

.chat-input-area form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-input-area input[type="text"] {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid #E4D9FF;
    border-radius: 4px;
    margin-right: 10px;
    font-size: 1em;
    background: #FAFAFF;
    color: #30343F;
}

.chat-input-area button {
    padding: 10px 15px;
    background-color: #1E2749;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
}

.chat-input-area button:hover {
    background-color: #273469;
}

/* ==========================================================================
   Dashboard Specifics
   ========================================================================== */
.dashboard-container {
    /* padding already handled by main or can be specific if needed */
}

.welcome-message {
    margin-bottom: 25px;
    font-size: 1.3em;
    padding: 15px;
    background-color: #eafaf1;
    border-left: 5px solid #27ae60;
    border-radius: 5px;
}

/* Generic List Table Styles (for #documentList, #adminUserList, etc.) */
.section table,
/* Apply to any table directly within a .section */
#documentList table,
/* Keep specific for now if needed, or remove if .section table is enough */
#adminUserList table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
    background: #FAFAFF;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(30, 39, 73, 0.06);
    overflow: hidden;
}

.section th,
.section td,
#documentList th,
#documentList td,
#adminUserList th,
#adminUserList td {
    border: 1px solid #ddd;
    padding: 10px 12px;
    /* More padding */
    text-align: left;
    font-size: 0.95em;
}

.section th,
#documentList th,
#adminUserList th {
    background-color: #E4D9FF;
    color: #1E2749;
    border-bottom: 2px solid #E4D9FF;
    font-size: 1.05em;
    letter-spacing: 0.02em;
}

.section td,
#documentList td,
#adminUserList td {
    background: #FAFAFF;
    color: #30343F;
    border-bottom: 1px solid #E4D9FF;
}

.section tr:nth-child(even),
#documentList tr:nth-child(even),
#adminUserList tr:nth-child(even) {
    background-color: #f9f9f9;
}

.section tr:hover,
#documentList tr:hover,
#adminUserList tr:hover {
    background: #E4D9FF;
    transition: background 0.2s;
}

/* Enhanced Styles for AI-generated tables */
.answer table,
.ai-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5em 0;
    background: #FAFAFF;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(30, 39, 73, 0.12), 0 2px 8px rgba(30, 39, 73, 0.08);
    border: 1px solid #E4D9FF;
    font-size: 0.95em;
    line-height: 1.5;
}

.answer th,
.answer td,
.ai-table th,
.ai-table td {
    padding: 16px 18px;
    text-align: left;
    border: none;
    border-bottom: 1px solid #E4D9FF;
    vertical-align: top;
}

.answer th,
.ai-table th {
    background: linear-gradient(135deg, #1E2749 0%, #273469 100%);
    color: #FAFAFF;
    font-weight: 600;
    font-size: 1em;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    border-bottom: 2px solid #E4D9FF;
    position: sticky;
    top: 0;
    z-index: 10;
}

.answer td,
.ai-table td {
    background-color: #FAFAFF;
    color: #30343F;
    transition: background-color 0.2s ease;
}

.answer tr:nth-child(even) td,
.ai-table tr:nth-child(even) td {
    background-color: #f8f9fa;
}

.answer tr:hover td,
.ai-table tr:hover td {
    background-color: #E4D9FF;
    color: #1E2749;
    transform: translateY(-1px);
    transition: all 0.2s ease;
}

/* Enhanced styling for table data */
.answer td:first-child,
.ai-table td:first-child {
    font-weight: 500;
    color: #1E2749;
}

/* Responsive table styling */
@media (max-width: 768px) {
    .answer table,
    .ai-table {
        font-size: 0.85em;
        margin: 1em 0;
    }
    
    .answer th,
    .answer td,
    .ai-table th,
    .ai-table td {
        padding: 12px 10px;
    }
}

/* Table container with horizontal scroll for mobile */
.answer .table-container,
.ai-table-container {
    /* overflow-x: auto; */
    margin: 1.5em 0;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(30, 39, 73, 0.12);
}

/* Additional table enhancement for numeric data */
.answer td[data-type="number"],
.answer td.numeric,
.ai-table td[data-type="number"],
.ai-table td.numeric {
    text-align: right;
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-weight: 500;
}

/* Price/currency styling */
.answer td.price,
.answer td[data-type="price"],
.ai-table td.price,
.ai-table td[data-type="price"] {
    color: #27ae60;
    font-weight: 600;
}

/* Table caption styling */
.answer table caption,
.ai-table caption {
    caption-side: top;
    padding: 12px 0;
    font-size: 1.1em;
    font-weight: 600;
    color: #1E2749;
    text-align: left;
}

.answer pre {
    background-color: #2d2d2d;
    /* Dark background for code blocks */
    color: #f8f8f2;
    /* Light text for code */
    padding: 1em;
    border-radius: 5px;
    overflow-x: auto;
    /* Allow horizontal scrolling for long lines */
    margin-top: 1em;
    margin-bottom: 1em;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.answer code {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
    font-size: 0.9em;
    background-color: #2d2d2d;
    /* Ensure inline code also has dark bg if not in pre */
    color: #f8f8f2;
    padding: 0.2em 0.4em;
    /* Padding for inline code */
    border-radius: 3px;
}

.answer pre code {
    /* Code specifically within pre should not have extra padding/bg */
    padding: 0;
    background-color: transparent;
    border-radius: 0;
}

.answer ul,
.answer ol {
    margin-left: 20px;
    padding-left: 20px;
}

.answer li {
    margin-bottom: 0.5em;
}

.answer blockquote {
    border-left: 4px solid #ccc;
    padding-left: 1em;
    margin-left: 0;
    color: #666;
    font-style: italic;
}

.answer h1,
.answer h2,
.answer h3,
.answer h4,
.answer h5,
.answer h6 {
    margin-top: 1.2em;
    margin-bottom: 0.6em;
    color: #2c3e50;
}

/* ==========================================================================
   Chat App Split Panel Layout
   ========================================================================== */
.chat-app-layout {
    display: flex;
    flex: 1 1 auto;
    width: 100vw;
    min-width: 900px;
    max-width: 100vw;
    height: 80vh;
    border: 1px solid #E4D9FF;
    background: #FAFAFF;
    border-radius: 8px;
    overflow: hidden;
}

.chat-list-panel {
    width: 260px;
    min-width: 220px;
    max-width: 320px;
    background: #273469;
    border-right: 1px solid #E4D9FF;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.03);
    z-index: 2;
}

.chat-list {
    min-height: 40px;
    background: #EBF2FA;
    color: #000;
}

/* Highlight active chat session */
.chat-list .chat-session.active {
    background: #1E2749;
    color: #E4D9FF;
}

/* Chat window */
.chat-container {
    border: 1px solid #E4D9FF;
    background: #FAFAFF;
}

.chat-history {
    background-color: #FAFAFF;
}

.message-wrapper .chat-message.user {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #ffffff;
    border: none;
}

.message-wrapper .chat-message.bot {
    background-color: #ffffff;
    color: #374151;
    border: 1px solid #e5e7eb;
}

.chat-input-area {
    background-color: #FAFAFF;
    border-top: 1px solid #E4D9FF;
}

.chat-input-area input[type="text"] {
    background: #FAFAFF;
    border: 1px solid #E4D9FF;
    color: #30343F;
}

.chat-input-area button {
    background-color: #1E2749;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
}

.chat-input-area button:hover {
    background-color: #273469;
}

/* ==========================================================================
   AI Table Styles
   ========================================================================== */
.ai-table {
    background: #FAFAFF;
    border: 1px solid #E4D9FF;
}

.ai-table th {
    background: #C5C3C6;
    color: #1E2749;
}

.ai-table tr:nth-child(even) {
    background: #f1f3fa;
}

.ai-table tr:hover {
    background: #E6E6E6;
}

/* Login Form */
.form-container {
    background: #FAFAFF;
    box-shadow: 0 4px 24px rgba(30, 39, 73, 0.10), 0 1.5px 6px rgba(30, 39, 73, 0.08);
}

/* --- UI Polish & Consistency Enhancements --- */

/* Table Styles (Admin/User/Document Lists) */
.section table,
#documentList table,
#adminUserList table {
    background: #FAFAFF;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(30, 39, 73, 0.06);
    overflow: hidden;
}

.section th,
#documentList th,
#adminUserList th {
    background-color: #E4D9FF;
    color: #1E2749;
    border-bottom: 2px solid #E4D9FF;
    font-size: 1.05em;
    letter-spacing: 0.02em;
}

.section td,
#documentList td,
#adminUserList td {
    background: #FAFAFF;
    color: #30343F;
    border-bottom: 1px solid #E4D9FF;
    height: 70px;
}

.section tr:hover,
#documentList tr:hover,
#adminUserList tr:hover {
    background: #E4D9FF;
    transition: background 0.2s;
}

/* Form Inputs & Focus */
.form-group input[type="text"],
.form-group input[type="password"],
.form-group select,
.form-group textarea {
    box-shadow: 0 1px 4px rgba(30, 39, 73, 0.04);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input[type="text"]:focus,
.form-group input[type="password"]:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: #273469;
    box-shadow: 0 0 0 2px #E4D9FF;
}

/* Button Polish */
.button,
.form-group button,
.query-section button,
.action-button,
.chat-input-area button {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #FAFAFF;
    font-weight: 500;
    letter-spacing: 0.01em;
    box-shadow: 0 2px 8px rgba(30, 39, 73, 0.08);
    transition: background 0.2s, box-shadow 0.2s;
}

.button:hover,
.form-group button:hover,
.query-section button:hover,
.action-button:hover,
.chat-input-area button:hover {
    background: linear-gradient(135deg, #764ba2, #667eea);
    box-shadow: 0 4px 16px rgba(30, 39, 73, 0.12);
}

/* Sidebar/Chat List Panel Polish */
.chat-list-panel {
    background: linear-gradient(180deg, #273469 80%, #1E2749 100%);
    box-shadow: 2px 0 12px rgba(30, 39, 73, 0.06);
}

.chat-list {
    padding: 12px 0;
}

.chat-list .chat-session {
    padding: 12px 20px;
    border-radius: 6px;
    margin: 6px 10px;
    cursor: pointer;
    transition: background 0.18s, color 0.18s;
    font-size: 1.04em;
    color: #FAFAFF;
}

.chat-list .chat-session:hover {
    background: #E4D9FF;
    color: #1E2749;
}

.chat-list .chat-session.active {
    background: #1E2749;
    color: #E4D9FF;
    font-weight: 600;
}

/* Dashboard Welcome Message Polish */
.welcome-message {
    background: #E4D9FF;
    color: #1E2749;
    border-left: 5px solid #273469;
    box-shadow: 0 2px 8px rgba(30, 39, 73, 0.04);
}

/* Responsive Tweaks */
@media (max-width: 768px) {

    .section,
    .form-container {
        padding: 16px 8px;
    }

    .chat-list .chat-session {
        padding: 10px 8px;
        font-size: 1em;
    }
}

/* Modal/Overlay Polish (if used) */
.modal,
.overlay {
    background: rgba(30, 39, 73, 0.85);
    color: #FAFAFF;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(30, 39, 73, 0.18);
}

/* Miscellaneous Polish */
::-webkit-scrollbar-thumb {
    background: #E4D9FF;
    border-radius: 6px;
}

::-webkit-scrollbar-track {
    background: #FAFAFF;
}

/* Ensure all admin/user/dashboard pages use the new palette */
.admin-header,
.user-header {
    background: #1E2749;
    color: #FAFAFF;
    border-bottom: 2px solid #E4D9FF;
}

.admin-sidebar,
.user-sidebar {
    background: #273469;
    color: #FAFAFF;
    border-right: 1px solid #E4D9FF;
}

.admin-sidebar a,
.user-sidebar a {
    color: #FAFAFF;
    transition: color 0.18s;
}

.admin-sidebar a:hover,
.user-sidebar a:hover {
    color: #E4D9FF;
}

/* ==========================================================================
   Citation Styling
   ========================================================================== */
.citation {
    font-size: 0.8em;
    color: #3498db;
    font-weight: 600;
    vertical-align: baseline;
    text-decoration: none;
    margin-left: 2px;
    margin-right: 2px;
    display: inline;
}

.citation:hover {
    color: #2980b9;
    text-decoration: underline;
}

/* Enhanced citation styles for bot messages */
.chat-message.bot h4 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: #1E2749;
    font-size: 1.1rem;
    font-weight: 600;
    border-bottom: 1px solid #E4D9FF;
    padding-bottom: 0.5rem;
}

/* Sources section styling */
.chat-message.bot p:has(strong:contains("Sources:")) {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid #E4D9FF;
}

/* Citation links in sources */
.chat-message.bot a {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s ease;
    border-bottom: 1px solid transparent;
}

.chat-message.bot a:hover {
    color: #5a67d8;
    text-decoration: none;
    border-bottom: 1px solid #5a67d8;
    background-color: rgba(102, 126, 234, 0.05);
    padding: 2px 4px;
    border-radius: 3px;
}

/* External link indicator */
.chat-message.bot a[href^="http"]:after {
    content: " ↗";
    font-size: 0.8em;
    color: #6b7280;
    margin-left: 2px;
}

/* Inline citation numbers - tiny bookmark style */
.chat-message.bot .citation,
.chat-message.bot sup {
    background: linear-gradient(135deg, #e8f2ff, #f0f4ff);
    color: #4a5568;
    padding: 2px 5px;
    border-radius: 6px;
    font-size: 0.65em;
    font-weight: 600;
    margin: 0 1px;
    text-decoration: none;
    display: inline-block;
    line-height: 1;
    vertical-align: super;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    border: 1px solid #d1d5db;
    min-width: 16px;
    text-align: center;
    position: relative;
    top: -2px;
}

.chat-message.bot .citation:hover,
.chat-message.bot sup:hover {
    background: linear-gradient(135deg, #dbeafe, #e0e7ff);
    color: #374151;
    transform: scale(1.1);
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    border-color: #9ca3af;
    z-index: 10;
}

/* Bookmark-style citation with small triangle */
.chat-message.bot .citation::after,
.chat-message.bot sup::after {
    content: '';
    position: absolute;
    bottom: -3px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 2px solid transparent;
    border-right: 2px solid transparent;
    border-top: 2px solid #9ca3af;
    opacity: 0.6;
}

.chat-message.bot .citation:hover::after,
.chat-message.bot sup:hover::after {
    border-top-color: #6b7280;
    opacity: 0.8;
}

/* Enhanced styling for citation spans */
.chat-message.bot span.citation {
    background: linear-gradient(135deg, #f3f4f6, #f9fafb);
    color: #4b5563;
    padding: 1px 4px;
    border-radius: 4px;
    font-size: 0.7em;
    font-weight: 600;
    margin: 0 1px;
    text-decoration: none;
    display: inline-block;
    line-height: 1.2;
    vertical-align: baseline;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    border: 1px solid #e5e7eb;
    min-width: 14px;
    text-align: center;
    position: relative;
    top: -1px;
}

.chat-message.bot span.citation:hover {
    background: linear-gradient(135deg, #e5e7eb, #f3f4f6);
    color: #374151;
    transform: scale(1.05);
    transition: all 0.2s ease;
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.12);
    border-color: #d1d5db;
}

/* ==========================================================================
   Chat Delete Button Styling
   ========================================================================== */
.chat-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
}

.chat-title {
    flex: 1;
    cursor: pointer;
    padding-right: 8px;
}

.chat-delete-btn {
    background: rgba(231, 76, 60, 0.8);
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s, background-color 0.2s;
    flex-shrink: 0;
}

.chat-list li:hover .chat-delete-btn {
    opacity: 1;
}

.chat-delete-btn:hover {
    background: rgba(192, 57, 43, 0.9);
    transform: scale(1.1);
}

/* ==========================================================================
   Status Badge Styling
   ========================================================================== */
.status-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.8em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1px solid transparent;
}

.status-badge.active {
    background-color: #d4edda;
    color: #155724;
    border-color: #c3e6cb;
}

.status-badge.disabled {
    background-color: #f8d7da;
    color: #721c24;
    border-color: #f5c6cb;
}

/* Document Processing Status Styles */
.document-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.document-status.processing {
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid #fbbf24;
}

.document-status.pending {
    background-color: #e0e7ff;
    color: #3730a3;
    border: 1px solid #a5b4fc;
}

.document-status.failed {
    background-color: #fee2e2;
    color: #dc2626;
    border: 1px solid #fca5a5;
}

.document-status.active {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

.document-status .status-text {
    font-size: 0.7rem;
}

/* Source Type Badge Styles */
.source-type-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.source-type-badge.source-upload {
    background-color: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

.source-type-badge.source-url {
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid #fbbf24;
}

.source-type-badge.source-crawler {
    background-color: #e0e7ff;
    color: #3730a3;
    border: 1px solid #a5b4fc;
}

.source-type-badge.source-notion {
    background-color: #f3e8ff;
    color: #7c3aed;
    border: 1px solid #c4b5fd;
}

/* Document Icon Styles */
.document-icon.notion-doc {
    background: linear-gradient(135deg, #667eea, #764ba2);
}

.document-icon.notion-doc i {
    color: white;
}

/* End UI Polish */

/* ==========================================================================
   Modern Analytics Dashboard Styles
   ========================================================================== */

/* Main Layout */
.analytics-main {
    min-height: calc(100vh - 80px);
    background: linear-gradient(135deg, #f8faff 0%, #f1f5ff 100%);
}

.analytics-content {
    padding: 2rem;
    overflow-y: auto;
    max-width: 100vw;
}

/* Analytics Header */
.analytics-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.header-title h1 {
    margin: 0 0 0.5rem;
    font-size: 2.5rem;
    background: linear-gradient(135deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 700;
}

.header-title p {
    color: #6B7280;
    margin: 0;
    font-size: 1.1rem;
}

.analytics-controls {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 200px;
}

.control-group label {
    font-weight: 600;
    color: #374151;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modern-select {
    padding: 0.75rem 1rem;
    border: 2px solid #E4D9FF;
    border-radius: 12px;
    background: white;
    color: #374151;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.modern-select:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    outline: none;
    transform: translateY(-1px);
}

.export-btn {
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.2);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.export-btn:hover {
    background: linear-gradient(135deg, #5a67d8, #6b46c1);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.3);
}

/* Overview Section */
.overview-section {
    margin-bottom: 2rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-radius: 20px 20px 0 0;
}

.stat-card.primary::before {
    background: linear-gradient(135deg, #667eea, #764ba2);
}

.stat-card.secondary::before {
    background: linear-gradient(135deg, #34d399, #059669);
}

.stat-card.tertiary::before {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
}

.stat-card.quaternary::before {
    background: linear-gradient(135deg, #f87171, #ef4444);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.12);
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    flex-shrink: 0;
}

.stat-card.primary .stat-icon {
    background: linear-gradient(135deg, #667eea, #764ba2);
}

.stat-card.secondary .stat-icon {
    background: linear-gradient(135deg, #34d399, #059669);
}

.stat-card.tertiary .stat-icon {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
}

.stat-card.quaternary .stat-icon {
    background: linear-gradient(135deg, #f87171, #ef4444);
}

.stat-content h3 {
    margin: 0 0 0.5rem;
    font-size: 1.1rem;
    color: #374151;
    font-weight: 600;
}

.stat-number {
    font-size: 2.5rem;
    font-weight: 700;
    margin: 0.5rem 0;
    color: #1f2937;
    line-height: 1;
}

.stat-label {
    font-size: 0.85rem;
    color: #6b7280;
    margin: 0;
}

/* Dashboard Sections */
.dashboard-section {
    background: white;
    border-radius: 20px;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
}

.dashboard-section:hover {
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
}

.section-header {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 2px solid #f3f4f6;
}

.section-title h2 {
    margin: 0 0 0.5rem;
    font-size: 1.8rem;
    color: #1f2937;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.section-title h2 i {
    color: #667eea;
}

.section-title p {
    color: #6b7280;
    margin: 0;
    font-size: 1rem;
}

/* Chart Grid */
.chart-grid {
    display: grid;
    gap: 2rem;
}

.chart-grid.two-columns {
    grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
}

.chart-card {
    background: linear-gradient(145deg, #ffffff, #f8faff);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
    border: 1px solid #e5e7eb;
    transition: all 0.3s ease;
}

.chart-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.chart-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #f3f4f6;
}

.chart-header h3 {
    margin: 0 0 0.25rem;
    font-size: 1.3rem;
    color: #1f2937;
    font-weight: 600;
}

.chart-subtitle {
    color: #6b7280;
    font-size: 0.9rem;
}

.chart-container {
    position: relative;
    height: 400px;
    width: 100%;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .analytics-sidebar {
        width: 240px;
    }

    .analytics-content {
        max-width: calc(100vw - 240px);
    }

    .chart-grid.two-columns {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 968px) {
    .analytics-main {
        flex-direction: column;
    }

    .analytics-sidebar {
        width: 100%;
        position: relative;
    }

    .analytics-content {
        max-width: 100vw;
        padding: 1rem;
    }

    .analytics-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1.5rem;
    }

    .analytics-controls {
        justify-content: stretch;
    }

    .control-group {
        min-width: auto;
        flex: 1;
    }

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

    .stat-card {
        padding: 1.5rem;
    }

    .chart-container {
        height: 300px;
    }
}

@media (max-width: 640px) {
    .analytics-content {
        padding: 0.5rem;
    }

    .analytics-header {
        padding: 1.5rem;
    }

    .header-title h1 {
        font-size: 2rem;
    }

    .dashboard-section {
        padding: 1.5rem;
    }

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

    .stat-card {
        flex-direction: column;
        text-align: center;
        gap: 1rem;
    }

    .chart-card {
        padding: 1rem;
    }

    .chart-container {
        height: 250px;
    }
}

/* ==========================================================================
   Context Menu Fix - Override All Conflicting Styles
   ========================================================================== */

/* ==========================================================================
   Context Menu Fix - Override All Conflicting Styles
   ========================================================================== */

/* FORCE THREE DOTS TO SHOW ON HOVER - OVERRIDE ALL EXISTING RULES */
.chat-list li:hover .chat-menu-btn {
    opacity: 1 !important;
    visibility: visible !important;
    display: flex !important;
}

.chat-list li .chat-menu-btn {
    opacity: 0 !important;
    transition: opacity 0.2s ease !important;
}

/* FORCE CONTEXT MENU TEXT TO BE READABLE - OVERRIDE ALL RULES */
.chat-context-menu-item {
    color: #000000 !important;
    background: #ffffff !important;
    /* font-weight: 600 !important; */
    padding: 12px 16px !important;
    border: none !important;
    text-decoration: none !important;
}

.chat-context-menu-item:hover {
    color: #000000 !important;
    background: #f5f5f5 !important;
}

.chat-context-menu-item.delete {
    color: #d32f2f !important;
}

.chat-context-menu-item.delete:hover {
    color: #b71c1c !important;
    background: #ffebee !important;
}

.chat-context-menu-item svg {
    color: inherit !important;
    /* fill: currentColor !important; */
}

.chat-context-menu {
    background: #ffffff !important;
    color: #000000 !important;
    border: 1px solid #e0e0e0 !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15) !important;
}

/* ==========================================================================
   Message Wrapper & Reactions Styling
   ========================================================================== */

.message-wrapper {
    margin-bottom: 20px;
    clear: both;
    max-width: 75%;
    width: fit-content;
}

.message-wrapper.user {
    float: right;
    margin-left: auto;
    text-align: right;
}

.message-wrapper.bot {
    float: left;
    margin-right: auto;
    text-align: left;
}

.message-reactions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding: 8px 0;
    justify-content: flex-start;
}

.message-wrapper.user .message-reactions {
    justify-content: flex-end;
}

.reaction-btn {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 16px;
    padding: 4px 8px;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    color: #6c757d;
    position: relative;
}

.reaction-btn:hover {
    background: #e9ecef;
    transform: scale(1.1);
    border-color: #adb5bd;
}

.reaction-btn.thumbs-up:hover {
    background: #d4edda;
    border-color: #28a745;
    color: #155724;
}

.reaction-btn.thumbs-down:hover {
    background: #f8d7da;
    border-color: #dc3545;
    color: #721c24;
}

.reaction-btn.active {
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.reaction-btn.thumbs-up.active {
    background: #28a745;
    border-color: #28a745;
    color: white;
}

.reaction-btn.thumbs-down.active {
    background: #dc3545;
    border-color: #dc3545;
    color: white;
}

.reaction-btn:active {
    transform: scale(0.95);
}

/* Feedback tooltip for reactions */
.reaction-feedback {
    position: fixed;
    background: linear-gradient(135deg, #1f2937, #374151);
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    z-index: 1000;
    pointer-events: none;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(8px);
}

/* Only show reactions on bot messages */
.message-wrapper.bot .message-reactions {
    display: flex;
}

.message-wrapper.user .message-reactions {
    display: none;
}

/* Responsive adjustments for reactions */
@media (max-width: 768px) {
    .message-wrapper {
        max-width: 85%;
    }
    
    .reaction-btn {
        min-width: 30px;
        height: 30px;
        font-size: 18px;
    }
    
    .message-reactions {
        gap: 6px;
        margin-top: 10px;
    }
}
