/* CSS Variables for Theme */
:root {
    --bg-main: #0B0E14;
    --bg-surface: rgba(22, 27, 34, 0.6);
    --bg-surface-hover: rgba(33, 38, 45, 0.8);
    --glass-border: rgba(255, 255, 255, 0.1);
    
    /* Primary brand colors - vibrant blue/purple gradient */
    --accent-primary: #3B82F6;
    --accent-secondary: #8B5CF6;
    --accent-gradient: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    
    /* Text colors */
    --text-primary: #F8FAFC;
    --text-secondary: #94A3B8;
    --text-placeholder: #64748B;
    
    /* System colors */
    --success: #10B981;
    --error: #EF4444;
    
    --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
}

/* Reset & Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-main);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    /* Subtle background mesh gradient effect */
    background-image: 
        radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(139, 92, 246, 0.15) 0px, transparent 50%);
    background-attachment: fixed;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    color: var(--text-primary);
}

/* Glassmorphism Utilities */
.glass-panel {
    background: var(--bg-surface);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-glass);
}

/* Layout Container */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    padding: 1rem;
    gap: 1rem;
}

/* --- Sidebar Styles --- */
.sidebar {
    width: 320px;
    display: flex;
    flex-direction: column;
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    flex-shrink: 0;
    overflow-y: auto;
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}
.sidebar::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 4px;
}

.sidebar-header {
    margin-bottom: 2rem;
}

.sidebar-header h2 {
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-header h2 i {
    -webkit-text-fill-color: var(--accent-primary);
}

.subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Upload Section */
.upload-section {
    margin-bottom: 2rem;
}

.upload-zone {
    border: 2px dashed var(--glass-border);
    border-radius: var(--radius-md);
    padding: 2rem 1rem;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.02);
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--accent-primary);
    background: rgba(59, 130, 246, 0.05);
}

.upload-icon {
    font-size: 2rem;
    color: var(--accent-primary);
    margin-bottom: 1rem;
}

.upload-zone p {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.or-divider {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin: 0.5rem 0;
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
    width: 100%;
}

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

.btn-primary:active {
    transform: scale(0.98);
}

.upload-info {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 0.75rem;
}

/* Document List */
.document-list h3 {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.badge {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
    padding: 0.1rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
}

#doc-ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.doc-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    transition: border-color 0.2s;
    font-size: 0.875rem;
}

.doc-item:hover {
    border-color: var(--glass-border);
}

.doc-icon {
    color: var(--error); /* PDF color */
}

.doc-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-remove {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.2s;
}

.doc-remove:hover {
    color: var(--error);
}

.empty-state {
    text-align: center;
    padding: 1rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-style: italic;
}

/* Sidebar Footer */
.sidebar-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.dot.online { background-color: var(--success); box-shadow: 0 0 8px var(--success); }

/* --- Chat Area Styles --- */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-lg);
}

.header-info h1 {
    font-size: 1.25rem;
}

.header-info p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: all 0.2s;
}

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

/* Chat Window */
.chat-window {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    scroll-behavior: smooth;
}

.chat-window::-webkit-scrollbar { width: 6px; }
.chat-window::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 10px; }

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.message {
    display: flex;
    gap: 1rem;
    max-width: 80%;
}

.message.bot { align-self: flex-start; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: white;
}

.bot .avatar { background: var(--accent-gradient); box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3); }
.user .avatar { background: var(--bg-surface-hover); border: 1px solid var(--glass-border); }

.message-content {
    background: var(--bg-surface);
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--glass-border);
    font-size: 0.95rem;
    line-height: 1.5;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.bot .message-content {
    border-top-left-radius: 4px;
}

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

/* Markdown Styles for Bot Messages */
.bot .message-content h1, 
.bot .message-content h2, 
.bot .message-content h3 {
    margin-top: 1.25rem;
    margin-bottom: 0.75rem;
    font-weight: 700;
    line-height: 1.3;
}

.bot .message-content h1 { 
    font-size: 1.6rem; 
    color: var(--accent-primary);
    border-bottom: 2px solid var(--accent-primary); 
    padding-bottom: 0.4rem; 
}
.bot .message-content h2 { 
    font-size: 1.35rem; 
    color: var(--accent-secondary); 
}
.bot .message-content h3 { 
    font-size: 1.15rem; 
    color: #3CCBFF; /* A vibrant light blue */
}

.bot .message-content p {
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.bot .message-content p:last-child {
    margin-bottom: 0;
}

.bot .message-content ul, 
.bot .message-content ol {
    margin-bottom: 1rem;
    padding-left: 1.6rem;
}

.bot .message-content li {
    margin-bottom: 0.4rem;
}

.bot .message-content code {
    background: rgba(255, 255, 255, 0.08);
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 0.9em;
    color: #FFD29D; /* Soft orange for inline code */
}

.bot .message-content pre {
    background: #0d1117;
    padding: 1.25rem;
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin: 1.25rem 0;
    border: 1px solid var(--glass-border);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.bot .message-content pre code {
    background: transparent;
    padding: 0;
    display: block;
    line-height: 1.6;
    color: #e6edf3;
    font-size: 0.9rem;
}

.bot .message-content blockquote {
    border-left: 4px solid var(--accent-gradient);
    padding: 0.5rem 0 0.5rem 1.25rem;
    color: var(--text-secondary);
    font-style: italic;
    background: rgba(255, 255, 255, 0.02);
    margin: 1.25rem 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.bot .message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.25rem 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.bot .message-content th, 
.bot .message-content td {
    padding: 0.75rem 1rem;
    border: 1px solid var(--glass-border);
    text-align: left;
}

.bot .message-content th {
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent-primary);
    font-weight: 700;
}

.bot .message-content a {
    color: var(--accent-primary);
    text-decoration: none;
    border-bottom: 1px dashed var(--accent-primary);
}

.bot .message-content a:hover {
    color: white;
    border-bottom-style: solid;
}

/* Input Area */
.input-area {
    padding: 1rem;
    border-radius: var(--radius-lg);
}

.chat-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-md);
    padding: 0.5rem;
    border: 1px solid var(--glass-border);
    transition: border-color 0.3s;
}

.chat-form:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.chat-form input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 1rem;
    padding: 0.5rem;
    outline: none;
}

.chat-form input::placeholder {
    color: var(--text-placeholder);
}

.btn-send {
    background: var(--accent-gradient);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

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

/* Animations */
.appear-animation {
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes slideUp {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* Typing Indicator */
.typing-indicator.hidden {
    display: none;
}

.typing-indicator {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    margin-top: 0.5rem;
}

.typing-indicator .bubble {
    background: var(--bg-surface);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    border-top-left-radius: 4px;
    border: 1px solid var(--glass-border);
    display: flex;
    gap: 0.25rem;
}

.typing-indicator .dot {
    width: 6px;
    height: 6px;
    background-color: var(--text-secondary);
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-indicator .dot:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator .dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Responsive */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        height: auto;
        max-height: 300px;
    }
}
