:root {
    
    --bg-app: #f3f4f6;
    /* Light Grey Background */
    --bg-panel: #ffffff;
    /* White Sidebar/Panels */
    --text-main: #1f2937;
    /* Dark Grey Text */
    --text-muted: #6b7280;
    /* Light Grey Text */
    --border: #e5e7eb;
    /* Light Grey Border */
    --accent: #2563eb;
    /* Blue Accent */
    --input-bg: #ffffff;
    /* White Input Background */
    --msg-user: #e5e7eb;
    /* Light Grey Bubble */
    --shadow: rgba(0, 0, 0, 0.05);
}

/* --- DARK MODE (Overrides) --- */
body.dark-mode,
.dark-mode body,
.dark-mode {
    --bg-app: #18181b;
    /* Very Dark Grey Background */
    --bg-panel: #27272a;
    /* Slightly Lighter Grey Panel */
    --text-main: #f3f4f6;
    /* White Text */
    --text-muted: #9ca3af;
    /* Muted Grey Text */
    --border: #3f3f46;
    /* Dark Grey Border */
    --accent: #3b82f6;
    /* Brighter Blue for Contrast */
    --input-bg: #27272a;
    /* Dark Grey Input Background */
    --msg-user: #3f3f46;
    /* Dark Grey Bubble */
    --shadow: rgba(0, 0, 0, 0.5);
}

/* Logo Inversion Logic:
   Original logo.svg is white. 
   - Light Mode: Invert (make dark)
   - Dark Mode: No Invert (stay white)
*/
.logo img {
    filter: invert(1);
    transition: filter 0.3s ease;
}

body.dark-mode .logo img,
.dark-mode .logo img {
    filter: invert(0);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-app);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.app-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* --- SIDEBAR --- */
.sidebar {
    width: 280px;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border);
    padding: 24px;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s, border-color 0.3s;
}

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

.logo {
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* THEME TOGGLE BUTTON */
.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-main);
    
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: var(--border);
}

.theme-icon {
    width: 20px;
    height: 20px;
}

/* BUTTONS */
.primary-btn {
    background-color: var(--text-main);
    /* Inverts automatically: Black in light, White in dark */
    color: var(--bg-panel);
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.9rem;
    transition: opacity 0.2s;
}

.primary-btn:hover {
    opacity: 0.8;
}

.full-width {
    width: 100%;
}

.divider {
    height: 1px;
    background-color: var(--border);
    margin: 20px 0;
}

.section-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 12px;
}


.skeleton-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 250px;
}

.skeleton-line {
    height: 12px;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--border) 25%, var(--bg-panel) 50%, var(--border) 75%);
    background-size: 200% 100%;
    animation: pulse 1.5s infinite linear;
}

.skeleton-line.short {
    width: 60%;
}

@keyframes pulse {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

.file-list {
    flex: 1;
    overflow-y: auto;
}

.empty-state {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
}

.file-item {
    font-size: 0.9rem;
    padding: 10px;
    background-color: var(--bg-app);
    /* Matches main background */
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: 6px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --- CITATION BADGES --- */
.citation {
    display: inline-block;
    background-color: var(--border);
    color: var(--text-main);
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 4px;
    margin-left: 6px;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    font-family: 'Inter', sans-serif;
    vertical-align: middle;
}

.citation:hover {
    background-color: var(--accent);
    color: white;
}

/* --- FILE METADATA IN SIDEBAR --- */
.file-info {
    display: flex;
    flex-direction: column;
    width: 100%;
    overflow: hidden;
}

.file-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    margin-top: 3px;
}

.status-badge {
    color: var(--accent);
    font-weight: 600;
}

/* --- MAIN CHAT AREA --- */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background-color: var(--bg-panel);
    /* Ensures main area changes color */
    transition: background-color 0.3s;
}

.chat-feed {
    flex: 1;
    padding: 40px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.start-screen {
    margin-top: 15vh;
    text-align: center;
    color: var(--text-muted);
}

.start-screen h1 {
    color: var(--text-main);
    margin-bottom: 10px;
}

/* MESSAGES */
.message-row {
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    gap: 15px;
}

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

.bubble {
    padding: 14px 18px;
    border-radius: 12px;
    line-height: 1.5;
    max-width: 80%;
    color: var(--text-main);
    /* Ensures text is visible */
}

.user .bubble {
    background-color: var(--msg-user);
}

.bot .bubble {
    background-color: transparent;
    padding-left: 0;
}

/* INPUT AREA */
.input-container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 30px;
    background-color: transparent;
}

.input-box {
    display: flex;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px;
    background-color: var(--input-bg);
    box-shadow: 0 4px 20px var(--shadow);
    transition: background-color 0.3s, border-color 0.3s;
}

.input-box textarea {
    flex: 1;
    width: 100%; /* FIX 1: Forces the box to stretch across the entire empty space */
    background-color: transparent !important; /* FIX 2: Forces it to stay invisible */
    border: none;
    outline: none;
    padding: 10px 14px;
    min-height: 44px;
    font-size: 1rem;
    color: var(--text-main);
    resize: none; /* Keeps the drag handle hidden */
    font-family: inherit;
    line-height: 1.5;
    max-height: 150px; 
    overflow-y: auto;  
}

.send-icon {
    background-color: var(--accent);
    color: white;
    border: none;
    width: 44px;
    height: 44px; /* FIX 1: Lock the height so it never stretches */
    align-self: flex-end; /* FIX 2: Anchor it to the bottom of the box */
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0; /* Prevents the button from being squished by long text */
}

/* --- TOAST NOTIFICATIONS --- */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    /* Lets users click through the gap */
}

.toast {
    min-width: 280px;
    max-width: 350px;
    background-color: var(--bg-panel);
    color: var(--text-main);
    border-left: 4px solid var(--accent);
    padding: 14px 18px;
    border-radius: 6px;
    box-shadow: 0 4px 15px var(--shadow);
    font-size: 0.85rem;
    font-family: 'Inter', sans-serif;
    display: flex;
    align-items: center;
    gap: 10px;

    /* Animation settings */
    animation: slideIn 0.3s ease-out forwards;
    transition: opacity 0.3s ease-out, transform 0.3s ease-out;
}

/* Toast Color Themes */
.toast.success {
    border-left-color: #22c55e;
}

/* Green */
.toast.error {
    border-left-color: #ef4444;
}

/* Red */
.toast.warning {
    border-left-color: #f59e0b;
}

/* Orange */

/* Fade out class added by JavaScript */
.toast.hide {
    opacity: 0;
    transform: translateX(120%);
}

@keyframes slideIn {
    from {
        transform: translateX(120%);
        opacity: 0;
    }

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

/* --- MARKDOWN AI OUTPUT STYLES --- */
.bubble p {
    margin-bottom: 10px;
    margin-top: 5px;
}

.bubble p:last-child {
    margin-bottom: 0;
}

.bubble ul,
.bubble ol {
    margin-left: 20px;
    margin-bottom: 10px;
}

/* Inline code formatting */
.bubble code {
    background-color: rgba(0, 0, 0, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

body.dark-mode .bubble code {
    background-color: rgba(255, 255, 255, 0.15);
}

/* Code block formatting */
.bubble pre {
    background-color: #1e1e24;
    /* Deep dark background for code blocks */
    color: #e4e4e7;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
    font-family: monospace;
    font-size: 0.9em;
    border: 1px solid #333;
}

/* Override inline code style if it's inside a code block */
.bubble pre code {
    background-color: transparent;
    padding: 0;
    color: inherit;
}


/* --- DISABLED INPUT STATE --- */
/* Changed 'input' to 'textarea' */
.input-box textarea:disabled {
    background-color: transparent !important; /* Strips away the default browser grey */
    color: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.5;
}

.send-icon:disabled {
    background-color: var(--border);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* Ensure the wrapper also shows the not-allowed cursor */
/* Changed 'input' to 'textarea' here too! */
.input-box:has(textarea:disabled) {
    background-color: var(--bg-app);
    cursor: not-allowed;
}

/* --- STREAMING CURSOR --- */
.blinking-cursor {
    display: inline-block;
    width: 8px;
    height: 16px;
    background-color: var(--accent);
    animation: blink 1s step-end infinite;
    vertical-align: text-bottom;
    margin-left: 4px;
}

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

::-webkit-scrollbar {
    width: 8px; 
}

::-webkit-scrollbar-track {
    background: transparent; 
}

::-webkit-scrollbar-thumb {
    background-color: var(--border); 
    border-radius: 10px; 
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--text-muted); 
}