:root {
    /* Premium Dark Theme Colors */
    --bg-main: #0b0d12;
    --bg-sidebar: #13161f;
    --bg-msg-user: #1a1e28;
    --bg-msg-assistant: #0b0d12;
    --bg-input: #1a1e28;
    
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    
    --accent-color: #8b5cf6; /* Purple matching Torus gradient */
    --accent-hover: #7c3aed;
    
    --border-color: #2d313d;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    overflow: hidden;
    line-height: 1.6;
}

/* App Container */
.app-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
}

.sidebar-header {
    padding: 20px;
    background-color: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 20px;
    width: 100%;
}

.brand-logo {
    height: 40px;
    margin-bottom: 15px;
    object-fit: contain;
}

.sidebar-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
    color: #e5e7eb;
    letter-spacing: 0.5px;
    text-align: center;
}

.primary-btn {
    width: 100%;
    padding: 12px;
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s ease;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.primary-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
    background-color: rgba(139, 92, 246, 0.1);
}

.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.session-item {
    padding: 12px 15px;
    margin-bottom: 8px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.9rem;
    white-space: nowrap;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
}

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

.session-item.active {
    background-color: rgba(139, 92, 246, 0.15);
    color: #c4b5fd;
    font-weight: 500;
}

.session-title-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-actions {
    display: none;
    gap: 8px;
    margin-left: 5px;
}

.session-item:hover .session-actions {
    display: flex;
}

.session-action-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    transition: color 0.2s;
}

.session-action-btn:hover {
    color: var(--text-primary);
}

.session-title-input {
    flex: 1;
    background: var(--bg-main);
    border: 1px solid var(--accent-color);
    color: var(--text-primary);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.9rem;
    outline: none;
    display: none;
}

/* Main Chat Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
}

.chat-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    text-align: center;
    background: rgba(11, 13, 18, 0.95);
    backdrop-filter: blur(5px);
    z-index: 10;
}

.chat-header h3 {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 1rem;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
    padding-bottom: 140px;
}

.message {
    padding: 30px 20px;
    border-bottom: 1px solid var(--border-color);
}

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

.message.assistant-message {
    background-color: var(--bg-msg-assistant);
}

.msg-wrapper {
    max-width: 850px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}

/* Role Label (User / Bot) */
.msg-role {
    font-weight: 700;
    font-size: 0.9rem;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.user-message .msg-role {
    color: var(--text-secondary);
}

.assistant-message .msg-role {
    color: var(--accent-color);
    display: flex;
    align-items: center;
    gap: 8px;
    background: -webkit-linear-gradient(45deg, #a855f7, #3b82f6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Status Indicator */
.bot-status {
    font-size: 0.85rem;
    color: #34d399;
    font-weight: 500;
    display: none;
    align-items: center;
    gap: 6px;
    background: rgba(52, 211, 153, 0.1);
    padding: 4px 10px;
    border-radius: 20px;
    width: fit-content;
    margin-bottom: 10px;
}

.bot-status.active {
    display: inline-flex;
}

.bot-status .spinner {
    width: 12px;
    height: 12px;
    border: 2px solid rgba(52, 211, 153, 0.2);
    border-top-color: #34d399;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin { 
    to { transform: rotate(360deg); } 
}

.msg-content {
    line-height: 1.7;
    color: var(--text-primary);
}

/* Markdown Styles */
.msg-content p { margin-bottom: 1.2em; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content pre {
    background-color: #1e293b;
    border: 1px solid #334155;
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 1.2em;
    font-size: 0.9em;
}
.msg-content code {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.9em;
}
.msg-content p code, .msg-content li code {
    background-color: #1e293b;
    padding: 2px 6px;
    border-radius: 4px;
    color: #fca5a5;
}
.msg-content a { 
    color: #60a5fa;
    text-decoration: none;
    font-weight: 500;
}
.msg-content a:hover { text-decoration: underline; }
.msg-content ul, .msg-content ol { margin-left: 20px; margin-bottom: 1.2em; }
.msg-content li { margin-bottom: 0.5em; }
.msg-content h1, .msg-content h2, .msg-content h3 { margin: 1.5em 0 0.5em; color: #fff; }

.sources-box {
    margin-top: 20px;
    padding: 12px 15px;
    background-color: #1a1e28;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.85em;
    color: var(--text-secondary);
}

/* Input Area */
.chat-input-container {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 20px 20px 10px 20px;
    background: linear-gradient(0deg, rgba(11, 13, 18, 1) 70%, rgba(11, 13, 18, 0));
    display: flex;
    flex-direction: column;
    align-items: center;
}

#chat-form {
    width: 100%;
    max-width: 850px;
    position: relative;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background-color: var(--bg-input);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.input-wrapper:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}

#user-input {
    width: 100%;
    padding: 16px 50px 16px 20px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1rem;
    resize: none;
    max-height: 200px;
    outline: none;
    font-family: inherit;
    line-height: 1.5;
}

#user-input::placeholder {
    color: #6b7280;
}

#send-btn {
    position: absolute;
    right: 12px;
    bottom: 12px;
    background: var(--accent-color);
    border: none;
    color: white;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

#send-btn:hover:not(:disabled) {
    background-color: var(--accent-hover);
}

#send-btn:disabled {
    background-color: #374151;
    color: #6b7280;
    cursor: not-allowed;
}



/* Typing Indicator */
.cursor {
    display: inline-block;
    width: 8px;
    height: 18px;
    background-color: var(--text-primary);
    animation: blink 1s step-end infinite;
    vertical-align: text-bottom;
    margin-left: 4px;
}

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