:root {
    --bg-main: #0B0F19;
    --bg-surface: #1E293B;
    --bg-surface-glass: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-primary: #F8FAFC;
    --text-secondary: #94A3B8;
    --primary-color: #6366F1;
    --primary-hover: #4F46E5;
    --accent-color: #8B5CF6;
    --msg-user: rgba(99, 102, 241, 0.1);
    --msg-assistant: transparent;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    overflow: hidden;
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 85% 30%, rgba(139, 92, 246, 0.08) 0%, transparent 50%);
}

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

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--bg-surface-glass);
    backdrop-filter: blur(16px);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 24px;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 32px;
}

.brand h1 {
    font-size: 1.25rem;
    font-weight: 600;
    background: linear-gradient(to right, #818CF8, #C084FC);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.session-info {
    margin-bottom: 24px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: #10B981;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #10B981;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

.secondary-btn {
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 16px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.secondary-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

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

/* Chat Area */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 40px;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.chat-history::-webkit-scrollbar {
    width: 6px;
}

.chat-history::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

/* Messages */
.message {
    display: flex;
    width: 100%;
    animation: fadeIn 0.4s ease forwards;
    opacity: 0;
    transform: translateY(10px);
}

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

.message-inner {
    display: flex;
    gap: 16px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user .avatar {
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
}

.assistant .avatar {
    background-color: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border-color);
}

.message-content {
    flex: 1;
    line-height: 1.6;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.message-content p {
    margin-bottom: 12px;
}

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

.message-content a {
    color: #818CF8;
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

.message-content pre {
    background-color: #0F172A;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 12px;
    border: 1px solid var(--border-color);
}

.message-content code {
    font-family: monospace;
    font-size: 0.85rem;
    background-color: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
}

.message-content pre code {
    background-color: transparent;
    padding: 0;
}

.user .message-content {
    background-color: var(--msg-user);
    padding: 16px 20px;
    border-radius: 0 12px 12px 12px;
    border: 1px solid rgba(99, 102, 241, 0.2);
}

/* Sources */
.sources-container {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.sources-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.source-chip {
    display: inline-flex;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-right: 8px;
    margin-bottom: 8px;
}

.source-chip::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background-color: var(--primary-color);
    border-radius: 50%;
    margin-right: 6px;
}

/* Welcome Message */
.welcome-msg .message-content {
    background-color: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    padding: 24px;
    border-radius: 12px;
}

.welcome-msg h3 {
    margin-bottom: 8px;
    font-weight: 500;
}

.suggestions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

.suggestion-btn {
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 12px 16px;
    border-radius: 8px;
    text-align: left;
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.suggestion-btn:hover {
    background-color: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.3);
    color: var(--text-primary);
}

/* Typing Indicator */
.typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background-color: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

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

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

/* Input Area */
.input-container {
    padding: 24px 40px;
    background: linear-gradient(to top, var(--bg-main) 60%, transparent);
}

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    position: relative;
}

#chat-form {
    display: flex;
    position: relative;
    border-radius: 16px;
    background-color: var(--bg-surface-glass);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
    transition: border-color 0.3s;
}

#chat-form:focus-within {
    border-color: var(--primary-color);
}

#query-input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 18px 24px;
    padding-right: 60px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    outline: none;
}

#query-input::placeholder {
    color: var(--text-secondary);
}

.primary-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background-color: var(--primary-color);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.primary-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-50%) scale(1.05);
}

.primary-btn:disabled {
    background-color: var(--bg-surface);
    color: var(--text-secondary);
    cursor: not-allowed;
    transform: translateY(-50%);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .chat-history, .input-container { padding: 16px; }
    .message-content { padding: 12px; }
}

/* ── Utilities ──────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Auth Screen ────────────────────────────────────────────────────────── */
.auth-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-main);
    background-image:
        radial-gradient(circle at 20% 50%, rgba(99, 102, 241, 0.12) 0%, transparent 50%),
        radial-gradient(circle at 80% 30%, rgba(139, 92, 246, 0.12) 0%, transparent 50%);
    z-index: 1000;
}

.auth-card {
    background: var(--bg-surface-glass);
    backdrop-filter: blur(24px);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 28px;
    font-size: 1.1rem;
    font-weight: 600;
    background: linear-gradient(to right, #818CF8, #C084FC);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.auth-card h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.auth-subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 28px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-group input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 16px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: var(--primary-color);
}

.auth-btn {
    position: static !important;
    transform: none !important;
    width: 100%;
    height: 48px;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    margin-top: 8px;
    gap: 10px;
}

.auth-btn:hover { transform: none !important; background-color: var(--primary-hover) !important; }

.btn-loader {
    width: 16px;
    height: 16px;
    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); } }

.auth-switch {
    text-align: center;
    margin-top: 20px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.link-btn {
    background: none;
    border: none;
    color: #818CF8;
    cursor: pointer;
    font-family: inherit;
    font-size: inherit;
    text-decoration: underline;
}

.auth-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #FCA5A5;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 16px;
}

/* ── Sidebar Additions ───────────────────────────────────────────────────── */
.sidebar-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
}

.sessions-section {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.sessions-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.sessions-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sessions-empty {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
    padding: 16px 0;
}

.session-item {
    background: none;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
    text-align: left;
    width: 100%;
    transition: all 0.2s;
    font-family: inherit;
}

.session-item:hover {
    background: rgba(255,255,255,0.05);
    border-color: var(--border-color);
}

.session-preview {
    display: block;
    font-size: 0.8rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.session-date {
    display: block;
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.sidebar-footer {
    margin-top: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
}

.user-avatar-icon {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-email {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

.logout-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.logout-btn:hover {
    border-color: rgba(239, 68, 68, 0.5);
    color: #FCA5A5;
}

/* ── Streaming cursor ───────────────────────────────────────────────────── */
.cursor-blink {
    animation: blink 1s step-end infinite;
    color: var(--primary-color);
    font-weight: 200;
}

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

/* ── Upload Modal ───────────────────────────────────────────────────────── */
.modal-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: 2000;
}

.modal-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 32px;
    width: 100%;
    max-width: 460px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}

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

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.icon-btn {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    transition: all 0.2s;
}

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

.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: 40px 24px;
    text-align: center;
    color: var(--text-secondary);
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: default;
}

.drop-zone.drag-over {
    border-color: var(--primary-color);
    background: rgba(99,102,241,0.08);
}

.drop-zone p { font-size: 0.9rem; }
.drop-zone span { font-size: 0.8rem; }

.file-label {
    cursor: pointer;
    margin-top: 4px;
    padding: 8px 20px;
}

.upload-progress-bar {
    background: rgba(255,255,255,0.08);
    border-radius: 99px;
    height: 6px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(to right, var(--primary-color), var(--accent-color));
    border-radius: 99px;
    width: 0%;
    transition: width 0.3s ease;
}

#upload-status-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-align: center;
}

.upload-success {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(16,185,129,0.08);
    border: 1px solid rgba(16,185,129,0.3);
    border-radius: 10px;
    padding: 14px 16px;
}

.upload-success p {
    font-size: 0.875rem;
    color: #6EE7B7;
}
